Developer Documentation

unittests_split_copy.cc
1
2 #include <gtest/gtest.h>
3 #include <Unittests/unittests_common.hh>
4 #include <iostream>
5
6 namespace {
7
8 class OpenMeshSplitCopyTriangleMesh : 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 OpenMeshSplitCopyPolyMesh : 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 a face that has a property in a triangle mesh with split_copy
55 * the property should be copied to the new faces
56 */
57 TEST_F(OpenMeshSplitCopyTriangleMesh, SplitCopyTriangleMesh) {
58
59 mesh_.clear();
60 mesh_.request_face_status();
61 mesh_.request_edge_status();
62
63 // Add some vertices
64 Mesh::VertexHandle vhandle[5];
65
66 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
67 vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
68 vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
69 vhandle[3] = mesh_.add_vertex(Mesh::Point(0.25, 0.25, 0));
70 vhandle[4] = mesh_.add_vertex(Mesh::Point(0.5, 0.5, 0));
71
72 // Add one face
73 std::vector<Mesh::VertexHandle> face_vhandles;
74
75 face_vhandles.push_back(vhandle[2]);
76 face_vhandles.push_back(vhandle[1]);
77 face_vhandles.push_back(vhandle[0]);
78
79 Mesh::FaceHandle fh = mesh_.add_face(face_vhandles);
80 Mesh::EdgeHandle eh = *mesh_.edges_begin();
81
82 // Test setup:
83 // 1 === 2
84 // | /
85 // | /
86 // | /
87 // 0
88
89 // set property
90 OpenMesh::FPropHandleT<int> fprop_int;
91 mesh_.add_property(fprop_int);
92 mesh_.property(fprop_int, fh) = 999;
93 //set internal property
94 mesh_.status(fh).set_tagged(true);
95
96 // split face with new vertex
97 mesh_.split_copy(fh, vhandle[3]);
98
99 // Check setup
100 Mesh::FaceIter f_it = mesh_.faces_begin();
101 Mesh::FaceIter f_end = mesh_.faces_end();
102 for (; f_it != f_end; ++f_it)
103 {
104 EXPECT_EQ(999, mesh_.property(fprop_int, *f_it)) << "Different Property value";
105 EXPECT_TRUE(mesh_.status(*f_it).tagged()) << "Different internal property value";
106 }
107
108 //check the function overload for edgehandles
109 OpenMesh::EPropHandleT<int> eprop_int;
110 mesh_.add_property(eprop_int);
111 mesh_.property(eprop_int, eh) = 999;
112 //set internal property
113 mesh_.status(eh).set_feature(true);
114 //split edge with new vertex
115 mesh_.split_copy(eh, vhandle[4]);
116 // Check setup
117 Mesh::EdgeHandle eh0 = mesh_.edge_handle( mesh_.next_halfedge_handle( mesh_.halfedge_handle(eh, 1) ) );
118 EXPECT_EQ(999, mesh_.property(eprop_int, eh0)) << "Different Property value";
119 EXPECT_TRUE(mesh_.status(eh0).feature()) << "Different internal property value";
120 }
121
122 /* splits a face that has a property in a poly mesh with split_copy
123 * the property should be copied to the new faces
124 */
125 TEST_F(OpenMeshSplitCopyPolyMesh, SplitCopyPolymesh) {
126
127 mesh_.clear();
128 mesh_.request_face_status();
129
130 // Add some vertices
131 Mesh::VertexHandle vhandle[5];
132
133 vhandle[0] = mesh_.add_vertex(PolyMesh::Point(0, 0, 0));
134 vhandle[1] = mesh_.add_vertex(PolyMesh::Point(0, 1, 0));
135 vhandle[2] = mesh_.add_vertex(PolyMesh::Point(1, 1, 0));
136 vhandle[3] = mesh_.add_vertex(PolyMesh::Point(1, 0, 0));
137 vhandle[4] = mesh_.add_vertex(PolyMesh::Point(0.5, 0.5, 0));
138
139 // Add face
140 std::vector<Mesh::VertexHandle> face_vhandles;
141
142 face_vhandles.push_back(vhandle[0]);
143 face_vhandles.push_back(vhandle[1]);
144 face_vhandles.push_back(vhandle[2]);
145 face_vhandles.push_back(vhandle[3]);
146
147 PolyMesh::FaceHandle fh = mesh_.add_face(face_vhandles);
148
149 // Test setup:
150 // 1 === 2
151 // | |
152 // | |
153 // | |
154 // 0 === 3
155
156 // set property
157 OpenMesh::FPropHandleT<int> fprop_int;
158 mesh_.add_property(fprop_int);
159 mesh_.property(fprop_int, fh) = 999;
160 //set internal property
161 mesh_.status(fh).set_tagged(true);
162
163 // split face with new vertex
164 mesh_.split_copy(fh, vhandle[4]);
165
166 // Check setup
167 PolyMesh::FaceIter f_it = mesh_.faces_begin();
168 PolyMesh::FaceIter f_end = mesh_.faces_end();
169 for (; f_it != f_end; ++f_it)
170 {
171 EXPECT_EQ(999, mesh_.property(fprop_int, *f_it)) << "Different Property value";
172 EXPECT_TRUE(mesh_.status(*f_it).tagged()) << "Different internal property value";
173 }
174
175 }
176 }
OpenMesh::EPropHandleT
Definition: Property.hh:510
OpenMesh::PolyMeshT::Point
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:112
OpenMesh::PolyMeshT::add_vertex
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:235
OpenMesh::TriMeshT::split_copy
VertexHandle split_copy(EdgeHandle _eh, const Point &_p)
Edge split (= 2-to-4 split)
Definition: TriMeshT.hh:281
OpenMesh::PolyMeshT::VertexHandle
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:136
OpenMeshBase
Definition: unittests_common.hh:26
OpenMeshBasePoly
Definition: unittests_common.hh:50
OpenMesh::FPropHandleT
Definition: Property.hh:524