diff --git a/src/Unittests/TestFiles/cube1.pm b/src/Unittests/TestFiles/cube1.pm new file mode 100644 index 00000000..0f9eca3d Binary files /dev/null and b/src/Unittests/TestFiles/cube1.pm differ diff --git a/src/Unittests/unittests_vdpm.cc b/src/Unittests/unittests_vdpm.cc new file mode 100644 index 00000000..dee87170 --- /dev/null +++ b/src/Unittests/unittests_vdpm.cc @@ -0,0 +1,276 @@ +#include +#include + +#include +#include +#include + +#include +#include +#include + +namespace { + + class OpenMeshVDPM : public OpenMeshBase { + + protected: + + // This function is called before each test is run + virtual void SetUp() { + } + + // 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 +* ==================================================================== +*/ + +/* + * 2 tests, one is creating a pm file (cube1.pm) and the second test loads and analyze the readings. + */ + +struct PMInfo +{ + Mesh::Point p0; + Mesh::VertexHandle v0, v1, vl, vr; +}; + +struct VDPMTraits : public OpenMesh::DefaultTraits +{ + typedef OpenMesh::VDPM::VHierarchyNodeHandle VHierarchyNodeHandle; + typedef OpenMesh::VDPM::VHierarchyNodeHandle VHierarchyNodeIndex; + VertexTraits + { + public: + + VHierarchyNodeHandle vhierarchy_node_handle() + { + return node_handle_; + } + + void set_vhierarchy_node_handle(VHierarchyNodeHandle _node_handle) + { + node_handle_ = _node_handle; + } + + bool is_ancestor(const VHierarchyNodeIndex &_other) + { + return false; + } + + private: + + VHierarchyNodeHandle node_handle_; + + }; + + + HalfedgeTraits + { + public: + + VHierarchyNodeHandle + vhierarchy_leaf_node_handle() + { + return leaf_node_handle_; + } + + void + set_vhierarchy_leaf_node_handle(VHierarchyNodeHandle _leaf_node_handle) + { + leaf_node_handle_ = _leaf_node_handle; + } + + private: + + VHierarchyNodeHandle leaf_node_handle_; + + }; + + VertexAttributes(OpenMesh::Attributes::Status | + OpenMesh::Attributes::Normal); + HalfedgeAttributes(OpenMesh::Attributes::PrevHalfedge); + EdgeAttributes(OpenMesh::Attributes::Status); + FaceAttributes(OpenMesh::Attributes::Status | + OpenMesh::Attributes::Normal); + +}; + +typedef OpenMesh::TriMesh_ArrayKernelT VDPMMesh; + +struct LoadInfo +{ + unsigned n_base_vertices; + unsigned n_base_faces; + unsigned n_details; + std::vector pm_infos; + OpenMesh::VDPM::VHierarchy vhierarchy; + VDPMMesh mesh; +}; + +LoadInfo open_progresult_mesh(const std::string& _filename) +{ + VDPMMesh::Point p; + unsigned int i, i0, i1, i2; + unsigned int v1, vl, vr; + char c[10]; + VDPMMesh::VertexHandle vertex_handle; + OpenMesh::VDPM::VHierarchyNodeHandle node_handle, lchild_handle, rchild_handle; + OpenMesh::VDPM::VHierarchyNodeIndex node_index; + LoadInfo result; + + std::ifstream ifs(_filename.c_str(), std::ios::binary); + if (!ifs) + { + EXPECT_TRUE(false) << "Could not open file"; + return result; + } + + // + bool swap = OpenMesh::Endian::local() != OpenMesh::Endian::LSB; + + // read header + ifs.read(c, 8); c[8] = '\0'; + if (std::string(c) != std::string("ProgMesh")) + { + EXPECT_TRUE(false) << "Wrong file format"; + return result; + } + + OpenMesh::IO::restore(ifs, result.n_base_vertices, swap); + OpenMesh::IO::restore(ifs, result.n_base_faces, swap); + OpenMesh::IO::restore(ifs, result.n_details, swap); + + result.vhierarchy.set_num_roots(result.n_base_vertices); + + for (i = 0; i Decimater; + typedef OpenMesh::Decimater::ModProgMeshT< Mesh >::Handle HModProg; + typedef OpenMesh::Decimater::ModQuadricT< Mesh >::Handle HModQuadric; + + Decimater decimater(mesh); + HModProg hModProg; + HModQuadric hModQuadric; + decimater.add(hModQuadric); + decimater.add(hModProg); + decimater.initialize(); + size_t removedVertices = 0; + removedVertices = decimater.decimate(0); + + std::string filename = "vdpm_test_file.pm"; + + EXPECT_TRUE(decimater.module(hModProg).write(filename)) << "Could not write PM file."; + + LoadInfo info = open_progresult_mesh(filename); + EXPECT_EQ(7526, info.mesh.n_vertices()) << "Vertices differ"; + EXPECT_EQ(6, info.mesh.n_edges()) << "Edges differ"; + EXPECT_EQ(4, info.mesh.n_faces()) << "Faces differ"; + EXPECT_EQ(7522, info.n_details) << "Details differ"; + + remove(filename.c_str()); +} + + + + + +}