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_vertex.hh
1 #pragma once
2
3 #include <gtest/gtest.h>
4 #include <Unittests/unittests_common.hh>
5
6 #include <iostream>
7
8 class OpenMeshTrimeshCirculatorVertexVertex : 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 VertexFaceOutgoingHalfedgeIterator Test without holes in it
37 */
38 TEST_F(OpenMeshTrimeshCirculatorVertexVertex, VertexVertexIncrement) {
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 // Starting vertex is 1->4
89
90
91 // Iterate around vertex 1 at the middle (with holes in between)
92 Mesh::VertexVertexIter vv_it = mesh_.vv_begin(vhandle[1]);
93 Mesh::VertexVertexIter vv_end = mesh_.vv_end(vhandle[1]);
94
95 EXPECT_EQ(4, vv_it.handle().idx() ) << "Index wrong in VertexVertexIter begin at initialization";
96 EXPECT_EQ(4, vv_end.handle().idx() ) << "Index wrong in VertexVertexIter end at initialization";
97 EXPECT_TRUE(vv_it) << "Iterator invalid in VertexVertexIter at initialization";
98
99 ++vv_it ;
100
101 EXPECT_EQ(3, vv_it.handle().idx() ) << "Index wrong in VertexVertexIter step 1";
102 EXPECT_TRUE(vv_it) << "Iterator invalid in VertexVertexIter at step 1";
103
104 ++vv_it ;
105
106 EXPECT_EQ(0, vv_it.handle().idx() ) << "Index wrong in VertexVertexIter step 2";
107 EXPECT_TRUE(vv_it) << "Iterator invalid in VertexVertexIter at step 2";
108
109 ++vv_it ;
110
111 EXPECT_EQ(2, vv_it.handle().idx() ) << "Index wrong in VertexVertexIter step 3";
112 EXPECT_TRUE(vv_it) << "Iterator invalid in VertexVertexIter at step 3";
113
114 ++vv_it ;
115
116 EXPECT_EQ(4, vv_it.handle().idx() ) << "Index wrong in VertexVertexIter step 4";
117 EXPECT_FALSE(vv_it) << "Iterator still valid in VertexVertexIter at step 4";
118 EXPECT_TRUE( vv_it == vv_end ) << "Miss matched end iterator";
119
120 }
121
122 /*
123 * Small VertexFaceOutgoingHalfedgeIterator Test at boundary vertex
124 */
125 TEST_F(OpenMeshTrimeshCirculatorVertexVertex, VertexVertexBoundaryIncrement) {
126
127 mesh_.clear();
128
129 // Add some vertices
130 Mesh::VertexHandle vhandle[5];
131
132 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
133 vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
134 vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
135 vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
136 vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
137
138 // Add two faces
139 std::vector<Mesh::VertexHandle> face_vhandles;
140
141 face_vhandles.push_back(vhandle[0]);
142 face_vhandles.push_back(vhandle[1]);
143 face_vhandles.push_back(vhandle[2]);
144 mesh_.add_face(face_vhandles);
145
146 face_vhandles.clear();
147
148 face_vhandles.push_back(vhandle[1]);
149 face_vhandles.push_back(vhandle[3]);
150 face_vhandles.push_back(vhandle[4]);
151 mesh_.add_face(face_vhandles);
152
153 face_vhandles.clear();
154
155 face_vhandles.push_back(vhandle[0]);
156 face_vhandles.push_back(vhandle[3]);
157 face_vhandles.push_back(vhandle[1]);
158 mesh_.add_face(face_vhandles);
159
160 face_vhandles.clear();
161
162 face_vhandles.push_back(vhandle[2]);
163 face_vhandles.push_back(vhandle[1]);
164 face_vhandles.push_back(vhandle[4]);
165 mesh_.add_face(face_vhandles);
166
167 /* Test setup:
168 0 ==== 2
169 |\ 0 /|
170 | \ / |
171 |2 1 3|
172 | / \ |
173 |/ 1 \|
174 3 ==== 4 */
175 // Starting vertex is 1->4
176
177
178 // Iterate around vertex 1 at the middle (with holes in between)
179 Mesh::VertexVertexIter vv_it = mesh_.vv_begin(vhandle[2]);
180 Mesh::VertexVertexIter vv_end = mesh_.vv_end(vhandle[2]);
181
182 EXPECT_EQ(4, vv_it.handle().idx() ) << "Index wrong in VertexVertexIter begin at initialization";
183 EXPECT_EQ(4, vv_end.handle().idx() ) << "Index wrong in VertexVertexIter end at initialization";
184 EXPECT_TRUE(vv_it) << "Iterator invalid in VertexVertexIter at initialization";
185
186 ++vv_it ;
187
188 EXPECT_EQ(1, vv_it.handle().idx() ) << "Index wrong in VertexVertexIter step 1";
189 EXPECT_TRUE(vv_it) << "Iterator invalid in VertexVertexIter at step 1";
190
191 ++vv_it ;
192
193 EXPECT_EQ(0, vv_it.handle().idx() ) << "Index wrong in VertexVertexIter step 2";
194 EXPECT_TRUE(vv_it) << "Iterator invalid in VertexVertexIter at step 2";
195
196 ++vv_it ;
197
198 EXPECT_EQ(4, vv_it.handle().idx() ) << "Index wrong in VertexVertexIter step 3";
199 EXPECT_FALSE(vv_it) << "Iterator invalid in VertexVertexIter at step 3";
200 EXPECT_TRUE( vv_it == vv_end ) << "Miss matched end iterator";
201
202 }