Skip to content

Commit 599c513

Browse files
committed
Minimal changes version of the update of passing in the plane when
creating a new polygon.
1 parent 98313f9 commit 599c513

File tree

16 files changed

+214
-162
lines changed

16 files changed

+214
-162
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public boolean contains(Vector3d v) {
151151
* box; {@code false} otherwise
152152
*/
153153
public boolean contains(Polygon p) {
154-
return p.vertices.stream().allMatch(v -> contains(v));
154+
return p.getVertices().stream().allMatch(v -> contains(v));
155155
}
156156

157157
/**

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

+15-15
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ public StringBuilder toStlString(StringBuilder sb) {
14741474
sb.append("solid v3d.csg\n");
14751475
for (Polygon p : getPolygons()) {
14761476
try {
1477-
Plane.computeNormal(p.vertices);
1477+
Plane.computeNormal(p.getVertices());
14781478
p.toStlString(sb);
14791479
} catch (Exception ex) {
14801480
System.out.println("Prune Polygon on export");
@@ -1571,7 +1571,7 @@ private void runCPUMakeManifold() {
15711571
Edge e = null;
15721572
// Test every polygon
15731573
Polygon i = polygons.get(threadIndex);
1574-
ArrayList<Vertex> vertices = i.vertices;
1574+
List<Vertex> vertices = i.getVertices();
15751575
for (int k = 0; k < vertices.size(); k++) {
15761576
// each point in the checking polygon
15771577
int now = k;
@@ -1591,7 +1591,7 @@ private void runCPUMakeManifold() {
15911591
Polygon ii = polygons.get(l);
15921592
if (threadIndex != l) {
15931593
// every other polygon besides this one being tested
1594-
ArrayList<Vertex> vert = ii.vertices;
1594+
List<Vertex> vert = ii.getVertices();
15951595
for (int iii = 0; iii < vert.size(); iii++) {
15961596
Vertex vi = vert.get(iii);
15971597
// if they are coincident, move along
@@ -1602,7 +1602,7 @@ private void runCPUMakeManifold() {
16021602
// edge
16031603
if (e.contains(vi.pos, tOL)) {
16041604
// System.out.println("Inserting point "+vi);
1605-
vertices.add(next, vi);
1605+
i.add(next, vi);
16061606
e.setP2(vi);
16071607
// totalAdded++;
16081608
}
@@ -1645,7 +1645,7 @@ private void runGPUMakeManifold() {
16451645
int roomForMore = 10;
16461646
int size = polygons.size();
16471647
for (int i = 0; i < size; i++) {
1648-
numberOfPoints += (polygons.get(i).vertices.size());
1648+
numberOfPoints += (polygons.get(i).getVertices().size());
16491649
}
16501650
float[] pointData = new float[numberOfPoints * 3];
16511651
int[] startIndex = new int[size];
@@ -1656,10 +1656,10 @@ private void runGPUMakeManifold() {
16561656
insertions[i] = -1;
16571657
}
16581658
for (int polyIndex = 0; polyIndex < size; polyIndex++) {
1659-
sizes[polyIndex] = polygons.get(polyIndex).vertices.size();
1659+
sizes[polyIndex] = polygons.get(polyIndex).getVertices().size();
16601660
startIndex[polyIndex] = runningPointIndex;
16611661
for (int ii = 0; ii < sizes[polyIndex]; ii++) {
1662-
Vector3d pos = polygons.get(polyIndex).vertices.get(ii).pos.clone()
1662+
Vector3d pos = polygons.get(polyIndex).getVertices().get(ii).pos.clone()
16631663
.roundToEpsilon(Vector3d.getEXPORTEPSILON());
16641664
pointData[startIndex[polyIndex] + 0 + ii] = (float) pos.x;
16651665
pointData[startIndex[polyIndex] + 1 + ii] = (float) pos.y;
@@ -1728,7 +1728,7 @@ private CSG fixDegenerates(ArrayList<Polygon> toAdd, Polygon p) {
17281728
// both list of points should be right hand, but since they are other polygons,
17291729
// that may not be the case, so sorting needs to take place
17301730
ArrayList<Vertex> newpoints = new ArrayList<Vertex>();
1731-
for (Vertex v : ptoA.vertices) {
1731+
for (Vertex v : ptoA.getVertices()) {
17321732
newpoints.add(v);
17331733
if (e.isThisPointOneOfMine(v, Plane.EPSILON_Point)) {
17341734
for (Vertex v2 : degen)
@@ -1771,7 +1771,7 @@ private CSG updatePolygons(ArrayList<Polygon> toAdd, ArrayList<Polygon> degenera
17711771
// return;
17721772
// }
17731773

1774-
if (p.vertices.size() == 3) {
1774+
if (p.getVertices().size() == 3) {
17751775
toAdd.add(p);
17761776
} else {
17771777
// //com.neuronrobotics.sdk.common.Log.error("Fixing error in STL " + name + "
@@ -1849,7 +1849,7 @@ public PolygonStruct(PropertyStorage storage, List<Integer> indices, String mate
18491849
for (Polygon p : getPolygons()) {
18501850
List<Integer> polyIndices = new ArrayList<>();
18511851

1852-
p.vertices.stream().forEach((v) -> {
1852+
p.getVertices().stream().forEach((v) -> {
18531853
if (!vertices.contains(v)) {
18541854
vertices.add(v);
18551855
v.toObjString(sb);
@@ -2019,9 +2019,9 @@ public Bounds getBounds() {
20192019

20202020
for (Polygon p : getPolygons()) {
20212021

2022-
for (int i = 0; i < p.vertices.size(); i++) {
2022+
for (int i = 0; i < p.getVertices().size(); i++) {
20232023

2024-
Vertex vert = p.vertices.get(i);
2024+
Vertex vert = p.getVertices().get(i);
20252025

20262026
if (vert.pos.x < minX) {
20272027
minX = vert.pos.x;
@@ -2254,10 +2254,10 @@ public ArrayList<CSG> minkowskiHullShape(CSG travelingShape) {
22542254
ArrayList<CSG> bits = new ArrayList<>();
22552255
for (Polygon p : this.getPolygons()) {
22562256
List<Vector3d> plist = new ArrayList<>();
2257-
for (Vertex v : p.vertices) {
2257+
for (Vertex v : p.getVertices()) {
22582258
CSG newSHape = travelingShape.move(v);
22592259
for (Polygon np : newSHape.getPolygons()) {
2260-
for (Vertex nv : np.vertices) {
2260+
for (Vertex nv : np.getVertices()) {
22612261
plist.add(nv.pos);
22622262
}
22632263
}
@@ -2280,7 +2280,7 @@ public ArrayList<CSG> minkowskiHullShape(CSG travelingShape) {
22802280
public ArrayList<CSG> minkowski(CSG travelingShape) {
22812281
HashMap<Vertex, CSG> map = new HashMap<>();
22822282
for (Polygon p : travelingShape.getPolygons()) {
2283-
for (Vertex v : p.vertices) {
2283+
for (Vertex v : p.getVertices()) {
22842284
if (map.get(v) == null)// use hashmap to avoid duplicate locations
22852285
map.put(v, this.move(v));
22862286
}

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ public static MeshContainer meshFromPolygon(List<Polygon> poly) {
2323

2424
int counter = 0;
2525
for (Polygon p : poly) {
26-
if (p.vertices.size() >= 3) {
26+
if (p.getVertices().size() >= 3) {
2727

2828
// TODO: improve the triangulation?
2929
//
3030
// JavaOne requires triangular polygons.
3131
// If our polygon has more vertices, create
3232
// multiple triangles:
33-
Vertex firstVertex = p.vertices.get(0);
34-
for (int i = 0; i < p.vertices.size() - 2; i++) {
33+
Vertex firstVertex = p.getVertices().get(0);
34+
for (int i = 0; i < p.getVertices().size() - 2; i++) {
3535

3636
if (firstVertex.pos.x < minX) {
3737
minX = firstVertex.pos.x;
@@ -59,7 +59,7 @@ public static MeshContainer meshFromPolygon(List<Polygon> poly) {
5959
mesh.getTexCoords().addAll(0); // texture (not covered)
6060
mesh.getTexCoords().addAll(0);
6161

62-
Vertex secondVertex = p.vertices.get(i + 1);
62+
Vertex secondVertex = p.getVertices().get(i + 1);
6363

6464
if (secondVertex.pos.x < minX) {
6565
minX = secondVertex.pos.x;
@@ -87,7 +87,7 @@ public static MeshContainer meshFromPolygon(List<Polygon> poly) {
8787
mesh.getTexCoords().addAll(0); // texture (not covered)
8888
mesh.getTexCoords().addAll(0);
8989

90-
Vertex thirdVertex = p.vertices.get(i + 2);
90+
Vertex thirdVertex = p.getVertices().get(i + 2);
9191

9292
mesh.getPoints().addAll((float) thirdVertex.pos.x, (float) thirdVertex.pos.y,
9393
(float) thirdVertex.pos.z);

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public Vertex getP2() {
8282
public static List<Edge> fromPolygon(Polygon poly) {
8383
List<Edge> result = new ArrayList<>();
8484

85-
for (int i = 0; i < poly.vertices.size(); i++) {
86-
Edge e = new Edge(poly.vertices.get(i), poly.vertices.get((i + 1) % poly.vertices.size()));
85+
for (int i = 0; i < poly.getVertices().size(); i++) {
86+
Edge e = new Edge(poly.getVertices().get(i), poly.getVertices().get((i + 1) % poly.getVertices().size()));
8787

8888
result.add(e);
8989
}
@@ -124,7 +124,7 @@ public static Polygon toPolygon(List<Vector3d> points, Plane plane) {
124124
// collect(Collectors.toList());
125125
Polygon p = Polygon.fromPoints(points);
126126

127-
p.vertices.stream().forEachOrdered((vertex) -> {
127+
p.getVertices().stream().forEachOrdered((vertex) -> {
128128
vertex.normal = plane.getNormal().clone();
129129
});
130130

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

+29-29
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,18 @@ private CSG monotoneExtrude(Vector3d dir, Polygon polygon1) {
8686
CSG extrude;
8787
//polygon1=polygon1.flipped();
8888
newPolygons.addAll(PolygonUtil.concaveToConvex(polygon1.flipped()));
89-
Polygon polygon2 = polygon1.translated(dir);
89+
Polygon polygon2 = polygon1.transformed(new Transform().move(dir));
9090

91-
int numvertices = polygon1.vertices.size();
91+
int numvertices = polygon1.getVertices().size();
9292
//com.neuronrobotics.sdk.common.Log.error("Building Polygon "+polygon1.getPoints().size());
9393
for (int i = 0; i < numvertices; i++) {
9494

9595
int nexti = (i + 1) % numvertices;
9696

97-
Vector3d bottomV1 = polygon1.vertices.get(i).pos;
98-
Vector3d topV1 = polygon2.vertices.get(i).pos;
99-
Vector3d bottomV2 = polygon1.vertices.get(nexti).pos;
100-
Vector3d topV2 = polygon2.vertices.get(nexti).pos;
97+
Vector3d bottomV1 = polygon1.getVertices().get(i).pos;
98+
Vector3d topV1 = polygon2.getVertices().get(i).pos;
99+
Vector3d bottomV2 = polygon1.getVertices().get(nexti).pos;
100+
Vector3d topV2 = polygon2.getVertices().get(nexti).pos;
101101
double distance = bottomV1.minus(bottomV2).magnitude();
102102
if(Math.abs(distance)<Plane.getEPSILON()) {
103103
//com.neuronrobotics.sdk.common.Log.error("Skipping invalid polygon "+i+" to "+nexti);
@@ -149,19 +149,19 @@ public static CSG polygons(Polygon polygon1, Polygon polygon2) {
149149
List<Polygon> newPolygons = new ArrayList<>();
150150
CSG extrude;
151151
newPolygons.addAll(PolygonUtil.concaveToConvex(polygon1.flipped()));
152-
if (polygon1.vertices.size() != polygon2.vertices.size()) {
152+
if (polygon1.getVertices().size() != polygon2.getVertices().size()) {
153153
throw new RuntimeException("These polygons do not match");
154154
}
155155

156-
int numvertices = polygon1.vertices.size();
156+
int numvertices = polygon1.getVertices().size();
157157
for (int i = 0; i < numvertices; i++) {
158158

159159
int nexti = (i + 1) % numvertices;
160160

161-
Vector3d bottomV1 = polygon1.vertices.get(i).pos;
162-
Vector3d topV1 = polygon2.vertices.get(i).pos;
163-
Vector3d bottomV2 = polygon1.vertices.get(nexti).pos;
164-
Vector3d topV2 = polygon2.vertices.get(nexti).pos;
161+
Vector3d bottomV1 = polygon1.getVertices().get(i).pos;
162+
Vector3d topV1 = polygon2.getVertices().get(i).pos;
163+
Vector3d bottomV2 = polygon1.getVertices().get(nexti).pos;
164+
Vector3d topV2 = polygon2.getVertices().get(nexti).pos;
165165

166166
List<Vector3d> pPoints = Arrays.asList(bottomV2, topV2, topV1, bottomV1);
167167

@@ -266,15 +266,15 @@ public static boolean isCCW(Polygon polygon) {
266266

267267
// thanks to Sepp Reiter for explaining me the algorithm!
268268

269-
if (polygon.vertices.size() < 3) {
269+
if (polygon.getVertices().size() < 3) {
270270
throw new IllegalArgumentException("Only polygons with at least 3 vertices are supported!");
271271
}
272272

273273
// search highest left vertex
274274
int highestLeftVertexIndex = 0;
275-
Vertex highestLeftVertex = polygon.vertices.get(0);
276-
for (int i = 0; i < polygon.vertices.size(); i++) {
277-
Vertex v = polygon.vertices.get(i);
275+
Vertex highestLeftVertex = polygon.getVertices().get(0);
276+
for (int i = 0; i < polygon.getVertices().size(); i++) {
277+
Vertex v = polygon.getVertices().get(i);
278278

279279
if (v.pos.y > highestLeftVertex.pos.y) {
280280
highestLeftVertex = v;
@@ -286,13 +286,13 @@ public static boolean isCCW(Polygon polygon) {
286286
}
287287

288288
// determine next and previous vertex indices
289-
int nextVertexIndex = (highestLeftVertexIndex + 1) % polygon.vertices.size();
289+
int nextVertexIndex = (highestLeftVertexIndex + 1) % polygon.getVertices().size();
290290
int prevVertexIndex = highestLeftVertexIndex - 1;
291291
if (prevVertexIndex < 0) {
292-
prevVertexIndex = polygon.vertices.size() - 1;
292+
prevVertexIndex = polygon.getVertices().size() - 1;
293293
}
294-
Vertex nextVertex = polygon.vertices.get(nextVertexIndex);
295-
Vertex prevVertex = polygon.vertices.get(prevVertexIndex);
294+
Vertex nextVertex = polygon.getVertices().get(nextVertexIndex);
295+
Vertex prevVertex = polygon.getVertices().get(prevVertexIndex);
296296

297297
// edge 1
298298
double a1 = normalizedX(highestLeftVertex.pos, nextVertex.pos);
@@ -309,12 +309,12 @@ public static boolean isCCW(Polygon polygon) {
309309
selectedVIndex = prevVertexIndex;
310310
}
311311

312-
if (selectedVIndex == 0 && highestLeftVertexIndex == polygon.vertices.size() - 1) {
313-
selectedVIndex = polygon.vertices.size();
312+
if (selectedVIndex == 0 && highestLeftVertexIndex == polygon.getVertices().size() - 1) {
313+
selectedVIndex = polygon.getVertices().size();
314314
}
315315

316-
if (highestLeftVertexIndex == 0 && selectedVIndex == polygon.vertices.size() - 1) {
317-
highestLeftVertexIndex = polygon.vertices.size();
316+
if (highestLeftVertexIndex == 0 && selectedVIndex == polygon.getVertices().size() - 1) {
317+
highestLeftVertexIndex = polygon.getVertices().size();
318318
}
319319

320320
// indicates whether edge points from highestLeftVertexIndex towards
@@ -605,16 +605,16 @@ public static CSG sweep(Polygon p, double angle, double z, double radius, int st
605605
public static List<Polygon> monotoneExtrude(Polygon polygon2, Polygon polygon1) {
606606
List<Polygon> newPolygons = new ArrayList<>();
607607

608-
int numvertices = polygon1.vertices.size();
608+
int numvertices = polygon1.getVertices().size();
609609

610610
for (int i = 0; i < numvertices; i++) {
611611

612612
int nexti = (i + 1) % numvertices;
613613

614-
Vector3d bottomV1 = polygon1.vertices.get(i).pos;
615-
Vector3d topV1 = polygon2.vertices.get(i).pos;
616-
Vector3d bottomV2 = polygon1.vertices.get(nexti).pos;
617-
Vector3d topV2 = polygon2.vertices.get(nexti).pos;
614+
Vector3d bottomV1 = polygon1.getVertices().get(i).pos;
615+
Vector3d topV1 = polygon2.getVertices().get(i).pos;
616+
Vector3d bottomV2 = polygon1.getVertices().get(nexti).pos;
617+
Vector3d topV2 = polygon2.getVertices().get(nexti).pos;
618618
double distance = bottomV1.minus(bottomV2).magnitude();
619619
if (Math.abs(distance) < Plane.getEPSILON()) {
620620
continue;

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static CSG outerFillet(List<Polygon> polys, double rad) {
4242

4343
ArrayList<CSG> parts = new ArrayList<>();
4444
for (Polygon p : polys) {
45-
int size = p.vertices.size();
45+
int size = p.getVertices().size();
4646
for (int i = 0; i < size; i++) {
4747
// if(i>1)
4848
// continue;
@@ -52,9 +52,9 @@ public static CSG outerFillet(List<Polygon> polys, double rad) {
5252
int nextNext = next + 1;
5353
if (nextNext == size)
5454
nextNext = 0;
55-
Vector3d position0 = p.vertices.get(i).pos;
56-
Vector3d position1 = p.vertices.get(next).pos;
57-
Vector3d position2 = p.vertices.get(nextNext).pos;
55+
Vector3d position0 = p.getVertices().get(i).pos;
56+
Vector3d position1 = p.getVertices().get(next).pos;
57+
Vector3d position2 = p.getVertices().get(nextNext).pos;
5858
Vector3d seg1 = position0.minus(position1);
5959
Vector3d seg2 = position2.minus(position1);
6060
double len = seg1.magnitude();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public Modifier(WeightFunction function) {
3333
*/
3434
void modify(CSG csg) {
3535
for(Polygon p : csg.getPolygons()) {
36-
for(Vertex v : p.vertices) {
36+
for(Vertex v : p.getVertices()) {
3737
v.setWeight(function.eval(v.pos, csg));
3838
}
3939
}

0 commit comments

Comments
 (0)