Commit c79efc9e authored by Jan Möbius's avatar Jan Möbius

refs #65

- Added Unittests for loop subdivision
- Added unittest to perform subdivision after a vertex has been deleted
parent 18b08611
Pipeline #9616 failed with stage
in 16 minutes and 34 seconds
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <Unittests/unittests_common.hh> #include <Unittests/unittests_common.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/CatmullClarkT.hh> #include <OpenMesh/Tools/Subdivider/Uniform/CatmullClarkT.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/LoopT.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/Sqrt3T.hh> #include <OpenMesh/Tools/Subdivider/Uniform/Sqrt3T.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/MidpointT.hh> #include <OpenMesh/Tools/Subdivider/Uniform/MidpointT.hh>
...@@ -147,6 +148,226 @@ TEST_F(OpenMeshSubdividerUniform_Triangle, Subdivider_Sqrt3) { ...@@ -147,6 +148,226 @@ TEST_F(OpenMeshSubdividerUniform_Triangle, Subdivider_Sqrt3) {
EXPECT_EQ(216u, mesh_.n_faces() ) << "Wrong number of faces after subdivision with sqrt3"; EXPECT_EQ(216u, mesh_.n_faces() ) << "Wrong number of faces after subdivision with sqrt3";
} }
TEST_F(OpenMeshSubdividerUniform_Triangle, Subdivider_Loop) {
mesh_.clear();
// Add some vertices
Mesh::VertexHandle vhandle[9];
vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
vhandle[2] = mesh_.add_vertex(Mesh::Point(0, 2, 0));
vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
vhandle[4] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
vhandle[5] = mesh_.add_vertex(Mesh::Point(1, 2, 0));
vhandle[6] = mesh_.add_vertex(Mesh::Point(2, 0, 0));
vhandle[7] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
vhandle[8] = mesh_.add_vertex(Mesh::Point(2, 2, 0));
// Add eight faces
std::vector<Mesh::VertexHandle> face_vhandles;
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[3]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
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[1]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[4]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[4]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[7]);
face_vhandles.push_back(vhandle[6]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[7]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[8]);
face_vhandles.push_back(vhandle[7]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[8]);
mesh_.add_face(face_vhandles);
// Test setup:
// 6 === 7 === 8
// | / | / |
// | / | / |
// | / | / |
// 3 === 4 === 5
// | / | \ |
// | / | \ |
// | / | \ |
// 0 === 1 === 2
// Initialize subdivider
OpenMesh::Subdivider::Uniform::LoopT<Mesh> loop;
// Check setup
EXPECT_EQ(9u, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(8u, mesh_.n_faces() ) << "Wrong number of faces";
// Execute 3 subdivision steps
loop.attach(mesh_);
loop( 3 );
loop.detach();
// Check setup
EXPECT_EQ(289u, mesh_.n_vertices() ) << "Wrong number of vertices after subdivision with loop";
EXPECT_EQ(512u, mesh_.n_faces() ) << "Wrong number of faces after subdivision with loop";
}
TEST_F(OpenMeshSubdividerUniform_Triangle, Subdivider_Loop_delete_vertex) {
mesh_.clear();
// Request status flags to use delete and garbage collection
mesh_.request_vertex_status();
mesh_.request_halfedge_status();
mesh_.request_edge_status();
mesh_.request_face_status();
// Add some vertices
Mesh::VertexHandle vhandle[9];
vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
vhandle[2] = mesh_.add_vertex(Mesh::Point(0, 2, 0));
vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
vhandle[4] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
vhandle[5] = mesh_.add_vertex(Mesh::Point(1, 2, 0));
vhandle[6] = mesh_.add_vertex(Mesh::Point(2, 0, 0));
vhandle[7] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
vhandle[8] = mesh_.add_vertex(Mesh::Point(2, 2, 0));
// Add eight faces
std::vector<Mesh::VertexHandle> face_vhandles;
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[3]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
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[1]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[4]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[4]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[7]);
face_vhandles.push_back(vhandle[6]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[7]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[8]);
face_vhandles.push_back(vhandle[7]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[8]);
mesh_.add_face(face_vhandles);
// Test setup:
// 6 === 7 === 8
// | / | / |
// | / | / |
// | / | / |
// 3 === 4 === 5
// | / | \ |
// | / | \ |
// | / | \ |
// 0 === 1 === 2
// Delete one vertex
mesh_.delete_vertex(vhandle[1]);
mesh_.garbage_collection();
// Initialize subdivider
OpenMesh::Subdivider::Uniform::LoopT<Mesh> loop;
// Check setup
EXPECT_EQ(9u, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(8u, mesh_.n_faces() ) << "Wrong number of faces";
// Execute 3 subdivision steps
loop.attach(mesh_);
loop( 3 );
loop.detach();
// Check setup
EXPECT_EQ(121u, mesh_.n_vertices() ) << "Wrong number of vertices after subdivision with loop";
EXPECT_EQ(216u, mesh_.n_faces() ) << "Wrong number of faces after subdivision with loop";
}
/* /*
* ==================================================================== * ====================================================================
* Define tests below * Define tests below
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment