integrated curvature vis to display property

still need to add the radius setting part
This commit is contained in:
hoskillua 2023-08-27 19:13:42 +03:00
parent 4b450a5948
commit 28efeb2056
1 changed files with 73 additions and 4 deletions

View File

@ -22,11 +22,13 @@
#include <CGAL/Polygon_mesh_processing/compute_normal.h>
#include <CGAL/Polygon_mesh_processing/measure.h>
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
#include <CGAL/Polygon_mesh_processing/interpolated_corrected_curvatures.h>
#include <QAbstractItemView>
#include <QAction>
#include <QApplication>
#include <QColor>
#include <QSlider>
#include <QColorDialog>
#include <QInputDialog>
#include <QMainWindow>
@ -47,6 +49,8 @@
using namespace CGAL::Three;
Viewer_interface* (&getActiveViewer)() = Three::activeViewer;
class DockWidget
@ -99,6 +103,11 @@ private:
MAX_VALUE
};
enum CurvatureType {
MEAN_CURVATURE,
GAUSSIAN_CURVATURE
};
public:
bool applicable(QAction*) const Q_DECL_OVERRIDE
{
@ -238,6 +247,14 @@ private:
dock_widget->maxBox->setRange(0, 360);
dock_widget->maxBox->setValue(0);
}
else if (property_name == "Interpolated Corrected Gaussian Curvature" ||
property_name == "Interpolated Corrected Mean Curvature")
{
dock_widget->minBox->setRange(-1000, 1000);
dock_widget->minBox->setValue(0);
dock_widget->maxBox->setRange(-1000, 1000);
dock_widget->maxBox->setValue(0);
}
else if(property_name == "Scaled Jacobian")
{
dock_widget->minBox->setRange(-1000, 1000);
@ -432,11 +449,15 @@ private:
dock_widget->propertyBox->addItems({"Smallest Angle Per Face",
"Largest Angle Per Face",
"Scaled Jacobian",
"Face Area"});
"Face Area",
"Interpolated Corrected Mean Curvature",
"Interpolated Corrected Gaussian Curvature"});
property_simplex_types = { Property_simplex_type::FACE,
Property_simplex_type::FACE,
Property_simplex_type::FACE,
Property_simplex_type::FACE };
Property_simplex_type::FACE,
Property_simplex_type::VERTEX,
Property_simplex_type::VERTEX };
detectSMScalarProperties(*(sm_item->face_graph()));
}
else if(ps_item)
@ -506,10 +527,15 @@ private:
{
CGAL_assertion(static_cast<std::size_t>(dock_widget->propertyBox->count()) == property_simplex_types.size());
const int property_index = dock_widget->propertyBox->currentIndex();
// leave it flat if it was, otherwise set to flat+edges
if(sm_item->renderingMode() != Flat && sm_item->renderingMode() != FlatPlusEdges)
if(sm_item->renderingMode() != Flat && sm_item->renderingMode() != FlatPlusEdges && property_simplex_types.at(property_index) == Property_simplex_type::FACE)
sm_item->setRenderingMode(FlatPlusEdges);
if(sm_item->renderingMode() != Gouraud && sm_item->renderingMode() != GouraudPlusEdges && property_simplex_types.at(property_index) == Property_simplex_type::VERTEX)
sm_item->setRenderingMode(GouraudPlusEdges);
const std::string& property_name = dock_widget->propertyBox->currentText().toStdString();
if(property_name == "Smallest Angle Per Face")
{
@ -527,6 +553,14 @@ private:
{
displayArea(sm_item);
}
else if(property_name == "Interpolated Corrected Mean Curvature")
{
displayCurvature(sm_item, MEAN_CURVATURE);
}
else if(property_name == "Interpolated Corrected Gaussian Curvature")
{
displayCurvature(sm_item, GAUSSIAN_CURVATURE);
}
else
{
const int property_index = dock_widget->propertyBox->currentIndex();
@ -629,6 +663,8 @@ private:
removeDisplayPluginProperty(item, "f:display_plugin_largest_angle");
removeDisplayPluginProperty(item, "f:display_plugin_scaled_jacobian");
removeDisplayPluginProperty(item, "f:display_plugin_area");
removeDisplayPluginProperty(item, "f:display_plugin_mean_curvature");
removeDisplayPluginProperty(item, "f:display_plugin_gaussian_curvature");
}
void displayExtremumAnglePerFace(Scene_surface_mesh_item* sm_item,
@ -809,6 +845,32 @@ private:
displaySMProperty<face_descriptor>("f:display_plugin_area", *sm);
}
void displayCurvature(Scene_surface_mesh_item* sm_item,
const CurvatureType curvature_type)
{
SMesh* sm = sm_item->face_graph();
if(sm == nullptr)
return;
bool not_initialized;
std::string tied_string = (curvature_type == MEAN_CURVATURE) ?
"v:display_plugin_mean_curvature" : "v:display_plugin_gaussian_curvature";
SMesh::Property_map<vertex_descriptor, double> vcurvature;
std::tie(vcurvature, not_initialized) = sm->add_property_map<vertex_descriptor, double>(tied_string, 0);
if (curvature_type == MEAN_CURVATURE)
{
CGAL::Polygon_mesh_processing::interpolated_corrected_mean_curvature(*sm, vcurvature);
}
else if (curvature_type == GAUSSIAN_CURVATURE)
{
CGAL::Polygon_mesh_processing::interpolated_corrected_Gaussian_curvature(*sm, vcurvature);
}
displaySMProperty<vertex_descriptor>(tied_string, *sm);
}
private:
template<typename Functor>
bool call_on_PS_property(const std::string& name,
@ -964,6 +1026,10 @@ private:
zoomToSimplexWithPropertyExtremum(faces(mesh), mesh, "f:display_plugin_scaled_jacobian", extremum);
else if(property_name == "Face Area")
zoomToSimplexWithPropertyExtremum(faces(mesh), mesh, "f:display_plugin_area", extremum);
else if(property_name == "Interpolated Corrected Mean Curvature")
zoomToSimplexWithPropertyExtremum(vertices(mesh), mesh, "v:display_plugin_mean_curvature", extremum);
else if(property_name == "Interpolated Corrected Gaussian Curvature")
zoomToSimplexWithPropertyExtremum(vertices(mesh), mesh, "v:display_plugin_gaussian_curvature", extremum);
else if(property_simplex_types.at(property_index) == Property_simplex_type::VERTEX)
zoomToSimplexWithPropertyExtremum(vertices(mesh), mesh, property_name, extremum);
else if(property_simplex_types.at(property_index) == Property_simplex_type::FACE)
@ -1298,7 +1364,10 @@ isSMPropertyScalar(const std::string& name,
if(name == "f:display_plugin_smallest_angle" ||
name == "f:display_plugin_largest_angle" ||
name == "f:display_plugin_scaled_jacobian" ||
name == "f:display_plugin_area")
name == "f:display_plugin_area" ||
name == "f:display_plugin_mean_curvature" ||
name == "f:display_plugin_gaussian_curvature")
return false;
// the dispatch function does the filtering we want: if it founds a property