diff --git a/src/main.cpp b/src/main.cpp index 5632411..3af7065 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,6 +25,8 @@ static MeshProcessor *create_mesh_processor(const QString &path, mesh_processor, &MeshProcessor::setImplicitHoleFillingScale); QObject::connect(&main_window, &MainWindow::fillHolesImplicitDiscrChanged, mesh_processor, &MeshProcessor::setImplicitHoleFillingDiscr); + QObject::connect(&main_window, &MainWindow::filterNoiseClicked, + mesh_processor, &MeshProcessor::removeNoise); return mesh_processor; } diff --git a/src/main_window.cpp b/src/main_window.cpp index ac53835..8102739 100644 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -9,6 +9,7 @@ #include #include #include +#include MainWindow::MainWindow(QWidget *parent) @@ -113,4 +114,19 @@ MainWindow::MainWindow(QWidget *parent) this, &MainWindow::patchViewToggled); curvature_layout->addWidget(patch_mode); toolbar.addWidget(curvature_box); + + + // Noise cleaning + QGroupBox *noise_box = new QGroupBox("Élagage"); + QLayout *noise_layout = new QVBoxLayout(); + noise_box->setLayout(noise_layout); + QSlider *noise_slider = new QSlider(Qt::Horizontal); + QPushButton *noise_button = new QPushButton("Élaguer"); + connect(noise_button, &QPushButton::clicked, + [=]() { + emit filterNoiseClicked(noise_slider->value()); + }); + noise_layout->addWidget(noise_slider); + noise_layout->addWidget(noise_button); + toolbar.addWidget(noise_box); } diff --git a/src/main_window.h b/src/main_window.h index c95d61e..7058bbc 100644 --- a/src/main_window.h +++ b/src/main_window.h @@ -32,6 +32,7 @@ signals: void smoothUniformClicked(); void smoothCotangentClicked(double factor); void patchViewToggled(bool checked); + void filterNoiseClicked(int value); public: MeshViewer mesh_viewer; diff --git a/src/mesh_processor.cpp b/src/mesh_processor.cpp index ba27eb7..4cf75fb 100644 --- a/src/mesh_processor.cpp +++ b/src/mesh_processor.cpp @@ -4,6 +4,7 @@ #include "hole_filling.h" #include "smoothing.h" #include "curvature.h" +#include "noise_removal.h" #include #include @@ -131,3 +132,12 @@ void MeshProcessor::click(QVector3D position) { mesh_viewer.addMesh(patch); mesh_viewer.updateForReal(); } + + +void MeshProcessor::removeNoise(int value) { + std::cout << value << std::endl; + ::remove_noise(mesh, value); + mesh_viewer.removeMesh(mesh); + mesh_viewer.addMesh(mesh); + mesh_viewer.updateForReal(); +} diff --git a/src/mesh_processor.h b/src/mesh_processor.h index 38cfcb5..95210a6 100644 --- a/src/mesh_processor.h +++ b/src/mesh_processor.h @@ -38,6 +38,7 @@ public slots: void smoothUniform(); void setPatchView(bool on); void click(QVector3D position); + void removeNoise(int value); }; diff --git a/src/mesh_viewer.h b/src/mesh_viewer.h index 47e044e..d00139c 100644 --- a/src/mesh_viewer.h +++ b/src/mesh_viewer.h @@ -15,7 +15,7 @@ #define WIREFRAME_COLOR 0, 0, 0 -#define FOV 70 +#define FOV 40 using namespace OpenMesh; diff --git a/src/my_mesh.h b/src/my_mesh.h index f0f2114..931e353 100644 --- a/src/my_mesh.h +++ b/src/my_mesh.h @@ -14,9 +14,10 @@ struct MyTraits : public OpenMesh::DefaultTraits { using Point = Eigen::Vector3; using Normal = Eigen::Vector3; using Color = Eigen::Vector3; - VertexAttributes(OpenMesh::Attributes::Normal | OpenMesh::Attributes::Color); + VertexAttributes(OpenMesh::Attributes::Normal | OpenMesh::Attributes::Color | OpenMesh::Attributes::Status); + EdgeAttributes(OpenMesh::Attributes::Status); HalfedgeAttributes(OpenMesh::Attributes::PrevHalfedge); - FaceAttributes(OpenMesh::Attributes::Normal); + FaceAttributes(OpenMesh::Attributes::Normal | OpenMesh::Attributes::Status); // EdgeAttributes(OpenMesh::Attributes::Color); }; diff --git a/src/noise_removal.cpp b/src/noise_removal.cpp index cb6f60b..0293944 100644 --- a/src/noise_removal.cpp +++ b/src/noise_removal.cpp @@ -2,7 +2,14 @@ #include "util.h" -void remove_noise(MyMesh &mesh) { - auto connected_components = find_connected_components(mesh); - +void remove_noise(MyMesh &mesh, unsigned threshold) { + auto components = find_connected_components(mesh); + for (auto component : components) { + if (component.size() < threshold) { + for (VertexHandle vh : component) { + mesh.delete_vertex(vh); + } + } + } + mesh.garbage_collection(); } diff --git a/src/noise_removal.h b/src/noise_removal.h index 120685d..c69971a 100644 --- a/src/noise_removal.h +++ b/src/noise_removal.h @@ -4,7 +4,7 @@ #include "my_mesh.h" -void remove_noise(MyMesh &mesh); +void remove_noise(MyMesh &mesh, unsigned threshold=20); #endif \ No newline at end of file