add observer pattern to all decimaters

closes #2366

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@1197 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
Matthias Möller
2015-01-15 10:19:39 +00:00
parent 094a7f540f
commit b9fd3edef9
8 changed files with 266 additions and 27 deletions

View File

@@ -106,4 +106,58 @@ TEST_F(OpenMeshMultipleChoiceDecimater, DecimateMeshToFaceFaceLimit) {
EXPECT_EQ(14994u, mesh_.n_edges()) << "The number of edges after decimation is not correct!";
EXPECT_EQ(9996u, mesh_.n_faces()) << "The number of faces after decimation is not correct!";
}
class UnittestObserver : public OpenMesh::Decimater::Observer
{
size_t notifies_;
size_t all_steps_;
public:
UnittestObserver(size_t _steps) :Observer(_steps), notifies_(0), all_steps_(0) {}
void notify(size_t _step)
{
++notifies_;
all_steps_ = _step;
}
bool abort() const
{
return all_steps_ >= 2526u;
}
size_t countedNotifies()
{
return notifies_;
}
};
TEST_F(OpenMeshMultipleChoiceDecimater, DecimateMeshStoppedByObserver) {
bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off");
ASSERT_TRUE(ok);
typedef OpenMesh::Decimater::McDecimaterT< Mesh > Decimater;
typedef OpenMesh::Decimater::ModQuadricT< Mesh >::Handle HModQuadric;
Decimater decimaterDBG(mesh_);
HModQuadric hModQuadricDBG;
decimaterDBG.add(hModQuadricDBG);
decimaterDBG.module(hModQuadricDBG).unset_max_err();
decimaterDBG.initialize();
UnittestObserver obs(2);
decimaterDBG.set_observer(&obs);
size_t removedVertices = 0;
removedVertices = decimaterDBG.decimate_to_faces(0, 0);
decimaterDBG.mesh().garbage_collection();
EXPECT_TRUE(obs.abort()) << "Observer did not abort the decimater!";
EXPECT_EQ(obs.countedNotifies(), 2526u / 2u) << "Observer did not get the right amount of notifications!";
EXPECT_EQ(2526u, removedVertices) << "The number of remove vertices is not correct!";
EXPECT_EQ(5000u, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!";
EXPECT_EQ(14994u, mesh_.n_edges()) << "The number of edges after decimation is not correct!";
EXPECT_EQ(9996u, mesh_.n_faces()) << "The number of faces after decimation is not correct!";
}
}