示例#1
0
        protected void AddVertex(Face face, Vertex vertex)
        {
            base.AddVertex(vertex);
            Faces.Remove(face);

            HalfEdge h1 = face.HalfEdge;
            HalfEdge h2 = h1.Next;
            HalfEdge h3 = h2.Next;

            HalfEdge h4 = new HalfEdge(h1.Origin);
            HalfEdge h5 = new HalfEdge(h2.Origin);
            HalfEdge h6 = new HalfEdge(h3.Origin);
            HalfEdge h7 = new HalfEdge(vertex);
            HalfEdge h8 = new HalfEdge(vertex);
            HalfEdge h9 = new HalfEdge(vertex);
            HalfEdges.AddRange(new List<HalfEdge> {h4, h5, h6, h7, h8, h9});

            h4.Twin = h7;
            h7.Twin = h4;
            h5.Twin = h8;
            h8.Twin = h5;
            h6.Twin = h9;
            h9.Twin = h6;

            // Set all next
            h1.Next = h5;
            h5.Prev = h1;
            h5.Next = h7;
            h7.Prev = h5;
            h7.Next = h1;
            h1.Prev = h7;

            h2.Next = h6;
            h6.Prev = h2;
            h6.Next = h8;
            h8.Prev = h6;
            h8.Next = h2;
            h2.Prev = h8;

            h3.Next = h4;
            h4.Prev = h3;
            h4.Next = h9;
            h9.Prev = h4;
            h9.Next = h3;
            h3.Prev = h9;

            Triangle t1 = new Triangle(h1);
            Triangle t2 = new Triangle(h2);
            Triangle t3 = new Triangle(h3);

            Faces.Add(t1);
            Faces.Add(t2);
            Faces.Add(t3);

            Tree.Add(vertex, t1, t2, t3);

            LogEntry logEntry = new LogEntry("Adding edges.", this);
            logEntry.Objects.Add(vertex);
            Log.Add(logEntry);
        }
示例#2
0
        public override bool AddVertex(Vertex vertex)
        {
            Triangle face = FindFace(vertex) as Triangle;

            if (face == null)
                return false;

            AddVertex(face, vertex);

            // Find halfedges of triangle
            HalfEdge h1 = face.HalfEdge;
            HalfEdge h2 = face.HalfEdge.Next.Twin.Next;
            HalfEdge h3 = face.HalfEdge.Next.Twin.Next.Next.Twin.Next;

            // Log registration for playback
            LogEntry logEntry = new LogEntry("Select edges for delauney check", this);
            logEntry.Objects.Add(vertex);
            logEntry.Objects.Add(new Edge(h1.Origin, h1.Next.Origin));
            logEntry.Objects.Add(new Edge(h2.Origin, h2.Next.Origin));
            logEntry.Objects.Add(new Edge(h3.Origin, h3.Next.Origin));
            Log.Add(logEntry);

            // Flip if needed
            LegalizeEdge(vertex, h1, h1.Face as Triangle);
            LegalizeEdge(vertex, h2, h2.Face as Triangle);
            LegalizeEdge(vertex, h3, h3.Face as Triangle);

            return true;
        }
示例#3
0
        public virtual bool AddVertex(Vertex vertex)
        {
            Vertices.Add(vertex);

            LogEntry logEntry = new LogEntry("Adding vertex.", this);
            logEntry.Objects.Add(vertex);
            Log.Add(logEntry);

            return true;
        }
示例#4
0
        private void Flip(HalfEdge h)
        {
            HalfEdge h1 = h;
            HalfEdge h2 = h1.Next;
            HalfEdge h3 = h2.Next;
            HalfEdge h4 = h.Twin;
            HalfEdge h5 = h4.Next;
            HalfEdge h6 = h5.Next;

            if (h1.Face == null || h4.Face == null)
                return;

            LogEntry logEntry = new LogEntry("Flipping edge", this);
            logEntry.Objects.Add(new Edge(h.Origin, h.Next.Origin));
            Log.Add(logEntry);

            // Remove old faces
            Faces.Remove(h.Face);
            Faces.Remove(h.Twin.Face);

            h1.Next = h6;
            h6.Prev = h1;
            h6.Next = h2;
            h2.Prev = h6;
            h2.Next = h1;
            h1.Prev = h2;
            h1.Origin = h3.Origin;

            h4.Next = h3;
            h3.Prev = h4;
            h3.Next = h5;
            h5.Prev = h3;
            h5.Next = h4;
            h4.Prev = h5;
            h4.Origin = h6.Origin;

            Faces.Add(new Triangle(h1));
            Faces.Add(new Triangle(h1.Twin));
        }
示例#5
0
        private void LegalizeEdge(Vertex vertex, HalfEdge halfEdge, Triangle triangle)
        {
            if (vertex == null) throw new ArgumentNullException(nameof(vertex));

            if (triangle == null)
                return;

            LogEntry logEntry = new LogEntry("Checking edge", this);
            //logEntry.objects.Add(vertex);
            logEntry.Objects.Add(halfEdge.Face);
            logEntry.Objects.Add(new Edge(halfEdge.Origin, halfEdge.Next.Origin));
            Log.Add(logEntry);

            // Points to test
            Vertex v1 = halfEdge.Twin.Next.Next.Origin;
            Vertex v2 = halfEdge.Next.Twin.Next.Next.Origin;
            Vertex v3 = halfEdge.Next.Next.Twin.Next.Next.Origin;

            logEntry.Objects.Add(v1);
            logEntry.Objects.Add(v2);
            logEntry.Objects.Add(v3);

            if (triangle.InsideCircumcenter(v1))
            {
                logEntry = new LogEntry("Found point Inside circumcenter", this);
                logEntry.Objects.Add(v1);
                logEntry.Objects.Add(halfEdge.Face);
                Log.Add(logEntry);
            }

            if (triangle.InsideCircumcenter(v2))
            {
                logEntry = new LogEntry("Found point Inside circumcenter", this);
                logEntry.Objects.Add(v2);
                logEntry.Objects.Add(halfEdge.Face);
                Log.Add(logEntry);
            }

            if (triangle.InsideCircumcenter(v3))
            {
                logEntry = new LogEntry("Found point Inside circumcenter", this);
                logEntry.Objects.Add(v3);
                logEntry.Objects.Add(halfEdge.Face);
                Log.Add(logEntry);
            }

            if (triangle.InsideCircumcenter(v1) || triangle.InsideCircumcenter(v2) || triangle.InsideCircumcenter(v3))
            {
                HalfEdge h1 = halfEdge.Twin.Next.Twin;
                HalfEdge h2 = halfEdge.Twin.Prev.Twin;

                Flip(halfEdge);

                logEntry = new LogEntry("Select recursive flip edges", this);
                logEntry.Objects.Add(new Edge(h1.Origin, h1.Next.Origin));
                logEntry.Objects.Add(new Edge(h2.Origin, h2.Next.Origin));
                Log.Add(logEntry);

                LegalizeEdge(vertex, h1.Twin, h1.Twin.Face as Triangle);
                LegalizeEdge(vertex, h2.Twin, h2.Twin.Face as Triangle);
            }
        }