Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/NeuronRobotics/JCSG.git
Browse files Browse the repository at this point in the history
 into development
  • Loading branch information
Kevin Harrington committed Oct 23, 2024
2 parents 52948fb + 830cd15 commit 4b0b1f9
Show file tree
Hide file tree
Showing 13 changed files with 786 additions and 255 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/testSpline.svg
/CSGdatabase.json
/*.stl
/*.svg
/Test.svg
out

/*.mtl
Expand All @@ -26,3 +26,4 @@ html
/handmade.step
/test-export-2.step
/test-export.step
/Part-Num-0.svg.png
136 changes: 136 additions & 0 deletions Part-Num-0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 32 additions & 18 deletions src/main/java/com/piro/bezier/BezierPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import eu.mihosoft.vrl.v3d.Plane;
import eu.mihosoft.vrl.v3d.Vector3d;

public class BezierPath {
Expand All @@ -14,7 +15,7 @@ public class BezierPath {

BezierListProducer path;

private ArrayList<Vector3d> pointList = new ArrayList<Vector3d>();
private ArrayList<Vector3d> plInternal = new ArrayList<Vector3d>();
double resolution = 0.075;

/** Creates a new instance of Animate */
Expand Down Expand Up @@ -60,97 +61,97 @@ protected void parsePathList(String list) {
x = nextFloat(tokens);
y = nextFloat(tokens);
path.movetoAbs(x, y);
pointList.add(new Vector3d(x, y, 0));
setThePoint(new Vector3d(x, y, 0));
curCmd = 'L';
break;
case 'm':
x = nextFloat(tokens);
y = nextFloat(tokens);
path.movetoRel(x, y);
pointList.add(new Vector3d(x, y, 0));
setThePoint(new Vector3d(x, y, 0));
curCmd = 'l';
break;
case 'L':
path.linetoAbs(nextFloat(tokens), nextFloat(tokens));
pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(1));
setThePoint(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(1));
break;
case 'l':
path.linetoRel(nextFloat(tokens), nextFloat(tokens));
pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(1));
setThePoint(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(1));
break;
case 'H':
path.linetoHorizontalAbs(nextFloat(tokens));

pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(1));
setThePoint(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(1));

break;
case 'h':
path.linetoHorizontalRel(nextFloat(tokens));

pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(1));
setThePoint(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(1));

break;
case 'V':
path.linetoVerticalAbs(nextFloat(tokens));

pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(1));
setThePoint(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(1));

break;
case 'v':
path.linetoVerticalAbs(nextFloat(tokens));
pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(1));
setThePoint(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(1));
break;
case 'A':
case 'a':
break;
case 'Q':
path.curvetoQuadraticAbs(nextFloat(tokens), nextFloat(tokens), nextFloat(tokens), nextFloat(tokens));
for (double i = resolution; i < 1; i += resolution) {
pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(i));
addingPoint(i);
}
break;
case 'q':
path.curvetoQuadraticAbs(nextFloat(tokens), nextFloat(tokens), nextFloat(tokens), nextFloat(tokens));
for (double i = resolution; i < 1; i += resolution) {
pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(i));
addingPoint(i);
}
break;
case 'T':
path.curvetoQuadraticSmoothAbs(nextFloat(tokens), nextFloat(tokens));
for (double i = resolution; i < 1; i += resolution) {
pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(i));
addingPoint(i);
}
break;
case 't':
path.curvetoQuadraticSmoothRel(nextFloat(tokens), nextFloat(tokens));
for (double i = resolution; i < 1; i += resolution) {
pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(i));
addingPoint(i);
}
break;
case 'C':
path.curvetoCubicAbs(nextFloat(tokens), nextFloat(tokens), nextFloat(tokens), nextFloat(tokens),
nextFloat(tokens), nextFloat(tokens));
for (double i = resolution; i < 1; i += resolution) {
pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(i));
addingPoint(i);
}
break;
case 'c':
path.curvetoCubicRel(nextFloat(tokens), nextFloat(tokens), nextFloat(tokens), nextFloat(tokens),
nextFloat(tokens), nextFloat(tokens));
for (double i = resolution; i < 1; i += resolution) {
pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(i));
addingPoint(i);
}
break;
case 'S':
path.curvetoCubicSmoothAbs(nextFloat(tokens), nextFloat(tokens), nextFloat(tokens), nextFloat(tokens));
for (double i = resolution; i < 1; i += resolution) {
pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(i));
addingPoint(i);
}
break;
case 's':
path.curvetoCubicSmoothRel(nextFloat(tokens), nextFloat(tokens), nextFloat(tokens), nextFloat(tokens));
for (double i = resolution; i < 1; i += resolution) {
pointList.add(path.bezierSegs.get(path.bezierSegs.size() - 1).eval(i));
addingPoint(i);
}
break;
case 'Z':
Expand All @@ -167,6 +168,19 @@ protected void parsePathList(String list) {
}
}

