99
1010#ifdef IPC_TOOLKIT_WITH_CORRECT_CCD
1111#include < tight_inclusion/ccd.hpp>
12- #include < tight_inclusion/interval_root_finder.hpp>
1312#else
1413#include < ipc/ccd/inexact_point_edge.hpp>
1514#include < CTCD.h>
2019
2120namespace ipc {
2221
23- namespace {
24- inline Eigen::Vector3d to_3D (const VectorMax3d& v)
25- {
26- assert (v.size () == 2 || v.size () == 3 );
27- return v.size () == 2 ? Eigen::Vector3d (v.x (), v.y (), 0 ) : v.head <3 >();
28- }
29-
30- inline bool check_initial_distance (
31- const double initial_distance, const double min_distance, double & toi)
32- {
33- if (initial_distance > min_distance) {
34- return false ;
35- }
36-
37- logger ().warn (
38- " Initial distance {} ≤ d_min={}, returning toi=0!" ,
39- initial_distance, min_distance);
40-
41- toi = 0 ; // Initially touching
42-
43- return true ;
44- }
45- } // namespace
46-
47- // / @brief Scale the distance tolerance to be at most this fraction of the initial distance.
22+ // / Scale the distance tolerance to be at most this fraction of the initial
23+ // / distance.
4824static constexpr double INITIAL_DISTANCE_TOLERANCE_SCALE = 0.5 ;
4925
50- // / @brief Special value for max_iterations to run tight inclusion without a maximum number of iterations.
26+ // / Special value for max_iterations to run tight inclusion without a maximum
27+ // / number of iterations.
5128static constexpr long TIGHT_INCLUSION_UNLIMITED_ITERATIONS = -1 ;
5229
53- // / @brief Tolerance for small time of impact which triggers rerunning CCD without a minimum separation.
54- static constexpr double SMALL_TOI = 1e-6 ;
55-
5630bool ccd_strategy (
5731 const std::function<bool (
5832 long /* max_iterations*/ ,
@@ -87,15 +61,15 @@ bool ccd_strategy(
8761 // #ifdef IPC_TOOLKIT_WITH_CORRECT_CCD
8862 // // Tight inclusion will have higher accuracy and better performance
8963 // // if we shrink the minimum distance. The value 1e-10 is arbitrary.
90- // while (is_impacting && toi < SMALL_TOI && min_distance > 1e-10) {
64+ // while (is_impacting && toi < CCD_SMALL_TOI && min_distance > 1e-10) {
9165 // min_distance /= 10;
9266 // is_impacting =
9367 // ccd(max_iterations, min_distance, /*no_zero_toi=*/false,
9468 // toi);
9569 // }
9670 // #endif
9771
98- if (is_impacting && toi < SMALL_TOI ) {
72+ if (is_impacting && toi < CCD_SMALL_TOI ) {
9973 is_impacting = ccd (
10074 /* max_iterations=*/ TIGHT_INCLUSION_UNLIMITED_ITERATIONS,
10175 /* min_distance=*/ min_distance, /* no_zero_toi=*/ true , toi);
@@ -219,7 +193,7 @@ bool point_edge_ccd_3D(
219193 max_iterations, // maximum number of iterations
220194 output_tolerance, // delta_actual
221195 no_zero_toi);
222- if (adjusted_tolerance < output_tolerance && toi < SMALL_TOI ) {
196+ if (adjusted_tolerance < output_tolerance && toi < CCD_SMALL_TOI ) {
223197 logger ().trace (
224198 " ticcd::edgeEdgeCCD exceeded iteration limit (min_dist={:g} "
225199 " max_iterations={:d} input_tol={:g} output_tol={:g} toi={:g})" ,
@@ -252,10 +226,9 @@ bool point_edge_ccd(
252226 const long max_iterations,
253227 const double conservative_rescaling)
254228{
255- int dim = p_t0.size ();
256- assert (p_t1.size () == dim);
257- assert (e0_t0.size () == dim && e1_t0.size () == dim);
258- assert (e0_t1.size () == dim && e1_t1.size () == dim);
229+ assert (p_t1.size () == p_t0.size ());
230+ assert (e0_t0.size () == p_t0.size () && e1_t0.size () == p_t0.size ());
231+ assert (e0_t1.size () == p_t0.size () && e1_t1.size () == p_t0.size ());
259232 return point_edge_ccd_3D (
260233 to_3D (p_t0), to_3D (e0_t0), to_3D (e1_t0), to_3D (p_t1), to_3D (e0_t1),
261234 to_3D (e1_t1), toi, min_distance, tmax, tolerance, max_iterations,
@@ -305,7 +278,7 @@ bool edge_edge_ccd(
305278 max_iterations, // maximum number of iterations
306279 output_tolerance, // delta_actual
307280 no_zero_toi);
308- if (adjusted_tolerance < output_tolerance && toi < SMALL_TOI ) {
281+ if (adjusted_tolerance < output_tolerance && toi < CCD_SMALL_TOI ) {
309282 logger ().trace (
310283 " ticcd::edgeEdgeCCD exceeded iteration limit (min_dist={:g} "
311284 " max_iterations={:d} input_tol={:g} output_tol={:g} toi={:g})" ,
@@ -368,7 +341,7 @@ bool point_triangle_ccd(
368341 max_iterations, // maximum number of iterations
369342 output_tolerance, // delta_actual
370343 no_zero_toi);
371- if (adjusted_tolerance < output_tolerance && toi < SMALL_TOI ) {
344+ if (adjusted_tolerance < output_tolerance && toi < CCD_SMALL_TOI ) {
372345 logger ().trace (
373346 " ticcd::vertexFaceCCD exceeded iteration limit (min_dist={:g} "
374347 " max_iterations={:d} input_tol={:g} output_tol={:g} toi={:g})" ,
@@ -388,4 +361,22 @@ bool point_triangle_ccd(
388361 conservative_rescaling, toi);
389362}
390363
364+ // -----------------------------------------------------------------------------
365+
366+ bool check_initial_distance (
367+ const double initial_distance, const double min_distance, double & toi)
368+ {
369+ if (initial_distance > min_distance) {
370+ return false ;
371+ }
372+
373+ logger ().warn (
374+ " Initial distance {} ≤ d_min={}, returning toi=0!" , initial_distance,
375+ min_distance);
376+
377+ toi = 0 ; // Initially touching
378+
379+ return true ;
380+ }
381+
391382} // namespace ipc
0 commit comments