/// <summary>
        /// Gets the horizontal plane length
        /// </summary>
        /// <param name="axisRange"></param>
        /// <param name="origin"></param>
        /// <returns></returns>
        public double GetPlaneLength(NRange1DD axisRange, double origin, int originPoint, bool xOrZ)
        {
            NVector3DD vecA = GetVectorFromPoint(0);
            NVector3DD vecB = GetVectorFromPoint(1);

            NVector3DD lengthVector = new NVector3DD();

            lengthVector.Subtract(ref vecB, ref vecA);
            double orgPlaneLength = lengthVector.GetLength();
            double sign;

            if (originPoint == 0 || originPoint == 2)
            {
                // left point
                if (xOrZ)
                {
                    sign = vecA.X < vecB.X ? 1 : -1;
                }
                else
                {
                    sign = vecA.Z < vecB.Z ? 1 : -1;
                }
            }
            else
            {
                // right point
                if (xOrZ)
                {
                    sign = vecB.X < vecA.X ? 1 : -1;
                }
                else
                {
                    sign = vecB.Z < vecA.Z ? 1 : -1;
                }
            }

            axisRange.Normalize();

            if (sign > 0)
            {
                if (origin + orgPlaneLength > axisRange.End)
                {
                    orgPlaneLength = axisRange.End - origin;
                }
            }
            else
            {
                if (origin - orgPlaneLength < axisRange.Begin)
                {
                    orgPlaneLength = origin - axisRange.Begin;
                }
            }

            return(orgPlaneLength * sign);
        }
        /// <summary>
        /// Updates the mesh surface from the point series
        /// </summary>
        private void UpdateMeshSurface()
        {
            NVector3DD vecA = GetVectorFromPoint(0);
            NVector3DD vecB = GetVectorFromPoint(1);
            NVector3DD vecC = GetVectorFromPoint(2);
            NVector3DD vecD = GetVectorFromPoint(3);

            m_MeshSurface.Data.SetValue(0, 0, vecA.Y, vecA.X, vecA.Z);
            m_MeshSurface.Data.SetValue(0, 1, vecB.Y, vecB.X, vecB.Z);
            m_MeshSurface.Data.SetValue(1, 1, vecC.Y, vecC.X, vecC.Z);
            m_MeshSurface.Data.SetValue(1, 0, vecD.Y, vecD.X, vecD.Z);
        }
