public void PosTest()
        {
            var v  = new DCELVertex(0, 1);
            var v2 = new DCELVertex(new Vector2(0, 1));

            Assert.AreEqual(new Vector2(0, 1), v.Pos);
            Assert.AreEqual(v.Pos, v2.Pos);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a Voronoi DCEL from a triangulation. Triangulation should be Delaunay
        /// </summary>
        /// <param name="m_Delaunay"></param>
        /// <returns></returns>
        public static DCEL Create(Triangulation m_Delaunay)
        {
            if (!Delaunay.IsValid(m_Delaunay))
            {
                throw new GeomException("Triangulation should be delaunay for the Voronoi diagram.");
            }

            var dcel = new DCEL();

            // create vertices for each triangles circumcenter and store them in a dictionary
            Dictionary <Triangle, DCELVertex> vertexMap = new Dictionary <Triangle, DCELVertex>();

            foreach (var triangle in m_Delaunay.Triangles)
            {
                // degenerate triangle, just ignore
                if (!triangle.Circumcenter.HasValue)
                {
                    continue;
                }

                var vertex = new DCELVertex(triangle.Circumcenter.Value);
                dcel.AddVertex(vertex);
                vertexMap.Add(triangle, vertex);
            }

            // remember which edges where visited
            // since each edge has a twin
            var edgesVisited = new HashSet <TriangleEdge>();

            foreach (var edge in m_Delaunay.Edges)
            {
                // either already visited twin edge or edge is outer triangle
                if (edgesVisited.Contains(edge) || edge.IsOuter)
                {
                    continue;
                }

                // add edge between the two adjacent triangles vertices
                // vertices at circumcenter of triangle
                if (edge.T != null && edge.Twin.T != null)
                {
                    var v1 = vertexMap[edge.T];
                    var v2 = vertexMap[edge.Twin.T];

                    HalfEdge e1 = dcel.AddEdge(v1, v2);

                    e1.Twin.Face.owner = m_Delaunay.GetOwner(edge.Point1);
                    e1.Face.owner      = m_Delaunay.GetOwner(edge.Point2);

                    edgesVisited.Add(edge);
                    edgesVisited.Add(edge.Twin);
                }
            }

            return(dcel);
        }
        public void LeavingTest()
        {
            var v  = new DCELVertex(0, 1);
            var v2 = new DCELVertex(new Vector2(1, 2));
            var e  = new HalfEdge(v, v2);
            var v3 = new DCELVertex(new Vector2(0, 1), e);

            v.Leaving = e;

            Assert.AreEqual(v.Leaving, v3.Leaving);
        }
Exemplo n.º 4
0
 public HalfEdgeTest()
 {
     v          = new DCELVertex(0, 1);
     v2         = new DCELVertex(4, 4);
     e          = new HalfEdge(v, v2);
     eTwin      = new HalfEdge(v2, v);
     e.Twin     = eTwin;
     eTwin.Twin = e;
     e.Next     = e.Prev = eTwin;
     eTwin.Next = eTwin.Prev = e;
 }
Exemplo n.º 5
0
        public DCELPrimitive(GraphicsDevice graphicsDevice, DCELMesh mesh, float size)
        {
            int n = 0;

            mesh.Triangulate();

            foreach (var face in mesh.FaceList)
            {
                DCELHalfEdge he    = face.Edge;
                DCELVertex   first = he.Origin;

                do
                {
                    AddVertex(
                        GetVector3(he.Origin.Coordinates) * size,
                        GetVector3(he.Origin.Normal));
                    AddIndex(n++);
                    he = he.Next;
                }while (he.Origin != first);
            }

            InitializePrimitive(graphicsDevice);
        }
 public HalfEdge(DCELVertex from, DCELVertex to)
 {
     From = from;
     To   = to;
 }