Skip to content

Commit cf48f52

Browse files
committed
all updated to the new API
1 parent 3b46100 commit cf48f52

12 files changed

Lines changed: 122 additions & 119 deletions

File tree

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

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ public CSG setManipulator(javafx.scene.transform.Affine m) {
473473
* @return the mesh
474474
* @throws ColinearPointsException
475475
*/
476-
public MeshView getMesh() throws ColinearPointsException {
476+
public MeshView getMesh() {
477477
if (getCurrentMeshView() != null)
478478
return getCurrentMeshView();
479479
setCurrentMeshView(newMesh());
@@ -486,7 +486,7 @@ public MeshView getMesh() throws ColinearPointsException {
486486
* @return the mesh
487487
* @throws ColinearPointsException
488488
*/
489-
public MeshView newMesh() throws ColinearPointsException {
489+
public MeshView newMesh() {
490490

491491
MeshContainer meshContainer = toJavaFXMesh(null);
492492

@@ -1047,16 +1047,24 @@ public CSG union(CSG csg) {
10471047
* @return a csg consisting of the polygons of this csg and the specified csg
10481048
* @throws ColinearPointsException
10491049
*/
1050-
public CSG dumbUnion(CSG csg) throws ColinearPointsException {
1050+
public CSG dumbUnion(CSG csg) {
10511051
// boolean tri = triangulated && csg.triangulated;
10521052
CSG result = this.clone();
10531053
CSG other = csg.clone();
10541054

1055-
ArrayList<Polygon> polygonsFromMesh = result.generatePolygonsFromMesh();
1056-
polygonsFromMesh.addAll(other.generatePolygonsFromMesh());
1057-
bounds = null;
1058-
// result.triangulated = tri;
1059-
return new CSG(polygonsFromMesh).historySync(csg).historySync(this);
1055+
ArrayList<Polygon> polygonsFromMesh;
1056+
try {
1057+
polygonsFromMesh = result.generatePolygonsFromMesh();
1058+
polygonsFromMesh.addAll(other.generatePolygonsFromMesh());
1059+
bounds = null;
1060+
// result.triangulated = tri;
1061+
return new CSG(polygonsFromMesh).historySync(csg).historySync(this);
1062+
} catch (ColinearPointsException e) {
1063+
// TODO Auto-generated catch block
1064+
e.printStackTrace();
1065+
return this;
1066+
}
1067+
10601068
}
10611069

10621070
/**
@@ -1126,12 +1134,7 @@ public CSG union(List<CSG> incoming) {
11261134
if (dumb == null) {
11271135
dumb = test;
11281136
} else
1129-
try {
1130-
dumb = dumb.dumbUnion(test);
1131-
} catch (ColinearPointsException e) {
1132-
// TODO Auto-generated catch block
1133-
e.printStackTrace();
1134-
}
1137+
dumb = dumb.dumbUnion(test);
11351138
}
11361139

11371140
}
@@ -1166,12 +1169,7 @@ else if (solid == null && hole != null)
11661169
else
11671170
result = solid.difference(hole);
11681171
if (dumb != null) {
1169-
try {
1170-
result = result.dumbUnion(dumb);
1171-
} catch (ColinearPointsException e) {
1172-
// TODO Auto-generated catch block
1173-
e.printStackTrace();
1174-
}
1172+
result = result.dumbUnion(dumb);
11751173
}
11761174
return result;
11771175
}
@@ -1410,12 +1408,7 @@ private CSG _unionNoOpt(CSG csg) {
14101408
// TODO Auto-generated catch block
14111409
e.printStackTrace();
14121410
}
1413-
try {
1414-
return dumbUnion(csg);
1415-
} catch (ColinearPointsException e) {
1416-
e.printStackTrace();
1417-
return this;
1418-
}
1411+
return dumbUnion(csg);
14191412
}
14201413

14211414
/**
@@ -2545,7 +2538,7 @@ public CSG color(Color c) {
25452538
* @return the specified string builder
25462539
* @throws ColinearPointsException
25472540
*/
2548-
public StringBuilder toObjString(StringBuilder sb) throws ColinearPointsException {
2541+
public StringBuilder toObjString(StringBuilder sb) {
25492542
triangulate(true);
25502543
sb.append("# Group").append("\n");
25512544
sb.append("g v3d.csg\n");
@@ -2568,20 +2561,25 @@ public PolygonStruct(PropertyStorage storage, List<Integer> indices, String mate
25682561

25692562
sb.append("\n# Vertices\n");
25702563

2571-
for (Polygon p : generatePolygonsFromMesh()) {
2572-
List<Integer> polyIndices = new ArrayList<>();
2564+
try {
2565+
for (Polygon p : generatePolygonsFromMesh()) {
2566+
List<Integer> polyIndices = new ArrayList<>();
25732567

2574-
p.getVertices().stream().forEach((v) -> {
2575-
if (!vertices.contains(v)) {
2576-
vertices.add(v);
2577-
v.toObjString(sb);
2578-
polyIndices.add(vertices.size());
2579-
} else {
2580-
polyIndices.add(vertices.indexOf(v) + 1);
2581-
}
2582-
});
2583-
indices.add(new PolygonStruct(getStorage(), polyIndices, " "));
2568+
p.getVertices().stream().forEach((v) -> {
2569+
if (!vertices.contains(v)) {
2570+
vertices.add(v);
2571+
v.toObjString(sb);
2572+
polyIndices.add(vertices.size());
2573+
} else {
2574+
polyIndices.add(vertices.indexOf(v) + 1);
2575+
}
2576+
});
2577+
indices.add(new PolygonStruct(getStorage(), polyIndices, " "));
25842578

2579+
}
2580+
} catch (ColinearPointsException e) {
2581+
// TODO Auto-generated catch block
2582+
e.printStackTrace();
25852583
}
25862584
HashMap<Vertex, Integer> mapping = new HashMap<Vertex, Integer>();
25872585
HashMap<Transform, Vertex> mappingTF = new HashMap<>();
@@ -2633,7 +2631,7 @@ public PolygonStruct(PropertyStorage storage, List<Integer> indices, String mate
26332631
* @return this csg in OBJ string format
26342632
* @throws ColinearPointsException
26352633
*/
2636-
public String toObjString() throws ColinearPointsException {
2634+
public String toObjString() {
26372635
StringBuilder sb = new StringBuilder();
26382636
return toObjString(sb).toString();
26392637
}
@@ -2714,7 +2712,7 @@ public CSG transformed(Transform transform) {
27142712
* @throws ColinearPointsException
27152713
*/
27162714
// TODO finish experiment (20.7.2014)
2717-
public MeshContainer toJavaFXMesh(CadInteractionEvent interact) throws ColinearPointsException {
2715+
public MeshContainer toJavaFXMesh(CadInteractionEvent interact) {
27182716

27192717
return toJavaFXMeshSimple(interact);
27202718

@@ -2740,9 +2738,15 @@ public MeshContainer toJavaFXMesh(CadInteractionEvent interact) throws ColinearP
27402738
* @return the CSG as JavaFX triangle mesh
27412739
* @throws ColinearPointsException
27422740
*/
2743-
public MeshContainer toJavaFXMeshSimple(CadInteractionEvent interact) throws ColinearPointsException {
2741+
public MeshContainer toJavaFXMeshSimple(CadInteractionEvent interact) {
27442742

2745-
return CSGtoJavafx.meshFromPolygon(generatePolygonsFromMesh());
2743+
try {
2744+
return CSGtoJavafx.meshFromPolygon(generatePolygonsFromMesh());
2745+
} catch (ColinearPointsException e) {
2746+
// TODO Auto-generated catch block
2747+
e.printStackTrace();
2748+
return CSGtoJavafx.meshFromPolygon(new ArrayList<>());
2749+
}
27462750
}
27472751

27482752
/**
@@ -3772,20 +3776,14 @@ public int getPrintBedIndex() {
37723776
}
37733777

37743778
public static CSG text(String text, double height, double fontSize) {
3775-
try {
3776-
return text(text, height, fontSize, Font.getDefault().getName());
3777-
} catch (ColinearPointsException e) {
3778-
// TODO Auto-generated catch block
3779-
e.printStackTrace();
3780-
return new CSG();
3781-
}
3779+
return text(text, height, fontSize, Font.getDefault().getName());
37823780
}
37833781

37843782
public static CSG text(String text, double height) {
37853783
return text(text, height, 30);
37863784
}
37873785

3788-
public static CSG text(String text, double height, double fontSize, String fontType) throws ColinearPointsException {
3786+
public static CSG text(String text, double height, double fontSize, String fontType) {
37893787
javafx.scene.text.Font font = new javafx.scene.text.Font(fontType, fontSize);
37903788
if (!font.getName().toLowerCase().contains(fontType.toLowerCase())) {
37913789
String options = "";
@@ -4439,4 +4437,15 @@ public String getUniqueId() {
44394437
return uniqueId;
44404438
}
44414439

4440+
public Vector3d vertexAt(int i) {
4441+
return vertexAt(vertices, i);
4442+
}
4443+
4444+
public List<Vector3d> getPoints() {
4445+
List<Vector3d> points = new ArrayList<Vector3d>();
4446+
for(int i=0;i<vertCount;i++)
4447+
points.add(vertexAt(i));
4448+
return points;
4449+
}
4450+
44424451
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,19 @@ public static CSG file(URL path) throws IOException, URISyntaxException, Colinea
8484
* if loading failed
8585
* @throws ColinearPointsException
8686
*/
87-
public static CSG file(Path path) throws IOException, ColinearPointsException {
87+
public static CSG file(Path path) throws IOException {
8888
STLLoader loader = new STLLoader();
8989

9090
ArrayList<Polygon> polygons = loader.parse(path.toFile());
9191

92-
CSG fromPolygons = new CSG(polygons);
92+
CSG fromPolygons;
93+
try {
94+
fromPolygons = new CSG(polygons);
95+
} catch (ColinearPointsException e) {
96+
// TODO Auto-generated catch block
97+
e.printStackTrace();
98+
fromPolygons= new CSG();
99+
}
93100
return fromPolygons;
94101
}
95102
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public Wedge(double w, double h, double d) {
4141
* @see eu.mihosoft.vrl.v3d.Primitive#toPolygons()
4242
*/
4343
@Override
44-
public List<Polygon> toPolygons() {
44+
public CSG toCSG() {
4545
CSG polygon = null;
4646
try {
4747
polygon = Extrude.points(new Vector3d(0, 0, h), // This is the extrusion depth
@@ -53,6 +53,6 @@ public List<Polygon> toPolygons() {
5353
// TODO Auto-generated catch block
5454
e.printStackTrace();
5555
}
56-
return polygon.getPolygons();
56+
return polygon;
5757
}
5858
}

src/main/java/eu/mihosoft/vrl/v3d/ext/quickhull3d/HullUtil.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ private HullUtil() {
3434
* @param points
3535
* the points
3636
* @return the csg
37+
* @throws ColinearPointsException
3738
*/
3839
public static CSG hull(List<?> points) {
3940
List<Vector3d> plist = new ArrayList<>();
@@ -42,9 +43,12 @@ public static CSG hull(List<?> points) {
4243
return hull(plist, new PropertyStorage());
4344
}
4445
if (CSG.class.isInstance(points.get(0))) {
45-
for (Object csg : points)
46-
((CSG) csg).getPolygons().forEach((p) -> p.getVertices().forEach((v) -> plist.add(v.pos)));
47-
46+
for (Object csg : points) {
47+
CSG csg2 = (CSG) csg;
48+
for(int i=0;i<csg2.getNumberOfTriangles()*3;i++) {
49+
plist.add(csg2.vertexAt(i));
50+
}
51+
}
4852
return hull(plist, new PropertyStorage());
4953
}
5054
throw new RuntimeException("Objects in list are of unknown type: " + points.get(0).getClass().getName()
@@ -59,8 +63,9 @@ public static CSG hull(List<?> points) {
5963
* @param storage
6064
* the storage
6165
* @return the csg
66+
* @throws ColinearPointsException
6267
*/
63-
public static CSG hull(List<Vector3d> points, PropertyStorage storage) {
68+
public static CSG hull(List<Vector3d> points, PropertyStorage storage) {
6469
if (CSGClient.isRunning()) {
6570
try {
6671
CSG csg = CSGClient.getClient().hull(points, new PropertyStorage()).get(0);
@@ -99,7 +104,13 @@ public static CSG hull(List<Vector3d> points, PropertyStorage storage) {
99104
vertices.clear();
100105
}
101106

102-
return CSG.fromPolygons(polygons);
107+
try {
108+
return new CSG(polygons);
109+
} catch (ColinearPointsException e) {
110+
// TODO Auto-generated catch block
111+
e.printStackTrace();
112+
return new CSG();
113+
}
103114
}
104115

105116
/**
@@ -113,10 +124,8 @@ public static CSG hull(List<Vector3d> points, PropertyStorage storage) {
113124
*/
114125
public static CSG hull(CSG csg, PropertyStorage storage) {
115126

116-
List<Vector3d> points = new ArrayList<>(csg.getPolygons().size() * 3);
117-
118-
csg.getPolygons().forEach((p) -> p.getVertices().forEach((v) -> points.add(v.pos)));
119-
127+
List<Vector3d> points = csg.getPoints();
128+
120129
return hull(points, storage);
121130
}
122131

@@ -131,8 +140,7 @@ public static CSG hull(CSG... csgList) {
131140

132141
List<Vector3d> points = new ArrayList<>();
133142
for (CSG csg : csgList)
134-
csg.getPolygons().forEach((p) -> p.getVertices().forEach((v) -> points.add(v.pos)));
135-
143+
points.addAll(csg.getPoints());
136144
return hull(points, new PropertyStorage());
137145
}
138146
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public void setColor_ShouldSetColorToAllPolygons() {
1111
CSG cube = new Cube().toCSG().setColor(Color.BLUE);
1212
assertEquals(Color.BLUE, cube.getColor());
1313

14-
cube.getPolygons().forEach(polygon -> {
15-
assertEquals("Expected the polygon to get the same color as the CSG", Color.BLUE, polygon.getColor());
16-
});
14+
// cube.getPolygons().forEach(polygon -> {
15+
// assertEquals("Expected the polygon to get the same color as the CSG", Color.BLUE, polygon.getColor());
16+
// });
1717
}
1818

1919
@Test
@@ -71,9 +71,9 @@ public void setColor_OnCSGShouldChangeColorsOfAllPolygons() {
7171

7272
cube.setColor(Color.RED);
7373

74-
cube.getPolygons().forEach(polygon -> {
75-
assertEquals("Expected the cube polygons to be another color", Color.RED, polygon.getColor());
76-
});
74+
// cube.getPolygons().forEach(polygon -> {
75+
// assertEquals("Expected the cube polygons to be another color", Color.RED, polygon.getColor());
76+
// });
7777
}
7878

7979
@Test

0 commit comments

Comments
 (0)