@@ -204,10 +204,10 @@ private enum PlaneType {
204
204
*/
205
205
public void splitPolygon (Polygon polygon , List <Polygon > coplanarFront , List <Polygon > coplanarBack ,
206
206
List <Polygon > front , List <Polygon > back ) {
207
- // final int COPLANAR = 0;
208
- // final int FRONT = 1;
209
- // final int BACK = 2;
210
- // final int SPANNING = 3; // == some in the FRONT + some in the BACK
207
+ final int COPLANAR = 0 ;
208
+ final int FRONT = 1 ;
209
+ final int BACK = 2 ;
210
+ final int SPANNING = 3 ; // == some in the FRONT + some in the BACK
211
211
if (debugger != null && useDebugger ) {
212
212
// debugger.display(polygon);
213
213
// debugger.display(coplanarFront);
@@ -219,26 +219,25 @@ public void splitPolygon(Polygon polygon, List<Polygon> coplanarFront, List<Poly
219
219
double negEpsilon = polygon .getNegEpsilon ();
220
220
double posEpsilon = polygon .getPosEpsilon ();
221
221
222
- PlaneType polygonType = PlaneType . COPLANAR ;
223
- List <PlaneType > types = new ArrayList <>();
222
+ int polygonType = 0 ;
223
+ List <Integer > types = new ArrayList <>();
224
224
boolean somePointsInfront = false ;
225
225
boolean somePointsInBack = false ;
226
226
for (int i = 0 ; i < polygon .size (); i ++) {
227
227
double t = this .getNormal ().dot (polygon .get (i ).pos ) - this .getDist ();
228
- PlaneType type = (t < negEpsilon ) ? PlaneType .BACK
229
- : (t > posEpsilon ) ? PlaneType .FRONT : PlaneType .COPLANAR ;
230
- if (type == PlaneType .BACK )
228
+ int type = (t < negEpsilon ) ? BACK : (t > posEpsilon ) ? FRONT : COPLANAR ;
229
+ if (type == BACK )
231
230
somePointsInBack = true ;
232
- if (type == PlaneType . FRONT )
231
+ if (type == FRONT )
233
232
somePointsInfront = true ;
234
233
types .add (type );
235
234
}
236
235
if (somePointsInBack && somePointsInfront )
237
- polygonType = PlaneType . SPANNING ;
236
+ polygonType = SPANNING ;
238
237
else if (somePointsInBack ) {
239
- polygonType = PlaneType . BACK ;
238
+ polygonType = BACK ;
240
239
} else if (somePointsInfront )
241
- polygonType = PlaneType . FRONT ;
240
+ polygonType = FRONT ;
242
241
243
242
// Put the polygon in the correct list, splitting it when necessary.
244
243
switch (polygonType ) {
@@ -252,88 +251,88 @@ else if (somePointsInBack) {
252
251
back .add (polygon );
253
252
break ;
254
253
case SPANNING :
255
- ArrayList <Vertex > f = new ArrayList <>();
256
- ArrayList <Vertex > b = new ArrayList <>();
254
+ List <Vertex > f = new ArrayList <>();
255
+ List <Vertex > b = new ArrayList <>();
257
256
for (int i = 0 ; i < polygon .size (); i ++) {
258
257
int j = (i + 1 ) % polygon .size ();
259
- PlaneType ti = types .get (i );
260
- PlaneType tj = types .get (j );
258
+ int ti = types .get (i );
259
+ int tj = types .get (j );
261
260
Vertex vi = polygon .get (i );
262
261
Vertex vj = polygon .get (j );
263
- if (ti != PlaneType . BACK ) {
264
- f .add (vi . clone () );
262
+ if (ti != BACK ) {
263
+ f .add (vi );
265
264
}
266
- if (ti != PlaneType . FRONT ) {
267
- b .add (vi .clone ());
265
+ if (ti != FRONT ) {
266
+ b .add (ti != BACK ? vi .clone () : vi );
268
267
}
269
- if ((ti == PlaneType .FRONT && tj == PlaneType .BACK )
270
- || (ti == PlaneType .BACK && tj == PlaneType .FRONT )) {
268
+ if ((ti | tj ) == SPANNING ) {
271
269
double t = (this .getDist () - this .getNormal ().dot (vi .pos ))
272
270
/ this .getNormal ().dot (vj .pos .minus (vi .pos ));
273
- if (t > 1 )
274
- t = 1 ;
275
- if (t < 0 )
276
- t = 0 ;
277
271
Vertex v = vi .interpolate (vj , t );
278
272
f .add (v );
279
273
b .add (v .clone ());
280
274
}
281
275
}
282
-
283
- try {
284
- Polygon frontPoly = new Polygon (f , polygon .getStorage (), polygon .plane ).setColor (polygon .getColor ());
285
- if (f .size () == 3 )
286
- front .add (frontPoly );
287
- else
288
- try {
289
- front .addAll (PolygonUtil .triangulate (frontPoly ));
290
- } catch (Exception e ) {
291
- throw e ;
292
- }
293
- } catch (InvalidNormalException e ) {
294
- // Auto-generated catch block
295
- e .printStackTrace ();
296
- } catch (TooFewPointsException e ) {
297
- // Auto-generated catch block
298
- e .printStackTrace ();
299
- } catch (PointsColinearException e ) {
300
- // Auto-generated catch block
301
- e .printStackTrace ();
302
- } catch (PointsNotCoplainer e ) {
303
- // Auto-generated catch block
304
- e .printStackTrace ();
305
- } catch (java .lang .IllegalStateException e ) {
306
- // Auto-generated catch block
307
- e .printStackTrace ();
276
+ if (f .size () >= 3 ) {
277
+ try {
278
+ Polygon frontPoly = new Polygon (f , polygon .getStorage (), polygon .plane ).setColor (polygon .getColor ());
279
+ if (f .size () == 3 )
280
+ front .add (frontPoly );
281
+ else
282
+ try {
283
+ front .addAll (PolygonUtil .triangulate (frontPoly ));
284
+ } catch (Exception e ) {
285
+ throw e ;
286
+ }
287
+ } catch (InvalidNormalException e ) {
288
+ // Auto-generated catch block
289
+ e .printStackTrace ();
290
+ } catch (TooFewPointsException e ) {
291
+ // Auto-generated catch block
292
+ e .printStackTrace ();
293
+ } catch (PointsColinearException e ) {
294
+ // Auto-generated catch block
295
+ e .printStackTrace ();
296
+ } catch (PointsNotCoplainer e ) {
297
+ // Auto-generated catch block
298
+ e .printStackTrace ();
299
+ } catch (java .lang .IllegalStateException e ) {
300
+ // Auto-generated catch block
301
+ e .printStackTrace ();
302
+ }
303
+ } else {
304
+ // com.neuronrobotics.sdk.common.Log.error("Front Clip Fault!");
308
305
}
309
-
310
- try {
311
- Polygon backPoly = new Polygon (b , polygon .getStorage (), polygon .plane ).setColor (polygon .getColor ());
312
- if (b .size () == 3 )
313
- back .add (backPoly );
314
- else
315
- try {
316
- back .addAll (PolygonUtil .triangulate (backPoly ));
317
- } catch (Exception e ) {
318
- throw e ;
319
- }
320
- } catch (InvalidNormalException e ) {
321
- // Auto-generated catch block
322
- e .printStackTrace ();
323
- } catch (TooFewPointsException e ) {
324
- // Auto-generated catch block
325
- e .printStackTrace ();
326
- } catch (PointsColinearException e ) {
327
- // Auto-generated catch block
328
- e .printStackTrace ();
329
- } catch (PointsNotCoplainer e ) {
330
- // Auto-generated catch block
331
- e .printStackTrace ();
332
- } catch (java .lang .IllegalStateException e ) {
333
- // Auto-generated catch block
334
- e .printStackTrace ();
306
+ if (b .size () >= 3 ) {
307
+ try {
308
+ Polygon backPoly = new Polygon (b , polygon .getStorage (), polygon .plane ).setColor (polygon .getColor ());
309
+ if (b .size () == 3 )
310
+ back .add (backPoly );
311
+ else
312
+ try {
313
+ back .addAll (PolygonUtil .triangulate (backPoly ));
314
+ } catch (Exception e ) {
315
+ throw e ;
316
+ }
317
+ } catch (InvalidNormalException e ) {
318
+ // Auto-generated catch block
319
+ e .printStackTrace ();
320
+ } catch (TooFewPointsException e ) {
321
+ // Auto-generated catch block
322
+ e .printStackTrace ();
323
+ } catch (PointsColinearException e ) {
324
+ // Auto-generated catch block
325
+ e .printStackTrace ();
326
+ } catch (PointsNotCoplainer e ) {
327
+ // Auto-generated catch block
328
+ e .printStackTrace ();
329
+ } catch (java .lang .IllegalStateException e ) {
330
+ // Auto-generated catch block
331
+ e .printStackTrace ();
332
+ }
333
+ } else {
334
+ // com.neuronrobotics.sdk.common.Log.error("Back Clip Fault!");
335
335
}
336
-
337
336
break ;
338
337
}
339
338
}
0 commit comments