From cc58e8d50d503f44d7e37a2411a03629055a73e4 Mon Sep 17 00:00:00 2001 From: Norihiro Watanabe <norihiro.watanabe@ufz.de> Date: Fri, 29 Aug 2014 17:22:17 +0200 Subject: [PATCH] add a general searching function for any geometric types in MeshNodeSearcher --- MeshGeoToolsLib/MeshNodeSearcher.cpp | 22 ++++++++++++++++++++++ MeshGeoToolsLib/MeshNodeSearcher.h | 7 +++++++ 2 files changed, 29 insertions(+) diff --git a/MeshGeoToolsLib/MeshNodeSearcher.cpp b/MeshGeoToolsLib/MeshNodeSearcher.cpp index 325c61a56f7..2b0cd19c1ec 100644 --- a/MeshGeoToolsLib/MeshNodeSearcher.cpp +++ b/MeshGeoToolsLib/MeshNodeSearcher.cpp @@ -75,6 +75,28 @@ MeshNodeSearcher::~MeshNodeSearcher() } } +std::vector<std::size_t> MeshNodeSearcher::getMeshNodeIDs(GeoLib::GeoObject const& geoObj) +{ + std::vector<std::size_t> vec_nodes; + switch (geoObj.getGeoType()) { + case GeoLib::GEOTYPE::POINT: + { + auto node_id = this->getMeshNodeIDForPoint(*dynamic_cast<const GeoLib::PointWithID*>(&geoObj)); + if (node_id) vec_nodes.push_back(*node_id); + break; + } + case GeoLib::GEOTYPE::POLYLINE: + vec_nodes = this->getMeshNodeIDsAlongPolyline(*dynamic_cast<const GeoLib::Polyline*>(&geoObj)); + break; + case GeoLib::GEOTYPE::SURFACE: + vec_nodes = this->getMeshNodeIDsAlongSurface(*dynamic_cast<const GeoLib::Surface*>(&geoObj)); + break; + default: + break; + } + return vec_nodes; +} + boost::optional<std::size_t> MeshNodeSearcher::getMeshNodeIDForPoint(GeoLib::Point const& pnt) const { auto* found = _mesh_grid.getNearestPoint(pnt.getCoords()); diff --git a/MeshGeoToolsLib/MeshNodeSearcher.h b/MeshGeoToolsLib/MeshNodeSearcher.h index c576569585e..e11d7a544c3 100644 --- a/MeshGeoToolsLib/MeshNodeSearcher.h +++ b/MeshGeoToolsLib/MeshNodeSearcher.h @@ -51,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 -- GitLab