unittests_trimesh_circulator_vertex_edge.cc 13.9 KB
Newer Older
1
2
3
4
5
#include <gtest/gtest.h>
#include <Unittests/unittests_common.hh>

#include <iostream>

6
7
namespace {

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class OpenMeshTrimeshCirculatorVertexEdge : public OpenMeshBase {

    protected:

        // This function is called before each test is run
        virtual void SetUp() {
        }

        // This function is called after all tests are through
        virtual void TearDown() {

            // Do some final stuff with the member data here...
        }


    // Member already defined in OpenMeshBase
    //Mesh mesh_;  
};

/*
 * ====================================================================
 * Define tests below
 * ====================================================================
 */

Jan Möbius's avatar
Jan Möbius committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91


/*
 * Small VertexEdgeIterator Test without holes in it
 */
TEST_F(OpenMeshTrimeshCirculatorVertexEdge, VertexEdgeIterWithoutHolesIncrement) {

  mesh_.clear();

  // Add some vertices
  Mesh::VertexHandle vhandle[5];

  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
  vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));

  // Add two faces
  std::vector<Mesh::VertexHandle> face_vhandles;

  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[2]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[3]);
  face_vhandles.push_back(vhandle[4]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[3]);
  face_vhandles.push_back(vhandle[1]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[4]);
  mesh_.add_face(face_vhandles);

  /* Test setup:
      0 ==== 2
      |\  0 /|
      | \  / |
      |2  1 3|
      | /  \ |
      |/  1 \|
      3 ==== 4 */

  // Iterate around vertex 1 at the middle (with holes in between)
  Mesh::VertexEdgeIter ve_it  = mesh_.ve_begin(vhandle[1]);
  Mesh::VertexEdgeIter ve_end = mesh_.ve_end(vhandle[1]);
92
  EXPECT_EQ(5, ve_it->idx() ) << "Index wrong in VertexEdgeIter at initialization";
93
  EXPECT_TRUE(ve_it.is_valid()) << "Iterator invalid in VertexEdgeIter at initialization";
Jan Möbius's avatar
Jan Möbius committed
94
  ++ve_it ;
95
  EXPECT_EQ(3, ve_it->idx() ) << "Index wrong in VertexEdgeIter at step 1";
96
  EXPECT_TRUE(ve_it.is_valid()) << "Iterator invalid in VertexEdgeIter at step 1";
Jan Möbius's avatar
Jan Möbius committed
97
  ++ve_it ;
98
  EXPECT_EQ(0, ve_it->idx() ) << "Index wrong in VertexEdgeIter at step 2";
99
  EXPECT_TRUE(ve_it.is_valid()) << "Iterator invalid in VertexEdgeIter at step 2";
Jan Möbius's avatar
Jan Möbius committed
100
  ++ve_it ;
101
  EXPECT_EQ(1, ve_it->idx() ) << "Index wrong in VertexEdgeIter at step 3";
102
  EXPECT_TRUE(ve_it.is_valid()) << "Iterator invalid in VertexEdgeIter at step 3";
Jan Möbius's avatar
Jan Möbius committed
103
  ++ve_it ;
104
  EXPECT_EQ(5, ve_it->idx() ) << "Index wrong in VertexEdgeIter at end";
105
  EXPECT_FALSE(ve_it.is_valid()) << "Iterator not invalid in VertexEdgeIter at end";
Jan Möbius's avatar
Jan Möbius committed
106
107
108
109
110
  EXPECT_TRUE( ve_it == ve_end )  << "End iterator for VertexEdgeIter not matching";

  // Iterate around vertex 1 at the middle (with holes in between) with const iterator
  Mesh::ConstVertexEdgeIter cve_it  = mesh_.cve_begin(vhandle[1]);
  Mesh::ConstVertexEdgeIter cve_end = mesh_.cve_end(vhandle[1]);
111
  EXPECT_EQ(5, cve_it->idx() ) << "Index wrong in ConstVertexEdgeIter at initialization";
112
  EXPECT_TRUE(cve_it.is_valid()) << "Iterator invalid in ConstVertexEdgeIter at initialization";
Jan Möbius's avatar
Jan Möbius committed
113
  ++cve_it ;
114
  EXPECT_EQ(3, cve_it->idx() ) << "Index wrong in ConstVertexEdgeIter at step 1";
115
  EXPECT_TRUE(cve_it.is_valid()) << "Iterator invalid in ConstVertexEdgeIter at step 1";
Jan Möbius's avatar
Jan Möbius committed
116
  ++cve_it ;
117
  EXPECT_EQ(0, cve_it->idx() ) << "Index wrong in ConstVertexEdgeIter at step 2";
