Commit 6b518742 authored by Jan Möbius's avatar Jan Möbius

Merge branch 'midpoint_unittest' into 'master'

Midpoint unittest

See merge request !119
parents b3bd58a3 ca7abc7e
Pipeline #4153 passed with stage
in 40 minutes and 43 seconds
......@@ -13,7 +13,7 @@ namespace Uniform {
/**
* Midpoint subdivision algorithm.
*
* With every step, the set of vertices is replaced with by the midpoints of all
* With every step, the set of vertices is replaced by the midpoints of all
* current edges. Then, two sets of faces are created to set up the new
* connectivity: From all midpoints of edges surrounding an original face, a new
* face is created. Also, for all midpoints of edges surrounding an original
......@@ -47,6 +47,10 @@ protected: // SubdividerT interface
//! @note The _update_points option is ignored
bool subdivide(mesh_t& _m, size_t _n, const bool _update_points = true)
{
_m.request_halfedge_status();
_m.request_edge_status();
_m.request_vertex_status();
_m.request_face_status();
PropertyManager<EPropHandleT<typename mesh_t::VertexHandle>, mesh_t> edge_midpoint(_m, "edge_midpoint");
PropertyManager<VPropHandleT<bool>, mesh_t> is_original_vertex(_m, "is_original_vertex");
......@@ -90,6 +94,7 @@ protected: // SubdividerT interface
_m.delete_vertex(vh);
}
}
_m.garbage_collection();
}
return true;
}
......
......@@ -3,44 +3,37 @@
#include <Unittests/unittests_common.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/CatmullClarkT.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/Sqrt3T.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/MidpointT.hh>
namespace {
class OpenMeshSubdividerUniform_Poly : public OpenMeshBasePoly {
protected:
// This function is called before each test is run
virtual void SetUp() {
// Do some initial stuff with the member data here...
}
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...
}
// 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_;
};
class OpenMeshSubdividerUniform_Triangle : public OpenMeshBase {
protected:
// This function is called before each test is run
virtual void SetUp() {
// Do some initial stuff with the member data here...
}
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...
}
// 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_;
......@@ -52,110 +45,106 @@ class OpenMeshSubdividerUniform_Triangle : public OpenMeshBase {
* ====================================================================
*/
/*
*/
TEST_F(OpenMeshSubdividerUniform_Triangle, Subdivider_Loop) {
mesh_.clear();
// Add some vertices
Mesh::VertexHandle vhandle[9];
TEST_F(OpenMeshSubdividerUniform_Triangle, Subdivider_Sqrt3) {
mesh_.clear();
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 some vertices
Mesh::VertexHandle vhandle[9];
// Add eight faces
std::vector<Mesh::VertexHandle> face_vhandles;
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));
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[3]);
// Add eight faces
std::vector<Mesh::VertexHandle> face_vhandles;
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[3]);
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();
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]);
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();
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]);
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();
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]);
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();
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]);
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();
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]);
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();
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]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[8]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
mesh_.add_face(face_vhandles);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[8]);
// Test setup:
// 6 === 7 === 8
// | / | / |
// | / | / |
// | / | / |
// 3 === 4 === 5
// | / | \ |
// | / | \ |
// | / | \ |
// 0 === 1 === 2
mesh_.add_face(face_vhandles);
// Initialize subdivider
OpenMesh::Subdivider::Uniform::Sqrt3T<Mesh> sqrt3;
// Test setup:
// 6 === 7 === 8
// | / | / |
// | / | / |
// | / | / |
// 3 === 4 === 5
// | / | \ |
// | / | \ |
// | / | \ |
// 0 === 1 === 2
// Check setup
EXPECT_EQ(9u, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(8u, mesh_.n_faces() ) << "Wrong number of faces";
// Initialize subdivider
OpenMesh::Subdivider::Uniform::Sqrt3T<Mesh> sqrt3;
// Execute 3 subdivision steps
sqrt3.attach(mesh_);
sqrt3( 3 );
sqrt3.detach();
// Check setup
EXPECT_EQ(9u, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(8u, mesh_.n_faces() ) << "Wrong number of faces";
// Check setup
EXPECT_EQ(121u, mesh_.n_vertices() ) << "Wrong number of vertices after subdivision with sqrt3";
EXPECT_EQ(216u, mesh_.n_faces() ) << "Wrong number of faces after subdivision with sqrt3";
// Execute 3 subdivision steps
sqrt3.attach(mesh_);
sqrt3( 3 );
sqrt3.detach();
// Check setup
EXPECT_EQ(121u, mesh_.n_vertices() ) << "Wrong number of vertices after subdivision with sqrt3";
EXPECT_EQ(216u, mesh_.n_faces() ) << "Wrong number of faces after subdivision with sqrt3";
}
/*
......@@ -167,81 +156,177 @@ TEST_F(OpenMeshSubdividerUniform_Triangle, Subdivider_Loop) {
/*
*/
TEST_F(OpenMeshSubdividerUniform_Poly, Subdivider_CatmullClark) {
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 four faces
std::vector<Mesh::VertexHandle> face_vhandles;
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[1]);
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[1]);
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[4]);
face_vhandles.push_back(vhandle[5]);
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[3]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[7]);
face_vhandles.push_back(vhandle[6]);
mesh_.add_face(face_vhandles);
// Test setup:
// 6 === 7 === 8
// | | |
// | | |
// | | |
// 3 === 4 === 5
// | | |
// | | |
// | | |
// 0 === 1 === 2
// Initialize subdivider
OpenMesh::Subdivider::Uniform::CatmullClarkT<PolyMesh> catmull;
// Check setup
EXPECT_EQ(9u, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(4u, mesh_.n_faces() ) << "Wrong number of faces";
// Execute 3 subdivision steps
catmull.attach(mesh_);
catmull( 3 );
catmull.detach();
EXPECT_EQ(289u, mesh_.n_vertices() ) << "Wrong number of vertices after subdivision with catmull clark";
EXPECT_EQ(256u, mesh_.n_faces() ) << "Wrong number of faces after subdivision with catmull clark";
}
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 four faces
std::vector<Mesh::VertexHandle> face_vhandles;
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[1]);
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[1]);
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[4]);
face_vhandles.push_back(vhandle[5]);
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[3]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[7]);
face_vhandles.push_back(vhandle[6]);
mesh_.add_face(face_vhandles);
// Test setup:
// 6 === 7 === 8
// | | |
// | | |
// | | |
// 3 === 4 === 5
// | | |
// | | |
// | | |
// 0 === 1 === 2
// Initialize subdivider
OpenMesh::Subdivider::Uniform::CatmullClarkT<PolyMesh> catmull;
// Check setup
EXPECT_EQ(9u, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(4u, mesh_.n_faces() ) << "Wrong number of faces";
// Execute 3 subdivision steps
catmull.attach(mesh_);
catmull( 3 );
catmull.detach();
EXPECT_EQ(289u, mesh_.n_vertices() ) << "Wrong number of vertices after subdivision with catmull clark";
EXPECT_EQ(256u, mesh_.n_faces() ) << "Wrong number of faces after subdivision with catmull clark";
/* Adds a cube to a polymesh
*/
TEST_F(OpenMeshSubdividerUniform_Poly, Midpoint) {
mesh_.clear();
// Add some vertices
Mesh::VertexHandle vhandle[8];
vhandle[0] = mesh_.add_vertex(PolyMesh::Point(-1, -1, 1));
vhandle[1] = mesh_.add_vertex(PolyMesh::Point( 1, -1, 1));
vhandle[2] = mesh_.add_vertex(PolyMesh::Point( 1, 1, 1));
vhandle[3] = mesh_.add_vertex(PolyMesh::Point(-1, 1, 1));
vhandle[4] = mesh_.add_vertex(PolyMesh::Point(-1, -1, -1));
vhandle[5] = mesh_.add_vertex(PolyMesh::Point( 1, -1, -1));
vhandle[6] = mesh_.add_vertex(PolyMesh::Point( 1, 1, -1));
vhandle[7] = mesh_.add_vertex(PolyMesh::Point(-1, 1, -1));
// Add six faces to form a cube
std::vector<Mesh::VertexHandle> face_vhandles;
face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[3]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[7]);
face_vhandles.push_back(vhandle[6]);
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[1]);
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[5]);
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[5]);
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[2]);
face_vhandles.push_back(vhandle[6]);
face_vhandles.push_back(vhandle[7]);
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[7]);
face_vhandles.push_back(vhandle[4]);
mesh_.add_face(face_vhandles);
// Test setup:
//
//
// 3 ======== 2
// / /|
// / / | z
// 0 ======== 1 | |
// | | | | y
// | 7 | 6 | /
// | | / | /
// | |/ |/
// 4 ======== 5 -------> x
//
// Check setup
EXPECT_EQ(12u, mesh_.n_edges()) << "Wrong number of Edges";
EXPECT_EQ(24u, mesh_.n_halfedges()) << "Wrong number of HalfEdges";
EXPECT_EQ(8u, mesh_.n_vertices()) << "Wrong number of vertices";
EXPECT_EQ(6u, mesh_.n_faces()) << "Wrong number of faces";
// Initialize subdivider
OpenMesh::Subdivider::Uniform::MidpointT<PolyMesh> midpoint;
// Execute 2 subdivision steps
midpoint.attach(mesh_);
midpoint(2);
midpoint.detach();
// Check Result
EXPECT_EQ(48u, mesh_.n_edges()) << "Wrong number of Edges";
EXPECT_EQ(96u, mesh_.n_halfedges()) << "Wrong number of HalfEdges";
EXPECT_EQ(24u, mesh_.n_vertices()) << "Wrong number of vertices";
EXPECT_EQ(26u, mesh_.n_faces()) << "Wrong number of faces";
}
}
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