diff --git a/src/Unittests/unittests.cc b/src/Unittests/unittests.cc index 704f5e79..dadd1105 100644 --- a/src/Unittests/unittests.cc +++ b/src/Unittests/unittests.cc @@ -7,6 +7,7 @@ #include "unittests_trimesh_collapse.hh" #include "unittests_trimesh_circulators.hh" #include "unittests_decimater.hh" +#include "unittests_trimesh_normal_calculations.hh" int main(int _argc, char** _argv) { diff --git a/src/Unittests/unittests_trimesh_normal_calculations.hh b/src/Unittests/unittests_trimesh_normal_calculations.hh new file mode 100644 index 00000000..5d74f037 --- /dev/null +++ b/src/Unittests/unittests_trimesh_normal_calculations.hh @@ -0,0 +1,106 @@ +#ifndef INCLUDE_UNITTESTS_NORMAL_CALCULATIONS_HH +#define INCLUDE_UNITTESTS_NORMAL_CALCULATIONS_HH + +#include +#include + +#include + +class OpenMeshNormals : public OpenMeshBase { + + protected: + + // This function is called before each test is run + virtual void SetUp() { + } + + // This function is called after all tests are through + virtual void TearDown() { + + // Do some final stuff with the member data here... + } + + // Member already defined in OpenMeshBase + //Mesh mesh_; +}; + +/* + * ==================================================================== + * Define tests below + * ==================================================================== + */ + +/* + * Collapsing a tetrahedron + */ +TEST_F(OpenMeshNormals, NormalCalculations) { + + mesh_.clear(); + + // Add some vertices + Mesh::VertexHandle vhandle[4]; + + vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0)); + vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0)); + vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0)); + vhandle[3] = mesh_.add_vertex(Mesh::Point(0, 0, 1)); + + // Add four faces + std::vector face_vhandles; + + face_vhandles.push_back(vhandle[0]); + face_vhandles.push_back(vhandle[1]); + face_vhandles.push_back(vhandle[2]); + mesh_.add_face(face_vhandles); + + face_vhandles.clear(); + + face_vhandles.push_back(vhandle[0]); + face_vhandles.push_back(vhandle[2]); + face_vhandles.push_back(vhandle[3]); + mesh_.add_face(face_vhandles); + + face_vhandles.clear(); + + face_vhandles.push_back(vhandle[2]); + face_vhandles.push_back(vhandle[1]); + face_vhandles.push_back(vhandle[3]); + mesh_.add_face(face_vhandles); + + face_vhandles.clear(); + + face_vhandles.push_back(vhandle[3]); + face_vhandles.push_back(vhandle[1]); + face_vhandles.push_back(vhandle[0]); + mesh_.add_face(face_vhandles); + + // =============================================== + // Setup complete + // =============================================== + + + // Check one Request only vertex normals + // Face normals are required for vertex and halfedge normals, so + // This will compute no normals and is only a runtime check if the blocks + // that prevent access to non existing properties are in place + + mesh_.request_vertex_normals(); + mesh_.request_face_normals(); + mesh_.request_halfedge_normals(); + + // Automatically compute all normals + // As only vertex normals are requested and no face normals, this will compute nothing. + mesh_.update_normals(); + + // Face normals alone + mesh_.update_face_normals(); + + // Vertex normals alone (require valid face normals) + mesh_.update_vertex_normals(); + + // Halfedge normals alone (require valid face normals) + mesh_.update_halfedge_normals(); + +} + +#endif // INCLUDE GUARD