Пример #1
0
        private void displayVertex(TinSurfaceVertex vertex)
        {
            string msg = String.Format("\nVertex: ({0},{1},{2})",
                                       vertex.Location.X, vertex.Location.Y, vertex.Location.Z);

            write(msg);
        }
Пример #2
0
 /// <summary>
 /// Получить номер вершины в треугольнике
 /// </summary>
 /// <param name="vertex"></param>
 /// <returns></returns>
 private short GetVertNum(TinSurfaceVertex vertex)
 {
     if (vertex.Equals(tinSurfaceTriangle.Vertex1))
     {
         return(0);
     }
     else if (vertex.Equals(tinSurfaceTriangle.Vertex2))
     {
         return(1);
     }
     else if (vertex.Equals(tinSurfaceTriangle.Vertex3))
     {
         return(2);
     }
     return(-1);
 }
        public static void FindWaterBowlsByVertex()
        {
            CivilDocument civilDoc = CivilApplication.ActiveDocument;
            Document      doc      = Application.DocumentManager.MdiActiveDocument;
            Database      db       = doc.Database;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                BlockTableRecord   modelSpace = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                ObjectIdCollection surfaceIds = civilDoc.GetSurfaceIds();
                foreach (ObjectId surfaceId in surfaceIds)
                {
                    TinSurface surf = trans.GetObject(surfaceId, OpenMode.ForRead) as TinSurface;
                    if (surf == null)
                    {
                        continue;
                    }

                    foreach (TinSurfaceVertex vertex in surf.Vertices)
                    {
                        // start assuming is a low point
                        bool isLowest = true;
                        // now look at the other end of each Edge from the vertex
                        foreach (TinSurfaceEdge edge in vertex.Edges)
                        {
                            TinSurfaceVertex otherVertice = (edge.Vertex1.Location.DistanceTo(vertex.Location) < Tolerance.Global.EqualPoint ? edge.Vertex2 : edge.Vertex1);
                            // is the other vertice lower?
                            if (otherVertice.Location.Z < vertex.Location.Z)
                            {
                                isLowest = false; // other is lower, therefore this is not the lowest
                            }
                        }

                        // if is the lowest, add a point there
                        if (isLowest)
                        {
                            DBPoint newPoint = new DBPoint();
                            newPoint.Position = vertex.Location;
                            modelSpace.AppendEntity(newPoint);
                            trans.AddNewlyCreatedDBObject(newPoint, true);
                        }
                    }
                }
                trans.Commit();
            }
        }
Пример #4
0
        public static List <Acad.Vector3d> GetOffsetPoints(TinSurfaceVertex vert, double offset)
        {
            var points = new List <Acad.Vector3d>();

            try
            {
                var sum  = new SummationsAcad();
                var sumv = new SummationsAcad();

                Acad.Vector3d centerOfPlane = new Acad.Vector3d();
                Acad.Vector3d centerv1      = new Acad.Vector3d();
                Acad.Vector3d centerv2      = new Acad.Vector3d();
                Acad.Vector3d centerv3      = new Acad.Vector3d();

                // central connection point

                var location = vert.Location;

                var cenpoint = MathNet.Numerics.LinearAlgebra.Vector <double> .Build.DenseOfArray(new[] { location.X, location.Y, location.Z });

                var cenpointp3d = new Acad.Point3d(cenpoint[0], cenpoint[1], cenpoint[2]);

                // all the connecting Triangles

                var triangles = vert.Triangles;


                // all the connecting vertices's

                var connectedvertices  = vert.Vertices;
                var connectedTriangles = vert.Triangles;

                foreach (var tri in connectedTriangles)
                {
                    var v1 = tri.Vertex1.Location;
                    var v2 = tri.Vertex2.Location;
                    var v3 = tri.Vertex3.Location;


                    var vec1 = v1.GetVectorTo(v2);
                    var vec2 = v1.GetVectorTo(v3);

                    var norm = vec1.CrossProduct(vec2);
                    var e1   = UnitVector3D(vec1);
                    var e2   = UnitVector3D(vec2);

                    centerOfPlane = FindTriangleCenter(v1, v2, v3, vec1.CrossProduct(vec2));

                    //create 3 more points on the plane

                    centerv1 = new Acad.Vector3d(cenpointp3d.X + v1.X, cenpointp3d.Y + v1.Y, cenpointp3d.Z + v1.Z) / 2.0;
                    centerv2 = new Acad.Vector3d(cenpointp3d.X + v2.X, cenpointp3d.Y + v2.Y, cenpointp3d.Z + v2.Z) / 2.0;
                    centerv3 = new Acad.Vector3d(cenpointp3d.X + v3.X, cenpointp3d.Y + v3.Y, cenpointp3d.Z + v3.Z) / 2.0;


                    sum = IterateAdjacentTrianglesAcad(connectedTriangles, cenpointp3d);
                }

                //Triangle Center Points

                var M = (new Acad.Vector3d(sum.Top.X, sum.Top.Y, sum.Top.Z) / (Magnitude(new Acad.Vector3d(sum.Bot.X, sum.Bot.Y, sum.Bot.Z)))) * offset;

                var offsetvecCenter = (centerOfPlane.Add(M));
                var offsetcenterv1  = (centerv1.Add(M));
                var offsetcenterv2  = (centerv2.Add(M));
                var offsetcenterv3  = (centerv3.Add(M));

                points.Add(offsetvecCenter);
                points.Add(offsetcenterv1);
                points.Add(offsetcenterv2);
                points.Add(offsetcenterv3);
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine("Error: " + ex.Message);
            }

            return(points.ToList());
        }
