2 #include <gtest/gtest.h> 3 #include <Unittests/unittests_common.hh> 14 virtual void SetUp() {
20 virtual void TearDown() {
37 TEST_F(OpenMeshDecimater, DecimateMesh) {
46 Decimater decimaterDBG(mesh_);
47 HModQuadric hModQuadricDBG;
48 decimaterDBG.add( hModQuadricDBG );
49 decimaterDBG.initialize();
50 size_t removedVertices = 0;
51 removedVertices = decimaterDBG.decimate_to(5000);
52 decimaterDBG.mesh().garbage_collection();
54 EXPECT_EQ(2526u, removedVertices) <<
"The number of remove vertices is not correct!";
55 EXPECT_EQ(5000u, mesh_.n_vertices()) <<
"The number of vertices after decimation is not correct!";
56 EXPECT_EQ(14994u, mesh_.n_edges()) <<
"The number of edges after decimation is not correct!";
57 EXPECT_EQ(9996u, mesh_.n_faces()) <<
"The number of faces after decimation is not correct!";
60 TEST_F(OpenMeshDecimater, DecimateMeshToFaceVerticesLimit) {
69 Decimater decimaterDBG(mesh_);
70 HModQuadric hModQuadricDBG;
71 decimaterDBG.add( hModQuadricDBG );
72 decimaterDBG.initialize();
73 size_t removedVertices = 0;
74 removedVertices = decimaterDBG.decimate_to_faces(5000, 8000);
75 decimaterDBG.mesh().garbage_collection();
77 EXPECT_EQ(2526u, removedVertices) <<
"The number of remove vertices is not correct!";
78 EXPECT_EQ(5000u, mesh_.n_vertices()) <<
"The number of vertices after decimation is not correct!";
79 EXPECT_EQ(14994u, mesh_.n_edges()) <<
"The number of edges after decimation is not correct!";
80 EXPECT_EQ(9996u, mesh_.n_faces()) <<
"The number of faces after decimation is not correct!";
83 TEST_F(OpenMeshDecimater, DecimateMeshToFaceFaceLimit) {
92 Decimater decimaterDBG(mesh_);
93 HModQuadric hModQuadricDBG;
94 decimaterDBG.add( hModQuadricDBG );
95 decimaterDBG.initialize();
96 size_t removedVertices = 0;
97 removedVertices = decimaterDBG.decimate_to_faces(4500, 9996);
98 decimaterDBG.mesh().garbage_collection();
100 EXPECT_EQ(2526u, removedVertices) <<
"The number of remove vertices is not correct!";
101 EXPECT_EQ(5000u, mesh_.n_vertices()) <<
"The number of vertices after decimation is not correct!";
102 EXPECT_EQ(14994u, mesh_.n_edges()) <<
"The number of edges after decimation is not correct!";
103 EXPECT_EQ(9996u, mesh_.n_faces()) <<
"The number of faces after decimation is not correct!";
106 TEST_F(OpenMeshDecimater, DecimateMeshExampleFromDoc) {
115 Decimater decimaterDBG(mesh_);
116 HModQuadric hModQuadricDBG;
117 decimaterDBG.add( hModQuadricDBG );
119 decimaterDBG.module( hModQuadricDBG ).unset_max_err();
121 decimaterDBG.initialize();
122 size_t removedVertices = 0;
123 removedVertices = decimaterDBG.decimate_to_faces(4500, 9996);
124 decimaterDBG.mesh().garbage_collection();
126 EXPECT_EQ(2526u, removedVertices) <<
"The number of remove vertices is not correct!";
127 EXPECT_EQ(5000u, mesh_.n_vertices()) <<
"The number of vertices after decimation is not correct!";
128 EXPECT_EQ(14994u, mesh_.n_edges()) <<
"The number of edges after decimation is not correct!";
129 EXPECT_EQ(9996u, mesh_.n_faces()) <<
"The number of faces after decimation is not correct!";
137 UnittestObserver(
size_t _steps) :Observer(_steps), notifies_(0), all_steps_(0) {}
139 void notify(
size_t _step)
146 return all_steps_ >= 2526u;
149 size_t countedNotifies()
155 TEST_F(OpenMeshDecimater, DecimateMeshStoppedByObserver) {
164 Decimater decimaterDBG(mesh_);
165 HModQuadric hModQuadricDBG;
166 decimaterDBG.add(hModQuadricDBG);
168 decimaterDBG.module(hModQuadricDBG).unset_max_err();
170 decimaterDBG.initialize();
171 UnittestObserver obs(2);
172 decimaterDBG.set_observer(&obs);
173 size_t removedVertices = 0;
174 removedVertices = decimaterDBG.decimate_to_faces(0, 0);
175 decimaterDBG.mesh().garbage_collection();
177 EXPECT_TRUE(obs.abort()) <<
"Observer did not abort the decimater!";
178 EXPECT_EQ(obs.countedNotifies(), 2526u / 2u) <<
"Observer did not get the right amount of notifications!";
180 EXPECT_EQ(2526u, removedVertices) <<
"The number of remove vertices is not correct!";
181 EXPECT_EQ(5000u, mesh_.n_vertices()) <<
"The number of vertices after decimation is not correct!";
182 EXPECT_EQ(14994u, mesh_.n_edges()) <<
"The number of edges after decimation is not correct!";
183 EXPECT_EQ(9996u, mesh_.n_faces()) <<
"The number of faces after decimation is not correct!";
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Mesh decimation module computing collapse priority based on error quadrics.