Skip to content

Commit 94b4508

Browse files
committed
Merge branch 'flatCSGData' of git@github.com:NeuronRobotics/JCSG.git
into manifold3d-test
2 parents 9572bb0 + f6913ab commit 94b4508

39 files changed

Lines changed: 746 additions & 771 deletions

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

Lines changed: 544 additions & 384 deletions
Large diffs are not rendered by default.

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ private ArrayList<CSG> performOperation(List<CSG> csgList, CSGRemoteOperation op
171171

172172
ArrayList<CSG> toSend = new ArrayList<CSG>();
173173
for (CSG c : csgList) {
174-
List<Polygon> polygons = c.getPolygons();
175-
if (polygons.size() == 0) {
174+
175+
if (c.getNumberOfTriangles() == 0) {
176176
Exception ex = new Exception("No Polygons In Incoming geometry here!");
177177
ex.printStackTrace();
178178
throw ex;
179179
}
180-
CSG tmp = CSG.fromPolygons(new ArrayList<>(polygons));
180+
CSG tmp = c.cloneShallow();
181181
tmp.setOptType(c.getOptType());
182182
toSend.add(tmp);
183183
}
@@ -210,14 +210,14 @@ private ArrayList<CSG> performOperation(List<CSG> csgList, CSGRemoteOperation op
210210
// Return results as ArrayList
211211
back = new ArrayList<CSG>();
212212
for (CSG c : response.getCsgList()) {
213-
if (c.getPolygons().size() == 0) {
213+
if (c.getNumberOfTriangles() == 0) {
214214
System.out.println("Running Operation on server: " + hostname + " " + operation);
215215
RuntimeException runtimeException = new RuntimeException(
216216
"Network CSG op resulted in no polygons here ");
217217
runtimeException.printStackTrace();
218218
throw runtimeException;
219219
}
220-
CSG historySync = CSG.fromPolygons(c.getPolygons());
220+
CSG historySync = c.cloneShallow();
221221
back.add(historySync);
222222
for (CSG s : csgList) {
223223
historySync.historySync(s);
@@ -283,7 +283,6 @@ public static void main(String[] args) {
283283
CSG c = new Cube(10, 10, 10).toCSG();
284284
CSG u = CSG.unionAll(a, b, c);
285285
CSG d = a.difference(b);
286-
CSG t = d.triangulate(true);
287286
ArrayList<CSG> m = a.minkowskiHullShape(b);
288287
CSGClient.close();
289288
} catch (Exception e) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private CSGResponse processCSGRequest(CSGRequest request) {
124124
case TRIANGULATE :
125125
CSG.setPreventNonManifoldTriangles(true);
126126
for (CSG c : csgList)
127-
back.add(c.triangulate(true));
127+
back.add(c.makeManifold());
128128
break;
129129
case UNION :
130130
try {
@@ -153,7 +153,7 @@ private CSGResponse processCSGRequest(CSGRequest request) {
153153
}
154154
} catch (Throwable t) {
155155
CSGClient.setServerCall(false);
156-
throw t;
156+
throw new RuntimeException(t);
157157
}
158158
CSGClient.setServerCall(false);
159159
return new CSGResponse(back, request.getOperation());

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package eu.mihosoft.vrl.v3d;
22

3-
import java.util.List;
4-
53
public class ChamferedCube extends Primitive {
64
double w, h, d, chamferHeight;
75

@@ -36,11 +34,11 @@ public ChamferedCube(double w, double h, double d, double chamferHeight) {
3634
* @see eu.mihosoft.vrl.v3d.Primitive#toPolygons()
3735
*/
3836
@Override
39-
public List<Polygon> toPolygons() {
37+
public CSG toCSG() {
4038
CSG cube1 = new Cube(w - chamferHeight * 2, h, d - chamferHeight * 2).toCSG();
4139
CSG cube2 = new Cube(w, h - chamferHeight * 2, d - chamferHeight * 2).toCSG();
4240
CSG cube3 = new Cube(w - chamferHeight * 2, h - chamferHeight * 2, d).toCSG();
43-
return cube1.union(cube2).union(cube3).hull().getPolygons();
41+
return cube1.union(cube2).union(cube3).hull();
4442
}
4543

4644
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package eu.mihosoft.vrl.v3d;
22

3-
import java.util.List;
4-
53
public class ChamferedCylinder extends Primitive {
64
double r, h, chamferHeight;
75
int sides = -1;
@@ -54,9 +52,9 @@ public ChamferedCylinder(double r, double h, double chamferHeight) {
5452
* @see eu.mihosoft.vrl.v3d.Primitive#toPolygons()
5553
*/
5654
@Override
57-
public List<Polygon> toPolygons() {
55+
public CSG toCSG() {
5856
CSG cube1 = new Cylinder(r - chamferHeight, r - chamferHeight, h, sides).toCSG();
5957
CSG cube2 = new Cylinder(r, r, h - chamferHeight * 2, sides).toCSG().movez(chamferHeight);
60-
return cube1.union(cube2).hull().getPolygons();
58+
return cube1.union(cube2).hull();
6159
}
6260
}

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

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import java.util.ArrayList;
3737
import java.util.List;
3838

39+
import eu.mihosoft.vrl.v3d.ext.quickhull3d.HullUtil;
40+
3941
// Auto-generated Javadoc
4042
/**
4143
* An axis-aligned solid cuboid defined by {@code center} and
@@ -122,7 +124,7 @@ public Cube(double w, double h, double d) {
122124
* @see eu.mihosoft.vrl.v3d.Primitive#toPolygons()
123125
*/
124126
@Override
125-
public List<Polygon> toPolygons() {
127+
public CSG toCSG() {
126128
if (dimensions.x <= 0)
127129
throw new NumberFormatException("X can not be negative");
128130
if (dimensions.y <= 0)
@@ -133,39 +135,27 @@ public List<Polygon> toPolygons() {
133135
// position // normal
134136
{{0, 4, 6, 2}, {-1, 0, 0}}, {{1, 3, 7, 5}, {+1, 0, 0}}, {{0, 1, 5, 4}, {0, -1, 0}},
135137
{{2, 6, 7, 3}, {0, +1, 0}}, {{0, 2, 3, 1}, {0, 0, -1}}, {{4, 5, 7, 6}, {0, 0, +1}}};
136-
List<Polygon> polygons = new ArrayList<>();
138+
// List<Polygon> polygons = new ArrayList<>();
139+
List<Vector3d> vertices = new ArrayList<>();
140+
137141
for (int[][] info : a) {
138-
List<Vertex> vertices = new ArrayList<>();
139142
for (int i : info[0]) {
140143
Vector3d pos = new Vector3d(center.x + dimensions.x * (1 * Math.min(1, i & 1) - 0.5),
141144
center.y + dimensions.y * (1 * Math.min(1, i & 2) - 0.5),
142145
center.z + dimensions.z * (1 * Math.min(1, i & 4) - 0.5));
143-
vertices.add(new Vertex(pos));
144-
}
145-
try {
146-
polygons.add(new Polygon(vertices, properties));
147-
} catch (ColinearPointsException e) {
148-
// TODO Auto-generated catch block
149-
e.printStackTrace();
146+
vertices.add(pos);
150147
}
151148
}
149+
CSG hull = HullUtil.hull(vertices, properties);
152150

153151
if (!centered) {
154152

155153
Transform centerTransform = Transform.unity().translate(dimensions.x / 2.0, dimensions.y / 2.0,
156154
dimensions.z / 2.0);
157-
158-
for (Polygon p : polygons) {
159-
try {
160-
p.transform(centerTransform);
161-
} catch (ColinearPointsException e) {
162-
// TODO Auto-generated catch block
163-
e.printStackTrace();
164-
}
165-
}
155+
hull = hull.transformed(centerTransform);
166156
}
167157

168-
return polygons;
158+
return hull;
169159
}
170160

171161
/**

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

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535

3636
import java.util.ArrayList;
3737
import java.util.Arrays;
38-
import java.util.List;
38+
39+
import eu.mihosoft.vrl.v3d.ext.quickhull3d.HullUtil;
3940

4041
// Auto-generated Javadoc
4142
/**
@@ -227,7 +228,7 @@ public Cylinder(double startRadius, double endRadius, double height) {
227228
* @see eu.mihosoft.vrl.v3d.Primitive#toPolygons()
228229
*/
229230
@Override
230-
public List<Polygon> toPolygons() {
231+
public CSG toCSG() {
231232
if (startRadius <= 0)
232233
throw new NumberFormatException("startRadius can not be negative");
233234
if (endRadius <= 0)
@@ -245,39 +246,23 @@ public List<Polygon> toPolygons() {
245246
boolean isY = (Math.abs(axisZ.y) > 0.5);
246247
final Vector3d axisX = new Vector3d(isY ? 1 : 0, !isY ? 1 : 0, 0).cross(axisZ).normalized();
247248
final Vector3d axisY = axisX.cross(axisZ).normalized();
248-
Vertex startV = new Vertex(s);
249-
Vertex endV = new Vertex(e);
250-
List<Polygon> polygons = new ArrayList<>();
251-
249+
Vector3d startV = s;
250+
Vector3d endV = e;
251+
// List<Polygon> polygons = new ArrayList<>();
252+
ArrayList<Vector3d> points = new ArrayList<Vector3d>();
252253
for (int i = 0; i < numSlices; i++) {
253254
double t0 = i / (double) numSlices, t1 = (i + 1) / (double) numSlices;
254-
try {
255-
polygons.add(
256-
new Polygon(Arrays.asList(startV, cylPoint(axisX, axisY, axisZ, ray, s, startRadius, 0, t0, -1),
257-
cylPoint(axisX, axisY, axisZ, ray, s, startRadius, 0, t1, -1)), properties));
258-
} catch (ColinearPointsException e1) {
259-
// TODO Auto-generated catch block
260-
e1.printStackTrace();
261-
}
262-
try {
263-
polygons.add(new Polygon(Arrays.asList(cylPoint(axisX, axisY, axisZ, ray, s, startRadius, 0, t1, 0),
264-
cylPoint(axisX, axisY, axisZ, ray, s, startRadius, 0, t0, 0),
265-
cylPoint(axisX, axisY, axisZ, ray, s, endRadius, 1, t0, 0),
266-
cylPoint(axisX, axisY, axisZ, ray, s, endRadius, 1, t1, 0)), properties));
267-
} catch (ColinearPointsException e1) {
268-
// TODO Auto-generated catch block
269-
e1.printStackTrace();
270-
}
271-
try {
272-
polygons.add(new Polygon(Arrays.asList(endV, cylPoint(axisX, axisY, axisZ, ray, s, endRadius, 1, t1, 1),
273-
cylPoint(axisX, axisY, axisZ, ray, s, endRadius, 1, t0, 1)), properties));
274-
} catch (ColinearPointsException e1) {
275-
// TODO Auto-generated catch block
276-
e1.printStackTrace();
277-
}
255+
points.addAll(Arrays.asList(startV, cylPoint(axisX, axisY, axisZ, ray, s, startRadius, 0, t0, -1),
256+
cylPoint(axisX, axisY, axisZ, ray, s, startRadius, 0, t1, -1)));
257+
points.addAll(Arrays.asList(cylPoint(axisX, axisY, axisZ, ray, s, startRadius, 0, t1, 0),
258+
cylPoint(axisX, axisY, axisZ, ray, s, startRadius, 0, t0, 0),
259+
cylPoint(axisX, axisY, axisZ, ray, s, endRadius, 1, t0, 0),
260+
cylPoint(axisX, axisY, axisZ, ray, s, endRadius, 1, t1, 0)));
261+
points.addAll(Arrays.asList(endV, cylPoint(axisX, axisY, axisZ, ray, s, endRadius, 1, t1, 1),
262+
cylPoint(axisX, axisY, axisZ, ray, s, endRadius, 1, t0, 1)));
278263
}
279264

280-
return polygons;
265+
return HullUtil.hull(points, properties);
281266
}
282267

283268
/**
@@ -303,13 +288,12 @@ public List<Polygon> toPolygons() {
303288
* the normal blend
304289
* @return the vertex
305290
*/
306-
private Vertex cylPoint(Vector3d axisX, Vector3d axisY, Vector3d axisZ, Vector3d ray, Vector3d s, double r,
291+
private Vector3d cylPoint(Vector3d axisX, Vector3d axisY, Vector3d axisZ, Vector3d ray, Vector3d s, double r,
307292
double stack, double slice, double normalBlend) {
308293
double angle = slice * Math.PI * 2;
309294
Vector3d out = axisX.times(Math.cos(angle)).plus(axisY.times(Math.sin(angle)));
310295
Vector3d pos = s.plus(ray.times(stack)).plus(out.times(r));
311-
Vector3d normal = out.times(1.0 - Math.abs(normalBlend)).plus(axisZ.times(normalBlend));
312-
return new Vertex(pos);
296+
return pos;
313297
}
314298

315299
/**

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public Dodecahedron(Vector3d center, double size) {
6464
* @see eu.mihosoft.vrl.v3d.Primitive#toPolygons()
6565
*/
6666
@Override
67-
public List<Polygon> toPolygons() {
67+
public CSG toCSG() {
6868
if (radius <= 0)
6969
throw new NumberFormatException("radius can not be negative");
7070

@@ -92,9 +92,7 @@ public List<Polygon> toPolygons() {
9292
points.add(new Vector3d(-1 / phi, -phi, 0));
9393
points.add(new Vector3d(0, -1 / phi, -phi));
9494

95-
List<Polygon> polygons = HullUtil.hull(points).scale(radius * (phi - 1)).getPolygons();
96-
97-
return polygons;
95+
return HullUtil.hull(points).scale(radius * (phi - 1));
9896
}
9997

10098
/**

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -835,15 +835,16 @@ public Optional<Vector3d> getCrossingPoint(Edge e) {
835835
* @return the list
836836
* @throws ColinearPointsException
837837
*/
838-
public static List<Polygon> boundaryPolygons(CSG csg) throws ColinearPointsException {
839-
List<Polygon> result = new ArrayList<>();
840-
841-
for (List<Polygon> polygonGroup : searchPlaneGroups(csg.getPolygons())) {
842-
result.addAll(boundaryPolygonsOfPlaneGroup(polygonGroup));
843-
}
844-
845-
return result;
846-
}
838+
// public static List<Polygon> boundaryPolygons(CSG csg) throws
839+
// ColinearPointsException {
840+
// List<Polygon> result = new ArrayList<>();
841+
//
842+
// for (List<Polygon> polygonGroup : searchPlaneGroups(csg.getPolygons())) {
843+
// result.addAll(boundaryPolygonsOfPlaneGroup(polygonGroup));
844+
// }
845+
//
846+
// return result;
847+
// }
847848

848849
/**
849850
* Boundary edges of plane group.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private CSG monotoneExtrude(Vector3d dir, Polygon polygon1) throws ColinearPoint
109109

110110
// ArrayList<Polygon> topPolygons = PolygonUtil.triangulatePolygon(polygon2);
111111

112-
extrude = CSG.fromPolygons(newPolygons);
112+
extrude = new CSG(newPolygons);
113113
return extrude;
114114
}
115115

@@ -598,7 +598,7 @@ public static CSG sweep(Polygon p, Transform increment, Transform offset, int st
598598
List<Polygon> topPolygons = PolygonUtil.triangulatePolygon(polygon2.flipped());
599599
newPolygons.addAll(topPolygons);
600600

601-
return CSG.fromPolygons(newPolygons);
601+
return new CSG(newPolygons);
602602
}
603603

604604
public static CSG sweep(Polygon p, double angle, double z, double radius, int steps)

0 commit comments

Comments
 (0)