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_normal_calculations.hh
1 #ifndef INCLUDE_UNITTESTS_NORMAL_CALCULATIONS_HH
2 #define INCLUDE_UNITTESTS_NORMAL_CALCULATIONS_HH
3
4 #include <gtest/gtest.h>
5 #include <Unittests/unittests_common.hh>
6
7 #include <iostream>
8
9 class OpenMeshNormals : 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 * Collapsing a tetrahedron
35 */
36 TEST_F(OpenMeshNormals, NormalCalculations) {
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
89 // Check blocks
90 mesh_.update_normals();
91
92 // Request required face normals
93 mesh_.request_face_normals();
94
95 // Automatically compute all normals
96 // As only vertex normals are requested and no face normals, this will compute nothing.
97 mesh_.update_normals();
98
99 // Face normals alone
100 mesh_.update_face_normals();
101
102 // Vertex normals alone (require valid face normals)
103 mesh_.update_vertex_normals();
104
105 // Halfedge normals alone (require valid face normals)
106 mesh_.update_halfedge_normals();
107
108 }
109
110 #endif // INCLUDE GUARD