77#include < algorithm>
88#include < QTime>
99
10+ #include < CGAL/Polygon_mesh_processing/border.h>
11+
1012Scene_edit_polyhedron_item::Scene_edit_polyhedron_item
1113(Scene_polyhedron_item* poly_item,
1214 Ui::DeformMesh* ui_widget,
@@ -446,24 +448,27 @@ void Scene_edit_polyhedron_item::deform()
446448
447449struct ROI_border_pmap
448450{
449- std::set<edge_descriptor>& m_set ;
451+ std::set<edge_descriptor>* m_set_ptr ;
450452
451453 typedef edge_descriptor key_type;
452454 typedef bool value_type;
453455 typedef bool reference;
454456 typedef boost::read_write_property_map_tag category;
455457
456- ROI_border_pmap (std::set<edge_descriptor>& set_)
457- : m_set(set_)
458+ ROI_border_pmap () : m_set_ptr(NULL ) {}
459+ ROI_border_pmap (std::set<edge_descriptor>* set_)
460+ : m_set_ptr(set_)
458461 {}
459462 friend bool get (const ROI_border_pmap& map, const key_type& k)
460463 {
461- return map.m_set .count (k);
464+ CGAL_assertion (map.m_set_ptr != NULL );
465+ return map.m_set_ptr ->count (k);
462466 }
463467 friend void put (ROI_border_pmap& map, const key_type& k, const value_type b)
464468 {
465- if (b) map.m_set .insert (k);
466- else map.m_set .erase (k);
469+ CGAL_assertion (map.m_set_ptr != NULL );
470+ if (b) map.m_set_ptr ->insert (k);
471+ else if (get (map,k)) map.m_set_ptr ->erase (k);
467472 }
468473};
469474
@@ -473,60 +478,63 @@ void Scene_edit_polyhedron_item::remesh()
473478 Array_based_vertex_point_map vpmap (&positions);
474479
475480 std::set<face_descriptor> roi_facets;
476- std::set<halfedge_descriptor> roi_halfedges;
481+ std::set<vertex_descriptor> roi_vertices (
482+ deform_mesh->roi_vertices ().begin (),deform_mesh->roi_vertices ().end ());
483+
477484 BOOST_FOREACH (vertex_descriptor v, deform_mesh->roi_vertices ())
478485 {
479486 BOOST_FOREACH (face_descriptor fv, CGAL::faces_around_target (halfedge (v, g), g))
480487 {
481- roi_facets. insert (fv) ;
482- BOOST_FOREACH (halfedge_descriptor h , CGAL::halfedges_around_face (halfedge (fv, g), g))
483- {
484- if (roi_halfedges. find ( opposite (h, g)) == roi_halfedges. end ()) // not already computed
485- roi_halfedges. insert (h);
486- }
488+ bool add_face= true ;
489+ BOOST_FOREACH (vertex_descriptor vfd , CGAL::vertices_around_face (halfedge (fv,g),g))
490+ if (roi_vertices. count (vfd)== 0 )
491+ add_face= false ;
492+ if (add_face)
493+ roi_facets. insert (fv);
487494 }
488495 }
489496
497+ // set face_index map needed for border_halfedges and isotropic_remeshing
498+ boost::property_map<Polyhedron, CGAL::face_index_t >::type fim
499+ = get (CGAL::face_index, *polyhedron ());
500+ unsigned int id = 0 ;
501+
502+ // estimate the target_length using the perimeter of the region to remesh
490503 bool automatic_target_length = !ui_widget->remeshingEdgeLengthInput_checkBox ->isChecked ();
491- double sum_len = 0 .;
492- std::set<edge_descriptor> roi_border;
493- BOOST_FOREACH (halfedge_descriptor h, roi_halfedges)
504+ double estimated_target_length = 0 .;
505+ if (automatic_target_length)
494506 {
495- if (roi_halfedges.find (opposite (h, g)) == roi_halfedges.end ())
507+ BOOST_FOREACH (face_descriptor f, faces (*polyhedron ()))
508+ put (fim, f, id++);
509+ std::set<halfedge_descriptor> roi_border_halfedges;
510+ CGAL::Polygon_mesh_processing::border_halfedges (roi_facets, g,
511+ std::inserter (roi_border_halfedges, roi_border_halfedges.begin ()));
512+
513+ double sum_len=0 .;
514+ BOOST_FOREACH (halfedge_descriptor h, roi_border_halfedges)
496515 {
497- roi_border.insert (edge (h, g));
498- if (automatic_target_length)
499- sum_len += CGAL::sqrt (CGAL::squared_distance (
500- get (vpmap, source (h, g)), get (vpmap, target (h, g))));
516+ sum_len += CGAL::sqrt (CGAL::squared_distance (
517+ get (vpmap, source (h, g)), get (vpmap, target (h, g))));
501518 }
519+ if (sum_len==0 ) automatic_target_length = false ;
520+ else
521+ estimated_target_length = sum_len / (0 . + roi_border_halfedges.size ());
502522 }
503523
504- if (roi_border.empty ())
505- automatic_target_length = false ;
506-
507524 double target_length = automatic_target_length
508- ? sum_len / ( 0 . + roi_border. size ())
525+ ? estimated_target_length
509526 : ui_widget->remeshing_edge_length_spinbox ->value ();
510527
511528 unsigned int nb_iter = ui_widget->remeshing_iterations_spinbox ->value ();
512529
513- // set face_index map for border_halfedges
514- boost::property_map<Polyhedron, CGAL::face_index_t >::type fim
515- = get (CGAL::face_index, *polyhedron ());
516- unsigned int id = 0 ;
517- BOOST_FOREACH (face_descriptor f, faces (*polyhedron ()))
518- put (fim, f, id++);
519-
520530 std::cout << " Remeshing..." ;
521- ROI_border_pmap border_pmap (roi_border);
522531 CGAL::Polygon_mesh_processing::isotropic_remeshing (
523532 roi_facets
524533 , target_length
525534 , *polyhedron ()
526535 , CGAL::Polygon_mesh_processing::parameters::number_of_iterations (nb_iter)
527536 .protect_constraints (false )
528537 .vertex_point_map (vpmap)
529- .edge_is_constrained_map (border_pmap)
530538 );
531539 std::cout << " done." << std::endl;
532540
@@ -545,12 +553,6 @@ void Scene_edit_polyhedron_item::remesh()
545553 Deform_mesh::Hedge_index_map (),
546554 vpmap);
547555
548- BOOST_FOREACH (halfedge_descriptor h, halfedges (*polyhedron ()))
549- {
550- if (get (border_pmap, edge (h, *polyhedron ())))
551- insert_roi_vertex (target (h, *polyhedron ()));
552- }
553-
554556 reset_drawing_data ();
555557 compute_normals_and_vertices ();
556558
@@ -611,7 +613,9 @@ bool Scene_edit_polyhedron_item::eventFilter(QObject* /*target*/, QEvent *event)
611613 const QPoint& p = viewer->mapFromGlobal (QCursor::pos ());
612614 bool need_repaint = activate_closest_manipulated_frame (p.x (), p.y ());
613615
614- if (ctrl_released_now && ui_widget->RemeshingCheckBox ->isChecked ()){
616+ if (!ui_widget->ActivatePivotingCheckBox ->isChecked () &&
617+ ctrl_released_now && ui_widget->RemeshingCheckBox ->isChecked ())
618+ {
615619 remesh ();
616620 }
617621
0 commit comments