Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
unittests_read_write_OBJ.cc
1 
2 #include <gtest/gtest.h>
3 #include <Unittests/unittests_common.hh>
4 #include <cstdio>
5 
6 
7 namespace {
8 
9 class OpenMeshReadWriteOBJ : public OpenMeshBase {
10 
11  protected:
12 
13  // This function is called before each test is run
14  virtual void SetUp() {
15 
16  // Do some initial stuff with the member data here...
17  }
18 
19  // This function is called after all tests are through
20  virtual void TearDown() {
21 
22  // Do some final stuff with the member data here...
23  }
24 
25  // Member already defined in OpenMeshBase
26  //Mesh mesh_;
27 };
28 
29 /*
30  * ====================================================================
31  * Define tests below
32  * ====================================================================
33  */
34 
35 /*
36  * Just load a obj file of a cube
37  */
38 TEST_F(OpenMeshReadWriteOBJ, LoadSimpleOBJ) {
39 
40  mesh_.clear();
41 
42  bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal.obj");
43 
44  EXPECT_TRUE(ok) << "Unable to load cube-minimal.obj";
45 
46  EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
47  EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
48  EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
49 }
50 
51 /*
52  * Just load a obj file of a cube with degenerated faces
53  */
54 TEST_F(OpenMeshReadWriteOBJ, LoadDegeneratedOBJ) {
55 
56  mesh_.clear();
57 
58  bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-degenerated.obj");
59 
60  EXPECT_TRUE(ok) << "Unable to load cube-minimal-degenerated.obj";
61 
62  EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
63  EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
64  EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
65 }
66 
67 /*
68  * Just load a obj file of a cube and checks the halfedge and vertex normals
69  */
70 TEST_F(OpenMeshReadWriteOBJ, LoadSimpleOBJCheckHalfEdgeAndVertexNormals) {
71 
72  mesh_.clear();
73 
74  mesh_.request_halfedge_normals();
75  mesh_.request_vertex_normals();
76 
77  OpenMesh::IO::Options options;
79 
80  std::string file_name = "cube-minimal.obj";
81 
82  bool ok = OpenMesh::IO::read_mesh(mesh_, file_name,options);
83 
84  EXPECT_TRUE(ok) << file_name;
85 
86  EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
87  EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
88  EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
89  EXPECT_EQ(36u , mesh_.n_halfedges()) << "The number of loaded halfedges is not correct!";
90 
92  //check vertex normals
93  EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[0] ) << "Wrong vertex normal at vertex 0 component 0";
94  EXPECT_EQ(-1, mesh_.normal(mesh_.vertex_handle(0))[1] ) << "Wrong vertex normal at vertex 0 component 1";
95  EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[2] ) << "Wrong vertex normal at vertex 0 component 2";
96 
97  EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(3))[0] ) << "Wrong vertex normal at vertex 3 component 0";
98  EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(3))[1] ) << "Wrong vertex normal at vertex 3 component 1";
99  EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(3))[2] ) << "Wrong vertex normal at vertex 3 component 2";
100 
101  EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(4))[0] ) << "Wrong vertex normal at vertex 4 component 0";
102  EXPECT_EQ(-1, mesh_.normal(mesh_.vertex_handle(4))[1] ) << "Wrong vertex normal at vertex 4 component 1";
103  EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(4))[2] ) << "Wrong vertex normal at vertex 4 component 2";
104 
105  EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(7))[0] ) << "Wrong vertex normal at vertex 7 component 0";
106  EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(7))[1] ) << "Wrong vertex normal at vertex 7 component 1";
107  EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(7))[2] ) << "Wrong vertex normal at vertex 7 component 2";
108 
110  //check halfedge normals
111  EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(0))[0] ) << "Wrong halfedge normal at halfedge 0 component 0";
112  EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(0))[1] ) << "Wrong halfedge normal at halfedge 0 component 1";
113  EXPECT_EQ(-1, mesh_.normal(mesh_.halfedge_handle(0))[2] ) << "Wrong halfedge normal at halfedge 0 component 2";
114 
115  EXPECT_EQ(-1, mesh_.normal(mesh_.halfedge_handle(10))[0] ) << "Wrong halfedge normal at halfedge 10 component 0";
116  EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(10))[1] ) << "Wrong halfedge normal at halfedge 10 component 1";
117  EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(10))[2] ) << "Wrong halfedge normal at halfedge 10 component 2";
118 
119  EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(19))[0] ) << "Wrong halfedge normal at halfedge 19 component 0";
120  EXPECT_EQ(1, mesh_.normal(mesh_.halfedge_handle(19))[1] ) << "Wrong halfedge normal at halfedge 19 component 1";
121  EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(19))[2] ) << "Wrong halfedge normal at halfedge 19 component 2";
122 
123  EXPECT_EQ(1, mesh_.normal(mesh_.halfedge_handle(24))[0] ) << "Wrong halfedge normal at halfedge 24 component 0";
124  EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(24))[1] ) << "Wrong halfedge normal at halfedge 24 component 1";
125  EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(24))[2] ) << "Wrong halfedge normal at halfedge 24 component 2";
126 
127  EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(30))[0] ) << "Wrong halfedge normal at halfedge 30 component 0";
128  EXPECT_EQ(-1, mesh_.normal(mesh_.halfedge_handle(30))[1] ) << "Wrong halfedge normal at halfedge 30 component 1";
129  EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(30))[2] ) << "Wrong halfedge normal at halfedge 30 component 2";
130 
131  EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(35))[0] ) << "Wrong halfedge normal at halfedge 35 component 0";
132  EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(35))[1] ) << "Wrong halfedge normal at halfedge 35 component 1";
133  EXPECT_EQ(1, mesh_.normal(mesh_.halfedge_handle(35))[2] ) << "Wrong halfedge normal at halfedge 35 component 2";
134 
135  mesh_.release_vertex_normals();
136  mesh_.release_halfedge_normals();
137 
138 }
139 
140 /*
141  * Just load a obj file and set vertex color option before loading
142  */
143 TEST_F(OpenMeshReadWriteOBJ, LoadSimpleOBJForceVertexColorsAlthoughNotAvailable) {
144 
145  mesh_.clear();
146 
147  mesh_.request_vertex_colors();
148 
149  std::string file_name = "cube-minimal.obj";
150 
151  OpenMesh::IO::Options options;
153 
154  bool ok = OpenMesh::IO::read_mesh(mesh_, file_name,options);
155 
156  EXPECT_TRUE(ok) << file_name;
157 
158  EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
159  EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
160  EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
161  EXPECT_EQ(36u , mesh_.n_halfedges()) << "The number of loaded halfedges is not correct!";
162 
163 }
164 
165 
166 /*
167  * Just load a obj file of a cube and checks the halfedge texCoords
168  */
169 TEST_F(OpenMeshReadWriteOBJ, LoadSimpleOBJCheckTexCoords) {
170 
171  mesh_.clear();
172 
173  mesh_.request_halfedge_texcoords2D();
174 
175  OpenMesh::IO::Options options;
177 
178  std::string file_name = "cube-minimal-texCoords.obj";
179 
180  bool ok = OpenMesh::IO::read_mesh(mesh_, file_name,options);
181 
182  EXPECT_TRUE(ok) << file_name;
183 
184  EXPECT_EQ(1, mesh_.texcoord2D(mesh_.halfedge_handle(0))[0] ) << "Wrong texCoord at halfedge 0 component 0";
185  EXPECT_EQ(1, mesh_.texcoord2D(mesh_.halfedge_handle(0))[1] ) << "Wrong texCoord at halfedge 0 component 1";
186 
187  EXPECT_EQ(3, mesh_.texcoord2D(mesh_.halfedge_handle(10))[0] ) << "Wrong texCoord at halfedge 1 component 0";
188  EXPECT_EQ(3, mesh_.texcoord2D(mesh_.halfedge_handle(10))[1] ) << "Wrong texCoord at halfedge 1 component 1";
189 
190  EXPECT_EQ(6, mesh_.texcoord2D(mesh_.halfedge_handle(19))[0] ) << "Wrong texCoord at halfedge 4 component 0";
191  EXPECT_EQ(6, mesh_.texcoord2D(mesh_.halfedge_handle(19))[1] ) << "Wrong texCoord at halfedge 4 component 1";
192 
193  EXPECT_EQ(7, mesh_.texcoord2D(mesh_.halfedge_handle(24))[0] ) << "Wrong texCoord at halfedge 7 component 0";
194  EXPECT_EQ(7, mesh_.texcoord2D(mesh_.halfedge_handle(24))[1] ) << "Wrong texCoord at halfedge 7 component 1";
195 
196  EXPECT_EQ(9, mesh_.texcoord2D(mesh_.halfedge_handle(30))[0] ) << "Wrong texCoord at halfedge 9 component 0";
197  EXPECT_EQ(9, mesh_.texcoord2D(mesh_.halfedge_handle(30))[1] ) << "Wrong texCoord at halfedge 9 component 1";
198 
199  EXPECT_EQ(12, mesh_.texcoord2D(mesh_.halfedge_handle(35))[0] ) << "Wrong texCoord at halfedge 11 component 0";
200  EXPECT_EQ(12, mesh_.texcoord2D(mesh_.halfedge_handle(35))[1] ) << "Wrong texCoord at halfedge 11 component 1";
201 
202  mesh_.release_halfedge_texcoords2D();
203 }
204 
205 /*
206  * Just load a obj file of a cube and checks the 3d halfedge texCoords
207  */
208 TEST_F(OpenMeshReadWriteOBJ, LoadSimpleOBJCheckTexCoords3d) {
209 
210  mesh_.clear();
211 
212  mesh_.request_halfedge_texcoords3D();
213 
214  OpenMesh::IO::Options options;
216 
217  std::string file_name = "cube-minimal-texCoords3d.obj";
218 
219  bool ok = OpenMesh::IO::read_mesh(mesh_, file_name,options);
220 
221  EXPECT_TRUE(ok) << file_name;
222 
223  EXPECT_EQ(1, mesh_.texcoord3D(mesh_.halfedge_handle(0))[0] ) << "Wrong texCoord at halfedge 0 component 0";
224  EXPECT_EQ(1, mesh_.texcoord3D(mesh_.halfedge_handle(0))[1] ) << "Wrong texCoord at halfedge 0 component 1";
225  EXPECT_EQ(1, mesh_.texcoord3D(mesh_.halfedge_handle(0))[2] ) << "Wrong texCoord at halfedge 0 component 2";
226 
227  EXPECT_EQ(3, mesh_.texcoord3D(mesh_.halfedge_handle(10))[0] ) << "Wrong texCoord at halfedge 1 component 0";
228  EXPECT_EQ(3, mesh_.texcoord3D(mesh_.halfedge_handle(10))[1] ) << "Wrong texCoord at halfedge 1 component 1";
229  EXPECT_EQ(3, mesh_.texcoord3D(mesh_.halfedge_handle(10))[2] ) << "Wrong texCoord at halfedge 1 component 2";
230 
231  EXPECT_EQ(6, mesh_.texcoord3D(mesh_.halfedge_handle(19))[0] ) << "Wrong texCoord at halfedge 4 component 0";
232  EXPECT_EQ(6, mesh_.texcoord3D(mesh_.halfedge_handle(19))[1] ) << "Wrong texCoord at halfedge 4 component 1";
233  EXPECT_EQ(6, mesh_.texcoord3D(mesh_.halfedge_handle(19))[2] ) << "Wrong texCoord at halfedge 4 component 2";
234 
235  EXPECT_EQ(7, mesh_.texcoord3D(mesh_.halfedge_handle(24))[0] ) << "Wrong texCoord at halfedge 7 component 0";
236  EXPECT_EQ(7, mesh_.texcoord3D(mesh_.halfedge_handle(24))[1] ) << "Wrong texCoord at halfedge 7 component 1";
237  EXPECT_EQ(7, mesh_.texcoord3D(mesh_.halfedge_handle(24))[2] ) << "Wrong texCoord at halfedge 7 component 2";
238 
239  EXPECT_EQ(9, mesh_.texcoord3D(mesh_.halfedge_handle(30))[0] ) << "Wrong texCoord at halfedge 9 component 0";
240  EXPECT_EQ(9, mesh_.texcoord3D(mesh_.halfedge_handle(30))[1] ) << "Wrong texCoord at halfedge 9 component 1";
241  EXPECT_EQ(9, mesh_.texcoord3D(mesh_.halfedge_handle(30))[2] ) << "Wrong texCoord at halfedge 9 component 2";
242 
243  EXPECT_EQ(12, mesh_.texcoord3D(mesh_.halfedge_handle(35))[0] ) << "Wrong texCoord at halfedge 11 component 0";
244  EXPECT_EQ(12, mesh_.texcoord3D(mesh_.halfedge_handle(35))[1] ) << "Wrong texCoord at halfedge 11 component 1";
245  EXPECT_EQ(12, mesh_.texcoord3D(mesh_.halfedge_handle(35))[2] ) << "Wrong texCoord at halfedge 11 component 2";
246 
247  mesh_.request_halfedge_texcoords3D();
248 }
249 
250 /*
251  * Just load a obj file of a square with a material
252  */
253 TEST_F(OpenMeshReadWriteOBJ, LoadObjWithMaterial) {
254 
255  mesh_.clear();
256 
257  mesh_.request_face_colors();
258 
259  OpenMesh::IO::Options options;
261 
262  std::string file_name = "square_material.obj";
263 
264  bool ok = OpenMesh::IO::read_mesh(mesh_, file_name,options);
265 
266  EXPECT_TRUE(ok) << file_name;
267 
268  OpenMesh::FaceHandle fh = mesh_.face_handle(mesh_.halfedge_handle(0));
269 
270  EXPECT_TRUE(fh.is_valid()) << "fh should be valid";
271 
272  EXPECT_EQ(128, mesh_.color(fh)[0] ) << "Wrong vertex color at vertex 0 component 0";
273  EXPECT_EQ(128, mesh_.color(fh)[1] ) << "Wrong vertex color at vertex 0 component 1";
274  EXPECT_EQ(128, mesh_.color(fh)[2] ) << "Wrong vertex color at vertex 0 component 2";
275 
276  mesh_.release_face_colors();
277 }
278 
279 TEST_F(OpenMeshReadWriteOBJ, LoadObjWithTexture) {
280 
281  mesh_.clear();
282 
283  mesh_.request_face_colors();
284  mesh_.request_face_texture_index();
285 
286  OpenMesh::IO::Options options;
288 
289  std::string file_name = "square_material_texture.obj";
290 
291  bool ok = OpenMesh::IO::read_mesh(mesh_, file_name, options);
292 
293  EXPECT_TRUE(ok) << file_name;
294 
295  //check texture mapping for the mesh
297  mesh_.get_property_handle(property, "TextureMapping");
298  EXPECT_EQ(mesh_.property(property).size(), 1u) << "More than one texture defined";
299  std::map< int, std::string >::iterator tex = mesh_.property(property).find(1);
300  EXPECT_TRUE(tex != mesh_.property(property).end()) << "Could not find texture with id 1";
301  EXPECT_TRUE((mesh_.property(property)[1] == std::string("square_material_texture.jpg"))) << "Wrong texture name";
302 
303  //check texture mapping per face
304  OpenMesh::FaceHandle fh = mesh_.face_handle(mesh_.halfedge_handle(0));
305  EXPECT_TRUE(fh.is_valid()) << "fh should be valid";
306  EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(),fh),1) << "Face texture index is not set correctly";
307 
308  mesh_.release_face_colors();
309  mesh_.release_face_texture_index();
310 }
311 
312 /*
313  * Just load a obj file of a cube with vertex colors defined directly after the vertex definitions
314  */
315 TEST_F(OpenMeshReadWriteOBJ, LoadSimpleOBJWithVertexColorsAfterVertices) {
316 
317  mesh_.clear();
318 
319  mesh_.request_vertex_colors();
320 
321  OpenMesh::IO::Options options;
323 
324  bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-vertex-colors-after-vertex-definition.obj",options);
325 
326  EXPECT_TRUE(ok) << "Unable to load cube-minimal-vertex-colors-after-vertex-definition.obj";
327 
328  EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
329  EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
330  EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
331 
332  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
333  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
334  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
335 
336  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
337  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
338  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
339 
340  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
341  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
342  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
343 
344  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
345  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
346  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
347 
348  mesh_.release_vertex_colors();
349 }
350 
351 /*
352  * Just load a obj file of a cube with vertex colors defined as separate lines
353  */
354 TEST_F(OpenMeshReadWriteOBJ, LoadSimpleOBJWithVertexColorsAsVCLines) {
355 
356  mesh_.clear();
357 
358  mesh_.request_vertex_colors();
359 
360  OpenMesh::IO::Options options;
362 
363  bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-vertex-colors-as-vc-lines.obj",options);
364 
365  EXPECT_TRUE(ok) << "Unable to load cube-minimal-vertex-colors-as-vc-lines.obj";
366 
367  EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
368  EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
369  EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
370 
371  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
372  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
373  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
374 
375  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
376  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
377  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
378 
379  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
380  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
381  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
382 
383  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
384  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
385  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
386 
387  mesh_.release_vertex_colors();
388 
389 }
390 
391 /*
392  * Load, save and load a simple obj
393  */
394 TEST_F(OpenMeshReadWriteOBJ, ReadWriteReadSimpleOBJ) {
395 
396  mesh_.clear();
397  mesh_.request_vertex_normals();
398 
399  OpenMesh::IO::Options options;
401  bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal.obj", options);
402 
403  EXPECT_TRUE(ok) << "Unable to load cube-minimal.obj";
404 
405  options.clear();
407  const char* filename = "cube-minimal_openmeshOutputTestfile.obj";
408  ok = OpenMesh::IO::write_mesh(mesh_, filename, options);
409 
410  mesh_.release_vertex_normals();
411  ASSERT_TRUE(ok) << "Unable to write obj mesh";
412 
413  Mesh mesh2;
414  mesh2.request_vertex_normals();
415 
416  options.clear();
417 
419  ok = OpenMesh::IO::read_mesh(mesh2, filename, options);
420  remove(filename);
421  ASSERT_TRUE(ok) << "Unable to read written mesh";
422 
423  EXPECT_EQ(8u , mesh2.n_vertices()) << "The number of loaded vertices is not correct!";
424  EXPECT_EQ(18u , mesh2.n_edges()) << "The number of loaded edges is not correct!";
425  EXPECT_EQ(12u , mesh2.n_faces()) << "The number of loaded faces is not correct!";
426 
428  //check vertex normals
429  EXPECT_EQ(0, mesh2.normal(mesh2.vertex_handle(0))[0] ) << "Wrong vertex normal at vertex 0 component 0";
430  EXPECT_EQ(-1, mesh2.normal(mesh2.vertex_handle(0))[1] ) << "Wrong vertex normal at vertex 0 component 1";
431  EXPECT_EQ(0, mesh2.normal(mesh2.vertex_handle(0))[2] ) << "Wrong vertex normal at vertex 0 component 2";
432 
433  EXPECT_EQ(0, mesh2.normal(mesh2.vertex_handle(3))[0] ) << "Wrong vertex normal at vertex 3 component 0";
434  EXPECT_EQ(0, mesh2.normal(mesh2.vertex_handle(3))[1] ) << "Wrong vertex normal at vertex 3 component 1";
435  EXPECT_EQ(1, mesh2.normal(mesh2.vertex_handle(3))[2] ) << "Wrong vertex normal at vertex 3 component 2";
436 
437  EXPECT_EQ(0, mesh2.normal(mesh2.vertex_handle(4))[0] ) << "Wrong vertex normal at vertex 4 component 0";
438  EXPECT_EQ(-1, mesh2.normal(mesh2.vertex_handle(4))[1] ) << "Wrong vertex normal at vertex 4 component 1";
439  EXPECT_EQ(0, mesh2.normal(mesh2.vertex_handle(4))[2] ) << "Wrong vertex normal at vertex 4 component 2";
440 
441  EXPECT_EQ(0, mesh2.normal(mesh2.vertex_handle(7))[0] ) << "Wrong vertex normal at vertex 7 component 0";
442  EXPECT_EQ(0, mesh2.normal(mesh2.vertex_handle(7))[1] ) << "Wrong vertex normal at vertex 7 component 1";
443  EXPECT_EQ(1, mesh2.normal(mesh2.vertex_handle(7))[2] ) << "Wrong vertex normal at vertex 7 component 2";
444 
445 }
446 }
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Definition: MeshIO.hh:104
Has (r) / store (w) vertex normals.
Definition: Options.hh:109
Has (r) / store (w) face colors.
Definition: Options.hh:114
bool is_valid() const
The handle is valid iff the index is not equal to -1.
Definition: Handles.hh:77
Set options for reader/writer modules.
Definition: Options.hh:95
Has (r) / store (w) face texture coordinates.
Definition: Options.hh:115
Handle for a face entity.
Definition: Handles.hh:146
void clear(void)
Clear all bits.
Definition: Options.hh:151
Has (r) / store (w) vertex colors.
Definition: Options.hh:110
bool write_mesh(const Mesh &_mesh, const std::string &_filename, Options _opt=Options::Default, std::streamsize _precision=6)
Write a mesh to the file _filename.
Definition: MeshIO.hh:199