Skip to content

Commit df2dfc7

Browse files
committed
SVG loading should detect if a polygon is a hole when the polygon is
created.
1 parent 552527a commit df2dfc7

File tree

5 files changed

+139
-6
lines changed

5 files changed

+139
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ html
3434
/SVGExportTest5.svg
3535
/box.svg.png
3636
/brokenSTL.STL.png
37+
/InsideOutsideTest.svg.png

InsideOutsideTest.svg

Lines changed: 102 additions & 0 deletions
Loading

src/main/java/eu/mihosoft/vrl/v3d/Polygon.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public final class Polygon {
6363
* Note: uses first three vertices to define the plane.
6464
*/
6565
public Plane plane;
66-
66+
private boolean isHole = false;
6767

6868
/**
6969
* Sets the storage.
@@ -191,7 +191,6 @@ private void validateAndInit( boolean allowDegenerate) {
191191
// throw runtimeException;
192192
new RuntimeException("This polygon is colinear").printStackTrace();
193193
}
194-
195194
}
196195
/**
197196
* Constructor. Creates a new polygon that consists of the specified
@@ -748,4 +747,12 @@ public String toString() {
748747
return ret+" ] ";
749748
}
750749

750+
public boolean isHole() {
751+
return isHole;
752+
}
753+
754+
public void setHole(boolean isHole) {
755+
this.isHole = isHole;
756+
}
757+
751758
}

src/main/java/eu/mihosoft/vrl/v3d/svg/SVGLoad.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,15 +637,18 @@ private void loadSingle(String code, double resolution, Transform startingFrame,
637637
point.transform(new Transform().rotZ(-180));
638638
point.transform(new Transform().rotY(180));
639639
}
640-
640+
641641
// //com.neuronrobotics.sdk.common.Log.error(" Path " + code);
642642
Polygon poly = Polygon.fromPoints(p);
643+
boolean hole = !Extrude.isCCW(poly);
643644
if (getPolygonByLayers() == null)
644645
setPolygonByLayers(new HashMap<String, List<Polygon>>());
645646
if (getPolygonByLayers().get(encapsulatingLayer) == null)
646647
getPolygonByLayers().put(encapsulatingLayer, new ArrayList<Polygon>());
647648
List<Polygon> list = getPolygonByLayers().get(encapsulatingLayer);
649+
648650
poly = Polygon.fromPoints(Extrude.toCCW(poly.getPoints()));
651+
poly.setHole(hole);
649652
if (c != null)
650653
colors.put(poly, c);
651654
list.add(poly);
@@ -699,6 +702,7 @@ public HashMap<String, ArrayList<CSG>> extrudeLayers(double t, double resolution
699702
ArrayList<CSG> parts = csgByLayers.get(key);
700703
parts.clear();
701704
for (Polygon p : getPolygonByLayers().get(key)) {
705+
boolean isHole =p.isHole();
702706
CSG newbit;
703707
try {
704708
newbit = Extrude.getExtrusionEngine().extrude(new Vector3d(0, 0, thickness), p);
@@ -708,6 +712,11 @@ public HashMap<String, ArrayList<CSG>> extrudeLayers(double t, double resolution
708712
if (colors.get(p) != null) {
709713
newbit.setColor(colors.get(p));
710714
}
715+
if(isHole) {
716+
//newbit=newbit.movez(negativeThickness?0.5:-0.5);
717+
newbit.setIsHole(true);
718+
newbit.setColor(Color.BLACK);
719+
}
711720
parts.add(newbit);
712721
} catch (Exception ex) {
713722
//ex.printStackTrace();

src/test/java/eu/mihosoft/vrl/v3d/SVGLoadTest.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,22 @@ public void box() throws IOException {
3030
// Auto-generated catch block
3131
e.printStackTrace();
3232
}
33-
34-
// fail("Not yet implemented");
33+
}
34+
@Test
35+
public void inside() throws IOException {
36+
JavaFXInitializer.go();
37+
File svg = new File("InsideOutsideTest.svg");
38+
if (!svg.exists())
39+
throw new RuntimeException("Test file missing!" + svg.getAbsolutePath());
40+
SVGLoad s = new SVGLoad(svg.toURI());
41+
ArrayList<CSG>parts =run(s);
42+
try {
43+
ThumbnailImage.setCullFaceValue(CullFace.NONE);
44+
ThumbnailImage.writeImage(parts,new File(svg.getAbsolutePath()+".png")).join();
45+
} catch (InterruptedException e) {
46+
// Auto-generated catch block
47+
e.printStackTrace();
48+
}
3549
}
3650
@Test
3751
public void adversarial() throws IOException {
@@ -82,7 +96,7 @@ private ArrayList<CSG> run(SVGLoad s) {
8296
//System.out.println("Adding layer: "+key);
8397
ArrayList<CSG> csgs = extrudeLayerToCSG.get(key);
8498
if(csgs.size()>0)
85-
polys.add(CSG.unionAll(csgs));
99+
polys.addAll(csgs);
86100
// for(CSG c:extrudeLayerToCSG.get(key)) {
87101
// polys.add(c);
88102
// }

0 commit comments

Comments
 (0)