Пример #1
0
        private void btnConstructMultiTriMesh_Click(object sender, EventArgs e)
        {
            try
            {
                if (gfactory == null)
                    gfactory = new GeometryFactory();
                multiTriMesh = gfactory.CreateGeometry(gviGeometryType.gviGeometryMultiTrimesh, gviVertexAttribute.gviVertexAttributeZ) as IMultiTriMesh;
                if (multiTriMesh == null)
                    return;

                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));
                }
                triMesh.AddTriangle(vertices[0] as ITopoNode, vertices[1] as ITopoNode, vertices[2] as ITopoNode);
                triMesh.AddTriangle(vertices[2] as ITopoNode, vertices[1] as ITopoNode, vertices[3] as ITopoNode);
                triMesh.AddTriangle(vertices[3] as ITopoNode, vertices[1] as ITopoNode, vertices[4] as ITopoNode);
                triMesh.AddTriangle(vertices[3] as ITopoNode, vertices[4] as ITopoNode, vertices[5] as ITopoNode);
                triMesh.AddTriangle(vertices[5] as ITopoNode, vertices[4] as ITopoNode, vertices[6] as ITopoNode);
                triMesh.AddTriangle(vertices[5] as ITopoNode, vertices[6] as ITopoNode, vertices[7] as ITopoNode);
                triMesh.AddTriangle(vertices[7] as ITopoNode, vertices[6] as ITopoNode, vertices[8] as ITopoNode);
                triMesh.AddTriangle(vertices[7] as ITopoNode, vertices[8] as ITopoNode, vertices[9] as ITopoNode);
                triMesh.AddTriangle(vertices[7] as ITopoNode, vertices[9] as ITopoNode, vertices[10] as ITopoNode);
                triMesh.AddTriangle(vertices[10] as ITopoNode, vertices[9] as ITopoNode, vertices[11] as ITopoNode);
                triMesh.AddTriangle(vertices[10] as ITopoNode, vertices[11] as ITopoNode, vertices[12] as ITopoNode);
                triMesh.AddTriangle(vertices[13] as ITopoNode, vertices[10] as ITopoNode, vertices[12] as ITopoNode);
                triMesh.AddTriangle(vertices[13] as ITopoNode, vertices[14] as ITopoNode, vertices[10] as ITopoNode);
                triMesh.AddTriangle(vertices[13] as ITopoNode, vertices[15] as ITopoNode, vertices[14] as ITopoNode);
                triMesh.AddTriangle(vertices[15] as ITopoNode, vertices[16] as ITopoNode, vertices[14] as ITopoNode);
                triMesh.AddTriangle(vertices[16] as ITopoNode, vertices[5] as ITopoNode, vertices[14] as ITopoNode);
                triMesh.AddTriangle(vertices[3] as ITopoNode, vertices[5] as ITopoNode, vertices[16] as ITopoNode);
                triMesh.AddTriangle(vertices[2] as ITopoNode, vertices[3] as ITopoNode, vertices[16] as ITopoNode);

                multiTriMesh.AddGeometry(triMesh);

                MultiSurface geo = new MultiSurface();
                // Geometry属性
                geo.Dimension = multiTriMesh.Dimension;
                if (multiTriMesh.Envelope != null)
                {
                    geo.MaxX = multiTriMesh.Envelope.MaxX;
                    geo.MaxY = multiTriMesh.Envelope.MaxY;
                    geo.MaxZ = multiTriMesh.Envelope.MaxZ;
                    geo.MinX = multiTriMesh.Envelope.MinX;
                    geo.MinY = multiTriMesh.Envelope.MinY;
                    geo.MinZ = multiTriMesh.Envelope.MinZ;
                }
                geo.GeometryType = multiTriMesh.GeometryType;
                geo.IsEmpty = multiTriMesh.IsEmpty;
                geo.IsValid = multiTriMesh.IsValid;
                geo.VertexAttribute = multiTriMesh.VertexAttribute;
                geo.HasId = multiTriMesh.HasId();
                geo.HasM = multiTriMesh.HasM();
                geo.HasZ = multiTriMesh.HasZ();
                // GeometryCollection属性
                geo.GeometryCount = multiTriMesh.GeometryCount;
                geo.IsOverlap = multiTriMesh.IsOverlap;
                // MultiSurface属性
                geo.Area = multiTriMesh.GetArea();

                this.propertyGrid1.SelectedObject = geo;
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
        }
Пример #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;
        }