Exemplo n.º 1
0
        private void btnConstructClosedTriMesh_Click(object sender, EventArgs e)
        {
            if (gfactory == null)
                gfactory = new GeometryFactory();
            closedTriMesh = gfactory.CreateGeometry(gviGeometryType.gviGeometryClosedTriMesh, gviVertexAttribute.gviVertexAttributeZ) as IClosedTriMesh;
            if (closedTriMesh == null)
                return;

            string tmpFile = (strMediaPath + @"\off");
            if (File.Exists(String.Format("{0}\\oblong.off", tmpFile)))
            {
                StreamReader sr = new StreamReader(String.Format("{0}\\oblong.off", tmpFile));
                sr.ReadLine();
                string countParameter = sr.ReadLine();  //点数 面数
                string[] countParameters = countParameter.Split(' ');
                int nPointsCount = int.Parse(countParameters[0]);
                int nFacetsCount = int.Parse(countParameters[1]);
                if (nPointsCount == 0 && nFacetsCount == 0)
                {
                    sr.Close();
                    return;
                }

                sr.ReadLine();

                ArrayList vertices = new ArrayList();  //ITopoNode数组
                point = gfactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                for (int i = 0; i < nPointsCount; ++i)
                {
                    string[] pointCoords = sr.ReadLine().Split(' ');
                    double dx = double.Parse(pointCoords[0]);
                    double dy = double.Parse(pointCoords[1]);
                    double dz = double.Parse(pointCoords[2]);
                    point.SetCoords(dx, dy, dz, 0, 0);
                    vertices.Add(closedTriMesh.AddPoint(point));
                }

                ArrayList facets = new ArrayList();  //ITopoFacet数组
                for (int j = 0; j < nFacetsCount; ++j)
                {
                    string[] facetParas = sr.ReadLine().Split(' ');
                    int nFirst = int.Parse(facetParas[1]);
                    int nSecond = int.Parse(facetParas[2]);
                    int nThird = int.Parse(facetParas[3]);
                    facets.Add(closedTriMesh.AddTriangle(vertices[nFirst] as ITopoNode, vertices[nSecond] as ITopoNode, vertices[nThird] as ITopoNode));
                }

                sr.Close();
            }

            TriMesh geo = new TriMesh();
            // Geometry属性
            geo.Dimension = closedTriMesh.Dimension;
            if (closedTriMesh.Envelope != null)
            {
                geo.MaxX = closedTriMesh.Envelope.MaxX;
                geo.MaxY = closedTriMesh.Envelope.MaxY;
                geo.MaxZ = closedTriMesh.Envelope.MaxZ;
                geo.MinX = closedTriMesh.Envelope.MinX;
                geo.MinY = closedTriMesh.Envelope.MinY;
                geo.MinZ = closedTriMesh.Envelope.MinZ;
            }
            geo.GeometryType = closedTriMesh.GeometryType;
            geo.IsEmpty = closedTriMesh.IsEmpty;
            geo.IsValid = closedTriMesh.IsValid;
            geo.VertexAttribute = closedTriMesh.VertexAttribute;
            geo.HasId = closedTriMesh.HasId();
            geo.HasM = closedTriMesh.HasM();
            geo.HasZ = closedTriMesh.HasZ();
            // Surface属性
            if (closedTriMesh.Centroid != null)
            {
                geo.CentroidX = closedTriMesh.Centroid.X;
                geo.CentroidY = closedTriMesh.Centroid.Y;
                geo.CentroidZ = closedTriMesh.Centroid.Z;
            }
            geo.IsClosed = closedTriMesh.IsClosed;
            if (closedTriMesh.PointOnSurface != null)
            {
                geo.PointOnSurfaceX = closedTriMesh.PointOnSurface.X;
                geo.PointOnSurfaceY = closedTriMesh.PointOnSurface.Y;
                geo.PointOnSurfaceZ = closedTriMesh.PointOnSurface.Z;
            }
            // TriMesh属性
            geo.DirectedEdgeCount = closedTriMesh.DirectedEdgeCount;
            geo.FacetCount = closedTriMesh.FacetCount;
            geo.VertexCount = closedTriMesh.VertexCount;

            this.propertyGrid1.SelectedObject = geo;
        }
