@@ -147,11 +147,11 @@ public class CSG implements IuserAPI, Serializable {
147147 private static String defaultcolor = "#007956" ;
148148
149149 /** The color. */
150- //private Color color = getDefaultColor();
151- private double r = getDefaultColor ().getRed ();
152- private double g = getDefaultColor ().getGreen ();
153- private double b = getDefaultColor ().getBlue ();
154- private double o = getDefaultColor ().getOpacity ();
150+ // private Color color = getDefaultColor();
151+ private double r = getDefaultColor ().getRed ();
152+ private double g = getDefaultColor ().getGreen ();
153+ private double b = getDefaultColor ().getBlue ();
154+ private double o = getDefaultColor ().getOpacity ();
155155 /** The manipulator. */
156156 private Affine manipulator ;
157157 private Bounds bounds ;
@@ -228,10 +228,10 @@ public Color getColor() {
228228 * @param color the new color
229229 */
230230 public CSG setColor (Color color ) {
231- r = color .getRed ();
232- g = color .getGreen ();
233- b = color .getBlue ();
234- o = color .getOpacity ();
231+ r = color .getRed ();
232+ g = color .getGreen ();
233+ b = color .getBlue ();
234+ o = color .getOpacity ();
235235 for (Polygon p : polygons )
236236 p .setColor (color );
237237 return this ;
@@ -800,15 +800,16 @@ public CSG optimization(OptType type) {
800800 * @return union of this csg and the specified csg
801801 */
802802 public CSG union (CSG csg ) {
803- if (CSGClient .isRunning ()) {
804- ArrayList <CSG > go =new ArrayList <CSG >(Arrays .asList (this ));
805- try {
806- return CSGClient .getClient ().union (go ).get (0 );
807- } catch (Exception e ) {
808- // TODO Auto-generated catch block
809- e .printStackTrace ();
803+ if (this .polygons .size () > 200 || csg .polygons .size () > 200 )
804+ if (CSGClient .isRunning ()) {
805+ ArrayList <CSG > go = new ArrayList <CSG >(Arrays .asList (this ));
806+ try {
807+ return CSGClient .getClient ().union (go ).get (0 );
808+ } catch (Exception e ) {
809+ // TODO Auto-generated catch block
810+ e .printStackTrace ();
811+ }
810812 }
811- }
812813// triangulate();
813814// csg.triangulate();
814815 switch (getOptType ()) {
@@ -956,7 +957,13 @@ public static CSG unionAll(CSG... csgs) {
956957 }
957958
958959 public static CSG unionAll (List <CSG > csgs ) {
959- if (CSGClient .isRunning ()) {
960+ boolean offload =false ;
961+ for (int i =0 ;i <csgs .size ();i ++)
962+ if (csgs .get (i ).polygons .size ()>200 ) {
963+ offload =true ;
964+ break ;
965+ }
966+ if (CSGClient .isRunning ()) {
960967 List <CSG > back ;
961968 try {
962969 back = CSGClient .getClient ().union (csgs );
@@ -968,7 +975,7 @@ public static CSG unionAll(List<CSG> csgs) {
968975 }
969976 CSG first = csgs .get (0 );
970977 return first .union (csgs .stream ().skip (1 ).collect (Collectors .toList ()));
971-
978+
972979 }
973980
974981 public static CSG hullAll (CSG ... csgs ) {
@@ -1233,15 +1240,16 @@ public CSG difference(CSG... csgs) {
12331240 * @return difference of this csg and the specified csg
12341241 */
12351242 public CSG difference (CSG csg ) {
1236- if (CSGClient .isRunning ()) {
1237- ArrayList <CSG > go =new ArrayList <CSG >(Arrays .asList (this ,csg ));
1238- try {
1239- return CSGClient .getClient ().difference (go ).get (0 );
1240- } catch (Exception e ) {
1241- // TODO Auto-generated catch block
1242- e .printStackTrace ();
1243+ if (this .polygons .size () > 200 || csg .polygons .size () > 200 )
1244+ if (CSGClient .isRunning ()) {
1245+ ArrayList <CSG > go = new ArrayList <CSG >(Arrays .asList (this , csg ));
1246+ try {
1247+ return CSGClient .getClient ().difference (go ).get (0 );
1248+ } catch (Exception e ) {
1249+ // TODO Auto-generated catch block
1250+ e .printStackTrace ();
1251+ }
12431252 }
1244- }
12451253// triangulate();
12461254// csg.triangulate();
12471255 try {
@@ -1392,15 +1400,16 @@ private CSG _differenceNoOpt(CSG csg) {
13921400 * @return intersection of this csg and the specified csg
13931401 */
13941402 public CSG intersect (CSG csg ) {
1395- if (CSGClient .isRunning ()) {
1396- ArrayList <CSG > go =new ArrayList <CSG >(Arrays .asList (this ,csg ));
1397- try {
1398- return CSGClient .getClient ().intersect (go ).get (0 );
1399- } catch (Exception e ) {
1400- // TODO Auto-generated catch block
1401- e .printStackTrace ();
1403+ if (this .polygons .size () > 200 || csg .polygons .size () > 200 )
1404+ if (CSGClient .isRunning ()) {
1405+ ArrayList <CSG > go = new ArrayList <CSG >(Arrays .asList (this , csg ));
1406+ try {
1407+ return CSGClient .getClient ().intersect (go ).get (0 );
1408+ } catch (Exception e ) {
1409+ // TODO Auto-generated catch block
1410+ e .printStackTrace ();
1411+ }
14021412 }
1403- }
14041413// triangulate();
14051414// csg.triangulate();
14061415 Node a = new Node (this .clone ().getPolygons ());
@@ -1544,27 +1553,28 @@ public CSG triangulate(boolean fix) {
15441553 triangulated = false ;
15451554 if (triangulated )
15461555 return this ;
1547- if (CSGClient .isRunning ()) {
1548- ArrayList <CSG > go =new ArrayList <CSG >(Arrays .asList (this ));
1549- try {
1550- return CSGClient .getClient ().triangulate (go ).get (0 );
1551- } catch (Exception e ) {
1552- // TODO Auto-generated catch block
1553- e .printStackTrace ();
1556+ if (this .polygons .size () > 200 )
1557+ if (CSGClient .isRunning ()) {
1558+ ArrayList <CSG > go = new ArrayList <CSG >(Arrays .asList (this ));
1559+ try {
1560+ return CSGClient .getClient ().triangulate (go ).get (0 );
1561+ } catch (Exception e ) {
1562+ // TODO Auto-generated catch block
1563+ e .printStackTrace ();
1564+ }
15541565 }
1555- }
15561566 if (providerOf3d == null && Debug3dProvider .provider != null )
15571567 providerOf3d = Debug3dProvider .provider ;
15581568 IDebug3dProvider start = Debug3dProvider .provider ;
15591569 Debug3dProvider .setProvider (null );
1560- //performTriangulation();
1570+ // performTriangulation();
15611571 if (preventNonManifoldTriangles ) {
1562- //for (int i = 0; i < 1; i++)
1563- if (isUseGPU ()) {
1564- runGPUMakeManifold ();
1565- } else {
1566- runCPUMakeManifold ();
1567- }
1572+ // for (int i = 0; i < 1; i++)
1573+ if (isUseGPU ()) {
1574+ runGPUMakeManifold ();
1575+ } else {
1576+ runCPUMakeManifold ();
1577+ }
15681578 }
15691579 performTriangulation ();
15701580 // now all polygons are definantly triangles
@@ -1576,22 +1586,23 @@ public CSG triangulate(boolean fix) {
15761586 private void performTriangulation () {
15771587 ArrayList <Polygon > toAdd = new ArrayList <Polygon >();
15781588 int failedPolys = 0 ;
1579- for (int i = 0 ; i < polygons .size ();i ++) {
1589+ for (int i = 0 ; i < polygons .size (); i ++) {
15801590 Polygon p = polygons .get (i );
15811591 CSG ret = updatePolygons (toAdd , p );
1582- if (ret ==null )
1592+ if (ret == null )
15831593 failedPolys ++;
15841594 }
1585- if (failedPolys > 0 )
1586- System .out .println ("Pruned " + failedPolys + " polygons from CSG " + getName ());
1595+ if (failedPolys > 0 )
1596+ System .out .println ("Pruned " + failedPolys + " polygons from CSG " + getName ());
15871597 if (toAdd .size () > 0 ) {
15881598 setPolygons (toAdd );
15891599 }
15901600 }
15911601
15921602 private void runCPUMakeManifold () {
15931603 long start = System .currentTimeMillis ();
1594- //System.err.println("Cleaning up the mesh by adding coincident points to the polygons they touch");
1604+ // System.err.println("Cleaning up the mesh by adding coincident points to the
1605+ // polygons they touch");
15951606
15961607 int totalAdded = 0 ;
15971608 double tOL = 1.0e-11 ;
@@ -1653,7 +1664,7 @@ private void runCPUMakeManifold() {
16531664 }
16541665 totalAdded += 32 ;
16551666 threads .clear ();
1656- if (threadIndex / 32 % 50 == 0 || j == polygons .size () - 1 ) {
1667+ if (threadIndex / 32 % 50 == 0 || j == polygons .size () - 1 ) {
16571668 progressMoniter .progressUpdate (j , polygons .size (),
16581669 "STL Processing Polygons for Manifold Vertex, #" + totalAdded + " added so far" , this );
16591670 }
@@ -1669,7 +1680,8 @@ private void runCPUMakeManifold() {
16691680 // Auto-generated catch block
16701681 e .printStackTrace ();
16711682 }
1672- //progressMoniter.progressUpdate(polygons.size(),polygons.size(),"Manifold fix took " + (System.currentTimeMillis() - start),this);
1683+ // progressMoniter.progressUpdate(polygons.size(),polygons.size(),"Manifold fix
1684+ // took " + (System.currentTimeMillis() - start),this);
16731685 }
16741686
16751687 private void runGPUMakeManifold () {
@@ -1742,19 +1754,18 @@ private CSG updatePolygons(ArrayList<Polygon> toAdd, Polygon p) {
17421754 if (p == null )
17431755 return this ;
17441756
1745-
17461757 if (p .getVertices ().size () == 3 ) {
17471758 toAdd .add (p );
17481759 } else {
17491760
17501761 try {
1751- if (!p .areAllPointsCollinear ()) {
1762+ if (!p .areAllPointsCollinear ()) {
17521763 List <Polygon > triangles = PolygonUtil .concaveToConvex (p );
17531764 for (Polygon poly : triangles ) {
17541765 toAdd .add (poly );
17551766 }
1756- }else {
1757- System .err .println ("Polygon is colinear, removing " + p );
1767+ } else {
1768+ System .err .println ("Polygon is colinear, removing " + p );
17581769 return null ;
17591770 }
17601771 } catch (Throwable ex ) {
@@ -2404,7 +2415,7 @@ public CSG historySync(CSG dyingCSG) {
24042415 }
24052416 if (getName ().length () == 0 )
24062417 setName (dyingCSG .getName ());
2407- setColor ( dyingCSG .getColor ());
2418+ setColor (dyingCSG .getColor ());
24082419 return this ;
24092420 }
24102421
@@ -2533,8 +2544,9 @@ public CSG setRegenerate(IRegenerate function) {
25332544 regenerate = function ;
25342545 return this ;
25352546 }
2547+
25362548 public IRegenerate getRegenerate () {
2537- return regenerate ;
2549+ return regenerate ;
25382550 }
25392551
25402552 public CSG regenerate () {
@@ -3113,7 +3125,7 @@ public boolean isHole() {
31133125
31143126 public CSG syncProperties (CSG dying ) {
31153127 getStorage ().syncProperties (dying .getStorage ());
3116- regenerate = dying .regenerate ;
3128+ regenerate = dying .regenerate ;
31173129 return this ;
31183130 }
31193131
0 commit comments