示例#1
0
        public TopoTriangle BuildTriangle(TopoModel model)
        {
            TopoVertex sharedPoint = null;
            TopoVertex p1 = null, p2 = null;

            if (edgeA.v1 == edgeB.v1)
            {
                sharedPoint = edgeA.v1;
                p1          = edgeA.v2;
                p2          = edgeB.v2;
            }
            else if (edgeA.v1 == edgeB.v2)
            {
                sharedPoint = edgeA.v1;
                p1          = edgeA.v2;
                p2          = edgeB.v1;
            }
            else if (edgeA.v2 == edgeB.v1)
            {
                sharedPoint = edgeA.v1;
                p1          = edgeA.v1;
                p2          = edgeB.v2;
            }
            else if (edgeA.v2 == edgeB.v2)
            {
                sharedPoint = edgeA.v2;
                p1          = edgeA.v1;
                p2          = edgeB.v1;
            }
            TopoTriangle faceA       = edgeA.faces.First.Value;
            TopoTriangle newTriangle = new TopoTriangle(model, sharedPoint, p1, p2, 0, 0, 1);

            if (newTriangle.SameNormalOrientation(faceA) == false)
            {
                newTriangle.FlipDirection();
            }
            newTriangle.RecomputeNormal();
            model.AddTriangle(newTriangle);
            return(newTriangle);
        }
示例#2
0
        /// <summary>
        /// Splits an edge and changes the connected triangles to maintain
        /// a topological correct system.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="vertex"></param>
        public void InsertVertex(TopoModel model, TopoVertex vertex)
        {
            LinkedList <TopoTriangle> delList   = new LinkedList <TopoTriangle>();
            LinkedList <TopoTriangle> testFaces = new LinkedList <TopoTriangle>();

            foreach (TopoTriangle oldTriangle in faces)
            {
                testFaces.AddLast(oldTriangle);
            }
            foreach (TopoTriangle oldTriangle in testFaces)
            {
                delList.AddLast(oldTriangle);
                for (int i = 0; i < 3; i++)
                {
                    if (oldTriangle.vertices[i] != v1 && oldTriangle.vertices[i] != v2)
                    {
                        TopoTriangle newTriangle = new TopoTriangle(model, v1, vertex, oldTriangle.vertices[i]);
                        if (newTriangle.IsDegenerated())
                        {
                            newTriangle.Unlink(model);
                        }
                        else
                        {
                            // Test orientation
                            for (int e = 0; e < 3; e++)
                            {
                                TopoTriangle neigbour = newTriangle.edges[i].GetFaceExcept(newTriangle);
                                if (neigbour != null)
                                {
                                    if (!newTriangle.SameNormalOrientation(neigbour))
                                    {
                                        newTriangle.FlipDirection();
                                    }
                                    break;
                                }
                            }
                            model.AddTriangle(newTriangle);
                        }
                        newTriangle = new TopoTriangle(model, vertex, v2, oldTriangle.vertices[i]);
                        if (newTriangle.IsDegenerated())
                        {
                            newTriangle.Unlink(model);
                        }
                        else
                        {
                            // Test orientation
                            for (int e = 0; e < 3; e++)
                            {
                                TopoTriangle neigbour = newTriangle.edges[i].GetFaceExcept(newTriangle);
                                if (neigbour != null)
                                {
                                    if (!newTriangle.SameNormalOrientation(neigbour))
                                    {
                                        newTriangle.FlipDirection();
                                    }
                                    break;
                                }
                            }
                            model.AddTriangle(newTriangle);
                        }
                    }
                }
            }
            foreach (TopoTriangle tri in delList)
            {
                tri.Unlink(model);
                model.removeTriangle(tri);
            }
        }