Add discrete curvatures to display plugin

This commit is contained in:
Mael Rouxel-Labbé 2024-12-10 21:17:57 +01:00
parent 373ad84461
commit 1189356739
1 changed files with 63 additions and 11 deletions

View File

@ -22,6 +22,7 @@
#include <CGAL/Polygon_mesh_processing/compute_normal.h> #include <CGAL/Polygon_mesh_processing/compute_normal.h>
#include <CGAL/Polygon_mesh_processing/measure.h> #include <CGAL/Polygon_mesh_processing/measure.h>
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h> #include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
#include <CGAL/Polygon_mesh_processing/internal/curvature.h>
#include <CGAL/Polygon_mesh_processing/interpolated_corrected_curvatures.h> #include <CGAL/Polygon_mesh_processing/interpolated_corrected_curvatures.h>
#include <QAbstractItemView> #include <QAbstractItemView>
@ -350,11 +351,11 @@ private:
template<typename ValueType> template<typename ValueType>
void displayMapLegend(const std::vector<ValueType>& values) void displayMapLegend(const std::vector<ValueType>& values)
{ {
const std::size_t size = (std::min)(color_map.size(), std::size_t(1024)); const std::size_t size = (std::min)(color_map.size(), std::size_t(4096));
const int text_height = 20; const int text_height = 20;
const int height = text_height * static_cast<int>(size) + text_height; const int height = text_height * static_cast<int>(size) + text_height;
const int width = 140; const int width = 200;
const int cell_width = width / 3; const int cell_width = width / 3;
const int top_margin = 15; const int top_margin = 15;
const int left_margin = 5; const int left_margin = 5;
@ -381,13 +382,13 @@ private:
tick_height, tick_height,
color); color);
QRect text_rect(left_margin + cell_width + 10, drawing_height - top_margin - j, 50, text_height); QRect text_rect(left_margin + cell_width + 10, drawing_height - top_margin - j, 100, text_height);
painter.drawText(text_rect, Qt::AlignCenter, QObject::tr("%1").arg(values[i], 0, 'f', 3, QLatin1Char(' '))); painter.drawText(text_rect, Qt::AlignCenter, QObject::tr("%1").arg(values[i], 0, 'f', 6, QLatin1Char(' ')));
} }
if(color_map.size() > size) if(color_map.size() > size)
{ {
QRect text_rect(left_margin + cell_width + 10, 0, 50, text_height); QRect text_rect(left_margin + cell_width + 10, 0, 100, text_height);
painter.drawText(text_rect, Qt::AlignCenter, QObject::tr("[...]")); painter.drawText(text_rect, Qt::AlignCenter, QObject::tr("[...]"));
} }
@ -463,6 +464,8 @@ private:
"Largest Angle Per Face", "Largest Angle Per Face",
"Scaled Jacobian", "Scaled Jacobian",
"Face Area", "Face Area",
"Discrete Mean Curvature",
"Discrete Gaussian Curvature",
"Interpolated Corrected Mean Curvature", "Interpolated Corrected Mean Curvature",
"Interpolated Corrected Gaussian Curvature"}); "Interpolated Corrected Gaussian Curvature"});
property_simplex_types = { Property_simplex_type::FACE, property_simplex_types = { Property_simplex_type::FACE,
@ -470,6 +473,8 @@ private:
Property_simplex_type::FACE, Property_simplex_type::FACE,
Property_simplex_type::FACE, Property_simplex_type::FACE,
Property_simplex_type::VERTEX, Property_simplex_type::VERTEX,
Property_simplex_type::VERTEX,
Property_simplex_type::VERTEX,
Property_simplex_type::VERTEX }; Property_simplex_type::VERTEX };
detectSMScalarProperties(*(sm_item->face_graph())); detectSMScalarProperties(*(sm_item->face_graph()));
} }
@ -516,12 +521,12 @@ private Q_SLOTS:
// Curvature property-specific slider // Curvature property-specific slider
const std::string& property_name = dock_widget->propertyBox->currentText().toStdString(); const std::string& property_name = dock_widget->propertyBox->currentText().toStdString();
const bool is_curvature_property = (property_name == "Interpolated Corrected Mean Curvature" || const bool is_interpolated_curvature_property = (property_name == "Interpolated Corrected Mean Curvature" ||
property_name == "Interpolated Corrected Gaussian Curvature"); property_name == "Interpolated Corrected Gaussian Curvature");
dock_widget->expandingRadiusLabel->setVisible(is_curvature_property); dock_widget->expandingRadiusLabel->setVisible(is_interpolated_curvature_property);
dock_widget->expandingRadiusSlider->setVisible(is_curvature_property); dock_widget->expandingRadiusSlider->setVisible(is_interpolated_curvature_property);
dock_widget->expandingRadiusLabel->setEnabled(is_curvature_property); dock_widget->expandingRadiusLabel->setEnabled(is_interpolated_curvature_property);
dock_widget->expandingRadiusSlider->setEnabled(is_curvature_property); dock_widget->expandingRadiusSlider->setEnabled(is_interpolated_curvature_property);
} }
else // no or broken property else // no or broken property
{ {
@ -570,6 +575,16 @@ private:
{ {
displayArea(sm_item); displayArea(sm_item);
} }
else if(property_name == "Discrete Mean Curvature")
{
displayDiscreteCurvatureMeasure(sm_item, MEAN_CURVATURE);
sm_item->setRenderingMode(Gouraud);
}
else if(property_name == "Discrete Gaussian Curvature")
{
displayDiscreteCurvatureMeasure(sm_item, GAUSSIAN_CURVATURE);
sm_item->setRenderingMode(Gouraud);
}
else if(property_name == "Interpolated Corrected Mean Curvature") else if(property_name == "Interpolated Corrected Mean Curvature")
{ {
displayInterpolatedCurvatureMeasure(sm_item, MEAN_CURVATURE); displayInterpolatedCurvatureMeasure(sm_item, MEAN_CURVATURE);
@ -682,6 +697,8 @@ private:
removeDisplayPluginProperty(item, "f:display_plugin_largest_angle"); removeDisplayPluginProperty(item, "f:display_plugin_largest_angle");
removeDisplayPluginProperty(item, "f:display_plugin_scaled_jacobian"); removeDisplayPluginProperty(item, "f:display_plugin_scaled_jacobian");
removeDisplayPluginProperty(item, "f:display_plugin_area"); removeDisplayPluginProperty(item, "f:display_plugin_area");
removeDisplayPluginProperty(item, "v:display_plugin_discrete_mean_curvature");
removeDisplayPluginProperty(item, "v:display_plugin_discrete_Gaussian_curvature");
removeDisplayPluginProperty(item, "v:display_plugin_interpolated_corrected_mean_curvature"); removeDisplayPluginProperty(item, "v:display_plugin_interpolated_corrected_mean_curvature");
removeDisplayPluginProperty(item, "v:display_plugin_interpolated_corrected_Gaussian_curvature"); removeDisplayPluginProperty(item, "v:display_plugin_interpolated_corrected_Gaussian_curvature");
} }
@ -864,6 +881,35 @@ private:
displaySMProperty<face_descriptor>("f:display_plugin_area", *sm); displaySMProperty<face_descriptor>("f:display_plugin_area", *sm);
} }
private:
void displayDiscreteCurvatureMeasure(Scene_surface_mesh_item* sm_item,
CurvatureType mu_index)
{
SMesh* sm = sm_item->face_graph();
if(sm == nullptr)
return;
if(mu_index != MEAN_CURVATURE && mu_index != GAUSSIAN_CURVATURE)
return;
std::string vdc_name = (mu_index == MEAN_CURVATURE) ? "v:display_plugin_discrete_mean_curvature"
: "v:display_plugin_discrete_Gaussian_curvature";
bool not_initialized;
SMesh::Property_map<vertex_descriptor, double> vdc;
std::tie(vdc, not_initialized) = sm->add_property_map<vertex_descriptor, double>(vdc_name, 0);
if(not_initialized)
{
if(mu_index == MEAN_CURVATURE)
PMP::discrete_mean_curvatures(*sm, vdc);
else
PMP::discrete_Gaussian_curvatures(*sm, vdc);
}
displaySMProperty<vertex_descriptor>(vdc_name, *sm);
}
private Q_SLOTS: private Q_SLOTS:
void setExpandingRadius() void setExpandingRadius()
{ {
@ -1131,6 +1177,10 @@ private:
zoomToSimplexWithPropertyExtremum(faces(mesh), mesh, "f:display_plugin_scaled_jacobian", extremum); zoomToSimplexWithPropertyExtremum(faces(mesh), mesh, "f:display_plugin_scaled_jacobian", extremum);
else if(property_name == "Face Area") else if(property_name == "Face Area")
zoomToSimplexWithPropertyExtremum(faces(mesh), mesh, "f:display_plugin_area", extremum); zoomToSimplexWithPropertyExtremum(faces(mesh), mesh, "f:display_plugin_area", extremum);
else if(property_name == "Discrete Mean Curvature")
zoomToSimplexWithPropertyExtremum(vertices(mesh), mesh, "v:display_plugin_discrete_mean_curvature", extremum);
else if(property_name == "Discrete Gaussian Curvature")
zoomToSimplexWithPropertyExtremum(vertices(mesh), mesh, "v:display_plugin_discrete_Gaussian_curvature", extremum);
else if(property_name == "Interpolated Corrected Mean Curvature") else if(property_name == "Interpolated Corrected Mean Curvature")
zoomToSimplexWithPropertyExtremum(vertices(mesh), mesh, "v:display_plugin_interpolated_corrected_mean_curvature", extremum); zoomToSimplexWithPropertyExtremum(vertices(mesh), mesh, "v:display_plugin_interpolated_corrected_mean_curvature", extremum);
else if(property_name == "Interpolated Corrected Gaussian Curvature") else if(property_name == "Interpolated Corrected Gaussian Curvature")
@ -1470,6 +1520,8 @@ isSMPropertyScalar(const std::string& name,
name == "f:display_plugin_largest_angle" || name == "f:display_plugin_largest_angle" ||
name == "f:display_plugin_scaled_jacobian" || name == "f:display_plugin_scaled_jacobian" ||
name == "f:display_plugin_area" || name == "f:display_plugin_area" ||
name == "v:display_plugin_discrete_mean_curvature" ||
name == "v:display_plugin_discrete_Gaussian_curvature" ||
name == "v:display_plugin_interpolated_corrected_mean_curvature" || name == "v:display_plugin_interpolated_corrected_mean_curvature" ||
name == "v:display_plugin_interpolated_corrected_Gaussian_curvature") name == "v:display_plugin_interpolated_corrected_Gaussian_curvature")
return false; return false;