Permalink
Browse files

Corrected version in WB_Version

  • Loading branch information...
1 parent d8f3755 commit 1e69c936d7e583d2262c3e7614a8af8ffa033f1b @wblut committed Feb 5, 2017
Showing with 173 additions and 2 deletions.
  1. +2 −2 src/wblut/core/WB_Version.java
  2. +171 −0 src_hemesh_tools/wblut/hemesh/HET_Contours.java
@@ -18,7 +18,7 @@
public static final int MINOR = 0;
- public static final int PATCH = 1;
+ public static final int PATCH = 2;
private static final String releaseInfo = "Reboot";
@@ -66,7 +66,7 @@ public static int getPatch() {
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#toString()
*/
@Override
@@ -0,0 +1,171 @@
+/**
+* Base on Paul Bourke's CONREC routine: http://paulbourke.net/papers/conrec/
+ *
+ */
+package wblut.hemesh;
+
+import java.util.List;
+
+import javolution.util.FastTable;
+import wblut.geom.WB_Coord;
+import wblut.geom.WB_Plane;
+import wblut.geom.WB_Point;
+import wblut.geom.WB_Segment;
+
+/**
+ * @author FVH
+ *
+ */
+public class HET_Contours {
+
+ public static List<WB_Segment> contours(final HE_Mesh mesh, final WB_Plane P) {
+ double A, B, C, D;
+ double[] side = new double[3];
+ List<WB_Segment> segments = new FastTable<WB_Segment>();
+
+ A = P.getNormal().xd();
+ B = P.getNormal().yd();
+ C = P.getNormal().zd();
+ D = P.d();
+
+ WB_Coord p, q, r;
+ WB_Point p1, p2;
+ HE_Mesh lmesh = mesh;
+ lmesh.triangulate();
+
+ HE_Face f;
+ HE_FaceIterator fItr = lmesh.fItr();
+ while (fItr.hasNext()) {
+ f = fItr.next();
+ p = f.getHalfedge().getVertex();
+ q = f.getHalfedge().getEndVertex();
+ r = f.getHalfedge().getNextInFace().getEndVertex();
+ p1 = new WB_Point();
+ p2 = new WB_Point();
+
+ side[0] = A * p.xd() + B * p.yd() + C * p.zd() + D;
+ side[1] = A * q.xd() + B * q.yd() + C * q.zd() + D;
+ side[2] = A * r.xd() + B * r.yd() + C * r.zd() + D;
+
+ /* Are all the vertices on the same side */
+ if (side[0] >= 0 && side[1] >= 0 && side[2] >= 0) {
+ continue;
+ }
+ if (side[0] <= 0 && side[1] <= 0 && side[2] <= 0) {
+ continue;
+ }
+
+ /* Is p0 the only point on a side by itself */
+ if (Math.signum(side[0]) != Math.signum(side[1]) && Math.signum(side[0]) != Math.signum(side[2])) {
+ p1.set(p.xd() - side[0] * (r.xd() - p.xd()) / (side[2] - side[0]),
+ p.yd() - side[0] * (r.yd() - p.yd()) / (side[2] - side[0]),
+ p.zd() - side[0] * (r.zd() - p.zd()) / (side[2] - side[0]));
+ p2.set(p.xd() - side[0] * (q.xd() - p.xd()) / (side[1] - side[0]),
+ p.yd() - side[0] * (q.yd() - p.yd()) / (side[1] - side[0]),
+ p.zd() - side[0] * (q.zd() - p.zd()) / (side[1] - side[0]));
+ segments.add(new WB_Segment(p1, p2));
+ }
+
+ /* Is p1 the only point on a side by itself */
+ if (Math.signum(side[1]) != Math.signum(side[0]) && Math.signum(side[1]) != Math.signum(side[2])) {
+ p1.set(q.xd() - side[1] * (r.xd() - q.xd()) / (side[2] - side[1]),
+ q.yd() - side[1] * (r.yd() - q.yd()) / (side[2] - side[1]),
+ q.zd() - side[1] * (r.zd() - q.zd()) / (side[2] - side[1]));
+ p2.set(q.xd() - side[1] * (p.xd() - q.xd()) / (side[0] - side[1]),
+ q.yd() - side[1] * (p.yd() - q.yd()) / (side[0] - side[1]),
+ q.zd() - side[1] * (p.zd() - q.zd()) / (side[0] - side[1]));
+ segments.add(new WB_Segment(p1, p2));
+ }
+
+ /* Is p2 the only point on a side by itself */
+ if (Math.signum(side[2]) != Math.signum(side[0]) && Math.signum(side[2]) != Math.signum(side[1])) {
+ p1.set(r.xd() - side[2] * (p.xd() - r.xd()) / (side[0] - side[2]),
+ r.yd() - side[2] * (p.yd() - r.yd()) / (side[0] - side[2]),
+ r.zd() - side[2] * (p.zd() - r.zd()) / (side[0] - side[2]));
+ p2.set(r.xd() - side[2] * (q.xd() - r.xd()) / (side[1] - side[2]),
+ r.yd() - side[2] * (q.yd() - r.yd()) / (side[1] - side[2]),
+ r.zd() - side[2] * (q.zd() - r.zd()) / (side[1] - side[2]));
+ segments.add(new WB_Segment(p1, p2));
+ }
+ }
+ return segments;
+ }
+
+ public static List<WB_Segment> contours(final HE_Mesh mesh, final WB_Plane P, final double min, final double max,
+ final double step) {
+ double A, B, C, D;
+ double[] side = new double[3];
+ List<WB_Segment> segments = new FastTable<WB_Segment>();
+ double start = Math.min(min, max);
+ double end = Math.max(min, max);
+ double inc = Math.abs(step);
+ WB_Coord p, q, r;
+ WB_Point p1, p2;
+ A = P.getNormal().xd();
+ B = P.getNormal().yd();
+ C = P.getNormal().zd();
+ HE_Mesh lmesh = mesh;
+ lmesh.triangulate();
+ for (double offset = start; offset <= end; offset += inc) {
+ WB_Plane offsetP = new WB_Plane(P.getOrigin().addMul(offset, P.getNormal()), P.getNormal());
+ D = offsetP.d();
+
+ HE_Face f;
+ HE_FaceIterator fItr = lmesh.fItr();
+ while (fItr.hasNext()) {
+ f = fItr.next();
+ p = f.getHalfedge().getVertex();
+ q = f.getHalfedge().getEndVertex();
+ r = f.getHalfedge().getNextInFace().getEndVertex();
+ p1 = new WB_Point();
+ p2 = new WB_Point();
+
+ side[0] = A * p.xd() + B * p.yd() + C * p.zd() + D;
+ side[1] = A * q.xd() + B * q.yd() + C * q.zd() + D;
+ side[2] = A * r.xd() + B * r.yd() + C * r.zd() + D;
+
+ /* Are all the vertices on the same side */
+ if (side[0] >= 0 && side[1] >= 0 && side[2] >= 0) {
+ continue;
+ }
+ if (side[0] <= 0 && side[1] <= 0 && side[2] <= 0) {
+ continue;
+ }
+
+ /* Is p0 the only point on a side by itself */
+ if (Math.signum(side[0]) != Math.signum(side[1]) && Math.signum(side[0]) != Math.signum(side[2])) {
+ p1.set(p.xd() - side[0] * (r.xd() - p.xd()) / (side[2] - side[0]),
+ p.yd() - side[0] * (r.yd() - p.yd()) / (side[2] - side[0]),
+ p.zd() - side[0] * (r.zd() - p.zd()) / (side[2] - side[0]));
+ p2.set(p.xd() - side[0] * (q.xd() - p.xd()) / (side[1] - side[0]),
+ p.yd() - side[0] * (q.yd() - p.yd()) / (side[1] - side[0]),
+ p.zd() - side[0] * (q.zd() - p.zd()) / (side[1] - side[0]));
+ segments.add(new WB_Segment(p1, p2));
+ }
+
+ /* Is p1 the only point on a side by itself */
+ if (Math.signum(side[1]) != Math.signum(side[0]) && Math.signum(side[1]) != Math.signum(side[2])) {
+ p1.set(q.xd() - side[1] * (r.xd() - q.xd()) / (side[2] - side[1]),
+ q.yd() - side[1] * (r.yd() - q.yd()) / (side[2] - side[1]),
+ q.zd() - side[1] * (r.zd() - q.zd()) / (side[2] - side[1]));
+ p2.set(q.xd() - side[1] * (p.xd() - q.xd()) / (side[0] - side[1]),
+ q.yd() - side[1] * (p.yd() - q.yd()) / (side[0] - side[1]),
+ q.zd() - side[1] * (p.zd() - q.zd()) / (side[0] - side[1]));
+ segments.add(new WB_Segment(p1, p2));
+ }
+
+ /* Is p2 the only point on a side by itself */
+ if (Math.signum(side[2]) != Math.signum(side[0]) && Math.signum(side[2]) != Math.signum(side[1])) {
+ p1.set(r.xd() - side[2] * (p.xd() - r.xd()) / (side[0] - side[2]),
+ r.yd() - side[2] * (p.yd() - r.yd()) / (side[0] - side[2]),
+ r.zd() - side[2] * (p.zd() - r.zd()) / (side[0] - side[2]));
+ p2.set(r.xd() - side[2] * (q.xd() - r.xd()) / (side[1] - side[2]),
+ r.yd() - side[2] * (q.yd() - r.yd()) / (side[1] - side[2]),
+ r.zd() - side[2] * (q.zd() - r.zd()) / (side[1] - side[2]));
+ segments.add(new WB_Segment(p1, p2));
+ }
+ }
+ }
+ return segments;
+ }
+}

0 comments on commit 1e69c93

Please sign in to comment.