//public double[,] CreatePatternGradient(Point4D[,] data)
        //{
        //    double minZ = double.MaxValue;
        //    double maxZ = double.MinValue;
        //    //double minW = double.MaxValue;
        //    //double maxW = double.MinValue;

        //    int n = data.GetUpperBound(0) + 1;
        //    int m = data.GetUpperBound(0) + 1;
        //    for (int i = 0; i < n; i++)
        //        for (int j = 0; j < m; j++)
        //        {
        //            double z = data[i, j].Z;
        //            double w = data[i, j].W;
        //            maxZ = Math.Max(maxZ, z);
        //            minZ = Math.Min(minZ, z);
        //            //maxW = Math.Max(maxW, w);
        //            //minW = Math.Min(minW, w);
        //        }

        //    var K = new double[n, m];

        //    for (int i = 0; i < n; i++)
        //        for (int j = 0; j < m; j++)
        //        {
        //            double mod = MathUtil.Scale(minZ, maxZ, data[i, j].Z, 100, 0);
        //            double fas = data[i, j].W;          //MathUtil.Scale(0, 2 * Math.PI, data[i, j].W);
        //            K[i, j] = i + j; //0.5 + mod + fas;//* Math.Cos(fas);
        //        }

        //    return K;
        //}

        public double[,] FindGradientZ(Point3D[,] data, int offset = 0)
        {
            double minZ = double.MaxValue;
            double maxZ = double.MinValue;

            int n = data.GetUpperBound(0) + 1;
            int m = data.GetUpperBound(0) + 1;

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    double z = data[i, j].Z;
                    maxZ = Math.Max(maxZ, z);
                    minZ = Math.Min(minZ, z);
                }
            }


            var K = new double[n, m];

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    K[i, j] = MathUtil.Scale(minZ, maxZ, data[i, j].Z, n);
                }
            }

            return(K);
        }
        /// <summary>
        ///     Creates a mesh with a horizontal and vertical resolution indicated
        ///     by the input parameters.  It will generate
        ///     (precisionU-1)*(precisionV-1) quads.
        /// </summary>
        public MeshGeometry3D CreateMesh(int precisionU, int precisionV)
        {
            _lengthX = precisionU;
            _lengthY = precisionV;
            _du      = (UMax - UMin) / (precisionU - 1);
            _dv      = (VMax - VMin) / (precisionV - 1);

            _positions     = new Point3D[_lengthX, _lengthY];
            _normals       = new Vector3D[_lengthX, _lengthY];
            _textureCoords = new Point[_lengthX, _lengthY];
            _indices       = new ArrayList();

            var v = VMin;

            for (var y = 0; y < _lengthY; y++)
            {
                var u = UMin;
                if (y == _lengthY - 1)
                {
                    v = VMax;
                }
                for (var x = 0; x < _lengthX; x++)
                {
                    if (x == _lengthX - 1)
                    {
                        u = UMax;
                    }
                    VariableExpression.Define("u", u);
                    VariableExpression.Define("v", v);
                    _positions[x, y] = Evaluate();
                    _normals[x, y]   = GetNormal(u, v);
                    u += _du;
                }
                v += _dv;
            }
            VariableExpression.Undefine("u");
            VariableExpression.Undefine("v");

            SetTextureCoordinates();
            SetIndices();

            var mesh = new MeshGeometry3D();

            for (var y = 0; y < _lengthY; y++)
            {
                for (var x = 0; x < _lengthX; x++)
                {
                    mesh.Positions.Add(_positions[x, y]);
                    mesh.Normals.Add(_normals[x, y]);
                    mesh.TextureCoordinates.Add(_textureCoords[x, y]);
                }
            }
            mesh.TriangleIndices = new Int32Collection();
            foreach (int index in _indices)
            {
                mesh.TriangleIndices.Add(index);
            }

            return(mesh);
        }
Exemple #3
0
        private static Point3D BilinearInterpolation(Point3D[,] p, double i, double j)
        {
            int n  = p.GetUpperBound(0);
            int m  = p.GetUpperBound(1);
            var i0 = (int)i;
            var j0 = (int)j;

            if (i0 + 1 >= n)
            {
                i0 = n - 2;
            }
            if (j0 + 1 >= m)
            {
                j0 = m - 2;
            }

            if (i < 0)
            {
                i = 0;
            }
            if (j < 0)
            {
                j = 0;
            }
            double   u   = i - i0;
            double   v   = j - j0;
            Vector3D v00 = p[i0, j0].ToVector3D();
            Vector3D v01 = p[i0, j0 + 1].ToVector3D();
            Vector3D v10 = p[i0 + 1, j0].ToVector3D();
            Vector3D v11 = p[i0 + 1, j0 + 1].ToVector3D();
            Vector3D v0  = v00 * (1 - u) + v10 * u;
            Vector3D v1  = v01 * (1 - u) + v11 * u;

            return((v0 * (1 - v) + v1 * v).ToPoint3D());
        }
