OpenMesh

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
unittests_read_write_OM.hh
1 #ifndef INCLUDE_UNITTESTS_READ_WRITE_OM_HH
2 #define INCLUDE_UNITTESTS_READ_WRITE_OM_HH
3
4 #include <gtest/gtest.h>
5 #include <Unittests/unittests_common.hh>
6
7
8 class OpenMeshReadWriteOM : public OpenMeshBase {
9
10 protected:
11
12 // This function is called before each test is run
13 virtual void SetUp() {
14
15 // Do some initial stuff with the member data here...
16 }
17
18 // This function is called after all tests are through
19 virtual void TearDown() {
20
21 // Do some final stuff with the member data here...
22 }
23
24 // Member already defined in OpenMeshBase
25 //Mesh mesh_;
26 };
27
28 /*
29 * ====================================================================
30 * Define tests below
31 * ====================================================================
32 */
33
34 /*
35 * Just load an om file and set vertex color option before loading
36 */
37 TEST_F(OpenMeshReadWriteOM, LoadSimpleOMForceVertexColorsAlthoughNotAvailable) {
38
39 mesh_.clear();
40
41 mesh_.request_vertex_colors();
42
43 std::string file_name = "cube-minimal.om";
44
45 OpenMesh::IO::Options options;
46 options += OpenMesh::IO::Options::VertexColor;
47
48 bool ok = OpenMesh::IO::read_mesh(mesh_, file_name,options);
49
50 EXPECT_TRUE(ok) << file_name;
51
52 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
53 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
54 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
55 EXPECT_EQ(36u , mesh_.n_halfedges()) << "The number of loaded halfedges is not correct!";
56
57 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
58 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
59 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!";
60 }
61
62 /*
63 * Just load an om file of a cube with vertex texCoords
64 */
65 TEST_F(OpenMeshReadWriteOM, LoadSimpleOMWithTexCoords) {
66
67 mesh_.clear();
68
69 mesh_.request_vertex_texcoords2D();
70
71 OpenMesh::IO::Options options;
72 options += OpenMesh::IO::Options::VertexTexCoord;
73
74 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-texCoords.om",options);
75
76 EXPECT_TRUE(ok) << "Unable to load cube-minimal-texCoords.om";
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 EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
83 EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
84
85 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[0] ) << "Wrong vertex color at vertex 2 component 0";
86 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[1] ) << "Wrong vertex color at vertex 2 component 1";
87
88 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
89 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
90
91 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
92 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
93
94
95 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
96 EXPECT_TRUE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
97 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!";
98
99 mesh_.release_vertex_texcoords2D();
100 }
101
102 /*
103 * Just load an om file of a cube with vertex colors
104 */
105 TEST_F(OpenMeshReadWriteOM, LoadSimpleOMWithVertexColors) {
106
107 mesh_.clear();
108
109 mesh_.request_vertex_colors();
110
111 OpenMesh::IO::Options options;
112 options += OpenMesh::IO::Options::VertexColor;
113
114 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-vertexColors.om",options);
115
116 EXPECT_TRUE(ok) << "Unable to load cube-minimal-vertexColors.om";
117
118 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
119 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
120 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
121
122 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
123 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
124 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
125
126 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
127 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
128 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
129
130 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
131 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
132 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
133
134 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
135 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
136 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
137
138 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
139 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
140 EXPECT_TRUE(options.vertex_has_color()) << "Wrong user options are returned!";
141
142 mesh_.release_vertex_colors();
143 }
144
145 #endif // INCLUDE GUARD