118
  EXPECT_TRUE(cve_it.is_valid()) << "Iterator invalid in ConstVertexEdgeIter at step 2";
Jan Möbius's avatar
Jan Möbius committed
119
  ++cve_it ;
120
  EXPECT_EQ(1, cve_it->idx() ) << "Index wrong in ConstVertexEdgeIter at step 3";
121
  EXPECT_TRUE(cve_it.is_valid()) << "Iterator invalid in ConstVertexEdgeIter at step 3";
Jan Möbius's avatar
Jan Möbius committed
122
  ++cve_it ;
123
  EXPECT_EQ(5, cve_it->idx() ) << "Index wrong in ConstVertexEdgeIter at end";
124
  EXPECT_FALSE(cve_it.is_valid()) << "Iterator not invalid in VertexEdgeIter at end";
Jan Möbius's avatar
Jan Möbius committed
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
  EXPECT_TRUE( cve_it == cve_end )  << "End iterator for ConstVertexEdgeIter not matching";
}

/*
 * Small VertexEdgeIterator Test without holes in it
 */
TEST_F(OpenMeshTrimeshCirculatorVertexEdge, VertexEdgeIterBoundaryIncrement) {

  mesh_.clear();

  // Add some vertices
  Mesh::VertexHandle vhandle[5];

  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
  vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));

  // Add two faces
  std::vector<Mesh::VertexHandle> face_vhandles;

  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[2]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[3]);
  face_vhandles.push_back(vhandle[4]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[3]);
  face_vhandles.push_back(vhandle[1]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[4]);
  mesh_.add_face(face_vhandles);

  /* Test setup:
      0 ==== 2
      |\  0 /|
      | \  / |
      |2  1 3|
      | /  \ |
      |/  1 \|
      3 ==== 4 */

  // Iterate around vertex 1 at the middle (with holes in between)
  Mesh::VertexEdgeIter ve_it  = mesh_.ve_begin(vhandle[2]);
  Mesh::VertexEdgeIter ve_end = mesh_.ve_end(vhandle[2]);
185
  EXPECT_EQ(7, ve_it->idx() ) << "Index wrong in VertexEdgeIter at initialization";
186
  EXPECT_TRUE(ve_it.is_valid()) << "Iterator invalid in VertexEdgeIter at initialization";
Jan Möbius's avatar
Jan Möbius committed
187
  ++ve_it ;
188
  EXPECT_EQ(1, ve_it->idx() ) << "Index wrong in VertexEdgeIter at step 1";
189
  EXPECT_TRUE(ve_it.is_valid()) << "Iterator invalid in VertexEdgeIter at step 1";
Jan Möbius's avatar
Jan Möbius committed
190
  ++ve_it ;
191
  EXPECT_EQ(2, ve_it->idx() ) << "Index wrong in VertexEdgeIter at step 2";
192
  EXPECT_TRUE(ve_it.is_valid()) << "Iterator invalid in VertexEdgeIter at step 2";
Jan Möbius's avatar
Jan Möbius committed
193
  ++ve_it ;
194
  EXPECT_EQ(7, ve_it->idx() ) << "Index wrong in VertexEdgeIter at step 3";
195
  EXPECT_FALSE(ve_it.is_valid()) << "Iterator not invalid in VertexEdgeIter at end";
Jan Möbius's avatar
Jan Möbius committed
196
197
198
199
200
  EXPECT_TRUE( ve_it == ve_end )  << "End iterator for VertexEdgeIter not matching";

}


