OpenMesh

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

- File List
- File Members

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