Example #1
0
  /**
   * Constructs a triangule Face from vertices v0, v1, and v2.
   *
   * @param v0 first vertex
   * @param v1 second vertex
   * @param v2 third vertex
   */
  public static Face createTriangle(Vertex v0, Vertex v1, Vertex v2, double minArea) {
    Face face = new Face();
    HalfEdge he0 = new HalfEdge(v0, face);
    HalfEdge he1 = new HalfEdge(v1, face);
    HalfEdge he2 = new HalfEdge(v2, face);

    he0.prev = he2;
    he0.next = he1;
    he1.prev = he0;
    he1.next = he2;
    he2.prev = he1;
    he2.next = he0;

    face.he0 = he0;

    // compute the normal and offset
    face.computeNormalAndCentroid(minArea);
    return face;
  }
Example #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;
  }
Example #3
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();
    }
  }