Developer Documentation

unittests_read_write_PLY.cc
1 #include <gtest/gtest.h>
2 #include <Unittests/unittests_common.hh>
3
4
5 namespace {
6
7 class 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
27 /*
28 * ====================================================================
29 * Define tests below
30 * ====================================================================
31 */
32
33 /*
34 * Just load a point file in ply format and count whether
35 * the right number of entities has been loaded.
36 */
37 TEST_F(OpenMeshReadWritePLY, LoadSimplePointPLYFileWithBadEncoding) {
38
39 mesh_.clear();
40
41 bool ok = OpenMesh::IO::read_mesh(mesh_, "pointCloudBadEncoding.ply");
42
43 EXPECT_TRUE(ok) << "Unable to load pointCloudBadEncoding.ply";
44
45 EXPECT_EQ(10u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
46 EXPECT_EQ(0u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
47 EXPECT_EQ(0u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
48 }
49
50 /*
51 * Just load a point file in ply format and count whether
52 * the right number of entities has been loaded.
53 */
54 TEST_F(OpenMeshReadWritePLY, LoadSimplePointPLYFileWithGoodEncoding) {
55
56 mesh_.clear();
57
58 bool ok = OpenMesh::IO::read_mesh(mesh_, "pointCloudGoodEncoding.ply");
59
60 EXPECT_TRUE(ok) << "Unable to load pointCloudGoodEncoding.ply";
61
62 EXPECT_EQ(10u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
63 EXPECT_EQ(0u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
64 EXPECT_EQ(0u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
65 }
66
67 /*
68 * Just load a ply
69 */
70 TEST_F(OpenMeshReadWritePLY, LoadSimplePLY) {
71
72 mesh_.clear();
73
74 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal.ply");
75
76 EXPECT_TRUE(ok) << "Unable to load cube-minimal.ply";
77
78 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
79 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
80 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
81
82 }
83
84 /*
85 * Load a ply ascii file without a newline at the end of the file
86 *
87 */
88 TEST_F(OpenMeshReadWritePLY, LoadSimplePLYNoEndl) {
89
90 mesh_.clear();
91
92 bool ok = OpenMesh::IO::read_mesh(mesh_, "sphere840.ply");
93
94 EXPECT_TRUE(ok) << "Unable to load sphere840.ply";
95
96 EXPECT_EQ(422u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
97 EXPECT_EQ(1260u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
98 EXPECT_EQ(840u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
99
100 }
101
102 /*
103 * Just load a ply file and set vertex color option before loading
104 */
105 TEST_F(OpenMeshReadWritePLY, LoadSimplePLYForceVertexColorsAlthoughNotAvailable) {
106
107 mesh_.clear();
108
109 mesh_.request_vertex_colors();
110
111 std::string file_name = "cube-minimal.ply";
112
113 OpenMesh::IO::Options options;
114 options += OpenMesh::IO::Options::VertexColor;
115
116 bool ok = OpenMesh::IO::read_mesh(mesh_, file_name,options);
117
118 EXPECT_TRUE(ok) << file_name;
119
120 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
121 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
122 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
123 EXPECT_EQ(36u , mesh_.n_halfedges()) << "The number of loaded halfedges is not correct!";
124
125 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
126 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
127 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!";
128 }
129
130 /*
131 * Just load a ply file of a cube with vertex colors
132 */
133 TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithVertexColors) {
134
135 mesh_.clear();
136
137 mesh_.request_vertex_colors();
138
139 OpenMesh::IO::Options options;
140 options += OpenMesh::IO::Options::VertexColor;
141
142 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-vertexColors.ply",options);
143
144 EXPECT_TRUE(ok) << "Unable to load cube-minimal-vertexColors.ply";
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
150 #ifdef TEST_DOUBLE_TRAITS
151 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
152 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
153 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
154
155 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
156 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
157 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
158
159 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
160 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
161 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
162
163 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
164 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
165 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
166 #else
167 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
168 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
169 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
170
171 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
172 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
173 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
174
175 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
176 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
177 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
178
179 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
180 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
181 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
182 #endif
183
184 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
185 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
186 EXPECT_TRUE(options.vertex_has_color()) << "Wrong user options are returned!";
187
188 mesh_.release_vertex_colors();
189 }
190
191 /*
192 * Just load a ply file of a cube with vertex colors
193 */
194 TEST_F(OpenMeshReadWritePLY, LoadPLYFromMeshLabWithVertexColors) {
195
196 mesh_.clear();
197
198 mesh_.request_vertex_colors();
199
200 OpenMesh::IO::Options options;
201 options += OpenMesh::IO::Options::VertexColor;
202
203 bool ok = OpenMesh::IO::read_mesh(mesh_, "meshlab.ply",options);
204
205 EXPECT_TRUE(ok) << "Unable to load meshlab.ply";
206
207 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
208 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
209 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
210
211 #ifdef TEST_DOUBLE_TRAITS
212 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
213 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
214 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
215
216 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
217 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
218 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
219
220 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
221 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
222 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
223
224 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
225 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
226 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
227 #else
228 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
229 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
230 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
231
232 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
233 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
234 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
235
236 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
237 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
238 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
239
240 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
241 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
242 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
243 #endif
244
245 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
246 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
247 EXPECT_TRUE(options.vertex_has_color()) << "Wrong user options are returned!";
248
249 mesh_.release_vertex_colors();
250 }
251
252 /*
253 * Just read and write a binary ply file of a cube with vertex colors
254 */
255 TEST_F(OpenMeshReadWritePLY, WriteAndReadBinaryPLYWithVertexColors) {
256
257 mesh_.clear();
258
259 mesh_.request_vertex_colors();
260
261 OpenMesh::IO::Options options;
262 options += OpenMesh::IO::Options::VertexColor;
263
264 bool ok = OpenMesh::IO::read_mesh(mesh_, "meshlab.ply",options);
265
266 EXPECT_TRUE(ok) << "Unable to load meshlab.ply";
267
268 options += OpenMesh::IO::Options::Binary;
269
270 ok = OpenMesh::IO::write_mesh(mesh_, "meshlab_binary.ply",options);
271 EXPECT_TRUE(ok) << "Unable to write meshlab_binary.ply";
272
273 mesh_.clear();
274 ok = OpenMesh::IO::read_mesh(mesh_, "meshlab_binary.ply",options);
275 EXPECT_TRUE(ok) << "Unable to load meshlab_binary.ply";
276
277 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
278 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
279 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
280
281 #ifdef TEST_DOUBLE_TRAITS
282 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
283 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
284 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
285
286 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
287 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
288 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
289
290 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
291 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
292 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
293
294 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
295 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
296 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
297 #else
298 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
299 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
300 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
301
302 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
303 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
304 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
305
306 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
307 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
308 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
309
310 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
311 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
312 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
313 #endif
314
315 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
316 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
317 EXPECT_TRUE(options.vertex_has_color()) << "Wrong user options are returned!";
318
319 mesh_.release_vertex_colors();
320 }
321
322 /*
323 * Just read and write a ply file of a cube with float vertex colors
324 */
325 TEST_F(OpenMeshReadWritePLY, WriteAndReadPLYWithFloatVertexColors) {
326
327 mesh_.clear();
328
329 mesh_.request_vertex_colors();
330
331 OpenMesh::IO::Options options;
332 options += OpenMesh::IO::Options::VertexColor;
333
334 bool ok = OpenMesh::IO::read_mesh(mesh_, "meshlab.ply",options);
335
336 EXPECT_TRUE(ok) << "Unable to load meshlab.ply";
337
338 options += OpenMesh::IO::Options::ColorFloat;
339
340 ok = OpenMesh::IO::write_mesh(mesh_, "meshlab_float.ply",options);
341 EXPECT_TRUE(ok) << "Unable to write meshlab_float.ply";
342
343 mesh_.clear();
344 ok = OpenMesh::IO::read_mesh(mesh_, "meshlab_float.ply",options);
345 EXPECT_TRUE(ok) << "Unable to load meshlab_float.ply";
346
347 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
348 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
349 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
350
351 #ifdef TEST_DOUBLE_TRAITS
352 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
353 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
354 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
355
356 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
357 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
358 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
359
360 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
361 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
362 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
363
364 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
365 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
366 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
367 #else
368 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
369 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
370 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
371
372 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
373 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
374 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
375
376 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
377 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
378 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
379
380 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
381 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
382 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
383 #endif
384
385 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
386 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
387 EXPECT_TRUE(options.vertex_has_color()) << "Wrong user options are returned!";
388 EXPECT_TRUE(options.color_is_float()) << "Wrong user options are returned!";
389
390 mesh_.release_vertex_colors();
391 }
392
393 /*
394 * Just read and write a binary ply file of a cube with float vertex colors
395 */
396 TEST_F(OpenMeshReadWritePLY, WriteAndReadBinaryPLYWithFloatVertexColors) {
397
398 mesh_.clear();
399
400 mesh_.request_vertex_colors();
401
402 OpenMesh::IO::Options options;
403 options += OpenMesh::IO::Options::VertexColor;
404
405 bool ok = OpenMesh::IO::read_mesh(mesh_, "meshlab.ply",options);
406
407 EXPECT_TRUE(ok) << "Unable to load meshlab.ply";
408
409 options += OpenMesh::IO::Options::ColorFloat;
410 options += OpenMesh::IO::Options::Binary;
411
412 ok = OpenMesh::IO::write_mesh(mesh_, "meshlab_binary_float.ply",options);
413 EXPECT_TRUE(ok) << "Unable to write meshlab_binary_float.ply";
414
415 mesh_.clear();
416 ok = OpenMesh::IO::read_mesh(mesh_, "meshlab_binary_float.ply",options);
417 EXPECT_TRUE(ok) << "Unable to load meshlab_binary_float.ply";
418
419 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
420 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
421 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
422
423 #ifdef TEST_DOUBLE_TRAITS
424 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
425 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
426 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
427
428 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
429 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
430 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
431
432 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
433 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
434 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
435
436 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
437 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
438 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
439 #else
440 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
441 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
442 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
443
444 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
445 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
446 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
447
448 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
449 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
450 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
451
452 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
453 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
454 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
455 #endif
456
457 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
458 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
459 EXPECT_TRUE(options.vertex_has_color()) << "Wrong user options are returned!";
460 EXPECT_TRUE(options.color_is_float()) << "Wrong user options are returned!";
461 EXPECT_TRUE(options.is_binary()) << "Wrong user options are returned!";
462
463 mesh_.release_vertex_colors();
464 }
465
466 /*
467 * Just load a ply file of a cube with vertex texCoords
468 */
469 TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithTexCoords) {
470
471 mesh_.clear();
472
473 mesh_.request_vertex_texcoords2D();
474
475 OpenMesh::IO::Options options;
476 options += OpenMesh::IO::Options::VertexTexCoord;
477
478 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-texCoords.ply",options);
479
480 EXPECT_TRUE(ok) << "Unable to load cube-minimal-texCoords.ply";
481
482 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
483 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
484 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
485
486 EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
487 EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
488
489 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[0] ) << "Wrong vertex color at vertex 2 component 0";
490 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[1] ) << "Wrong vertex color at vertex 2 component 1";
491
492 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
493 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
494
495 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
496 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
497
498
499 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
500 EXPECT_TRUE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
501 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!";
502
503 mesh_.release_vertex_texcoords2D();
504 }
505
506 /*
507 * Just load a ply with normals, ascii mode
508 */
509 TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithNormals) {
510
511 mesh_.clear();
512
513 mesh_.request_vertex_normals();
514
515 OpenMesh::IO::Options options;
516 options += OpenMesh::IO::Options::VertexNormal;
517
518 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-normals.ply", options);
519
520 EXPECT_TRUE(ok) << "Unable to load cube-minimal-normals.ply";
521
522 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
523 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
524 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
525
526 EXPECT_TRUE(options.vertex_has_normal()) << "Wrong user options are returned!";
527 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
528 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!";
529
530
531 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[0] ) << "Wrong normal at vertex 0 component 0";
532 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[1] ) << "Wrong normal at vertex 0 component 1";
533 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(0))[2] ) << "Wrong normal at vertex 0 component 2";
534
535 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(3))[0] ) << "Wrong normal at vertex 3 component 0";
536 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(3))[1] ) << "Wrong normal at vertex 3 component 1";
537 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(3))[2] ) << "Wrong normal at vertex 3 component 2";
538
539 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(4))[0] ) << "Wrong normal at vertex 4 component 0";
540 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(4))[1] ) << "Wrong normal at vertex 4 component 1";
541 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(4))[2] ) << "Wrong normal at vertex 4 component 2";
542
543 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(7))[0] ) << "Wrong normal at vertex 7 component 0";
544 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(7))[1] ) << "Wrong normal at vertex 7 component 1";
545 EXPECT_EQ(2, mesh_.normal(mesh_.vertex_handle(7))[2] ) << "Wrong normal at vertex 7 component 2";
546
547 mesh_.release_vertex_normals();
548
549 }
550
551 /*
552 * Just load a ply with custom properties, ascii mode
553 */
554 TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithCustomProps) {
555
556 PolyMesh mesh;
557
558 OpenMesh::IO::Options options;
559 options += OpenMesh::IO::Options::Custom;
560
561 bool ok = OpenMesh::IO::read_mesh(mesh, "cube-minimal-custom_props.ply", options);
562
563 EXPECT_TRUE(ok) << "Unable to load cube-minimal-custom_props.ply";
564
565 EXPECT_EQ(8u , mesh.n_vertices()) << "The number of loaded vertices is not correct!";
566 EXPECT_EQ(12u , mesh.n_edges()) << "The number of loaded edges is not correct!";
567 EXPECT_EQ(6u , mesh.n_faces()) << "The number of loaded faces is not correct!";
568
569 OpenMesh::VPropHandleT<float> qualityProp;
570 OpenMesh::VPropHandleT<unsigned int> indexProp;
571 ASSERT_TRUE(mesh.get_property_handle(qualityProp,"quality")) << "Could not access quality property";
572 ASSERT_TRUE(mesh.get_property_handle(indexProp,"index")) << "Could not access index property";
573
574 //check index property
575 for (unsigned i = 0; i < mesh.n_vertices(); ++i)
576 EXPECT_EQ(i ,mesh.property(indexProp,OpenMesh::VertexHandle(i))) << "Vertex index at vertex " << i << " is wrong";
577
578 //check quality property
579 EXPECT_EQ(1.f,mesh.property(qualityProp,OpenMesh::VertexHandle(0))) << "Wrong quality value at Vertex 0";
580 EXPECT_EQ(0.5f,mesh.property(qualityProp,OpenMesh::VertexHandle(1))) << "Wrong quality value at Vertex 1";
581 EXPECT_EQ(0.7f,mesh.property(qualityProp,OpenMesh::VertexHandle(2))) << "Wrong quality value at Vertex 2";
582 EXPECT_EQ(1.f,mesh.property(qualityProp,OpenMesh::VertexHandle(3))) << "Wrong quality value at Vertex 3";
583 EXPECT_EQ(0.1f,mesh.property(qualityProp,OpenMesh::VertexHandle(4))) << "Wrong quality value at Vertex 4";
584 EXPECT_EQ(0.f,mesh.property(qualityProp,OpenMesh::VertexHandle(5))) << "Wrong quality value at Vertex 5";
585 EXPECT_EQ(2.f,mesh.property(qualityProp,OpenMesh::VertexHandle(6))) << "Wrong quality value at Vertex 6";
586 EXPECT_EQ(5.f,mesh.property(qualityProp,OpenMesh::VertexHandle(7))) << "Wrong quality value at Vertex 7";
587
588 //check for custom list properties
589
590 OpenMesh::VPropHandleT< std::vector<int> > testValues;
591 ASSERT_TRUE(mesh.get_property_handle(testValues,"test_values")) << "Could not access texcoords per face";
592
593 EXPECT_EQ(2u,mesh.property(testValues,OpenMesh::VertexHandle(0)).size()) << "Wrong verctor size";
594
595 EXPECT_EQ(1,mesh.property(testValues,OpenMesh::VertexHandle(0))[0]) << "Wrong list value at Vertex 0";
596 EXPECT_EQ(4,mesh.property(testValues,OpenMesh::VertexHandle(1))[1]) << "Wrong list value at Vertex 1";
597 EXPECT_EQ(5,mesh.property(testValues,OpenMesh::VertexHandle(2))[0]) << "Wrong list value at Vertex 2";
598 EXPECT_EQ(8,mesh.property(testValues,OpenMesh::VertexHandle(3))[1]) << "Wrong list value at Vertex 3";
599 EXPECT_EQ(9,mesh.property(testValues,OpenMesh::VertexHandle(4))[0]) << "Wrong list value at Vertex 4";
600 EXPECT_EQ(12,mesh.property(testValues,OpenMesh::VertexHandle(5))[1]) << "Wrong list value at Vertex 5";
601 EXPECT_EQ(13,mesh.property(testValues,OpenMesh::VertexHandle(6))[0]) << "Wrong list value at Vertex 6";
602 EXPECT_EQ(16,mesh.property(testValues,OpenMesh::VertexHandle(7))[1]) << "Wrong list value at Vertex 7";
603
604 OpenMesh::FPropHandleT< std::vector<float> > texCoordsPerFace;
605 ASSERT_TRUE(mesh.get_property_handle(texCoordsPerFace,"texcoords")) << "Could not access texcoords per face";
606
607 for (Mesh::FaceIter f_iter = mesh.faces_begin(); f_iter != mesh.faces_end(); ++f_iter)
608 {
609 EXPECT_EQ(8u, mesh.property(texCoordsPerFace, *f_iter).size()) << "Texcoords per face container has wrong size on face: " << f_iter->idx();
610 if (!mesh.property(texCoordsPerFace, *f_iter).empty())
611 {
612 EXPECT_EQ(1.0, mesh.property(texCoordsPerFace, *f_iter)[0]) << "Texcoords wrong on index 0 with face: " << f_iter->idx();
613 EXPECT_EQ(1.0, mesh.property(texCoordsPerFace, *f_iter)[1]) << "Texcoords wrong on index 1 with face: " << f_iter->idx();
614 EXPECT_EQ(-1.0f, mesh.property(texCoordsPerFace, *f_iter)[2]) << "Texcoords wrong on index 2 with face: " << f_iter->idx();
615 EXPECT_EQ(-1.0f, mesh.property(texCoordsPerFace, *f_iter)[3]) << "Texcoords wrong on index 3 with face: " << f_iter->idx();
616 EXPECT_EQ(0.0f, mesh.property(texCoordsPerFace, *f_iter)[4]) << "Texcoords wrong on index 4 with face: " << f_iter->idx();
617 EXPECT_EQ(0.0f, mesh.property(texCoordsPerFace, *f_iter)[5]) << "Texcoords wrong on index 5 with face: " << f_iter->idx();
618 EXPECT_EQ(-0.5f, mesh.property(texCoordsPerFace, *f_iter)[6]) << "Texcoords wrong on index 6 with face: " << f_iter->idx();
619 EXPECT_EQ(-0.5f, mesh.property(texCoordsPerFace, *f_iter)[7]) << "Texcoords wrong on index 7 with face: " << f_iter->idx();
620 }
621
622 }
623
624 OpenMesh::FPropHandleT< unsigned > faceIndex;
625 ASSERT_TRUE(mesh.get_property_handle(faceIndex,"faceIndex")) << "Could not access faceIndex per face";
626
627 EXPECT_EQ(0u,mesh.property(faceIndex,OpenMesh::FaceHandle(0))) << "Wrong index value at FaceHandle 0";
628 EXPECT_EQ(1u,mesh.property(faceIndex,OpenMesh::FaceHandle(1))) << "Wrong index value at FaceHandle 1";
629 EXPECT_EQ(2u,mesh.property(faceIndex,OpenMesh::FaceHandle(2))) << "Wrong index value at FaceHandle 2";
630 EXPECT_EQ(3u,mesh.property(faceIndex,OpenMesh::FaceHandle(3))) << "Wrong index value at FaceHandle 3";
631 EXPECT_EQ(4u,mesh.property(faceIndex,OpenMesh::FaceHandle(4))) << "Wrong index value at FaceHandle 4";
632 EXPECT_EQ(5u,mesh.property(faceIndex,OpenMesh::FaceHandle(5))) << "Wrong index value at FaceHandle 5";
633
634 }
635
636 /*
637 * Just load a ply with custom properties, binary mode
638 */
639 TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithCustomPropsBinary) {
640
641 PolyMesh mesh;
642
643 OpenMesh::IO::Options options;
644 options += OpenMesh::IO::Options::Custom;
645 options += OpenMesh::IO::Options::Binary;
646
647 bool ok = OpenMesh::IO::read_mesh(mesh, "cube-minimal-custom_props-binary.ply", options);
648
649 EXPECT_TRUE(ok) << "Unable to load cube-minimal-custom_props.ply";
650
651 EXPECT_EQ(8u , mesh.n_vertices()) << "The number of loaded vertices is not correct!";
652 EXPECT_EQ(12u , mesh.n_edges()) << "The number of loaded edges is not correct!";
653 EXPECT_EQ(6u , mesh.n_faces()) << "The number of loaded faces is not correct!";
654
655 OpenMesh::VPropHandleT<float> qualityProp;
656 OpenMesh::VPropHandleT<unsigned int> indexProp;
657 ASSERT_TRUE(mesh.get_property_handle(qualityProp,"quality")) << "Could not access quality property";
658 ASSERT_TRUE(mesh.get_property_handle(indexProp,"index")) << "Could not access index property";
659
660 //check index property
661 for (unsigned i = 0; i < mesh.n_vertices(); ++i)
662 EXPECT_EQ(i ,mesh.property(indexProp,OpenMesh::VertexHandle(i))) << "Vertex index at vertex " << i << " is wrong";
663
664 //check quality property
665 EXPECT_EQ(1.f,mesh.property(qualityProp,OpenMesh::VertexHandle(0))) << "Wrong quality value at Vertex 0";
666 EXPECT_EQ(0.5f,mesh.property(qualityProp,OpenMesh::VertexHandle(1))) << "Wrong quality value at Vertex 1";
667 EXPECT_EQ(0.7f,mesh.property(qualityProp,OpenMesh::VertexHandle(2))) << "Wrong quality value at Vertex 2";
668 EXPECT_EQ(1.f,mesh.property(qualityProp,OpenMesh::VertexHandle(3))) << "Wrong quality value at Vertex 3";
669 EXPECT_EQ(0.1f,mesh.property(qualityProp,OpenMesh::VertexHandle(4))) << "Wrong quality value at Vertex 4";
670 EXPECT_EQ(0.f,mesh.property(qualityProp,OpenMesh::VertexHandle(5))) << "Wrong quality value at Vertex 5";
671 EXPECT_EQ(2.f,mesh.property(qualityProp,OpenMesh::VertexHandle(6))) << "Wrong quality value at Vertex 6";
672 EXPECT_EQ(5.f,mesh.property(qualityProp,OpenMesh::VertexHandle(7))) << "Wrong quality value at Vertex 7";
673
674 //check for custom list properties
675
676 OpenMesh::VPropHandleT< std::vector<int> > testValues;
677 ASSERT_TRUE(mesh.get_property_handle(testValues,"test_values")) << "Could not access texcoords per face";
678
679 EXPECT_EQ(2u,mesh.property(testValues,OpenMesh::VertexHandle(0)).size()) << "Wrong verctor size";
680
681 EXPECT_EQ(1,mesh.property(testValues,OpenMesh::VertexHandle(0))[0]) << "Wrong list value at Vertex 0";
682 EXPECT_EQ(4,mesh.property(testValues,OpenMesh::VertexHandle(1))[1]) << "Wrong list value at Vertex 1";
683 EXPECT_EQ(5,mesh.property(testValues,OpenMesh::VertexHandle(2))[0]) << "Wrong list value at Vertex 2";
684 EXPECT_EQ(8,mesh.property(testValues,OpenMesh::VertexHandle(3))[1]) << "Wrong list value at Vertex 3";
685 EXPECT_EQ(9,mesh.property(testValues,OpenMesh::VertexHandle(4))[0]) << "Wrong list value at Vertex 4";
686 EXPECT_EQ(12,mesh.property(testValues,OpenMesh::VertexHandle(5))[1]) << "Wrong list value at Vertex 5";
687 EXPECT_EQ(13,mesh.property(testValues,OpenMesh::VertexHandle(6))[0]) << "Wrong list value at Vertex 6";
688 EXPECT_EQ(16,mesh.property(testValues,OpenMesh::VertexHandle(7))[1]) << "Wrong list value at Vertex 7";
689
690 OpenMesh::FPropHandleT< std::vector<float> > texCoordsPerFace;
691 ASSERT_TRUE(mesh.get_property_handle(texCoordsPerFace,"texcoords")) << "Could not access texcoords per face";
692
693 for (Mesh::FaceIter f_iter = mesh.faces_begin(); f_iter != mesh.faces_end(); ++f_iter)
694 {
695 EXPECT_EQ(8u, mesh.property(texCoordsPerFace, *f_iter).size()) << "Texcoords per face container has wrong size on face: " << f_iter->idx();
696 if (!mesh.property(texCoordsPerFace, *f_iter).empty())
697 {
698 EXPECT_EQ(1.0, mesh.property(texCoordsPerFace, *f_iter)[0]) << "Texcoords wrong on index 0 with face: " << f_iter->idx();
699 EXPECT_EQ(1.0, mesh.property(texCoordsPerFace, *f_iter)[1]) << "Texcoords wrong on index 1 with face: " << f_iter->idx();
700 EXPECT_EQ(-1.0f, mesh.property(texCoordsPerFace, *f_iter)[2]) << "Texcoords wrong on index 2 with face: " << f_iter->idx();
701 EXPECT_EQ(-1.0f, mesh.property(texCoordsPerFace, *f_iter)[3]) << "Texcoords wrong on index 3 with face: " << f_iter->idx();
702 EXPECT_EQ(0.0f, mesh.property(texCoordsPerFace, *f_iter)[4]) << "Texcoords wrong on index 4 with face: " << f_iter->idx();
703 EXPECT_EQ(0.0f, mesh.property(texCoordsPerFace, *f_iter)[5]) << "Texcoords wrong on index 5 with face: " << f_iter->idx();
704 EXPECT_EQ(-0.5f, mesh.property(texCoordsPerFace, *f_iter)[6]) << "Texcoords wrong on index 6 with face: " << f_iter->idx();
705 EXPECT_EQ(-0.5f, mesh.property(texCoordsPerFace, *f_iter)[7]) << "Texcoords wrong on index 7 with face: " << f_iter->idx();
706 }
707
708 }
709
710 OpenMesh::FPropHandleT< unsigned > faceIndex;
711 ASSERT_TRUE(mesh.get_property_handle(faceIndex,"faceIndex")) << "Could not access faceIndex per face";
712
713 EXPECT_EQ(0u,mesh.property(faceIndex,OpenMesh::FaceHandle(0))) << "Wrong index value at FaceHandle 0";
714 EXPECT_EQ(1u,mesh.property(faceIndex,OpenMesh::FaceHandle(1))) << "Wrong index value at FaceHandle 1";
715 EXPECT_EQ(2u,mesh.property(faceIndex,OpenMesh::FaceHandle(2))) << "Wrong index value at FaceHandle 2";
716 EXPECT_EQ(3u,mesh.property(faceIndex,OpenMesh::FaceHandle(3))) << "Wrong index value at FaceHandle 3";
717 EXPECT_EQ(4u,mesh.property(faceIndex,OpenMesh::FaceHandle(4))) << "Wrong index value at FaceHandle 4";
718 EXPECT_EQ(5u,mesh.property(faceIndex,OpenMesh::FaceHandle(5))) << "Wrong index value at FaceHandle 5";
719
720 }
721
722 TEST_F(OpenMeshReadWritePLY, WriteReadSimplePLYWithCustomProps) {
723
724 PolyMesh mesh;
725
726 OpenMesh::IO::Options options;
727 bool ok = OpenMesh::IO::read_mesh(mesh, "cube-minimal.ply", options);
728
729
730 OpenMesh::VPropHandleT<unsigned short> indexProp;
731 OpenMesh::VPropHandleT<unsigned int> nonPersistant;
732 OpenMesh::VPropHandleT<double> qualityProp;
733 OpenMesh::FPropHandleT<signed int> faceProp;
734 OpenMesh::VPropHandleT<int> removedProp;
735
736 const std::string indexPropName = "mySuperIndexProperty";
737 const std::string qualityPropName = "quality";
738 const std::string facePropName = "anotherPropForFaces";
739 const std::string nonPersistantName = "nonPersistant";
740 const std::string removedPropName = "willBeRemoved";
741
742 mesh.add_property(indexProp,indexPropName);
743 mesh.add_property(qualityProp,qualityPropName);
744 mesh.add_property(removedProp, removedPropName);
745 mesh.add_property(faceProp,facePropName);
746 mesh.add_property(nonPersistant,nonPersistantName);
747
748 mesh.property(indexProp).set_persistent(true);
749 mesh.property(qualityProp).set_persistent(true);
750 mesh.property(faceProp).set_persistent(true);
751 mesh.remove_property(removedProp);
752
753 signed char i=0;
754 for (Mesh::VertexIter v_iter = mesh.vertices_begin(); v_iter != mesh.vertices_end(); ++v_iter, ++i)
755 {
756 mesh.property(indexProp, *v_iter) = i;
757 mesh.property(qualityProp, *v_iter) = 3.5*i;
758 }
759
760 i = 0;
761 for (Mesh::FaceIter f_iter = mesh.faces_begin(); f_iter != mesh.faces_end(); ++f_iter, ++i)
762 {
763 mesh.property(faceProp, *f_iter) = -i;
764 }
765
766 const char* outFilename = "cube-minimal-customprops_openmeshOutputTestfile.ply";
767 ok = OpenMesh::IO::write_mesh(mesh, outFilename);
768
769 ASSERT_TRUE(ok);
770
771 PolyMesh loadedMesh;
772
773 EXPECT_FALSE(loadedMesh.get_property_handle(indexProp,indexPropName)) << "Could access to property which was deleted";
774
775 options += OpenMesh::IO::Options::Custom;
776 ok = OpenMesh::IO::read_mesh(loadedMesh, outFilename, options);
777
778 ASSERT_TRUE(ok);
779
780
781 ASSERT_TRUE(loadedMesh.get_property_handle(indexProp,indexPropName)) << "Could not access index property";
782 ASSERT_TRUE(loadedMesh.get_property_handle(qualityProp,qualityPropName)) << "Could not access quality property";
783 ASSERT_TRUE(loadedMesh.get_property_handle(faceProp,facePropName)) << "Could not access face property";
784 EXPECT_FALSE(loadedMesh.get_property_handle(nonPersistant,nonPersistantName)) << "Could access non persistant property";
785
786 i=0;
787 for (Mesh::VertexIter v_iter = loadedMesh.vertices_begin(); v_iter != loadedMesh.vertices_end(); ++v_iter, ++i)
788 {
789 EXPECT_EQ(loadedMesh.property(indexProp, *v_iter), static_cast<unsigned>(i));
790 EXPECT_EQ(loadedMesh.property(qualityProp, *v_iter),3.5*i);
791 }
792
793 i = 0;
794 for (Mesh::FaceIter f_iter = loadedMesh.faces_begin(); f_iter != loadedMesh.faces_end(); ++f_iter, ++i)
795 {
796 EXPECT_EQ(loadedMesh.property(faceProp, *f_iter),-i);
797 }
798
799
800 remove(outFilename);
801
802 }
803
804 TEST_F(OpenMeshReadWritePLY, WriteReadBinaryPLYWithCustomProps) {
805
806 PolyMesh mesh;
807
808 OpenMesh::IO::Options options;
809 bool ok = OpenMesh::IO::read_mesh(mesh, "cube-minimal.ply", options);
810
811
812 OpenMesh::VPropHandleT<unsigned short> indexProp;
813 OpenMesh::VPropHandleT<unsigned int> nonPersistant;
814 OpenMesh::VPropHandleT<double> qualityProp;
815 OpenMesh::FPropHandleT<signed int> faceProp;
816 OpenMesh::VPropHandleT<int> removedProp;
817
818 const std::string indexPropName = "mySuperIndexProperty";
819 const std::string qualityPropName = "quality";
820 const std::string facePropName = "anotherPropForFaces";
821 const std::string nonPersistantName = "nonPersistant";
822 const std::string removedPropName = "willBeRemoved";
823
824 mesh.add_property(indexProp,indexPropName);
825 mesh.add_property(qualityProp,qualityPropName);
826 mesh.add_property(removedProp, removedPropName);
827 mesh.add_property(faceProp,facePropName);
828 mesh.add_property(nonPersistant,nonPersistantName);
829
830 mesh.property(indexProp).set_persistent(true);
831 mesh.property(qualityProp).set_persistent(true);
832 mesh.property(faceProp).set_persistent(true);
833 mesh.remove_property(removedProp);
834
835 signed char i=0;
836 for (Mesh::VertexIter v_iter = mesh.vertices_begin(); v_iter != mesh.vertices_end(); ++v_iter, ++i)
837 {
838 mesh.property(indexProp, *v_iter) = i;
839 mesh.property(qualityProp, *v_iter) = 3.5*i;
840 }
841
842 i = 0;
843 for (Mesh::FaceIter f_iter = mesh.faces_begin(); f_iter != mesh.faces_end(); ++f_iter, ++i)
844 {
845 mesh.property(faceProp, *f_iter) = -i;
846 }
847
848 const char* outFilename = "cube-minimal-customprops_openmeshOutputTestfileBinary.ply";
849 options += OpenMesh::IO::Options::Binary;
850 ok = OpenMesh::IO::write_mesh(mesh, outFilename, options);
851
852 ASSERT_TRUE(ok);
853
854 PolyMesh loadedMesh;
855
856 EXPECT_FALSE(loadedMesh.get_property_handle(indexProp,indexPropName)) << "Could access to property which was deleted";
857
858 options.clear();
859 options += OpenMesh::IO::Options::Custom;
860 options += OpenMesh::IO::Options::Binary;
861 ok = OpenMesh::IO::read_mesh(loadedMesh, outFilename, options);
862
863 ASSERT_TRUE(ok);
864
865
866 ASSERT_TRUE(loadedMesh.get_property_handle(indexProp,indexPropName)) << "Could not access index property";
867 ASSERT_TRUE(loadedMesh.get_property_handle(qualityProp,qualityPropName)) << "Could not access quality property";
868 ASSERT_TRUE(loadedMesh.get_property_handle(faceProp,facePropName)) << "Could not access face property";
869 EXPECT_FALSE(loadedMesh.get_property_handle(nonPersistant,nonPersistantName)) << "Could access non persistant property";
870
871 i=0;
872 for (Mesh::VertexIter v_iter = loadedMesh.vertices_begin(); v_iter != loadedMesh.vertices_end(); ++v_iter, ++i)
873 {
874 EXPECT_EQ(loadedMesh.property(indexProp, *v_iter), static_cast<unsigned>(i));
875 EXPECT_EQ(loadedMesh.property(qualityProp, *v_iter),3.5*i);
876 }
877
878 i = 0;
879 for (Mesh::FaceIter f_iter = loadedMesh.faces_begin(); f_iter != loadedMesh.faces_end(); ++f_iter, ++i)
880 {
881 EXPECT_EQ(loadedMesh.property(faceProp, *f_iter),-i);
882 }
883
884
885 //remove(outFilename);
886
887 }
888
889 /*
890 * Just load a ply with extra elements
891 */
892 TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithExtraElements) {
893
894 mesh_.clear();
895
896 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-extra-elements.ply");
897
898 EXPECT_TRUE(ok) << "Unable to load cube-minimal-extra-elements.ply";
899
900 EXPECT_EQ(8u, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
901 EXPECT_EQ(18u, mesh_.n_edges()) << "The number of loaded edges is not correct!";
902 EXPECT_EQ(12u, mesh_.n_faces()) << "The number of loaded faces is not correct!";
903
904 }
905
906 /*
907 * Just load a binary ply with extra elements
908 */
909 TEST_F(OpenMeshReadWritePLY, LoadSimpleBinaryPLYWithExtraElements) {
910
911 mesh_.clear();
912
913 OpenMesh::IO::Options options = OpenMesh::IO::Options::Binary;
914
915 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-extra-elements-binary.ply", options);
916
917 EXPECT_TRUE(ok) << "Unable to load cube-minimal-extra-elements-binary.ply";
918
919 EXPECT_EQ(8u, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
920 EXPECT_EQ(18u, mesh_.n_edges()) << "The number of loaded edges is not correct!";
921 EXPECT_EQ(12u, mesh_.n_faces()) << "The number of loaded faces is not correct!";
922
923 }
924
925 /*
926 * Ignore a file that does not contain vertices and faces
927 */
928 TEST_F(OpenMeshReadWritePLY, IgnoreNonMeshPlyFile) {
929
930 mesh_.clear();
931
932 std::stringstream data;
933 data << "ply" << "\n";
934 data << "format binary_little_endian 1.0" << "\n";
935 data << "comment Image data" << "\n";
936 data << "element image 0" << "\n";
937 data << "property list uint16 uint16 row" << "\n";
938 data << "end_header" << "\n";
939
940 OpenMesh::IO::Options options = OpenMesh::IO::Options::Binary;
941
942 bool ok = OpenMesh::IO::read_mesh(mesh_, data, ".ply", options);
943
944 EXPECT_TRUE(ok) << "This empty file should be readable without an error!";
945
946 EXPECT_EQ(0u, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
947 EXPECT_EQ(0u, mesh_.n_edges()) << "The number of loaded edges is not correct!";
948 EXPECT_EQ(0u, mesh_.n_faces()) << "The number of loaded faces is not correct!";
949 }
950
951
952 /*
953 * Ignore a file that does not contain vertices and faces
954 */
955 TEST_F(OpenMeshReadWritePLY, FailOnUnknownPropertyTypeForLists) {
956
957 mesh_.clear();
958
959 std::stringstream data;
960 data << "ply" << "\n";
961 data << "format binary_little_endian 1.0" << "\n";
962 data << "comment Image data" << "\n";
963 data << "element image 0" << "\n";
964 data << "property list blibb blubb row" << "\n";
965 data << "end_header" << "\n";
966
967 OpenMesh::IO::Options options = OpenMesh::IO::Options::Binary;
968
969 bool ok = OpenMesh::IO::read_mesh(mesh_, data, ".ply", options);
970
971 EXPECT_FALSE(ok) << "This file should fail to read!";
972
973 EXPECT_EQ(0u, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
974 EXPECT_EQ(0u, mesh_.n_edges()) << "The number of loaded edges is not correct!";
975 EXPECT_EQ(0u, mesh_.n_faces()) << "The number of loaded faces is not correct!";
976 }
977
978 /*
979 * Load an ASCII PLY file of a cube with float RGB face colors
980 */
981 TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithFaceColors) {
982
983 mesh_.clear();
984
985 mesh_.request_face_colors();
986
987 OpenMesh::IO::Options options;
988 options += OpenMesh::IO::Options::FaceColor;
989
990 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-faceColors.ply",options);
991
992 EXPECT_TRUE(ok) << "Unable to load cube-minimal-faceColors.ply";
993
994 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
995 EXPECT_EQ(18u, mesh_.n_edges()) << "The number of loaded edges is not correct!";
996 EXPECT_EQ(12u, mesh_.n_faces()) << "The number of loaded faces is not correct!";
997
998 #ifdef TEST_DOUBLE_TRAITS
999 EXPECT_FLOAT_EQ(107/255.0, mesh_.color(mesh_.face_handle(0))[0] ) << "Wrong face color at face 0";
1000 EXPECT_FLOAT_EQ(117/255.0, mesh_.color(mesh_.face_handle(0))[1] ) << "Wrong face color at face 0";
1001 EXPECT_FLOAT_EQ(177/255.0, mesh_.color(mesh_.face_handle(0))[2] ) << "Wrong face color at face 0";
1002
1003 EXPECT_FLOAT_EQ(107/255.0, mesh_.color(mesh_.face_handle(3))[0] ) << "Wrong face color at face 3";
1004 EXPECT_FLOAT_EQ(255/255.0, mesh_.color(mesh_.face_handle(3))[1] ) << "Wrong face color at face 3";
1005 EXPECT_FLOAT_EQ(135/255.0, mesh_.color(mesh_.face_handle(3))[2] ) << "Wrong face color at face 3";
1006
1007 EXPECT_FLOAT_EQ(163/255.0, mesh_.color(mesh_.face_handle(4))[0] ) << "Wrong face color at face 4";
1008 EXPECT_FLOAT_EQ(107/255.0, mesh_.color(mesh_.face_handle(4))[1] ) << "Wrong face color at face 4";
1009 EXPECT_FLOAT_EQ(177/255.0, mesh_.color(mesh_.face_handle(4))[2] ) << "Wrong face color at face 4";
1010
1011 EXPECT_FLOAT_EQ(255/255.0, mesh_.color(mesh_.face_handle(7))[0] ) << "Wrong face color at face 7";
1012 EXPECT_FLOAT_EQ(140/255.0, mesh_.color(mesh_.face_handle(7))[1] ) << "Wrong face color at face 7";
1013 EXPECT_FLOAT_EQ(107/255.0, mesh_.color(mesh_.face_handle(7))[2] ) << "Wrong face color at face 7";
1014 #else
1015 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(0))[0] ) << "Wrong face color at face 0";
1016 EXPECT_EQ(117, mesh_.color(mesh_.face_handle(0))[1] ) << "Wrong face color at face 0";
1017 EXPECT_EQ(177, mesh_.color(mesh_.face_handle(0))[2] ) << "Wrong face color at face 0";
1018
1019 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(3))[0] ) << "Wrong face color at face 3";
1020 EXPECT_EQ(255, mesh_.color(mesh_.face_handle(3))[1] ) << "Wrong face color at face 3";
1021 EXPECT_EQ(135, mesh_.color(mesh_.face_handle(3))[2] ) << "Wrong face color at face 3";
1022
1023 EXPECT_EQ(163, mesh_.color(mesh_.face_handle(4))[0] ) << "Wrong face color at face 4";
1024 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(4))[1] ) << "Wrong face color at face 4";
1025 EXPECT_EQ(177, mesh_.color(mesh_.face_handle(4))[2] ) << "Wrong face color at face 4";
1026
1027 EXPECT_EQ(255, mesh_.color(mesh_.face_handle(7))[0] ) << "Wrong face color at face 7";
1028 EXPECT_EQ(140, mesh_.color(mesh_.face_handle(7))[1] ) << "Wrong face color at face 7";
1029 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(7))[2] ) << "Wrong face color at face 7";
1030 #endif
1031
1032 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
1033 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
1034 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!";
1035 EXPECT_TRUE(options.face_has_color()) << "Wrong user options are returned!";
1036 EXPECT_FALSE(options.color_has_alpha()) << "Wrong user options are returned!";
1037 EXPECT_FALSE(options.is_binary()) << "Wrong user options are returned!";
1038
1039 mesh_.release_face_colors();
1040 }
1041
1042 /*
1043 * Write and read PLY files with face colors in various formats
1044 */
1045 TEST_F(OpenMeshReadWritePLY, WriteAndReadPLYWithFaceColors) {
1046 struct Format {
1047 Format(const char* outFileName, OpenMesh::IO::Options options) :
1048 _outFileName(outFileName),
1049 _options(options)
1050 {}
1051 const char* _outFileName;
1052 const OpenMesh::IO::Options _options;
1053 }
1054 formats[] =
1055 {
1056 Format("cube-minimal-faceColors_ascii_uchar.ply",
1057 OpenMesh::IO::Options::Default),
1058 Format("cube-minimal-faceColors_ascii_float.ply",
1059 OpenMesh::IO::Options::ColorFloat),
1060 Format("cube-minimal-faceColors_binary_uchar.ply",
1061 OpenMesh::IO::Options::Binary),
1062 Format("cube-minimal-faceColors_binary_float.ply",
1063 OpenMesh::IO::Options::Binary | OpenMesh::IO::Options::ColorFloat),
1064 // Test writing/reading alpha values (all default 1.0/255), but the test mesh
1065 // Color type has no alpha channel so there's nothing to test below
1066 Format("cube-minimal-faceColors_alpha_ascii_uchar.ply",
1067 OpenMesh::IO::Options::ColorAlpha),
1068 Format("cube-minimal-faceColors_alpha_ascii_float.ply",
1069 OpenMesh::IO::Options::ColorFloat | OpenMesh::IO::Options::ColorAlpha),
1070 Format("cube-minimal-faceColors_alpha_binary_uchar.ply",
1071 OpenMesh::IO::Options::Binary | OpenMesh::IO::Options::ColorAlpha),
1072 Format("cube-minimal-faceColors_alpha_binary_float.ply",
1073 OpenMesh::IO::Options::Binary | OpenMesh::IO::Options::ColorFloat | OpenMesh::IO::Options::ColorAlpha),
1074 };
1075
1076 for (size_t i = 0; i < sizeof(formats) / sizeof(Format); ++i)
1077 {
1078 const char* outFileName = formats[i]._outFileName;
1079
1080 mesh_.clear();
1081
1082 mesh_.request_face_colors();
1083
1084 OpenMesh::IO::Options options;
1085 options += OpenMesh::IO::Options::FaceColor;
1086
1087 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-faceColors.ply", options);
1088
1089 EXPECT_TRUE(ok) << "Unable to load cube-minimal-faceColors.ply";
1090
1091 options = formats[i]._options;
1092 options += OpenMesh::IO::Options::FaceColor;
1093 ok = OpenMesh::IO::write_mesh(mesh_, outFileName, options);
1094 EXPECT_TRUE(ok) << "Unable to write " << outFileName;
1095
1096 // Reset for reading: let the reader determine binary/float/etc.
1097 options = OpenMesh::IO::Options::FaceColor;
1098 mesh_.clear();
1099 ok = OpenMesh::IO::read_mesh(mesh_, outFileName, options);
1100 EXPECT_TRUE(ok) << "Unable to load " << outFileName;
1101
1102 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct: " << outFileName;
1103 EXPECT_EQ(18u, mesh_.n_edges()) << "The number of loaded edges is not correct: " << outFileName;
1104 EXPECT_EQ(12u, mesh_.n_faces()) << "The number of loaded faces is not correct: " << outFileName;
1105
1106 #ifdef TEST_DOUBLE_TRAITS
1107 EXPECT_FLOAT_EQ(107/255.0, mesh_.color(mesh_.face_handle(0))[0] ) << "Wrong face color at face 0";
1108 EXPECT_FLOAT_EQ(117/255.0, mesh_.color(mesh_.face_handle(0))[1] ) << "Wrong face color at face 0";
1109 EXPECT_FLOAT_EQ(177/255.0, mesh_.color(mesh_.face_handle(0))[2] ) << "Wrong face color at face 0";
1110
1111 EXPECT_FLOAT_EQ(107/255.0, mesh_.color(mesh_.face_handle(3))[0] ) << "Wrong face color at face 3";
1112 EXPECT_FLOAT_EQ(255/255.0, mesh_.color(mesh_.face_handle(3))[1] ) << "Wrong face color at face 3";
1113 EXPECT_FLOAT_EQ(135/255.0, mesh_.color(mesh_.face_handle(3))[2] ) << "Wrong face color at face 3";
1114
1115 EXPECT_FLOAT_EQ(163/255.0, mesh_.color(mesh_.face_handle(4))[0] ) << "Wrong face color at face 4";
1116 EXPECT_FLOAT_EQ(107/255.0, mesh_.color(mesh_.face_handle(4))[1] ) << "Wrong face color at face 4";
1117 EXPECT_FLOAT_EQ(177/255.0, mesh_.color(mesh_.face_handle(4))[2] ) << "Wrong face color at face 4";
1118
1119 EXPECT_FLOAT_EQ(255/255.0, mesh_.color(mesh_.face_handle(7))[0] ) << "Wrong face color at face 7";
1120 EXPECT_FLOAT_EQ(140/255.0, mesh_.color(mesh_.face_handle(7))[1] ) << "Wrong face color at face 7";
1121 EXPECT_FLOAT_EQ(107/255.0, mesh_.color(mesh_.face_handle(7))[2] ) << "Wrong face color at face 7";
1122 #else
1123 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(0))[0] ) << "Wrong face color at face 0";
1124 EXPECT_EQ(117, mesh_.color(mesh_.face_handle(0))[1] ) << "Wrong face color at face 0";
1125 EXPECT_EQ(177, mesh_.color(mesh_.face_handle(0))[2] ) << "Wrong face color at face 0";
1126
1127 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(3))[0] ) << "Wrong face color at face 3";
1128 EXPECT_EQ(255, mesh_.color(mesh_.face_handle(3))[1] ) << "Wrong face color at face 3";
1129 EXPECT_EQ(135, mesh_.color(mesh_.face_handle(3))[2] ) << "Wrong face color at face 3";
1130
1131 EXPECT_EQ(163, mesh_.color(mesh_.face_handle(4))[0] ) << "Wrong face color at face 4";
1132 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(4))[1] ) << "Wrong face color at face 4";
1133 EXPECT_EQ(177, mesh_.color(mesh_.face_handle(4))[2] ) << "Wrong face color at face 4";
1134
1135 EXPECT_EQ(255, mesh_.color(mesh_.face_handle(7))[0] ) << "Wrong face color at face 7";
1136 EXPECT_EQ(140, mesh_.color(mesh_.face_handle(7))[1] ) << "Wrong face color at face 7";
1137 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(7))[2] ) << "Wrong face color at face 7";
1138 #endif
1139
1140 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned: " << outFileName;
1141 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned: " << outFileName;
1142 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned: " << outFileName;
1143 EXPECT_TRUE(options.face_has_color()) << "Wrong user options are returned: " << outFileName;
1144 EXPECT_EQ(formats[i]._options.color_is_float(), options.color_is_float()) <<
1145 "Wrong user options are returned: " << outFileName;
1146 EXPECT_EQ(formats[i]._options.is_binary(), options.is_binary()) <<
1147 "Wrong user options are returned: " << outFileName;
1148
1149 mesh_.release_face_colors();
1150 }
1151 }
1152
1153 }
OpenMesh::FaceHandle
Handle for a face entity.
Definition: Handles.hh:141
OpenMesh::VPropHandleT< float >
OpenMesh::IO::Options::VertexColor
Has (r) / store (w) vertex colors.
Definition: Options.hh:105
OpenMesh::IO::Options::clear
void clear(void)
Clear all bits.
Definition: Options.hh:147
OpenMesh::IO::Options::FaceColor
Has (r) / store (w) face colors.
Definition: Options.hh:109
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:207
OpenMesh::IO::Options::ColorFloat
Has (r) / store (w) float values for colors (currently only implemented for PLY and OFF files) ...
Definition: Options.hh:112
OpenMesh::BaseHandle::idx
int idx() const
Get the underlying index of this handle.
Definition: Handles.hh:69
OpenMesh::VertexHandle
Handle for a vertex entity.
Definition: Handles.hh:120
OpenMesh::IO::Options::ColorAlpha
Has (r) / store (w) alpha values for colors.
Definition: Options.hh:111
OpenMesh::IO::read_mesh
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Definition: MeshIO.hh:112
OpenMesh::IO::Options::Custom
Has (r) custom properties (currently only implemented in PLY Reader ASCII version) ...
Definition: Options.hh:113
OpenMesh::IO::Options
Set options for reader/writer modules.
Definition: Options.hh:90
OpenMeshBase
Definition: unittests_common.hh:29
OpenMesh::IO::Options::Default
No options.
Definition: Options.hh:99
OpenMesh::IO::Options::VertexNormal
Has (r) / store (w) vertex normals.
Definition: Options.hh:104
OpenMesh::FPropHandleT
Definition: Property.hh:529
OpenMesh::IO::Options::Binary
Set binary mode for r/w.
Definition: Options.hh:100
OpenMesh::IO::Options::VertexTexCoord
Has (r) / store (w) texture coordinates.
Definition: Options.hh:106