From a920fe5a8d66a662a0492fd3a3758d3ddd45e807 Mon Sep 17 00:00:00 2001 From: "Dmitry Yu. Naumov" <github@naumov.de> Date: Thu, 27 Sep 2018 16:45:33 +0200 Subject: [PATCH] [MGTL] Add getMeshNodeIDs for point vector. --- MeshGeoToolsLib/MeshNodeSearcher.cpp | 35 ++++++++++++++++++++++++++++ MeshGeoToolsLib/MeshNodeSearcher.h | 8 +++++++ 2 files changed, 43 insertions(+) diff --git a/MeshGeoToolsLib/MeshNodeSearcher.cpp b/MeshGeoToolsLib/MeshNodeSearcher.cpp index fc19986e196..7d7e5f551d8 100644 --- a/MeshGeoToolsLib/MeshNodeSearcher.cpp +++ b/MeshGeoToolsLib/MeshNodeSearcher.cpp @@ -76,6 +76,41 @@ std::vector<std::size_t> MeshNodeSearcher::getMeshNodeIDs( return vec_nodes; } +std::vector<std::size_t> MeshNodeSearcher::getMeshNodeIDs( + std::vector<MathLib::Point3dWithID*> const& points) const +{ + double const epsilon_radius = _search_length_algorithm->getSearchLength(); + + std::vector<std::size_t> node_ids; + node_ids.reserve(points.size()); + + for (auto const* const p_ptr : points) + { + auto const& p = *p_ptr; + std::vector<std::size_t> const ids = + _mesh_grid.getPointsInEpsilonEnvironment(p, epsilon_radius); + if (ids.empty()) + { + OGS_FATAL( + "No nodes could be found in the mesh for point %d : (%g, %g, " + "%g) in %g epsilon radius in the mesh '%s'", + p.getID(), p[0], p[1], p[2], epsilon_radius, + _mesh.getName().c_str()); + } + if (ids.size() != 1) + { + OGS_FATAL( + "Found %d nodes in the mesh for point %d : (%g, %g, %g) in %g " + "epsilon radius in the mesh '%s'. Expected to find exactly one " + "node.", + ids.size(), p.getID(), p[0], p[1], p[2], epsilon_radius, + _mesh.getName().c_str()); + } + node_ids.push_back(ids.front()); + } + return node_ids; +} + std::vector<std::size_t> const& MeshNodeSearcher::getMeshNodeIDsForPoint( GeoLib::Point const& pnt) const { diff --git a/MeshGeoToolsLib/MeshNodeSearcher.h b/MeshGeoToolsLib/MeshNodeSearcher.h index df70806611b..26d3ddc9e97 100644 --- a/MeshGeoToolsLib/MeshNodeSearcher.h +++ b/MeshGeoToolsLib/MeshNodeSearcher.h @@ -76,6 +76,14 @@ public: std::vector<std::size_t> getMeshNodeIDs( GeoLib::GeoObject const& geoObj) const; + /** + * Finds unique mesh nodes of each of the input points. + * + * \return a vector of mesh node ids. + */ + std::vector<std::size_t> getMeshNodeIDs( + std::vector<MathLib::Point3dWithID*> const& points) const; + /** * 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