Developer Documentation
unittests_iterators.cc
1 #include "unittests_common.hh"
2 
3 
4 using namespace OpenVolumeMesh;
5 
6 TEST_F(HexahedralMeshBase, HexVertexIterTest) {
7 
8  generateHexahedralMesh(mesh_);
9 
10  HexVertexIter hv_it = mesh_.hv_iter(CellHandle(0));
11 
12  EXPECT_TRUE(hv_it.valid());
13 
14  EXPECT_HANDLE_EQ(VertexHandle(0), *hv_it); ++hv_it;
15  EXPECT_HANDLE_EQ(VertexHandle(1), *hv_it); ++hv_it;
16  EXPECT_HANDLE_EQ(VertexHandle(2), *hv_it); ++hv_it;
17  EXPECT_HANDLE_EQ(VertexHandle(3), *hv_it); ++hv_it;
18  EXPECT_HANDLE_EQ(VertexHandle(4), *hv_it); ++hv_it;
19  EXPECT_HANDLE_EQ(VertexHandle(7), *hv_it); ++hv_it;
20  EXPECT_HANDLE_EQ(VertexHandle(6), *hv_it); ++hv_it;
21  EXPECT_HANDLE_EQ(VertexHandle(5), *hv_it);
22 }
23 
24 TEST_F(TetrahedralMeshBase, VertexVertexIteratorTest) {
25 
26  generateTetrahedralMesh(mesh_);
27 
28  {
29 
30  VertexVertexIter vv_it = mesh_.vv_iter(VertexHandle(0));
31 
32  EXPECT_TRUE(vv_it.valid());
33 
34  std::set<VertexHandle> onering;
35  int valence = 0;
36 
37  while (vv_it.valid())
38  {
39  ++valence;
40  onering.insert(*vv_it);
41  ++vv_it;
42  }
43 
44  // check that there have been three adjacent vertices
45  EXPECT_EQ(3, valence);
46 
47  // check that no vertex was visited twice
48  EXPECT_EQ(3u, onering.size());
49 
50  // check that no invalid vertex was adjacent
51  EXPECT_EQ(onering.end(), std::find(onering.begin(), onering.end(), VertexHandle(-1)));
52 
53  }
54 
55 #if __cplusplus >= 201103L || _MSC_VER >= 1800 // C++11
56  {
57 
58  std::set<VertexHandle> onering;
59  int valence = 0;
60 
61  for (auto vh : mesh_.vertex_vertices(VertexHandle(0)))
62  {
63  ++valence;
64  onering.insert(vh);
65  }
66 
67  // check that there have been three adjacent vertices
68  EXPECT_EQ(3, valence);
69 
70  // check that no vertex was visited twice
71  EXPECT_EQ(3u, onering.size());
72 
73  // check that no invalid vertex was adjacent
74  EXPECT_EQ(onering.end(), std::find(onering.begin(), onering.end(), VertexHandle(-1)));
75 
76  }
77 #endif
78 
79 }
80 
81 TEST_F(TetrahedralMeshBase, VertexFaceIteratorTest) {
82 
83  generateTetrahedralMesh(mesh_);
84 
85  {
86 
87  VertexFaceIter vf_it = mesh_.vf_iter(VertexHandle(0));
88 
89  EXPECT_TRUE(vf_it.valid());
90 
91  std::set<FaceHandle> incident_faces;
92  int valence = 0;
93 
94  while (vf_it.valid())
95  {
96  ++valence;
97  incident_faces.insert(*vf_it);
98  ++vf_it;
99  }
100 
101  // check that there have been three adjacent vertices
102  EXPECT_EQ(3, valence);
103 
104  // check that no vertex was visited twice
105  EXPECT_EQ(3u, incident_faces.size());
106 
107  // check that no invalid vertex was adjacent
108  EXPECT_EQ(incident_faces.end(), std::find(incident_faces.begin(), incident_faces.end(), FaceHandle(-1)));
109 
110  }
111 
112 #if __cplusplus >= 201103L || _MSC_VER >= 1800 // C++11
113  {
114 
115  std::set<VertexHandle> onering;
116  int valence = 0;
117 
118  for (auto vh : mesh_.vertex_vertices(VertexHandle(0)))
119  {
120  ++valence;
121  onering.insert(vh);
122  }
123 
124  // check that there have been three adjacent vertices
125  EXPECT_EQ(3, valence);
126 
127  // check that no vertex was visited twice
128  EXPECT_EQ(3u, onering.size());
129 
130  // check that no invalid vertex was adjacent
131  EXPECT_EQ(onering.end(), std::find(onering.begin(), onering.end(), VertexHandle(-1)));
132 
133  }
134 #endif
135 
136 }
137 
138 #if __cplusplus >= 201103L || _MSC_VER >= 1800 // C++11
139 TEST_F(HexahedralMeshBase, RangeForTest) {
140  // no EXPECTs here, if it compiles, it'll work.
141  generateHexahedralMesh(mesh_);
142  VertexHandle _dummy; // use vh to avoid compiler warnings
143  for (const auto& vh: mesh_.vertices()) { _dummy = vh;}
144  const auto& constref = mesh_;
145  for (const auto& vh: constref.vertices()) { _dummy = vh;}
146 }
147 #endif
Iterate over all vertices of a hexahedron in a specific order.