Пример #1
0
            /// <summary>
            /// Get all adjacent vertices to this face.
            /// </summary>
            /// <returns>Returns a list of all adjacent vertices in order.</returns>
            public List <HE_Vertex> adjacentVertices()
            {
                List <HE_Vertex> _vertices = new List <HE_Vertex>();
                HE_HalfEdge      _edge     = this.HalfEdge;

                do
                {
                    _vertices.Add(_edge.Vertex);
                    _edge = _edge.Next;
                } while (_edge != this.HalfEdge);
                return(_vertices);
            }
Пример #2
0
            /// <summary>
            /// Get all adjacent corners to this face.
            /// </summary>
            /// <returns>Returns a list of all adjacent corners in order.</returns>
            public List <HE_Corner> adjacentCorners()
            {
                List <HE_Corner> _corners = new List <HE_Corner>();
                HE_HalfEdge      _edge    = this.HalfEdge;

                do
                {
                    _corners.Add(_edge.Corner);
                    _edge = _edge.Next;
                } while (_edge != this.HalfEdge);
                return(_corners);
            }
Пример #3
0
            /// <summary>
            /// Get all adjacent faces to this face.
            /// </summary>
            /// <returns>Returns a list of all adjacent faces in order.</returns>
            public List <HE_Face> adjacentFaces()
            {
                List <HE_Face> _faces = new List <HE_Face>();
                HE_HalfEdge    _edge  = this.HalfEdge;

                do
                {
                    _faces.Add(_edge.Twin.Face);
                    _edge = _edge.Next;
                } while (_edge != this.HalfEdge);
                return(_faces);
            }
Пример #4
0
            /// <summary>
            /// Get all adjacent half-edges to this face.
            /// </summary>
            /// <returns>Returns a list of all adjacent half-edges in order.</returns>
            public List <HE_HalfEdge> adjacentHalfEdges()
            {
                HE_HalfEdge        _edge      = this.HalfEdge;
                List <HE_HalfEdge> _halfEdges = new List <HE_HalfEdge>();

                do
                {
                    _halfEdges.Add(_edge);
                    _edge = _edge.Next;
                }while (_edge != this.HalfEdge);

                return(_halfEdges);
            }
Пример #5
0
        // Returns a list with all the adjacent HE_Edge of this vertex
        public List <HE_Edge> adjacentEdges()
        {
            List <HE_Edge> _edges    = new List <HE_Edge>();
            HE_HalfEdge    _halfEdge = this.HalfEdge;

            do
            {
                _edges.Add(_halfEdge.Edge);
                _halfEdge = _halfEdge.Twin.Next;
            } while (_halfEdge != this.HalfEdge);

            return(_edges);
        }
Пример #6
0
        // Returns a list with all adjacent HE_Face of a vertex
        public List <HE_Face> adjacentFaces()
        {
            HE_HalfEdge    _halfEdge = this.HalfEdge;
            List <HE_Face> _faces    = new List <HE_Face>();

            do
            {
                if (!_halfEdge.onBoundary)
                {
                    _faces.Add(_halfEdge.Face);
                }
                _halfEdge = _halfEdge.Twin.Next;
            }while (_halfEdge != this.HalfEdge);

            return(_faces);
        }
Пример #7
0
        // Returns a list with all the adjacent HE_Corners of this vertex
        public List <HE_Corner> adjacentCorners()
        {
            List <HE_Corner> _corners  = new List <HE_Corner>();
            HE_HalfEdge      _halfEdge = this.HalfEdge;

            do
            {
                if (!_halfEdge.onBoundary)
                {
                    _corners.Add(_halfEdge.Next.Corner);
                }
                _halfEdge = _halfEdge.Twin.Next;
            } while (_halfEdge != this.HalfEdge);

            return(_corners);
        }