Exemplo n.º 2
0
        private void btnConstructTriMesh_Click(object sender, EventArgs e)
        {
            if (gfactory == null)
                gfactory = new GeometryFactory();
            triMesh = gfactory.CreateGeometry(gviGeometryType.gviGeometryTriMesh, gviVertexAttribute.gviVertexAttributeZ) as ITriMesh;
            if (triMesh == null)
                return;

            ArrayList vertices = new ArrayList();  //ITopoNode数组
            point = gfactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
            for (int i = 0; i < 17; ++i)
            {
                point.SetCoords(i, i, i, 0, 0);
                vertices.Add(triMesh.AddPoint(point));
            }

            point.SetCoords(100, 100, 100, 0, 0);
            triMesh.AddPoint(point);

            ArrayList facets = new ArrayList();  //ITopoFacet数组
            facets.Add(triMesh.AddTriangle(vertices[0] as ITopoNode, vertices[1] as ITopoNode, vertices[2] as ITopoNode));
            facets.Add(triMesh.AddTriangle(vertices[2] as ITopoNode, vertices[1] as ITopoNode, vertices[3] as ITopoNode));
            facets.Add(triMesh.AddTriangle(vertices[3] as ITopoNode, vertices[1] as ITopoNode, vertices[4] as ITopoNode));
            facets.Add(triMesh.AddTriangle(vertices[3] as ITopoNode, vertices[4] as ITopoNode, vertices[5] as ITopoNode));
            facets.Add(triMesh.AddTriangle(vertices[5] as ITopoNode, vertices[4] as ITopoNode, vertices[6] as ITopoNode));
            facets.Add(triMesh.AddTriangle(vertices[5] as ITopoNode, vertices[6] as ITopoNode, vertices[7] as ITopoNode));
            facets.Add(triMesh.AddTriangle(vertices[7] as ITopoNode, vertices[6] as ITopoNode, vertices[8] as ITopoNode));
            facets.Add(triMesh.AddTriangle(vertices[7] as ITopoNode, vertices[8] as ITopoNode, vertices[9] as ITopoNode));
            facets.Add(triMesh.AddTriangle(vertices[7] as ITopoNode, vertices[9] as ITopoNode, vertices[10] as ITopoNode));
            facets.Add(triMesh.AddTriangle(vertices[10] as ITopoNode, vertices[9] as ITopoNode, vertices[11] as ITopoNode));
            facets.Add(triMesh.AddTriangle(vertices[10] as ITopoNode, vertices[11] as ITopoNode, vertices[12] as ITopoNode));
            facets.Add(triMesh.AddTriangle(vertices[13] as ITopoNode, vertices[10] as ITopoNode, vertices[12] as ITopoNode));
            facets.Add(triMesh.AddTriangle(vertices[13] as ITopoNode, vertices[14] as ITopoNode, vertices[10] as ITopoNode));
            facets.Add(triMesh.AddTriangle(vertices[13] as ITopoNode, vertices[15] as ITopoNode, vertices[14] as ITopoNode));
            facets.Add(triMesh.AddTriangle(vertices[15] as ITopoNode, vertices[16] as ITopoNode, vertices[14] as ITopoNode));
            facets.Add(triMesh.AddTriangle(vertices[16] as ITopoNode, vertices[5] as ITopoNode, vertices[14] as ITopoNode));
            facets.Add(triMesh.AddTriangle(vertices[3] as ITopoNode, vertices[5] as ITopoNode, vertices[16] as ITopoNode));
            facets.Add(triMesh.AddTriangle(vertices[2] as ITopoNode, vertices[3] as ITopoNode, vertices[16] as ITopoNode));

            TriMesh geo = new TriMesh();
            // Geometry属性
            geo.Dimension = triMesh.Dimension;
            if (triMesh.Envelope != null)
            {
                geo.MaxX = triMesh.Envelope.MaxX;
                geo.MaxY = triMesh.Envelope.MaxY;
                geo.MaxZ = triMesh.Envelope.MaxZ;
                geo.MinX = triMesh.Envelope.MinX;
                geo.MinY = triMesh.Envelope.MinY;
                geo.MinZ = triMesh.Envelope.MinZ;
            }
            geo.GeometryType = triMesh.GeometryType;
            geo.IsEmpty = triMesh.IsEmpty;
            geo.IsValid = triMesh.IsValid;
            geo.VertexAttribute = triMesh.VertexAttribute;
            geo.HasId = triMesh.HasId();
            geo.HasM = triMesh.HasM();
            geo.HasZ = triMesh.HasZ();
            // Surface属性
            if (triMesh.Centroid != null)
            {
                geo.CentroidX = triMesh.Centroid.X;
                geo.CentroidY = triMesh.Centroid.Y;
                geo.CentroidZ = triMesh.Centroid.Z;
            }
            geo.IsClosed = triMesh.IsClosed;
            if (triMesh.PointOnSurface != null)
            {
                geo.PointOnSurfaceX = triMesh.PointOnSurface.X;
                geo.PointOnSurfaceY = triMesh.PointOnSurface.Y;
                geo.PointOnSurfaceZ = triMesh.PointOnSurface.Z;
            }
            // TriMesh属性
            geo.DirectedEdgeCount = triMesh.DirectedEdgeCount;
            geo.FacetCount = triMesh.FacetCount;
            geo.VertexCount = triMesh.VertexCount;

            this.propertyGrid1.SelectedObject = geo;
        }