Exemple #3
0
        private void OnChartMouseDown(object sender, MouseEventArgs e)
        {
            if (MouseModeComboBox.SelectedIndex != 0)
            {
                return;
            }

            NPointF    ptViewPoint   = new NPointF((float)e.X, (float)e.Y);
            NVector3DD vecScalePoint = new NVector3DD();
            NViewToScale3DTransformation viewToScale;

            NAxis xAxis = m_Chart.Axis(StandardAxis.PrimaryX);
            NAxis yAxis = m_Chart.Axis(StandardAxis.PrimaryY);
            NAxis zAxis = m_Chart.Axis(StandardAxis.Depth);

            if (CreatePointAtPlaneComboBox.SelectedIndex == 0)
            {
                viewToScale = new NViewToScale3DTransformation(m_Chart, (int)StandardAxis.PrimaryX, (int)StandardAxis.Depth, (int)StandardAxis.PrimaryY, (double)XZPlaneValueNumericUpDown.Value);

                if (viewToScale.Transform(ptViewPoint, ref vecScalePoint))
                {
                    if (ClampValuesToRulerCheckBox.Checked)
                    {
                        vecScalePoint.X = xAxis.Scale.ViewRange.GetValueInRange(vecScalePoint.X);
                        vecScalePoint.Z = yAxis.Scale.ViewRange.GetValueInRange(vecScalePoint.Z);
                        vecScalePoint.Y = zAxis.Scale.ViewRange.GetValueInRange(vecScalePoint.Y);
                    }

                    m_Point.AddDataPoint(new NDataPoint(vecScalePoint.X, vecScalePoint.Z, vecScalePoint.Y, "Point" + m_Point.Values.Count.ToString()));
                    nChartControl1.Refresh();
                }
            }
            else
            {
                viewToScale = new NViewToScale3DTransformation(m_Chart, (int)StandardAxis.PrimaryX, (int)StandardAxis.PrimaryY, (int)StandardAxis.Depth, (double)XYPlaneValueNumericUpDown.Value);

                if (viewToScale.Transform(ptViewPoint, ref vecScalePoint))
                {
                    if (ClampValuesToRulerCheckBox.Checked)
                    {
                        vecScalePoint.X = xAxis.Scale.ViewRange.GetValueInRange(vecScalePoint.X);
                        vecScalePoint.Y = yAxis.Scale.ViewRange.GetValueInRange(vecScalePoint.Y);
                        vecScalePoint.Z = zAxis.Scale.ViewRange.GetValueInRange(vecScalePoint.Z);
                    }

                    m_Point.AddDataPoint(new NDataPoint(vecScalePoint.X, vecScalePoint.Y, vecScalePoint.Z, "Point" + m_Point.Values.Count.ToString()));
                    nChartControl1.Refresh();
                }
            }
        }
        private void FillData()
        {
            NChart chart = nChartControl1.Charts[0];
            NTriangulatedSurfaceSeries surface = (NTriangulatedSurfaceSeries)chart.Series[0];

            Random rand = new Random();

            const int countX = 100;
            const int countZ = 100;

            NRange1DD rangeX = new NRange1DD(-10, 10);
            NRange1DD rangeZ = new NRange1DD(-10, 10);

            double stepX = rangeX.GetLength() / (countX - 1);
            double stepZ = rangeZ.GetLength() / (countZ - 1);

            double cx = -3.0;
            double cz = -5.0;

            NVector3DD[] vectorData = new NVector3DD[countZ * countX];
            int          index      = 0;

            for (int n = 0; n < countZ; n++)
            {
                double z = rangeZ.Begin + n * stepZ;

                for (int m = 0; m < countX; m++)
                {
                    double x        = rangeX.Begin + m * stepX;
                    double dx       = cx - x;
                    double dz       = cz - z;
                    double distance = Math.Sqrt(dx * dx + dz * dz);

                    vectorData[index] = new NVector3DD(x, Math.Sin(distance) * Math.Exp(-distance * 0.1), z);
                    index++;
                }
            }

            if (SimplifySurfaceCheckBox.Checked)
            {
                NPointSetSimplifier3D pointSetSimplifier3D = new NPointSetSimplifier3D();
                pointSetSimplifier3D.DistanceFactor = 0.01f;

                vectorData = pointSetSimplifier3D.Simplify(vectorData);
            }

            surface.Data.Clear();
            surface.Data.AddValues(vectorData);
        }
        /// <summary>
        /// Initializer constructor
        /// </summary>
        /// <param name="vecA"></param>
        /// <param name="vecB"></param>
        /// <param name="vecC"></param>
        /// <param name="vecD"></param>
        public NDragPlane(NVector3DD vecA, NVector3DD vecB, NVector3DD vecC, NVector3DD vecD)
        {
            NPointSeries pointSeries = new NPointSeries();

            pointSeries.Tag                    = (int)1;
            pointSeries.PointShape             = PointShape.Sphere;
            pointSeries.UseXValues             = true;
            pointSeries.UseZValues             = true;
            pointSeries.DataLabelStyle.Visible = false;
            pointSeries.InflateMargins         = false;
            pointSeries.Size                   = new NLength(8);

            pointSeries.Values.Add(vecA.Y);
            pointSeries.XValues.Add(vecA.X);
            pointSeries.ZValues.Add(vecA.Z);
            pointSeries.FillStyles[0] = new NColorFillStyle(Color.Red);

            pointSeries.Values.Add(vecB.Y);
            pointSeries.XValues.Add(vecB.X);
            pointSeries.ZValues.Add(vecB.Z);
            pointSeries.FillStyles[1] = new NColorFillStyle(Color.Blue);

            pointSeries.Values.Add(vecC.Y);
            pointSeries.XValues.Add(vecC.X);
            pointSeries.ZValues.Add(vecC.Z);
            pointSeries.FillStyles[2] = new NColorFillStyle(Color.Blue);


            pointSeries.Values.Add(vecD.Y);
            pointSeries.XValues.Add(vecD.X);
            pointSeries.ZValues.Add(vecD.Z);
            pointSeries.FillStyles[3] = new NColorFillStyle(Color.Red);

            m_PointSeries = pointSeries;

            NMeshSurfaceSeries meshSeries = new NMeshSurfaceSeries();

            meshSeries.Data.SetGridSize(2, 2);

            m_MeshSurface           = meshSeries;
            m_MeshSurface.FillMode  = SurfaceFillMode.Uniform;
            m_MeshSurface.FrameMode = SurfaceFrameMode.None;
            m_MeshSurface.FillStyle = new NColorFillStyle(Color.Blue);
            m_MeshSurface.FillStyle.SetTransparencyPercent(50.0f);

            UpdateMeshSurface();
        }
        /// <summary>
        /// Overriden to perform dragging
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void OnDoDrag(object sender, Nevron.Chart.Windows.NMouseEventArgs e)
        {
            NChart chart = this.GetDocument().Charts[0];

            NViewToScale3DTransformation viewToScale;

            switch (m_DragPlaneSurface)
            {
            case DragPlaneSurface.XY:
                viewToScale = new NViewToScale3DTransformation(chart, (int)StandardAxis.PrimaryX, (int)StandardAxis.PrimaryY, (int)StandardAxis.Depth, m_OriginalPosition.Z);
                break;

            case DragPlaneSurface.XZ:
                viewToScale = new NViewToScale3DTransformation(chart, (int)StandardAxis.PrimaryX, (int)StandardAxis.Depth, (int)StandardAxis.PrimaryY, m_OriginalPosition.Y);
                break;

            case DragPlaneSurface.ZY:
                viewToScale = new NViewToScale3DTransformation(chart, (int)StandardAxis.Depth, (int)StandardAxis.PrimaryY, (int)StandardAxis.PrimaryX, m_OriginalPosition.X);
                break;

            default:
                Debug.Assert(false);     // new drag plane
                return;
            }

            NVector3DD vecNewPosition = new NVector3DD();

            viewToScale.Transform(new NPointF(e.X, e.Y), ref vecNewPosition);

            m_DragPlane.LockX = false;
            m_DragPlane.LockZ = false;

            if (LockX)
            {
                m_DragPlane.LockX = true;
            }
            else if (LockZ)
            {
                m_DragPlane.LockZ = true;
            }

            m_DragPlane.MovePoint(m_DragPlaneSurface, vecNewPosition, m_DataPointIndex);
            m_DragPlane.PointSeries.Document.Refresh();
        }
