Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
unittests_read_write_OM.cc
1 #include <gtest/gtest.h>
2 #include <Unittests/unittests_common.hh>
3
4
5 namespace {
6
7 class OpenMeshReadWriteOM : public OpenMeshBase {
8
9 protected:
10
11 // This function is called before each test is run
12 virtual void SetUp() {
13
14 // Do some initial stuff with the member data here...
15 }
16
17 // This function is called after all tests are through
18 virtual void TearDown() {
19
20 // Do some final stuff with the member data here...
21 }
22
23 // Member already defined in OpenMeshBase
24 //Mesh mesh_;
25 };
26
27 /*
28 * ====================================================================
29 * Define tests below
30 * ====================================================================
31 */
32
33 /*
34 * Just load an om file and set vertex color option before loading
35 */
36 TEST_F(OpenMeshReadWriteOM, LoadSimpleOMForceVertexColorsAlthoughNotAvailable) {
37
38 mesh_.clear();
39
40 mesh_.request_vertex_colors();
41
42 std::string file_name = "cube-minimal.om";
43
44 OpenMesh::IO::Options options;
45 options += OpenMesh::IO::Options::VertexColor;
46
47 bool ok = OpenMesh::IO::read_mesh(mesh_, file_name,options);
48
49 EXPECT_TRUE(ok) << file_name;
50
51 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
52 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
53 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
54 EXPECT_EQ(36u , mesh_.n_halfedges()) << "The number of loaded halfedges is not correct!";
55
56 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
57 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
58 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!";
59 }
60
61 /*
62 * Just load an om file of a cube with vertex texCoords
63 */
64 TEST_F(OpenMeshReadWriteOM, LoadSimpleOMWithTexCoords) {
65
66 mesh_.clear();
67
68 mesh_.request_vertex_texcoords2D();
69
70 OpenMesh::IO::Options options;
71 options += OpenMesh::IO::Options::VertexTexCoord;
72
73 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-texCoords.om",options);
74
75 EXPECT_TRUE(ok) << "Unable to load cube-minimal-texCoords.om";
76
77 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
78 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
79 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
80
81 EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
82 EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
83
84 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[0] ) << "Wrong vertex color at vertex 2 component 0";
85 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[1] ) << "Wrong vertex color at vertex 2 component 1";
86
87 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
88 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
89
90 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
91 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
92
93
94 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
95 EXPECT_TRUE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
96 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!";
97
98 mesh_.release_vertex_texcoords2D();
99 }
100
101 /*
102 * Just load an om file of a cube with vertex colors
103 */
104 TEST_F(OpenMeshReadWriteOM, LoadSimpleOMWithVertexColors) {
105
106 mesh_.clear();
107
108 mesh_.request_vertex_colors();
109
110 OpenMesh::IO::Options options;
111 options += OpenMesh::IO::Options::VertexColor;
112
113 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-vertexColors.om",options);
114
115 EXPECT_TRUE(ok) << "Unable to load cube-minimal-vertexColors.om";
116
117 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
118 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
119 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
120
121 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
122 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
123 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
124
125 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
126 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
127 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
128
129 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
130 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
131 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
132
133 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
134 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
135 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
136
137 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
138 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
139 EXPECT_TRUE(options.vertex_has_color()) << "Wrong user options are returned!";
140
141 mesh_.release_vertex_colors();
142 }
143
144 /*
145 * Save and load simple mesh
146 */
147 TEST_F(OpenMeshReadWriteOM, WriteTriangle) {
148
149 Mesh mesh;
150 mesh.clear();
151
152 const std::string filename = "triangle-minimal.om";
153
154 // generate data
155 Mesh::VertexHandle v1 = mesh.add_vertex(Mesh::Point(1.0,0.0,0.0));
156 Mesh::VertexHandle v2 = mesh.add_vertex(Mesh::Point(0.0,1.0,0.0));
157 Mesh::VertexHandle v3 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0));
158 mesh.add_face(v1,v2,v3);
159
160 // save
161 bool ok = OpenMesh::IO::write_mesh(mesh,filename);
162 EXPECT_TRUE(ok) << "Unable to write " << filename;
163
164 // reset
165 mesh.clear();
166
167 // load
168 ok = OpenMesh::IO::read_mesh(mesh,filename);
169 EXPECT_TRUE(ok) << "Unable to read " << filename;
170
171 // compare
172 EXPECT_EQ(3u , mesh.n_vertices()) << "The number of loaded vertices is not correct!";
173 EXPECT_EQ(3u , mesh.n_edges()) << "The number of loaded edges is not correct!";
174 EXPECT_EQ(1u , mesh.n_faces()) << "The number of loaded faces is not correct!";
175
176 EXPECT_EQ(Mesh::Point(1.0,0.0,0.0) , mesh.point(v1)) << "Wrong coordinates at vertex 0";
177 EXPECT_EQ(Mesh::Point(0.0,1.0,0.0) , mesh.point(v2)) << "Wrong coordinates at vertex 1";
178 EXPECT_EQ(Mesh::Point(0.0,0.0,1.0) , mesh.point(v3)) << "Wrong coordinates at vertex 2";
179
180 // cleanup
181 remove(filename.c_str());
182
183 }
184
185 /*
186 * Save and load simple mesh with integer colors per vertex
187 */
188 TEST_F(OpenMeshReadWriteOM, WriteTriangleVertexIntegerColor) {
189
190 Mesh mesh;
191
192 mesh.request_vertex_colors();
193
194 OpenMesh::IO::Options options;
195 options += OpenMesh::IO::Options::VertexColor;
196 options -= OpenMesh::IO::Options::ColorFloat;
197
198 const std::string filename = "triangle-minimal-ColorsPerVertex.om";
199
200 // generate data
201 Mesh::VertexHandle v1 = mesh.add_vertex(Mesh::Point(1.0,0.0,0.0));
202 Mesh::VertexHandle v2 = mesh.add_vertex(Mesh::Point(0.0,1.0,0.0));
203 Mesh::VertexHandle v3 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0));
204 mesh.add_face(v1,v2,v3);
205
206 Mesh::Color c1 = Mesh::Color(0,0,123),
207 c2 = Mesh::Color(21,0,0),
208 c3 = Mesh::Color(0,222,0);
209
210 mesh.set_color(v1,c1);
211 mesh.set_color(v2,c2);
212 mesh.set_color(v3,c3);
213
214 // save
215 bool ok = OpenMesh::IO::write_mesh(mesh,filename,options);
216 EXPECT_TRUE(ok) << "Unable to write "<<filename;
217
218 mesh.release_vertex_colors();
219
220 // load
221 Mesh cmpMesh;
222 cmpMesh.request_vertex_colors();
223 ok = OpenMesh::IO::read_mesh(cmpMesh,filename,options);
224 EXPECT_TRUE(ok) << "Unable to read "<<filename;
225
226 EXPECT_TRUE(cmpMesh.has_vertex_colors()) << "Loaded mesh has no vertex colors.";
227
228 // compare
229 EXPECT_EQ(3u , cmpMesh.n_vertices()) << "The number of loaded vertices is not correct!";
230 EXPECT_EQ(3u , cmpMesh.n_edges()) << "The number of loaded edges is not correct!";
231 EXPECT_EQ(1u , cmpMesh.n_faces()) << "The number of loaded faces is not correct!";
232
233 EXPECT_EQ(Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) << "Wrong coordinates at vertex 0";
234 EXPECT_EQ(Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) << "Wrong coordinates at vertex 1";
235 EXPECT_EQ(Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) << "Wrong coordinates at vertex 2";
236
237 EXPECT_EQ(c1 , cmpMesh.color(v1)) << "Wrong colors at vertex 0";
238 EXPECT_EQ(c2 , cmpMesh.color(v2)) << "Wrong colors at vertex 1";
239 EXPECT_EQ(c3 , cmpMesh.color(v3)) << "Wrong colors at vertex 2";
240
241 //clean up
242 cmpMesh.release_vertex_colors();
243 remove(filename.c_str());
244
245 }
246
247 /*
248 * Save and load simple mesh with custom property
249 */
250 TEST_F(OpenMeshReadWriteOM, WriteTriangleVertexBoolProperty) {
251
252 Mesh mesh;
253
254 const std::string filename = "triangle-minimal-VBProp.om";
255
256 // generate data
257 Mesh::VertexHandle v1 = mesh.add_vertex(Mesh::Point(1.0,0.0,0.0));
258 Mesh::VertexHandle v2 = mesh.add_vertex(Mesh::Point(0.0,1.0,0.0));
259 Mesh::VertexHandle v3 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0));
260 mesh.add_face(v1,v2,v3);
261
262 OpenMesh::VPropHandleT<bool> prop;
263 mesh.add_property(prop,"VBProp");
264 mesh.property(prop).set_persistent(true);
265
266 mesh.property(prop,v1) = true;
267 mesh.property(prop,v2) = false;
268 mesh.property(prop,v3) = true;
269
270 // save
271 bool ok = OpenMesh::IO::write_mesh(mesh,filename);
272 EXPECT_TRUE(ok) << "Unable to write "<<filename;
273
274 // load
275 Mesh cmpMesh;
276
277
278 cmpMesh.add_property(prop,"VBProp");
279 cmpMesh.property(prop).set_persistent(true);
280
281 ok = OpenMesh::IO::read_mesh(cmpMesh,filename);
282 EXPECT_TRUE(ok) << "Unable to read "<<filename;
283
284 // compare
285 EXPECT_EQ(3u , cmpMesh.n_vertices()) << "The number of loaded vertices is not correct!";
286 EXPECT_EQ(3u , cmpMesh.n_edges()) << "The number of loaded edges is not correct!";
287 EXPECT_EQ(1u , cmpMesh.n_faces()) << "The number of loaded faces is not correct!";
288
289 EXPECT_EQ(Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) << "Wrong coordinates at vertex 0";
290 EXPECT_EQ(Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) << "Wrong coordinates at vertex 1";
291 EXPECT_EQ(Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) << "Wrong coordinates at vertex 2";
292
293 EXPECT_TRUE(cmpMesh.property(prop,v1)) << "Wrong Property value at vertex 0";
294 EXPECT_FALSE(cmpMesh.property(prop,v2)) << "Wrong Property value at vertex 1";
295 EXPECT_TRUE(cmpMesh.property(prop,v3)) << "Wrong Property value at vertex 2";
296
297 // cleanup
298 remove(filename.c_str());
299
300 }
301
302 /*
303 * Save and load simple mesh with custom property
304 */
305 TEST_F(OpenMeshReadWriteOM, WriteTriangleVertexBoolPropertySpaceEquivalent) {
306
307 Mesh mesh;
308
309 const std::string filename = "triangle-minimal-VBProp-pattern-test.om";
310
311 // generate data
312 Mesh::VertexHandle v1 = mesh.add_vertex(Mesh::Point(1.0,0.0,0.0));
313 Mesh::VertexHandle v2 = mesh.add_vertex(Mesh::Point(0.0,1.0,0.0));
314 Mesh::VertexHandle v3 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0));
315 mesh.add_face(v1,v2,v3);
316
317 Mesh::VertexHandle v4 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0));
318 Mesh::VertexHandle v5 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0));
319 Mesh::VertexHandle v6 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0));
320 mesh.add_face(v4,v5,v6);
321
322 Mesh::VertexHandle v7 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0));
323 Mesh::VertexHandle v8 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0));
324 Mesh::VertexHandle v9 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0));
325
326 OpenMesh::VPropHandleT<bool> prop;
327 mesh.add_property(prop,"VBProp");
328 mesh.property(prop).set_persistent(true);
329
330 // Create a 0x20 hex pattern in the bitset
331 mesh.property(prop,v1) = false;
332 mesh.property(prop,v2) = false;
333 mesh.property(prop,v3) = false;
334 mesh.property(prop,v4) = false;
335 mesh.property(prop,v5) = false;
336 mesh.property(prop,v6) = true;
337 mesh.property(prop,v7) = false;
338 mesh.property(prop,v8) = false;
339 mesh.property(prop,v9) = true;
340
341 // save
342 bool ok = OpenMesh::IO::write_mesh(mesh,filename);
343 EXPECT_TRUE(ok) << "Unable to write "<<filename;
344
345 // load
346 Mesh cmpMesh;
347
348 cmpMesh.add_property(prop,"VBProp");
349 cmpMesh.property(prop).set_persistent(true);
350
351 ok = OpenMesh::IO::read_mesh(cmpMesh,filename);
352 EXPECT_TRUE(ok) << "Unable to read "<<filename;
353
354 // compare
355 EXPECT_EQ(9u , cmpMesh.n_vertices()) << "The number of loaded vertices is not correct!";
356 EXPECT_EQ(6u , cmpMesh.n_edges()) << "The number of loaded edges is not correct!";
357 EXPECT_EQ(2u , cmpMesh.n_faces()) << "The number of loaded faces is not correct!";
358
359 EXPECT_FALSE(cmpMesh.property(prop,v1)) << "Wrong Property value at vertex 0";
360 EXPECT_FALSE(cmpMesh.property(prop,v2)) << "Wrong Property value at vertex 1";
361 EXPECT_FALSE(cmpMesh.property(prop,v3)) << "Wrong Property value at vertex 2";
362 EXPECT_FALSE(cmpMesh.property(prop,v4)) << "Wrong Property value at vertex 3";
363 EXPECT_FALSE(cmpMesh.property(prop,v5)) << "Wrong Property value at vertex 4";
364 EXPECT_TRUE(cmpMesh.property(prop,v6)) << "Wrong Property value at vertex 5";
365 EXPECT_FALSE(cmpMesh.property(prop,v7)) << "Wrong Property value at vertex 6";
366 EXPECT_FALSE(cmpMesh.property(prop,v8)) << "Wrong Property value at vertex 7";
367 EXPECT_TRUE(cmpMesh.property(prop,v9)) << "Wrong Property value at vertex 8";
368
369 // cleanup
370 remove(filename.c_str());
371
372 }
373
374 /*
375 * Save and load simple mesh with multiple custom property
376 */
377 TEST_F(OpenMeshReadWriteOM, WriteTriangleTwoVertexBoolProperty) {
378
379 Mesh mesh;
380
381 const std::string filename = "triangle-minimal-VBProp.om";
382
383 // generate data
384 Mesh::VertexHandle v1 = mesh.add_vertex(Mesh::Point(1.0,0.0,0.0));
385 Mesh::VertexHandle v2 = mesh.add_vertex(Mesh::Point(0.0,1.0,0.0));
386 Mesh::VertexHandle v3 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0));
387 mesh.add_face(v1,v2,v3);
388
389 OpenMesh::VPropHandleT<bool> prop;
390 mesh.add_property(prop,"VBProp");
391 mesh.property(prop).set_persistent(true);
392
393 mesh.property(prop,v1) = true;
394 mesh.property(prop,v2) = false;
395 mesh.property(prop,v3) = true;
396
397 OpenMesh::VPropHandleT<bool> prop2;
398 mesh.add_property(prop2,"VBProp2");
399 mesh.property(prop2).set_persistent(true);
400
401 mesh.property(prop2,v1) = false;
402 mesh.property(prop2,v2) = false;
403 mesh.property(prop2,v3) = false;
404
405 // save
406 bool ok = OpenMesh::IO::write_mesh(mesh,filename);
407 EXPECT_TRUE(ok) << "Unable to write "<<filename;
408
409
410 // load
411 Mesh cmpMesh;
412 cmpMesh.add_property(prop,"VBProp");
413 cmpMesh.property(prop).set_persistent(true);
414
415 cmpMesh.add_property(prop2,"VBProp2");
416 cmpMesh.property(prop2).set_persistent(true);
417
418 ok = OpenMesh::IO::read_mesh(cmpMesh,filename);
419 EXPECT_TRUE(ok) << "Unable to read "<<filename;
420
421 // compare
422 EXPECT_EQ(3u , cmpMesh.n_vertices()) << "The number of loaded vertices is not correct!";
423 EXPECT_EQ(3u , cmpMesh.n_edges()) << "The number of loaded edges is not correct!";
424 EXPECT_EQ(1u , cmpMesh.n_faces()) << "The number of loaded faces is not correct!";
425
426 EXPECT_EQ(Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) << "Wrong coordinates at vertex 0";
427 EXPECT_EQ(Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) << "Wrong coordinates at vertex 1";
428 EXPECT_EQ(Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) << "Wrong coordinates at vertex 2";
429
430 EXPECT_TRUE(cmpMesh.property(prop,v1)) << "Wrong Property value at vertex 0";
431 EXPECT_FALSE(cmpMesh.property(prop,v2)) << "Wrong Property value at vertex 1";
432 EXPECT_TRUE(cmpMesh.property(prop,v3)) << "Wrong Property value at vertex 2";
433
434 EXPECT_FALSE(cmpMesh.property(prop2,v1)) << "Wrong second Property value at vertex 0";
435 EXPECT_FALSE(cmpMesh.property(prop2,v2)) << "Wrong second Property value at vertex 1";
436 EXPECT_FALSE(cmpMesh.property(prop2,v3)) << "Wrong second Property value at vertex 2";
437
438 // cleanup
439 remove(filename.c_str());
440
441 }
442
443 /*
444 * Save and load simple mesh with custom property
445 */
446 TEST_F(OpenMeshReadWriteOM, WriteTriangleEdgeIntProperty) {
447
448 Mesh mesh;
449
450 const std::string propName = "EIProp";
451 const std::string filename = std::string("triangle-minimal-")+propName+".om";
452
453 // generate data
454 Mesh::VertexHandle v1 = mesh.add_vertex(Mesh::Point(1.0,0.0,0.0));
455 Mesh::VertexHandle v2 = mesh.add_vertex(Mesh::Point(0.0,1.0,0.0));
456 Mesh::VertexHandle v3 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0));
457 mesh.add_face(v1,v2,v3);
458
459 OpenMesh::EPropHandleT<int> prop;
460 mesh.add_property(prop,propName);
461 mesh.property(prop).set_persistent(true);
462
463 Mesh::EdgeHandle e1 = Mesh::EdgeHandle(0);
464 Mesh::EdgeHandle e2 = Mesh::EdgeHandle(1);
465 Mesh::EdgeHandle e3 = Mesh::EdgeHandle(2);
466
467 int va1ue1 = 10,
468 value2 = 21,
469 value3 = 32;
470
471 mesh.property(prop,e1) = va1ue1;
472 mesh.property(prop,e2) = value2;
473 mesh.property(prop,e3) = value3;
474
475 // save
476 bool ok = OpenMesh::IO::write_mesh(mesh,filename);
477 EXPECT_TRUE(ok) << "Unable to write "<<filename;
478
479 // load
480 Mesh cmpMesh;
481
482 cmpMesh.add_property(prop,propName);
483 cmpMesh.property(prop).set_persistent(true);
484
485 ok = OpenMesh::IO::read_mesh(cmpMesh,filename);
486 EXPECT_TRUE(ok) << "Unable to read "<<filename;
487
488 // compare
489 EXPECT_EQ(3u , cmpMesh.n_vertices()) << "The number of loaded vertices is not correct!";
490 EXPECT_EQ(3u , cmpMesh.n_edges()) << "The number of loaded edges is not correct!";
491 EXPECT_EQ(1u , cmpMesh.n_faces()) << "The number of loaded faces is not correct!";
492
493 EXPECT_EQ(Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) << "Wrong coordinates at vertex 0";
494 EXPECT_EQ(Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) << "Wrong coordinates at vertex 1";
495 EXPECT_EQ(Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) << "Wrong coordinates at vertex 2";
496
497 EXPECT_EQ(va1ue1 , cmpMesh.property(prop,e1)) << "Wrong property at edge 0";
498 EXPECT_EQ(value2 , cmpMesh.property(prop,e2)) << "Wrong property at edge 1";
499 EXPECT_EQ(value3 , cmpMesh.property(prop,e3)) << "Wrong property at edge 2";
500
501 // cleanup
502 remove(filename.c_str());
503
504 }
505
506 /*
507 * Save and load simple mesh with custom property
508 */
509 TEST_F(OpenMeshReadWriteOM, WriteTriangleFaceDoubleProperty) {
510
511 Mesh mesh;
512
513 const std::string propName = "FDProp";
514 const std::string filename = std::string("triangle-minimal-")+propName+".om";
515
516 // generate data
517 Mesh::VertexHandle v1 = mesh.add_vertex(Mesh::Point(1.0,0.0,0.0));
518 Mesh::VertexHandle v2 = mesh.add_vertex(Mesh::Point(0.0,1.0,0.0));
519 Mesh::VertexHandle v3 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0));
520 mesh.add_face(v1,v2,v3);
521
522 OpenMesh::FPropHandleT<double> prop;
523 mesh.add_property(prop,propName);
524 mesh.property(prop).set_persistent(true);
525
526 Mesh::FaceHandle f1 = Mesh::FaceHandle(0);
527
528 double va1ue1 = 0.5;
529
530 mesh.property(prop,f1) = va1ue1;
531
532 // save
533 bool ok = OpenMesh::IO::write_mesh(mesh,filename);
534 EXPECT_TRUE(ok) << "Unable to write "<<filename;
535
536 // load
537 Mesh cmpMesh;
538
539 cmpMesh.add_property(prop,propName);
540 cmpMesh.property(prop).set_persistent(true);
541
542 ok = OpenMesh::IO::read_mesh(cmpMesh,filename);
543 EXPECT_TRUE(ok) << "Unable to read "<<filename;
544
545 // compare
546 EXPECT_EQ(3u , cmpMesh.n_vertices()) << "The number of loaded vertices is not correct!";
547 EXPECT_EQ(3u , cmpMesh.n_edges()) << "The number of loaded edges is not correct!";
548 EXPECT_EQ(1u , cmpMesh.n_faces()) << "The number of loaded faces is not correct!";
549
550 EXPECT_EQ(Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) << "Wrong coordinates at vertex 0";
551 EXPECT_EQ(Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) << "Wrong coordinates at vertex 1";
552 EXPECT_EQ(Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) << "Wrong coordinates at vertex 2";
553
554 EXPECT_EQ(va1ue1 , cmpMesh.property(prop,f1)) << "Wrong property at edge 0";
555
556 // cleanup
557 remove(filename.c_str());
558
559 }
560
561 /*
562 * Save and load simple mesh with custom property
563 */
564 TEST_F(OpenMeshReadWriteOM, WriteTriangleFaceFloatProperty) {
565
566 const std::string propName = "FFProp";
567 const std::string filename = std::string("triangle-minimal-")+propName+".om";
568
569 // generate data
570 Mesh mesh;
571 Mesh::VertexHandle v1 = mesh.add_vertex(Mesh::Point(1.0,0.0,0.0));
572 Mesh::VertexHandle v2 = mesh.add_vertex(Mesh::Point(0.0,1.0,0.0));
573 Mesh::VertexHandle v3 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0));
574 mesh.add_face(v1,v2,v3);
575
576 OpenMesh::FPropHandleT<float> prop;
577 mesh.add_property(prop,propName);
578 mesh.property(prop).set_persistent(true);
579
580 Mesh::FaceHandle f1 = Mesh::FaceHandle(0);
581
582 float va1ue1 = 3.1f;
583
584 mesh.property(prop,f1) = va1ue1;
585
586 // save
587 bool ok = OpenMesh::IO::write_mesh(mesh,filename);
588 EXPECT_TRUE(ok) << "Unable to write "<<filename;
589
590
591 // load
592 Mesh cmpMesh;
593 cmpMesh.add_property(prop,propName);
594 cmpMesh.property(prop).set_persistent(true);
595
596 ok = OpenMesh::IO::read_mesh(cmpMesh,filename);
597 EXPECT_TRUE(ok) << "Unable to read "<<filename;
598
599 // compare
600 EXPECT_EQ(3u , cmpMesh.n_vertices()) << "The number of loaded vertices is not correct!";
601 EXPECT_EQ(3u , cmpMesh.n_edges()) << "The number of loaded edges is not correct!";
602 EXPECT_EQ(1u , cmpMesh.n_faces()) << "The number of loaded faces is not correct!";
603
604 EXPECT_EQ(Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) << "Wrong coordinates at vertex 0";
605 EXPECT_EQ(Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) << "Wrong coordinates at vertex 1";
606 EXPECT_EQ(Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) << "Wrong coordinates at vertex 2";
607
608 EXPECT_EQ(va1ue1 , cmpMesh.property(prop,f1)) << "Wrong property at edge 0";
609
610 // cleanup
611 remove(filename.c_str());
612
613 }
614
615 /*
616 * Save and load simple mesh with custom property
617 */
618 TEST_F(OpenMeshReadWriteOM, ReadBigMeshWithCustomProperty) {
619
620 OpenMesh::FPropHandleT<double> faceProp;
621 OpenMesh::VPropHandleT<int> vertexProp;
622 bool ok;
623
624 //generate file
625 /* mesh_.clear();
626 ok = OpenMesh::IO::read_mesh(mesh_,"cube1.off");
627
628 mesh_.add_property(faceProp,"DFProp");
629 mesh_.property(faceProp).set_persistent(true);
630
631 mesh_.add_property(vertexProp, "IVProp");
632 mesh_.property(vertexProp).set_persistent(true);
633
634
635 for (Mesh::FaceIter fIter = mesh_.faces_begin(); fIter != mesh_.faces_end(); ++fIter)
636 mesh_.property(faceProp,*fIter) = 0.3;
637
638 for (Mesh::VertexIter vIter = mesh_.vertices_begin(); vIter != mesh_.vertices_end(); ++vIter)
639 mesh_.property(vertexProp,*vIter) = vIter->idx();
640
641 OpenMesh::IO::write_mesh(mesh_,"cube1_customProps.om");
642
643
644 mesh_.clear();
645 */
646 //read file
647 Mesh mesh;
648 mesh.add_property(faceProp,"DFProp");
649 mesh.property(faceProp).set_persistent(true);
650
651 mesh.add_property(vertexProp, "IVProp");
652 mesh.property(vertexProp).set_persistent(true);
653
654 ok = OpenMesh::IO::read_mesh(mesh,"cube1_customProps.om");
655 EXPECT_TRUE(ok) << "Unable to read cube1_customProps.om";
656
658 EXPECT_EQ(7526u , mesh.n_vertices()) << "The number of loaded vertices is not correct!";
659 EXPECT_EQ(22572u, mesh.n_edges()) << "The number of loaded edges is not correct!";
660 EXPECT_EQ(15048u, mesh.n_faces()) << "The number of loaded faces is not correct!";
661
662 bool wrong = false;
663 for (Mesh::FaceIter fIter = mesh.faces_begin(); fIter != mesh.faces_end() && !wrong; ++fIter)
664 wrong = (0.3 != mesh.property(faceProp,*fIter));
665 EXPECT_FALSE(wrong) << "min one face has wrong face property";
666
667 wrong = false;
668 for (Mesh::VertexIter vIter = mesh.vertices_begin(); vIter != mesh.vertices_end() && !wrong; ++vIter)
669 wrong = (vIter->idx() != mesh.property(vertexProp,*vIter));
670 EXPECT_FALSE(wrong) << "min one vertex has worng vertex property";
671 }
672
673 }
OpenMesh::IO::read_mesh
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Definition: MeshIO.hh:104
OpenMesh::PolyMeshT::Color
Kernel::Color Color
Color type.
Definition: PolyMeshT.hh:119
OpenMeshBase
Definition: unittests_common.hh:21
OpenMesh::PolyMeshT::Point
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:115
OpenMesh::PolyMeshT::add_vertex
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:236
OpenMesh::EPropHandleT
Definition: Property.hh:515
OpenMesh::TriMesh_ArrayKernelT
Definition: TriMesh_ArrayKernelT.hh:98
OpenMesh::IO::Options::VertexTexCoord
Has (r) / store (w) texture coordinates.
Definition: Options.hh:111
OpenMesh::IO::Options
Set options for reader/writer modules.
Definition: Options.hh:95
OpenMesh::VPropHandleT< bool >
OpenMesh::IO::Options::ColorFloat
Has (r) / store (w) float values for colors (currently only implemented for PLY and OFF files) ...
Definition: Options.hh:117
OpenMesh::PolyMeshT::VertexHandle
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:139
OpenMesh::FPropHandleT
Definition: Property.hh:529
OpenMesh::IO::Options::VertexColor
Has (r) / store (w) vertex colors.
Definition: Options.hh:110
OpenMesh::IO::write_mesh
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