Exemple #4
0
        public GeometryModel3D createRoadModel(Point3D[] points, double roadWidth)
        {
            // 转为相对坐标
            for (int i = 0; i < points.Length; i++)
            {
                points[i].X -= Offset.X;
                points[i].Y -= Offset.Y;
                points[i].Z -= Offset.Z;
            }

            Point3D[,] RoadPts = createRoadMesh(points, roadWidth);
            // 构造道路面的mesh
            MeshBuilder mb = new MeshBuilder(false, false);

            mb.AddRectangularMesh(RoadPts, closed0: false, closed1: false);
            var mesh  = mb.ToMesh();
            var model = new GeometryModel3D();

            model.Geometry = mesh;
            var material = MaterialHelper.CreateMaterial(RoadColor);

            model.Material     = material;
            model.BackMaterial = material;
            return(model);
        }
Exemple #5
0
 private void AddAdjacentNeighbours(Point3D[,] edgesPoints, List <AdjacentPoints>[] adjacentPoints)
 {
     for (int i = 0; i < edgesPoints.GetLength(0); ++i)
     {
         AddEdgeNeighbours(edgesPoints, i, adjacentPoints[i]);
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="xyzPoints"></param>
        /// <returns></returns>
        public static Point3D FindMinValues(Point3D[,] xyzPoints)
        {
            int numberElementsX = xyzPoints.GetUpperBound(0);
            int numberElementsY = xyzPoints.GetUpperBound(1);

            double minX = float.MaxValue;
            double minY = float.MaxValue;
            double minZ = float.MaxValue;

            for (int x = 0; x <= numberElementsX; x++)
            {
                for (int y = 0; y <= numberElementsY; y++)
                {
                    Point3D p3D = xyzPoints[x, y];
                    if (p3D.X < minX)
                    {
                        minX = p3D.X;
                    }
                    if (p3D.Y < minY)
                    {
                        minY = p3D.Y;
                    }
                    if (p3D.Z < minZ)
                    {
                        minZ = p3D.Z;
                    }
                }
            }

            return(new Point3D(minX, minY, minZ));
        }
Exemple #7
0
        // получение всех пикселей сцены
        public void GetPixels()
        {
            /*
             * Учитывая разницу между размером комнаты и экранным отображение приводим координаты к пикселям
             */
            pixels       = new Point3D[w, h];
            pixels_color = new Color[w, h];
            Point3D step_up   = (up_right - up_left) / (w - 1);     //отношение ширины комнаты к ширине экрана
            Point3D step_down = (down_right - down_left) / (w - 1); //отношение высоты комнаты к высоте экрана
            Point3D up        = new Point3D(up_left);
            Point3D down      = new Point3D(down_left);

            for (int i = 0; i < w; ++i)
            {
                Point3D step_y = (up - down) / (h - 1);
                Point3D d      = new Point3D(down);
                for (int j = 0; j < h; ++j)
                {
                    pixels[i, j] = d;
                    d           += step_y;
                }
                up   += step_up;
                down += step_down;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="xyzPoints"></param>
        /// <returns></returns>
        public static Point3D FindMaxValues(Point3D[,] xyzPoints)
        {
            int numberElementsX = xyzPoints.GetUpperBound(0);
            int numberElementsY = xyzPoints.GetUpperBound(1);

            double maxX = float.MinValue;
            double maxY = float.MinValue;
            double maxZ = float.MinValue;

            for (int x = 0; x <= numberElementsX; x++)
            {
                for (int y = 0; y <= numberElementsY; y++)
                {
                    Point3D p3D = xyzPoints[x, y];
                    if (p3D.X > maxX)
                    {
                        maxX = p3D.X;
                    }
                    if (p3D.Y > maxY)
                    {
                        maxY = p3D.Y;
                    }
                    if (p3D.Z > maxZ)
                    {
                        maxZ = p3D.Z;
                    }
                }
            }

            return(new Point3D(maxX, maxY, maxZ));
        }
Exemple #9
0
        void refreshSlicedGrid()
        {
            double xySizeD2High = 1000 * VolumeSizeX / 2;
            double xySizeD2Low  = -1000 * VolumeSizeX / 2;
            double zSizeD2High  = 1000 * VolumeSizeZ / 2;
            double zSizeD2Low   = -1000 * VolumeSizeZ / 2;

            double aZ = zSizeD2High - 1000 * VolumeSizeZ * (1 - SelectedPlaneZ);
            double aY = xySizeD2High - 1000 * VolumeSizeX * SelectedPlaneY;
            double aX = xySizeD2High - 1000 * VolumeSizeX * (1 - SelectedPlaneX);

            _slicedGrid       = new Point3D[3, 4];
            _slicedGrid[0, 0] = new Point3D(xySizeD2Low, xySizeD2Low, aZ);
            _slicedGrid[0, 1] = new Point3D(xySizeD2High, xySizeD2Low, aZ);
            _slicedGrid[0, 2] = new Point3D(xySizeD2High, xySizeD2High, aZ);
            _slicedGrid[0, 3] = new Point3D(xySizeD2Low, xySizeD2High, aZ);

            _slicedGrid[1, 0] = new Point3D(aX, xySizeD2Low, zSizeD2High);
            _slicedGrid[1, 1] = new Point3D(aX, xySizeD2Low, zSizeD2Low);
            _slicedGrid[1, 2] = new Point3D(aX, xySizeD2High, zSizeD2Low);
            _slicedGrid[1, 3] = new Point3D(aX, xySizeD2High, zSizeD2High);

            _slicedGrid[2, 0] = new Point3D(xySizeD2High, aY, zSizeD2High);
            _slicedGrid[2, 1] = new Point3D(xySizeD2High, aY, zSizeD2Low);
            _slicedGrid[2, 2] = new Point3D(xySizeD2Low, aY, zSizeD2Low);
            _slicedGrid[2, 3] = new Point3D(xySizeD2Low, aY, zSizeD2High);

            _zRegionSlicesCoord[0] = new Point3D(xySizeD2Low, xySizeD2Low, 0);
            _zRegionSlicesCoord[1] = new Point3D(xySizeD2High, xySizeD2Low, 0);
            _zRegionSlicesCoord[2] = new Point3D(xySizeD2High, xySizeD2High, 0);
            _zRegionSlicesCoord[3] = new Point3D(xySizeD2Low, xySizeD2High, 0);
        }
        private static IEnumerable <Point3D> Wireframe2(Point3D[,] points)
        {
            var width            = points.GetLength(0);
            var heigth           = points.GetLength(1);
            var currentPoint     = new Point(0, heigth - 1);
            var finishPoint      = new Point(width - 1, 0);
            var currentDirection = new Vector(1, 0);
            var wireframe        = new List <Point3D>();

            while (true)
            {
                wireframe.Add(points[(int)currentPoint.X, (int)currentPoint.Y]);
                currentPoint.Offset(currentDirection.X, currentDirection.Y);
                wireframe.Add(points[(int)currentPoint.X, (int)currentPoint.Y]);
                if (currentPoint.X == 0 || currentPoint.X == width - 1)
                {
                    currentPoint.Offset(0, -1);
                    currentDirection.X = currentPoint.X == 0 ? 1 : -1;
                    if (currentPoint == finishPoint)
                    {
                        break;
                    }
                }
            }
            return(wireframe);
        }
        // http://en.wikipedia.org/wiki/Numerical_differentiation
        public double[,] FindGradientY(Point3D[,] data)
        {
            int n = data.GetUpperBound(0) + 1;
            int m = data.GetUpperBound(0) + 1;
            var K = new double[n, m];

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    // Finite difference approximation
                    var p10 = data[i + 1 < n ? i + 1 : i, j - 1 > 0 ? j - 1 : j];
                    var p00 = data[i - 1 > 0 ? i - 1 : i, j - 1 > 0 ? j - 1 : j];
                    var p11 = data[i + 1 < n ? i + 1 : i, j + 1 < m ? j + 1 : j];
                    var p01 = data[i - 1 > 0 ? i - 1 : i, j + 1 < m ? j + 1 : j];

                    //double dx = p01.X - p00.X;
                    //double dz = p01.Z - p00.Z;
                    //double Fx = dz / dx;

                    double dy = p10.Y - p00.Y;
                    double dz = p10.Z - p00.Z;

                    K[i, j] = dz / dy;
                }
            }
            return(K);
        }
Exemple #12
0
        void buildColorMap(Point3D up1, Point3D up2, Point3D down1, Point3D down2, int w, int h)
        {
            points   = new Point3D[w, h];
            colormap = new Color[w, h];

            Point3D stepup   = (up2 - up1) / (w - 1);
            Point3D stepdown = (down2 - down1) / (w - 1);

            Point3D u = new Point3D(up1);
            Point3D d = new Point3D(down1);

            for (int i = 0; i < w; i++)
            {
                Point3D stepy = (u - d) / (h - 1);
                Point3D p     = new Point3D(d);
                for (int j = 0; j < h; j++)
                {
                    points[i, j] = p;
                    p           += stepy;
                }


                d += stepdown;
                u += stepup;
            }
        }
Exemple #13
0
        ///<summary>贝塞尔平滑插点计算,X方向</summary>
        private Point3D[,] insertXPoint(Point3D[,] allpoint, int insertcount) //x方向插点
        {
            // bezier平滑插值
            Point[] ap, cp1, cp2;
            Point   calpoint;

            Point3D[,] resultpoint = new Point3D[(allpoint.GetLength(0) - 1) * (insertcount + 1) + 1, allpoint.GetLength(1)];
            Point[] cp = new Point[4];
            for (int i = 0; i < allpoint.GetLength(1); i++)
            {
                ap = new Point[allpoint.GetLength(0)];
                for (int j = 0; j < allpoint.GetLength(0); j++)
                {
                    ap[j].X = allpoint[j, i].X;
                    ap[j].Y = allpoint[j, i].Y;
                }
                MyGeometryHelper.GetCurveControlPoints(ap, out cp1, out cp2);
                for (int j = 0; j < allpoint.GetLength(0) - 1; j++)
                {
                    resultpoint[j * (insertcount + 1), i] = allpoint[j, i]; //原有的点
                    cp[0] = ap[j]; cp[1] = cp1[j]; cp[2] = cp2[j]; cp[3] = ap[j + 1];
                    for (int k = 0; k < insertcount; k++)
                    {
                        calpoint = MyGeometryHelper.PointOnBezier(cp, 1.0 / (insertcount + 1) * (k + 1));
                        resultpoint[j * (insertcount + 1) + 1 + k, i] = new Point3D(calpoint.X, calpoint.Y, allpoint[j, i].Z); //插入的点
                    }
                }
                resultpoint[(allpoint.GetLength(0) - 1) * (insertcount + 1), i] = allpoint[allpoint.GetLength(0) - 1, i]; //原有的终点
            }
            return(resultpoint);
        }
        private void AddXYColor(ChartStyle2D cs2d, DataSeriesSurface ds)
        {
            Point3D[,] pts = ds.PointArray;
            double zmin = ds.ZDataMin();
            double zmax = ds.ZDataMax();

            // Draw surface on the XY plane:
            if (!IsInterp)
            {
                for (int i = 0; i < pts.GetLength(0) - 1; i++)
                {
                    for (int j = 0; j < pts.GetLength(1) - 1; j++)
                    {
                        plg                 = new Polygon();
                        plg.Stroke          = ds.LineColor;
                        plg.StrokeThickness = ds.LineThickness;
                        plg.Fill            = GetBrush(pts[i, j].Z, zmin, zmax);
                        if (IsLineColorMatch)
                        {
                            plg.Stroke = GetBrush(pts[i, j].Z, zmin, zmax);
                        }
                        plg.Points.Add(cs2d.NormalizePoint(new Point(pts[i, j].X, pts[i, j].Y)));
                        plg.Points.Add(cs2d.NormalizePoint(new Point(pts[i, j + 1].X, pts[i, j + 1].Y)));
                        plg.Points.Add(cs2d.NormalizePoint(new Point(pts[i + 1, j + 1].X, pts[i + 1, j + 1].Y)));
                        plg.Points.Add(cs2d.NormalizePoint(new Point(pts[i + 1, j].X, pts[i + 1, j].Y)));
                        cs2d.Chart2dCanvas.Children.Add(plg);
                    }
                }
            }
            else if (IsInterp)
            {
                for (int i = 0; i < pts.GetLength(0) - 1; i++)
                {
                    for (int j = 0; j < pts.GetLength(1) - 1; j++)
                    {
                        Point3D[] points = new Point3D[4];
                        points[0] = pts[i, j];
                        points[1] = pts[i, j + 1];
                        points[2] = pts[i + 1, j + 1];
                        points[3] = pts[i + 1, j];

                        Interp2D(cs2d, points, zmin, zmax);
                        plg        = new Polygon();
                        plg.Stroke = ds.LineColor;
                        if (IsLineColorMatch)
                        {
                            plg.Stroke = GetBrush(pts[i, j].Z, zmin, zmax);
                        }
                        plg.StrokeThickness = ds.LineThickness;
                        plg.Fill            = Brushes.Transparent;
                        plg.Points.Add(cs2d.NormalizePoint(new Point(pts[i, j].X, pts[i, j].Y)));
                        plg.Points.Add(cs2d.NormalizePoint(new Point(pts[i, j + 1].X, pts[i, j + 1].Y)));
                        plg.Points.Add(cs2d.NormalizePoint(new Point(pts[i + 1, j + 1].X, pts[i + 1, j + 1].Y)));
                        plg.Points.Add(cs2d.NormalizePoint(new Point(pts[i + 1, j].X, pts[i + 1, j].Y)));
                        cs2d.Chart2dCanvas.Children.Add(plg);
                    }
                }
            }
        }
        public override Material CreateTexture(Point3D[,] points)
        {
            if (_vsTexture == null)
            {
                this._vsTexture = CreateVisibleSpectrumMaterial(points);
            }

            return(_vsTexture);
        }
        /// <summary>
        /// Terrain Constructor
        /// </summary>
        /// <param name="gridPoints"></param>
        /// <param name="vpt"></param>
        public TerrainFill(Point3D[,] gridPoints, Viewport3D vpt)
        {
            this.terrainGridPoints = gridPoints;
            this.vpt3D             = vpt;

            this.ApplyTrianglesToGridPoints(this.terrainGridPoints);
            Environment.DrawLight(vpt);
            Camera.ApplyPerspective(vpt);
        }
Exemple #17
0
 private void AddEdgeNeighbours(Point3D[,] edgesPoints, int edgeNumber, List <AdjacentPoints> adjacentPointsLst)
 {
     foreach (var adjacentPoints in adjacentPointsLst)
     {
         foreach (var adjIdxs in adjacentPoints.Item2)
         {
             edgesPoints[edgeNumber, adjIdxs.Item1].AddNeighbour(edgesPoints[adjacentPoints.Item1, adjIdxs.Item2]);
         }
     }
 }
Exemple #18
0
        public Surface()
            : base()
        {
            mp = new Point3D[4, 4];
            mx = new double[4, 4];
            my = new double[4, 4];
            mz = new double[4, 4];

            softness = 8;
        }
Exemple #19
0
 protected ModelBase()
 {
     mPtData            = null;
     mPtDataInMeshForm  = null;
     uFacesIndex        = null;
     mDbVertices        = null;
     mDbTextureCoors    = null;
     mSzTextureFilename = String.Empty;
     mSzOutputFilename  = String.Empty;
 }
        public static LinesVisual3D GenerateWireframe(Point3D[,] points)
        {
            var wireframe = new List <Point3D>();

            wireframe.AddRange(Task.Run(() => Wireframe1(points)).Result);
            wireframe.AddRange(Task.Run(() => Wireframe2(points)).Result);
            return(new LinesVisual3D()
            {
                Points = new Point3DCollection(wireframe)
            });
        }
Exemple #21
0
 private static Point3D[,] RemoveNoizes(Point3D[,] points)
 {
     for (var y = 0; y < points.GetLength(1); y++)
     {
         for (var x = 0; x < points.GetLength(0); x++)
         {
             var z = points[x, y].Z;
             points[x, y] = new Point3D(x, y, (z > 1200 || z < 700) ? 1200 : z);
         }
     }
     return(points);
 }
Exemple #22
0
        private Polyhedron BuildPolyhedronFromPoints(Point3D[,] points)
        {
            //TODO: build polyhedron from points
            var polyhedron = new Polyhedron();

            polyhedron.vertexes.Clear();
            foreach (var point in points)
            {
                polyhedron.vertexes.Add(point);
            }
            return(polyhedron);
        }
Exemple #23
0
 /* Longitude Line - φ is const. */
 private void BuildLongitudeLines(Point3D[,] points, int rows, int cols)
 {
     for (var φ = 0; φ < cols; φ += DencityFactor)
     {
         var lines = MakeLinesVisual3D();
         for (var θ = 0; θ < rows; ++θ)
         {
             lines.Points.Add(points[(θ + 0) % rows, φ]);
             lines.Points.Add(points[(θ + 1) % rows, φ]);
         }
         Children.Add(lines);
     }
 }
Exemple #24
0
 /* Latitude Line - θ is const. */
 private void BuildLatitudeLines(Point3D[,] points, int rows, int cols)
 {
     for (var θ = 0; θ < rows; θ += DencityFactor)
     {
         var lines = MakeLinesVisual3D();
         for (var φ = 0; φ < cols; ++φ)
         {
             lines.Points.Add(points[θ, (φ + 0) % cols]);
             lines.Points.Add(points[θ, (φ + 1) % cols]);
         }
         Children.Add(lines);
     }
 }
Exemple #25
0
        public BezierPatch(Point3D[,] controlPoints, int detalizationDegree)
        {
            this.controlPoints      = controlPoints;
            this.detalizationDegree = detalizationDegree;

            // Инициализируем матрицы функции изгиба
            // Для сплайнов Безье матрица изгиба при транспонировании дает себя же
            double[,] MArray = new double[4, 4] {
                { -1, 3, -3, 1 },
                { 3, -6, 3, 0 },
                { -3, 3, 0, 0 },
                { 1, 0, 0, 0 }
            };
            M  = new Matrix(MArray);
            Mt = new Matrix(MArray);
            Mt.Transpose();

            // Инициализируем матрицы для координат точек по координатам X, Y и Z
            double[,] PxArray = new double[4, 4]
            {
                { controlPoints[0, 0].X, controlPoints[0, 1].X, controlPoints[0, 2].X, controlPoints[0, 3].X },
                { controlPoints[1, 0].X, controlPoints[1, 1].X, controlPoints[1, 2].X, controlPoints[1, 3].X },
                { controlPoints[2, 0].X, controlPoints[2, 1].X, controlPoints[2, 2].X, controlPoints[2, 3].X },
                { controlPoints[3, 0].X, controlPoints[3, 1].X, controlPoints[3, 2].X, controlPoints[3, 3].X }
            };
            Px = new Matrix(PxArray);
            // По оси Y
            double[,] PyArray = new double[4, 4]
            {
                { controlPoints[0, 0].Y, controlPoints[0, 1].Y, controlPoints[0, 2].Y, controlPoints[0, 3].Y },
                { controlPoints[1, 0].Y, controlPoints[1, 1].Y, controlPoints[1, 2].Y, controlPoints[1, 3].Y },
                { controlPoints[2, 0].Y, controlPoints[2, 1].Y, controlPoints[2, 2].Y, controlPoints[2, 3].Y },
                { controlPoints[3, 0].Y, controlPoints[3, 1].Y, controlPoints[3, 2].Y, controlPoints[3, 3].Y }
            };
            Py = new Matrix(PyArray);
            // По оси Z
            double[,] PzArray = new double[4, 4]
            {
                { controlPoints[0, 0].Z, controlPoints[0, 1].Z, controlPoints[0, 2].Z, controlPoints[0, 3].Z },
                { controlPoints[1, 0].Z, controlPoints[1, 1].Z, controlPoints[1, 2].Z, controlPoints[1, 3].Z },
                { controlPoints[2, 0].Z, controlPoints[2, 1].Z, controlPoints[2, 2].Z, controlPoints[2, 3].Z },
                { controlPoints[3, 0].Z, controlPoints[3, 1].Z, controlPoints[3, 2].Z, controlPoints[3, 3].Z }
            };
            Pz = new Matrix(PzArray);

            fillPoints();
            fillAxis();
            this.currentPointList = sourcePointsList.ToList();
            updateEdges();
            updateFaces();
        }
Exemple #26
0
 private void Restart()
 {
     alfabeta          = new Point3D[N, N];
     axonom            = new Point3D[N, N];
     screen            = new Point[N, N];
     bmp               = new Bitmap(pictureBox2.Width, pictureBox2.Height);
     g                 = Graphics.FromImage(bmp);
     pictureBox2.Image = bmp;
     g.Clear(backgrColor);
     fillMatr3D();
     MatrixToAxon();
     fillScreenMatrix();
     Draw();
 }
Exemple #27
0
 private void Triangulation(PlaneMap pm)
 {
     Point3D[,] dots = GetPartition();
     for (int i = 0; i < nx - 1; ++i)
     {
         for (int j = 0; j < ny - 1; ++j)
         {
             this.AddPolygons(pm.Stretch(dots[i + 1, j + 1],
                                         dots[i + 1, j],
                                         dots[i, j],
                                         dots[i, j + 1]));
         }
     }
 }
 public ViewerReadyPlayerReforge(string name, GearResults gear, Point3D[,] mesh, double[,] meshTex, Brush brush, Model3DGroup lights, string xLabel, string yLabel, string zLabel, int total, int statcount)
 {
     this.PlayerName   = name;
     this.PlayerGear   = gear;
     this.PlayerMesh   = mesh;
     this.SurfaceBrush = brush;
     this.MeshColors   = meshTex;
     this.Lights       = lights;
     this.XAxis        = xLabel;
     this.YAxis        = yLabel;
     this.ZAxis        = zLabel;
     this.Total        = total;
     this.StatCount    = statcount;
 }
Exemple #29
0
 public static Point3d[,] ToPoint3d(this Point3D[,] pts)
 {
     if (!(pts == null))
     {
         var myPts = new Point3d[pts.GetLength(0), pts.GetLength(1)];
         for (int i = 0; i < pts.GetLength(0); i++)
         {
             for (int j = 0; j < pts.GetLength(1); j++)
             {
                 myPts[i, j] = pts[i, j].ToPoint3d();
             }
         }
         return(myPts);
     }
     return(null);
 }
Exemple #30
0
        private void ParseEdge(string edgeStr, int edgeNumber, Point3D[,] pointsList)
        {
            var pointsAndAdjacentVertexStr = edgeStr.Split('|').ToArray();

            for (int i = 0; i < pointsAndAdjacentVertexStr.Length; ++i)
            {
                pointsList[edgeNumber, i] = ParsePoint(pointsAndAdjacentVertexStr[i]);
                if (i > 0)
                {
                    pointsList[edgeNumber, i].AddNeighbour(pointsList[edgeNumber, i - 1]);
                    pointsList[edgeNumber, i - 1].AddNeighbour(pointsList[edgeNumber, i]);
                }
            }
            pointsList[edgeNumber, 0].AddNeighbour(pointsList[edgeNumber, pointsList.GetLength(1) - 1]);
            pointsList[edgeNumber, pointsList.GetLength(1) - 1].AddNeighbour(pointsList[edgeNumber, 0]);
        }
Exemple #31
0
        public void RefreshVectorWithBumb()
        {
            int width  = _bumpBitmap.Width < _vectorMapBitmap.Width ? _bumpBitmap.Width : _vectorMapBitmap.Width;
            int height = _bumpBitmap.Height < _vectorMapBitmap.Height ? _bumpBitmap.Height : _vectorMapBitmap.Height;

            _vectorMap = new Point3D[width, height];

            for (int i = 0; i < width - 1; i++)
            {
                for (int j = 0; j < height - 1; j++)
                {
                    var pixel      = _bumpBitmap.GetPixel(i, j);
                    var nextPixelX = _bumpBitmap.GetPixel(i + 1, j);
                    var nextPixelY = _bumpBitmap.GetPixel(i, j + 1);

                    double dhx = ((double)nextPixelX.R - pixel.R) * _bumpCoef;
                    double dhy = ((double)nextPixelY.R - pixel.R) * _bumpCoef;

                    var    vectorMapPixel = _vectorMapBitmap.GetPixel(i, j);
                    double nx             = vectorMapPixel.R / 127.5 - 1;
                    double ny             = vectorMapPixel.G / 127.5 - 1;
                    double nz             = vectorMapPixel.B / 127.5 - 1;

                    double Tx = 1;
                    double Ty = 0;
                    double Tz = -nx;

                    double Bx = 0;
                    double By = 1;
                    double Bz = -ny;

                    double Dx = Tx * dhx + Bx * dhy;
                    double Dy = Ty * dhx + By * dhy;
                    double Dz = Tz * dhx + Bz * dhy;

                    double Nx = nx + Dx;
                    double Ny = ny + Dy;
                    double Nz = nz + Dz;

                    double squareLen = Nx * Nx + Ny * Ny + Nz * Nz;
                    double sqrt      = Math.Sqrt(squareLen);
                    _vectorMap[i, j] = new Point3D(Nx / sqrt, Ny / sqrt, Nz / sqrt);
                }
            }
        }
Exemple #32
0
        /// <summary>
        /// Creates a mesh with a horizontal and vertical resolution indicated
        /// by the input parameters.  It will generate 
        /// (precisionU-1)*(precisionV-1) quads.
        /// </summary>
        public MeshGeometry3D CreateMesh( int precisionU, int precisionV )
        {
            lengthX = precisionU;
            lengthY = precisionV;
            du = ( uMax - uMin ) / (double)(precisionU-1);
            dv = ( vMax - vMin ) / (double)(precisionV-1);

            positions = new Point3D[ lengthX, lengthY ];
            normals = new Vector3D[ lengthX, lengthY ];
            textureCoords = new Point[ lengthX, lengthY ];
            indices = new ArrayList();

            double v = vMin;
            for ( int y = 0; y < lengthY; y++ )
            {
                double u = uMin;
                if ( y == lengthY-1 )
                {
                    v = vMax;
                }
                for ( int x = 0; x < lengthX; x++ )
                {
                    if ( x == lengthX-1 )
                    {
                        u = uMax;
                    }
                    VariableExpression.Define( "u", u );
                    VariableExpression.Define( "v", v );
                    positions[ x,y ] = Evaluate();
                    normals[ x,y ] = GetNormal( u,v );
                    u += du;
                }
                v += dv;
            }
            VariableExpression.Undefine( "u" );
            VariableExpression.Undefine( "v" );

            SetTextureCoordinates();
            SetIndices();

            MeshGeometry3D mesh = new MeshGeometry3D();
            for ( int y = 0; y < lengthY; y++ )
            {
                for ( int x = 0; x < lengthX; x++ )
                {
                    mesh.Positions.Add( positions[ x,y ] );
                    mesh.Normals.Add( normals[ x,y ] );
                    mesh.TextureCoordinates.Add( textureCoords[ x,y ] );
                }
            }
            mesh.TriangleIndices = new Int32Collection();
            foreach (int index in indices)
                mesh.TriangleIndices.Add(index);

            return mesh;
        }
Exemple #33
0
        /// <summary>
        ///     Creates a mesh with a horizontal and vertical resolution indicated
        ///     by the input parameters.  It will generate
        ///     (precisionU-1)*(precisionV-1) quads.
        /// </summary>
        public MeshGeometry3D CreateMesh(int precisionU, int precisionV)
        {
            _lengthX = precisionU;
            _lengthY = precisionV;
            _du = (UMax - UMin)/(precisionU - 1);
            _dv = (VMax - VMin)/(precisionV - 1);

            _positions = new Point3D[_lengthX, _lengthY];
            _normals = new Vector3D[_lengthX, _lengthY];
            _textureCoords = new Point[_lengthX, _lengthY];
            _indices = new ArrayList();

            var v = VMin;
            for (var y = 0; y < _lengthY; y++)
            {
                var u = UMin;
                if (y == _lengthY - 1)
                {
                    v = VMax;
                }
                for (var x = 0; x < _lengthX; x++)
                {
                    if (x == _lengthX - 1)
                    {
                        u = UMax;
                    }
                    VariableExpression.Define("u", u);
                    VariableExpression.Define("v", v);
                    _positions[x, y] = Evaluate();
                    _normals[x, y] = GetNormal(u, v);
                    u += _du;
                }
                v += _dv;
            }
            VariableExpression.Undefine("u");
            VariableExpression.Undefine("v");

            SetTextureCoordinates();
            SetIndices();

            var mesh = new MeshGeometry3D();
            for (var y = 0; y < _lengthY; y++)
            {
                for (var x = 0; x < _lengthX; x++)
                {
                    mesh.Positions.Add(_positions[x, y]);
                    mesh.Normals.Add(_normals[x, y]);
                    mesh.TextureCoordinates.Add(_textureCoords[x, y]);
                }
            }
            mesh.TriangleIndices = new Int32Collection();
            foreach (int index in _indices)
                mesh.TriangleIndices.Add(index);

            return mesh;
        }
        /// <summary>
        /// Creates a mesh with a horizontal and vertical resolution indicated
        /// by the input parameters.  It will generate 
        /// (precisionU-1)*(precisionV-1) quads.
        /// </summary>
        public Model3DGroup CreateWireframeModel( int precisionU, int precisionV )
        {
            lengthX = precisionU;
            lengthY = precisionV;
            du = ( uMax - uMin ) / (double)(precisionU-1);
            dv = ( vMax - vMin ) / (double)(precisionV-1);

            positions = new Point3D[ lengthX, lengthY ];

            double v = vMin;
            for ( int y = 0; y < lengthY; y++ )
            {
                double u = uMin;
                if ( y == lengthY-1 )
                {
                    v = vMax;
                }
                for ( int x = 0; x < lengthX; x++ )
                {
                    if ( x == lengthX-1 )
                    {
                        u = uMax;
                    }
                    VariableExpression.Define( "u", u );
                    VariableExpression.Define( "v", v );
                    positions[ x,y ] = Evaluate();
                    u += du;
                }
                v += dv;
            }
            VariableExpression.Undefine( "u" );
            VariableExpression.Undefine( "v" );

            Model3DGroup group = new Model3DGroup();

            // TODO: Remove
            //ScreenSpaceLines3D lines;
            /*
            // Create Horizontal lines
            for ( int y = 0; y < lengthY; y++ )
            {
                lines = new ScreenSpaceLines3D();
                lines.Color = Colors.Black;
                lines.Thickness = 1;
                for ( int x = 0; x < lengthX; x++ )
                {
                    lines.Points.Add( positions[ x,y ] );
                }
                group.Children.Add( lines );
            }

            // Create Vertical lines
            for ( int x = 0; x < lengthX; x++ )
            {
                lines = new ScreenSpaceLines3D();
                lines.Color = Colors.Black;
                lines.Thickness = 1;
                for ( int y = 0; y < lengthY; y++ )
                {
                    lines.Points.Add( positions[ x,y ] );
                }
                group.Children.Add( lines );
            }
            */

            return group;
        }
        /// <summary>
        ///     Creates a mesh with a horizontal and vertical resolution indicated
        ///     by the input parameters.  It will generate
        ///     (precisionU-1)*(precisionV-1) quads.
        /// </summary>
        public Model3DGroup CreateWireframeModel(int precisionU, int precisionV)
        {
            _lengthX = precisionU;
            _lengthY = precisionV;
            _du = (UMax - UMin)/(precisionU - 1);
            _dv = (VMax - VMin)/(precisionV - 1);

            _positions = new Point3D[_lengthX, _lengthY];

            var v = VMin;
            for (var y = 0; y < _lengthY; y++)
            {
                var u = UMin;
                if (y == _lengthY - 1)
                {
                    v = VMax;
                }
                for (var x = 0; x < _lengthX; x++)
                {
                    if (x == _lengthX - 1)
                    {
                        u = UMax;
                    }
                    VariableExpression.Define("u", u);
                    VariableExpression.Define("v", v);
                    _positions[x, y] = Evaluate();
                    u += _du;
                }
                v += _dv;
            }
            VariableExpression.Undefine("u");
            VariableExpression.Undefine("v");

            var group = new Model3DGroup();

            // TODO: Remove
            //ScreenSpaceLines3D lines;
            /*
            // Create Horizontal lines
            for ( int y = 0; y < lengthY; y++ )
            {
                lines = new ScreenSpaceLines3D();
                lines.Color = Colors.Black;
                lines.Thickness = 1;
                for ( int x = 0; x < lengthX; x++ )
                {
                    lines.Points.Add( positions[ x,y ] );
                }
                group.Children.Add( lines );
            }

            // Create Vertical lines
            for ( int x = 0; x < lengthX; x++ )
            {
                lines = new ScreenSpaceLines3D();
                lines.Color = Colors.Black;
                lines.Thickness = 1;
                for ( int y = 0; y < lengthY; y++ )
                {
                    lines.Points.Add( positions[ x,y ] );
                }
                group.Children.Add( lines );
            }
            */

            return group;
        }