Skip to content

Commit

Permalink
Merge branch 'development' of [email protected]:NeuronRobotics/JCSG.git
Browse files Browse the repository at this point in the history
into development
  • Loading branch information
madhephaestus committed Nov 23, 2024
2 parents 030f361 + 1e306e5 commit e603832
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions src/main/java/eu/mihosoft/vrl/v3d/CSG.java
Original file line number Diff line number Diff line change
Expand Up @@ -1507,12 +1507,12 @@ public CSG triangulate(boolean fix) {
IDebug3dProvider start = Debug3dProvider.provider;
Debug3dProvider.setProvider(null);
if (preventNonManifoldTriangles) {
for(int i=0;i<2;i++)
if (isUseGPU()) {
runGPUMakeManifold();
} else {
runCPUMakeManifold();
}
for (int i = 0; i < 2; i++)
if (isUseGPU()) {
runGPUMakeManifold();
} else {
runCPUMakeManifold();
}
}
try {
Stream<Polygon> polygonStream;
Expand Down Expand Up @@ -1560,13 +1560,15 @@ public CSG triangulate(boolean fix) {
private void runCPUMakeManifold() {
long start = System.currentTimeMillis();
System.err.println("Cleaning up the mesh by adding coincident points to the polygons they touch");
double tOL =1.0e-11;

ArrayList<Thread> threads = new ArrayList<Thread>();
int totalAdded = 0;
double tOL = 1.0e-11;

ArrayList<Thread> threads = new ArrayList<Thread>();
for (int j = 0; j < polygons.size(); j++) {
int threadIndex = j;
Thread t=new Thread(()->{
Edge e=null ;
Thread t = new Thread(() -> {
Edge e = null;
// Test every polygon
Polygon i = polygons.get(threadIndex);
ArrayList<Vertex> vertices = i.vertices;
Expand All @@ -1579,21 +1581,21 @@ private void runCPUMakeManifold() {
// take the 2 points of this section of polygon to make an edge
Vertex p1 = vertices.get(now);
Vertex p2 = vertices.get(next);
if(e==null)
if (e == null)
e = new Edge(p1, p2);
else {
e.setP1(p1);
e.setP2(p2);
}
for (int l = 0; l < polygons.size(); l++) {
Polygon ii = polygons.get(l);
if (threadIndex!=l) {
if (threadIndex != l) {
// every other polygon besides this one being tested
ArrayList<Vertex> vert = ii.vertices;
for (int iii = 0; iii < vert.size(); iii++) {
Vertex vi = vert.get(iii);
// if they are coincident, move along
if (e.isThisPointOneOfMine(vi,tOL))
if (e.isThisPointOneOfMine(vi, tOL))
continue;
// if the point is on the line then we have a non manifold point
// it needs to be inserted into the polygon between the 2 points defined in the
Expand All @@ -1602,35 +1604,40 @@ private void runCPUMakeManifold() {
// System.out.println("Inserting point "+vi);
vertices.add(next, vi);
e.setP2(vi);
//totalAdded++;
// totalAdded++;
}
}
}
}
}
});
if(threads.size()>32) {
for(Thread tr:threads)
if (threads.size() > 32) {
for (Thread tr : threads)
try {
tr.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
totalAdded += 32;
threads.clear();
if (threadIndex/32 % 50 == 0 || j == polygons.size() - 1) {
progressMoniter.progressUpdate(j, polygons.size(),
"STL Processing Polygons for Manifold Vertex, #" + totalAdded + " added so far", this);
}
}

threads.add(t);
t.start();
}
for(Thread t:threads)
for (Thread t : threads)
try {
t.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.err.println("Manifold fix took "+(System.currentTimeMillis()-start));
progressMoniter.progressUpdate(polygons.size(),polygons.size(),"Manifold fix took " + (System.currentTimeMillis() - start),this);
}

private void runGPUMakeManifold() {
Expand Down Expand Up @@ -1723,7 +1730,7 @@ private CSG fixDegenerates(ArrayList<Polygon> toAdd, Polygon p) {
ArrayList<Vertex> newpoints = new ArrayList<Vertex>();
for (Vertex v : ptoA.vertices) {
newpoints.add(v);
if (e.isThisPointOneOfMine(v,Plane.EPSILON_Point)) {
if (e.isThisPointOneOfMine(v, Plane.EPSILON_Point)) {
for (Vertex v2 : degen)
newpoints.add(v2);
}
Expand Down Expand Up @@ -1776,7 +1783,7 @@ private CSG updatePolygons(ArrayList<Polygon> toAdd, ArrayList<Polygon> degenera
toAdd.add(poly);
}
} catch (Throwable ex) {
ex.printStackTrace();
//ex.printStackTrace();
progressMoniter.progressUpdate(1, 1, "Pruning bad polygon CSG::updatePolygons " + p, null);
// try {PolygonUtil.concaveToConvex(p);} catch (Throwable ex2) {
// ex2.printStackTrace();
Expand Down

0 comments on commit e603832

Please sign in to comment.