Developer Documentation
unittests_smarttagger.cc
1 #include <gtest/gtest.h>
2 #include <Unittests/unittests_common.hh>
3 #include <iostream>
4 #include <OpenMesh/Tools/SmartTagger/SmartTaggerT.hh>
5 
6 namespace {
7 
8 class OpenMeshSmartTagger : 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 /* Checks SmartTagger on vertices
35  */
36 TEST_F(OpenMeshSmartTagger, SmartTaggerVertices) {
37 
38  mesh_.clear();
39 
40  // Add some vertices
41  Mesh::VertexHandle vhandle[7];
42 
43  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
44  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
45  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
46  vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
47  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
48  vhandle[5] = mesh_.add_vertex(Mesh::Point(3, 0, 0));
49 
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  face_vhandles.clear();
81 
82  face_vhandles.push_back(vhandle[5]);
83  face_vhandles.push_back(vhandle[2]);
84  face_vhandles.push_back(vhandle[4]);
85  mesh_.add_face(face_vhandles);
86 
87  /* Test setup:
88  0 ==== 2
89  |\ /|\
90  | \ / | \
91  | 1 | 5
92  | / \ | /
93  |/ \|/
94  3 ==== 4
95 
96  */
97 
98 
99  OpenMesh::SmartTaggerVT< Mesh > tagger(mesh_);
100 
101 
102  EXPECT_FALSE( tagger.is_tagged(vhandle[0] ) ) << "Vertex should be untagged after init!";
103  EXPECT_FALSE( tagger.is_tagged(vhandle[1] ) ) << "Vertex should be untagged after init!";
104  EXPECT_FALSE( tagger.is_tagged(vhandle[2] ) ) << "Vertex should be untagged after init!";
105  EXPECT_FALSE( tagger.is_tagged(vhandle[3] ) ) << "Vertex should be untagged after init!";
106  EXPECT_FALSE( tagger.is_tagged(vhandle[4] ) ) << "Vertex should be untagged after init!";
107  EXPECT_FALSE( tagger.is_tagged(vhandle[5] ) ) << "Vertex should be untagged after init!";
108 
109  // Reset tagged flag on all vertices
110  tagger.untag_all();
111 
112  EXPECT_FALSE( tagger.is_tagged(vhandle[0] ) ) << "Vertex should be untagged after first untag_all!";
113  EXPECT_FALSE( tagger.is_tagged(vhandle[1] ) ) << "Vertex should be untagged after first untag_all!";
114  EXPECT_FALSE( tagger.is_tagged(vhandle[2] ) ) << "Vertex should be untagged after first untag_all!";
115  EXPECT_FALSE( tagger.is_tagged(vhandle[3] ) ) << "Vertex should be untagged after first untag_all!";
116  EXPECT_FALSE( tagger.is_tagged(vhandle[4] ) ) << "Vertex should be untagged after first untag_all!";
117  EXPECT_FALSE( tagger.is_tagged(vhandle[5] ) ) << "Vertex should be untagged after first untag_all!";
118 
119 
120  // Set tagged:
121  tagger.set_tag(vhandle[2]);
122  tagger.set_tag(vhandle[4]);
123 
124  EXPECT_FALSE( tagger.is_tagged(vhandle[0] ) ) << "Vertex should be untagged!";
125  EXPECT_FALSE( tagger.is_tagged(vhandle[1] ) ) << "Vertex should be untagged!";
126  EXPECT_TRUE( tagger.is_tagged(vhandle[2] ) ) << "Vertex should be tagged!";
127  EXPECT_FALSE( tagger.is_tagged(vhandle[3] ) ) << "Vertex should be untagged!";
128  EXPECT_TRUE( tagger.is_tagged(vhandle[4] ) ) << "Vertex should be tagged!";
129  EXPECT_FALSE( tagger.is_tagged(vhandle[5] ) ) << "Vertex should be untagged!";
130 
131  // Reset tagged flag on all vertices
132  tagger.untag_all();
133 
134  EXPECT_FALSE( tagger.is_tagged(vhandle[0] ) ) << "Vertex should be untagged after second untag_all!";
135  EXPECT_FALSE( tagger.is_tagged(vhandle[1] ) ) << "Vertex should be untagged after second untag_all!";
136  EXPECT_FALSE( tagger.is_tagged(vhandle[2] ) ) << "Vertex should be untagged after second untag_all!";
137  EXPECT_FALSE( tagger.is_tagged(vhandle[3] ) ) << "Vertex should be untagged after second untag_all!";
138  EXPECT_FALSE( tagger.is_tagged(vhandle[4] ) ) << "Vertex should be untagged after second untag_all!";
139  EXPECT_FALSE( tagger.is_tagged(vhandle[5] ) ) << "Vertex should be untagged after second untag_all!";
140 
141 }
142 
143 /* Checks SmartTagger on vertices
144  */
145 TEST_F(OpenMeshSmartTagger, SmartTaggerFaces) {
146 
147  mesh_.clear();
148 
149  // Add some vertices
150  Mesh::VertexHandle vhandle[7];
151 
152  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
153  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
154  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
155  vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
156  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
157  vhandle[5] = mesh_.add_vertex(Mesh::Point(3, 0, 0));
158 
159 
160  // Add two faces
161  std::vector<Mesh::VertexHandle> face_vhandles;
162 
163  face_vhandles.push_back(vhandle[0]);
164  face_vhandles.push_back(vhandle[1]);
165  face_vhandles.push_back(vhandle[2]);
166  Mesh::FaceHandle fh1 = mesh_.add_face(face_vhandles);
167 
168  face_vhandles.clear();
169 
170  face_vhandles.push_back(vhandle[1]);
171  face_vhandles.push_back(vhandle[3]);
172  face_vhandles.push_back(vhandle[4]);
173  Mesh::FaceHandle fh2 = mesh_.add_face(face_vhandles);
174 
175  face_vhandles.clear();
176 
177  face_vhandles.push_back(vhandle[0]);
178  face_vhandles.push_back(vhandle[3]);
179  face_vhandles.push_back(vhandle[1]);
180  Mesh::FaceHandle fh3 = mesh_.add_face(face_vhandles);
181 
182  face_vhandles.clear();
183 
184  face_vhandles.push_back(vhandle[2]);
185  face_vhandles.push_back(vhandle[1]);
186  face_vhandles.push_back(vhandle[4]);
187  Mesh::FaceHandle fh4 = mesh_.add_face(face_vhandles);
188 
189  face_vhandles.clear();
190 
191  face_vhandles.push_back(vhandle[5]);
192  face_vhandles.push_back(vhandle[2]);
193  face_vhandles.push_back(vhandle[4]);
194  Mesh::FaceHandle fh5 = mesh_.add_face(face_vhandles);
195 
196  /* Test setup:
197  0 ==== 2
198  |\ /|\
199  | \ / | \
200  | 1 | 5
201  | / \ | /
202  |/ \|/
203  3 ==== 4
204 
205  */
206 
207 
208  OpenMesh::SmartTaggerFT< Mesh > tagger(mesh_);
209 
210 
211  EXPECT_FALSE( tagger.is_tagged( fh1 ) ) << "Face should be untagged after init!";
212  EXPECT_FALSE( tagger.is_tagged( fh2 ) ) << "Face should be untagged after init!";
213  EXPECT_FALSE( tagger.is_tagged( fh3 ) ) << "Face should be untagged after init!";
214  EXPECT_FALSE( tagger.is_tagged( fh4 ) ) << "Face should be untagged after init!";
215  EXPECT_FALSE( tagger.is_tagged( fh5 ) ) << "Face should be untagged after init!";
216 
217 
218  // Reset tagged flag on all vertices
219  tagger.untag_all();
220 
221  EXPECT_FALSE( tagger.is_tagged( fh1 ) ) << "Face should be untagged after first untag_all!";
222  EXPECT_FALSE( tagger.is_tagged( fh2 ) ) << "Face should be untagged after first untag_all!";
223  EXPECT_FALSE( tagger.is_tagged( fh3 ) ) << "Face should be untagged after first untag_all!";
224  EXPECT_FALSE( tagger.is_tagged( fh4 ) ) << "Face should be untagged after first untag_all!";
225  EXPECT_FALSE( tagger.is_tagged( fh5 ) ) << "Face should be untagged after first untag_all!";
226 
227 
228 
229  // Set tagged:
230  tagger.set_tag(fh3);
231  tagger.set_tag(fh5);
232 
233 
234  EXPECT_FALSE( tagger.is_tagged(fh1 ) ) << "Face should be untagged!";
235  EXPECT_FALSE( tagger.is_tagged(fh2 ) ) << "Face should be untagged!";
236  EXPECT_TRUE( tagger.is_tagged(fh3 ) ) << "Face should be tagged!";
237  EXPECT_FALSE( tagger.is_tagged(fh4 ) ) << "Face should be tagged!";
238  EXPECT_TRUE( tagger.is_tagged(fh5 ) ) << "Face should be tagged!";
239 
240 
241  // Reset tagged flag on all vertices
242  tagger.untag_all();
243 
244  EXPECT_FALSE( tagger.is_tagged( fh1 ) ) << "Face should be untagged after second untag_all!";
245  EXPECT_FALSE( tagger.is_tagged( fh2 ) ) << "Face should be untagged after second untag_all!";
246  EXPECT_FALSE( tagger.is_tagged( fh3 ) ) << "Face should be untagged after second untag_all!";
247  EXPECT_FALSE( tagger.is_tagged( fh4 ) ) << "Face should be untagged after second untag_all!";
248  EXPECT_FALSE( tagger.is_tagged( fh5 ) ) << "Face should be untagged after second untag_all!";
249 
250 }
251 
252 }
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:112
SmartVertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:235
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:136