@@ -1611,10 +1611,10 @@ public CSG triangulate(boolean fix) {
16111611 }
16121612 int extraSpace = ExtraSpace ;
16131613 long longLength = 1 + np + ((numberOfPolygons + 1 ) * extraSpace );
1614- if (longLength * 4 > Integer .MAX_VALUE )
1614+ if (longLength * 4 > Integer .MAX_VALUE )
16151615 new RuntimeException ("Mesh too large to process with integers!" ).printStackTrace ();
16161616 else {
1617- System .err .println ("Processing Mesh Manifold with " + longLength * 4 + " byte buffer" );
1617+ System .err .println ("Processing Mesh Manifold with " + longLength * 4 + " byte buffer" );
16181618 added = runGPUMakeManifold (itr , (int ) np , (int ) longLength , numberOfPolygons );
16191619 if (added >= 0 )
16201620 System .out .println ("Manifold iteration added " + added + " points " );
@@ -1645,7 +1645,7 @@ private void performTriangulation() {
16451645 }
16461646
16471647 private int runGPUMakeManifold (int iteration , int np , int longLength , int numPoly ) {
1648- if (iteration < 0 || np <= 0 || longLength <= 0 || numPoly <= 0 )
1648+ if (iteration < 0 || np <= 0 || longLength <= 0 || numPoly <= 0 )
16491649 throw new RuntimeException ("Error none of the dataa lengths can be negative nor 0" );
16501650 // Flattened approach - more Aparapi-friendly
16511651 int numberOfPolygons = numPoly ;
@@ -1692,7 +1692,11 @@ private int runGPUMakeManifold(int iteration, int np, int longLength, int numPol
16921692
16931693 // System.out.println("Data loaded!");
16941694 float eps = 0.00001f ;
1695- float epsSq = (float )(eps * eps );
1695+ float epsSq = (float ) (eps * eps );
1696+ int [] added = new int [numberOfPolygons ];
1697+ int testPointChunk = 50 ;
1698+ int snapChunk = 500 ;
1699+ int [] tp = new int [] { 0 , snapChunk };
16961700
16971701 // Aparapi-compatible kernel with flattened data
16981702 Kernel snapPointsToDistance = new Kernel () {
@@ -1703,7 +1707,7 @@ public void run() {
17031707 float meX = pointDataX [mePointIndex ];
17041708 float meY = pointDataY [mePointIndex ];
17051709 float meZ = pointDataZ [mePointIndex ];
1706- for (int i = 0 ; i < polySizes .length ; i ++) {
1710+ for (int i = tp [ 0 ]; ( i < tp [ 1 ] && i < polySizes .length ) ; i ++) {
17071711 int polyStart = polyStartIndex [i ];
17081712 int polySize = polySizes [i ];
17091713
@@ -1733,8 +1737,19 @@ public void run() {
17331737 }
17341738 }
17351739 };
1736- gpuRun ( numberOfPoints , snapPointsToDistance , done , "Snap Points Itr(" + iteration + ")" , () -> false , iteration , 1 );
1740+
17371741 if (preventNonManifoldTriangles ) {
1742+ gpuRun (numberOfPoints , snapPointsToDistance , done , "Snap Points Itr(" + iteration + ")" , () -> {
1743+ tp [0 ] += snapChunk ;
1744+ tp [1 ] += snapChunk ;
1745+ if (tp [1 ] > polySizes .length )
1746+ tp [1 ] = polySizes .length ;
1747+ if (tp [0 ] < polySizes .length )
1748+ return true ;
1749+ return false ;
1750+ }, iteration , polySizes .length /snapChunk );
1751+ tp [0 ] = 0 ;
1752+ tp [1 ] = testPointChunk ;
17381753 HashSet <Integer > unique = new HashSet <Integer >();
17391754 int running = 0 ;
17401755 for (int i = 0 ; i < numberOfPolygons ; i ++) {
@@ -1754,9 +1769,7 @@ public void run() {
17541769 for (int val : unique ) {
17551770 uniquePoints [b ++] = val ;
17561771 }
1757- int [] added = new int [numberOfPolygons ];
1758- int testPointChunk = 50 ;
1759- int [] tp =new int [] {0 ,testPointChunk };
1772+
17601773 Kernel findNonManifoldPoints = new Kernel () {
17611774 @ Override
17621775 public void run () {
@@ -1797,7 +1810,7 @@ public void run() {
17971810 skip = true ;
17981811 }
17991812 if (!skip ) {
1800- for (int tpInc = tp [0 ]; tpInc < tp [1 ]&& tpInc < uniquePoints .length ; tpInc ++) {
1813+ for (int tpInc = tp [0 ]; tpInc < tp [1 ] && tpInc < uniquePoints .length ; tpInc ++) {
18011814 int testPointIndex = uniquePoints [tpInc ];
18021815 skip = false ;
18031816 for (int px = 0 ; px < originalPolySize + added [mePoly ]; px ++) {
@@ -1921,13 +1934,13 @@ public void run() {
19211934 pointsAdded = 0 ;
19221935
19231936 gpuRun (numberOfPolygons , findNonManifoldPoints , done , "Manifold Itr(" + iteration + ")" , () -> {
1924- //for (int tp = 0; tp < uniquePoints.length; tp++)
1937+ // for (int tp = 0; tp < uniquePoints.length; tp++)
19251938 // Iterate through each of the test points in host thread
1926- tp [0 ]+= testPointChunk ;
1927- tp [1 ]+= testPointChunk ;
1928- if (tp [1 ]> uniquePoints .length )
1929- tp [1 ]= uniquePoints .length ;
1930- if (tp [0 ]< uniquePoints .length )
1939+ tp [0 ] += testPointChunk ;
1940+ tp [1 ] += testPointChunk ;
1941+ if (tp [1 ] > uniquePoints .length )
1942+ tp [1 ] = uniquePoints .length ;
1943+ if (tp [0 ] < uniquePoints .length )
19311944 return true ;
19321945 pointsAdded = 0 ;
19331946 String out = "points added report [" ;
@@ -1950,7 +1963,7 @@ public void run() {
19501963 // return true;
19511964 }
19521965 return false ;
1953- }, iteration ,uniquePoints .length / testPointChunk );
1966+ }, iteration , uniquePoints .length / testPointChunk );
19541967 }
19551968 ArrayList <Polygon > newPoly = new ArrayList <>();
19561969 for (int i = 0 ; i < polygons .size (); i ++) {
@@ -1959,7 +1972,7 @@ public void run() {
19591972 ArrayList <Vertex > points = new ArrayList <Vertex >();
19601973 int startIndex = polyStartIndex [i ];
19611974 int polySize = polySizes [i ];
1962- //HashSet<Integer> pointIndexSet = new HashSet<Integer>();
1975+ // HashSet<Integer> pointIndexSet = new HashSet<Integer>();
19631976 for (int j = 0 ; j < polySize ; j ++) {
19641977 int pointIndex = polygonPointOrder [startIndex + j ];
19651978 if (pointIndex < 0 ) {
@@ -1970,7 +1983,7 @@ public void run() {
19701983// System.out.println("ERR polygon " + i + " already has a point " + pointIndex);
19711984// continue;
19721985// }
1973- //pointIndexSet.add(pointIndex);
1986+ // pointIndexSet.add(pointIndex);
19741987 Vector3d thispoint = orderedPoints [pointIndex ];
19751988 points .add (new Vertex (thispoint , pl .getNormal ()));
19761989 }
@@ -1987,11 +2000,12 @@ public void run() {
19872000 return pointsAdded ;
19882001 }
19892002
1990- public static void gpuRun (int numberOfPoints , Kernel kernel , float [] done , String type , BooleanSupplier test , int itr , int expectedIterations ) {
2003+ public static void gpuRun (int numberOfPoints , Kernel kernel , float [] done , String type , BooleanSupplier test ,
2004+ int itr , int expectedIterations ) {
19912005
19922006 progressMoniter .progressUpdate (0 , 100 , "Start " + typOfCPU (kernel ) + type , null );
19932007 if (!useGPU ) {
1994- String valueOf = String .valueOf (Runtime .getRuntime ().availableProcessors ()* 4 );
2008+ String valueOf = String .valueOf (Runtime .getRuntime ().availableProcessors () * 4 );
19952009 progressMoniter .progressUpdate (0 , 100 , "CPU mode " + valueOf , null );
19962010 System .setProperty ("com.aparapi.threadPoolSize" , valueOf );
19972011 kernel .setExecutionMode (Kernel .EXECUTION_MODE .JTP ); // Java Thread Pool
@@ -2003,18 +2017,19 @@ public static void gpuRun(int numberOfPoints, Kernel kernel, float[] done, Strin
20032017 do {
20042018 kernel .execute (numberOfPoints );
20052019 iteration [0 ] += 1 ;
2006- long sinceStart = System .currentTimeMillis ()- begin ;
2007- long took = sinceStart / iteration [0 ];
2008- long expected = took * (expectedIterations + 2 );
2009- long remaining =expected - sinceStart ;
2020+ long sinceStart = System .currentTimeMillis () - begin ;
2021+ long took = sinceStart / iteration [0 ];
2022+ long expected = took * (expectedIterations + 2 );
2023+ long remaining = expected - sinceStart ;
20102024 for (int i = 0 ; i < done .length ; i ++) {
20112025 done [i ] = 0 ;
20122026 }
2013- if (remaining < 0 )
2014- remaining = 0 ;
2027+ if (remaining < 0 )
2028+ remaining = 0 ;
20152029 String dur = makeTimestamp (expected );
20162030 String rem = makeTimestamp (remaining );
2017- progressMoniter .progressUpdate (iteration [0 ], expectedIterations , typOfCPU (kernel ) + type + "(" + iteration [0 ] + ") Estimated time: " +dur +" Remaining: " +rem , null );
2031+ progressMoniter .progressUpdate (iteration [0 ], expectedIterations , "Rem->" + rem + " " + type
2032+ + typOfCPU (kernel ) + "(" + iteration [0 ] + ") Estimated Total: " + dur , null );
20182033 } while (test .getAsBoolean ());
20192034 });
20202035 thread .start ();
@@ -2030,8 +2045,9 @@ public static void gpuRun(int numberOfPoints, Kernel kernel, float[] done, Strin
20302045 float percent = doneness / ((float ) done .length ) * 100.0f ;
20312046 // int currentPass = kernel.getCurrentPass();
20322047 // percent=(float)currentPass/(float)numberOfPoints;
2033- if (expectedIterations ==1 )
2034- progressMoniter .progressUpdate ((int ) (percent ), 100 , typOfCPU (kernel ) + type + "(" + iteration [0 ] + ")" , null );
2048+ if (expectedIterations == 1 )
2049+ progressMoniter .progressUpdate ((int ) (percent ), 100 ,
2050+ typOfCPU (kernel ) + type + "(" + iteration [0 ] + ")" , null );
20352051 }
20362052 try {
20372053 Thread .sleep (useGPU ? 1 : 100 );
@@ -2055,12 +2071,12 @@ private static String typOfCPU(Kernel kernel) {
20552071
20562072 private static String makeTimestamp (long expected ) {
20572073 Duration duration = Duration .ofMillis (expected );
2058-
2074+
20592075 long hours = duration .toHours ();
20602076 long minutes = duration .toMinutes () % 60 ;
20612077 long seconds = duration .getSeconds () % 60 ;
2062-
2063- String dur = String .format ("%02d:%02d:%02d" , hours , minutes , seconds );
2078+
2079+ String dur = String .format ("%02d:%02d:%02d" , hours , minutes , seconds );
20642080 return dur ;
20652081 }
20662082
0 commit comments