|
@@ -9,13 +9,14 @@
|
|
|
#define IGL_SELFINTERSECTMESH_H
|
|
|
|
|
|
#include "CGAL_includes.hpp"
|
|
|
-#include "remesh_self_intersections.h"
|
|
|
+#include "RemeshSelfIntersectionsParam.h"
|
|
|
|
|
|
#include <Eigen/Dense>
|
|
|
#include <list>
|
|
|
#include <map>
|
|
|
#include <vector>
|
|
|
|
|
|
+//#define IGL_SELFINTERSECTMESH_DEBUG
|
|
|
#ifndef IGL_FIRST_HIT_EXCEPTION
|
|
|
#define IGL_FIRST_HIT_EXCEPTION 10
|
|
|
#endif
|
|
@@ -325,18 +326,22 @@ inline igl::SelfIntersectMesh<
|
|
|
using namespace std;
|
|
|
using namespace Eigen;
|
|
|
|
|
|
- //const auto & tictoc = []()
|
|
|
- //{
|
|
|
- // static double t_start = igl::get_seconds();
|
|
|
- // double diff = igl::get_seconds()-t_start;
|
|
|
- // t_start += diff;
|
|
|
- // return diff;
|
|
|
- //};
|
|
|
- //tictoc();
|
|
|
+#ifdef IGL_SELFINTERSECTMESH_DEBUG
|
|
|
+ const auto & tictoc = []()
|
|
|
+ {
|
|
|
+ static double t_start = igl::get_seconds();
|
|
|
+ double diff = igl::get_seconds()-t_start;
|
|
|
+ t_start += diff;
|
|
|
+ return diff;
|
|
|
+ };
|
|
|
+ tictoc();
|
|
|
+#endif
|
|
|
|
|
|
// Compute and process self intersections
|
|
|
mesh_to_cgal_triangle_list(V,F,T);
|
|
|
- //cout<<"mesh_to_cgal_triangle_list: "<<tictoc()<<endl;
|
|
|
+#ifdef IGL_SELFINTERSECTMESH_DEBUG
|
|
|
+ cout<<"mesh_to_cgal_triangle_list: "<<tictoc()<<endl;
|
|
|
+#endif
|
|
|
// http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Box_intersection_d/Chapter_main.html#Section_63.5
|
|
|
// Create the corresponding vector of bounding boxes
|
|
|
std::vector<Box> boxes;
|
|
@@ -355,7 +360,9 @@ inline igl::SelfIntersectMesh<
|
|
|
// _1 etc. in global namespace)
|
|
|
std::placeholders::_1,
|
|
|
std::placeholders::_2);
|
|
|
- //cout<<"boxes and bind: "<<tictoc()<<endl;
|
|
|
+#ifdef IGL_SELFINTERSECTMESH_DEBUG
|
|
|
+ cout<<"boxes and bind: "<<tictoc()<<endl;
|
|
|
+#endif
|
|
|
// Run the self intersection algorithm with all defaults
|
|
|
try{
|
|
|
CGAL::box_self_intersection_d(boxes.begin(), boxes.end(),cb);
|
|
@@ -368,7 +375,9 @@ inline igl::SelfIntersectMesh<
|
|
|
}
|
|
|
// Otherwise just fall through
|
|
|
}
|
|
|
- //cout<<"box_self_intersection_d: "<<tictoc()<<endl;
|
|
|
+#ifdef IGL_SELFINTERSECTMESH_DEBUG
|
|
|
+ cout<<"box_self_intersection_d: "<<tictoc()<<endl;
|
|
|
+#endif
|
|
|
|
|
|
// Convert lIF to Eigen matrix
|
|
|
assert(lIF.size()%2 == 0);
|
|
@@ -387,7 +396,9 @@ inline igl::SelfIntersectMesh<
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
|
- //cout<<"IF: "<<tictoc()<<endl;
|
|
|
+#ifdef IGL_SELFINTERSECTMESH_DEBUG
|
|
|
+ cout<<"IF: "<<tictoc()<<endl;
|
|
|
+#endif
|
|
|
|
|
|
if(params.detect_only)
|
|
|
{
|
|
@@ -409,6 +420,9 @@ inline igl::SelfIntersectMesh<
|
|
|
map<typename CDT_plus_2::Vertex_handle,Index> v2i;
|
|
|
// Loop over offending triangles
|
|
|
const size_t noff = offending.size();
|
|
|
+#ifdef IGL_SELFINTERSECTMESH_DEBUG
|
|
|
+ double t_proj_del = 0;
|
|
|
+#endif
|
|
|
// Unfortunately it looks like CGAL has trouble allocating memory when
|
|
|
// multiple openmp threads are running. Crashes durring CDT...
|
|
|
//# pragma omp parallel for if (noff>1000)
|
|
@@ -417,7 +431,13 @@ inline igl::SelfIntersectMesh<
|
|
|
// index in F
|
|
|
const Index f = offending[o];
|
|
|
{
|
|
|
+#ifdef IGL_SELFINTERSECTMESH_DEBUG
|
|
|
+ const double t_before = get_seconds();
|
|
|
+#endif
|
|
|
projected_delaunay(T[f],F_objects[f],cdt[o]);
|
|
|
+#ifdef IGL_SELFINTERSECTMESH_DEBUG
|
|
|
+ t_proj_del += (get_seconds()-t_before);
|
|
|
+#endif
|
|
|
}
|
|
|
// Q: Is this also delaunay in 3D?
|
|
|
// A: No, because the projection is affine and delaunay is not affine
|
|
@@ -527,7 +547,10 @@ inline igl::SelfIntersectMesh<
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //cout<<"CDT: "<<tictoc()<<" "<<t_proj_del<<endl;
|
|
|
+#ifdef IGL_SELFINTERSECTMESH_DEBUG
|
|
|
+ cout<<"CDT: "<<tictoc()<<" "<<t_proj_del<<endl;
|
|
|
+#endif
|
|
|
+
|
|
|
assert(NV_count == (Index)NV.size());
|
|
|
// Build output
|
|
|
#ifndef NDEBUG
|
|
@@ -565,7 +588,7 @@ inline igl::SelfIntersectMesh<
|
|
|
}
|
|
|
// Append vertices
|
|
|
VV.resize(V.rows()+NV_count,3);
|
|
|
- VV.block(0,0,V.rows(),3) = V;
|
|
|
+ VV.block(0,0,V.rows(),3) = V.template cast<typename DerivedVV::Scalar>();
|
|
|
{
|
|
|
Index i = 0;
|
|
|
for(
|
|
@@ -576,13 +599,14 @@ inline igl::SelfIntersectMesh<
|
|
|
for(Index d = 0;d<3;d++)
|
|
|
{
|
|
|
const Point_3 & p = *nvit;
|
|
|
- VV(V.rows()+i,d) = CGAL::to_double(p[d]);
|
|
|
- // This distinction does not seem necessary:
|
|
|
-//#ifdef INEXACT_CONSTRUCTION
|
|
|
-// VV(V.rows()+i,d) = CGAL::to_double(p[d]);
|
|
|
-//#else
|
|
|
-// VV(V.rows()+i,d) = CGAL::to_double(p[d].exact());
|
|
|
-//#endif
|
|
|
+ // Don't convert via double if output type is same as Kernel
|
|
|
+ if(std::is_same<typename DerivedVV::Scalar,typename Kernel::FT>::value)
|
|
|
+ {
|
|
|
+ VV(V.rows()+i,d) = p[d];
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ VV(V.rows()+i,d) = CGAL::to_double(p[d]);
|
|
|
+ }
|
|
|
}
|
|
|
i++;
|
|
|
}
|
|
@@ -619,7 +643,9 @@ inline igl::SelfIntersectMesh<
|
|
|
v++;
|
|
|
}
|
|
|
}
|
|
|
- //cout<<"Output + dupes: "<<tictoc()<<endl;
|
|
|
+#ifdef IGL_SELFINTERSECTMESH_DEBUG
|
|
|
+ cout<<"Output + dupes: "<<tictoc()<<endl;
|
|
|
+#endif
|
|
|
|
|
|
// Q: Does this give the same result as TETGEN?
|
|
|
// A: For the cow and beast, yes.
|