Example #1
0
        protected void addNewFaces(FaceList newFaces, Vertex eyeVtx, ArrayList horizon)
        {
            newFaces.clear();

            HalfEdge hedgeSidePrev  = null;
            HalfEdge hedgeSideBegin = null;

            foreach (object o in horizon)
            {
                HalfEdge horizonHe = (HalfEdge)o;
                HalfEdge hedgeSide = addAdjoiningFace(eyeVtx, horizonHe);
                if (debug)
                {
                    Console.WriteLine(
                        "new face: " + hedgeSide.face.getVertexString());
                }
                if (hedgeSidePrev != null)
                {
                    hedgeSide.next.setOpposite(hedgeSidePrev);
                }
                else
                {
                    hedgeSideBegin = hedgeSide;
                }
                newFaces.add(hedgeSide.getFace());
                hedgeSidePrev = hedgeSide;
            }
            hedgeSideBegin.next.setOpposite(hedgeSidePrev);
        }
Example #2
0
        public void triangulate(FaceList newFaces, double minArea)
        {
            HalfEdge hedge;

            if (numVertices() < 4)
            {
                return;
            }

            Vertex v0       = he0.head();
            Face   prevFace = null;

            hedge = he0.next;
            HalfEdge oppPrev = hedge.opposite;
            Face     face0   = null;

            for (hedge = hedge.next; hedge != he0.prev; hedge = hedge.next)
            {
                Face face =
                    createTriangle(v0, hedge.prev.head(), hedge.head(), minArea);
                face.he0.next.setOpposite(oppPrev);
                face.he0.prev.setOpposite(hedge.opposite);
                oppPrev = face.he0;
                newFaces.add(face);
                if (face0 == null)
                {
                    face0 = face;
                }
            }
            hedge = new HalfEdge(he0.prev.prev.head(), this);
            hedge.setOpposite(oppPrev);

            hedge.prev      = he0;
            hedge.prev.next = hedge;

            hedge.next      = he0.prev;
            hedge.next.prev = hedge;

            computeNormalAndCentroid(minArea);
            checkConsistency();

            for (Face face = face0; face != null; face = face.next)
            {
                face.checkConsistency();
            }
        }
Example #3
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");
                    }
                }
            }
        }