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

Merge pull request #453 from norihiro-w/add-getmeshnode

Add a general node searching function for any geometric types
parents 3248e200 499867db
No related branches found
No related tags found
No related merge requests found
......@@ -39,7 +39,7 @@ MeshNodeSearcher::MeshNodeSearcher(MeshLib::Mesh const& mesh) :
it != elements.cend(); ++it) {
std::size_t const n_edges((*it)->getNEdges());
for (std::size_t k(0); k<n_edges; k++) {
MeshLib::Line const* edge(dynamic_cast<MeshLib::Line const*>((*it)->getEdge(k)));
MeshLib::Line const* edge(static_cast<MeshLib::Line const*>((*it)->getEdge(k)));
if (!edge) {
delete edge;
continue;
......@@ -75,9 +75,35 @@ MeshNodeSearcher::~MeshNodeSearcher()
}
}
std::size_t MeshNodeSearcher::getMeshNodeIDForPoint(GeoLib::Point const& pnt) const
std::vector<std::size_t> MeshNodeSearcher::getMeshNodeIDs(GeoLib::GeoObject const& geoObj)
{
return (_mesh_grid.getNearestPoint(pnt.getCoords()))->getID();
std::vector<std::size_t> vec_nodes;
switch (geoObj.getGeoType()) {
case GeoLib::GEOTYPE::POINT:
{
boost::optional<std::size_t> node_id = this->getMeshNodeIDForPoint(*static_cast<const GeoLib::PointWithID*>(&geoObj));
if (node_id) vec_nodes.push_back(*node_id);
break;
}
case GeoLib::GEOTYPE::POLYLINE:
vec_nodes = this->getMeshNodeIDsAlongPolyline(*static_cast<const GeoLib::Polyline*>(&geoObj));
break;
case GeoLib::GEOTYPE::SURFACE:
vec_nodes = this->getMeshNodeIDsAlongSurface(*static_cast<const GeoLib::Surface*>(&geoObj));
break;
default:
break;
}
return vec_nodes;
}
boost::optional<std::size_t> MeshNodeSearcher::getMeshNodeIDForPoint(GeoLib::Point const& pnt) const
{
const MeshLib::Node* found = _mesh_grid.getNearestPoint(pnt.getCoords());
if (found)
return found->getID();
else
return boost::none;
}
std::vector<std::size_t> const& MeshNodeSearcher::getMeshNodeIDsAlongPolyline(
......
......@@ -14,6 +14,8 @@
#include <vector>
#include "boost/optional.hpp"
// GeoLib
#include "Point.h"
#include "Polyline.h"
......@@ -49,6 +51,13 @@ public:
explicit MeshNodeSearcher(MeshLib::Mesh const& mesh);
virtual ~MeshNodeSearcher();
/**
* Searches for the nearest mesh nodes on the given geometric object (point, polyline, surface).
* @param geoObj a GeoLib::GeoObject where the nearest mesh node is searched for
* @return a vector of mesh node ids
*/
std::vector<std::size_t> getMeshNodeIDs(GeoLib::GeoObject const& geoObj);
/**
* Searches for the node nearest by the given point. If there are two nodes
* with the same distance the id of the one that was first found will be
......@@ -57,7 +66,7 @@ public:
* @param pnt a GeoLib::Point the nearest mesh node is searched for
* @return the id of the nearest mesh node
*/
std::size_t getMeshNodeIDForPoint(GeoLib::Point const& pnt) const;
boost::optional<std::size_t> getMeshNodeIDForPoint(GeoLib::Point const& pnt) const;
/**
* Searches for the nearest mesh nodes along a GeoLib::Polyline.
......
......@@ -69,27 +69,27 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PointSearch)
MeshGeoToolsLib::MeshNodeSearcher mesh_node_searcher(*_quad_mesh);
// find ORIGIN
ASSERT_EQ(0u, mesh_node_searcher.getMeshNodeIDForPoint(pnt));
ASSERT_EQ(0u, *mesh_node_searcher.getMeshNodeIDForPoint(pnt));
pnt[0] = 0.049;
pnt[1] = 0.049;
ASSERT_EQ(0u, mesh_node_searcher.getMeshNodeIDForPoint(pnt));
ASSERT_EQ(0u, *mesh_node_searcher.getMeshNodeIDForPoint(pnt));
pnt[0] = 0.051;
pnt[1] = 0.049;
ASSERT_EQ(1u, mesh_node_searcher.getMeshNodeIDForPoint(pnt));
ASSERT_EQ(1u, *mesh_node_searcher.getMeshNodeIDForPoint(pnt));
pnt[0] = 0.049;
pnt[1] = 0.051;
ASSERT_EQ(100u, mesh_node_searcher.getMeshNodeIDForPoint(pnt));
ASSERT_EQ(100u, *mesh_node_searcher.getMeshNodeIDForPoint(pnt));
pnt[0] = 0.051;
pnt[1] = 0.051;
ASSERT_EQ(101u, mesh_node_searcher.getMeshNodeIDForPoint(pnt));
ASSERT_EQ(101u, *mesh_node_searcher.getMeshNodeIDForPoint(pnt));
pnt[0] = 9.951;
pnt[1] = 9.951;
ASSERT_EQ((_number_of_subdivisions_per_direction+1) * (_number_of_subdivisions_per_direction+1) - 1, mesh_node_searcher.getMeshNodeIDForPoint(pnt));
ASSERT_EQ((_number_of_subdivisions_per_direction+1) * (_number_of_subdivisions_per_direction+1) - 1, *mesh_node_searcher.getMeshNodeIDForPoint(pnt));
}
TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch)
......
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