From 979b3a23355b4901aca2dd3cc8db88552d7f7a8d Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <github@naumov.de> Date: Sat, 2 Jun 2018 01:15:52 +0200 Subject: [PATCH] [MeL] MS: Extract nodesNodesIntersection. The function is independent of the MeshSubset. --- MeshLib/MeshSubset.h | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/MeshLib/MeshSubset.h b/MeshLib/MeshSubset.h index dfff96d8eee..b78d7d40224 100644 --- a/MeshLib/MeshSubset.h +++ b/MeshLib/MeshSubset.h @@ -22,6 +22,27 @@ namespace MeshLib { +inline std::vector<Node*> nodesNodesIntersection( + std::vector<Node*> const& nodes_a, std::vector<Node*> const& nodes_b) +{ + if (nodes_a.empty() || nodes_b.empty()) + { + return {}; + } + + std::vector<Node*> active_nodes; + + for (auto const& n_a : nodes_a) + { + auto it = std::find(begin(nodes_b), end(nodes_b), n_a); + if (it != end(nodes_b)) + { + active_nodes.push_back(n_a); + } + } + + return active_nodes; +} /// A subset of nodes or elements on a single mesh. class MeshSubset @@ -138,17 +159,13 @@ public: { auto* active_nodes = new std::vector<Node*>; - if (_nodes == nullptr || _nodes->empty()) - return MeshSubset(_msh, active_nodes); // Empty mesh subset - - for (auto n : nodes) + if (_nodes == nullptr) { - auto it = std::find(_nodes->cbegin(), _nodes->cend(), n); - if (it == _nodes->cend()) - continue; - active_nodes->push_back(n); + return MeshSubset(_msh, active_nodes); // Empty mesh subset } + *active_nodes = nodesNodesIntersection(*_nodes, nodes); + // Transfer the ownership of active_nodes to the new MeshSubset, which // deletes the pointer itself. return MeshSubset(_msh, active_nodes, @@ -171,5 +188,4 @@ private: bool const _delete_ptr = false; }; - } // namespace MeshLib -- GitLab