Ejemplo n.º 1
0
        public static CylinderVisual3DModel Closed2DAreaToCylinderVisual3DModel(List <Point> featurePoints, double upperZValue, double lowerZValue)
        {
            CylinderVisual3DModel cylinderVisual3D = new CylinderVisual3DModel();
            Rect            rect       = FeaturePointHelper.GetFeaturePointsBoundaryRect(featurePoints);
            List <Vertex2D> vertexList = new List <Vertex2D>();

            for (int i = 0; i < featurePoints.Count; i++)
            {
                Vertex2D vertex = new Vertex2D(featurePoints[i])
                {
                    Index = i
                };
                vertexList.Add(vertex);
            }
            bool isCw = PolygonTriangulationHelper.IsClockwise(vertexList);

            if (!isCw)
            {
                featurePoints.Reverse();
            }
            //List<int> trianglePointIndexList = PolygonTriangulationHelper.ResolveToTriangles(vertexList);
            List <Vec> vecList = new List <Vec>();

            for (int i = 0; i < featurePoints.Count; i++)
            {
                Vec vec = new Vec {
                    x = (float)featurePoints[i].X, y = (float)featurePoints[i].Y
                };
                vecList.Add(vec);
            }

            List <int> trianglePointIndexList = PolygonHelper.Resolve(vecList);

            if (trianglePointIndexList == null)
            {
                return(null);
            }

            List <int> lowerUnderSurfacePointIndexList = new List <int>();

            for (int i = 0; i < trianglePointIndexList.Count; i = i + 3)
            {
                lowerUnderSurfacePointIndexList.Add(trianglePointIndexList[i]);
                lowerUnderSurfacePointIndexList.Add(trianglePointIndexList[i + 2]);
                lowerUnderSurfacePointIndexList.Add(trianglePointIndexList[i + 1]);
            }

            Geometry3DModel upperGeometry3DModel = FeaturePointsToGeometry3DModel(featurePoints, upperZValue, rect, lowerUnderSurfacePointIndexList);

            cylinderVisual3D.UpperUndersurface = upperGeometry3DModel;

            Geometry3DModel lowerGeometry3DModel = FeaturePointsToGeometry3DModel(featurePoints, lowerZValue, rect, trianglePointIndexList);

            cylinderVisual3D.LowerUndersurface = lowerGeometry3DModel;

            cylinderVisual3D.SideSurface = FeaturePointsToSideSurefaceGeometry3DModel(featurePoints, upperZValue, lowerZValue);
            return(cylinderVisual3D);
        }
Ejemplo n.º 2
0
        private static Geometry3DModel FeaturePointsToGeometry3DModel(IList <Point> featurePoints, double zValue, Rect rect, List <int> trianglePointIndexList)
        {
            Geometry3DModel geometry3DModel = new Geometry3DModel();

            geometry3DModel.TriangleIndices.AddRange(trianglePointIndexList);

            List <Point3D> point3DList = ClosedPathPointsToPoint3Ds(featurePoints, zValue);

            foreach (Point3D point3D in point3DList)
            {
                geometry3DModel.Positions.Add(point3D);

                double textureCoordinateX = (point3D.X - rect.X) / rect.Width;
                double textureCoordinateY = (point3D.Y - rect.Y) / rect.Height;

                Point point = new Point(textureCoordinateX, textureCoordinateY);
                geometry3DModel.TextureCoordinates.Add(point);
            }

            return(geometry3DModel);
        }
Ejemplo n.º 3
0
        private static Geometry3DModel FeaturePointsToSideSurefaceGeometry3DModel(IList <Point> featurePoints, double upperZValue, double lowerZValue)
        {
            if (featurePoints == null || featurePoints.Count < 3)
            {
                throw new Exception("The count of closed path points must large than or equal to 3.");
            }

            Geometry3DModel geometry3DModel = new Geometry3DModel();
            List <Point3D>  point3DList     = ClosedAreaFeaturePointsToSideSurfacePoint3Ds(featurePoints, upperZValue, lowerZValue);

            for (int i = 0; i < point3DList.Count; i++)
            {
                geometry3DModel.Positions.Add(point3DList[i]);
                geometry3DModel.TextureCoordinates.Add(new Point(i / 2.0 / point3DList.Count, i % 2.0 / point3DList.Count));
            }

            for (int i = 0; i < geometry3DModel.Positions.Count / 2 - 1; i++)
            {
                int startIndex = i * 2;
                geometry3DModel.TriangleIndices.Add(startIndex);
                geometry3DModel.TriangleIndices.Add(startIndex + 1);
                geometry3DModel.TriangleIndices.Add(startIndex + 3);

                geometry3DModel.TriangleIndices.Add(startIndex);
                geometry3DModel.TriangleIndices.Add(startIndex + 3);
                geometry3DModel.TriangleIndices.Add(startIndex + 2);
            }

            //连接首尾
            geometry3DModel.TriangleIndices.Add(geometry3DModel.Positions.Count - 2);
            geometry3DModel.TriangleIndices.Add(geometry3DModel.Positions.Count - 1);
            geometry3DModel.TriangleIndices.Add(1);

            geometry3DModel.TriangleIndices.Add(geometry3DModel.Positions.Count - 2);
            geometry3DModel.TriangleIndices.Add(1);
            geometry3DModel.TriangleIndices.Add(0);

            return(geometry3DModel);
        }
Ejemplo n.º 4
0
        public static MeshGeometry3D CreateGeometry3D(Geometry3DModel geometry3DModel)
        {
            MeshGeometry3D mesh = new MeshGeometry3D();

            if (geometry3DModel == null)
            {
                return(mesh);
            }

            if (geometry3DModel.Positions != null)
            {
                foreach (Point3D point3D in geometry3DModel.Positions)
                {
                    mesh.Positions.Add(point3D);
                }
            }

            if (geometry3DModel.TriangleIndices != null)
            {
                foreach (int pointIndice in geometry3DModel.TriangleIndices)
                {
                    mesh.TriangleIndices.Add(pointIndice);
                }
            }

            if (geometry3DModel.TextureCoordinates != null)
            {
                foreach (Point point in geometry3DModel.TextureCoordinates)
                {
                    mesh.TextureCoordinates.Add(point);
                }
            }

            mesh.Freeze();
            return(mesh);
        }