Esempio n. 1
0
        protected void resolveUnclaimedPoints(FaceList newFaces)
        {
            Vertex vtxNext = unclaimed.first();

            for (Vertex vtx = vtxNext; vtx != null; vtx = vtxNext)
            {
                vtxNext = vtx.next;

                double maxDist = tolerance;
                Face   maxFace = null;
                for (Face newFace = newFaces.first(); newFace != null;
                     newFace = newFace.next)
                {
                    if (newFace.mark == Face.VISIBLE)
                    {
                        double dist = newFace.distanceToPlane(vtx.pnt);
                        if (dist > maxDist)
                        {
                            maxDist = dist;
                            maxFace = newFace;
                        }
                        if (maxDist > 1000 * tolerance)
                        {
                            break;
                        }
                    }
                }
                if (maxFace != null)
                {
                    addPointToFace(vtx, maxFace);
                    if (debug && vtx.index == findIndex)
                    {
                        Console.WriteLine(findIndex + " CLAIMED BY " +
                                          maxFace.getVertexString());
                    }
                }
                else
                {
                    if (debug && vtx.index == findIndex)
                    {
                        Console.WriteLine(findIndex + " DISCARDED");
                    }
                }
            }
        }
Esempio n. 2
0
        protected void calculateHorizon(Point3d eyePnt, HalfEdge edge0, Face face, ArrayList horizon)
        {
            //	   oldFaces.add (face);
            deleteFacePoints(face, null);
            face.mark = Face.DELETED;
            if (debug)
            {
                Console.WriteLine("  visiting face " + face.getVertexString());
            }
            HalfEdge edge;

            if (edge0 == null)
            {
                edge0 = face.getEdge(0);
                edge  = edge0;
            }
            else
            {
                edge = edge0.getNext();
            }
            do
            {
                Face oppFace = edge.oppositeFace();
                if (oppFace.mark == Face.VISIBLE)
                {
                    if (oppFace.distanceToPlane(eyePnt) > tolerance)
                    {
                        calculateHorizon(eyePnt, edge.getOpposite(),
                                         oppFace, horizon);
                    }
                    else
                    {
                        horizon.Add(edge);
                        if (debug)
                        {
                            Console.WriteLine("  adding horizon edge " +
                                              edge.getVertexString());
                        }
                    }
                }
                edge = edge.getNext();
            }while (edge != edge0);
        }
Esempio n. 3
0
        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. 4
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);
        }