Commit 485356ab authored by Isaak Lim's avatar Isaak Lim

- removed a wrong assertion in the refine method for vector handles

- added unittests for the adaptive composite subdivider

closes #261

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@755 fdac6126-5c0c-442c-9429-916003d36597
parent 471e6200
......@@ -276,8 +276,6 @@ void CompositeT<M>::refine(typename Mesh::VertexHandle& _vh)
// calculate next final level for vertex
int new_vertex_state = generation(_vh) + l_rule()->number() + 1;
assert( new_vertex_state == mesh_.data(_vh).state()+1 );
// raise vertex to final position
l_rule()->raise(_vh, new_vertex_state);
}
......
......@@ -5,6 +5,8 @@
#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/RulesT.hh>
class OpenMeshSubdivider_Poly : public OpenMeshBasePoly {
......@@ -245,4 +247,250 @@ TEST_F(OpenMeshSubdivider_Poly, Subdivider_CatmullClark) {
}
struct MeshTraits : public OpenMesh::Subdivider::Adaptive::CompositeTraits {
typedef OpenMesh::Vec3f Point;
typedef OpenMesh::Vec3f Normal;
VertexAttributes(OpenMesh::Attributes::Status | OpenMesh::Attributes::Normal);
EdgeAttributes(OpenMesh::Attributes::Status);
FaceAttributes(OpenMesh::Attributes::Status | OpenMesh::Attributes::Normal);
};
typedef OpenMesh::TriMesh_ArrayKernelT<MeshTraits> MyMesh;
TEST_F(OpenMeshSubdivider_Triangle, AdaptiveCompositeRefineVertex) {
MyMesh mesh;
mesh.request_vertex_status();
mesh.request_edge_status();
mesh.request_face_status();
mesh.request_vertex_normals();
mesh.request_face_normals();
// Add some vertices
MyMesh::VertexHandle vhandle[9];
vhandle[0] = mesh.add_vertex(MyMesh::Point(0, 0, 0));
vhandle[1] = mesh.add_vertex(MyMesh::Point(0, 1, 0));
vhandle[2] = mesh.add_vertex(MyMesh::Point(0, 2, 0));
vhandle[3] = mesh.add_vertex(MyMesh::Point(1, 0, 0));
vhandle[4] = mesh.add_vertex(MyMesh::Point(1, 1, 0));
vhandle[5] = mesh.add_vertex(MyMesh::Point(1, 2, 0));
vhandle[6] = mesh.add_vertex(MyMesh::Point(2, 0, 0));
vhandle[7] = mesh.add_vertex(MyMesh::Point(2, 1, 0));
vhandle[8] = mesh.add_vertex(MyMesh::Point(2, 2, 0));
// Add eight faces
std::vector<MyMesh::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]);
MyMesh::FaceHandle fh = mesh.add_face(face_vhandles);
//// Test setup:
//// 6 === 7 === 8
//// | / | / |
//// | / | / |
//// | / | / |
//// 3 === 4 === 5
//// | / | \ |
//// | / | \ |
//// | / | \ |
//// 0 === 1 === 2
// Initialize subdivider
OpenMesh::Subdivider::Adaptive::CompositeT<MyMesh> subdivider(mesh);
subdivider.add<OpenMesh::Subdivider::Adaptive::Tvv3<MyMesh> >();
subdivider.add<OpenMesh::Subdivider::Adaptive::VF<MyMesh> >();
subdivider.add<OpenMesh::Subdivider::Adaptive::FF<MyMesh> >();
subdivider.add<OpenMesh::Subdivider::Adaptive::FVc<MyMesh> >();
subdivider.initialize();
// Check setup
EXPECT_EQ(9u, mesh.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(8u, mesh.n_faces() ) << "Wrong number of faces";
// execute adaptive composite subdivision
subdivider.refine(vhandle[4]);
// Check setup
EXPECT_EQ(17u, mesh.n_vertices() ) << "Wrong number of vertices after subdivision with sqrt3";
EXPECT_EQ(24u, mesh.n_faces() ) << "Wrong number of faces after subdivision with sqrt3";
}
TEST_F(OpenMeshSubdivider_Triangle, AdaptiveCompositeRefineFace) {
MyMesh mesh;
mesh.request_vertex_status();
mesh.request_edge_status();
mesh.request_face_status();
mesh.request_vertex_normals();
mesh.request_face_normals();
// Add some vertices
MyMesh::VertexHandle vhandle[9];
vhandle[0] = mesh.add_vertex(MyMesh::Point(0, 0, 0));
vhandle[1] = mesh.add_vertex(MyMesh::Point(0, 1, 0));
vhandle[2] = mesh.add_vertex(MyMesh::Point(0, 2, 0));
vhandle[3] = mesh.add_vertex(MyMesh::Point(1, 0, 0));
vhandle[4] = mesh.add_vertex(MyMesh::Point(1, 1, 0));
vhandle[5] = mesh.add_vertex(MyMesh::Point(1, 2, 0));
vhandle[6] = mesh.add_vertex(MyMesh::Point(2, 0, 0));
vhandle[7] = mesh.add_vertex(MyMesh::Point(2, 1, 0));
vhandle[8] = mesh.add_vertex(MyMesh::Point(2, 2, 0));
// Add eight faces
std::vector<MyMesh::VertexHandle> face_vhandles;
std::vector<MyMesh::FaceHandle> face_handles;
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[3]);
face_handles.push_back(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_handles.push_back(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_handles.push_back(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_handles.push_back(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_handles.push_back(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_handles.push_back(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_handles.push_back(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_handles.push_back(mesh.add_face(face_vhandles));
//// Test setup:
//// 6 === 7 === 8
//// | / | / |
//// | / | / |
//// | / | / |
//// 3 === 4 === 5
//// | / | \ |
//// | / | \ |
//// | / | \ |
//// 0 === 1 === 2
// Initialize subdivider
OpenMesh::Subdivider::Adaptive::CompositeT<MyMesh> subdivider(mesh);
subdivider.add<OpenMesh::Subdivider::Adaptive::Tvv3<MyMesh> >();
subdivider.add<OpenMesh::Subdivider::Adaptive::VF<MyMesh> >();
subdivider.add<OpenMesh::Subdivider::Adaptive::FF<MyMesh> >();
subdivider.add<OpenMesh::Subdivider::Adaptive::FVc<MyMesh> >();
subdivider.initialize();
// Check setup
EXPECT_EQ(9u, mesh.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(8u, mesh.n_faces() ) << "Wrong number of faces";
// execute adaptive composite subdivision
std::vector<MyMesh::FaceHandle>::iterator it, end;
it = face_handles.begin();
end = face_handles.end();
for (; it != end; ++it)
subdivider.refine(*it);
// Check setup
EXPECT_EQ(245u, mesh.n_vertices() ) << "Wrong number of vertices after subdivision with sqrt3";
EXPECT_EQ(458u, mesh.n_faces() ) << "Wrong number of faces after subdivision with sqrt3";
}
#endif // INCLUDE GUARD
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