Пример #5
0
 public Triangle(TinSurfaceVertex vertex1, TinSurfaceVertex vertex2, TinSurfaceVertex vertex3)
 {
     V1 = new Vector3d(vertex1.Location.X, vertex1.Location.Y, vertex1.Location.Z);
     V2 = new Vector3d(vertex2.Location.X, vertex2.Location.Y, vertex2.Location.Z);
     V3 = new Vector3d(vertex3.Location.X, vertex3.Location.Y, vertex3.Location.Z);
 }
Пример #6
0
        public static IEnumerable <Vector <double> > OldGetOffsetPoints(TinSurfaceVertex vert, double offset)
        {
            var points = new List <Vector <double> >();

            try
            {
                var sum  = new Summations();
                var sumv = new Summations();

                Vector <double> centerOfPlane = null;
                Vector <double> centerv1      = null;
                Vector <double> centerv2      = null;
                Vector <double> centerv3      = null;
                // central connection point

                var location = vert.Location;

                var cenpoint = MathNet.Numerics.LinearAlgebra.Vector <double> .Build.DenseOfArray(new [] { location.X, location.Y, location.Z });

                // all the connecting Triangles

                var triangles = vert.Triangles;

                // all the connecting vertices

                var convertices = vert.Vertices;

                foreach (var tri in triangles)
                {
                    var v1 = tri.Vertex1.Location;
                    var v2 = tri.Vertex2.Location;
                    var v3 = tri.Vertex3.Location;

                    var p1 = Vector <double> .Build.DenseOfArray(new[] { v1.X, v1.Y, v1.Z });

                    var p2 = Vector <double> .Build.DenseOfArray(new[] { v2.X, v2.Y, v2.Z });

                    var p3 = Vector <double> .Build.DenseOfArray(new[] { v3.X, v3.Y, v3.Z });

                    centerOfPlane = FindTriangleCenter(p1, p2, p3, Cross(p1, p2));
                    centerv1      = (cenpoint + p1) / 2.0;
                    centerv2      = (cenpoint + p2) / 2.0;
                    centerv3      = (cenpoint + p3) / 2.0;

                    //Convert Formatting

                    var NodeTriangles1 = new List <Triangle>();


                    foreach (var triVertex in triangles)
                    {
                        NodeTriangles1.Add(new Triangle(triVertex.Vertex1, triVertex.Vertex2, triVertex.Vertex3));
                    }


                    //Triangle Center Points

                    sum = IterateAdjacentTriangles(NodeTriangles1, cenpoint);

                    //Triangle shared at vertex 1, 2, and 3

                    //sumv = IterateVertexTriangles(NodeTriangles1, p1);
                    //sumv = IterateVertexTriangles(NodeTriangles1, p2);
                    //sumv = IterateVertexTriangles(NodeTriangles1, p3);
                }

                var M = ((sum.Top) / Magnitude(sum.Bot)) * offset;

                var offsetvecCenter = (centerOfPlane + M);
                var offsetcenterv1  = (centerv1 + M);
                var offsetcenterv2  = (centerv2 + M);
                var offsetcenterv3  = (centerv3 + M);

                points.Add(offsetvecCenter);
                points.Add(offsetcenterv1);
                points.Add(offsetcenterv2);
                points.Add(offsetcenterv3);
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine("Error: " + ex.Message);
            }

            return(points);
        }
