Developer Documentation

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
unittests_cpp_11_features.cc
1
2 #include <gtest/gtest.h>
3 #include <Unittests/unittests_common.hh>
4 //#include <OpenMesh/Tools/Smoother/JacobiLaplaceSmootherT.hh>
5
6 namespace {
7
8 class OpenMesh_Poly : public OpenMeshBasePoly {
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 class OpenMesh_Triangle : public OpenMeshBase {
29
30 protected:
31
32 // This function is called before each test is run
33 virtual void SetUp() {
34
35 // Do some initial stuff with the member data here...
36 }
37
38 // This function is called after all tests are through
39 virtual void TearDown() {
40
41 // Do some final stuff with the member data here...
42 }
43
44 // Member already defined in OpenMeshBase
45 //Mesh mesh_;
46 };
47
48
49
50 /*
51 * ====================================================================
52 * Define tests below
53 * ====================================================================
54 */
55
56 #if _MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
57
58 /*
59 */
60 TEST_F(OpenMesh_Triangle, cpp11_initializer_test) {
61
62 OpenMesh::Vec3d vec1 = { 1, 0, 0};
63 OpenMesh::Vec3d vec2 = {0, 0.777971, 0.996969};
64
65
66 EXPECT_EQ( dot(vec1,vec2) ,0.0 );
67
68 }
69
70
71 // ////////////////////////////////////////////////////////////////////
72 // C++11 Range tests
73 // ////////////////////////////////////////////////////////////////////
74
75
79 TEST_F(OpenMesh_Triangle, cpp11_vertexrange_test) {
80 //check empty vertexrange
81 mesh_.clear();
82 for(Mesh::VertexHandle t : mesh_.vertices())
83 {
84 FAIL() << "The Vertexrange for an empty Mesh is not empty";
85 EXPECT_TRUE(t.is_valid()); // Just so we don't get an unused variable warning.
86 }
87
88 //add vertices to mesh
89 mesh_.add_vertex(Mesh::Point(0, 1, 0));
90 mesh_.add_vertex(Mesh::Point(1, 0, 0));
91 mesh_.add_vertex(Mesh::Point(2, 1, 0));
92 mesh_.add_vertex(Mesh::Point(0,-1, 0));
93 mesh_.add_vertex(Mesh::Point(2,-1, 0));
94
95 //check nonempty mesh vertexrange
96 int iteration_counter = 0;
97 for(Mesh::VertexHandle t : mesh_.vertices())
98 {
99 EXPECT_TRUE(t.is_valid());
100 ++iteration_counter;
101 }
102 EXPECT_EQ(iteration_counter,5);
103 }
104
108 TEST_F(OpenMesh_Poly, cpp11_vertexrange_test) {
109 //check empty vertexrange
110 mesh_.clear();
111 for(PolyMesh::VertexHandle t : mesh_.vertices())
112 {
113 FAIL() << "The Vertexrange for an empty Mesh is not empty";
114 EXPECT_TRUE(t.is_valid()); // Just so we don't get an unused variable warning.
115 }
116
117 //add vertices to mesh
118 mesh_.add_vertex(PolyMesh::Point(0, 1, 0));
119 mesh_.add_vertex(PolyMesh::Point(1, 0, 0));
120 mesh_.add_vertex(PolyMesh::Point(2, 1, 0));
121 mesh_.add_vertex(PolyMesh::Point(0,-1, 0));
122 mesh_.add_vertex(PolyMesh::Point(2,-1, 0));
123
124 //check nonempty mesh vertexrange
125 int iteration_counter = 0;
126 for(PolyMesh::VertexHandle t : mesh_.vertices())
127 {
128 EXPECT_TRUE(t.is_valid());
129 ++iteration_counter;
130 }
131 EXPECT_EQ(iteration_counter,5);
132 }
133
137 TEST_F(OpenMesh_Triangle, cpp11_vvrange_test) {
138 //check empty vv_range
139 mesh_.clear();
140 Mesh::VertexHandle vhandle[5];
141 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
142 for(Mesh::VertexHandle t : mesh_.vv_range(vhandle[0]))
143 {
144 FAIL() << "The vvrange for a single vertex in a TriMesh is not empty";
145 EXPECT_TRUE(t.is_valid()); // Just so we don't get an unused variable warning.
146 }
147
148 //add more vertices
149 vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
150 vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
151 vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
152 vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
153
154 // Add 4 faces
155 std::vector<Mesh::VertexHandle> face_vhandles;
156
157 face_vhandles.push_back(vhandle[0]);
158 face_vhandles.push_back(vhandle[1]);
159 face_vhandles.push_back(vhandle[2]);
160 mesh_.add_face(face_vhandles);
161
162 face_vhandles.clear();
163
164 face_vhandles.push_back(vhandle[1]);
165 face_vhandles.push_back(vhandle[3]);
166 face_vhandles.push_back(vhandle[4]);
167 mesh_.add_face(face_vhandles);
168
169 face_vhandles.clear();
170
171 face_vhandles.push_back(vhandle[0]);
172 face_vhandles.push_back(vhandle[3]);
173 face_vhandles.push_back(vhandle[1]);
174 mesh_.add_face(face_vhandles);
175
176 face_vhandles.clear();
177
178 face_vhandles.push_back(vhandle[2]);
179 face_vhandles.push_back(vhandle[1]);
180 face_vhandles.push_back(vhandle[4]);
181 mesh_.add_face(face_vhandles);
182
183 //check nonempty vvrange
184 int iteration_counter = 0;
185 for(Mesh::VertexHandle t : mesh_.vv_range(vhandle[1]))
186 {
187 EXPECT_TRUE(t.is_valid());
188 ++iteration_counter;
189 }
190 EXPECT_EQ(iteration_counter,4);
191 }
192
196 TEST_F(OpenMesh_Poly, cpp11_vvrange_test) {
197 //check empty vv_range
198 mesh_.clear();
199 Mesh::VertexHandle vhandle[5];
200 vhandle[0] = mesh_.add_vertex(PolyMesh::Point(0, 1, 0));
201 for(PolyMesh::VertexHandle t : mesh_.vv_range(vhandle[0]))
202 {
203 FAIL() << "The vvrange for a single vertex in a PolyMesh is not empty";
204 EXPECT_TRUE(t.is_valid()); // Just so we don't get an unused variable warning.
205 }
206
207 //add more vertices
208 vhandle[1] = mesh_.add_vertex(PolyMesh::Point(1, 0, 0));
209 vhandle[2] = mesh_.add_vertex(PolyMesh::Point(2, 1, 0));
210 vhandle[3] = mesh_.add_vertex(PolyMesh::Point(0,-1, 0));
211 vhandle[4] = mesh_.add_vertex(PolyMesh::Point(2,-1, 0));
212
213 // Add 4 faces
214 std::vector<PolyMesh::VertexHandle> face_vhandles;
215
216 face_vhandles.push_back(vhandle[0]);
217 face_vhandles.push_back(vhandle[1]);
218 face_vhandles.push_back(vhandle[2]);
219 mesh_.add_face(face_vhandles);
220
221 face_vhandles.clear();
222
223 face_vhandles.push_back(vhandle[1]);
224 face_vhandles.push_back(vhandle[3]);
225 face_vhandles.push_back(vhandle[4]);
226 mesh_.add_face(face_vhandles);
227
228 face_vhandles.clear();
229
230 face_vhandles.push_back(vhandle[0]);
231 face_vhandles.push_back(vhandle[3]);
232 face_vhandles.push_back(vhandle[1]);
233 mesh_.add_face(face_vhandles);
234
235 face_vhandles.clear();
236
237 face_vhandles.push_back(vhandle[2]);
238 face_vhandles.push_back(vhandle[1]);
239 face_vhandles.push_back(vhandle[4]);
240 mesh_.add_face(face_vhandles);
241
242 //check nonempty vvrange
243 int iteration_counter = 0;
244 for(PolyMesh::VertexHandle t : mesh_.vv_range(vhandle[1]))
245 {
246 EXPECT_TRUE(t.is_valid());
247 ++iteration_counter;
248 }
249 EXPECT_EQ(iteration_counter,4);
250 }
251
252 #endif
253
254 }
OpenMeshBasePoly
Definition: unittests_common.hh:45
OpenMesh::VectorT::dot
Scalar dot(const VectorT< Scalar, N > &_v1, const VectorT< Scalar, N > &_v2)
Definition: MeshNode2T.cc:263
OpenMeshBase
Definition: unittests_common.hh:21
OpenMesh::PolyMeshT::Point
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:115
OpenMesh::PolyMeshT::add_vertex
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:236
OpenMesh::VectorT
Definition: Vector11T.hh:83
OpenMesh::PolyMeshT::VertexHandle
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:139