From 5e5dd1fc3dfd40a876a5d194e9eef1ce48ba049e Mon Sep 17 00:00:00 2001 From: TomFischer <thomas.fischer@ufz.de> Date: Wed, 9 Aug 2023 14:40:42 +0200 Subject: [PATCH] [GL] Extract GeoLib::markUsedPoints() for polylines --- .../Utils/GeoTools/RemoveUnusedPoints.cpp | 5 +---- GeoLib/Polyline.cpp | 15 +++++++++++++++ GeoLib/Polyline.h | 3 +++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Applications/Utils/GeoTools/RemoveUnusedPoints.cpp b/Applications/Utils/GeoTools/RemoveUnusedPoints.cpp index 4399ed00f13..8de26bf2c5e 100644 --- a/Applications/Utils/GeoTools/RemoveUnusedPoints.cpp +++ b/Applications/Utils/GeoTools/RemoveUnusedPoints.cpp @@ -85,10 +85,7 @@ int main(int argc, char* argv[]) { for (auto const* polyline : *polylines) { - for (std::size_t i = 0; i < polyline->getNumberOfPoints(); ++i) - { - used_points[polyline->getPointID(i)] = true; - } + GeoLib::markUsedPoints(*polyline, used_points); } } if (surfaces) diff --git a/GeoLib/Polyline.cpp b/GeoLib/Polyline.cpp index d7967199333..c41414bc201 100644 --- a/GeoLib/Polyline.cpp +++ b/GeoLib/Polyline.cpp @@ -494,6 +494,21 @@ void resetPointIDs(Polyline& polyline, std::vector<std::size_t> const& mapping) } } +void markUsedPoints(Polyline const& polyline, std::vector<bool>& used_points) +{ + if (polyline.getPointsVec().size() != used_points.size()) + { + OGS_FATAL( + "internal error in markUsedPoints(): polyline based on point " + "vector of size {}, given used_points has size {}", + polyline.getPointsVec().size(), used_points.size()); + } + for (std::size_t i = 0; i < polyline.getNumberOfPoints(); ++i) + { + used_points[polyline.getPointID(i)] = true; + } +} + bool containsEdge(const Polyline& ply, std::size_t id0, std::size_t id1) { if (id0 == id1) diff --git a/GeoLib/Polyline.h b/GeoLib/Polyline.h index 0f50261e809..60790b717f7 100644 --- a/GeoLib/Polyline.h +++ b/GeoLib/Polyline.h @@ -230,6 +230,9 @@ bool containsEdge (const Polyline& ply, std::size_t id0, std::size_t id1); /// Resets the point IDs of the polyline corresponding to the mapping. void resetPointIDs(Polyline& polyline, std::vector<std::size_t> const& mapping); +/// Resets the point IDs of the polyline corresponding to the mapping. +void markUsedPoints(Polyline const& polyline, std::vector<bool>& used_points); + /** * comparison operator * \param lhs first polyline -- GitLab