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_trimesh_circulator_vertex_edge.hh
1 #pragma once
2
3 #include <gtest/gtest.h>
4 #include <Unittests/unittests_common.hh>
5
6 #include <iostream>
7
8 class OpenMeshTrimeshCirculatorVertexEdge : public OpenMeshBase {
9
10 protected:
11
12 // This function is called before each test is run
13 virtual void SetUp() {
14 }
15
16 // This function is called after all tests are through
17 virtual void TearDown() {
18
19 // Do some final stuff with the member data here...
20 }
21
22
23 // Member already defined in OpenMeshBase
24 //Mesh mesh_;
25 };
26
27 /*
28 * ====================================================================
29 * Define tests below
30 * ====================================================================
31 */
32
33
34
35 /*
36 * Small VertexEdgeIterator Test without holes in it
37 */
38 TEST_F(OpenMeshTrimeshCirculatorVertexEdge, VertexEdgeIterWithoutHolesIncrement) {
39
40 mesh_.clear();
41
42 // Add some vertices
43 Mesh::VertexHandle vhandle[5];
44
45 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
46 vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
47 vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
48 vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
49 vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
50
51 // Add two faces
52 std::vector<Mesh::VertexHandle> face_vhandles;
53
54 face_vhandles.push_back(vhandle[0]);
55 face_vhandles.push_back(vhandle[1]);
56 face_vhandles.push_back(vhandle[2]);
57 mesh_.add_face(face_vhandles);
58
59 face_vhandles.clear();
60
61 face_vhandles.push_back(vhandle[1]);
62 face_vhandles.push_back(vhandle[3]);
63 face_vhandles.push_back(vhandle[4]);
64 mesh_.add_face(face_vhandles);
65
66 face_vhandles.clear();
67
68 face_vhandles.push_back(vhandle[0]);
69 face_vhandles.push_back(vhandle[3]);
70 face_vhandles.push_back(vhandle[1]);
71 mesh_.add_face(face_vhandles);
72
73 face_vhandles.clear();
74
75 face_vhandles.push_back(vhandle[2]);
76 face_vhandles.push_back(vhandle[1]);
77 face_vhandles.push_back(vhandle[4]);
78 mesh_.add_face(face_vhandles);
79
80 /* Test setup:
81 0 ==== 2
82 |\ 0 /|
83 | \ / |
84 |2 1 3|
85 | / \ |
86 |/ 1 \|
87 3 ==== 4 */
88
89 // Iterate around vertex 1 at the middle (with holes in between)
90 Mesh::VertexEdgeIter ve_it = mesh_.ve_begin(vhandle[1]);
91 Mesh::VertexEdgeIter ve_end = mesh_.ve_end(vhandle[1]);
92 EXPECT_EQ(5, ve_it.handle().idx() ) << "Index wrong in VertexEdgeIter at initialization";
93 EXPECT_TRUE(ve_it) << "Iterator invalid in VertexEdgeIter at initialization";
94 ++ve_it ;
95 EXPECT_EQ(3, ve_it.handle().idx() ) << "Index wrong in VertexEdgeIter at step 1";
96 EXPECT_TRUE(ve_it) << "Iterator invalid in VertexEdgeIter at step 1";
97 ++ve_it ;
98 EXPECT_EQ(0, ve_it.handle().idx() ) << "Index wrong in VertexEdgeIter at step 2";
99 EXPECT_TRUE(ve_it) << "Iterator invalid in VertexEdgeIter at step 2";
100 ++ve_it ;
101 EXPECT_EQ(1, ve_it.handle().idx() ) << "Index wrong in VertexEdgeIter at step 3";
102 EXPECT_TRUE(ve_it) << "Iterator invalid in VertexEdgeIter at step 3";
103 ++ve_it ;
104 EXPECT_EQ(5, ve_it.handle().idx() ) << "Index wrong in VertexEdgeIter at end";
105 EXPECT_FALSE(ve_it) << "Iterator not invalid in VertexEdgeIter at end";
106 EXPECT_TRUE( ve_it == ve_end ) << "End iterator for VertexEdgeIter not matching";
107
108 // Iterate around vertex 1 at the middle (with holes in between) with const iterator
109 Mesh::ConstVertexEdgeIter cve_it = mesh_.cve_begin(vhandle[1]);
110 Mesh::ConstVertexEdgeIter cve_end = mesh_.cve_end(vhandle[1]);
111 EXPECT_EQ(5, cve_it.handle().idx() ) << "Index wrong in ConstVertexEdgeIter at initialization";
112 EXPECT_TRUE(cve_it) << "Iterator invalid in ConstVertexEdgeIter at initialization";
113 ++cve_it ;
114 EXPECT_EQ(3, cve_it.handle().idx() ) << "Index wrong in ConstVertexEdgeIter at step 1";
115 EXPECT_TRUE(cve_it) << "Iterator invalid in ConstVertexEdgeIter at step 1";
116 ++cve_it ;
117 EXPECT_EQ(0, cve_it.handle().idx() ) << "Index wrong in ConstVertexEdgeIter at step 2";
118 EXPECT_TRUE(cve_it) << "Iterator invalid in ConstVertexEdgeIter at step 2";
119 ++cve_it ;
120 EXPECT_EQ(1, cve_it.handle().idx() ) << "Index wrong in ConstVertexEdgeIter at step 3";
121 EXPECT_TRUE(cve_it) << "Iterator invalid in ConstVertexEdgeIter at step 3";
122 ++cve_it ;
123 EXPECT_EQ(5, cve_it.handle().idx() ) << "Index wrong in ConstVertexEdgeIter at end";
124 EXPECT_FALSE(cve_it) << "Iterator not invalid in VertexEdgeIter at end";
125 EXPECT_TRUE( cve_it == cve_end ) << "End iterator for ConstVertexEdgeIter not matching";
126 }
127
128 /*
129 * Small VertexEdgeIterator Test without holes in it
130 */
131 TEST_F(OpenMeshTrimeshCirculatorVertexEdge, VertexEdgeIterBoundaryIncrement) {
132
133 mesh_.clear();
134
135 // Add some vertices
136 Mesh::VertexHandle vhandle[5];
137
138 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
139 vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
140 vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
141 vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
142 vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
143
144 // Add two faces
145 std::vector<Mesh::VertexHandle> face_vhandles;
146
147 face_vhandles.push_back(vhandle[0]);
148 face_vhandles.push_back(vhandle[1]);
149 face_vhandles.push_back(vhandle[2]);
150 mesh_.add_face(face_vhandles);
151
152 face_vhandles.clear();
153
154 face_vhandles.push_back(vhandle[1]);
155 face_vhandles.push_back(vhandle[3]);
156 face_vhandles.push_back(vhandle[4]);
157 mesh_.add_face(face_vhandles);
158
159 face_vhandles.clear();
160
161 face_vhandles.push_back(vhandle[0]);
162 face_vhandles.push_back(vhandle[3]);
163 face_vhandles.push_back(vhandle[1]);
164 mesh_.add_face(face_vhandles);
165
166 face_vhandles.clear();
167
168 face_vhandles.push_back(vhandle[2]);
169 face_vhandles.push_back(vhandle[1]);
170 face_vhandles.push_back(vhandle[4]);
171 mesh_.add_face(face_vhandles);
172
173 /* Test setup:
174 0 ==== 2
175 |\ 0 /|
176 | \ / |
177 |2 1 3|
178 | / \ |
179 |/ 1 \|
180 3 ==== 4 */
181
182 // Iterate around vertex 1 at the middle (with holes in between)
183 Mesh::VertexEdgeIter ve_it = mesh_.ve_begin(vhandle[2]);
184 Mesh::VertexEdgeIter ve_end = mesh_.ve_end(vhandle[2]);
185 EXPECT_EQ(7, ve_it.handle().idx() ) << "Index wrong in VertexEdgeIter at initialization";
186 EXPECT_TRUE(ve_it) << "Iterator invalid in VertexEdgeIter at initialization";
187 ++ve_it ;
188 EXPECT_EQ(1, ve_it.handle().idx() ) << "Index wrong in VertexEdgeIter at step 1";
189 EXPECT_TRUE(ve_it) << "Iterator invalid in VertexEdgeIter at step 1";
190 ++ve_it ;
191 EXPECT_EQ(2, ve_it.handle().idx() ) << "Index wrong in VertexEdgeIter at step 2";
192 EXPECT_TRUE(ve_it) << "Iterator invalid in VertexEdgeIter at step 2";
193 ++ve_it ;
194 EXPECT_EQ(7, ve_it.handle().idx() ) << "Index wrong in VertexEdgeIter at step 3";
195 EXPECT_FALSE(ve_it) << "Iterator not invalid in VertexEdgeIter at end";
196 EXPECT_TRUE( ve_it == ve_end ) << "End iterator for VertexEdgeIter not matching";
197
198 }
199
200
201
202
203