Developer Documentation
Loading...
Searching...
No Matches
unittests_iterators.cc
1#include "unittests_common.hh"
2
3
4using namespace OpenVolumeMesh;
5
6TEST_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
24TEST_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 {
56
57 std::set<VertexHandle> onering;
58 int valence = 0;
59
60 for (auto vh : mesh_.vertex_vertices(VertexHandle(0)))
61 {
62 ++valence;
63 onering.insert(vh);
64 }
65
66 // check that there have been three adjacent vertices
67 EXPECT_EQ(3, valence);
68
69 // check that no vertex was visited twice
70 EXPECT_EQ(3u, onering.size());
71
72 // check that no invalid vertex was adjacent
73 EXPECT_EQ(onering.end(), std::find(onering.begin(), onering.end(), VertexHandle(-1)));
74
75 }
76
77}
78
79TEST_F(TetrahedralMeshBase, VertexFaceIteratorTest) {
80
81 generateTetrahedralMesh(mesh_);
82
83 {
84
85 VertexFaceIter vf_it = mesh_.vf_iter(VertexHandle(0));
86
87 EXPECT_TRUE(vf_it.valid());
88
89 std::set<FaceHandle> incident_faces;
90 int valence = 0;
91
92 while (vf_it.valid())
93 {
94 ++valence;
95 incident_faces.insert(*vf_it);
96 ++vf_it;
97 }
98
99 // check that there have been three adjacent vertices
100 EXPECT_EQ(3, valence);
101
102 // check that no vertex was visited twice
103 EXPECT_EQ(3u, incident_faces.size());
104
105 // check that no invalid vertex was adjacent
106 EXPECT_EQ(incident_faces.end(), std::find(incident_faces.begin(), incident_faces.end(), FaceHandle(-1)));
107
108 }
109
110 {
111
112 std::set<VertexHandle> onering;
113 int valence = 0;
114
115 for (auto vh : mesh_.vertex_vertices(VertexHandle(0)))
116 {
117 ++valence;
118 onering.insert(vh);
119 }
120
121 // check that there have been three adjacent vertices
122 EXPECT_EQ(3, valence);
123
124 // check that no vertex was visited twice
125 EXPECT_EQ(3u, onering.size());
126
127 // check that no invalid vertex was adjacent
128 EXPECT_EQ(onering.end(), std::find(onering.begin(), onering.end(), VertexHandle(-1)));
129
130 }
131
132}
133
134TEST_F(HexahedralMeshBase, RangeForTest) {
135 // no EXPECTs here, if it compiles, it'll work.
136 generateHexahedralMesh(mesh_);
137 VertexHandle _dummy; // use vh to avoid compiler warnings
138 for (const auto& vh: mesh_.vertices()) { _dummy = vh;}
139 const auto& constref = mesh_;
140 for (const auto& vh: constref.vertices()) { _dummy = vh;}
141}
Iterate over all vertices of a hexahedron in a specific order.