/** * @file TestProjectMeshOnPlane.cpp * @author Karsten Rink * @date 2015-04-16 * @brief Tests for projectMeshOnPlane * * @copyright * Copyright (c) 2012-2017, OpenGeoSys Community (http://www.opengeosys.org) * Distributed under a Modified BSD License. * See accompanying file LICENSE.txt or * http://www.opengeosys.org/LICENSE.txt */ #include #include "gtest/gtest.h" #include "MeshLib/Elements/Element.h" #include "MeshLib/Elements/Line.h" #include "MeshLib/Mesh.h" #include "MeshLib/MeshEditing/projectMeshOntoPlane.h" #include "MeshLib/Node.h" class ProjectionTest : public ::testing::Test { public: ProjectionTest() : _mesh(nullptr) { std::size_t const n_nodes (100); std::vector nodes; for (std::size_t i=1; i<=n_nodes; i++) nodes.push_back(new MeshLib::Node(static_cast(i), static_cast(i), i*0.5)); std::vector elements; for (std::size_t i=0; i{{nodes[i], nodes[i+1]}})); _mesh = std::unique_ptr{new MeshLib::Mesh{"TestMesh", nodes, elements}}; } protected: std::unique_ptr _mesh; }; // Project to parallels of XY plane TEST_F(ProjectionTest, ProjectToXY) { MathLib::Vector3 normal (0,0,1); std::size_t const n_nodes (_mesh->getNumberOfNodes()); for (std::size_t p=0; p<10; p++) { MathLib::Point3d origin (std::array{{0,0,static_cast(p)}}); MeshLib::Mesh* result = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal); for (std::size_t i=0; i(p), (*result->getNode(i))[2], std::numeric_limits::epsilon()); delete result; } } // Project to parallels of XZ plane TEST_F(ProjectionTest, ProjectToXZ) { MathLib::Vector3 normal (0,1,0); std::size_t const n_nodes (_mesh->getNumberOfNodes()); for (std::size_t p=0; p<10; p++) { MathLib::Point3d origin (std::array{{0,static_cast(p),0}}); MeshLib::Mesh* result = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal); for (std::size_t i=0; i(p), (*result->getNode(i))[1], std::numeric_limits::epsilon()); delete result; } } // Project to parallels of YZ plane TEST_F(ProjectionTest, ProjectToYZ) { MathLib::Vector3 normal (1,0,0); std::size_t const n_nodes (_mesh->getNumberOfNodes()); for (std::size_t p=0; p<10; p++) { MathLib::Point3d origin (std::array{{static_cast(p),0,0}}); MeshLib::Mesh* result = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal); for (std::size_t i=0; i(p), (*result->getNode(i))[0], std::numeric_limits::epsilon()); delete result; } } // Sign of normal vector does not matter. TEST_F(ProjectionTest, NormalDirection) { MathLib::Vector3 normal_p (0,0,1); MathLib::Vector3 normal_n (0,0,-1); std::size_t const n_nodes (_mesh->getNumberOfNodes()); MathLib::Point3d origin (std::array{{0,0,0}}); MeshLib::Mesh* result_p = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal_p); MeshLib::Mesh* result_n = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal_n); for (std::size_t i=0; igetNode(i))[2], (*result_n->getNode(i))[2]); delete result_p; delete result_n; } // Length of normal does not matter (it's normalised within the method) TEST_F(ProjectionTest, NormalLength) { MathLib::Point3d origin (std::array{{0,0,0}}); MathLib::Vector3 normal (0,0,1); std::size_t const n_nodes (_mesh->getNumberOfNodes()); MeshLib::Mesh* result = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal); for (std::size_t p=2; p<10; p++) { normal[2] = static_cast(p); MeshLib::Mesh* result_p = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal); for (std::size_t i=0; igetNode(i))[2], (*result_p->getNode(i))[2]); delete result_p; } delete result; }