Jan Möbius's avatar
Jan Möbius committed
201
202
/*
 * Test if the end iterator stays invalid after one lap
203
 * DISABLED as long as the normal iterators using old behavior
Jan Möbius's avatar
Jan Möbius committed
204
 */
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
//TEST_F(OpenMeshTrimeshCirculatorVertexEdge, VertexEdgeIterCheckInvalidationAtEnds) {
//
//  mesh_.clear();
//
//  // Add some vertices
//  Mesh::VertexHandle vhandle[5];
//
//  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
//  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
//  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
//  vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
//  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
//
//  // Add two faces
//  std::vector<Mesh::VertexHandle> face_vhandles;
//
//  face_vhandles.push_back(vhandle[0]);
//  face_vhandles.push_back(vhandle[1]);
//  face_vhandles.push_back(vhandle[2]);
//  Mesh::FaceHandle fh0 = mesh_.add_face(face_vhandles);
//
//  face_vhandles.clear();
//
//  face_vhandles.push_back(vhandle[1]);
//  face_vhandles.push_back(vhandle[3]);
//  face_vhandles.push_back(vhandle[4]);
//  mesh_.add_face(face_vhandles);
//
//  face_vhandles.clear();
//
//  face_vhandles.push_back(vhandle[0]);
//  face_vhandles.push_back(vhandle[3]);
//  face_vhandles.push_back(vhandle[1]);
//  mesh_.add_face(face_vhandles);
//
//  face_vhandles.clear();
//
//  face_vhandles.push_back(vhandle[2]);
//  face_vhandles.push_back(vhandle[1]);
//  face_vhandles.push_back(vhandle[4]);
//  mesh_.add_face(face_vhandles);
//
//  /* Test setup:
//      0 ==== 2
//      |\  0 /|
//      | \  / |
//      |2  1 3|
//      | /  \ |
//      |/  1 \|
//      3 ==== 4 */
//
//
//  // Check if the end iterator stays invalid after end
//  Mesh::VertexEdgeIter endIter = mesh_.ve_end(vhandle[1]);
//  EXPECT_FALSE(endIter.is_valid()) << "EndIter is not invalid";
//  ++endIter ;
//  EXPECT_FALSE(endIter.is_valid()) << "EndIter is not invalid after increment";
//
//  // Check if the end iterators becomes valid after decrement
//  endIter = mesh_.ve_end(vhandle[1]);
//  EXPECT_FALSE(endIter.is_valid()) << "EndIter is not invalid";
//  --endIter;
//  EXPECT_TRUE(endIter.is_valid()) << "EndIter is invalid after decrement";
//  EXPECT_EQ(1,endIter->idx()) << "EndIter points on the wrong element";
//
//
//  // Check if the start iterator decrement is invalid
//  Mesh::VertexEdgeIter startIter = mesh_.ve_begin(vhandle[1]);
//  EXPECT_TRUE(startIter.is_valid()) << "StartIter is not valid";
//  --startIter;
//  EXPECT_FALSE(startIter.is_valid()) << "StartIter decrement is not invalid";
//
//  // Check if the start iterator becomes valid
//  ++startIter;
//  EXPECT_TRUE(startIter.is_valid()) << "StarIter is invalid after re-incrementing";
//  EXPECT_EQ(startIter->idx(), mesh_.ve_begin(vhandle[1])->idx()) << "StartIter points on the wrong element";
//
//}
Jan Möbius's avatar
Jan Möbius committed
283

284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/*
 * Test CW and CCW iterators
 */
TEST_F(OpenMeshTrimeshCirculatorVertexEdge, CWAndCCWCheck) {

  mesh_.clear();

  // Add some vertices
  Mesh::VertexHandle vhandle[5];

  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
  vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));

  // Add two faces
  std::vector<Mesh::VertexHandle> face_vhandles;

  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[2]);
  Mesh::FaceHandle fh0 = mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[3]);
  face_vhandles.push_back(vhandle[4]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[3]);
  face_vhandles.push_back(vhandle[1]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[4]);
  mesh_.add_face(face_vhandles);

  /* Test setup:
      0 ==== 2
      |\  0 /|
      | \  / |
      |2  1 3|
      | /  \ |
      |/  1 \|
      3 ==== 4 */


  int indices[5] = {5, 1, 0, 3, 5};
  int rev_indices[5];
  std::reverse_copy(indices,indices+5,rev_indices);

Matthias Möller's avatar
Matthias Möller committed
343
344
  Mesh::VertexHandle vh = vhandle[1];

345
  //CCW
Matthias Möller's avatar
Matthias Möller committed
346
347
  Mesh::VertexEdgeCCWIter ve_ccwit  = mesh_.ve_ccwbegin(vh);
  Mesh::VertexEdgeCCWIter ve_ccwend = mesh_.ve_ccwend(vh);
348
349
350
351
352
353
354
355
356
357
  size_t i = 0;
  for (;ve_ccwit != ve_ccwend; ++ve_ccwit, ++i)
  {
    EXPECT_EQ(indices[i], ve_ccwit->idx()) << "Index wrong in VertexEdgeCCWIter";
  }

  EXPECT_FALSE(ve_ccwit.is_valid()) << "Iterator invalid in VertexEdgeCCWIter at end";
  EXPECT_TRUE( ve_ccwit == ve_ccwend )  << "End iterator for VertexEdgeCCWIter not matching";

  //constant CCW
Matthias Möller's avatar
Matthias Möller committed
358
359
  Mesh::ConstVertexEdgeCCWIter cve_ccwit  = mesh_.cve_ccwbegin(vh);
  Mesh::ConstVertexEdgeCCWIter cve_ccwend = mesh_.cve_ccwend(vh);
