Skip to content

Commit dee4739

Browse files
committed
Merge pull request #915 from janetournois/Polyhedron_demo-fix_deformation_plugin-jtournois
Polyhedron demo : fix deformation plugin
2 parents 5243664 + b64d0ee commit dee4739

File tree

3 files changed

+60
-56
lines changed

3 files changed

+60
-56
lines changed

Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/remesh_impl.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <boost/property_map/property_map.hpp>
4646
#include <boost/range.hpp>
4747
#include <boost/unordered_map.hpp>
48+
#include <boost/shared_ptr.hpp>
4849

4950
#include <map>
5051
#include <list>
@@ -101,7 +102,7 @@ namespace internal {
101102
typedef typename boost::graph_traits<PM>::halfedge_descriptor halfedge_descriptor;
102103
typedef typename boost::graph_traits<PM>::edge_descriptor edge_descriptor;
103104

104-
std::map<edge_descriptor, bool> border_edges;
105+
boost::shared_ptr< std::set<edge_descriptor> > border_edges_ptr;
105106
const PM* pmesh_ptr_;
106107

107108
public:
@@ -110,38 +111,37 @@ namespace internal {
110111
typedef value_type& reference;
111112
typedef boost::read_write_property_map_tag category;
112113

113-
Border_constraint_pmap():pmesh_ptr_(NULL) {}
114+
Border_constraint_pmap()
115+
: border_edges_ptr(new std::set<edge_descriptor>() )
116+
, pmesh_ptr_(NULL)
117+
{}
114118
Border_constraint_pmap(const PM& pmesh, const FaceRange& faces)
115-
: pmesh_ptr_(&pmesh)
119+
: border_edges_ptr(new std::set<edge_descriptor>() )
120+
, pmesh_ptr_(&pmesh)
116121
{
117122
std::vector<halfedge_descriptor> border;
118123
PMP::border_halfedges(faces, *pmesh_ptr_, std::back_inserter(border));
119124

120-
BOOST_FOREACH(edge_descriptor e, edges(*pmesh_ptr_))
121-
border_edges.insert(std::make_pair(e, false));
122-
123125
BOOST_FOREACH(halfedge_descriptor h, border)
124-
border_edges[edge(h, *pmesh_ptr_)] = true;
126+
border_edges_ptr->insert(edge(h, *pmesh_ptr_));
125127
}
126128

127129
friend bool get(const Border_constraint_pmap<PM, FaceRange>& map,
128130
const edge_descriptor& e)
129131
{
130132
CGAL_assertion(map.pmesh_ptr_!=NULL);
131-
CGAL_assertion(!map.border_edges.empty());
132-
typename std::map<edge_descriptor, bool>::const_iterator it
133-
= map.border_edges.find(e);
134-
135-
CGAL_assertion(it != map.border_edges.end());
136-
return it->second;
133+
return map.border_edges_ptr->count(e)!=0;
137134
}
138135

139136
friend void put(Border_constraint_pmap<PM, FaceRange>& map,
140137
const edge_descriptor& e,
141138
const bool is)
142139
{
143140
CGAL_assertion(map.pmesh_ptr_ != NULL);
144-
map.border_edges[e] = is;
141+
if (is)
142+
map.border_edges_ptr->insert(e);
143+
else
144+
map.border_edges_ptr->erase(e);
145145
}
146146
};
147147

Polyhedron/demo/Polyhedron/Plugins/Surface_mesh_deformation/Scene_edit_polyhedron_item.cpp

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <algorithm>
88
#include <QTime>
99

10+
#include <CGAL/Polygon_mesh_processing/border.h>
11+
1012
Scene_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

447449
struct 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

Surface_mesh_deformation/include/CGAL/Surface_mesh_deformation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ class Surface_mesh_deformation
857857
/**
858858
* Returns the range of vertices in the region-of-interest.
859859
*/
860-
Roi_vertex_range roi_vertices() const
860+
const Roi_vertex_range& roi_vertices() const
861861
{
862862
return roi;
863863
}

0 commit comments

Comments
 (0)