Commit cb981241 authored by Isaak Lim's avatar Isaak Lim
Browse files

- fixed typedef problems

- split unittests for uniform and adaptive subdivider

refs #261

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@756 fdac6126-5c0c-442c-9429-916003d36597
parent 485356ab
...@@ -170,7 +170,7 @@ initialize( void ) ...@@ -170,7 +170,7 @@ initialize( void )
template<class M> template<class M>
void CompositeT<M>::refine(typename Mesh::FaceHandle& _fh) void CompositeT<M>::refine(typename M::FaceHandle& _fh)
{ {
std::vector<typename Mesh::HalfedgeHandle> hh_vector; std::vector<typename Mesh::HalfedgeHandle> hh_vector;
...@@ -271,7 +271,7 @@ void CompositeT<M>::refine(typename Mesh::FaceHandle& _fh) ...@@ -271,7 +271,7 @@ void CompositeT<M>::refine(typename Mesh::FaceHandle& _fh)
template<class M> template<class M>
void CompositeT<M>::refine(typename Mesh::VertexHandle& _vh) void CompositeT<M>::refine(typename M::VertexHandle& _vh)
{ {
// calculate next final level for vertex // calculate next final level for vertex
int new_vertex_state = generation(_vh) + l_rule()->number() + 1; int new_vertex_state = generation(_vh) + l_rule()->number() + 1;
......
...@@ -172,11 +172,11 @@ public: ...@@ -172,11 +172,11 @@ public:
/// Refine one face. /// Refine one face.
void refine(typename Mesh::FaceHandle& _fh); void refine(typename M::FaceHandle& _fh);
/// Raise one vertex to next final level. /// Raise one vertex to next final level.
void refine(typename Mesh::VertexHandle& _vh); void refine(typename M::VertexHandle& _vh);
/// Return subdivision split type (3 for 1-to-3 split, 4 for 1-to-4 split). /// Return subdivision split type (3 for 1-to-3 split, 4 for 1-to-4 split).
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
#include "unittests_decimater.hh" #include "unittests_decimater.hh"
#include "unittests_mc_decimater.hh" #include "unittests_mc_decimater.hh"
#include "unittests_mixed_decimater.hh" #include "unittests_mixed_decimater.hh"
#include "unittests_subdivider.hh" #include "unittests_subdivider_uniform.hh"
#include "unittests_subdivider_adaptive.hh"
#include "unittests_trimesh_normal_calculations.hh" #include "unittests_trimesh_normal_calculations.hh"
#include "unittests_trimesh_others.hh" #include "unittests_trimesh_others.hh"
#include "unittests_add_face.hh" #include "unittests_add_face.hh"
......
#ifndef INCLUDE_UNITTESTS_SUBIVIDER_HH #ifndef INCLUDE_UNITTESTS_SUBIVIDER_ADAPTIVE_HH
#define INCLUDE_UNITTESTS_SUBIVIDER_HH #define INCLUDE_UNITTESTS_SUBIVIDER_ADAPTIVE_HH
#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/Sqrt3T.hh>
#include <OpenMesh/Tools/Subdivider/Adaptive/Composite/CompositeT.hh> #include <OpenMesh/Tools/Subdivider/Adaptive/Composite/CompositeT.hh>
#include <OpenMesh/Tools/Subdivider/Adaptive/Composite/RulesT.hh> #include <OpenMesh/Tools/Subdivider/Adaptive/Composite/RulesT.hh>
class OpenMeshSubdivider_Poly : public OpenMeshBasePoly { class OpenMeshSubdividerAdaptive_Poly : public OpenMeshBasePoly {
protected: protected:
...@@ -28,7 +26,7 @@ class OpenMeshSubdivider_Poly : public OpenMeshBasePoly { ...@@ -28,7 +26,7 @@ class OpenMeshSubdivider_Poly : public OpenMeshBasePoly {
//Mesh mesh_; //Mesh mesh_;
}; };
class OpenMeshSubdivider_Triangle : public OpenMeshBase { class OpenMeshSubdividerAdaptive_Triangle : public OpenMeshBase {
protected: protected:
...@@ -54,199 +52,6 @@ class OpenMeshSubdivider_Triangle : public OpenMeshBase { ...@@ -54,199 +52,6 @@ class OpenMeshSubdivider_Triangle : public OpenMeshBase {
* ==================================================================== * ====================================================================
*/ */
/*
*/
TEST_F(OpenMeshSubdivider_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::Sqrt3T<Mesh> sqrt3;
// 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
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";
}
/*
* ====================================================================
* Define tests below
* ====================================================================
*/
/*
*/
TEST_F(OpenMeshSubdivider_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";
}
struct MeshTraits : public OpenMesh::Subdivider::Adaptive::CompositeTraits { struct MeshTraits : public OpenMesh::Subdivider::Adaptive::CompositeTraits {
typedef OpenMesh::Vec3f Point; typedef OpenMesh::Vec3f Point;
typedef OpenMesh::Vec3f Normal; typedef OpenMesh::Vec3f Normal;
...@@ -257,8 +62,10 @@ struct MeshTraits : public OpenMesh::Subdivider::Adaptive::CompositeTraits { ...@@ -257,8 +62,10 @@ struct MeshTraits : public OpenMesh::Subdivider::Adaptive::CompositeTraits {
}; };
typedef OpenMesh::TriMesh_ArrayKernelT<MeshTraits> MyMesh; typedef OpenMesh::TriMesh_ArrayKernelT<MeshTraits> MyMesh;
typedef MyMesh::VertexHandle VHandle;
typedef MyMesh::FaceHandle FHandle;
TEST_F(OpenMeshSubdivider_Triangle, AdaptiveCompositeRefineVertex) { TEST_F(OpenMeshSubdividerAdaptive_Triangle, AdaptiveCompositeRefineVertex) {
MyMesh mesh; MyMesh mesh;
mesh.request_vertex_status(); mesh.request_vertex_status();
...@@ -268,7 +75,7 @@ TEST_F(OpenMeshSubdivider_Triangle, AdaptiveCompositeRefineVertex) { ...@@ -268,7 +75,7 @@ TEST_F(OpenMeshSubdivider_Triangle, AdaptiveCompositeRefineVertex) {
mesh.request_face_normals(); mesh.request_face_normals();
// Add some vertices // Add some vertices
MyMesh::VertexHandle vhandle[9]; VHandle vhandle[9];
vhandle[0] = mesh.add_vertex(MyMesh::Point(0, 0, 0)); vhandle[0] = mesh.add_vertex(MyMesh::Point(0, 0, 0));
vhandle[1] = mesh.add_vertex(MyMesh::Point(0, 1, 0)); vhandle[1] = mesh.add_vertex(MyMesh::Point(0, 1, 0));
...@@ -281,7 +88,7 @@ TEST_F(OpenMeshSubdivider_Triangle, AdaptiveCompositeRefineVertex) { ...@@ -281,7 +88,7 @@ TEST_F(OpenMeshSubdivider_Triangle, AdaptiveCompositeRefineVertex) {
vhandle[8] = mesh.add_vertex(MyMesh::Point(2, 2, 0)); vhandle[8] = mesh.add_vertex(MyMesh::Point(2, 2, 0));
// Add eight faces // Add eight faces
std::vector<MyMesh::VertexHandle> face_vhandles; std::vector<VHandle> face_vhandles;
face_vhandles.push_back(vhandle[0]); face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[4]); face_vhandles.push_back(vhandle[4]);
...@@ -336,7 +143,7 @@ TEST_F(OpenMeshSubdivider_Triangle, AdaptiveCompositeRefineVertex) { ...@@ -336,7 +143,7 @@ TEST_F(OpenMeshSubdivider_Triangle, AdaptiveCompositeRefineVertex) {
face_vhandles.push_back(vhandle[5]); face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[8]); face_vhandles.push_back(vhandle[8]);
MyMesh::FaceHandle fh = mesh.add_face(face_vhandles); mesh.add_face(face_vhandles);
//// Test setup: //// Test setup:
//// 6 === 7 === 8 //// 6 === 7 === 8
...@@ -373,7 +180,7 @@ TEST_F(OpenMeshSubdivider_Triangle, AdaptiveCompositeRefineVertex) { ...@@ -373,7 +180,7 @@ TEST_F(OpenMeshSubdivider_Triangle, AdaptiveCompositeRefineVertex) {
} }
TEST_F(OpenMeshSubdivider_Triangle, AdaptiveCompositeRefineFace) { TEST_F(OpenMeshSubdividerAdaptive_Triangle, AdaptiveCompositeRefineFace) {
MyMesh mesh; MyMesh mesh;
mesh.request_vertex_status(); mesh.request_vertex_status();
...@@ -383,7 +190,7 @@ TEST_F(OpenMeshSubdivider_Triangle, AdaptiveCompositeRefineFace) { ...@@ -383,7 +190,7 @@ TEST_F(OpenMeshSubdivider_Triangle, AdaptiveCompositeRefineFace) {
mesh.request_face_normals(); mesh.request_face_normals();
// Add some vertices // Add some vertices
MyMesh::VertexHandle vhandle[9]; VHandle vhandle[9];
vhandle[0] = mesh.add_vertex(MyMesh::Point(0, 0, 0)); vhandle[0] = mesh.add_vertex(MyMesh::Point(0, 0, 0));
vhandle[1] = mesh.add_vertex(MyMesh::Point(0, 1, 0)); vhandle[1] = mesh.add_vertex(MyMesh::Point(0, 1, 0));
...@@ -396,8 +203,8 @@ TEST_F(OpenMeshSubdivider_Triangle, AdaptiveCompositeRefineFace) { ...@@ -396,8 +203,8 @@ TEST_F(OpenMeshSubdivider_Triangle, AdaptiveCompositeRefineFace) {
vhandle[8] = mesh.add_vertex(MyMesh::Point(2, 2, 0)); vhandle[8] = mesh.add_vertex(MyMesh::Point(2, 2, 0));
// Add eight faces // Add eight faces
std::vector<MyMesh::VertexHandle> face_vhandles; std::vector<VHandle> face_vhandles;
std::vector<MyMesh::FaceHandle> face_handles; std::vector<FHandle> face_handles;
face_vhandles.push_back(vhandle[0]); face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[4]); face_vhandles.push_back(vhandle[4]);
...@@ -480,7 +287,7 @@ TEST_F(OpenMeshSubdivider_Triangle, AdaptiveCompositeRefineFace) { ...@@ -480,7 +287,7 @@ TEST_F(OpenMeshSubdivider_Triangle, AdaptiveCompositeRefineFace) {
EXPECT_EQ(8u, mesh.n_faces() ) << "Wrong number of faces"; EXPECT_EQ(8u, mesh.n_faces() ) << "Wrong number of faces";
// execute adaptive composite subdivision // execute adaptive composite subdivision
std::vector<MyMesh::FaceHandle>::iterator it, end; std::vector<FHandle>::iterator it, end;
it = face_handles.begin(); it = face_handles.begin();
end = face_handles.end(); end = face_handles.end();
for (; it != end; ++it) for (; it != end; ++it)
......
#ifndef INCLUDE_UNITTESTS_SUBIVIDER_UNIFORM_HH
#define INCLUDE_UNITTESTS_SUBIVIDER_UNIFORM_HH
#include <gtest/gtest.h>
#include <Unittests/unittests_common.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/CatmullClarkT.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/Sqrt3T.hh>
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...
}
// 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...
}
// 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
* ====================================================================
*/
/*
*/
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::Sqrt3T<Mesh> sqrt3;
// 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
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";
}
/*
* ====================================================================
* Define tests below
* ====================================================================
*/
/*
*/
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;