mirror of https://github.com/CGAL/cgal
Add adaptive remeshing to Polyhedorn demo, PMP plugin
This commit is contained in:
parent
0fbcb4175c
commit
91216f7875
|
|
@ -465,16 +465,16 @@ void tangential_relaxation_with_sizing(const VertexRange& vertices,
|
||||||
const vertex_descriptor v2 = source(h, tm);
|
const vertex_descriptor v2 = source(h, tm);
|
||||||
|
|
||||||
//todo ip- alt calc
|
//todo ip- alt calc
|
||||||
const Vector_3 vec0 = vector(get(vpm, v), get(vpm, v1));
|
// const Vector_3 vec0 = vector(get(vpm, v), get(vpm, v1));
|
||||||
const Vector_3 vec1 = vector(get(vpm, v), get(vpm, v2));
|
// const Vector_3 vec1 = vector(get(vpm, v), get(vpm, v2));
|
||||||
const double sqarea = squared_length(cross_product(vec0, vec1));
|
// const double sqarea = squared_length(cross_product(vec0, vec1));
|
||||||
const double face_weight = CGAL::approximate_sqrt(sqarea)
|
// const double face_weight = CGAL::approximate_sqrt(sqarea)
|
||||||
/ pow(1. / 3. * (sizing.get_sizing(v) + sizing.get_sizing(v1) + sizing.get_sizing(v2)), 2);
|
// / pow(1. / 3. * (sizing.get_sizing(v) + sizing.get_sizing(v1) + sizing.get_sizing(v2)), 2);
|
||||||
|
|
||||||
//todo ip- paper implementation
|
//todo ip- paper implementation
|
||||||
// const double tri_area = gt_area(get(vpm, v), get(vpm, v1), get(vpm, v2));
|
const double tri_area = gt_area(get(vpm, v), get(vpm, v1), get(vpm, v2));
|
||||||
// const double face_weight = tri_area
|
const double face_weight = tri_area
|
||||||
// / (1. / 3. * (sizing.get_sizing(v) + sizing.get_sizing(v1) + sizing.get_sizing(v2)));
|
/ (1. / 3. * (sizing.get_sizing(v) + sizing.get_sizing(v1) + sizing.get_sizing(v2)));
|
||||||
weight += face_weight;
|
weight += face_weight;
|
||||||
|
|
||||||
const Point_3 centroid = gt_centroid(get(vpm, v), get(vpm, v1), get(vpm, v2));
|
const Point_3 centroid = gt_centroid(get(vpm, v), get(vpm, v1), get(vpm, v2));
|
||||||
|
|
|
||||||
|
|
@ -358,9 +358,13 @@ public Q_SLOTS:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int edge_sizing_type = ui.edgeSizing_type_combo_box->currentIndex();
|
||||||
bool edges_only = ui.splitEdgesOnly_checkbox->isChecked();
|
bool edges_only = ui.splitEdgesOnly_checkbox->isChecked();
|
||||||
bool preserve_duplicates = ui.preserveDuplicates_checkbox->isChecked();
|
bool preserve_duplicates = ui.preserveDuplicates_checkbox->isChecked();
|
||||||
double target_length = ui.edgeLength_dspinbox->value();
|
double target_length = ui.edgeLength_dspinbox->value();
|
||||||
|
double error_tol = ui.errorTol_edit->value();
|
||||||
|
double min_length = ui.minEdgeLength_edit->value();
|
||||||
|
double max_length = ui.maxEdgeLength_edit->value();
|
||||||
unsigned int nb_iter = ui.nbIterations_spinbox->value();
|
unsigned int nb_iter = ui.nbIterations_spinbox->value();
|
||||||
unsigned int nb_smooth = ui.nbSmoothing_spinbox->value();
|
unsigned int nb_smooth = ui.nbSmoothing_spinbox->value();
|
||||||
bool protect = ui.protect_checkbox->isChecked();
|
bool protect = ui.protect_checkbox->isChecked();
|
||||||
|
|
@ -457,6 +461,8 @@ public Q_SLOTS:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (edge_sizing_type == 0)
|
||||||
|
{
|
||||||
if (fpmap_valid)
|
if (fpmap_valid)
|
||||||
CGAL::Polygon_mesh_processing::isotropic_remeshing(faces(*selection_item->polyhedron())
|
CGAL::Polygon_mesh_processing::isotropic_remeshing(faces(*selection_item->polyhedron())
|
||||||
, target_length
|
, target_length
|
||||||
|
|
@ -480,6 +486,36 @@ public Q_SLOTS:
|
||||||
.vertex_is_constrained_map(selection_item->constrained_vertices_pmap())
|
.vertex_is_constrained_map(selection_item->constrained_vertices_pmap())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
else if (edge_sizing_type == 1)
|
||||||
|
{
|
||||||
|
std::pair<double, double> edge_min_max{min_length, max_length};
|
||||||
|
PMP::Adaptive_sizing_field adaptive_sizing_field(error_tol
|
||||||
|
, edge_min_max
|
||||||
|
, *selection_item->polyhedron());
|
||||||
|
if (fpmap_valid)
|
||||||
|
CGAL::Polygon_mesh_processing::isotropic_remeshing(faces(*selection_item->polyhedron())
|
||||||
|
, adaptive_sizing_field
|
||||||
|
, *selection_item->polyhedron()
|
||||||
|
, CGAL::parameters::number_of_iterations(nb_iter)
|
||||||
|
.protect_constraints(protect)
|
||||||
|
.edge_is_constrained_map(selection_item->constrained_edges_pmap())
|
||||||
|
.relax_constraints(smooth_features)
|
||||||
|
.number_of_relaxation_steps(nb_smooth)
|
||||||
|
.vertex_is_constrained_map(selection_item->constrained_vertices_pmap())
|
||||||
|
.face_patch_map(fpmap));
|
||||||
|
else
|
||||||
|
CGAL::Polygon_mesh_processing::isotropic_remeshing(faces(*selection_item->polyhedron())
|
||||||
|
, adaptive_sizing_field
|
||||||
|
, *selection_item->polyhedron()
|
||||||
|
, CGAL::parameters::number_of_iterations(nb_iter)
|
||||||
|
.protect_constraints(protect)
|
||||||
|
.edge_is_constrained_map(selection_item->constrained_edges_pmap())
|
||||||
|
.relax_constraints(smooth_features)
|
||||||
|
.number_of_relaxation_steps(nb_smooth)
|
||||||
|
.vertex_is_constrained_map(selection_item->constrained_vertices_pmap())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
else //selected_facets not empty
|
else //selected_facets not empty
|
||||||
{
|
{
|
||||||
for (auto f : selection_item->selected_facets)
|
for (auto f : selection_item->selected_facets)
|
||||||
|
|
@ -507,6 +543,8 @@ public Q_SLOTS:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (edge_sizing_type == 0)
|
||||||
|
{
|
||||||
if (fpmap_valid)
|
if (fpmap_valid)
|
||||||
CGAL::Polygon_mesh_processing::isotropic_remeshing(selection_item->selected_facets
|
CGAL::Polygon_mesh_processing::isotropic_remeshing(selection_item->selected_facets
|
||||||
, target_length
|
, target_length
|
||||||
|
|
@ -527,7 +565,38 @@ public Q_SLOTS:
|
||||||
.edge_is_constrained_map(selection_item->constrained_edges_pmap())
|
.edge_is_constrained_map(selection_item->constrained_edges_pmap())
|
||||||
.relax_constraints(smooth_features)
|
.relax_constraints(smooth_features)
|
||||||
.number_of_relaxation_steps(nb_smooth)
|
.number_of_relaxation_steps(nb_smooth)
|
||||||
.vertex_is_constrained_map(selection_item->constrained_vertices_pmap()));
|
.vertex_is_constrained_map(selection_item->constrained_vertices_pmap())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if (edge_sizing_type == 1)
|
||||||
|
{
|
||||||
|
std::pair<double, double> edge_min_max{min_length, max_length};
|
||||||
|
PMP::Adaptive_sizing_field adaptive_sizing_field(error_tol
|
||||||
|
, edge_min_max
|
||||||
|
, *selection_item->polyhedron());
|
||||||
|
if (fpmap_valid)
|
||||||
|
CGAL::Polygon_mesh_processing::isotropic_remeshing(selection_item->selected_facets
|
||||||
|
, adaptive_sizing_field
|
||||||
|
, *selection_item->polyhedron()
|
||||||
|
, CGAL::parameters::number_of_iterations(nb_iter)
|
||||||
|
.protect_constraints(protect)
|
||||||
|
.edge_is_constrained_map(selection_item->constrained_edges_pmap())
|
||||||
|
.relax_constraints(smooth_features)
|
||||||
|
.number_of_relaxation_steps(nb_smooth)
|
||||||
|
.vertex_is_constrained_map(selection_item->constrained_vertices_pmap())
|
||||||
|
.face_patch_map(fpmap));
|
||||||
|
else
|
||||||
|
CGAL::Polygon_mesh_processing::isotropic_remeshing(selection_item->selected_facets
|
||||||
|
, adaptive_sizing_field
|
||||||
|
, *selection_item->polyhedron()
|
||||||
|
, CGAL::parameters::number_of_iterations(nb_iter)
|
||||||
|
.protect_constraints(protect)
|
||||||
|
.edge_is_constrained_map(selection_item->constrained_edges_pmap())
|
||||||
|
.relax_constraints(smooth_features)
|
||||||
|
.number_of_relaxation_steps(nb_smooth)
|
||||||
|
.vertex_is_constrained_map(selection_item->constrained_vertices_pmap())
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -634,6 +703,8 @@ public Q_SLOTS:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (edge_sizing_type == 0)
|
||||||
|
{
|
||||||
if (fpmap_valid)
|
if (fpmap_valid)
|
||||||
CGAL::Polygon_mesh_processing::isotropic_remeshing(
|
CGAL::Polygon_mesh_processing::isotropic_remeshing(
|
||||||
faces(*poly_item->polyhedron())
|
faces(*poly_item->polyhedron())
|
||||||
|
|
@ -655,6 +726,35 @@ public Q_SLOTS:
|
||||||
.number_of_relaxation_steps(nb_smooth)
|
.number_of_relaxation_steps(nb_smooth)
|
||||||
.edge_is_constrained_map(ecm)
|
.edge_is_constrained_map(ecm)
|
||||||
.relax_constraints(smooth_features));
|
.relax_constraints(smooth_features));
|
||||||
|
}
|
||||||
|
else if (edge_sizing_type == 1)
|
||||||
|
{
|
||||||
|
std::pair<double, double> edge_min_max{min_length, max_length};
|
||||||
|
PMP::Adaptive_sizing_field adaptive_sizing_field(error_tol
|
||||||
|
, edge_min_max
|
||||||
|
, *poly_item->polyhedron());
|
||||||
|
if (fpmap_valid)
|
||||||
|
CGAL::Polygon_mesh_processing::isotropic_remeshing(
|
||||||
|
faces(*poly_item->polyhedron())
|
||||||
|
, adaptive_sizing_field
|
||||||
|
, *poly_item->polyhedron()
|
||||||
|
, CGAL::parameters::number_of_iterations(nb_iter)
|
||||||
|
.protect_constraints(protect)
|
||||||
|
.number_of_relaxation_steps(nb_smooth)
|
||||||
|
.edge_is_constrained_map(ecm)
|
||||||
|
.relax_constraints(smooth_features)
|
||||||
|
.face_patch_map(fpmap));
|
||||||
|
else
|
||||||
|
CGAL::Polygon_mesh_processing::isotropic_remeshing(
|
||||||
|
faces(*poly_item->polyhedron())
|
||||||
|
, adaptive_sizing_field
|
||||||
|
, *poly_item->polyhedron()
|
||||||
|
, CGAL::parameters::number_of_iterations(nb_iter)
|
||||||
|
.protect_constraints(protect)
|
||||||
|
.number_of_relaxation_steps(nb_smooth)
|
||||||
|
.edge_is_constrained_map(ecm)
|
||||||
|
.relax_constraints(smooth_features));
|
||||||
|
}
|
||||||
|
|
||||||
//recollect sharp edges
|
//recollect sharp edges
|
||||||
for(edge_descriptor e : edges(pmesh))
|
for(edge_descriptor e : edges(pmesh))
|
||||||
|
|
@ -687,7 +787,11 @@ public Q_SLOTS:
|
||||||
{
|
{
|
||||||
// Remeshing parameters
|
// Remeshing parameters
|
||||||
bool edges_only = false, preserve_duplicates = false;
|
bool edges_only = false, preserve_duplicates = false;
|
||||||
|
int edge_sizing_type = 0;
|
||||||
double target_length = 0.;
|
double target_length = 0.;
|
||||||
|
double error_tol = 0.;
|
||||||
|
double min_length = 0.;
|
||||||
|
double max_length = 0.;
|
||||||
unsigned int nb_iter = 1;
|
unsigned int nb_iter = 1;
|
||||||
bool protect = false;
|
bool protect = false;
|
||||||
bool smooth_features = true;
|
bool smooth_features = true;
|
||||||
|
|
@ -723,7 +827,11 @@ public Q_SLOTS:
|
||||||
|
|
||||||
edges_only = ui.splitEdgesOnly_checkbox->isChecked();
|
edges_only = ui.splitEdgesOnly_checkbox->isChecked();
|
||||||
preserve_duplicates = ui.preserveDuplicates_checkbox->isChecked();
|
preserve_duplicates = ui.preserveDuplicates_checkbox->isChecked();
|
||||||
|
edge_sizing_type = ui.edgeSizing_type_combo_box->currentIndex();
|
||||||
target_length = ui.edgeLength_dspinbox->value();
|
target_length = ui.edgeLength_dspinbox->value();
|
||||||
|
error_tol = ui.errorTol_edit->value();
|
||||||
|
min_length = ui.minEdgeLength_edit->value();
|
||||||
|
max_length = ui.maxEdgeLength_edit->value();
|
||||||
nb_iter = ui.nbIterations_spinbox->value();
|
nb_iter = ui.nbIterations_spinbox->value();
|
||||||
protect = ui.protect_checkbox->isChecked();
|
protect = ui.protect_checkbox->isChecked();
|
||||||
smooth_features = ui.smooth1D_checkbox->isChecked();
|
smooth_features = ui.smooth1D_checkbox->isChecked();
|
||||||
|
|
@ -785,8 +893,8 @@ public Q_SLOTS:
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
Remesh_polyhedron_item remesher(edges_only,
|
Remesh_polyhedron_item remesher(edges_only, edge_sizing_type,
|
||||||
target_length, nb_iter, protect, smooth_features);
|
target_length, error_tol, min_length, max_length, nb_iter, protect, smooth_features);
|
||||||
for(Scene_facegraph_item* poly_item : selection)
|
for(Scene_facegraph_item* poly_item : selection)
|
||||||
{
|
{
|
||||||
QElapsedTimer time;
|
QElapsedTimer time;
|
||||||
|
|
@ -823,6 +931,7 @@ private:
|
||||||
typedef boost::graph_traits<FaceGraph>::halfedge_descriptor halfedge_descriptor;
|
typedef boost::graph_traits<FaceGraph>::halfedge_descriptor halfedge_descriptor;
|
||||||
typedef boost::graph_traits<FaceGraph>::face_descriptor face_descriptor;
|
typedef boost::graph_traits<FaceGraph>::face_descriptor face_descriptor;
|
||||||
|
|
||||||
|
int edge_sizing_type_;
|
||||||
bool edges_only_;
|
bool edges_only_;
|
||||||
double target_length_;
|
double target_length_;
|
||||||
double error_tol_;
|
double error_tol_;
|
||||||
|
|
@ -859,6 +968,8 @@ private:
|
||||||
std::cout << "Isotropic remeshing of "
|
std::cout << "Isotropic remeshing of "
|
||||||
<< poly_item->name().toStdString() << " started..." << std::endl;
|
<< poly_item->name().toStdString() << " started..." << std::endl;
|
||||||
Scene_polyhedron_selection_item::Is_constrained_map<Edge_set> ecm(&edges_to_protect);
|
Scene_polyhedron_selection_item::Is_constrained_map<Edge_set> ecm(&edges_to_protect);
|
||||||
|
if (edge_sizing_type_ == 0)
|
||||||
|
{
|
||||||
CGAL::Polygon_mesh_processing::isotropic_remeshing(
|
CGAL::Polygon_mesh_processing::isotropic_remeshing(
|
||||||
faces(*poly_item->polyhedron())
|
faces(*poly_item->polyhedron())
|
||||||
, target_length_
|
, target_length_
|
||||||
|
|
@ -868,6 +979,23 @@ private:
|
||||||
.edge_is_constrained_map(ecm)
|
.edge_is_constrained_map(ecm)
|
||||||
.face_patch_map(get(CGAL::face_patch_id_t<int>(), *poly_item->polyhedron()))
|
.face_patch_map(get(CGAL::face_patch_id_t<int>(), *poly_item->polyhedron()))
|
||||||
.relax_constraints(smooth_features_));
|
.relax_constraints(smooth_features_));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::pair<double, double> edge_min_max{min_length_, max_length_};
|
||||||
|
PMP::Adaptive_sizing_field adaptive_sizing_field(error_tol_
|
||||||
|
, edge_min_max
|
||||||
|
, *poly_item->polyhedron());
|
||||||
|
CGAL::Polygon_mesh_processing::isotropic_remeshing(
|
||||||
|
faces(*poly_item->polyhedron())
|
||||||
|
, target_length_
|
||||||
|
, *poly_item->polyhedron()
|
||||||
|
, CGAL::parameters::number_of_iterations(nb_iter_)
|
||||||
|
.protect_constraints(protect_)
|
||||||
|
.edge_is_constrained_map(ecm)
|
||||||
|
.face_patch_map(get(CGAL::face_patch_id_t<int>(), *poly_item->polyhedron()))
|
||||||
|
.relax_constraints(smooth_features_));
|
||||||
|
}
|
||||||
std::cout << "Isotropic remeshing of "
|
std::cout << "Isotropic remeshing of "
|
||||||
<< poly_item->name().toStdString() << " done." << std::endl;
|
<< poly_item->name().toStdString() << " done." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
@ -876,12 +1004,20 @@ private:
|
||||||
public:
|
public:
|
||||||
Remesh_polyhedron_item(
|
Remesh_polyhedron_item(
|
||||||
const bool edges_only,
|
const bool edges_only,
|
||||||
|
const int edge_sizing_type,
|
||||||
const double target_length,
|
const double target_length,
|
||||||
|
const double error_tol,
|
||||||
|
const double min_length,
|
||||||
|
const double max_length,
|
||||||
const unsigned int nb_iter,
|
const unsigned int nb_iter,
|
||||||
const bool protect,
|
const bool protect,
|
||||||
const bool smooth_features)
|
const bool smooth_features)
|
||||||
: edges_only_(edges_only)
|
: edges_only_(edges_only)
|
||||||
|
, edge_sizing_type_(edge_sizing_type)
|
||||||
, target_length_(target_length)
|
, target_length_(target_length)
|
||||||
|
, error_tol_(error_tol)
|
||||||
|
, min_length_(min_length)
|
||||||
|
, max_length_(max_length)
|
||||||
, nb_iter_(nb_iter)
|
, nb_iter_(nb_iter)
|
||||||
, protect_(protect)
|
, protect_(protect)
|
||||||
, smooth_features_(smooth_features)
|
, smooth_features_(smooth_features)
|
||||||
|
|
@ -889,7 +1025,11 @@ private:
|
||||||
|
|
||||||
Remesh_polyhedron_item(const Remesh_polyhedron_item& remesh)
|
Remesh_polyhedron_item(const Remesh_polyhedron_item& remesh)
|
||||||
: edges_only_(remesh.edges_only_)
|
: edges_only_(remesh.edges_only_)
|
||||||
|
, edge_sizing_type_(remesh.edge_sizing_type_)
|
||||||
, target_length_(remesh.target_length_)
|
, target_length_(remesh.target_length_)
|
||||||
|
, error_tol_(remesh.error_tol_)
|
||||||
|
, min_length_(remesh.min_length_)
|
||||||
|
, max_length_(remesh.max_length_)
|
||||||
, nb_iter_(remesh.nb_iter_)
|
, nb_iter_(remesh.nb_iter_)
|
||||||
, protect_(remesh.protect_)
|
, protect_(remesh.protect_)
|
||||||
, smooth_features_(remesh.smooth_features_)
|
, smooth_features_(remesh.smooth_features_)
|
||||||
|
|
@ -916,11 +1056,17 @@ private:
|
||||||
const std::vector<Scene_facegraph_item*>& selection,
|
const std::vector<Scene_facegraph_item*>& selection,
|
||||||
std::map<FaceGraph*,Edge_set >& edges_to_protect,
|
std::map<FaceGraph*,Edge_set >& edges_to_protect,
|
||||||
const bool edges_only,
|
const bool edges_only,
|
||||||
|
const int edge_sizing_type,
|
||||||
const double target_length,
|
const double target_length,
|
||||||
|
const double error_tol,
|
||||||
|
const double min_length,
|
||||||
|
const double max_length,
|
||||||
const unsigned int nb_iter,
|
const unsigned int nb_iter,
|
||||||
const bool protect,
|
const bool protect,
|
||||||
const bool smooth_features)
|
const bool smooth_features)
|
||||||
: RemeshFunctor(edges_only, target_length, nb_iter, protect, smooth_features)
|
: RemeshFunctor(edges_only, edge_sizing_type, target_length
|
||||||
|
, error_tol, min_length, max_length
|
||||||
|
, nb_iter, protect, smooth_features)
|
||||||
, selection_(selection), edges_to_protect_(edges_to_protect)
|
, selection_(selection), edges_to_protect_(edges_to_protect)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
@ -973,6 +1119,9 @@ public Q_SLOTS:
|
||||||
ui.smooth1D_label->setEnabled(false);
|
ui.smooth1D_label->setEnabled(false);
|
||||||
ui.smooth1D_checkbox->setEnabled(false);
|
ui.smooth1D_checkbox->setEnabled(false);
|
||||||
ui.smooth1D_checkbox->setChecked(false);
|
ui.smooth1D_checkbox->setChecked(false);
|
||||||
|
|
||||||
|
ui.edgeSizing_type_combo_box->setCurrentIndex(0);
|
||||||
|
ui.edgeSizing_type_combo_box->setEnabled(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -986,6 +1135,8 @@ public Q_SLOTS:
|
||||||
|
|
||||||
ui.smooth1D_label->setEnabled(true);
|
ui.smooth1D_label->setEnabled(true);
|
||||||
ui.smooth1D_checkbox->setEnabled(true);
|
ui.smooth1D_checkbox->setEnabled(true);
|
||||||
|
|
||||||
|
ui.edgeSizing_type_combo_box->setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue