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()); } }
/* * (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(); }