Skip to content

Commit

Permalink
Make the epsilon values adjustable
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Harrington committed Nov 18, 2024
1 parent a0e2e03 commit b44276a
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/piro/bezier/BezierPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private boolean addingPoint(double i) {

private boolean setThePoint(Vector3d eval) {
for(Vector3d v:plInternal) {
if(Math.abs(v.minus(eval).magnitude())<Plane.EPSILON)
if(Math.abs(v.minus(eval).magnitude())<Plane.getEPSILON())
return false;
}
return plInternal.add(eval);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/eu/mihosoft/vrl/v3d/CSG.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public class CSG implements IuserAPI {
private boolean triangulated;
private static boolean needsDegeneratesPruned = false;
private static boolean useStackTraces = true;
private static boolean preventNonManifoldTriangles = true;
private static boolean preventNonManifoldTriangles = false;

private static ICSGProgress progressMoniter = new ICSGProgress() {
@Override
Expand Down Expand Up @@ -1532,7 +1532,7 @@ public CSG triangulate(boolean fix) {
continue;
// if the point is on the line then we have a non manifold point
// it needs to be inserted into the polygon between the 2 points defined in the edge
if (e.contains(vi.pos, Plane.EPSILON)) {
if (e.contains(vi.pos, Plane.getEPSILON())) {
// System.out.println("Inserting point "+vi);
vert.add(next, vi);
totalAdded++;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/eu/mihosoft/vrl/v3d/Edge.java
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ public boolean contains(Vector3d p, double TOL) {
* segment; <code>false</code> otherwise
*/
public boolean contains(Vector3d p) {
return contains(p, Plane.EPSILON);
return contains(p, Plane.getEPSILON());
}

/* (non-Javadoc)
Expand Down Expand Up @@ -674,7 +674,7 @@ public Optional<Vector3d> getClosestPoint(Edge e) {
double cos = ourDir.dot(e.getDirection());
double n = 1 - cos * cos;

if (n < Plane.EPSILON) {
if (n < Plane.getEPSILON()) {
// the lines are parallel
return Optional.empty();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/eu/mihosoft/vrl/v3d/Extrude.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private CSG monotoneExtrude(Vector3d dir, Polygon polygon1) {
Vector3d bottomV2 = polygon1.vertices.get(nexti).pos;
Vector3d topV2 = polygon2.vertices.get(nexti).pos;
double distance = bottomV1.minus(bottomV2).magnitude();
if(Math.abs(distance)<Plane.EPSILON) {
if(Math.abs(distance)<Plane.getEPSILON()) {
//com.neuronrobotics.sdk.common.Log.error("Skipping invalid polygon "+i+" to "+nexti);
continue;
}
Expand Down
28 changes: 18 additions & 10 deletions src/main/java/eu/mihosoft/vrl/v3d/Plane.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public class Plane {
* 0.00000001;
*/

public static final double EPSILON = 1.0e-11;
public static final double EPSILON_Point = EPSILON;
public static final double EPSILON_duplicate = 1.0e-4;
public static double EPSILON = 1.0e-9;
public static double EPSILON_Point = getEPSILON();
public static double EPSILON_duplicate = 1.0e-4;
/**
* XY plane.
*/
Expand Down Expand Up @@ -122,12 +122,12 @@ public static Vector3d computeNormal(List<Vertex> vertices) {
normal.z += (current.x - next.x) * (current.y + next.y);
if (n >= 3) {
Vector3d normalized = normal.normalized();
if (isValidNormal(normalized, EPSILON / 10)) {
if (isValidNormal(normalized, getEPSILON() / 10)) {
lastValid = normalized;
}
}
}
if (isValidNormal(lastValid, EPSILON / 10)) {
if (isValidNormal(lastValid, getEPSILON() / 10)) {
return lastValid;
}
throw new RuntimeException("Mesh has problems, can not work around it");
Expand Down Expand Up @@ -168,7 +168,7 @@ private static Vector3d findNormalFromNonColinearPoints(List<Vertex> vertices) {
for (int j = i + 1; j < n; j++) {
Vector3d v2 = vertices.get(j).pos.minus(firstPoint);
Vector3d cross = v1.cross(v2);
if (isValidNormal(cross, EPSILON)) {
if (isValidNormal(cross, getEPSILON())) {
return cross.normalized();
}
}
Expand Down Expand Up @@ -339,19 +339,19 @@ public void splitPolygon(Polygon polygon, List<Polygon> coplanarFront, List<Poly
// debugger.display(back);
}
// search for the epsilon values of the incoming plane
double negEpsilon = -Plane.EPSILON;
double posEpsilon = Plane.EPSILON;
double negEpsilon = -Plane.getEPSILON();
double posEpsilon = Plane.getEPSILON();
for (int i = 0; i < polygon.vertices.size(); i++) {
double t = polygon.plane.getNormal().dot(polygon.vertices.get(i).pos) - polygon.plane.getDist();
if (t > posEpsilon) {
// com.neuronrobotics.sdk.common.Log.error("Non flat polygon, increasing
// positive epsilon "+t);
posEpsilon = t + Plane.EPSILON;
posEpsilon = t + Plane.getEPSILON();
}
if (t < negEpsilon) {
// com.neuronrobotics.sdk.common.Log.error("Non flat polygon, decreasing
// negative epsilon "+t);
negEpsilon = t - Plane.EPSILON;
negEpsilon = t - Plane.getEPSILON();
}
}
int polygonType = 0;
Expand Down Expand Up @@ -477,4 +477,12 @@ public void setDist(double dist) {
throw numberFormatException;
}
}

public static double getEPSILON() {
return EPSILON;
}

public static void setEPSILON(double ePSILON) {
EPSILON = ePSILON;
}
}
26 changes: 21 additions & 5 deletions src/main/java/eu/mihosoft/vrl/v3d/Vector3d.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
public class Vector3d extends javax.vecmath.Vector3d{


private static final String exportString = "%.16f";
private static String exportString = "%.16f";

private static final double EXPORTEPSILON = 1.0e-12;
private static double EXPORTEPSILON =Plane.EPSILON*10;

/**
*
Expand Down Expand Up @@ -320,7 +320,7 @@ public String toStlString() {
* @return the specified string builder
*/
public StringBuilder toStlString(StringBuilder sb) {
double ep = EXPORTEPSILON;
double ep = getEXPORTEPSILON();
return sb.append(roundedValue(x, ep)).append(" ").
append(roundedValue(y, ep)).append(" ").
append(roundedValue(z, ep));
Expand Down Expand Up @@ -350,7 +350,7 @@ public String toObjString() {
* @return the specified string builder
*/
public StringBuilder toObjString(StringBuilder sb) {
double ep = EXPORTEPSILON;
double ep = getEXPORTEPSILON();
return sb.append(roundedValue(x, ep)).append(" ").
append(roundedValue(y, ep)).append(" ").
append(roundedValue(z, ep));
Expand All @@ -366,7 +366,7 @@ private double roundToEpsilon(double value,double epsilon) {
return ((double)Math.round(value / epsilon)) * epsilon;
}
private String roundedValue(double v,double ep) {
return String.format(exportString, roundToEpsilon(v,ep));
return String.format(getExportString(), roundToEpsilon(v,ep));
}

/**
Expand Down Expand Up @@ -654,4 +654,20 @@ public Vector3d orthogonal() {
// return z;
// }

public static String getExportString() {
return exportString;
}

public static void setExportString(String exportString) {
Vector3d.exportString = exportString;
}

public static double getEXPORTEPSILON() {
return EXPORTEPSILON;
}

public static void setEXPORTEPSILON(double eXPORTEPSILON) {
EXPORTEPSILON = eXPORTEPSILON;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static List<Polygon> concaveToConvex(Polygon incoming) {
return result;
Polygon concave = incoming;
Vector3d normalOfPlane = incoming.plane.getNormal();
boolean reorent = normalOfPlane.z < 1.0 - Plane.EPSILON;
boolean reorent = normalOfPlane.z < 1.0 - Plane.getEPSILON();
Transform orentationInv = null;
boolean debug = false;
Vector3d normal = concave.plane.getNormal().clone();
Expand Down

0 comments on commit b44276a

Please sign in to comment.