コード例 #1
0
ファイル: HE_Face.java プロジェクト: theomission/HE_Mesh2014
 public void checkValidity() {
   final Coordinate[] coords = new Coordinate[getFaceOrder() + 1];
   final WB_Point point = geometryfactory.createPoint();
   final WB_Map2D context = geometryfactory.createEmbeddedPlane(getPlane());
   HE_Halfedge he = _halfedge;
   int i = 0;
   do {
     context.mapPoint3D(he.getVertex(), point);
     coords[i] = new Coordinate(point.xd(), point.yd(), i);
     he = he.getNextInFace();
     i++;
   } while (he != _halfedge);
   context.mapPoint3D(he.getVertex(), point);
   coords[i] = new Coordinate(point.xd(), point.yd(), i);
   he = he.getNextInFace();
   final Polygon inputPolygon = new GeometryFactory().createPolygon(coords);
   final IsValidOp isValidOp = new IsValidOp(inputPolygon);
   if (!IsValidOp.isValid(inputPolygon)) {
     System.out.println(this);
     System.out.println(this.getFaceArea() + " " + this.getFaceNormal());
     he = _halfedge;
     i = 0;
     do {
       System.out.println("  " + i + ": " + he.getVertex());
       he = he.getNextInFace();
       i++;
     } while (he != _halfedge);
     System.out.println(isValidOp.getValidationError());
   }
 }
コード例 #2
0
 /*
  * (non-Javadoc)
  *
  * @see wblut.hemesh.HE_Creator#create()
  */
 @Override
 protected HE_Mesh createBase() {
   final WB_Point[] vertices = new WB_Point[(tubefacets + 1) * (torusfacets + 1)];
   final WB_Point[] uvws = new WB_Point[(tubefacets + 1) * (torusfacets + 1)];
   final double dtua = (2 * Math.PI) / tubefacets;
   final double dtoa = (2 * Math.PI) / torusfacets;
   final double dv = 1.0 / tubefacets;
   final double du = 1.0 / torusfacets;
   final double dtwa = (twist * dtoa) / tubefacets;
   int id = 0;
   WB_Point basevertex;
   for (int j = 0; j < torusfacets + 1; j++) {
     final int lj = (j == torusfacets) ? 0 : j;
     final double ca = Math.cos(lj * dtoa);
     final double sa = Math.sin(lj * dtoa);
     for (int i = 0; i < tubefacets + 1; i++) {
       final int li = (i == tubefacets) ? 0 : i;
       basevertex =
           new WB_Point(
               Ro + (Ri * Math.cos((dtua * li) + (j * dtwa))),
               0,
               Ri * Math.sin((dtua * li) + (j * dtwa)));
       vertices[id] = new WB_Point(ca * basevertex.xd(), sa * basevertex.xd(), basevertex.zd());
       uvws[id] = new WB_Point(j * du, i * dv, 0);
       id++;
     }
   }
   final int nfaces = tubefacets * torusfacets;
   id = 0;
   final int[][] faces = new int[nfaces][];
   int j = 0;
   for (j = 0; j < torusfacets; j++) {
     for (int i = 0; i < tubefacets; i++) {
       faces[id] = new int[4];
       faces[id][0] = i + (j * (tubefacets + 1));
       faces[id][1] = i + ((j + 1) * (tubefacets + 1));
       faces[id][2] = (i + 1) + ((j + 1) * (tubefacets + 1));
       faces[id][3] = (i + 1) + (j * (tubefacets + 1));
       id++;
     }
   }
   /*
    * for (int i = 0; i < tubefacets; i++) { faces[id] = new int[4];
    * faces[id][0] = i + ((torusfacets - 1) * (tubefacets + 1));
    * faces[id][1] = (i + twist) % (tubefacets + 1) + (torusfacets *
    * (tubefacets + 1)); faces[id][2] = (i + twist + 1) % (tubefacets + 1)
    * + (torusfacets * (tubefacets + 1)); faces[id][3] = (i + 1) +
    * ((torusfacets - 1) * (tubefacets + 1)); id++; }
    */
   final HEC_FromFacelist fl = new HEC_FromFacelist();
   fl.setVertices(vertices).setFaces(faces).setUVW(uvws);
   return fl.createBase();
 }
コード例 #3
0
ファイル: HE_Face.java プロジェクト: theomission/HE_Mesh2014
 /** @return */
 public WB_Coord getFaceCenter() {
   if (_halfedge == null) {
     return null;
   }
   HE_Halfedge he = _halfedge;
   final WB_Point _center = new WB_Point();
   int c = 0;
   do {
     _center.addSelf(he.getVertex());
     c++;
     he = he.getNextInFace();
   } while (he != _halfedge);
   _center.divSelf(c);
   return new WB_Point(_center);
 }
