Example #1
0
        /// <summary>
        /// Split edge in half
        /// </summary>
        /// <param name="m">Polymesh</param>
        /// <param name="eh">Edge Handle</param>
        /// <returns>New Half-edge Handle for the new Edge</returns>
        public static int SplitEdge(PolyMesh m, int eh)
        {
            int heh     = m.GetHalfedgeEdgeH(eh, 0);
            int opp_heh = m.GetHalfedgeEdgeH(eh, 1);

            int new_heh, opp_new_heh, t_heh;
            int vh, vh1 = m.GetEndVertexH(heh);

            Vector3 midP = m.GetPoint(vh1);

            midP += m.GetPoint(m.GetEndVertexH(opp_heh));
            midP *= 0.5f;

            // new vertex
            vh = m.AddVertex(midP);

            // Re-link mesh entities
            if (m.IsBoundaryEdge(eh))
            {
                for (t_heh = heh;
                     m.GetNextHalfedgeH(t_heh) != opp_heh;
                     t_heh = m.GetOppositeHalfedgeH(m.GetNextHalfedgeH(t_heh)))
                {
                }
            }
            else
            {
                for (t_heh = m.GetNextHalfedgeH(opp_heh);
                     m.GetNextHalfedgeH(t_heh) != opp_heh;
                     t_heh = m.GetNextHalfedgeH(t_heh))
                {
                }
            }

            new_heh     = m.NewEdge(vh, vh1);
            opp_new_heh = m.GetOppositeHalfedgeH(new_heh);
            m.SetVertexH(heh, vh);

            m.SetNextHalfedgeH(t_heh, opp_new_heh);
            m.SetNextHalfedgeH(new_heh, m.GetNextHalfedgeH(heh));
            m.SetNextHalfedgeH(heh, new_heh);
            m.SetNextHalfedgeH(opp_new_heh, opp_heh);

            if (m.GetFaceH(opp_heh).isValidHandle())
            {
                m.SetFaceH(opp_new_heh, m.GetFaceH(opp_heh));
                m.SetHalfedgeFaceH(m.GetFaceH(opp_new_heh), opp_new_heh);
            }

            m.SetFaceH(new_heh, m.GetFaceH(heh));
            m.SetHalfedgeVertexH(vh, new_heh);
            m.SetHalfedgeFaceH(m.GetFaceH(heh), heh);
            m.SetHalfedgeVertexH(vh1, opp_new_heh);

            // Never forget this, when playing with the topology
            m.AdjustOutgoingHalfedge(vh);
            m.AdjustOutgoingHalfedge(vh1);

            return(new_heh);
        }
        public void TestSubPolygon()
        {
            var meshPoints = new[]
            {
                new V3d(5719.47607421875, 10842.48046875, 269.109008789063),
                new V3d(5719.47607421875, 10600.814453125, 269.109008789063),
                new V3d(5719.623046875, 10603.544921875, 271.355010986328),
                new V3d(5719.8662109375, 10608.0615234375, 275.071990966797),
                new V3d(5720.8759765625, 10634.0517578125, 290.489990234375),
                new V3d(5721.4921875, 10657.4775390625, 299.914001464844),
                new V3d(5721.494140625, 10657.50390625, 299.924011230469),
                new V3d(5721.494140625, 10603.6572265625, 299.924011230469),
                new V3d(5721.4921875, 10603.63671875, 299.912994384766),
                new V3d(5721.13623046875, 10594.4521484375, 294.463989257813),
                new V3d(5719.72802734375, 10568.3193359375, 272.963989257813),
                new V3d(5719.47607421875, 10564.873046875, 269.109008789063),
                new V3d(5719.47607421875, 10554.31640625, 269.109008789063),
                new V3d(5721.4921875, 10581.8486328125, 299.912994384766),
                new V3d(5721.494140625, 10581.859375, 299.924011230469),
                new V3d(5721.494140625, 10550.1767578125, 299.924011230469),
                new V3d(5719.51806640625, 10523.21484375, 269.760009765625),
                new V3d(5719.47607421875, 10522.423828125, 269.109008789063),
                new V3d(5719.47607421875, 10498.8857421875, 269.109008789063),
                new V3d(5719.93408203125, 10510.69140625, 276.111999511719),
                new V3d(5721.4912109375, 10539.62109375, 299.911987304688),
                new V3d(5721.4921875, 10581.8486328125, 299.912994384766),
                new V3d(5721.4921875, 10603.63671875, 299.912994384766),
                new V3d(5721.4921875, 10657.4775390625, 299.914001464844),
                new V3d(5721.4921875, 10785.8115234375, 299.915985107422),
                new V3d(5720.8759765625, 10809.2421875, 290.489990234375),
                new V3d(5719.8662109375, 10835.232421875, 275.071990966797),
                new V3d(5719.623046875, 10839.7490234375, 271.355010986328)
            };

            var mesh = new PolyMesh();

            foreach (var p in meshPoints)
            {
                mesh.AddVertex(p);
            }

            mesh.AddFace(0.UpToExclusive(meshPoints.Length).ToArray());

            var triangleMesh = mesh.TriangulatedCopy();

            // Requirement 1: should not crash

            // Requirement 2: valid polygon / TODO
            Assert.That(triangleMesh.FaceCount > 0);
        }