Skip to content

Commit

Permalink
Merge #2840
Browse files Browse the repository at this point in the history
2840: Lin space r=KaiSzuttor a=fweik

Maybe fixes #2837.

Co-authored-by: Florian Weik <fweik@icp.uni-stuttgart.de>
Co-authored-by: Kai Szuttor <kai@icp.uni-stuttgart.de>
  • Loading branch information
3 people committed Jun 11, 2019
2 parents 5b88304 + 348a427 commit 7eebdb9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
27 changes: 14 additions & 13 deletions src/utils/include/utils/raster.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#ifndef UTILS_RASTER_HPP
#define UTILS_RASTER_HPP

#include <boost/multi_array.hpp>

#include "utils/Vector.hpp"
#include "utils/math/make_lin_space.hpp"

#include <boost/multi_array.hpp>

namespace Utils {

Expand All @@ -20,21 +21,21 @@ namespace Utils {
* @return Function values at the grid points.
*/
template <class T, class F>
auto raster(Vector3d const &offset, Vector3d const &grid_spacing, Vector3i size,
F f) {

auto raster(Vector<T, 3> const &offset, Vector<T, 3> const &grid_spacing,
Vector3i size, F f) {
using R = decltype(f((offset)));

boost::multi_array<R, 3> res(size);

Vector3i ind;
for (ind[0] = 0; ind[0] < size[0]; ind[0]++)
for (ind[1] = 0; ind[1] < size[1]; ind[1]++)
for (ind[2] = 0; ind[2] < size[2]; ind[2]++) {
auto const x = offset + Vector3d{ind[0] * grid_spacing[0],
ind[1] * grid_spacing[1],
ind[2] * grid_spacing[2]};
auto const end = offset + Vector<T, 3>{grid_spacing[0] * size[0],
grid_spacing[1] * size[1],
grid_spacing[2] * size[2]};

res(ind) = f(x);
auto it = res.data();
for (auto x : make_lin_space(offset[0], end[0], size[0], false))
for (auto y : make_lin_space(offset[1], end[1], size[1], false))
for (auto z : make_lin_space(offset[2], end[2], size[2], false)) {
*it++ = f(Vector<T, 3>{x, y, z});
}

return res;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/tests/raster_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ BOOST_AUTO_TEST_CASE(basic_test) {
Vector3d const h{2., 3., 4.};
Vector3i size{10, 11, 12};

auto const res = raster<Vector3d>(origin, h, size, [](auto i) { return i; });
auto const res = raster<double>(origin, h, size, [](auto i) { return i; });

for (int i = 0; i < size[0]; i++)
for (int j = 0; j < size[1]; j++)
Expand Down

0 comments on commit 7eebdb9

Please sign in to comment.