Exemple #7
0
        private void VolumeSelectionTool_EndDrag(object sender, EventArgs e)
        {
            NPointSeries        point      = (NPointSeries)nChartControl1.Charts[0].Series[0];
            NVolumeSelectorTool volumeTool = (NVolumeSelectorTool)sender;

            for (int i = 0; i < point.Values.Count; i++)
            {
                NVector3DD vec = new NVector3DD((float)(double)point.XValues[i], (float)(double)point.Values[i], (float)(double)point.ZValues[i]);
                if (volumeTool.TopPlane.Distance(ref vec) < 0 &&
                    volumeTool.RightPlane.Distance(ref vec) < 0 &&
                    volumeTool.BottomPlane.Distance(ref vec) < 0 &&
                    volumeTool.LeftPlane.Distance(ref vec) < 0)
                {
                    // point is contained in the set
                    point.FillStyles[i] = new NColorFillStyle(Color.Red);
                }
            }

            nChartControl1.Refresh();
        }
Exemple #8
0
        private void FillData()
        {
            if (nChartControl1 == null)
            {
                return;
            }

            NChart chart = nChartControl1.Charts[0];
            NTriangulatedSurfaceSeries surface     = (NTriangulatedSurfaceSeries)chart.Series[0];
            NTriangulatedSurfaceData   surfaceData = surface.Data;

            if (m_SurfaceVectorData == null)
            {
                Random rand = new Random();

                const int countX = 100;
                const int countZ = 100;

                NRange1DD rangeX = new NRange1DD(-10, 10);
                NRange1DD rangeZ = new NRange1DD(-10, 10);

                double stepX = rangeX.GetLength() / (countX - 1);
                double stepZ = rangeZ.GetLength() / (countZ - 1);

                double cx = -3.0;
                double cz = -5.0;

                NVector3DD[] vectorData = new NVector3DD[countZ * countX];
                int          index      = 0;

                for (int n = 0; n < countZ; n++)
                {
                    double z = rangeZ.Begin + n * stepZ;

                    for (int m = 0; m < countX; m++)
                    {
                        double x        = rangeX.Begin + m * stepX;
                        double dx       = cx - x;
                        double dz       = cz - z;
                        double distance = Math.Sqrt(dx * dx + dz * dz);

                        vectorData[index++] = new NVector3DD(x, Math.Sin(distance) * Math.Exp(-distance * 0.1), z);
                    }
                }

                m_SurfaceVectorData = vectorData;
            }

            NVector3DD[] newSurfaceVectorData = m_SurfaceVectorData;;

            if (SimplifySurfaceCheckBox.IsChecked.Value)
            {
                NPointSetSimplifier3D simplifier = new NPointSetSimplifier3D();
                simplifier.DistanceFactor = 0.01;

                newSurfaceVectorData = simplifier.Simplify(newSurfaceVectorData);
            }

            surfaceData.Clear();
            surfaceData.AddValues(newSurfaceVectorData);

            nChartControl1.Refresh();
        }
        private void VertexPrimitiveCombo_SelectedIndexChanged(object sender, EventArgs e)
        {
            m_Surface.Data.Clear();

            VertexPrimitive vertexPrimitive = (VertexPrimitive)VertexPrimitiveCombo.SelectedIndex;

            m_Surface.VertexPrimitive = vertexPrimitive;
            m_Surface.UseIndices      = false;

            Random rand            = new Random();
            string descriptionText = string.Empty;

            switch (vertexPrimitive)
            {
            case VertexPrimitive.Points:
            {
                descriptionText = "Each vertex represents a 3d point";

                m_Surface.FrameMode = SurfaceFrameMode.Dots;

                for (int i = 0; i < 10000; i++)
                {
                    m_Surface.Data.AddValue(rand.Next(100),
                                            rand.Next(100),
                                            rand.Next(100));
                }
            }
            break;

            case VertexPrimitive.Lines:
            {
                descriptionText = "Each consecutive pair of vertices represents a line segment";

                m_Surface.FrameMode = SurfaceFrameMode.Dots;

                for (int i = 0; i < 200; i++)
                {
                    m_Surface.Data.AddValue(rand.Next(100),
                                            rand.Next(100),
                                            rand.Next(100));

                    m_Surface.Data.AddValue(rand.Next(100),
                                            rand.Next(100),
                                            rand.Next(100));
                }
            }
            break;

            case VertexPrimitive.LineLoop:
            case VertexPrimitive.LineStrip:
            {
                descriptionText = "Adjacent vertices are connected with a line segment";

                for (int i = 0; i < 5; i++)
                {
                    m_Surface.Data.AddValue(rand.Next(100),
                                            rand.Next(100),
                                            rand.Next(100));
                }
            }
            break;

            case VertexPrimitive.Triangles:
            {
                descriptionText = "Each three consequtive vertices are considered a triangle";

                m_Surface.FrameMode = SurfaceFrameMode.Mesh;

                NVector3DD top   = new NVector3DD(0.5, 1, 0.5);
                NVector3DD baseA = new NVector3DD(0, 0, 0);
                NVector3DD baseB = new NVector3DD(1, 0, 0);
                NVector3DD baseC = new NVector3DD(1, 0, 1);
                NVector3DD baseD = new NVector3DD(0, 0, 1);

                m_Surface.Data.AddValue(top);
                m_Surface.Data.AddValue(baseA);
                m_Surface.Data.AddValue(baseB);

                m_Surface.Data.AddValue(top);
                m_Surface.Data.AddValue(baseB);
                m_Surface.Data.AddValue(baseC);

                m_Surface.Data.AddValue(top);
                m_Surface.Data.AddValue(baseC);
                m_Surface.Data.AddValue(baseD);

                m_Surface.Data.AddValue(top);
                m_Surface.Data.AddValue(baseD);
                m_Surface.Data.AddValue(baseA);
            }
            break;

            case VertexPrimitive.TriangleStrip:
            {
                descriptionText = "A series of connected triangles that share common vertices";

                m_Surface.FrameMode = SurfaceFrameMode.Mesh;

                NVector3DD A = new NVector3DD(0, 0, 0);
                NVector3DD B = new NVector3DD(1, 0, 0);
                NVector3DD C = new NVector3DD(0, 1, 1);
                NVector3DD D = new NVector3DD(1, 1, 1);

                m_Surface.Data.AddValue(A);
                m_Surface.Data.AddValue(B);
                m_Surface.Data.AddValue(C);
                m_Surface.Data.AddValue(D);
            }
            break;

            case VertexPrimitive.TriangleFan:
            {
                descriptionText = "A series of connected triangles that share a common vertex";

                m_Surface.FrameMode = SurfaceFrameMode.Mesh;

                m_Surface.Data.AddValue(0, 100, 0);

                int steps = 10;

                for (int i = 0; i < 3000; i++)
                {
                    double angle = i * 2 * Math.PI / steps;

                    m_Surface.Data.AddValue(Math.Cos(angle) * 100,
                                            0,
                                            Math.Sin(angle) * 100);
                }
            }
            break;

            case VertexPrimitive.Quads:
            {
                descriptionText = "Each for consecutive vertices form a quad";

                m_Surface.FrameMode = SurfaceFrameMode.Mesh;

                NVector3DD A = new NVector3DD(0, 0, 0);
                NVector3DD B = new NVector3DD(1, 0, 0);
                NVector3DD C = new NVector3DD(0, 1, 1);
                NVector3DD D = new NVector3DD(1, 1, 1);


                m_Surface.Data.AddValue(A);
                m_Surface.Data.AddValue(B);
                m_Surface.Data.AddValue(D);
                m_Surface.Data.AddValue(C);
            }
            break;

            case VertexPrimitive.QuadStrip:
            {
                descriptionText = "A series of connected quads that share common vertices";

                m_Surface.FrameMode = SurfaceFrameMode.Mesh;

                NVector3DD A = new NVector3DD(0, 0, 0);
                NVector3DD B = new NVector3DD(1, 0, 0);
                NVector3DD C = new NVector3DD(0, 1, 1);
                NVector3DD D = new NVector3DD(1, 1, 1);
                NVector3DD E = new NVector3DD(0, 2, 2);
                NVector3DD F = new NVector3DD(1, 2, 2);


                m_Surface.Data.AddValue(A);
                m_Surface.Data.AddValue(B);
                m_Surface.Data.AddValue(C);
                m_Surface.Data.AddValue(D);
                m_Surface.Data.AddValue(E);
                m_Surface.Data.AddValue(F);
            }

            break;
            }

            nChartControl1.Labels[0].Text = "Vertex Surface<br/><font size='10pt'>" + descriptionText + "</font>";

            nChartControl1.Refresh();
        }
        /// <summary>
        /// Synchronizes the points so that they are coplanar
        /// </summary>
        /// <param name="modifiedPointIndex"></param>
        public void SynchronizePoints(int modifiedPointIndex)
        {
            // then align points depending on which point is being dragged
            NVector3DD vecA = GetVectorFromPoint(0);
            NVector3DD vecB = GetVectorFromPoint(1);
            NVector3DD vecC = GetVectorFromPoint(2);
            NVector3DD vecD = GetVectorFromPoint(3);

            switch (modifiedPointIndex)
            {
            case 0:                     // left top
                // sync point 3 (left bottom)
            {
                NVector3DD vecCB = new NVector3DD();
                vecCB.Subtract(ref vecC, ref vecB);

                vecD.Add(ref vecA, ref vecCB);

                SetVectorToPoint(3, vecD);
            }
            break;

            case 1:                     // right top
            {
                // sync point 2 (right bottom)
                NVector3DD vecDA = new NVector3DD();
                vecDA.Subtract(ref vecD, ref vecA);

                vecC.Add(ref vecB, ref vecDA);

                SetVectorToPoint(2, vecC);
            }
            break;

            case 2:                     // right bottom
            {
                // sync point 1 (right top)
                NVector3DD vecAD = new NVector3DD();
                vecAD.Subtract(ref vecA, ref vecD);

                vecB.Add(ref vecC, ref vecAD);

                SetVectorToPoint(1, vecB);
            }
            break;

            case 3:                     // left bottom
            {
                // sync point 0 (left top)
                NVector3DD vecCB = new NVector3DD();
                vecCB.Subtract(ref vecB, ref vecC);

                vecA.Add(ref vecD, ref vecCB);

                SetVectorToPoint(0, vecA);
            }
            break;
            }

            // handle x / z locking
            if (m_LockX)
            {
                double x = GetVectorFromPoint(modifiedPointIndex).X;
                for (int i = 0; i < 4; i++)
                {
                    if (i != modifiedPointIndex)
                    {
                        SetXPointCoordinate(i, x);
                    }
                }
            }

            if (m_LockZ)
            {
                double z = GetVectorFromPoint(modifiedPointIndex).Z;

                for (int i = 0; i < 4; i++)
                {
                    if (i != modifiedPointIndex)
                    {
                        SetZPointCoordinate(i, z);
                    }
                }
            }
        }
 /// <summary>
 /// Initializer constructor
 /// </summary>
 /// <param name="dragPlane"></param>
 public NDragPlaneTool(NDragPlane dragPlane)
 {
     m_DragPlane        = dragPlane;
     m_OriginalPosition = new NVector3DD();
 }
 /// <summary>
 /// Sets the vector to the specified point
 /// </summary>
 /// <param name="dataPointIndex"></param>
 /// <param name="vector"></param>
 private void SetVectorToPoint(int dataPointIndex, NVector3DD vector)
 {
     SetXPointCoordinate(dataPointIndex, vector.X);
     SetYPointCoordinate(dataPointIndex, vector.Y);
     SetZPointCoordinate(dataPointIndex, vector.Z);
 }