Пример #7
0
        public static void testCreatePlateau()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            //select a surface
            PromptEntityOptions selSurface = new PromptEntityOptions("\nSelect a tin surface: ");

            selSurface.SetRejectMessage("\nOnly tin surface allowed");
            selSurface.AddAllowedClass(typeof(TinSurface), true);
            PromptEntityResult resSurface = ed.GetEntity(selSurface);

            if (resSurface.Status != PromptStatus.OK)
            {
                return;
            }
            ObjectId surfaceId = resSurface.ObjectId;

            //select a polyline
            PromptEntityOptions selPline = new PromptEntityOptions("\nSelect a polyline: ");

            selPline.SetRejectMessage("\nOnly polylines allowed");
            selPline.AddAllowedClass(typeof(Polyline), true);
            PromptEntityResult resPline = ed.GetEntity(selPline);

            if (resPline.Status != PromptStatus.OK)
            {
                return;
            }
            ObjectId plineId = resPline.ObjectId;

            //erase the pline?
            PromptKeywordOptions selYesNo = new PromptKeywordOptions("\nErase polyline?");

            selYesNo.Keywords.Add("Yes");
            selYesNo.Keywords.Add("No");
            PromptResult resYesNo = ed.GetKeywords(selYesNo);

            if (resYesNo.Status != PromptStatus.OK)
            {
                return;
            }
            bool erasePline = resYesNo.StringResult.Equals("Yes");

            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                TinSurface surface = trans.GetObject(surfaceId, OpenMode.ForWrite) as TinSurface;
                Polyline   pline   = trans.GetObject(plineId, OpenMode.ForWrite) as Polyline;
                var        test    = surface.ExtractGridded(SurfaceExtractionSettingsType.Model);
                //find all vertices inside a pline area
                ObjectIdCollection plinesBorder = new ObjectIdCollection();
                plinesBorder.Add(plineId);
                TinSurfaceVertex[] verticesInsidePline = surface.GetVerticesInsidePolylines(plinesBorder);

                //set the new elevation for all vertices founded
                surface.SetVerticesElevation(verticesInsidePline, pline.Elevation);

                //now create a surface vertex at each pline vertex
                for (int plineVertexIndex = 0; plineVertexIndex < pline.NumberOfVertices; plineVertexIndex++)
                {
                    //get the pline coordinate
                    Point3d plineVertex0 = pline.GetPoint3dAt(plineVertexIndex);
                    Point3d plineVertex1 = pline.GetPoint3dAt(plineVertexIndex < (pline.NumberOfVertices - 1) ? plineVertexIndex + 1 : 0);

                    //create a surface vertex at each pline vertex
                    //this will ensure that we have a vertex at each corner,
                    //which is required for the next step (AddLine)
                    SurfaceOperationAddTinVertex res0 = surface.AddVertex(plineVertex0);
                    SurfaceOperationAddTinVertex res1 = surface.AddVertex(plineVertex1);

                    //finally create a line connecting the newly creted vertices
                    TinSurfaceVertex vertex0 = surface.FindVertexAtXY(res0.Location.X, res0.Location.Y);
                    TinSurfaceVertex vertex1 = surface.FindVertexAtXY(res1.Location.X, res1.Location.Y);
                    surface.AddLine(vertex0, vertex1);
                }

                trans.Commit();
            }
        }
 public VertexWrapper(TinSurfaceVertex vertex) =>
 (_vertex) = (vertex);