From 9f91de0d86195fc2654eed324922288b5ce04056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Tue, 19 Jun 2018 14:39:59 +0200 Subject: [PATCH] Added basic unittest for smarttagger on vertices --- .../Tools/SmartTagger/SmartTaggerT.hh | 6 +- src/Unittests/unittests_smarttagger.cc | 143 ++++++++++++++++++ 2 files changed, 146 insertions(+), 3 deletions(-) create mode 100644 src/Unittests/unittests_smarttagger.cc diff --git a/src/OpenMesh/Tools/SmartTagger/SmartTaggerT.hh b/src/OpenMesh/Tools/SmartTagger/SmartTaggerT.hh index e6cf86a0..accabc8d 100644 --- a/src/OpenMesh/Tools/SmartTagger/SmartTaggerT.hh +++ b/src/OpenMesh/Tools/SmartTagger/SmartTaggerT.hh @@ -130,7 +130,7 @@ public: * @param _eh Edge handle for the tag * @param _tag Tag value */ - inline void set_tag ( const EHandle _eh, unsigned int _tag = 1); + inline void set_tag ( const EHandle _eh, unsigned int _tag = 1); /** \brief get tag value in range [0..tag_range] * @@ -144,7 +144,7 @@ public: * @param _eh Edge handle for the tag * @return Current tag value at that edge */ - inline bool is_tagged( const EHandle _eh) const; + inline bool is_tagged( const EHandle _eh) const; /** \brief set new tag range and untag_all * @@ -152,7 +152,7 @@ public: * * @param _tag_range New tag range of the tagger */ - inline void set_tag_range( const unsigned int _tag_range); + inline void set_tag_range( const unsigned int _tag_range); protected: diff --git a/src/Unittests/unittests_smarttagger.cc b/src/Unittests/unittests_smarttagger.cc new file mode 100644 index 00000000..fcbc9287 --- /dev/null +++ b/src/Unittests/unittests_smarttagger.cc @@ -0,0 +1,143 @@ +#include +#include +#include +#include + +namespace { + +class OpenMeshSmartTagger : public OpenMeshBase { + + protected: + + // This function is called before each test is run + virtual void SetUp() { + + // Do some initial stuff with the member data here... + } + + // This function is called after all tests are through + virtual void TearDown() { + + // Do some final stuff with the member data here... + } + + // Member already defined in OpenMeshBase + //Mesh mesh_; +}; + +/* + * ==================================================================== + * Define tests below + * ==================================================================== + */ + +/* Checks vertices, if they are boundary vertices + */ +TEST_F(OpenMeshSmartTagger, SmartTaggerVertices) { + + mesh_.clear(); + + // Add some vertices + Mesh::VertexHandle vhandle[7]; + + vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0)); + vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0)); + vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0)); + vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0)); + vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0)); + vhandle[5] = mesh_.add_vertex(Mesh::Point(3, 0, 0)); + + + // Add two faces + std::vector face_vhandles; + + face_vhandles.push_back(vhandle[0]); + face_vhandles.push_back(vhandle[1]); + face_vhandles.push_back(vhandle[2]); + mesh_.add_face(face_vhandles); + + face_vhandles.clear(); + + face_vhandles.push_back(vhandle[1]); + face_vhandles.push_back(vhandle[3]); + face_vhandles.push_back(vhandle[4]); + mesh_.add_face(face_vhandles); + + face_vhandles.clear(); + + face_vhandles.push_back(vhandle[0]); + face_vhandles.push_back(vhandle[3]); + face_vhandles.push_back(vhandle[1]); + mesh_.add_face(face_vhandles); + + face_vhandles.clear(); + + face_vhandles.push_back(vhandle[2]); + face_vhandles.push_back(vhandle[1]); + face_vhandles.push_back(vhandle[4]); + mesh_.add_face(face_vhandles); + + face_vhandles.clear(); + + face_vhandles.push_back(vhandle[5]); + face_vhandles.push_back(vhandle[2]); + face_vhandles.push_back(vhandle[4]); + mesh_.add_face(face_vhandles); + + /* Test setup: + 0 ==== 2 + |\ /|\ + | \ / | \ + | 1 | 5 + | / \ | / + |/ \|/ + 3 ==== 4 + + */ + + + OpenMesh::SmartTaggerVT< Mesh > tagger(mesh_); + + + EXPECT_FALSE( tagger.is_tagged(vhandle[0] ) ) << "Vertex should be untagged after init!"; + EXPECT_FALSE( tagger.is_tagged(vhandle[1] ) ) << "Vertex should be untagged after init!"; + EXPECT_FALSE( tagger.is_tagged(vhandle[2] ) ) << "Vertex should be untagged after init!"; + EXPECT_FALSE( tagger.is_tagged(vhandle[3] ) ) << "Vertex should be untagged after init!"; + EXPECT_FALSE( tagger.is_tagged(vhandle[4] ) ) << "Vertex should be untagged after init!"; + EXPECT_FALSE( tagger.is_tagged(vhandle[5] ) ) << "Vertex should be untagged after init!"; + + // Reset tagged flag on all vertices + tagger.untag_all(); + + EXPECT_FALSE( tagger.is_tagged(vhandle[0] ) ) << "Vertex should be untagged after first untag_all!"; + EXPECT_FALSE( tagger.is_tagged(vhandle[1] ) ) << "Vertex should be untagged after first untag_all!"; + EXPECT_FALSE( tagger.is_tagged(vhandle[2] ) ) << "Vertex should be untagged after first untag_all!"; + EXPECT_FALSE( tagger.is_tagged(vhandle[3] ) ) << "Vertex should be untagged after first untag_all!"; + EXPECT_FALSE( tagger.is_tagged(vhandle[4] ) ) << "Vertex should be untagged after first untag_all!"; + EXPECT_FALSE( tagger.is_tagged(vhandle[5] ) ) << "Vertex should be untagged after first untag_all!"; + + + // Set tagged: + tagger.set_tag(vhandle[2]); + tagger.set_tag(vhandle[4]); + + EXPECT_FALSE( tagger.is_tagged(vhandle[0] ) ) << "Vertex should be untagged!"; + EXPECT_FALSE( tagger.is_tagged(vhandle[1] ) ) << "Vertex should be untagged!"; + EXPECT_TRUE( tagger.is_tagged(vhandle[2] ) ) << "Vertex should be tagged!"; + EXPECT_FALSE( tagger.is_tagged(vhandle[3] ) ) << "Vertex should be untagged!"; + EXPECT_TRUE( tagger.is_tagged(vhandle[4] ) ) << "Vertex should be tagged!"; + EXPECT_FALSE( tagger.is_tagged(vhandle[5] ) ) << "Vertex should be untagged!"; + + // Reset tagged flag on all vertices + tagger.untag_all(); + + EXPECT_FALSE( tagger.is_tagged(vhandle[0] ) ) << "Vertex should be untagged after second untag_all!"; + EXPECT_FALSE( tagger.is_tagged(vhandle[1] ) ) << "Vertex should be untagged after second untag_all!"; + EXPECT_FALSE( tagger.is_tagged(vhandle[2] ) ) << "Vertex should be untagged after second untag_all!"; + EXPECT_FALSE( tagger.is_tagged(vhandle[3] ) ) << "Vertex should be untagged after second untag_all!"; + EXPECT_FALSE( tagger.is_tagged(vhandle[4] ) ) << "Vertex should be untagged after second untag_all!"; + EXPECT_FALSE( tagger.is_tagged(vhandle[5] ) ) << "Vertex should be untagged after second untag_all!"; + +} + +}