Skip to content
Snippets Groups Projects
Commit e23ba988 authored by Tom Fischer's avatar Tom Fischer
Browse files

[MeL] Remove unused projectMeshOntoPlane.

parent 00384ee3
No related branches found
No related tags found
No related merge requests found
......@@ -33,7 +33,6 @@
#include "MeshLib/Elements/FaceRule.h"
#include "MeshLib/Node.h"
#include "MeshLib/MeshSurfaceExtraction.h"
#include "MeshLib/MeshEditing/projectMeshOntoPlane.h"
#include "MeshLib/MeshSearch/MeshElementGrid.h"
namespace MeshGeoToolsLib {
......
/**
* \file
* \author Karsten Rink
* \date 2015-04-10
* \brief Definition of the projectMeshOntoPlane
*
* \copyright
* Copyright (c) 2012-2020, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#pragma once
#include <vector>
#include "MathLib/MathTools.h"
#include "MathLib/Point3d.h"
#include "MathLib/Vector3.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/Node.h"
#include "MeshLib/MeshEditing/DuplicateMeshComponents.h"
namespace MeshLib {
/**
* Projects all nodes of a mesh onto a plane specified by a point of origin and a normal vector.
* Overlapping elements, collapsed nodes, and other issues are not handled by the method.
* The normal vector need not be normalized.
*/
inline
MeshLib::Mesh* projectMeshOntoPlane(MeshLib::Mesh const& mesh,
MathLib::Point3d const& plane_origin,
MathLib::Vector3 const& plane_normal)
{
std::size_t const n_nodes (mesh.getNumberOfNodes());
std::vector<MeshLib::Node*> const& nodes (mesh.getNodes());
Eigen::Vector3d normal({plane_normal[0], plane_normal[1], plane_normal[2]});
normal.normalize();
std::vector<MeshLib::Node*> new_nodes;
new_nodes.reserve(n_nodes);
for (std::size_t i=0; i<n_nodes; ++i)
{
auto const node =
Eigen::Map<Eigen::Vector3d const>(nodes[i]->getCoords());
Eigen::Vector3d const v =
node - Eigen::Map<Eigen::Vector3d const>(plane_origin.getCoords());
double const dist(v.dot(normal));
Eigen::Vector3d const new_node = node - dist * normal;
new_nodes.push_back(
new MeshLib::Node(new_node[0], new_node[1], new_node[2]));
}
return new MeshLib::Mesh("Projected_Mesh", new_nodes,
MeshLib::copyElementVector(mesh.getElements(), new_nodes));
}
} // end namespace MeshLib
/**
* \file
* \author Karsten Rink
* \date 2015-04-16
* \brief Tests for projectMeshOnPlane
*
* \copyright
* Copyright (c) 2012-2020, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*/
#include <memory>
#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<MeshLib::Node*> nodes;
for (std::size_t i = 1; i <= n_nodes; i++)
{
nodes.push_back(new MeshLib::Node(static_cast<double>(i),
static_cast<double>(i), i * 0.5));
}
std::vector<MeshLib::Element*> elements;
for (std::size_t i = 0; i < n_nodes - 1; i++)
{
elements.push_back(new MeshLib::Line(
std::array<MeshLib::Node*, 2>{{nodes[i], nodes[i + 1]}}));
}
_mesh = std::make_unique<MeshLib::Mesh>("TestMesh", nodes, elements);
}
protected:
std::unique_ptr<MeshLib::Mesh> _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<double,3>{{0,0,static_cast<double>(p)}});
MeshLib::Mesh* result = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal);
for (std::size_t i = 0; i < n_nodes; i++)
{
ASSERT_NEAR(static_cast<double>(p), (*result->getNode(i))[2],
std::numeric_limits<double>::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<double,3>{{0,static_cast<double>(p),0}});
MeshLib::Mesh* result = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal);
for (std::size_t i = 0; i < n_nodes; i++)
{
ASSERT_NEAR(static_cast<double>(p), (*result->getNode(i))[1],
std::numeric_limits<double>::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<double,3>{{static_cast<double>(p),0,0}});
MeshLib::Mesh* result = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal);
for (std::size_t i = 0; i < n_nodes; i++)
{
ASSERT_NEAR(static_cast<double>(p), (*result->getNode(i))[0],
std::numeric_limits<double>::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<double,3>{{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; i < n_nodes; i++)
{
ASSERT_EQ((*result_p->getNode(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<double,3>{{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<double>(p);
MeshLib::Mesh* result_p = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal);
for (std::size_t i = 0; i < n_nodes; i++)
{
ASSERT_EQ((*result->getNode(i))[2], (*result_p->getNode(i))[2]);
}
delete result_p;
}
delete result;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment