コード例 #1
0
ファイル: MainForm.cs プロジェクト: batuZ/Samples
        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
ファイル: MainForm.cs プロジェクト: batuZ/Samples
        private void btnConstructMultiPolygon_Click(object sender, EventArgs e)
        {
            if (gfactory == null)
                gfactory = new GeometryFactory();
            multiPolygon = gfactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon;
            if (multiPolygon == null)
                return;

            //添加第一个polygon
            IPolygon polygonFirst = gfactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
            if (polygonFirst == null)
                return;
            /// 外环顺时针:1-4-3-2-1
            ///  4-------3
            ///  |       |
            ///  |       |
            ///  1-------2
            IRing exteriorRing = polygonFirst.ExteriorRing;
            point = gfactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
            point.SetCoords(0, 0, 0, 0, 1);
            exteriorRing.AppendPoint(point);
            point.SetCoords(0, 200, 0, 0, 2);
            exteriorRing.AppendPoint(point);
            point.SetCoords(100, 200, 0, 0, 3);
            exteriorRing.AppendPoint(point);           
            point.SetCoords(100, 0, 0, 0, 4);
            exteriorRing.AppendPoint(point);
            point.SetCoords(0, 0, 0, 0, 5);
            exteriorRing.AppendPoint(point);  //闭合
            /// 内环逆时针:1-2-3-4-1
            ///  4-------3
            ///  |       |
            ///  |       |
            ///  1-------2
            IRing interiorRing = gfactory.CreateGeometry(gviGeometryType.gviGeometryRing, gviVertexAttribute.gviVertexAttributeZ) as IRing;
            point.SetCoords(25, 25, 0, 0, 1);
            interiorRing.AppendPoint(point);
            point.SetCoords(75, 25, 0, 0, 2);
            interiorRing.AppendPoint(point);
            point.SetCoords(75, 75, 0, 0, 3);
            interiorRing.AppendPoint(point);
            point.SetCoords(25, 75, 0, 0, 4);
            interiorRing.AppendPoint(point);
            point.SetCoords(25, 25, 0, 0, 5);
            interiorRing.AppendPoint(point);  //闭合
            polygonFirst.AddInteriorRing(interiorRing);

            //Clone一个新的内环
            IRing pInteriorRingNew = interiorRing.Clone() as IRing;
            polygonFirst.AddInteriorRing(pInteriorRingNew);
            multiPolygon.AddPolygon(polygonFirst);

            //Clone一个新的polygon
            IPolygon pPolygonNew = polygonFirst.Clone() as IPolygon;
            multiPolygon.AddPolygon(pPolygonNew);

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

            this.propertyGrid1.SelectedObject = geo;
        }