@@ -142,6 +142,21 @@ public class CSG implements IuserAPI, Serializable {
142142 transient private static HashMap <String , IRegenerate > regenerate = new HashMap <String , IRegenerate >();
143143 transient private static HashMap <String , Affine > manipulator = new HashMap <String , Affine >();
144144
145+ /**
146+ * The Enum OptType.
147+ */
148+ public static enum OptType {
149+
150+ /** The csg bound. */
151+ CSG_BOUND ,
152+
153+ // /** The polygon bound. */
154+ // POLYGON_BOUND,
155+
156+ /** The none. */
157+ NONE
158+ }
159+
145160 transient private static OptType defaultOptType = OptType .CSG_BOUND ;
146161 transient private static String defaultcolor = "#007956" ;
147162 // private boolean triangulated;
@@ -151,12 +166,7 @@ public class CSG implements IuserAPI, Serializable {
151166 // GPU processing
152167 transient private static boolean useGPU = false ;
153168 transient private static int ExtraSpace = 100 ;
154- transient private static ICSGProgress progressMoniter = new ICSGProgress () {
155- @ Override
156- public void progressUpdate (int currentIndex , int finalIndex , String type , CSG intermediateShape ) {
157- System .err .println (type + " cur:" + currentIndex + " of " + finalIndex );
158- }
159- };
169+ transient private static ICSGProgress progressMoniter =new ICSGProgress (){@ Override public void progressUpdate (int currentIndex ,int finalIndex ,String type ,CSG intermediateShape ){System .err .println (type +" cur:" +currentIndex +" of " +finalIndex );}};
160170 transient private static ForkJoinPool poolGlobal = null ;
161171
162172 /** The polygons. */
@@ -253,6 +263,24 @@ private static Vector3d vertexAt(double[] verts, long index) {
253263 long base = index * 3 ;
254264 return new Vector3d (verts [(int ) base ], verts [(int ) (base + 1 )], verts [(int ) (base + 2 )]);
255265 }
266+ public Vector3d vertexAt (long i ) {
267+ return vertexAt (vertices , i );
268+ }
269+
270+ public List <Vector3d > getPoints () {
271+ List <Vector3d > points = new ArrayList <Vector3d >();
272+ for (int i = 0 ; i < vertCount ; i ++)
273+ points .add (vertexAt (i ));
274+ return points ;
275+ }
276+
277+ public Polygon getPolygonByIndex (int faceIndex ) throws ColinearPointsException {
278+ List <Vertex > points = new ArrayList <Vertex >();
279+ points .add (new Vertex (vertexAt (triangles [faceIndex * 3 ])));
280+ points .add (new Vertex (vertexAt (triangles [faceIndex * 3 + 1 ])));
281+ points .add (new Vertex (vertexAt (triangles [faceIndex * 3 + 2 ])));
282+ return new Polygon (points );
283+ }
256284
257285 public CSG processPolygonsToTriangles (ArrayList <Polygon > polygons ) throws ColinearPointsException {
258286 // Build an indexed triangle mesh.
@@ -311,24 +339,33 @@ public CSG processPolygonsToTriangles(ArrayList<Polygon> polygons) throws Coline
311339 return this ;
312340 }
313341
314- // /**
315- // * Gets the polygons.
316- // *
317- // * @return the polygons of this CSG
318- // */
319- // public ArrayList<Polygon> getPolygons() {
320- // return generatePolygonsFromMesh();
321- // }
342+ /**
343+ * Gets the polygons.
344+ *
345+ * @return the polygons of this CSG
346+ */
347+ public ArrayList <Polygon > getPolygons () {
348+ try {
349+ return generatePolygonsFromMesh ();
350+ } catch (ColinearPointsException e ) {
351+ // TODO Auto-generated catch block
352+ e .printStackTrace ();
353+ return new ArrayList <>();
354+ }
355+ }
356+
322357 /**
323358 * Sets the polygons.
324359 *
325360 * @param polygons
326361 * the new polygons
362+ * @throws ColinearPointsException
327363 */
328- // public CSG setPolygons(ArrayList<Polygon> polygons) {
329- // processPolygonsToTriangles(polygons);
330- // return this;
331- // }
364+ public CSG setPolygons (ArrayList <Polygon > polygons ) throws ColinearPointsException {
365+ processPolygonsToTriangles (polygons );
366+ return this ;
367+ }
368+
332369 public long getNumberOfTriangles () {
333370 return triCount ;
334371 }
@@ -2312,7 +2349,8 @@ public void run() {
23122349 }
23132350
23142351 public static List <ForkJoinWorkerThread > getForkJoinWorkers (ForkJoinPool pool ) {
2315- return Thread .getAllStackTraces ().keySet ().stream ().filter (thread -> thread instanceof ForkJoinWorkerThread )
2352+ return Thread .getAllStackTraces ().keySet ().stream ().filter (
2353+ thread -> thread instanceof ForkJoinWorkerThread )
23162354 .map (thread -> (ForkJoinWorkerThread ) thread ).collect (Collectors .toList ());
23172355 }
23182356
@@ -2944,20 +2982,7 @@ public CSG setOptType(OptType optType) {
29442982 }
29452983
29462984
2947- /**
2948- * The Enum OptType.
2949- */
2950- public static enum OptType {
2951-
2952- /** The csg bound. */
2953- CSG_BOUND ,
29542985
2955- // /** The polygon bound. */
2956- // POLYGON_BOUND,
2957-
2958- /** The none. */
2959- NONE
2960- }
29612986
29622987 /**
29632988 * Hail Zeon! In case you forget the name of minkowski and are a Gundam fan
@@ -4437,25 +4462,5 @@ public String getUniqueId() {
44374462 return uniqueId ;
44384463 }
44394464
4440- public Vector3d vertexAt (long 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-
4451- public Polygon getPolygonByIndex (int faceIndex ) throws ColinearPointsException {
4452- List <Vertex > points = new ArrayList <Vertex >();
4453- points .add (new Vertex (vertexAt (triangles [faceIndex * 3 ])));
4454- points .add (new Vertex (vertexAt (triangles [faceIndex * 3 + 1 ])));
4455- points .add (new Vertex (vertexAt (triangles [faceIndex * 3 + 2 ])));
4456-
4457-
4458- return new Polygon (points );
4459- }
44604465
44614466}
0 commit comments