Skip to content

Commit

Permalink
SVG loading should detect if a polygon is a hole when the polygon is
Browse files Browse the repository at this point in the history
created.
  • Loading branch information
madhephaestus committed Dec 27, 2024
1 parent 552527a commit df2dfc7
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ html
/SVGExportTest5.svg
/box.svg.png
/brokenSTL.STL.png
/InsideOutsideTest.svg.png
102 changes: 102 additions & 0 deletions InsideOutsideTest.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions src/main/java/eu/mihosoft/vrl/v3d/Polygon.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public final class Polygon {
* Note: uses first three vertices to define the plane.
*/
public Plane plane;

private boolean isHole = false;

/**
* Sets the storage.
Expand Down Expand Up @@ -191,7 +191,6 @@ private void validateAndInit( boolean allowDegenerate) {
// throw runtimeException;
new RuntimeException("This polygon is colinear").printStackTrace();
}

}
/**
* Constructor. Creates a new polygon that consists of the specified
Expand Down Expand Up @@ -748,4 +747,12 @@ public String toString() {
return ret+" ] ";
}

public boolean isHole() {
return isHole;
}

public void setHole(boolean isHole) {
this.isHole = isHole;
}

}
11 changes: 10 additions & 1 deletion src/main/java/eu/mihosoft/vrl/v3d/svg/SVGLoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -637,15 +637,18 @@ private void loadSingle(String code, double resolution, Transform startingFrame,
point.transform(new Transform().rotZ(-180));
point.transform(new Transform().rotY(180));
}

// //com.neuronrobotics.sdk.common.Log.error(" Path " + code);
Polygon poly = Polygon.fromPoints(p);
boolean hole = !Extrude.isCCW(poly);
if (getPolygonByLayers() == null)
setPolygonByLayers(new HashMap<String, List<Polygon>>());
if (getPolygonByLayers().get(encapsulatingLayer) == null)
getPolygonByLayers().put(encapsulatingLayer, new ArrayList<Polygon>());
List<Polygon> list = getPolygonByLayers().get(encapsulatingLayer);

poly = Polygon.fromPoints(Extrude.toCCW(poly.getPoints()));
poly.setHole(hole);
if (c != null)
colors.put(poly, c);
list.add(poly);
Expand Down Expand Up @@ -699,6 +702,7 @@ public HashMap<String, ArrayList<CSG>> extrudeLayers(double t, double resolution
ArrayList<CSG> parts = csgByLayers.get(key);
parts.clear();
for (Polygon p : getPolygonByLayers().get(key)) {
boolean isHole =p.isHole();
CSG newbit;
try {
newbit = Extrude.getExtrusionEngine().extrude(new Vector3d(0, 0, thickness), p);
Expand All @@ -708,6 +712,11 @@ public HashMap<String, ArrayList<CSG>> extrudeLayers(double t, double resolution
if (colors.get(p) != null) {
newbit.setColor(colors.get(p));
}
if(isHole) {
//newbit=newbit.movez(negativeThickness?0.5:-0.5);
newbit.setIsHole(true);
newbit.setColor(Color.BLACK);
}
parts.add(newbit);
} catch (Exception ex) {
//ex.printStackTrace();
Expand Down
20 changes: 17 additions & 3 deletions src/test/java/eu/mihosoft/vrl/v3d/SVGLoadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,22 @@ public void box() throws IOException {
// Auto-generated catch block
e.printStackTrace();
}

// fail("Not yet implemented");
}
@Test
public void inside() throws IOException {
JavaFXInitializer.go();
File svg = new File("InsideOutsideTest.svg");
if (!svg.exists())
throw new RuntimeException("Test file missing!" + svg.getAbsolutePath());
SVGLoad s = new SVGLoad(svg.toURI());
ArrayList<CSG>parts =run(s);
try {
ThumbnailImage.setCullFaceValue(CullFace.NONE);
ThumbnailImage.writeImage(parts,new File(svg.getAbsolutePath()+".png")).join();
} catch (InterruptedException e) {
// Auto-generated catch block
e.printStackTrace();
}
}
@Test
public void adversarial() throws IOException {
Expand Down Expand Up @@ -82,7 +96,7 @@ private ArrayList<CSG> run(SVGLoad s) {
//System.out.println("Adding layer: "+key);
ArrayList<CSG> csgs = extrudeLayerToCSG.get(key);
if(csgs.size()>0)
polys.add(CSG.unionAll(csgs));
polys.addAll(csgs);
// for(CSG c:extrudeLayerToCSG.get(key)) {
// polys.add(c);
// }
Expand Down

0 comments on commit df2dfc7

Please sign in to comment.