Developer Documentation

unittests_split_edge_copy.cc
1
2 #include <gtest/gtest.h>
3 #include <Unittests/unittests_common.hh>
4 #include <iostream>
5
6 namespace {
7
8 class OpenMeshSplitEdgeCopyTriangleMesh : 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 class OpenMeshSplitEdgeCopyPolyMesh : public OpenMeshBasePoly {
29
30 protected:
31
32 // This function is called before each test is run
33 virtual void SetUp() {
34
35 // Do some initial stuff with the member data here...
36 }
37
38 // This function is called after all tests are through
39 virtual void TearDown() {
40
41 // Do some final stuff with the member data here...
42 }
43
44 // Member already defined in OpenMeshBase
45 //Mesh mesh_;
46 };
47
48 /*
49 * ====================================================================
50 * Define tests below
51 * ====================================================================
52 */
53
54 /* splits an edge that has a property in a triangle mesh with split_edge_copy
55 * the property should be copied to the new edge
56 */
57 TEST_F(OpenMeshSplitEdgeCopyTriangleMesh, SplitEdgeCopyTriangleMesh) {
58
59 mesh_.clear();
60 mesh_.request_edge_status();
61
62 // Add some vertices
63 Mesh::VertexHandle vhandle[4];
64
65 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
66 vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
67 vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
68 vhandle[3] = mesh_.add_vertex(Mesh::Point(0.25, 0.25, 0));
69
70 // Add one face
71 std::vector<Mesh::VertexHandle> face_vhandles;
72
73 face_vhandles.push_back(vhandle[2]);
74 face_vhandles.push_back(vhandle[1]);
75 face_vhandles.push_back(vhandle[0]);
76
77 Mesh::FaceHandle fh = mesh_.add_face(face_vhandles);
78 Mesh::EdgeHandle eh = *mesh_.edges_begin();
79
80 // Test setup:
81 // 1 === 2
82 // | /
83 // | /
84 // | /
85 // 0
86
87 // set property
88 OpenMesh::EPropHandleT<int> eprop_int;
89 mesh_.add_property(eprop_int);
90 mesh_.property(eprop_int, eh) = 999;
91 //set internal property
92 mesh_.status(eh).set_tagged(true);
93
94 // split edge with new vertex
95 mesh_.split_copy(eh, vhandle[3]);
96
97 // Check setup
98 Mesh::EdgeHandle eh0 = mesh_.edge_handle( mesh_.next_halfedge_handle( mesh_.halfedge_handle(eh, 1) ) );
99 EXPECT_EQ(999, mesh_.property(eprop_int, eh0)) << "Different Property value";
100 EXPECT_TRUE(mesh_.status(eh0).tagged()) << "Different internal property value";
101
102 EXPECT_EQ(3u, mesh_.valence(fh)) << "Face of TriMesh has valence other than 3";
103 }
104
105 /* splits an edge that has a property in a poly mesh with split_edge_copy
106 * the property should be copied to the new faces
107 */
108 TEST_F(OpenMeshSplitEdgeCopyPolyMesh, SplitEdgeCopyPolymesh) {
109
110 mesh_.clear();
111 mesh_.request_edge_status();
112
113 // Add some vertices
114 Mesh::VertexHandle vhandle[5];
115
116 vhandle[0] = mesh_.add_vertex(PolyMesh::Point(0, 0, 0));
117 vhandle[1] = mesh_.add_vertex(PolyMesh::Point(0, 1, 0));
118 vhandle[2] = mesh_.add_vertex(PolyMesh::Point(1, 1, 0));
119 vhandle[3] = mesh_.add_vertex(PolyMesh::Point(1, 0, 0));
120 vhandle[4] = mesh_.add_vertex(PolyMesh::Point(0.5, 0.5, 0));
121
122 // Add face
123 std::vector<Mesh::VertexHandle> face_vhandles;
124
125 face_vhandles.push_back(vhandle[0]);
126 face_vhandles.push_back(vhandle[1]);
127 face_vhandles.push_back(vhandle[2]);
128 face_vhandles.push_back(vhandle[3]);
129
130 mesh_.add_face(face_vhandles);
131 PolyMesh::EdgeHandle eh = *mesh_.edges_begin();
132
133 // Test setup:
134 // 1 === 2
135 // | |
136 // | |
137 // | |
138 // 0 === 3
139
140 // set property
141 OpenMesh::EPropHandleT<int> eprop_int;
142 mesh_.add_property(eprop_int);
143 mesh_.property(eprop_int, eh) = 999;
144 //set internal property
145 mesh_.status(eh).set_tagged(true);
146
147
148 // split face with new vertex
149 mesh_.split_edge_copy(eh, vhandle[4]);
150
151
152 // Check setup
153 Mesh::EdgeHandle eh0 = mesh_.edge_handle( mesh_.next_halfedge_handle( mesh_.halfedge_handle(eh, 1) ) );
154 EXPECT_EQ(999, mesh_.property(eprop_int, eh0)) << "Different Property value";
155 EXPECT_TRUE(mesh_.status(eh0).tagged()) << "Different internal property value";
156 }
157
158
159 /* splits an edge in a triangle mesh that has a face property with split_edge_copy
160 * the property should be copied to the new edge
161 */
162 TEST_F(OpenMeshSplitEdgeCopyTriangleMesh, SplitEdgeCopyFacePropertiesTriangleMesh) {
163
164 mesh_.clear();
165 mesh_.request_edge_status();
166 mesh_.request_face_status();
167
168 static_assert(std::is_same<decltype (mesh_), Mesh>::value, "Mesh is not a triangle mesh");
169
170 // Add some vertices
171 Mesh::VertexHandle vhandle[4];
172
173 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
174 vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
175 vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
176 vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
177
178 Mesh::VertexHandle inner_vertex = mesh_.add_vertex(Mesh::Point(0.5, 0.5, 0));
179 Mesh::VertexHandle boundary_vertex = mesh_.add_vertex(Mesh::Point(0.0, 0.5, 0));
180
181 // Add two faces
182 std::vector<Mesh::VertexHandle> face_vhandles;
183 face_vhandles.push_back(vhandle[2]);
184 face_vhandles.push_back(vhandle[1]);
185 face_vhandles.push_back(vhandle[0]);
186
187 Mesh::FaceHandle fh0 = mesh_.add_face(face_vhandles);
188
189 face_vhandles.clear();
190 face_vhandles.push_back(vhandle[2]);
191 face_vhandles.push_back(vhandle[0]);
192 face_vhandles.push_back(vhandle[3]);
193
194 Mesh::FaceHandle fh1 = mesh_.add_face(face_vhandles);
195
196 Mesh::EdgeHandle inner_edge = Mesh::EdgeHandle(2);
197
198 EXPECT_EQ(mesh_.n_faces(), 2u);
199
200 // Test setup:
201 // 1 --- 2
202 // | / |
203 // | / |
204 // | / |
205 // 0 --- 3
206
207 // set property
208 OpenMesh::FPropHandleT<int> fprop_int;
209 mesh_.add_property(fprop_int);
210 mesh_.property(fprop_int, fh0) = 13;
211 mesh_.property(fprop_int, fh1) = 17;
212 //set internal property
213 mesh_.status(fh0).set_tagged(true);
214
215 // 2 to 4 split
216 mesh_.split_copy(inner_edge, inner_vertex);
217
218 EXPECT_EQ(mesh_.n_faces(), 4u);
219
220 for (auto fh : mesh_.faces())
221 {
222 EXPECT_EQ(3u, mesh_.valence(fh));
223 }
224
225 // Check setup
226 Mesh::HalfedgeHandle heh21 = mesh_.find_halfedge(vhandle[2], vhandle[1]);
227 Mesh::HalfedgeHandle heh10 = mesh_.find_halfedge(vhandle[1], vhandle[0]);
228 Mesh::HalfedgeHandle heh03 = mesh_.find_halfedge(vhandle[0], vhandle[3]);
229 Mesh::HalfedgeHandle heh32 = mesh_.find_halfedge(vhandle[3], vhandle[2]);
230
231 EXPECT_EQ(13, mesh_.property(fprop_int, mesh_.face_handle(heh21))) << "Different Property value";
232 EXPECT_EQ(13, mesh_.property(fprop_int, mesh_.face_handle(heh10))) << "Different Property value";
233 EXPECT_EQ(17, mesh_.property(fprop_int, mesh_.face_handle(heh03))) << "Different Property value";
234 EXPECT_EQ(17, mesh_.property(fprop_int, mesh_.face_handle(heh32))) << "Different Property value";
235 EXPECT_TRUE(mesh_.status(mesh_.face_handle(heh21)).tagged()) << "Different internal property value";
236 EXPECT_TRUE(mesh_.status(mesh_.face_handle(heh10)).tagged()) << "Different internal property value";
237 EXPECT_FALSE(mesh_.status(mesh_.face_handle(heh03)).tagged()) << "Different internal property value";
238 EXPECT_FALSE(mesh_.status(mesh_.face_handle(heh32)).tagged()) << "Different internal property value";
239
240 // also test boundary split
241 Mesh::EdgeHandle boundary_edge = mesh_.edge_handle(heh10);
242
243 // 1 to 2 split
244 mesh_.split_copy(boundary_edge, boundary_vertex);
245
246 Mesh::HalfedgeHandle heh1b = mesh_.find_halfedge(vhandle[1], boundary_vertex);
247 Mesh::HalfedgeHandle hehb0 = mesh_.find_halfedge(boundary_vertex, vhandle[0]);
248
249 EXPECT_EQ(13, mesh_.property(fprop_int, mesh_.face_handle(heh1b))) << "Different Property value";
250 EXPECT_EQ(13, mesh_.property(fprop_int, mesh_.face_handle(hehb0))) << "Different Property value";
251 EXPECT_TRUE(mesh_.status(mesh_.face_handle(heh1b)).tagged()) << "Different internal property value";
252 EXPECT_TRUE(mesh_.status(mesh_.face_handle(hehb0)).tagged()) << "Different internal property value";
253 }
254
255 }
OpenMesh::TriMeshT::split_copy
SmartVertexHandle split_copy(EdgeHandle _eh, const Point &_p)
Edge split (= 2-to-4 split)
Definition: TriMeshT.hh:281
OpenMesh::EPropHandleT
Definition: Property.hh:514
OpenMesh::PolyMeshT::Point
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:112
OpenMesh::TriMesh_ArrayKernelT
Definition: PolyMesh_ArrayKernelT.hh:73
OpenMeshBasePoly
Definition: unittests_common.hh:53
OpenMesh::PolyMeshT::add_vertex
SmartVertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:235
OpenMeshBase
Definition: unittests_common.hh:29
OpenMesh::FPropHandleT
Definition: Property.hh:529
OpenMesh::PolyMeshT::VertexHandle
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:136