Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        private Face connectHalfEdges(HalfEdge hedgePrev, HalfEdge hedge)
        {
            Face discardedFace = null;

            if (hedgePrev.oppositeFace() == hedge.oppositeFace())
            { // then there is a redundant edge that we can get rid off
                Face     oppFace = hedge.oppositeFace();
                HalfEdge hedgeOpp;

                if (hedgePrev == he0)
                {
                    he0 = hedge;
                }
                if (oppFace.numVertices() == 3)
                { // then we can get rid of the opposite face altogether
                    hedgeOpp = hedge.getOpposite().prev.getOpposite();

                    oppFace.mark  = DELETED;
                    discardedFace = oppFace;
                }
                else
                {
                    hedgeOpp = hedge.getOpposite().next;

                    if (oppFace.he0 == hedgeOpp.prev)
                    {
                        oppFace.he0 = hedgeOpp;
                    }
                    hedgeOpp.prev      = hedgeOpp.prev.prev;
                    hedgeOpp.prev.next = hedgeOpp;
                }
                hedge.prev      = hedgePrev.prev;
                hedge.prev.next = hedge;

                hedge.opposite    = hedgeOpp;
                hedgeOpp.opposite = hedge;

                // oppFace was modified, so need to recompute
                oppFace.computeNormalAndCentroid();
            }
            else
            {
                hedgePrev.next = hedge;
                hedge.prev     = hedgePrev;
            }
            return(discardedFace);
        }
Ejemplo n.º 3
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, dist2;

                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)
                    {
                        Console.WriteLine(
                            "  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)
                    {
                        Console.WriteLine(
                            "  result: " + face.getVertexString());
                    }
                    return(true);
                }
                hedge = hedge.next;
            }while (hedge != face.he0);
            if (!convex)
            {
                face.mark = Face.NON_CONVEX;
            }
            return(false);
        }