private boolean addingPoint(double i) {
Vector3d eval = path.bezierSegs.get(path.bezierSegs.size() - 1).eval(i);
return setThePoint(eval);
}

private boolean setThePoint(Vector3d eval) {
for(Vector3d v:plInternal) {
if(Math.abs(v.minus(eval).magnitude())<Plane.EPSILON)
return false;
}
return plInternal.add(eval);
}

static protected float nextFloat(LinkedList<String> l) {
String s = l.removeFirst();
return Float.parseFloat(s);
Expand Down Expand Up @@ -206,7 +220,7 @@ public Vector3d eval(float interp) {
*/
public ArrayList<Vector3d> evaluate() {

return pointList;
return plInternal;
}

}
6 changes: 3 additions & 3 deletions src/main/java/eu/mihosoft/vrl/v3d/Edge.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static Polygon toPolygon(List<Vector3d> points, Plane plane) {
Polygon p = Polygon.fromPoints(points);

p.vertices.stream().forEachOrdered((vertex) -> {
vertex.normal = plane.normal.clone();
vertex.normal = plane.getNormal().clone();
});

// // we try to detect wrong orientation by comparing normals
Expand Down Expand Up @@ -897,8 +897,8 @@ private static List<List<Polygon>> searchPlaneGroups(List<Polygon> polygons) {
continue;
}

Vector3d nOuter = pOuter.plane.normal;
Vector3d nInner = pInner.plane.normal;
Vector3d nOuter = pOuter.plane.getNormal();
Vector3d nInner = pInner.plane.getNormal();

double angle = nOuter.angle(nInner);

Expand Down
16 changes: 12 additions & 4 deletions src/main/java/eu/mihosoft/vrl/v3d/Extrude.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ private CSG monotoneExtrude(Vector3d dir, Polygon polygon1) {
Polygon polygon2 = polygon1.translated(dir);

int numvertices = polygon1.vertices.size();
System.out.println("Building Polygon "+polygon1.getPoints().size());
for (int i = 0; i < numvertices; i++) {

int nexti = (i + 1) % numvertices;
Expand All @@ -98,11 +99,18 @@ private CSG monotoneExtrude(Vector3d dir, Polygon polygon1) {
Vector3d topV1 = polygon2.vertices.get(i).pos;
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) {
System.out.println("Skipping invalid polygon "+i+" to "+nexti);
continue;
}
List<Vector3d> pPoints = Arrays.asList(bottomV2, topV2, topV1, bottomV1);

newPolygons.add(Polygon.fromPoints(pPoints, polygon1.getStorage()));

try {
newPolygons.add(Polygon.fromPoints(pPoints, polygon1.getStorage()));
}catch(Exception ex) {
System.out.println("Polygon has problems: ");
ex.printStackTrace();
}
}

polygon2 = polygon2.flipped();
Expand Down
Loading

0 comments on commit 4b0b1f9

Please sign in to comment.