Commit 5e76699d authored by Edwin Carlinet's avatar Edwin Carlinet

Merge branch 'development/fix-organoids' into 'next'

Fix bug  #72

See merge request !107
parents 1d14830c 686b34c3
Pipeline #26617 passed with stages
in 20 minutes and 53 seconds
......@@ -438,33 +438,13 @@ namespace mln
template <class T, int N>
inline __ndbuffer_image<T, 2> __ndbuffer_image<T, N>::slice(int z) const
{
int begin[N] = {this->__axes(0).domain_begin, this->__axes(1).domain_begin, z};
int end[N] = {this->__axes(0).domain_end, this->__axes(1).domain_end, z + 1};
for (int k = 3; k < m_pdim; ++k)
{
begin[k] = 0;
end[k] = 1;
}
ndbuffer_image_info_t tmp = *this->__info();
Impl::select(&tmp, 2, begin, end);
return *Impl::template cast<T, 2>(&tmp);
return static_cast<__ndbuffer_image<T,2>&&>(this->base::slice(z));
}
template <class T, int N>
inline __ndbuffer_image<T, 1> __ndbuffer_image<T, N>::row(int y) const
{
int begin[N] = {m_axes[0].domain_begin, y};
int end[N] = {m_axes[0].domain_end, y + 1};
for (int k = 2; k < m_pdim; ++k)
{
begin[k] = 0;
end[k] = 1;
}
ndbuffer_image_info_t tmp = *this->__info();
Impl::select(&tmp, 1, begin, end);
return *Impl::template cast<T, 1>(&tmp);
return static_cast<__ndbuffer_image<T,1>&&>(this->base::row(y));
}
template <class T, int N>
......
......@@ -6,9 +6,6 @@ namespace mln::details
{
static void select(ndbuffer_image_info_t* ima, int dim, const int begin_coords[], const int end_coords[]);
static std::size_t get_sample_byte_size(const ndbuffer_image_info_t* ima);
template <class T, int pdim>
static __ndbuffer_image<T, pdim>* cast(ndbuffer_image_info_t* ima);
};
template <class T>
......@@ -58,12 +55,6 @@ namespace mln::details
/**** Implementation ****/
/******************************************/
template <class T, int pdim>
__ndbuffer_image<T, pdim>* ndbuffer_image_impl_base_0::cast(ndbuffer_image_info_t* ima)
{
return reinterpret_cast<__ndbuffer_image<T, pdim>*>(ima);
}
template <int pdim>
constexpr int ndbuffer_image_impl_base_2<pdim>::get_pdim(const ndbuffer_image_info_t*)
{
......
......@@ -25,6 +25,21 @@ namespace mln
static constexpr int radial_extent() { return 1; }
/// \brief Return the input ROI for 3D box.
mln::box3d compute_input_region(mln::box3d roi) const
{
roi.inflate(1);
return roi;
}
/// \brief Return the output ROI for 3D box.
mln::box3d compute_output_region(mln::box3d roi) const
{
roi.inflate(-1);
return roi;
}
private:
static inline constexpr std::array<point_t, 26> m_offsets = {{
// clang-format off
......
......@@ -25,9 +25,26 @@ namespace mln
static constexpr int radial_extent() { return 1; }
/// \brief Return the input ROI for 3D box.
mln::box3d compute_input_region(mln::box3d roi) const
{
roi.inflate(1);
return roi;
}
/// \brief Return the output ROI for 3D box.
mln::box3d compute_output_region(mln::box3d roi) const
{
roi.inflate(-1);
return roi;
}
private:
static inline constexpr std::array<point_t, 6> m_offsets = {
{{+0, +0, -1}, {+0, -1, +0}, {-1, +0, +0}, {+1, +0, +0}, {+0, +1, +0}, {+0, +0, +1}}};
};
......
......@@ -808,6 +808,65 @@ TEST(ndbuffer_image, clip_invalid_roi)
EXPECT_THROW(img.clip(roi), std::runtime_error);
}
/********************************************************************/
/**** Test Slicing ****/
/********************************************************************/
TEST(ndbuffer_image, slice2d)
{
mln::image_build_params params;
params.border = 0;
{
mln::ndbuffer_image img(kSampleType, kWidth, kHeight, params);
iota(img);
auto f = img.row(1);
EXPECT_EQ(f.width(), kWidth);
EXPECT_EQ(f.pdim(), 1);
EXPECT_EQ(*static_cast<const uint32_t*>(f({0})), kWidth);
}
{
mln::image2d<uint32_t> img(kWidth, kHeight, params);
iota(img);
mln::image1d<uint32_t> f = img.row(1);
EXPECT_EQ(f.width(), kWidth);
EXPECT_EQ(f.pdim(), 1);
EXPECT_EQ(f({0}), kWidth);
}
}
TEST(ndbuffer_image, slice3d)
{
mln::image_build_params params;
params.border = 0;
{
mln::ndbuffer_image img(kSampleType, kWidth, kHeight, kDepth, params);
iota(img);
auto f = img.slice(1);
EXPECT_EQ(f.width(), kWidth);
EXPECT_EQ(f.height(), kHeight);
EXPECT_EQ(f.pdim(), 2);
EXPECT_EQ(*static_cast<const uint32_t*>(f({0,0})), kWidth * kHeight);
}
{
mln::image3d<uint32_t> img(kWidth, kHeight, kDepth, params);
iota(img);
mln::image2d<uint32_t> f = img.slice(1);
EXPECT_EQ(f.width(), kWidth);
EXPECT_EQ(f.height(), kHeight);
EXPECT_EQ(f.pdim(), 2);
EXPECT_EQ(f({0,0}), kWidth * kHeight);
}
}
/********************************************************************/
/**** Test Border Size Computation ****/
/********************************************************************/
......
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