コード例 #4
0
ファイル: HE_Face.java プロジェクト: theomission/HE_Mesh2014
 /**
  * @param d
  * @return
  */
 public WB_Plane getPlane(final double d) {
   final WB_Coord fn = getFaceNormal();
   return new WB_Plane(WB_Point.addMul(getFaceCenter(), d, fn), fn);
 }
コード例 #5
0
  @Override
  public HE_Mesh apply(final HE_Mesh mesh) {
    if (mesh.selectAllBoundaryEdges().numberOfEdges() > 0) {
      throw new IllegalArgumentException("HES_DooSabin only supports closed meshes at this time.");
    }
    Iterator<HE_Face> fItr = mesh.fItr();
    final FastMap<Integer, Integer> halfedgeCorrelation = new FastMap<Integer, Integer>();
    final ArrayList<WB_Point> newVertices = new ArrayList<WB_Point>();
    HE_Face f;
    HE_Halfedge he;
    WB_Point fc;
    int vertexCount = 0;
    double div = 1.0 + 2.0 * edgeFactor + faceFactor;

    if (WB_Epsilon.isZero(div)) {
      div = 1.0;
    }
    if (absolute) {
      div = 4.0;
    }
    while (fItr.hasNext()) {
      f = fItr.next();
      he = f.getHalfedge();
      fc = f.getFaceCenter();
      do {
        final WB_Point p = fc.multAndCopy(faceFactor);
        p.add(he.getVertex());
        p.add(he.getHalfedgeCenter().multAndCopy(edgeFactor));
        p.add(he.getPrevInFace().getHalfedgeCenter().multAndCopy(edgeFactor));
        p.div(div);
        if (absolute) {
          final double dcurrent = WB_Distance.distance(p, he.getVertex());
          p.sub(he.getVertex());
          p.mult(d / dcurrent);
          p.add(he.getVertex());
        }

        halfedgeCorrelation.put(he.key(), vertexCount);
        vertexCount++;

        newVertices.add(p);
        he = he.getNextInFace();
      } while (he != f.getHalfedge());
    }
    final int[][] faces =
        new int[mesh.numberOfFaces() + mesh.numberOfEdges() + mesh.numberOfVertices()][];
    final int[] labels =
        new int[mesh.numberOfFaces() + mesh.numberOfEdges() + mesh.numberOfVertices()];
    final int[] noe = {mesh.numberOfFaces(), mesh.numberOfEdges(), mesh.numberOfVertices()};
    int currentFace = 0;
    fItr = mesh.fItr();
    while (fItr.hasNext()) {
      f = fItr.next();
      faces[currentFace] = new int[f.getFaceOrder()];
      he = f.getHalfedge();
      int i = 0;
      labels[currentFace] = currentFace;
      do {
        faces[currentFace][i] = halfedgeCorrelation.get(he.key());
        he = he.getNextInFace();
        i++;
      } while (he != f.getHalfedge());
      currentFace++;
    }
    final Iterator<HE_Edge> eItr = mesh.eItr();
    HE_Edge e;
    int currentEdge = 0;
    while (eItr.hasNext()) {

      e = eItr.next();
      faces[currentFace] = new int[4];
      faces[currentFace][3] = halfedgeCorrelation.get(e.getHalfedge().key());
      faces[currentFace][2] = halfedgeCorrelation.get(e.getHalfedge().getNextInFace().key());
      faces[currentFace][1] = halfedgeCorrelation.get(e.getHalfedge().getPair().key());
      faces[currentFace][0] =
          halfedgeCorrelation.get(e.getHalfedge().getPair().getNextInFace().key());
      labels[currentFace] = currentEdge;
      currentEdge++;
      currentFace++;
    }
    final Iterator<HE_Vertex> vItr = mesh.vItr();
    HE_Vertex v;
    int currentVertex = 0;
    while (vItr.hasNext()) {
      v = vItr.next();
      faces[currentFace] = new int[v.getVertexOrder()];
      he = v.getHalfedge();
      int i = v.getVertexOrder() - 1;
      do {
        faces[currentFace][i] = halfedgeCorrelation.get(he.key());
        he = he.getNextInVertex();
        i--;
      } while (he != v.getHalfedge());
      labels[currentFace] = currentVertex;
      currentVertex++;
      currentFace++;
    }
    final HEC_FromFacelist fl =
        new HEC_FromFacelist().setFaces(faces).setVertices(newVertices).setDuplicate(false);
    mesh.set(fl.create());
    fItr = mesh.fItr();
    currentFace = 0;
    faceFaces = new HE_Selection(mesh);
    edgeFaces = new HE_Selection(mesh);
    vertexFaces = new HE_Selection(mesh);
    while (fItr.hasNext()) {
      f = fItr.next();
      f.setLabel(labels[currentFace]);
      if (currentFace < noe[0]) {
        faceFaces.add(f);
      } else if (currentFace < noe[0] + noe[1]) {
        edgeFaces.add(f);
      } else {
        vertexFaces.add(f);
      }
      currentFace++;
    }

    return mesh;
  }