360
361
362
363
364
365
366
367
368
369
  i = 0;
  for (;cve_ccwit != cve_ccwend; ++cve_ccwit, ++i)
  {
    EXPECT_EQ(indices[i], cve_ccwit->idx()) << "Index wrong in ConstVertexEdgeCCWIter";
  }

  EXPECT_FALSE(cve_ccwit.is_valid()) << "Iterator invalid in ConstVertexEdgeCCWIter at end";
  EXPECT_TRUE( cve_ccwit == cve_ccwend )  << "End iterator for ConstVertexEdgeCCWIter not matching";

  //CW
Matthias Möller's avatar
Matthias Möller committed
370
371
  Mesh::VertexEdgeCWIter ve_cwit  = mesh_.ve_cwbegin(vh);
  Mesh::VertexEdgeCWIter ve_cwend = mesh_.ve_cwend(vh);
372
373
374
375
376
377
378
379
380
  i = 0;
  for (;ve_cwit != ve_cwend; ++ve_cwit, ++i)
  {
    EXPECT_EQ(rev_indices[i], ve_cwit->idx()) << "Index wrong in VertexEdgeCWIter";
  }
  EXPECT_FALSE(ve_cwit.is_valid()) << "Iterator invalid in VertexEdgeCWIter at end";
  EXPECT_TRUE( ve_cwit == ve_cwend )  << "End iterator for VertexEdgeCWIter not matching";

  //constant CW
Matthias Möller's avatar
Matthias Möller committed
381
382
  Mesh::ConstVertexEdgeCWIter cve_cwit  = mesh_.cve_cwbegin(vh);
  Mesh::ConstVertexEdgeCWIter cve_cwend = mesh_.cve_cwend(vh);
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
  i = 0;
  for (;cve_cwit != cve_cwend; ++cve_cwit, ++i)
  {
    EXPECT_EQ(rev_indices[i], cve_cwit->idx()) << "Index wrong in ConstVertexEdgeCWIter";
  }
  EXPECT_FALSE(cve_cwit.is_valid()) << "Iterator invalid in ConstVertexEdgeCWIter at end";
  EXPECT_TRUE( cve_cwit == cve_cwend )  << "End iterator for ConstVertexEdgeCWIter not matching";

  /*
   * conversion properties:
   * a) cw_begin == CWIter(ccw_begin())
   * b) cw_iter->idx() == CCWIter(cw_iter)->idx() for valid iterators
   * c) --cw_iter == CWIter(++ccwIter) for valid iterators
   * d) cw_end == CWIter(ccw_end()) => --cw_end != CWIter(++ccw_end())   *
   */
Matthias Möller's avatar
Matthias Möller committed
398
  Mesh::VertexEdgeCWIter ve_cwIter = mesh_.ve_cwbegin(vh);
399
  // a)
Matthias Möller's avatar
Matthias Möller committed
400
401
  EXPECT_TRUE( ve_cwIter == Mesh::VertexEdgeCWIter(mesh_.ve_ccwbegin(vh)) ) << "ccw to cw conversion failed";
  EXPECT_TRUE( Mesh::VertexEdgeCCWIter(ve_cwIter) == mesh_.ve_ccwbegin(vh) ) << "cw to ccw conversion failed";
402
403
404
405
  // b)
  EXPECT_EQ( ve_cwIter->idx(), Mesh::VertexEdgeCCWIter(ve_cwIter)->idx()) << "iterators doesnt point on the same element";
  // c)
  ++ve_cwIter;
Matthias Möller's avatar
Matthias Möller committed
406
  ve_ccwend = mesh_.ve_ccwend(vh);
407
408
409
410
411
412
  --ve_ccwend;
  EXPECT_EQ(ve_cwIter->idx(),ve_ccwend->idx()) << "iteratoes are not equal after inc/dec";
  // additional conversion check
  ve_ccwend = Mesh::VertexEdgeCCWIter(ve_cwIter);
  EXPECT_EQ(ve_cwIter->idx(),ve_ccwend->idx())<< "iterators doesnt point on the same element";
  // d)
Matthias Möller's avatar
Matthias Möller committed
413
  ve_cwIter = Mesh::VertexEdgeCWIter(mesh_.ve_ccwend(vh));
414
  EXPECT_FALSE(ve_cwIter.is_valid()) << "end iterator is not invalid";
Matthias Möller's avatar
Matthias Möller committed
415
  EXPECT_TRUE(Mesh::VertexEdgeCCWIter(mesh_.ve_cwend(vh)) ==  mesh_.ve_ccwend(vh)) << "end iterators are not equal";
416
417
418
419


}

420
}