Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
unittests_trimesh_others.cc
1 #include <gtest/gtest.h>
2 #include <Unittests/unittests_common.hh>
3
4 #include <iostream>
5
6 namespace {
7
8 class OpenMeshOthers : public OpenMeshBase {
9
10 protected:
11
12 // This function is called before each test is run
13 virtual void SetUp() {
14 }
15
16 // This function is called after all tests are through
17 virtual void TearDown() {
18
19 // Do some final stuff with the member data here...
20 }
21
22 // Member already defined in OpenMeshBase
23 //Mesh mesh_;
24 };
25
26 /*
27 * ====================================================================
28 * Define tests below
29 * ====================================================================
30 */
31
32 /*
33 * Checking for feature edges based on angle
34 */
35 TEST_F(OpenMeshOthers, IsEstimatedFeatureEdge) {
36
37 mesh_.clear();
38
39 // Add some vertices
40 Mesh::VertexHandle vhandle[4];
41
42 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
43 vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
44 vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
45 vhandle[3] = mesh_.add_vertex(Mesh::Point(0, 0, 1));
46
47 // Add four faces
48 std::vector<Mesh::VertexHandle> face_vhandles;
49
50 face_vhandles.push_back(vhandle[0]);
51 face_vhandles.push_back(vhandle[1]);
52 face_vhandles.push_back(vhandle[2]);
53 mesh_.add_face(face_vhandles);
54
55 face_vhandles.clear();
56
57 face_vhandles.push_back(vhandle[0]);
58 face_vhandles.push_back(vhandle[2]);
59 face_vhandles.push_back(vhandle[3]);
60 mesh_.add_face(face_vhandles);
61
62 face_vhandles.clear();
63
64 face_vhandles.push_back(vhandle[2]);
65 face_vhandles.push_back(vhandle[1]);
66 face_vhandles.push_back(vhandle[3]);
67 mesh_.add_face(face_vhandles);
68
69 face_vhandles.clear();
70
71 face_vhandles.push_back(vhandle[3]);
72 face_vhandles.push_back(vhandle[1]);
73 face_vhandles.push_back(vhandle[0]);
74 mesh_.add_face(face_vhandles);
75
76 // ===============================================
77 // Setup complete
78 // ===============================================
79
80
81 // Check one Request only vertex normals
82 // Face normals are required for vertex and halfedge normals, so
83 // that prevent access to non existing properties are in place
84
85 mesh_.request_vertex_normals();
86 mesh_.request_halfedge_normals();
87 mesh_.request_face_normals();
88
89 // Automatically compute all normals
90 // As only vertex normals are requested and no face normals, this will compute nothing.
91 mesh_.update_normals();
92
93 Mesh::HalfedgeIter he_it = mesh_.halfedges_begin();
94
95 EXPECT_TRUE(mesh_.is_estimated_feature_edge(*he_it,0.0)) << "Wrong feature edge detection 0.0";
96
97 EXPECT_TRUE(mesh_.is_estimated_feature_edge(*he_it,0.125 * M_PI)) << "Wrong feature edge detection 0.125";
98
99 EXPECT_TRUE(mesh_.is_estimated_feature_edge(*he_it,0.25 * M_PI)) << "Wrong feature edge detection 0.25";
100
101 EXPECT_TRUE(mesh_.is_estimated_feature_edge(*he_it,0.375 * M_PI)) << "Wrong feature edge detection 0.375";
102
103 EXPECT_TRUE(mesh_.is_estimated_feature_edge(*he_it,0.5 * M_PI)) << "Wrong feature edge detection 0.5";
104
105 EXPECT_FALSE(mesh_.is_estimated_feature_edge(*he_it,0.625 * M_PI))<< "Wrong feature edge detection 0.625";
106
107 EXPECT_FALSE(mesh_.is_estimated_feature_edge(*he_it,0.75 * M_PI)) << "Wrong feature edge detection 0.75";
108
109 EXPECT_FALSE(mesh_.is_estimated_feature_edge(*he_it,0.875 * M_PI))<< "Wrong feature edge detection 0.875";
110
111 EXPECT_FALSE(mesh_.is_estimated_feature_edge(*he_it,1.0 * M_PI)) << "Wrong feature edge detection 1.0";
112
113 }
114
115 /*
116 * Checking for feature edges based on angle
117 */
118 TEST_F(OpenMeshOthers, CalcDihedralAngre ) {
119
120 mesh_.clear();
121
122 /* Test setup:
123 *
124 * 1 -- 2
125 * | / |
126 * | / |
127 * 0 -- 3
128 */
129
130 // Add some vertices
131 Mesh::VertexHandle vhandle[4];
132
133 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
134 vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
135 vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
136 vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
137
138 // Add four faces
139 std::vector<Mesh::VertexHandle> face_vhandles;
140
141 face_vhandles.push_back(vhandle[0]);
142 face_vhandles.push_back(vhandle[1]);
143 face_vhandles.push_back(vhandle[2]);
144 mesh_.add_face(face_vhandles);
145
146 face_vhandles.clear();
147
148 face_vhandles.push_back(vhandle[0]);
149 face_vhandles.push_back(vhandle[2]);
150 face_vhandles.push_back(vhandle[3]);
151 mesh_.add_face(face_vhandles);
152
153 // ===============================================
154 // Setup complete
155 // ===============================================
156
157 Mesh::HalfedgeHandle he = mesh_.halfedge_handle(4);
158
159 EXPECT_EQ( 0 , mesh_.to_vertex_handle(he).idx() ) << "Wrong halfedge!" << std::endl;
160 EXPECT_EQ( 2 , mesh_.from_vertex_handle(he).idx() ) << "Wrong halfedge!" << std::endl;
161 EXPECT_EQ( 2 , mesh_.edge_handle(he).idx() ) << "Wrong Edge!" << std::endl;
162
163 Mesh::EdgeHandle eh = mesh_.edge_handle(he);
164 EXPECT_EQ( 0.0 , mesh_.calc_dihedral_angle(eh) ) << "Wrong Dihedral angle!" << std::endl;
165
166 // Modify point
167 Mesh::Point tmp = ( Mesh::Point(0.0, 0.0, -1.0) + Mesh::Point(1.0, 1.0, -1.0) ) * 0.5;
168 mesh_.point(vhandle[2]) = tmp;
169
170 double difference = fabs( 1.36944 - mesh_.calc_dihedral_angle(eh) );
171
172 EXPECT_LT(difference, 0.00001) << "Wrong Dihedral angle, Difference is to big!" << std::endl;
173
174 }
175 }
OpenMeshBase
Definition: unittests_common.hh:21
OpenMesh::PolyMeshT::Point
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:115
OpenMesh::PolyMeshT::add_vertex
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:236
OpenMesh::PolyMeshT::VertexHandle
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:139
OpenMesh::PolyMeshT::update_normals
void update_normals()
Compute normals for all primitives.
Definition: PolyMeshT.cc:241
OpenMesh::PolyMeshT::is_estimated_feature_edge
bool is_estimated_feature_edge(HalfedgeHandle _heh, const double _feature_angle) const
Definition: PolyMeshT.cc:342