1 #include <gtest/gtest.h> 2 #include <Unittests/unittests_common.hh> 8 #include <OpenMesh/Tools/VDPM/VHierarchy.hh> 9 #include <OpenMesh/Tools/VDPM/VHierarchyNode.hh> 10 #include <OpenMesh/Tools/VDPM/VHierarchyNodeIndex.hh> 19 virtual void SetUp() {
23 virtual void TearDown() {
56 VHierarchyNodeHandle vhierarchy_node_handle()
61 void set_vhierarchy_node_handle(VHierarchyNodeHandle _node_handle)
63 node_handle_ = _node_handle;
66 bool is_ancestor(
const VHierarchyNodeIndex &_other)
73 VHierarchyNodeHandle node_handle_;
83 vhierarchy_leaf_node_handle()
85 return leaf_node_handle_;
89 set_vhierarchy_leaf_node_handle(VHierarchyNodeHandle _leaf_node_handle)
91 leaf_node_handle_ = _leaf_node_handle;
96 VHierarchyNodeHandle leaf_node_handle_;
113 unsigned n_base_vertices;
114 unsigned n_base_faces;
116 std::vector<PMInfo> pm_infos;
121 LoadInfo open_progresult_mesh(
const std::string& _filename)
124 unsigned int i, i0, i1, i2;
125 unsigned int v1, vl, vr;
127 VDPMMesh::VertexHandle vertex_handle;
132 std::ifstream ifs(_filename.c_str(), std::ios::binary);
135 EXPECT_TRUE(
false) <<
"Could not open file";
143 ifs.read(c, 8); c[8] =
'\0';
144 if (std::string(c) != std::string(
"ProgMesh"))
146 EXPECT_TRUE(
false) <<
"Wrong file format";
154 result.vhierarchy.set_num_roots(result.n_base_vertices);
156 for (i = 0; i<result.n_base_vertices; ++i)
160 vertex_handle = result.mesh.add_vertex(p);
161 node_index = result.vhierarchy.generate_node_index(i, 1);
162 node_handle = result.vhierarchy.add_node();
164 result.vhierarchy.node(node_handle).set_index(node_index);
165 result.vhierarchy.node(node_handle).set_vertex_handle(vertex_handle);
166 result.mesh.data(vertex_handle).set_vhierarchy_node_handle(node_handle);
169 for (i = 0; i<result.n_base_faces; ++i)
174 result.mesh.add_face(result.mesh.vertex_handle(i0),
175 result.mesh.vertex_handle(i1),
176 result.mesh.vertex_handle(i2));
180 for (i = 0; i<result.n_details; ++i)
189 pminfo.v0 = result.mesh.add_vertex(p);
193 result.pm_infos.push_back(pminfo);
195 node_handle = result.mesh.data(pminfo.v1).vhierarchy_node_handle();
197 result.vhierarchy.make_children(node_handle);
198 lchild_handle = result.vhierarchy.lchild_handle(node_handle);
199 rchild_handle = result.vhierarchy.rchild_handle(node_handle);
201 result.mesh.data(pminfo.v0).set_vhierarchy_node_handle(lchild_handle);
202 result.mesh.data(pminfo.v1).set_vhierarchy_node_handle(rchild_handle);
203 result.vhierarchy.node(lchild_handle).set_vertex_handle(pminfo.v0);
204 result.vhierarchy.node(rchild_handle).set_vertex_handle(pminfo.v1);
211 for (i = 0; i<result.n_base_vertices; ++i)
213 node_handle = result.vhierarchy.root_handle(i);
214 vertex_handle = result.vhierarchy.node(node_handle).vertex_handle();
216 result.mesh.data(vertex_handle).set_vhierarchy_node_handle(node_handle);
226 TEST_F(OpenMeshVDPM, ReadPM)
228 LoadInfo info = open_progresult_mesh(
"cube1.pm");
230 EXPECT_EQ(7526u, info.mesh.n_vertices()) <<
"Vertices differ";
231 EXPECT_EQ(6u, info.mesh.n_edges()) <<
"Edges differ";
232 EXPECT_EQ(4u, info.mesh.n_faces()) <<
"Faces differ";
233 EXPECT_EQ(7522u, info.n_details) <<
"Details differ";
239 TEST_F(OpenMeshVDPM, WriteReadPM)
250 Decimater decimater(mesh);
252 HModQuadric hModQuadric;
253 decimater.add(hModQuadric);
254 decimater.add(hModProg);
255 decimater.initialize();
256 decimater.decimate(0);
258 std::string filename =
"vdpm_test_file.pm";
260 EXPECT_TRUE(decimater.module(hModProg).write(filename)) <<
"Could not write PM file.";
262 LoadInfo info = open_progresult_mesh(filename);
263 EXPECT_EQ(7526u, info.mesh.n_vertices()) <<
"Vertices differ";
264 EXPECT_EQ(6u, info.mesh.n_edges()) <<
"Edges differ";
265 EXPECT_EQ(4u, info.mesh.n_faces()) <<
"Faces differ";
266 EXPECT_EQ(7522u, info.n_details) <<
"Details differ";
268 remove(filename.c_str());
void vector_cast(const src_t &_src, dst_t &_dst, GenProg::Int2Type< n >)
Cast vector type to another vector type by copying the vector elements.
Little endian (Intel family and clones)
Kernel::Point Point
Coordinate type.
size_t restore(std::istream &_is, T &_v, bool _swap=false)
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
#define VertexTraits
Macro for defining the vertex traits. See Specifying your MyMesh.
static Type local()
Return endian type of host system.
#define HalfedgeAttributes(_i)
Macro for defining the halfedge attributes. See Specifying your MyMesh.
#define EdgeAttributes(_i)
Macro for defining the edge attributes. See Specifying your MyMesh.
Add status to mesh item (all items)
Add storage for previous halfedge (halfedges). The bit is set by default in the DefaultTraits.
#define HalfedgeTraits
Macro for defining the halfedge traits. See Specifying your MyMesh.
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Add normals to mesh item (vertices/faces)
#define VertexAttributes(_i)
Macro for defining the vertex attributes. See Specifying your MyMesh.
Mesh decimation module computing collapse priority based on error quadrics.
#define FaceAttributes(_i)
Macro for defining the face attributes. See Specifying your MyMesh.