Developer Documentation
Loading...
Searching...
No Matches
unittests_read_write_PLY.cc
1#include <gtest/gtest.h>
2#include <Unittests/unittests_common.hh>
3
4
5namespace {
6
7class OpenMeshReadWritePLY : 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
27struct CustomTraits3f : public OpenMesh::DefaultTraits {
28 typedef OpenMesh::Vec3f Color;
29};
30
32
33class OpenMeshReadWritePLYColorVec3f : public testing::Test {
34
35 protected:
36
37 // This function is called before each test is run
38 virtual void SetUp() {
39
40 // Do some initial stuff with the member data here...
41 }
42
43 // This function is called after all tests are through
44 virtual void TearDown() {
45
46 // Do some final stuff with the member data here...
47 }
48
49 // This member will be accessible in all tests
50 Mesh3f mesh_;
51};
52
53/*
54 * ====================================================================
55 * Define tests below
56 * ====================================================================
57 */
58
59/*
60 * Just load a point file in ply format and count whether
61 * the right number of entities has been loaded.
62 */
63TEST_F(OpenMeshReadWritePLY, LoadSimplePointPLYFileWithBadEncoding) {
64
65 mesh_.clear();
66
67 bool ok = OpenMesh::IO::read_mesh(mesh_, "pointCloudBadEncoding.ply");
68
69 EXPECT_TRUE(ok) << "Unable to load pointCloudBadEncoding.ply";
70
71 EXPECT_EQ(10u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
72 EXPECT_EQ(0u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
73 EXPECT_EQ(0u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
74}
75
76/*
77 * Just load a point file in ply format and count whether
78 * the right number of entities has been loaded.
79 */
80TEST_F(OpenMeshReadWritePLY, LoadSimplePointPLYFileWithGoodEncoding) {
81
82 mesh_.clear();
83
84 bool ok = OpenMesh::IO::read_mesh(mesh_, "pointCloudGoodEncoding.ply");
85
86 EXPECT_TRUE(ok) << "Unable to load pointCloudGoodEncoding.ply";
87
88 EXPECT_EQ(10u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
89 EXPECT_EQ(0u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
90 EXPECT_EQ(0u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
91}
92
93/*
94 * Just load a ply
95 */
96TEST_F(OpenMeshReadWritePLY, LoadSimplePLY) {
97
98 mesh_.clear();
99
100 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal.ply");
101
102 EXPECT_TRUE(ok) << "Unable to load cube-minimal.ply";
103
104 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
105 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
106 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
107
108}
109
110/*
111 * Load a ply ascii file without a newline at the end of the file
112 *
113 */
114TEST_F(OpenMeshReadWritePLY, LoadSimplePLYNoEndl) {
115
116 mesh_.clear();
117
118 bool ok = OpenMesh::IO::read_mesh(mesh_, "sphere840.ply");
119
120 EXPECT_TRUE(ok) << "Unable to load sphere840.ply";
121
122 EXPECT_EQ(422u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
123 EXPECT_EQ(1260u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
124 EXPECT_EQ(840u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
125
126}
127
128/*
129 * Just load a ply file and set vertex color option before loading
130 */
131TEST_F(OpenMeshReadWritePLY, LoadSimplePLYForceVertexColorsAlthoughNotAvailable) {
132
133 mesh_.clear();
134
135 mesh_.request_vertex_colors();
136
137 std::string file_name = "cube-minimal.ply";
138
139 OpenMesh::IO::Options options;
141
142 bool ok = OpenMesh::IO::read_mesh(mesh_, file_name,options);
143
144 EXPECT_TRUE(ok) << file_name;
145
146 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
147 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
148 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
149 EXPECT_EQ(36u , mesh_.n_halfedges()) << "The number of loaded halfedges is not correct!";
150
151 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
152 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
153 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!";
154}
155
156/*
157 * Just load a ply file of a cube with vertex colors
158 */
159TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithVertexColors) {
160
161 mesh_.clear();
162
163 mesh_.request_vertex_colors();
164
165 OpenMesh::IO::Options options;
167
168 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-vertexColors.ply",options);
169
170 EXPECT_TRUE(ok) << "Unable to load cube-minimal-vertexColors.ply";
171
172 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
173 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
174 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
175
176#ifdef TEST_DOUBLE_TRAITS
177 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
178 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
179 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
180
181 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
182 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
183 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
184
185 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
186 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
187 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
188
189 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
190 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
191 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
192#else
193 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
194 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
195 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
196
197 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
198 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
199 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
200
201 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
202 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
203 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
204
205 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
206 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
207 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
208#endif
209
210 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
211 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
212 EXPECT_TRUE(options.vertex_has_color()) << "Wrong user options are returned!";
213
214 mesh_.release_vertex_colors();
215}
216
217/*
218 * Just load a ply file of a cube with vertex colors
219 */
220TEST_F(OpenMeshReadWritePLY, LoadPLYFromMeshLabWithVertexColors) {
221
222 mesh_.clear();
223
224 mesh_.request_vertex_colors();
225
226 OpenMesh::IO::Options options;
228
229 bool ok = OpenMesh::IO::read_mesh(mesh_, "meshlab.ply",options);
230
231 EXPECT_TRUE(ok) << "Unable to load meshlab.ply";
232
233 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
234 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
235 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
236
237#ifdef TEST_DOUBLE_TRAITS
238 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
239 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
240 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
241
242 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
243 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
244 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
245
246 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
247 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
248 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
249
250 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
251 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
252 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
253#else
254 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
255 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
256 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
257
258 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
259 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
260 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
261
262 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
263 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
264 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
265
266 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
267 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
268 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
269#endif
270
271 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
272 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
273 EXPECT_TRUE(options.vertex_has_color()) << "Wrong user options are returned!";
274
275 mesh_.release_vertex_colors();
276}
277
278/*
279 * Just read and write a binary ply file of a cube with vertex colors
280 */
281TEST_F(OpenMeshReadWritePLY, WriteAndReadBinaryPLYWithVertexColors) {
282
283 mesh_.clear();
284
285 mesh_.request_vertex_colors();
286
287 OpenMesh::IO::Options options;
289
290 bool ok = OpenMesh::IO::read_mesh(mesh_, "meshlab.ply",options);
291
292 EXPECT_TRUE(ok) << "Unable to load meshlab.ply";
293
295
296 ok = OpenMesh::IO::write_mesh(mesh_, "meshlab_binary.ply",options);
297 EXPECT_TRUE(ok) << "Unable to write meshlab_binary.ply";
298
299 mesh_.clear();
300 ok = OpenMesh::IO::read_mesh(mesh_, "meshlab_binary.ply",options);
301 EXPECT_TRUE(ok) << "Unable to load meshlab_binary.ply";
302
303 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
304 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
305 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
306
307#ifdef TEST_DOUBLE_TRAITS
308 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
309 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
310 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
311
312 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
313 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
314 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
315
316 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
317 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
318 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
319
320 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
321 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
322 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
323#else
324 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
325 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
326 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
327
328 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
329 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
330 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
331
332 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
333 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
334 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
335
336 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
337 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
338 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
339#endif
340
341 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
342 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
343 EXPECT_TRUE(options.vertex_has_color()) << "Wrong user options are returned!";
344
345 mesh_.release_vertex_colors();
346}
347
348/*
349 * Just read and write a ply file of a cube with float vertex colors
350 */
351TEST_F(OpenMeshReadWritePLY, WriteAndReadPLYWithFloatVertexColors) {
352
353 mesh_.clear();
354
355 mesh_.request_vertex_colors();
356
357 OpenMesh::IO::Options options;
359
360 bool ok = OpenMesh::IO::read_mesh(mesh_, "meshlab.ply",options);
361
362 EXPECT_TRUE(ok) << "Unable to load meshlab.ply";
363
365
366 ok = OpenMesh::IO::write_mesh(mesh_, "meshlab_float.ply",options);
367 EXPECT_TRUE(ok) << "Unable to write meshlab_float.ply";
368
369 mesh_.clear();
370 ok = OpenMesh::IO::read_mesh(mesh_, "meshlab_float.ply",options);
371 EXPECT_TRUE(ok) << "Unable to load meshlab_float.ply";
372
373 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
374 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
375 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
376
377#ifdef TEST_DOUBLE_TRAITS
378 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
379 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
380 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
381
382 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
383 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
384 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
385
386 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
387 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
388 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
389
390 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
391 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
392 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
393#else
394 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
395 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
396 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
397
398 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
399 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
400 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
401
402 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
403 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
404 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
405
406 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
407 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
408 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
409#endif
410
411 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
412 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
413 EXPECT_TRUE(options.vertex_has_color()) << "Wrong user options are returned!";
414 EXPECT_TRUE(options.color_is_float()) << "Wrong user options are returned!";
415
416 mesh_.release_vertex_colors();
417}
418
419/*
420 * Just read and write a binary ply file of a cube with float vertex colors
421 */
422TEST_F(OpenMeshReadWritePLY, WriteAndReadBinaryPLYWithFloatVertexColors) {
423
424 mesh_.clear();
425
426 mesh_.request_vertex_colors();
427
428 OpenMesh::IO::Options options;
430
431 bool ok = OpenMesh::IO::read_mesh(mesh_, "meshlab.ply",options);
432
433 EXPECT_TRUE(ok) << "Unable to load meshlab.ply";
434
437
438 ok = OpenMesh::IO::write_mesh(mesh_, "meshlab_binary_float.ply",options);
439 EXPECT_TRUE(ok) << "Unable to write meshlab_binary_float.ply";
440
441 mesh_.clear();
442 ok = OpenMesh::IO::read_mesh(mesh_, "meshlab_binary_float.ply",options);
443 EXPECT_TRUE(ok) << "Unable to load meshlab_binary_float.ply";
444
445 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
446 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
447 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
448
449#ifdef TEST_DOUBLE_TRAITS
450 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
451 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
452 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
453
454 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
455 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
456 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
457
458 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
459 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
460 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
461
462 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
463 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
464 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
465#else
466 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
467 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
468 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
469
470 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
471 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
472 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
473
474 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
475 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
476 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
477
478 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
479 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
480 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
481#endif
482
483 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
484 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
485 EXPECT_TRUE(options.vertex_has_color()) << "Wrong user options are returned!";
486 EXPECT_TRUE(options.color_is_float()) << "Wrong user options are returned!";
487 EXPECT_TRUE(options.is_binary()) << "Wrong user options are returned!";
488
489 mesh_.release_vertex_colors();
490}
491
492/*
493 * Just load a ply file of a cube with face texcoord and face texture index
494 */
495TEST_F(OpenMeshReadWritePLY, LoadPLYFromMeshLabWithFaceTexCoord) {
496
497 mesh_.clear();
498
499 mesh_.request_halfedge_texcoords2D();
500 mesh_.request_face_texture_index();
501
502 OpenMesh::IO::Options options;
504
505 std::string file_name = "meshlab-faceTexCoords.ply";
506
507 bool ok = OpenMesh::IO::read_mesh(mesh_, file_name, options);
508
509 EXPECT_TRUE(ok) << "Unable to load meshlab-faceTexCoords.ply";
510
511 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
512 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
513 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
514
515 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
516 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
517 EXPECT_TRUE(options.face_has_texcoord()) << "Wrong user options are returned!";
518
519 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(0))[0] ) << "Wrong texCoord at halfedge 0 component 0";
520 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(0))[1] ) << "Wrong texCoord at halfedge 0 component 1";
521 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(1))[0] ) << "Wrong texCoord at halfedge 1 component 0";
522 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(1))[1] ) << "Wrong texCoord at halfedge 1 component 1";
523 EXPECT_FLOAT_EQ(0.2, mesh_.texcoord2D(mesh_.halfedge_handle(2))[0] ) << "Wrong texCoord at halfedge 2 component 0";
524 EXPECT_FLOAT_EQ(0.2, mesh_.texcoord2D(mesh_.halfedge_handle(2))[1] ) << "Wrong texCoord at halfedge 2 component 1";
525 EXPECT_FLOAT_EQ(-0.2, mesh_.texcoord2D(mesh_.halfedge_handle(3))[0] ) << "Wrong texCoord at halfedge 3 component 0";
526 EXPECT_FLOAT_EQ(-0.2, mesh_.texcoord2D(mesh_.halfedge_handle(3))[1] ) << "Wrong texCoord at halfedge 3 component 1";
527 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(4))[0] ) << "Wrong texCoord at halfedge 4 component 0";
528 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(4))[1] ) << "Wrong texCoord at halfedge 4 component 1";
529 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(5))[0] ) << "Wrong texCoord at halfedge 5 component 0";
530 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(5))[1] ) << "Wrong texCoord at halfedge 5 component 1";
531 EXPECT_FLOAT_EQ(-0.1, mesh_.texcoord2D(mesh_.halfedge_handle(6))[0] ) << "Wrong texCoord at halfedge 6 component 0";
532 EXPECT_FLOAT_EQ(-0.1, mesh_.texcoord2D(mesh_.halfedge_handle(6))[1] ) << "Wrong texCoord at halfedge 6 component 1";
533 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(7))[0] ) << "Wrong texCoord at halfedge 7 component 0";
534 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(7))[1] ) << "Wrong texCoord at halfedge 7 component 1";
535 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(8))[0] ) << "Wrong texCoord at halfedge 8 component 0";
536 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(8))[1] ) << "Wrong texCoord at halfedge 8 component 1";
537 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(9))[0] ) << "Wrong texCoord at halfedge 9 component 0";
538 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(9))[1] ) << "Wrong texCoord at halfedge 9 component 1";
539 EXPECT_FLOAT_EQ(0.2, mesh_.texcoord2D(mesh_.halfedge_handle(10))[0] ) << "Wrong texCoord at halfedge 10 component 0";
540 EXPECT_FLOAT_EQ(0.3, mesh_.texcoord2D(mesh_.halfedge_handle(10))[1] ) << "Wrong texCoord at halfedge 10 component 1";
541 EXPECT_FLOAT_EQ(0.2, mesh_.texcoord2D(mesh_.halfedge_handle(11))[0] ) << "Wrong texCoord at halfedge 11 component 0";
542 EXPECT_FLOAT_EQ(0.2, mesh_.texcoord2D(mesh_.halfedge_handle(11))[1] ) << "Wrong texCoord at halfedge 11 component 1";
543 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(12))[0] ) << "Wrong texCoord at halfedge 12 component 0";
544 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(12))[1] ) << "Wrong texCoord at halfedge 12 component 1";
545 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(13))[0] ) << "Wrong texCoord at halfedge 13 component 0";
546 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(13))[1] ) << "Wrong texCoord at halfedge 13 component 1";
547 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(14))[0] ) << "Wrong texCoord at halfedge 14 component 0";
548 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(14))[1] ) << "Wrong texCoord at halfedge 14 component 1";
549 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(15))[0] ) << "Wrong texCoord at halfedge 15 component 0";
550 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(15))[1] ) << "Wrong texCoord at halfedge 15 component 1";
551 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(16))[0] ) << "Wrong texCoord at halfedge 16 component 0";
552 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(16))[1] ) << "Wrong texCoord at halfedge 16 component 1";
553 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(17))[0] ) << "Wrong texCoord at halfedge 17 component 0";
554 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(17))[1] ) << "Wrong texCoord at halfedge 17 component 1";
555
556 //check texture mapping for the mesh
558 mesh_.get_property_handle(property, "TextureMapping");
559 EXPECT_EQ(mesh_.property(property).size(), 2u) << "Wrong texture number";
560 EXPECT_EQ(mesh_.property(property).count(0), 1u) << "Could not find texture with id 0";
561 EXPECT_TRUE((mesh_.property(property)[0] == std::string("tex_0.jpg"))) << "Wrong texture name";
562 EXPECT_EQ(mesh_.property(property).count(1), 1u) << "Could not find texture with id 1";
563 EXPECT_TRUE((mesh_.property(property)[1] == std::string("tex_1.jpg"))) << "Wrong texture name";
564
565 //check texture mapping per face
566 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(0)), 0) << "Face 0 texture index is not set correctly";
567 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(1)), 0) << "Face 1 texture index is not set correctly";
568 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(2)), 1) << "Face 2 texture index is not set correctly";
569 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(3)), 1) << "Face 3 texture index is not set correctly";
570 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(4)), 1) << "Face 4 texture index is not set correctly";
571 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(5)), 1) << "Face 5 texture index is not set correctly";
572 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(6)), 0) << "Face 6 texture index is not set correctly";
573 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(7)), 0) << "Face 7 texture index is not set correctly";
574 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(8)), 0) << "Face 8 texture index is not set correctly";
575 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(9)), 0) << "Face 9 texture index is not set correctly";
576 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(10)), 0) << "Face 10 texture index is not set correctly";
577 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(11)), 0) << "Face 11 texture index is not set correctly";
578
579 mesh_.release_halfedge_texcoords2D();
580 mesh_.release_face_texture_index();
581
582}
583
584/*
585 * Just load a binary ply file of a cube with face texcoord and face texture index
586 */
587TEST_F(OpenMeshReadWritePLY, LoadBinaryPLYFromMeshLabWithFaceTexCoord) {
588
589 mesh_.clear();
590
591 mesh_.request_halfedge_texcoords2D();
592 mesh_.request_face_texture_index();
593
594 OpenMesh::IO::Options options;
597
598 std::string file_name = "meshlab-faceTexCoords-binary.ply";
599
600 bool ok = OpenMesh::IO::read_mesh(mesh_, file_name, options);
601
602 EXPECT_TRUE(ok) << "Unable to load meshlab-faceTexCoords-binary.ply";
603
604 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
605 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
606 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
607
608 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
609 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
610 EXPECT_TRUE(options.face_has_texcoord()) << "Wrong user options are returned!";
611
612 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(0))[0] ) << "Wrong texCoord at halfedge 0 component 0";
613 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(0))[1] ) << "Wrong texCoord at halfedge 0 component 1";
614 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(1))[0] ) << "Wrong texCoord at halfedge 1 component 0";
615 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(1))[1] ) << "Wrong texCoord at halfedge 1 component 1";
616 EXPECT_FLOAT_EQ(0.2, mesh_.texcoord2D(mesh_.halfedge_handle(2))[0] ) << "Wrong texCoord at halfedge 2 component 0";
617 EXPECT_FLOAT_EQ(0.2, mesh_.texcoord2D(mesh_.halfedge_handle(2))[1] ) << "Wrong texCoord at halfedge 2 component 1";
618 EXPECT_FLOAT_EQ(-0.2, mesh_.texcoord2D(mesh_.halfedge_handle(3))[0] ) << "Wrong texCoord at halfedge 3 component 0";
619 EXPECT_FLOAT_EQ(-0.2, mesh_.texcoord2D(mesh_.halfedge_handle(3))[1] ) << "Wrong texCoord at halfedge 3 component 1";
620 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(4))[0] ) << "Wrong texCoord at halfedge 4 component 0";
621 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(4))[1] ) << "Wrong texCoord at halfedge 4 component 1";
622 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(5))[0] ) << "Wrong texCoord at halfedge 5 component 0";
623 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(5))[1] ) << "Wrong texCoord at halfedge 5 component 1";
624 EXPECT_FLOAT_EQ(-0.1, mesh_.texcoord2D(mesh_.halfedge_handle(6))[0] ) << "Wrong texCoord at halfedge 6 component 0";
625 EXPECT_FLOAT_EQ(-0.1, mesh_.texcoord2D(mesh_.halfedge_handle(6))[1] ) << "Wrong texCoord at halfedge 6 component 1";
626 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(7))[0] ) << "Wrong texCoord at halfedge 7 component 0";
627 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(7))[1] ) << "Wrong texCoord at halfedge 7 component 1";
628 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(8))[0] ) << "Wrong texCoord at halfedge 8 component 0";
629 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(8))[1] ) << "Wrong texCoord at halfedge 8 component 1";
630 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(9))[0] ) << "Wrong texCoord at halfedge 9 component 0";
631 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(9))[1] ) << "Wrong texCoord at halfedge 9 component 1";
632 EXPECT_FLOAT_EQ(0.2, mesh_.texcoord2D(mesh_.halfedge_handle(10))[0] ) << "Wrong texCoord at halfedge 10 component 0";
633 EXPECT_FLOAT_EQ(0.3, mesh_.texcoord2D(mesh_.halfedge_handle(10))[1] ) << "Wrong texCoord at halfedge 10 component 1";
634 EXPECT_FLOAT_EQ(0.2, mesh_.texcoord2D(mesh_.halfedge_handle(11))[0] ) << "Wrong texCoord at halfedge 11 component 0";
635 EXPECT_FLOAT_EQ(0.2, mesh_.texcoord2D(mesh_.halfedge_handle(11))[1] ) << "Wrong texCoord at halfedge 11 component 1";
636 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(12))[0] ) << "Wrong texCoord at halfedge 12 component 0";
637 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(12))[1] ) << "Wrong texCoord at halfedge 12 component 1";
638 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(13))[0] ) << "Wrong texCoord at halfedge 13 component 0";
639 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(13))[1] ) << "Wrong texCoord at halfedge 13 component 1";
640 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(14))[0] ) << "Wrong texCoord at halfedge 14 component 0";
641 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(14))[1] ) << "Wrong texCoord at halfedge 14 component 1";
642 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(15))[0] ) << "Wrong texCoord at halfedge 15 component 0";
643 EXPECT_FLOAT_EQ(0.1, mesh_.texcoord2D(mesh_.halfedge_handle(15))[1] ) << "Wrong texCoord at halfedge 15 component 1";
644 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(16))[0] ) << "Wrong texCoord at halfedge 16 component 0";
645 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(16))[1] ) << "Wrong texCoord at halfedge 16 component 1";
646 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(17))[0] ) << "Wrong texCoord at halfedge 17 component 0";
647 EXPECT_FLOAT_EQ(0, mesh_.texcoord2D(mesh_.halfedge_handle(17))[1] ) << "Wrong texCoord at halfedge 17 component 1";
648
649 //check texture mapping for the mesh
651 mesh_.get_property_handle(property, "TextureMapping");
652 EXPECT_EQ(mesh_.property(property).size(), 2u) << "Wrong texture number";
653 EXPECT_EQ(mesh_.property(property).count(0), 1u) << "Could not find texture with id 0";
654 EXPECT_TRUE((mesh_.property(property)[0] == std::string("tex_0.jpg"))) << "Wrong texture name";
655 EXPECT_EQ(mesh_.property(property).count(1), 1u) << "Could not find texture with id 1";
656 EXPECT_TRUE((mesh_.property(property)[1] == std::string("tex_1.jpg"))) << "Wrong texture name";
657
658 //check texture mapping per face
659 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(0)), 0) << "Face 0 texture index is not set correctly";
660 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(1)), 0) << "Face 1 texture index is not set correctly";
661 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(2)), 1) << "Face 2 texture index is not set correctly";
662 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(3)), 1) << "Face 3 texture index is not set correctly";
663 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(4)), 1) << "Face 4 texture index is not set correctly";
664 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(5)), 1) << "Face 5 texture index is not set correctly";
665 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(6)), 0) << "Face 6 texture index is not set correctly";
666 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(7)), 0) << "Face 7 texture index is not set correctly";
667 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(8)), 0) << "Face 8 texture index is not set correctly";
668 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(9)), 0) << "Face 9 texture index is not set correctly";
669 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(10)), 0) << "Face 10 texture index is not set correctly";
670 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(), mesh_.face_handle(11)), 0) << "Face 11 texture index is not set correctly";
671
672 mesh_.release_halfedge_texcoords2D();
673 mesh_.release_face_texture_index();
674
675}
676
677/*
678 * Just load a ply file of a cube with vertex texCoords
679 */
680TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithTexCoords) {
681
682 mesh_.clear();
683
684 mesh_.request_vertex_texcoords2D();
685
686 OpenMesh::IO::Options options;
688
689 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-texCoords.ply",options);
690
691 EXPECT_TRUE(ok) << "Unable to load cube-minimal-texCoords.ply";
692
693 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
694 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
695 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
696
697 EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
698 EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
699
700 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[0] ) << "Wrong vertex color at vertex 2 component 0";
701 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[1] ) << "Wrong vertex color at vertex 2 component 1";
702
703 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
704 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
705
706 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
707 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
708
709
710 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
711 EXPECT_TRUE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
712 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!";
713
714 mesh_.release_vertex_texcoords2D();
715}
716
717/*
718 * Just load a ply with normals, ascii mode
719 */
720TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithNormals) {
721
722 mesh_.clear();
723
724 mesh_.request_vertex_normals();
725
726 OpenMesh::IO::Options options;
728
729 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-normals.ply", options);
730
731 EXPECT_TRUE(ok) << "Unable to load cube-minimal-normals.ply";
732
733 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
734 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
735 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
736
737 EXPECT_TRUE(options.vertex_has_normal()) << "Wrong user options are returned!";
738 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
739 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!";
740
741
742 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[0] ) << "Wrong normal at vertex 0 component 0";
743 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[1] ) << "Wrong normal at vertex 0 component 1";
744 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(0))[2] ) << "Wrong normal at vertex 0 component 2";
745
746 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(3))[0] ) << "Wrong normal at vertex 3 component 0";
747 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(3))[1] ) << "Wrong normal at vertex 3 component 1";
748 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(3))[2] ) << "Wrong normal at vertex 3 component 2";
749
750 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(4))[0] ) << "Wrong normal at vertex 4 component 0";
751 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(4))[1] ) << "Wrong normal at vertex 4 component 1";
752 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(4))[2] ) << "Wrong normal at vertex 4 component 2";
753
754 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(7))[0] ) << "Wrong normal at vertex 7 component 0";
755 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(7))[1] ) << "Wrong normal at vertex 7 component 1";
756 EXPECT_EQ(2, mesh_.normal(mesh_.vertex_handle(7))[2] ) << "Wrong normal at vertex 7 component 2";
757
758 mesh_.release_vertex_normals();
759
760}
761
762/*
763 * Just load a ply with custom properties, ascii mode
764 */
765TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithCustomProps) {
766
767 PolyMesh mesh;
768
769 OpenMesh::IO::Options options;
771
772 bool ok = OpenMesh::IO::read_mesh(mesh, "cube-minimal-custom_props.ply", options);
773
774 EXPECT_TRUE(ok) << "Unable to load cube-minimal-custom_props.ply";
775
776 EXPECT_EQ(8u , mesh.n_vertices()) << "The number of loaded vertices is not correct!";
777 EXPECT_EQ(12u , mesh.n_edges()) << "The number of loaded edges is not correct!";
778 EXPECT_EQ(6u , mesh.n_faces()) << "The number of loaded faces is not correct!";
779
782 ASSERT_TRUE(mesh.get_property_handle(qualityProp,"quality")) << "Could not access quality property";
783 ASSERT_TRUE(mesh.get_property_handle(indexProp,"index")) << "Could not access index property";
784
785 //check index property
786 for (unsigned i = 0; i < mesh.n_vertices(); ++i)
787 EXPECT_EQ(i ,mesh.property(indexProp,OpenMesh::VertexHandle(i))) << "Vertex index at vertex " << i << " is wrong";
788
789 //check quality property
790 EXPECT_EQ(1.f,mesh.property(qualityProp,OpenMesh::VertexHandle(0))) << "Wrong quality value at Vertex 0";
791 EXPECT_EQ(0.5f,mesh.property(qualityProp,OpenMesh::VertexHandle(1))) << "Wrong quality value at Vertex 1";
792 EXPECT_EQ(0.7f,mesh.property(qualityProp,OpenMesh::VertexHandle(2))) << "Wrong quality value at Vertex 2";
793 EXPECT_EQ(1.f,mesh.property(qualityProp,OpenMesh::VertexHandle(3))) << "Wrong quality value at Vertex 3";
794 EXPECT_EQ(0.1f,mesh.property(qualityProp,OpenMesh::VertexHandle(4))) << "Wrong quality value at Vertex 4";
795 EXPECT_EQ(0.f,mesh.property(qualityProp,OpenMesh::VertexHandle(5))) << "Wrong quality value at Vertex 5";
796 EXPECT_EQ(2.f,mesh.property(qualityProp,OpenMesh::VertexHandle(6))) << "Wrong quality value at Vertex 6";
797 EXPECT_EQ(5.f,mesh.property(qualityProp,OpenMesh::VertexHandle(7))) << "Wrong quality value at Vertex 7";
798
799 //check for custom list properties
800
802 ASSERT_TRUE(mesh.get_property_handle(testValues,"test_values")) << "Could not access texcoords per face";
803
804 EXPECT_EQ(2u,mesh.property(testValues,OpenMesh::VertexHandle(0)).size()) << "Wrong verctor size";
805
806 EXPECT_EQ(1,mesh.property(testValues,OpenMesh::VertexHandle(0))[0]) << "Wrong list value at Vertex 0";
807 EXPECT_EQ(4,mesh.property(testValues,OpenMesh::VertexHandle(1))[1]) << "Wrong list value at Vertex 1";
808 EXPECT_EQ(5,mesh.property(testValues,OpenMesh::VertexHandle(2))[0]) << "Wrong list value at Vertex 2";
809 EXPECT_EQ(8,mesh.property(testValues,OpenMesh::VertexHandle(3))[1]) << "Wrong list value at Vertex 3";
810 EXPECT_EQ(9,mesh.property(testValues,OpenMesh::VertexHandle(4))[0]) << "Wrong list value at Vertex 4";
811 EXPECT_EQ(12,mesh.property(testValues,OpenMesh::VertexHandle(5))[1]) << "Wrong list value at Vertex 5";
812 EXPECT_EQ(13,mesh.property(testValues,OpenMesh::VertexHandle(6))[0]) << "Wrong list value at Vertex 6";
813 EXPECT_EQ(16,mesh.property(testValues,OpenMesh::VertexHandle(7))[1]) << "Wrong list value at Vertex 7";
814
816 ASSERT_TRUE(mesh.get_property_handle(texCoordsPerFace,"texcoords")) << "Could not access texcoords per face";
817
818 for (Mesh::FaceIter f_iter = mesh.faces_begin(); f_iter != mesh.faces_end(); ++f_iter)
819 {
820 EXPECT_EQ(8u, mesh.property(texCoordsPerFace, *f_iter).size()) << "Texcoords per face container has wrong size on face: " << f_iter->idx();
821 if (!mesh.property(texCoordsPerFace, *f_iter).empty())
822 {
823 EXPECT_EQ(1.0, mesh.property(texCoordsPerFace, *f_iter)[0]) << "Texcoords wrong on index 0 with face: " << f_iter->idx();
824 EXPECT_EQ(1.0, mesh.property(texCoordsPerFace, *f_iter)[1]) << "Texcoords wrong on index 1 with face: " << f_iter->idx();
825 EXPECT_EQ(-1.0f, mesh.property(texCoordsPerFace, *f_iter)[2]) << "Texcoords wrong on index 2 with face: " << f_iter->idx();
826 EXPECT_EQ(-1.0f, mesh.property(texCoordsPerFace, *f_iter)[3]) << "Texcoords wrong on index 3 with face: " << f_iter->idx();
827 EXPECT_EQ(0.0f, mesh.property(texCoordsPerFace, *f_iter)[4]) << "Texcoords wrong on index 4 with face: " << f_iter->idx();
828 EXPECT_EQ(0.0f, mesh.property(texCoordsPerFace, *f_iter)[5]) << "Texcoords wrong on index 5 with face: " << f_iter->idx();
829 EXPECT_EQ(-0.5f, mesh.property(texCoordsPerFace, *f_iter)[6]) << "Texcoords wrong on index 6 with face: " << f_iter->idx();
830 EXPECT_EQ(-0.5f, mesh.property(texCoordsPerFace, *f_iter)[7]) << "Texcoords wrong on index 7 with face: " << f_iter->idx();
831 }
832
833 }
834
836 ASSERT_TRUE(mesh.get_property_handle(faceIndex,"faceIndex")) << "Could not access faceIndex per face";
837
838 EXPECT_EQ(0u,mesh.property(faceIndex,OpenMesh::FaceHandle(0))) << "Wrong index value at FaceHandle 0";
839 EXPECT_EQ(1u,mesh.property(faceIndex,OpenMesh::FaceHandle(1))) << "Wrong index value at FaceHandle 1";
840 EXPECT_EQ(2u,mesh.property(faceIndex,OpenMesh::FaceHandle(2))) << "Wrong index value at FaceHandle 2";
841 EXPECT_EQ(3u,mesh.property(faceIndex,OpenMesh::FaceHandle(3))) << "Wrong index value at FaceHandle 3";
842 EXPECT_EQ(4u,mesh.property(faceIndex,OpenMesh::FaceHandle(4))) << "Wrong index value at FaceHandle 4";
843 EXPECT_EQ(5u,mesh.property(faceIndex,OpenMesh::FaceHandle(5))) << "Wrong index value at FaceHandle 5";
844
845}
846
847/*
848 * Just load a ply with custom properties, binary mode
849 */
850TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithCustomPropsBinary) {
851
852 PolyMesh mesh;
853
854 OpenMesh::IO::Options options;
857
858 bool ok = OpenMesh::IO::read_mesh(mesh, "cube-minimal-custom_props-binary.ply", options);
859
860 EXPECT_TRUE(ok) << "Unable to load cube-minimal-custom_props.ply";
861
862 EXPECT_EQ(8u , mesh.n_vertices()) << "The number of loaded vertices is not correct!";
863 EXPECT_EQ(12u , mesh.n_edges()) << "The number of loaded edges is not correct!";
864 EXPECT_EQ(6u , mesh.n_faces()) << "The number of loaded faces is not correct!";
865
868 ASSERT_TRUE(mesh.get_property_handle(qualityProp,"quality")) << "Could not access quality property";
869 ASSERT_TRUE(mesh.get_property_handle(indexProp,"index")) << "Could not access index property";
870
871 //check index property
872 for (unsigned i = 0; i < mesh.n_vertices(); ++i)
873 EXPECT_EQ(i ,mesh.property(indexProp,OpenMesh::VertexHandle(i))) << "Vertex index at vertex " << i << " is wrong";
874
875 //check quality property
876 EXPECT_EQ(1.f,mesh.property(qualityProp,OpenMesh::VertexHandle(0))) << "Wrong quality value at Vertex 0";
877 EXPECT_EQ(0.5f,mesh.property(qualityProp,OpenMesh::VertexHandle(1))) << "Wrong quality value at Vertex 1";
878 EXPECT_EQ(0.7f,mesh.property(qualityProp,OpenMesh::VertexHandle(2))) << "Wrong quality value at Vertex 2";
879 EXPECT_EQ(1.f,mesh.property(qualityProp,OpenMesh::VertexHandle(3))) << "Wrong quality value at Vertex 3";
880 EXPECT_EQ(0.1f,mesh.property(qualityProp,OpenMesh::VertexHandle(4))) << "Wrong quality value at Vertex 4";
881 EXPECT_EQ(0.f,mesh.property(qualityProp,OpenMesh::VertexHandle(5))) << "Wrong quality value at Vertex 5";
882 EXPECT_EQ(2.f,mesh.property(qualityProp,OpenMesh::VertexHandle(6))) << "Wrong quality value at Vertex 6";
883 EXPECT_EQ(5.f,mesh.property(qualityProp,OpenMesh::VertexHandle(7))) << "Wrong quality value at Vertex 7";
884
885 //check for custom list properties
886
888 ASSERT_TRUE(mesh.get_property_handle(testValues,"test_values")) << "Could not access texcoords per face";
889
890 EXPECT_EQ(2u,mesh.property(testValues,OpenMesh::VertexHandle(0)).size()) << "Wrong verctor size";
891
892 EXPECT_EQ(1,mesh.property(testValues,OpenMesh::VertexHandle(0))[0]) << "Wrong list value at Vertex 0";
893 EXPECT_EQ(4,mesh.property(testValues,OpenMesh::VertexHandle(1))[1]) << "Wrong list value at Vertex 1";
894 EXPECT_EQ(5,mesh.property(testValues,OpenMesh::VertexHandle(2))[0]) << "Wrong list value at Vertex 2";
895 EXPECT_EQ(8,mesh.property(testValues,OpenMesh::VertexHandle(3))[1]) << "Wrong list value at Vertex 3";
896 EXPECT_EQ(9,mesh.property(testValues,OpenMesh::VertexHandle(4))[0]) << "Wrong list value at Vertex 4";
897 EXPECT_EQ(12,mesh.property(testValues,OpenMesh::VertexHandle(5))[1]) << "Wrong list value at Vertex 5";
898 EXPECT_EQ(13,mesh.property(testValues,OpenMesh::VertexHandle(6))[0]) << "Wrong list value at Vertex 6";
899 EXPECT_EQ(16,mesh.property(testValues,OpenMesh::VertexHandle(7))[1]) << "Wrong list value at Vertex 7";
900
902 ASSERT_TRUE(mesh.get_property_handle(texCoordsPerFace,"texcoords")) << "Could not access texcoords per face";
903
904 for (Mesh::FaceIter f_iter = mesh.faces_begin(); f_iter != mesh.faces_end(); ++f_iter)
905 {
906 EXPECT_EQ(8u, mesh.property(texCoordsPerFace, *f_iter).size()) << "Texcoords per face container has wrong size on face: " << f_iter->idx();
907 if (!mesh.property(texCoordsPerFace, *f_iter).empty())
908 {
909 EXPECT_EQ(1.0, mesh.property(texCoordsPerFace, *f_iter)[0]) << "Texcoords wrong on index 0 with face: " << f_iter->idx();
910 EXPECT_EQ(1.0, mesh.property(texCoordsPerFace, *f_iter)[1]) << "Texcoords wrong on index 1 with face: " << f_iter->idx();
911 EXPECT_EQ(-1.0f, mesh.property(texCoordsPerFace, *f_iter)[2]) << "Texcoords wrong on index 2 with face: " << f_iter->idx();
912 EXPECT_EQ(-1.0f, mesh.property(texCoordsPerFace, *f_iter)[3]) << "Texcoords wrong on index 3 with face: " << f_iter->idx();
913 EXPECT_EQ(0.0f, mesh.property(texCoordsPerFace, *f_iter)[4]) << "Texcoords wrong on index 4 with face: " << f_iter->idx();
914 EXPECT_EQ(0.0f, mesh.property(texCoordsPerFace, *f_iter)[5]) << "Texcoords wrong on index 5 with face: " << f_iter->idx();
915 EXPECT_EQ(-0.5f, mesh.property(texCoordsPerFace, *f_iter)[6]) << "Texcoords wrong on index 6 with face: " << f_iter->idx();
916 EXPECT_EQ(-0.5f, mesh.property(texCoordsPerFace, *f_iter)[7]) << "Texcoords wrong on index 7 with face: " << f_iter->idx();
917 }
918
919 }
920
922 ASSERT_TRUE(mesh.get_property_handle(faceIndex,"faceIndex")) << "Could not access faceIndex per face";
923
924 EXPECT_EQ(0u,mesh.property(faceIndex,OpenMesh::FaceHandle(0))) << "Wrong index value at FaceHandle 0";
925 EXPECT_EQ(1u,mesh.property(faceIndex,OpenMesh::FaceHandle(1))) << "Wrong index value at FaceHandle 1";
926 EXPECT_EQ(2u,mesh.property(faceIndex,OpenMesh::FaceHandle(2))) << "Wrong index value at FaceHandle 2";
927 EXPECT_EQ(3u,mesh.property(faceIndex,OpenMesh::FaceHandle(3))) << "Wrong index value at FaceHandle 3";
928 EXPECT_EQ(4u,mesh.property(faceIndex,OpenMesh::FaceHandle(4))) << "Wrong index value at FaceHandle 4";
929 EXPECT_EQ(5u,mesh.property(faceIndex,OpenMesh::FaceHandle(5))) << "Wrong index value at FaceHandle 5";
930
931}
932
933TEST_F(OpenMeshReadWritePLY, WriteReadSimplePLYWithCustomProps) {
934
935 PolyMesh mesh;
936
937 OpenMesh::IO::Options options;
938 bool ok = OpenMesh::IO::read_mesh(mesh, "cube-minimal.ply", options);
939
940
945 OpenMesh::VPropHandleT<int> removedProp;
946
947 const std::string indexPropName = "mySuperIndexProperty";
948 const std::string qualityPropName = "quality";
949 const std::string facePropName = "anotherPropForFaces";
950 const std::string nonPersistantName = "nonPersistant";
951 const std::string removedPropName = "willBeRemoved";
952
953 mesh.add_property(indexProp,indexPropName);
954 mesh.add_property(qualityProp,qualityPropName);
955 mesh.add_property(removedProp, removedPropName);
956 mesh.add_property(faceProp,facePropName);
957 mesh.add_property(nonPersistant,nonPersistantName);
958
959 mesh.property(indexProp).set_persistent(true);
960 mesh.property(qualityProp).set_persistent(true);
961 mesh.property(faceProp).set_persistent(true);
962 mesh.remove_property(removedProp);
963
964 signed char i=0;
965 for (Mesh::VertexIter v_iter = mesh.vertices_begin(); v_iter != mesh.vertices_end(); ++v_iter, ++i)
966 {
967 mesh.property(indexProp, *v_iter) = i;
968 mesh.property(qualityProp, *v_iter) = 3.5*i;
969 }
970
971 i = 0;
972 for (Mesh::FaceIter f_iter = mesh.faces_begin(); f_iter != mesh.faces_end(); ++f_iter, ++i)
973 {
974 mesh.property(faceProp, *f_iter) = -i;
975 }
976
977 const char* outFilename = "cube-minimal-customprops_openmeshOutputTestfile.ply";
978 ok = OpenMesh::IO::write_mesh(mesh, outFilename);
979
980 ASSERT_TRUE(ok);
981
982 PolyMesh loadedMesh;
983
984 EXPECT_FALSE(loadedMesh.get_property_handle(indexProp,indexPropName)) << "Could access to property which was deleted";
985
987 ok = OpenMesh::IO::read_mesh(loadedMesh, outFilename, options);
988
989 ASSERT_TRUE(ok);
990
991
992 ASSERT_TRUE(loadedMesh.get_property_handle(indexProp,indexPropName)) << "Could not access index property";
993 ASSERT_TRUE(loadedMesh.get_property_handle(qualityProp,qualityPropName)) << "Could not access quality property";
994 ASSERT_TRUE(loadedMesh.get_property_handle(faceProp,facePropName)) << "Could not access face property";
995 EXPECT_FALSE(loadedMesh.get_property_handle(nonPersistant,nonPersistantName)) << "Could access non persistant property";
996
997 i=0;
998 for (Mesh::VertexIter v_iter = loadedMesh.vertices_begin(); v_iter != loadedMesh.vertices_end(); ++v_iter, ++i)
999 {
1000 EXPECT_EQ(loadedMesh.property(indexProp, *v_iter), static_cast<unsigned>(i));
1001 EXPECT_EQ(loadedMesh.property(qualityProp, *v_iter),3.5*i);
1002 }
1003
1004 i = 0;
1005 for (Mesh::FaceIter f_iter = loadedMesh.faces_begin(); f_iter != loadedMesh.faces_end(); ++f_iter, ++i)
1006 {
1007 EXPECT_EQ(loadedMesh.property(faceProp, *f_iter),-i);
1008 }
1009
1010
1011 remove(outFilename);
1012
1013}
1014
1015TEST_F(OpenMeshReadWritePLY, WriteReadBinaryPLYWithCustomProps) {
1016
1017 PolyMesh mesh;
1018
1019 OpenMesh::IO::Options options;
1020 bool ok = OpenMesh::IO::read_mesh(mesh, "cube-minimal.ply", options);
1021
1022
1027 OpenMesh::VPropHandleT<int> removedProp;
1028
1029 const std::string indexPropName = "mySuperIndexProperty";
1030 const std::string qualityPropName = "quality";
1031 const std::string facePropName = "anotherPropForFaces";
1032 const std::string nonPersistantName = "nonPersistant";
1033 const std::string removedPropName = "willBeRemoved";
1034
1035 mesh.add_property(indexProp,indexPropName);
1036 mesh.add_property(qualityProp,qualityPropName);
1037 mesh.add_property(removedProp, removedPropName);
1038 mesh.add_property(faceProp,facePropName);
1039 mesh.add_property(nonPersistant,nonPersistantName);
1040
1041 mesh.property(indexProp).set_persistent(true);
1042 mesh.property(qualityProp).set_persistent(true);
1043 mesh.property(faceProp).set_persistent(true);
1044 mesh.remove_property(removedProp);
1045
1046 signed char i=0;
1047 for (Mesh::VertexIter v_iter = mesh.vertices_begin(); v_iter != mesh.vertices_end(); ++v_iter, ++i)
1048 {
1049 mesh.property(indexProp, *v_iter) = i;
1050 mesh.property(qualityProp, *v_iter) = 3.5*i;
1051 }
1052
1053 i = 0;
1054 for (Mesh::FaceIter f_iter = mesh.faces_begin(); f_iter != mesh.faces_end(); ++f_iter, ++i)
1055 {
1056 mesh.property(faceProp, *f_iter) = -i;
1057 }
1058
1059 const char* outFilename = "cube-minimal-customprops_openmeshOutputTestfileBinary.ply";
1061 ok = OpenMesh::IO::write_mesh(mesh, outFilename, options);
1062
1063 ASSERT_TRUE(ok);
1064
1065 PolyMesh loadedMesh;
1066
1067 EXPECT_FALSE(loadedMesh.get_property_handle(indexProp,indexPropName)) << "Could access to property which was deleted";
1068
1069 options.clear();
1072 ok = OpenMesh::IO::read_mesh(loadedMesh, outFilename, options);
1073
1074 ASSERT_TRUE(ok);
1075
1076
1077 ASSERT_TRUE(loadedMesh.get_property_handle(indexProp,indexPropName)) << "Could not access index property";
1078 ASSERT_TRUE(loadedMesh.get_property_handle(qualityProp,qualityPropName)) << "Could not access quality property";
1079 ASSERT_TRUE(loadedMesh.get_property_handle(faceProp,facePropName)) << "Could not access face property";
1080 EXPECT_FALSE(loadedMesh.get_property_handle(nonPersistant,nonPersistantName)) << "Could access non persistant property";
1081
1082 i=0;
1083 for (Mesh::VertexIter v_iter = loadedMesh.vertices_begin(); v_iter != loadedMesh.vertices_end(); ++v_iter, ++i)
1084 {
1085 EXPECT_EQ(loadedMesh.property(indexProp, *v_iter), static_cast<unsigned>(i));
1086 EXPECT_EQ(loadedMesh.property(qualityProp, *v_iter),3.5*i);
1087 }
1088
1089 i = 0;
1090 for (Mesh::FaceIter f_iter = loadedMesh.faces_begin(); f_iter != loadedMesh.faces_end(); ++f_iter, ++i)
1091 {
1092 EXPECT_EQ(loadedMesh.property(faceProp, *f_iter),-i);
1093 }
1094
1095
1096 //remove(outFilename);
1097
1098}
1099
1100/*
1101* Just load a ply with extra elements
1102*/
1103TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithExtraElements) {
1104
1105 mesh_.clear();
1106
1107 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-extra-elements.ply");
1108
1109 EXPECT_TRUE(ok) << "Unable to load cube-minimal-extra-elements.ply";
1110
1111 EXPECT_EQ(8u, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
1112 EXPECT_EQ(18u, mesh_.n_edges()) << "The number of loaded edges is not correct!";
1113 EXPECT_EQ(12u, mesh_.n_faces()) << "The number of loaded faces is not correct!";
1114
1115}
1116
1117/*
1118* Just load a binary ply with extra elements
1119*/
1120TEST_F(OpenMeshReadWritePLY, LoadSimpleBinaryPLYWithExtraElements) {
1121
1122 mesh_.clear();
1123
1125
1126 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-extra-elements-binary.ply", options);
1127
1128 EXPECT_TRUE(ok) << "Unable to load cube-minimal-extra-elements-binary.ply";
1129
1130 EXPECT_EQ(8u, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
1131 EXPECT_EQ(18u, mesh_.n_edges()) << "The number of loaded edges is not correct!";
1132 EXPECT_EQ(12u, mesh_.n_faces()) << "The number of loaded faces is not correct!";
1133
1134}
1135
1136/*
1137* Ignore a file that does not contain vertices and faces
1138*/
1139TEST_F(OpenMeshReadWritePLY, IgnoreNonMeshPlyFile) {
1140
1141 mesh_.clear();
1142
1143 std::stringstream data;
1144 data << "ply" << "\n";
1145 data << "format binary_little_endian 1.0" << "\n";
1146 data << "comment Image data" << "\n";
1147 data << "element image 0" << "\n";
1148 data << "property list uint16 uint16 row" << "\n";
1149 data << "end_header" << "\n";
1150
1152
1153 bool ok = OpenMesh::IO::read_mesh(mesh_, data, ".ply", options);
1154
1155 EXPECT_TRUE(ok) << "This empty file should be readable without an error!";
1156
1157 EXPECT_EQ(0u, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
1158 EXPECT_EQ(0u, mesh_.n_edges()) << "The number of loaded edges is not correct!";
1159 EXPECT_EQ(0u, mesh_.n_faces()) << "The number of loaded faces is not correct!";
1160}
1161
1162
1163/*
1164* Ignore a file that does not contain vertices and faces
1165*/
1166TEST_F(OpenMeshReadWritePLY, FailOnUnknownPropertyTypeForLists) {
1167
1168 mesh_.clear();
1169
1170 std::stringstream data;
1171 data << "ply" << "\n";
1172 data << "format binary_little_endian 1.0" << "\n";
1173 data << "comment Image data" << "\n";
1174 data << "element image 0" << "\n";
1175 data << "property list blibb blubb row" << "\n";
1176 data << "end_header" << "\n";
1177
1179
1180 bool ok = OpenMesh::IO::read_mesh(mesh_, data, ".ply", options);
1181
1182 EXPECT_FALSE(ok) << "This file should fail to read!";
1183
1184 EXPECT_EQ(0u, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
1185 EXPECT_EQ(0u, mesh_.n_edges()) << "The number of loaded edges is not correct!";
1186 EXPECT_EQ(0u, mesh_.n_faces()) << "The number of loaded faces is not correct!";
1187}
1188
1189/*
1190 * Load an ASCII PLY file of a cube with float RGB face colors
1191 */
1192TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithFaceColors) {
1193
1194 mesh_.clear();
1195
1196 mesh_.request_face_colors();
1197
1198 OpenMesh::IO::Options options;
1200
1201 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-faceColors.ply",options);
1202
1203 EXPECT_TRUE(ok) << "Unable to load cube-minimal-faceColors.ply";
1204
1205 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
1206 EXPECT_EQ(18u, mesh_.n_edges()) << "The number of loaded edges is not correct!";
1207 EXPECT_EQ(12u, mesh_.n_faces()) << "The number of loaded faces is not correct!";
1208
1209#ifdef TEST_DOUBLE_TRAITS
1210 EXPECT_FLOAT_EQ(107/255.0, mesh_.color(mesh_.face_handle(0))[0] ) << "Wrong face color at face 0";
1211 EXPECT_FLOAT_EQ(117/255.0, mesh_.color(mesh_.face_handle(0))[1] ) << "Wrong face color at face 0";
1212 EXPECT_FLOAT_EQ(177/255.0, mesh_.color(mesh_.face_handle(0))[2] ) << "Wrong face color at face 0";
1213
1214 EXPECT_FLOAT_EQ(107/255.0, mesh_.color(mesh_.face_handle(3))[0] ) << "Wrong face color at face 3";
1215 EXPECT_FLOAT_EQ(255/255.0, mesh_.color(mesh_.face_handle(3))[1] ) << "Wrong face color at face 3";
1216 EXPECT_FLOAT_EQ(135/255.0, mesh_.color(mesh_.face_handle(3))[2] ) << "Wrong face color at face 3";
1217
1218 EXPECT_FLOAT_EQ(163/255.0, mesh_.color(mesh_.face_handle(4))[0] ) << "Wrong face color at face 4";
1219 EXPECT_FLOAT_EQ(107/255.0, mesh_.color(mesh_.face_handle(4))[1] ) << "Wrong face color at face 4";
1220 EXPECT_FLOAT_EQ(177/255.0, mesh_.color(mesh_.face_handle(4))[2] ) << "Wrong face color at face 4";
1221
1222 EXPECT_FLOAT_EQ(255/255.0, mesh_.color(mesh_.face_handle(7))[0] ) << "Wrong face color at face 7";
1223 EXPECT_FLOAT_EQ(140/255.0, mesh_.color(mesh_.face_handle(7))[1] ) << "Wrong face color at face 7";
1224 EXPECT_FLOAT_EQ(107/255.0, mesh_.color(mesh_.face_handle(7))[2] ) << "Wrong face color at face 7";
1225#else
1226 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(0))[0] ) << "Wrong face color at face 0";
1227 EXPECT_EQ(117, mesh_.color(mesh_.face_handle(0))[1] ) << "Wrong face color at face 0";
1228 EXPECT_EQ(177, mesh_.color(mesh_.face_handle(0))[2] ) << "Wrong face color at face 0";
1229
1230 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(3))[0] ) << "Wrong face color at face 3";
1231 EXPECT_EQ(255, mesh_.color(mesh_.face_handle(3))[1] ) << "Wrong face color at face 3";
1232 EXPECT_EQ(135, mesh_.color(mesh_.face_handle(3))[2] ) << "Wrong face color at face 3";
1233
1234 EXPECT_EQ(163, mesh_.color(mesh_.face_handle(4))[0] ) << "Wrong face color at face 4";
1235 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(4))[1] ) << "Wrong face color at face 4";
1236 EXPECT_EQ(177, mesh_.color(mesh_.face_handle(4))[2] ) << "Wrong face color at face 4";
1237
1238 EXPECT_EQ(255, mesh_.color(mesh_.face_handle(7))[0] ) << "Wrong face color at face 7";
1239 EXPECT_EQ(140, mesh_.color(mesh_.face_handle(7))[1] ) << "Wrong face color at face 7";
1240 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(7))[2] ) << "Wrong face color at face 7";
1241#endif
1242
1243 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
1244 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
1245 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!";
1246 EXPECT_TRUE(options.face_has_color()) << "Wrong user options are returned!";
1247 EXPECT_FALSE(options.color_has_alpha()) << "Wrong user options are returned!";
1248 EXPECT_FALSE(options.is_binary()) << "Wrong user options are returned!";
1249
1250 mesh_.release_face_colors();
1251}
1252
1253/*
1254 * Write and read PLY files with face colors in various formats
1255 */
1256TEST_F(OpenMeshReadWritePLY, WriteAndReadPLYWithFaceColors) {
1257 struct Format {
1258 Format(const char* outFileName, OpenMesh::IO::Options options) :
1259 _outFileName(outFileName),
1260 _options(options)
1261 {}
1262 const char* _outFileName;
1263 const OpenMesh::IO::Options _options;
1264 }
1265 formats[] =
1266 {
1267 Format("cube-minimal-faceColors_ascii_uchar.ply",
1269 Format("cube-minimal-faceColors_ascii_float.ply",
1271 Format("cube-minimal-faceColors_binary_uchar.ply",
1273 Format("cube-minimal-faceColors_binary_float.ply",
1275 // Test writing/reading alpha values (all default 1.0/255), but the test mesh
1276 // Color type has no alpha channel so there's nothing to test below
1277 Format("cube-minimal-faceColors_alpha_ascii_uchar.ply",
1279 Format("cube-minimal-faceColors_alpha_ascii_float.ply",
1281 Format("cube-minimal-faceColors_alpha_binary_uchar.ply",
1283 Format("cube-minimal-faceColors_alpha_binary_float.ply",
1285 };
1286
1287 for (size_t i = 0; i < sizeof(formats) / sizeof(Format); ++i)
1288 {
1289 const char* outFileName = formats[i]._outFileName;
1290
1291 mesh_.clear();
1292
1293 mesh_.request_face_colors();
1294
1295 OpenMesh::IO::Options options;
1297
1298 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-faceColors.ply", options);
1299
1300 EXPECT_TRUE(ok) << "Unable to load cube-minimal-faceColors.ply";
1301
1302 options = formats[i]._options;
1304 ok = OpenMesh::IO::write_mesh(mesh_, outFileName, options);
1305 EXPECT_TRUE(ok) << "Unable to write " << outFileName;
1306
1307 // Reset for reading: let the reader determine binary/float/etc.
1309 mesh_.clear();
1310 ok = OpenMesh::IO::read_mesh(mesh_, outFileName, options);
1311 EXPECT_TRUE(ok) << "Unable to load " << outFileName;
1312
1313 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct: " << outFileName;
1314 EXPECT_EQ(18u, mesh_.n_edges()) << "The number of loaded edges is not correct: " << outFileName;
1315 EXPECT_EQ(12u, mesh_.n_faces()) << "The number of loaded faces is not correct: " << outFileName;
1316
1317#ifdef TEST_DOUBLE_TRAITS
1318 EXPECT_FLOAT_EQ(107/255.0, mesh_.color(mesh_.face_handle(0))[0] ) << "Wrong face color at face 0";
1319 EXPECT_FLOAT_EQ(117/255.0, mesh_.color(mesh_.face_handle(0))[1] ) << "Wrong face color at face 0";
1320 EXPECT_FLOAT_EQ(177/255.0, mesh_.color(mesh_.face_handle(0))[2] ) << "Wrong face color at face 0";
1321
1322 EXPECT_FLOAT_EQ(107/255.0, mesh_.color(mesh_.face_handle(3))[0] ) << "Wrong face color at face 3";
1323 EXPECT_FLOAT_EQ(255/255.0, mesh_.color(mesh_.face_handle(3))[1] ) << "Wrong face color at face 3";
1324 EXPECT_FLOAT_EQ(135/255.0, mesh_.color(mesh_.face_handle(3))[2] ) << "Wrong face color at face 3";
1325
1326 EXPECT_FLOAT_EQ(163/255.0, mesh_.color(mesh_.face_handle(4))[0] ) << "Wrong face color at face 4";
1327 EXPECT_FLOAT_EQ(107/255.0, mesh_.color(mesh_.face_handle(4))[1] ) << "Wrong face color at face 4";
1328 EXPECT_FLOAT_EQ(177/255.0, mesh_.color(mesh_.face_handle(4))[2] ) << "Wrong face color at face 4";
1329
1330 EXPECT_FLOAT_EQ(255/255.0, mesh_.color(mesh_.face_handle(7))[0] ) << "Wrong face color at face 7";
1331 EXPECT_FLOAT_EQ(140/255.0, mesh_.color(mesh_.face_handle(7))[1] ) << "Wrong face color at face 7";
1332 EXPECT_FLOAT_EQ(107/255.0, mesh_.color(mesh_.face_handle(7))[2] ) << "Wrong face color at face 7";
1333#else
1334 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(0))[0] ) << "Wrong face color at face 0";
1335 EXPECT_EQ(117, mesh_.color(mesh_.face_handle(0))[1] ) << "Wrong face color at face 0";
1336 EXPECT_EQ(177, mesh_.color(mesh_.face_handle(0))[2] ) << "Wrong face color at face 0";
1337
1338 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(3))[0] ) << "Wrong face color at face 3";
1339 EXPECT_EQ(255, mesh_.color(mesh_.face_handle(3))[1] ) << "Wrong face color at face 3";
1340 EXPECT_EQ(135, mesh_.color(mesh_.face_handle(3))[2] ) << "Wrong face color at face 3";
1341
1342 EXPECT_EQ(163, mesh_.color(mesh_.face_handle(4))[0] ) << "Wrong face color at face 4";
1343 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(4))[1] ) << "Wrong face color at face 4";
1344 EXPECT_EQ(177, mesh_.color(mesh_.face_handle(4))[2] ) << "Wrong face color at face 4";
1345
1346 EXPECT_EQ(255, mesh_.color(mesh_.face_handle(7))[0] ) << "Wrong face color at face 7";
1347 EXPECT_EQ(140, mesh_.color(mesh_.face_handle(7))[1] ) << "Wrong face color at face 7";
1348 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(7))[2] ) << "Wrong face color at face 7";
1349#endif
1350
1351 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned: " << outFileName;
1352 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned: " << outFileName;
1353 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned: " << outFileName;
1354 EXPECT_TRUE(options.face_has_color()) << "Wrong user options are returned: " << outFileName;
1355 EXPECT_EQ(formats[i]._options.color_is_float(), options.color_is_float()) <<
1356 "Wrong user options are returned: " << outFileName;
1357 EXPECT_EQ(formats[i]._options.is_binary(), options.is_binary()) <<
1358 "Wrong user options are returned: " << outFileName;
1359
1360 mesh_.release_face_colors();
1361 }
1362}
1363
1364/*
1365 * Just load a ply file of a cube with vertex colors
1366 */
1367TEST_F(OpenMeshReadWritePLYColorVec3f , LoadSimplePLYWithVertexColorsVec3f) {
1368
1369 mesh_.clear();
1370
1371 mesh_.request_vertex_colors();
1372
1373 OpenMesh::IO::Options options;
1375
1376 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-vertexColors.ply",options);
1377
1378 EXPECT_TRUE(ok) << "Unable to load cube-minimal-vertexColors.ply";
1379
1380 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
1381 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
1382 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
1383
1384#ifdef TEST_DOUBLE_TRAITS
1385 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
1386 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
1387 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
1388
1389 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
1390 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
1391 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
1392
1393 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
1394 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
1395 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
1396
1397 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
1398 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
1399 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
1400#else
1401 EXPECT_EQ(1.0f, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
1402 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
1403 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
1404
1405 EXPECT_EQ(1.0f, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
1406 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
1407 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
1408
1409 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
1410 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
1411 EXPECT_EQ(1.0f, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
1412
1413 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
1414 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
1415 EXPECT_EQ(1.0f, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
1416#endif
1417
1418 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
1419 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
1420 EXPECT_TRUE(options.vertex_has_color()) << "Wrong user options are returned!";
1421
1422 mesh_.release_vertex_colors();
1423}
1424
1425/*
1426 * Write and read PLY files with face colors in various formats
1427 */
1428TEST_F(OpenMeshReadWritePLYColorVec3f , WriteAndReadPLYWithFaceColorsVec3f) {
1429 struct Format {
1430 Format(const char* outFileName, OpenMesh::IO::Options options) :
1431 _outFileName(outFileName),
1432 _options(options)
1433 {}
1434 const char* _outFileName;
1435 const OpenMesh::IO::Options _options;
1436 }
1437 formats[] =
1438 {
1439 Format("cube-minimal-faceColors_ascii_uchar.ply",
1441 Format("cube-minimal-faceColors_ascii_float.ply",
1443 Format("cube-minimal-faceColors_binary_uchar.ply",
1445 Format("cube-minimal-faceColors_binary_float.ply",
1447 // Test writing/reading alpha values (all default 1.0/255), but the test mesh
1448 // Color type has no alpha channel so there's nothing to test below
1449 Format("cube-minimal-faceColors_alpha_ascii_uchar.ply",
1451 Format("cube-minimal-faceColors_alpha_ascii_float.ply",
1453 Format("cube-minimal-faceColors_alpha_binary_uchar.ply",
1455 Format("cube-minimal-faceColors_alpha_binary_float.ply",
1457 };
1458
1459 for (size_t i = 0; i < sizeof(formats) / sizeof(Format); ++i)
1460 {
1461 const char* outFileName = formats[i]._outFileName;
1462
1463 mesh_.clear();
1464
1465 mesh_.request_face_colors();
1466
1467 OpenMesh::IO::Options options;
1469
1470 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-faceColors.ply", options);
1471
1472 EXPECT_TRUE(ok) << "Unable to load cube-minimal-faceColors.ply";
1473
1474 options = formats[i]._options;
1476 ok = OpenMesh::IO::write_mesh(mesh_, outFileName, options);
1477 EXPECT_TRUE(ok) << "Unable to write " << outFileName;
1478
1479 // Reset for reading: let the reader determine binary/float/etc.
1481 mesh_.clear();
1482 ok = OpenMesh::IO::read_mesh(mesh_, outFileName, options);
1483 EXPECT_TRUE(ok) << "Unable to load " << outFileName;
1484
1485 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct: " << outFileName;
1486 EXPECT_EQ(18u, mesh_.n_edges()) << "The number of loaded edges is not correct: " << outFileName;
1487 EXPECT_EQ(12u, mesh_.n_faces()) << "The number of loaded faces is not correct: " << outFileName;
1488
1489
1490 // Just a compilation test and runtime. No value test, as they are float
1491
1492 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned: " << outFileName;
1493 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned: " << outFileName;
1494 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned: " << outFileName;
1495 EXPECT_TRUE(options.face_has_color()) << "Wrong user options are returned: " << outFileName;
1496 EXPECT_EQ(formats[i]._options.color_is_float(), options.color_is_float()) <<
1497 "Wrong user options are returned: " << outFileName;
1498 EXPECT_EQ(formats[i]._options.is_binary(), options.is_binary()) <<
1499 "Wrong user options are returned: " << outFileName;
1500
1501 mesh_.release_face_colors();
1502 }
1503}
1504
1505
1506}
int idx() const
Get the underlying index of this handle.
Definition Handles.hh:69
Set options for reader/writer modules.
Definition Options.hh:92
void clear(void)
Clear all bits.
Definition Options.hh:143
@ ColorFloat
Has (r) / store (w) float values for colors (currently only implemented for PLY and OFF files)
Definition Options.hh:113
@ FaceColor
Has (r) / store (w) face colors.
Definition Options.hh:110
@ FaceTexCoord
Has (r) / store (w) face texture coordinates.
Definition Options.hh:111
@ Binary
Set binary mode for r/w.
Definition Options.hh:101
@ Default
By default write persistent custom properties.
Definition Options.hh:117
@ ColorAlpha
Has (r) / store (w) alpha values for colors.
Definition Options.hh:112
@ VertexNormal
Has (r) / store (w) vertex normals.
Definition Options.hh:105
@ VertexTexCoord
Has (r) / store (w) texture coordinates.
Definition Options.hh:107
@ VertexColor
Has (r) / store (w) vertex colors.
Definition Options.hh:106
@ Custom
Has (r) / store (w) custom properties marked persistent (currently PLY only supports reading and only...
Definition Options.hh:114
Kernel::FaceIter FaceIter
Scalar type.
Definition PolyMeshT.hh:146
Kernel::VertexIter VertexIter
Scalar type.
Definition PolyMeshT.hh:143
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:190
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Definition MeshIO.hh:95
Vec3uc Color
The default color type is OpenMesh::Vec3uc.
Definition Traits.hh:140
Handle for a face entity.
Definition Handles.hh:142
Handle for a vertex entity.
Definition Handles.hh:121