From 46fcc1b13c9bf52c634a185c25788ae508ff3b1e Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Fri, 18 Jun 2021 11:07:35 +0200
Subject: [PATCH] [GL/Grid] Return result directly instead of using
 input/output parameter.

---
 GeoLib/Grid.h                                 | 24 ++++++++++++-------
 .../Mesh2MeshPropertyInterpolation.cpp        |  6 ++---
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/GeoLib/Grid.h b/GeoLib/Grid.h
index 5e1a7d1dfb0..41158c9d258 100644
--- a/GeoLib/Grid.h
+++ b/GeoLib/Grid.h
@@ -95,10 +95,9 @@ public:
     getPntVecsOfGridCellsIntersectingCube(P const& center,
                                           double half_len) const;
 
-    void getPntVecsOfGridCellsIntersectingCuboid(
-        Eigen::Vector3d const& min_pnt,
-        Eigen::Vector3d const& max_pnt,
-        std::vector<std::vector<POINT*> const*>& pnts) const;
+    std::vector<std::vector<POINT*> const*>
+    getPntVecsOfGridCellsIntersectingCuboid(
+        Eigen::Vector3d const& min_pnt, Eigen::Vector3d const& max_pnt) const;
 
 #ifndef NDEBUG
     /**
@@ -253,11 +252,16 @@ std::vector<std::vector<POINT*> const*>
 Grid<POINT>::getPntVecsOfGridCellsIntersectingCube(P const& center,
                                                    double half_len) const
 {
-    std::vector<std::vector<POINT*> const*> pnts;
     Eigen::Vector3d const c{center[0], center[1], center[2]};
     std::array<std::size_t, 3> min_coords(getGridCoords(c.array() - half_len));
     std::array<std::size_t, 3> max_coords(getGridCoords(c.array() + half_len));
 
+    std::vector<std::vector<POINT*> const*> pnts;
+    pnts.reserve(
+        (Eigen::Map<Eigen::Matrix<std::size_t, 3, 1>>(max_coords.data()) -
+         Eigen::Map<Eigen::Matrix<std::size_t, 3, 1>>(min_coords.data()))
+            .prod());
+
     std::size_t const steps0_x_steps1(_n_steps[0] * _n_steps[1]);
     for (std::size_t c0 = min_coords[0]; c0 < max_coords[0] + 1; c0++)
     {
@@ -276,14 +280,15 @@ Grid<POINT>::getPntVecsOfGridCellsIntersectingCube(P const& center,
 }
 
 template <typename POINT>
-void Grid<POINT>::getPntVecsOfGridCellsIntersectingCuboid(
-    Eigen::Vector3d const& min_pnt,
-    Eigen::Vector3d const& max_pnt,
-    std::vector<std::vector<POINT*> const*>& pnts) const
+std::vector<std::vector<POINT*> const*>
+Grid<POINT>::getPntVecsOfGridCellsIntersectingCuboid(
+    Eigen::Vector3d const& min_pnt, Eigen::Vector3d const& max_pnt) const
 {
     std::array<std::size_t, 3> min_coords(getGridCoords(min_pnt));
     std::array<std::size_t, 3> max_coords(getGridCoords(max_pnt));
 
+    std::vector<std::vector<POINT*> const*> pnts;
+
     std::size_t const steps0_x_steps1(_n_steps[0] * _n_steps[1]);
     for (std::size_t c0 = min_coords[0]; c0 < max_coords[0] + 1; c0++)
     {
@@ -298,6 +303,7 @@ void Grid<POINT>::getPntVecsOfGridCellsIntersectingCuboid(
             }
         }
     }
+    return pnts;
 }
 
 #ifndef NDEBUG
diff --git a/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp b/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp
index 5c31760f63b..3504a8efec1 100644
--- a/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp
+++ b/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp
@@ -116,9 +116,9 @@ void Mesh2MeshPropertyInterpolation::interpolatePropertiesForMesh(
             dest_element.getNodes() + dest_element.getNumberOfBaseNodes());
 
         // request "interesting" nodes from grid
-        std::vector<std::vector<MeshLib::Node*> const*> nodes;
-        src_grid.getPntVecsOfGridCellsIntersectingCuboid(
-            elem_aabb.getMinPoint(), elem_aabb.getMaxPoint(), nodes);
+        std::vector<std::vector<MeshLib::Node*> const*> const nodes =
+            src_grid.getPntVecsOfGridCellsIntersectingCuboid(
+                elem_aabb.getMinPoint(), elem_aabb.getMaxPoint());
 
         std::size_t cnt(0);
         double average_value(0.0);
-- 
GitLab