Пример #8
0
        // Takes a List containing another List per face with the vertex indexes belonging to that face
        private bool createFaces(List <List <int> > faceIndexes)
        {
            Dictionary <string, int>         edgeCount         = new Dictionary <string, int>();
            Dictionary <string, HE_HalfEdge> existingHalfEdges = new Dictionary <string, HE_HalfEdge>();
            Dictionary <HE_HalfEdge, bool>   hasTwinHalfEdge   = new Dictionary <HE_HalfEdge, bool>();

            // Create the faces, edges and half-edges, non-boundary loops and link references when possible;
            foreach (List <int> indexes in faceIndexes)
            {
                HE_Face f = new HE_Face();
                Faces.Add(f);

                List <HE_HalfEdge> tempHEdges = new List <HE_HalfEdge>(indexes.Count);
                //Create empty half-edges
                for (int i = 0; i < indexes.Count; i++)
                {
                    HE_HalfEdge h = new HE_HalfEdge();
                    tempHEdges.Add(h);
                }

                //Fill out each half edge
                for (int i = 0; i < indexes.Count; i++)
                {
                    //Edge goes from v0 to v1
                    int v0 = indexes[i];
                    int v1 = indexes[(i + 1) % indexes.Count];

                    HE_HalfEdge h = tempHEdges[i];
                    // Set previous and next
                    h.Next = tempHEdges[(i + 1) % indexes.Count];
                    h.Prev = tempHEdges[(i + indexes.Count - 1) % indexes.Count];

                    h.onBoundary = false;
                    hasTwinHalfEdge.Add(h, false);

                    // Set half-edge & vertex mutually
                    h.Vertex = Vertices[v0];
                    Vertices[v0].HalfEdge = h;

                    // Set half-edge face & vice versa
                    h.Face     = f;
                    f.HalfEdge = h;

                    // Reverse v0 and v1 if v0 > v1
                    if (v0 > v1)
                    {
                        int temp = v0;
                        v0 = v1;
                        v1 = temp;
                    }
                    string key = v0 + " " + v1;
                    if (existingHalfEdges.ContainsKey(key))
                    {
                        // If this half-edge key already exists, it is the twin of this current half-edge
                        HE_HalfEdge twin = existingHalfEdges[key];
                        h.Twin                = twin;
                        twin.Twin             = h;
                        h.Edge                = twin.Edge;
                        hasTwinHalfEdge[h]    = true;
                        hasTwinHalfEdge[twin] = true;
                        edgeCount[key]       += 1;
                    }
                    else
                    {
                        // Create an edge and set its half-edge
                        HE_Edge e = new HE_Edge();
                        Edges.Add(e);
                        h.Edge     = e;
                        e.HalfEdge = h;

                        // Record the newly created half-edge
                        existingHalfEdges.Add(key, h);
                        edgeCount.Add(key, 1);
                    }
                }

                HalfEdges.AddRange(tempHEdges);
            }

            // Create boundary edges
            for (int i = 0; i < HalfEdges.Count; i++)
            {
                HE_HalfEdge h = HalfEdges[i];
                if (!hasTwinHalfEdge[h])
                {
                    HE_Face f = new HE_Face();
                    Boundaries.Add(f);

                    List <HE_HalfEdge> boundaryCycle = new List <HE_HalfEdge>();
                    HE_HalfEdge        hE            = h;
                    do
                    {
                        HE_HalfEdge bH = new HE_HalfEdge();
                        HalfEdges.Add(bH);
                        boundaryCycle.Add(bH);

                        HE_HalfEdge nextHE = hE.Next;
                        while (hasTwinHalfEdge[nextHE])
                        {
                            nextHE = nextHE.Twin.Next;
                        }

                        bH.Vertex     = nextHE.Vertex;
                        bH.Edge       = hE.Edge;
                        bH.onBoundary = true;

                        bH.Face    = f;
                        f.HalfEdge = bH;

                        bH.Twin = hE;
                        hE.Twin = bH;

                        hE = nextHE;
                    } while (hE != h);

                    int n = boundaryCycle.Count;
                    for (int j = 0; j < n; j++)
                    {
                        boundaryCycle[j].Next                  = boundaryCycle[(j + n - 1) % n];
                        boundaryCycle[j].Prev                  = boundaryCycle[(j + 1) % n];
                        hasTwinHalfEdge[boundaryCycle[j]]      = true;
                        hasTwinHalfEdge[boundaryCycle[j].Twin] = true;
                    }
                }

                if (!h.onBoundary)
                {
                    HE_Corner corner = new HE_Corner();
                    corner.HalfEdge = h;
                    h.Corner        = corner;
                    Corners.Add(corner);
                }
            }

            // Check mesh for common errors
            if (HasIsolatedFaces() || HasIsolatedVertices() || HasNonManifoldEdges())
            {
                return(false);
            }

            // Index elements
            indexElements();

            return(true);
        }
Пример #9
0
 /// <summary>
 /// Initialize an empty half-edge mesh face.
 /// </summary>
 public HE_Face()
 {
     HalfEdge = null;
     Index    = -1;
 }