Browse Source

Expose cutoff parameter for CGAL intersections; better default (#2255) [ci skip]

* cutoff in cgal intersections

* missing cast
Alec Jacobson 2 years ago
parent
commit
7a84503c8e

+ 8 - 2
include/igl/copyleft/cgal/RemeshSelfIntersectionsParam.h

@@ -29,16 +29,22 @@ namespace igl
         bool stitch_all;
         bool stitch_all;
         /// whether to use slow and more precise rounding (see assign_scalar)
         /// whether to use slow and more precise rounding (see assign_scalar)
         bool slow_and_more_precise_rounding;
         bool slow_and_more_precise_rounding;
+        /// cutoff parameter for box_self_intersection_d (based on some casual
+        /// testing 1000 works better than 1,10,100,10000 etc. and better than
+        /// the recommended √n)
+        int cutoff;
         inline RemeshSelfIntersectionsParam(
         inline RemeshSelfIntersectionsParam(
           bool _detect_only=false, 
           bool _detect_only=false, 
           bool _first_only=false,
           bool _first_only=false,
           bool _stitch_all=false,
           bool _stitch_all=false,
-          bool _slow_and_more_precise_rounding=false
+          bool _slow_and_more_precise_rounding=false,
+          int _cutoff=1000
           ):
           ):
           detect_only(_detect_only),
           detect_only(_detect_only),
           first_only(_first_only),
           first_only(_first_only),
           stitch_all(_stitch_all),
           stitch_all(_stitch_all),
-          slow_and_more_precise_rounding(_slow_and_more_precise_rounding)
+          slow_and_more_precise_rounding(_slow_and_more_precise_rounding),
+          cutoff(_cutoff)
         {};
         {};
       };
       };
     }
     }

+ 2 - 2
include/igl/copyleft/cgal/SelfIntersectMesh.h

@@ -379,8 +379,8 @@ inline igl::copyleft::cgal::SelfIntersectMesh<
 #ifdef IGL_SELFINTERSECTMESH_TIMING
 #ifdef IGL_SELFINTERSECTMESH_TIMING
   log_time("box_and_bind");
   log_time("box_and_bind");
 #endif
 #endif
-  // Run the self intersection algorithm with all defaults
-  CGAL::box_self_intersection_d(boxes.begin(), boxes.end(),cb);
+  // Run the self intersection algorithm with given cutoff size
+  CGAL::box_self_intersection_d(boxes.begin(), boxes.end(),cb,std::ptrdiff_t(params.cutoff));
 #ifdef IGL_SELFINTERSECTMESH_TIMING
 #ifdef IGL_SELFINTERSECTMESH_TIMING
   log_time("box_intersection_d");
   log_time("box_intersection_d");
 #endif
 #endif

+ 2 - 1
include/igl/copyleft/cgal/intersect_other.cpp

@@ -136,7 +136,8 @@ namespace igl
           CGAL::box_intersection_d(
           CGAL::box_intersection_d(
             A_boxes.begin(), A_boxes.end(),
             A_boxes.begin(), A_boxes.end(),
             B_boxes.begin(), B_boxes.end(),
             B_boxes.begin(), B_boxes.end(),
-            cb);
+            cb,
+            std::ptrdiff_t(params.cutoff));
         }catch(int e)
         }catch(int e)
         {
         {
           // Rethrow if not FIRST_HIT_EXCEPTION
           // Rethrow if not FIRST_HIT_EXCEPTION