Commit 127dc297 authored by David Frank's avatar David Frank
Browse files

Fix minor bug in CartesianIndices

parent dfc79f9c
......@@ -289,23 +289,26 @@ namespace elsa
CartesianIndices neighbours_in_slice(const IndexVector_t& pos, const IndexVector_t& dist,
const IndexVector_t& lower, const IndexVector_t& upper)
{
IndexVector_t from = pos;
from.tail(pos.size() - 1).array() -= dist.array();
from.array() -= dist.array();
from = from.cwiseMax(lower);
IndexVector_t to = pos;
to.tail(pos.size() - 1).array() += dist.array() + 1;
to[0] += 1;
to.array() += dist.array() + 1;
to = to.cwiseMin(upper);
// FIXME: sometimes this happens when padding is added to an aabb
from = (to.array() == from.array()).select(from.array() - 1, from);
return {from, to};
}
CartesianIndices neighbours_in_slice(const IndexVector_t& pos, index_t dist,
CartesianIndices neighbours_in_slice(const IndexVector_t& pos, index_t dist, index_t leadingDim,
const IndexVector_t& lower, const IndexVector_t& upper)
{
return neighbours_in_slice(pos, IndexVector_t::Constant(pos.size() - 1, dist), lower,
upper);
IndexVector_t distvec = IndexVector_t::Constant(pos.size(), dist);
distvec[leadingDim] = 0;
return neighbours_in_slice(pos, distvec, lower, upper);
}
} // namespace elsa
......@@ -238,7 +238,7 @@ namespace elsa
const IndexVector_t& lower, const IndexVector_t& upper);
/// @overload
CartesianIndices neighbours_in_slice(const IndexVector_t& pos, index_t dist,
CartesianIndices neighbours_in_slice(const IndexVector_t& pos, index_t dist, index_t leadingDim,
const IndexVector_t& lower, const IndexVector_t& upper);
} // namespace elsa
......
......@@ -627,8 +627,8 @@ TEST_CASE("Visit neighbours in 2D with bounds")
auto cur = IndexVector_t({{2, 1}});
auto lower = IndexVector_t({{0, 0}});
auto upper = IndexVector_t({{5, 5}});
// auto grid = CartesianIndices(lower, upper);
auto grid = neighbours_in_slice(cur, 2, lower, upper);
auto grid = neighbours_in_slice(cur, 2, 0, lower, upper);
CHECK_EQ(grid.first(), IndexVector_t({{2, 0}}));
CHECK_EQ(grid.last(), IndexVector_t({{3, 4}}));
......@@ -649,7 +649,7 @@ TEST_CASE("Visit neighbours in 2D with bounds")
auto lower = IndexVector_t({{0, 0}});
auto upper = IndexVector_t({{5, 5}});
// auto grid = CartesianIndices(lower, upper);
auto grid = neighbours_in_slice(cur, 2, lower, upper);
auto grid = neighbours_in_slice(cur, 2, 0, lower, upper);
CHECK_EQ(grid.first(), IndexVector_t({{2, 2}}));
CHECK_EQ(grid.last(), IndexVector_t({{3, 5}}));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment