public void BoundingBoxWithPolygonTest()
        {
            Vertex a        = new Vertex(8, 14);
            Vertex b        = new Vertex(3, 10);
            Vertex c        = new Vertex(3, 3);
            Vertex d        = new Vertex(8, 1);
            Vertex e        = new Vertex(13, 4);
            Vertex f        = new Vertex(13, 11);
            Vertex bb1      = new Vertex(0, 0);
            Vertex bb2      = new Vertex(15, 0);
            Vertex bb3      = new Vertex(15, 15);
            Vertex bb4      = new Vertex(0, 15);
            var    vertices = new[] { f, e, d, c, b, a, bb1, bb2, bb3, bb4 };
            var    mesh     = new Mesh <Vertex, EdgeBase, FaceBase>(vertices);

            mesh.AddEdge(f, e);
            mesh.AddEdge(e, d);
            mesh.AddEdge(d, c);
            mesh.AddEdge(c, b);
            mesh.AddEdge(b, a);
            mesh.AddEdge(a, f);

            mesh.AddEdge(bb1, bb2);
            mesh.AddEdge(bb2, bb3);
            mesh.AddEdge(bb3, bb4);
            mesh.AddEdge(bb4, bb1);

            var myp = new MonotoneYPartitioner <Vertex, EdgeBase, FaceBase>(mesh);
            Mesh <Vertex, EdgeBase, FaceBase> result = myp.GetResult();

            Assert.AreEqual(10, result.VertexCount);
            Assert.AreEqual(12, result.EdgeCount);
        }
        public void NonMonotoneClockwisePolygonTest()
        {
            Vertex a        = new Vertex(8, 14);
            Vertex b        = new Vertex(3, 10);
            Vertex c        = new Vertex(3, 6);
            Vertex d        = new Vertex(6, 8);
            Vertex e        = new Vertex(3, 3);
            Vertex f        = new Vertex(8, 1);
            Vertex g        = new Vertex(13, 4);
            Vertex h        = new Vertex(13, 11);
            var    vertices = new[] { h, g, f, e, d, c, b, a };
            var    mesh     = new Mesh <Vertex, EdgeBase, FaceBase>(vertices);

            mesh.AddEdge(h, g);
            mesh.AddEdge(g, f);
            mesh.AddEdge(f, e);
            mesh.AddEdge(e, d);
            mesh.AddEdge(d, c);
            mesh.AddEdge(c, b);
            mesh.AddEdge(b, a);
            mesh.AddEdge(a, h);
            // TODO: Could add face here
            var myp = new MonotoneYPartitioner <Vertex, EdgeBase, FaceBase>(mesh);
            Mesh <Vertex, EdgeBase, FaceBase> result = myp.GetResult();

            Assert.AreEqual(8, result.VertexCount);
            Assert.AreEqual(9, result.EdgeCount);
        }
        public void BoundingBoxWithBoxTest()
        {
            Vertex a        = new Vertex(4, 4);
            Vertex b        = new Vertex(11, 4);
            Vertex c        = new Vertex(11, 11);
            Vertex d        = new Vertex(4, 11);
            Vertex bb1      = new Vertex(0, 0);
            Vertex bb2      = new Vertex(15, 0);
            Vertex bb3      = new Vertex(15, 15);
            Vertex bb4      = new Vertex(0, 15);
            var    vertices = new[] { a, b, c, d, bb1, bb2, bb3, bb4 };
            var    mesh     = new Mesh <Vertex, EdgeBase, FaceBase>(vertices);

            // Box
            mesh.AddEdge(a, b);
            mesh.AddEdge(b, c);
            mesh.AddEdge(c, d);
            mesh.AddEdge(d, a);

            // Bounding box
            mesh.AddEdge(bb1, bb2);
            mesh.AddEdge(bb2, bb3);
            mesh.AddEdge(bb3, bb4);
            mesh.AddEdge(bb4, bb1);

            var myp = new MonotoneYPartitioner <Vertex, EdgeBase, FaceBase>(mesh);
            Mesh <Vertex, EdgeBase, FaceBase> result = myp.GetResult();

            Assert.AreEqual(8, result.VertexCount);
            Assert.AreEqual(10, result.EdgeCount);
        }
        /// <summary>
        /// Insert a FaultEdge edge into the mesh between the two specified positions
        /// </summary>
        /// <param name="segment">The equivalent segment in the FaultNetwork</param>
        /// <param name="m">The mesh to which the edge is to be added</param>
        /// <param name="p1">A position at the start of the edge</param>
        /// <param name="p2">A position at the end of the edge</param>
        private static void AddFaultEdge(SegmentNode segment, Mesh <PositionedVertexBase, EdgeBase, FaceBase> m, IPositionable2D p1, IPositionable2D p2)
        {
            var v1 = m.Find(new FaultVertex(p1));

            Debug.Assert(v1 != null);
            var v2 = m.Find(new FaultVertex(p2));

            Debug.Assert(v2 != null);
            m.AddEdge(v1, v2, new FaultEdge(segment));
        }
        public void BoundingBoxTest()
        {
            Vertex a        = new Vertex(0, 0);
            Vertex b        = new Vertex(10, 0);
            Vertex c        = new Vertex(10, 10);
            Vertex d        = new Vertex(0, 10);
            var    vertices = new[] { a, b, c, d };
            var    mesh     = new Mesh <Vertex, EdgeBase, FaceBase>(vertices);

            mesh.AddEdge(a, b);
            mesh.AddEdge(b, c);
            mesh.AddEdge(c, d);
            mesh.AddEdge(d, a);
            // TODO: Could add face here
            var myp = new MonotoneYPartitioner <Vertex, EdgeBase, FaceBase>(mesh);
            Mesh <Vertex, EdgeBase, FaceBase> result = myp.GetResult();

            Assert.AreEqual(4, result.VertexCount);
            Assert.AreEqual(4, result.EdgeCount);
        }
Exemple #6
0
        private void Skeletonize()
        {
            // Duplicate the figure, but convert the types of vertices and edges
            // and maintain a mapping from the triangulation vertices to the wavefront vertices.
            var wavefrontMesh     = new Mesh <WavefrontVertex, EdgeBase, WavefrontFace>();
            var wavefrontVertices = new Dictionary <VertexBase, List <WavefrontVertex> >();

            foreach (TVertex v in figure.Vertices)
            {
                WavefrontVertex wavefrontVertex = new WavefrontVertex(v, new Vector2D());
                wavefrontMesh.Add(wavefrontVertex);
                if (!wavefrontVertices.ContainsKey(v))
                {
                    wavefrontVertices.Add(v, new List <WavefrontVertex>());
                }
                wavefrontVertices[v].Add(wavefrontVertex);
            }

            // Now insert the edges from the figure
            foreach (TEdge e in figure.Edges)
            {
                WavefrontVertex from = wavefrontVertices[e.Source].First();
                WavefrontVertex to   = wavefrontVertices[e.Target].First();
                wavefrontMesh.AddEdge(from, to, new FigureEdge());
            }

            // Triangulate the figure. All new edges inserted during the triangulation
            // are to be SpokeEdges. TODO: What about bounding-box edges?
            Algorithms.TriangulatePlanarSubdivision <WavefrontVertex, EdgeBase, WavefrontFace, TriangulationEdge>(wavefrontMesh, true);

            // Build the wavefront triangulation
            //  - insert additional zero size triangles at the terminals of the figure
            //  - split each edge of the figure along its length so that otherwise adjacent
            //    triangles do not share an edge
            foreach (TVertex figureVertex in figure.Vertices)
            {
                // TODO: Ensure we pass the right vertex to the functions here
                if (figureVertex.Degree >= 2)
                {
                    ProcessNonTerminalVertex(wavefrontMesh, wavefrontVertices, figureVertex);
                }
                else if (figureVertex.Degree == 1)
                {
                    ProcessTerminalVertex(wavefrontMesh, wavefrontVertices, figureVertex);
                }
            }
        }
        public void CollinearTest()
        {
            Vertex a = new Vertex(0, 0);
            Vertex b = new Vertex(5, 0);
            Vertex c = new Vertex(10, 0);
            Vertex d = new Vertex(10, 5);
            Vertex e = new Vertex(10, 10);
            Vertex f = new Vertex(5, 10);
            Vertex g = new Vertex(0, 10);
            Vertex h = new Vertex(0, 5);

            var      vertices = new[] { a, b, c, d, e, f, g, h, };
            var      mesh     = new Mesh <Vertex, EdgeBase, FaceBase>(vertices);
            EdgeBase ab       = mesh.AddEdge(a, b);
            EdgeBase bc       = mesh.AddEdge(b, c);
            EdgeBase cd       = mesh.AddEdge(c, d);
            EdgeBase de       = mesh.AddEdge(d, e);
            EdgeBase ef       = mesh.AddEdge(e, f);
            EdgeBase fg       = mesh.AddEdge(f, g);
            EdgeBase gh       = mesh.AddEdge(g, h);
            EdgeBase ha       = mesh.AddEdge(h, a);

            var myp = new MonotoneYPartitioner <Vertex, EdgeBase, FaceBase>(mesh);
            Mesh <Vertex, EdgeBase, FaceBase> result = myp.GetResult();

            Assert.AreEqual(8, result.VertexCount);
            Assert.AreEqual(8, result.EdgeCount);

            // Check for input edges
            Assert.AreEqual(ab, mesh.Find(a, b));
            Assert.AreEqual(bc, mesh.Find(b, c));
            Assert.AreEqual(cd, mesh.Find(c, d));
            Assert.AreEqual(de, mesh.Find(d, e));
            Assert.AreEqual(ef, mesh.Find(e, f));
            Assert.AreEqual(fg, mesh.Find(f, g));
            Assert.AreEqual(gh, mesh.Find(g, h));
            Assert.AreEqual(ha, mesh.Find(h, a));
        }
        public void PolygonAntiClockwiseTest()
        {
            Vertex a        = new Vertex(8, 14);
            Vertex b        = new Vertex(3, 10);
            Vertex c        = new Vertex(3, 3);
            Vertex d        = new Vertex(8, 1);
            Vertex e        = new Vertex(13, 4);
            Vertex f        = new Vertex(13, 11);
            var    vertices = new[] { a, b, c, d, e, f };
            var    mesh     = new Mesh <Vertex, EdgeBase, FaceBase>(vertices);

            mesh.AddEdge(a, b);
            mesh.AddEdge(b, c);
            mesh.AddEdge(c, d);
            mesh.AddEdge(d, e);
            mesh.AddEdge(e, f);
            mesh.AddEdge(f, a);
            // TODO: Could add face here
            var myp = new MonotoneYPartitioner <Vertex, EdgeBase, FaceBase>(mesh);
            Mesh <Vertex, EdgeBase, FaceBase> result = myp.GetResult();

            Assert.AreEqual(6, result.VertexCount);
            Assert.AreEqual(6, result.EdgeCount);
        }
Exemple #9
0
 private static void InsertDiagonal(Mesh <TVertex, TEdge, TFace> m, TVertex from, TVertex to)
 {
     Debug.Assert(m.Find(from, to) == null);
     // TODO: May need to handle faces here - e.g. use SplitFace Euler method
     m.AddEdge(from, to);
 }
        public void Init()
        {
            mesh = new Mesh <Vertex, EdgeBase, FaceBase>(false, true);

            v1 = new Vertex(3, 10);
            v2 = new Vertex(3, 6);
            v3 = new Vertex(6, 8);
            v4 = new Vertex(3, 3);
            v6 = new Vertex(13, 4);
            v7 = new Vertex(13, 11);

            mesh.Add(v1);
            mesh.Add(v2);
            edgeTwoToOne  = mesh.AddEdge(v2, v1);
            edgeTwoToOne2 = mesh.AddEdge(v2, v1);
            edgeOneToTwo  = mesh.AddEdge(v1, v2);

            mesh.Add(v3);
            edgeThreeToTwo = mesh.AddEdge(v3, v2);
            edgeTwoToThree = mesh.AddEdge(v2, v3);

            mesh.Add(v4);
            edgeFourToThree = mesh.AddEdge(v4, v3);

            mesh.Add(v7);
            mesh.Add(v6);
            edgeSevenToSix = mesh.AddEdge(v7, v6);

            v100 = new Vertex(101, 103);
            v101 = new Vertex(103, 103);
            v102 = new Vertex(108, 103);
            v103 = new Vertex(107, 103);
            v104 = new Vertex(109, 103);
            v105 = new Vertex(104, 101);
            v106 = new Vertex(106, 106);

            mesh.Add(v100);
            mesh.Add(v101);
            e100to101 = mesh.AddEdge(v100, v101);

            mesh.Add(v101);
            mesh.Add(v102);
            e101to102 = mesh.AddEdge(v101, v102);

            mesh.Add(v103);
            mesh.Add(v104);
            e103to104 = mesh.AddEdge(v103, v104);

            mesh.Add(v105);
            mesh.Add(v106);
            e105to106 = mesh.AddEdge(v105, v106);

            v200 = new Vertex(210, 180);
            v201 = new Vertex(90, 180);
            v202 = new Vertex(90, 60);

            mesh.Add(v200);
            mesh.Add(v201);
            mesh.Add(v202);
            e200to201 = mesh.AddEdge(v200, v201);
            e202to201 = mesh.AddEdge(v202, v201);

            v300 = new Vertex(210, 180);
            v301 = new Vertex(90, 180);
            v302 = new Vertex(90, 60);
            v303 = new Vertex(90, 170);

            mesh.Add(v300);
            mesh.Add(v301);
            mesh.Add(v302);
            mesh.Add(v303);
            e300to301 = mesh.AddEdge(v300, v301);
            e302to303 = mesh.AddEdge(v302, v303);

            comparer = new LeftToRightEdgeComparer();
        }
Exemple #11
0
 private void InsertDiagonal(TVertex from, TVertex to)
 {
     target.AddEdge(from, to);
 }
        public void BoundingBoxWithPlanarSubdivision3Test()
        {
            Vertex a = new Vertex(8, 14);
            Vertex b = new Vertex(3, 10);
            Vertex c = new Vertex(3, 6);
            Vertex d = new Vertex(6, 8);
            Vertex e = new Vertex(3, 3);
            Vertex f = new Vertex(8, 1);
            Vertex g = new Vertex(13, 4);
            Vertex h = new Vertex(13, 11);

            Vertex b1 = new Vertex(2, 10);
            Vertex f1 = new Vertex(8, 9);

            Vertex bb1 = new Vertex(0, 0);
            Vertex bb2 = new Vertex(15, 0);
            Vertex bb3 = new Vertex(15, 15);
            Vertex bb4 = new Vertex(0, 15);

            var      vertices = new[] { a, b, c, d, e, f, g, h, b1, f1, bb1, bb2, bb3, bb4 };
            var      mesh     = new Mesh <Vertex, EdgeBase, FaceBase>(vertices);
            EdgeBase ab       = mesh.AddEdge(a, b);
            EdgeBase bc       = mesh.AddEdge(b, c);
            EdgeBase cd       = mesh.AddEdge(c, d);
            EdgeBase de       = mesh.AddEdge(d, e);
            EdgeBase ef       = mesh.AddEdge(e, f);
            EdgeBase fg       = mesh.AddEdge(f, g);
            EdgeBase gh       = mesh.AddEdge(g, h);
            EdgeBase ha       = mesh.AddEdge(h, a);

            EdgeBase b_b1 = mesh.AddEdge(b, b1);
            EdgeBase ff1  = mesh.AddEdge(f, f1);

            EdgeBase bb1bb2 = mesh.AddEdge(bb1, bb2);
            EdgeBase bb2bb3 = mesh.AddEdge(bb2, bb3);
            EdgeBase bb3bb4 = mesh.AddEdge(bb3, bb4);
            EdgeBase bb4bb1 = mesh.AddEdge(bb4, bb1);

            var myp = new MonotoneYPartitioner <Vertex, EdgeBase, FaceBase>(mesh);
            Mesh <Vertex, EdgeBase, FaceBase> result = myp.GetResult();

            Assert.AreEqual(14, result.VertexCount);
            Assert.AreEqual(20, result.EdgeCount);

            // Check for input edges
            Assert.AreEqual(ab, mesh.Find(a, b));
            Assert.AreEqual(bc, mesh.Find(b, c));
            Assert.AreEqual(cd, mesh.Find(c, d));
            Assert.AreEqual(de, mesh.Find(d, e));
            Assert.AreEqual(ef, mesh.Find(e, f));
            Assert.AreEqual(fg, mesh.Find(f, g));
            Assert.AreEqual(gh, mesh.Find(g, h));
            Assert.AreEqual(ha, mesh.Find(h, a));
            Assert.AreEqual(b_b1, mesh.Find(b, b1));
            Assert.AreEqual(ff1, mesh.Find(f, f1));
            Assert.AreEqual(bb1bb2, mesh.Find(bb1, bb2));
            Assert.AreEqual(bb2bb3, mesh.Find(bb2, bb3));
            Assert.AreEqual(bb3bb4, mesh.Find(bb3, bb4));
            Assert.AreEqual(bb4bb1, mesh.Find(bb4, bb1));

            // Check for additional edges
            Assert.IsNotNull(mesh.Find(a, bb3));
            Assert.IsNotNull(mesh.Find(b1, a));
            Assert.IsNotNull(mesh.Find(f1, b));
            Assert.IsNotNull(mesh.Find(d, f1));
            Assert.IsNotNull(mesh.Find(c, e));
            Assert.IsNotNull(mesh.Find(f, bb1));
        }
 /// <summary>
 /// Used for inserting monotonizing diagonals into the mesh by the monotone partitioning algorithm.
 /// </summary>
 /// <param name="m"></param>
 /// <param name="fromVertex"></param>
 /// <param name="toVertex"></param>
 private static void InsertMonotonizingDiagonal(Mesh <PositionedVertexBase, EdgeBase, FaceBase> m, PositionedVertexBase fromVertex, PositionedVertexBase toVertex)
 {
     m.AddEdge(fromVertex, toVertex, new MonotonizingEdge());
 }