Esempio n. 1
0
 public void setPrev(HalfEdge edge)
 {
     prev = edge;
 }
Esempio n. 2
0
 public void setOpposite(HalfEdge edge)
 {
     opposite      = edge;
     edge.opposite = this;
 }
Esempio n. 3
0
 public void setNext(HalfEdge edge)
 {
     next = edge;
 }
Esempio n. 4
0
        public int mergeAdjacentFace(HalfEdge hedgeAdj,
                                     Face[] discarded)
        {
            Face oppFace      = hedgeAdj.oppositeFace();
            int  numDiscarded = 0;

            discarded[numDiscarded++] = oppFace;
            oppFace.mark = DELETED;

            HalfEdge hedgeOpp = hedgeAdj.getOpposite();

            HalfEdge hedgeAdjPrev = hedgeAdj.prev;
            HalfEdge hedgeAdjNext = hedgeAdj.next;
            HalfEdge hedgeOppPrev = hedgeOpp.prev;
            HalfEdge hedgeOppNext = hedgeOpp.next;

            while (hedgeAdjPrev.oppositeFace() == oppFace)
            {
                hedgeAdjPrev = hedgeAdjPrev.prev;
                hedgeOppNext = hedgeOppNext.next;
            }

            while (hedgeAdjNext.oppositeFace() == oppFace)
            {
                hedgeOppPrev = hedgeOppPrev.prev;
                hedgeAdjNext = hedgeAdjNext.next;
            }

            HalfEdge hedge;

            for (hedge = hedgeOppNext; hedge != hedgeOppPrev.next; hedge = hedge.next)
            {
                hedge.face = this;
            }

            if (hedgeAdj == he0)
            {
                he0 = hedgeAdjNext;
            }

            // handle the half edges at the head
            Face discardedFace;

            discardedFace = connectHalfEdges(hedgeOppPrev, hedgeAdjNext);
            if (discardedFace != null)
            {
                discarded[numDiscarded++] = discardedFace;
            }

            // handle the half edges at the tail
            discardedFace = connectHalfEdges(hedgeAdjPrev, hedgeOppNext);
            if (discardedFace != null)
            {
                discarded[numDiscarded++] = discardedFace;
            }

            computeNormalAndCentroid();
            checkConsistency();

            return(numDiscarded);
        }
Esempio n. 5
0
        public void checkConsistency()
        {
            // do a sanity check on the face
            HalfEdge hedge = he0;
            double   maxd  = 0;
            int      numv  = 0;

            if (numVerts < 3)
            {
                throw new Exception(
                          "degenerate face: " + getVertexString());
            }
            do
            {
                HalfEdge hedgeOpp = hedge.getOpposite();
                if (hedgeOpp == null)
                {
                    throw new Exception(
                              "face " + getVertexString() + ": " +
                              "unreflected half edge " + hedge.getVertexString());
                }
                else if (hedgeOpp.getOpposite() != hedge)
                {
                    throw new Exception(
                              "face " + getVertexString() + ": " +
                              "opposite half edge " + hedgeOpp.getVertexString() +
                              " has opposite " +
                              hedgeOpp.getOpposite().getVertexString());
                }
                if (hedgeOpp.head() != hedge.tail() ||
                    hedge.head() != hedgeOpp.tail())
                {
                    throw new Exception(
                              "face " + getVertexString() + ": " +
                              "half edge " + hedge.getVertexString() +
                              " reflected by " + hedgeOpp.getVertexString());
                }
                Face oppFace = hedgeOpp.face;
                if (oppFace == null)
                {
                    throw new Exception(
                              "face " + getVertexString() + ": " +
                              "no face on half edge " + hedgeOpp.getVertexString());
                }
                else if (oppFace.mark == DELETED)
                {
                    throw new Exception(
                              "face " + getVertexString() + ": " +
                              "opposite face " + oppFace.getVertexString() +
                              " not on hull");
                }
                double d = Math.Abs(distanceToPlane(hedge.head().pnt));
                if (d > maxd)
                {
                    maxd = d;
                }
                numv++;
                hedge = hedge.next;
            }while (hedge != he0);

            if (numv != numVerts)
            {
                throw new Exception(
                          "face " + getVertexString() + " numVerts=" + numVerts + " should be " + numv);
            }
        }
Esempio n. 6
0
        private bool doAdjacentMerge(Face face, int mergeType)
        {
            HalfEdge hedge = face.he0;

            bool convex = true;

            do
            {
                Face   oppFace = hedge.oppositeFace();
                bool   merge   = false;
                double dist1;

                if (mergeType == NONCONVEX)
                { // then merge faces if they are definitively non-convex
                    if (oppFaceDistance(hedge) > -tolerance ||
                        oppFaceDistance(hedge.opposite) > -tolerance)
                    {
                        merge = true;
                    }
                }
                else // mergeType == NONCONVEX_WRT_LARGER_FACE
                { // merge faces if they are parallel or non-convex
                    // wrt to the larger face; otherwise, just mark
                    // the face non-convex for the second pass.
                    if (face.area > oppFace.area)
                    {
                        if ((dist1 = oppFaceDistance(hedge)) > -tolerance)
                        {
                            merge = true;
                        }
                        else if (oppFaceDistance(hedge.opposite) > -tolerance)
                        {
                            convex = false;
                        }
                    }
                    else
                    {
                        if (oppFaceDistance(hedge.opposite) > -tolerance)
                        {
                            merge = true;
                        }
                        else if (oppFaceDistance(hedge) > -tolerance)
                        {
                            convex = false;
                        }
                    }
                }

                if (merge)
                {
                    if (debug)
                    {
                        Print(
                            "  merging " + face.getVertexString() + "  and  " +
                            oppFace.getVertexString());
                    }

                    int numd = face.mergeAdjacentFace(hedge, discardedFaces);
                    for (int i = 0; i < numd; i++)
                    {
                        deleteFacePoints(discardedFaces[i], face);
                    }
                    if (debug)
                    {
                        Print(
                            "  result: " + face.getVertexString());
                    }
                    return(true);
                }
                hedge = hedge.next;
            }while (hedge != face.he0);
            if (!convex)
            {
                face.mark = Face.NON_CONVEX;
            }
            return(false);
        }
Esempio n. 7
0
 private double oppFaceDistance(HalfEdge he)
 {
     return(he.face.distanceToPlane(he.opposite.face.getCentroid()));
 }