add noise filtering

This commit is contained in:
papush! 2022-01-05 16:44:35 +01:00
parent 3035ffacb8
commit 940ba1be7f
9 changed files with 45 additions and 7 deletions

View File

@ -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;
}

View File

@ -9,6 +9,7 @@
#include <QPushButton>
#include <QSlider>
#include <QLabel>
#include <qnamespace.h>
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);
}

View File

@ -32,6 +32,7 @@ signals:
void smoothUniformClicked();
void smoothCotangentClicked(double factor);
void patchViewToggled(bool checked);
void filterNoiseClicked(int value);
public:
MeshViewer mesh_viewer;

View File

@ -4,6 +4,7 @@
#include "hole_filling.h"
#include "smoothing.h"
#include "curvature.h"
#include "noise_removal.h"
#include <QGenericMatrix>
#include <unordered_set>
@ -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();
}

View File

@ -38,6 +38,7 @@ public slots:
void smoothUniform();
void setPatchView(bool on);
void click(QVector3D position);
void removeNoise(int value);
};

View File

@ -15,7 +15,7 @@
#define WIREFRAME_COLOR 0, 0, 0
#define FOV 70
#define FOV 40
using namespace OpenMesh;

View File

@ -14,9 +14,10 @@ struct MyTraits : public OpenMesh::DefaultTraits {
using Point = Eigen::Vector3<qreal>;
using Normal = Eigen::Vector3<qreal>;
using Color = Eigen::Vector3<qreal>;
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);
};

View File

@ -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();
}

View File

@ -4,7 +4,7 @@
#include "my_mesh.h"
void remove_noise(MyMesh &mesh);
void remove_noise(MyMesh &mesh, unsigned threshold=20);
#endif