示例#1
0
  public int vertexDegree(Vertex v) {
    int result = 0;
    Halfedge e = v.getHalfedge();

    Halfedge pEdge = e.getNext().getOpposite();
    while (pEdge != e) {
      pEdge = pEdge.getNext().getOpposite();
      result++;
    }

    return result + 1;
  }
示例#2
0
 public String facesToString() {
   String result = "List of faces\n";
   Iterator it = this.facets.iterator();
   int cont = 0;
   while (it.hasNext()) {
     Face<X> f = (Face<X>) it.next();
     result = result + "f" + cont + " ";
     Halfedge<X> e = f.getEdge();
     while (e.getNext() != f.getEdge()) {
       result = result + vertices.indexOf(e.getVertex()) + " ";
       e = e.getNext();
     }
     result = result + vertices.indexOf(e.getVertex()) + "\n";
     cont++;
   }
   return result;
 }
示例#3
0
  /**
   * creates a new triangle facet within the hole incident to h by connecting the tip of h with two
   * new halfedges and a new vertex. Returns the halfedge of the new edge that is incident to the
   * new facet and the new vertex.
   */
  public Halfedge<X> addTriangleToBorder(Halfedge h, X point) {
    if (h.face != null) throw new Error("no border edge");
    System.out.println("adding triangle to " + h);

    Face<X> newFace = new Face<X>();
    Vertex<X> newVertex = new Vertex<X>(point);
    Halfedge<X> hPrev = new Halfedge<X>();
    Halfedge<X> hNext = new Halfedge<X>();
    Halfedge<X> hPrevOpp = new Halfedge<X>();
    Halfedge<X> hNextOpp = new Halfedge<X>();

    // setting the new face
    newFace.setEdge(h);
    // setting hPrev (halfedge preceding h in the new face)
    hPrev.setFace(newFace);
    hPrev.setVertex(h.getOpposite().getVertex());
    hPrev.setPrev(hNext);
    hPrev.setNext(h);
    hPrev.setOpposite(hPrevOpp);
    // setting hNext (halfedge following h in the new face)
    hNext.setFace(newFace);
    hNext.setVertex(newVertex);
    hNext.setPrev(h);
    hNext.setNext(hPrev);
    hNext.setOpposite(hNextOpp);
    // setting hPrevOpp (new boundary halfedge)
    hPrevOpp.setFace(null);
    hPrevOpp.setVertex(newVertex);
    hPrevOpp.setPrev(h.getPrev());
    hPrevOpp.setNext(hNextOpp);
    hPrevOpp.setOpposite(hPrev);
    // setting hNextOpp (the other new boundary halfedge)
    hNextOpp.setFace(null);
    hNextOpp.setVertex(h.getVertex());
    hNextOpp.setPrev(hPrevOpp);
    hNextOpp.setNext(h.getNext());
    hNextOpp.setOpposite(hNext);
    // updating old boundary halfedge informations
    h.setFace(newFace);
    h.setPrev(hPrev);
    h.setNext(hNext);
    // setting newVertex
    newVertex.setEdge(hPrev); // LCA: a controler si c'est hPrev ou hNext

    // adding new facet, vertex and the four halfedges
    this.vertices.add(newVertex);
    this.facets.add(newFace);
    this.halfedges.add(hPrev);
    this.halfedges.add(hNext);
    this.halfedges.add(hPrevOpp);
    this.halfedges.add(hNextOpp);

    return hNext;
  }
示例#4
0
  public void createCenterVertex(Face<X> f) {
    int degree = f.degree();
    Point_[] neighbors = new Point_[degree];

    Halfedge<X> e = f.getEdge();
    neighbors[0] = e.getVertex().getPoint();
    for (int i = 1; i < degree; i++) {
      e = e.getNext();
      neighbors[i] = e.getVertex().getPoint();
    }
    Point_ centerVertex;
    if (neighbors[0].dimension() == 2) centerVertex = new Point_2();
    else if (neighbors[0].dimension() == 3) centerVertex = new Point_3();
    else throw new Error("error point dimension");
  }
示例#5
0
  /**
   * returns true if the polyhedral surface is combinatorially consistent. If borders==true
   * normalization of the border edges is checked too. This method checks that each facet is at
   * least a triangle and that the two incident facets of a non-border edge are distinct.
   */
  public boolean isValid(boolean borders) {
    boolean valid = true;
    System.out.print("Checking Polyhedron...");
    int n = this.vertices.size();
    int e = this.halfedges.size();
    int f = this.facets.size();

    for (int i = 0; i < this.halfedges.size(); i++) {
      Halfedge<X> pedge = this.halfedges.get(i);
      if (pedge.getOpposite() == null) {
        System.out.print("error opposite: " + i);
        valid = false;
        // Face face=pedge.getFace();
        // int[] ind=face.getVertexIndices(this);
        // System.out.println(" "+ind[0]+" "+ind[1]+" "+ind[2]);
      }
      if (pedge.getNext() == null) {
        System.out.println("error next_edge: " + i);
        valid = false;
      }
      if (pedge.getPrev() == null) {
        System.out.println("error prev_edge: " + i);
        valid = false;
      }
      if (pedge.getVertex() == null) {
        System.out.println("error vertex: " + i);
        valid = false;
      }
      if (pedge.opposite != null && pedge.face == pedge.getOpposite().face) {
        System.out.println("error edge: " + i);
        valid = false;
      }
    }
    for (int i = 0; i < this.facets.size(); i++) {
      Face<X> pface = this.facets.get(i);
      if (pface == null) {
        System.out.println("error face pointer");
        valid = false;
      }
      if (pface.halfedge == null) {
        System.out.println("error face.halfedge");
        valid = false;
      }
      if (pface.degree() < 3) {
        System.out.println("error face degree");
        return valid = false;
      }
    }
    for (int i = 0; i < this.vertices.size(); i++) {
      Vertex<X> pvertex = this.vertices.get(i);
      // System.out.println(""+pvertex.toString());
      if (pvertex == null) {
        System.out.println("error vertex pointer:" + i);
        valid = false;
      }
      if (pvertex.halfedge == null) {
        System.out.println("error vertex.halfedge: " + i);
        valid = false;
      }
      if (pvertex.getPoint() == null) {
        System.out.println("error vertex.point: " + i);
        valid = false;
      }
    }

    if (valid == true) System.out.println("ok");
    else System.out.println("not valid");

    System.out.print("n: " + n + "  e: " + e / 2 + "  f: " + f + " - ");
    int g = -(n - e / 2 + f - 2) / 2;
    System.out.println("genus: " + g);

    return valid;
  }