Merge pull request #5539 from sloriot/PMP-coref_check_si

Collect faces incident to edges too
This commit is contained in:
Sebastien Loriot 2021-04-17 11:04:38 +02:00 committed by GitHub
commit e9c97d2b59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 13 deletions

View File

@ -324,23 +324,41 @@ class Callback_with_self_intersection_report
: public Base : public Base
{ {
typedef typename Base::face_descriptor face_descriptor; typedef typename Base::face_descriptor face_descriptor;
typedef typename Base::halfedge_descriptor halfedge_descriptor;
typedef typename Base::Box Box; typedef typename Base::Box Box;
boost::shared_ptr< std::set<face_descriptor> > faces_with_bbox_involved_in_intersections; std::set<face_descriptor>* tmf_collected_faces_ptr;
std::set<face_descriptor>* tme_collected_faces_ptr;
public: public:
Callback_with_self_intersection_report(const Base& base) Callback_with_self_intersection_report(const Base& base,
: Base(base), faces_with_bbox_involved_in_intersections(new std::set<face_descriptor>()) std::set<face_descriptor>& tmf_collected_faces,
std::set<face_descriptor>& tme_collected_faces)
: Base(base),
tmf_collected_faces_ptr(&tmf_collected_faces),
tme_collected_faces_ptr(&tme_collected_faces)
{} {}
void operator()( const Box* fb, const Box* eb) { void operator()( const Box* fb, const Box* eb) {
faces_with_bbox_involved_in_intersections->insert( face(fb->info(), this->tm_faces) ); halfedge_descriptor h = eb->info();
if (!is_border(h, this->tm_edges))
tme_collected_faces_ptr->insert( face(h, this->tm_edges) );
h = opposite(h, this->tm_edges);
if (!is_border(h, this->tm_edges))
tme_collected_faces_ptr->insert( face(h, this->tm_edges) );
tmf_collected_faces_ptr->insert( face(fb->info(), this->tm_faces) );
Base::operator()(fb, eb); Base::operator()(fb, eb);
} }
bool self_intersections_found() bool self_intersections_found()
{ {
return Polygon_mesh_processing::does_self_intersect( return
*faces_with_bbox_involved_in_intersections, Polygon_mesh_processing::does_self_intersect(
*tmf_collected_faces_ptr,
this->tm_faces, this->tm_faces,
Polygon_mesh_processing::parameters::vertex_point_map(this->vpmap_tmf)); Polygon_mesh_processing::parameters::vertex_point_map(this->vpmap_tmf))
||
Polygon_mesh_processing::does_self_intersect(
*tme_collected_faces_ptr,
this->tm_edges,
Polygon_mesh_processing::parameters::vertex_point_map(this->vpmap_tme));
} }
}; };

View File

@ -195,7 +195,10 @@ class Intersection_of_triangle_meshes
const TriangleMesh& tm_e, const TriangleMesh& tm_e,
const VPMF& vpm_f, const VPMF& vpm_f,
const VPME& vpm_e, const VPME& vpm_e,
bool throw_on_self_intersection) bool throw_on_self_intersection,
std::set<face_descriptor>& tm_f_faces,
std::set<face_descriptor>& tm_e_faces,
bool run_check)
{ {
std::vector<Box> face_boxes, edge_boxes; std::vector<Box> face_boxes, edge_boxes;
std::vector<Box*> face_boxes_ptr, edge_boxes_ptr; std::vector<Box*> face_boxes_ptr, edge_boxes_ptr;
@ -245,11 +248,11 @@ class Intersection_of_triangle_meshes
#endif #endif
//using pointers in box_intersection_d is about 10% faster //using pointers in box_intersection_d is about 10% faster
if (throw_on_self_intersection){ if (throw_on_self_intersection){
Callback_with_self_intersection_report<TriangleMesh, Callback> callback_si(callback); Callback_with_self_intersection_report<TriangleMesh, Callback> callback_si(callback, tm_f_faces, tm_e_faces);
CGAL::box_intersection_d( face_boxes_ptr.begin(), face_boxes_ptr.end(), CGAL::box_intersection_d( face_boxes_ptr.begin(), face_boxes_ptr.end(),
edge_boxes_ptr.begin(), edge_boxes_ptr.end(), edge_boxes_ptr.begin(), edge_boxes_ptr.end(),
callback_si, cutoff ); callback_si, cutoff );
if (callback_si.self_intersections_found()) if (run_check && callback_si.self_intersections_found())
throw Self_intersection_exception(); throw Self_intersection_exception();
} }
else { else {
@ -1302,8 +1305,11 @@ public:
const VertexPointMap1& vpm1=nodes.vpm1; const VertexPointMap1& vpm1=nodes.vpm1;
const VertexPointMap2& vpm2=nodes.vpm2; const VertexPointMap2& vpm2=nodes.vpm2;
filter_intersections(tm1, tm2, vpm1, vpm2, throw_on_self_intersection); // used only if throw_on_self_intersection == true
filter_intersections(tm2, tm1, vpm2, vpm1, throw_on_self_intersection); std::set<face_descriptor> tm1_faces;
std::set<face_descriptor> tm2_faces;
filter_intersections(tm1, tm2, vpm1, vpm2, throw_on_self_intersection, tm1_faces, tm2_faces, false);
filter_intersections(tm2, tm1, vpm2, vpm1, throw_on_self_intersection, tm2_faces, tm1_faces, true);
Node_id current_node((std::numeric_limits<Node_id>::max)()); Node_id current_node((std::numeric_limits<Node_id>::max)());
CGAL_assertion(current_node+1==0); CGAL_assertion(current_node+1==0);