Commit a9f96455 authored by Michaël Roynard's avatar Michaël Roynard
Browse files

Migrate clone

parent 63599df1
#include <mln/colors/rgba.hpp>
#include <mln/core/algorithm/clone.hpp>
#include <mln/core/algorithm/transform.hpp>
#include <mln/core/image/image2d.hpp>
......@@ -66,7 +67,8 @@ class BMAlgorithms : public benchmark::Fixture
mln::io::imread(filename, m_input_rgb8);
m_input_uint8 = mln::clone(mln::red(m_input_rgb8));
auto ima_red = mln::transform(m_input_rgb8, [](auto& rgb8) -> auto& { return mln::getter<0>{}(rgb8); });
m_input_uint8 = mln::clone(ima_red);
m_pixel_count = m_input_rgb8.domain().size();
}
......
......@@ -17,62 +17,20 @@ namespace mln
///
/// \tparam I The input image type
/// \param ima The image to clone.
template <typename I>
[[deprecated]] mln_concrete(I) clone(const Image<I>& ima);
namespace experimental
{
template <class InputImage>
image_concrete_t<InputImage> clone(InputImage input);
}
template <class InputImage>
image_concrete_t<InputImage> clone(InputImage input);
/******************/
/* Implem */
/******************/
namespace impl
template <class InputImage>
image_concrete_t<InputImage> clone(InputImage input)
{
static_assert(mln::is_a<InputImage, experimental::Image>());
// Clone by copy construction
template <typename Image>
mln_concrete(Image) clone(const Image& ima, std::true_type _use_copy_construction_)
{
(void)_use_copy_construction_;
mln_concrete(Image) x(ima);
return x;
}
// Clone by deep copy
template <typename Image>
mln_concrete(Image) clone(const Image& ima, std::false_type _use_copy_construction_)
{
(void)_use_copy_construction_;
mln_concrete(Image) x = imconcretize(ima);
mln::copy(ima, x);
return x;
}
image_concrete_t<InputImage> out = input.concretize();
mln::experimental::copy(std::move(input), out);
return out;
}
template <typename I>
mln_concrete(I) clone(const Image<I>& ima)
{
return impl::clone(exact(ima), check_t < std::is_convertible<I, mln_concrete(I)>::value and
not image_traits<mln_concrete(I)>::shallow_copy::value > ());
}
namespace experimental
{
template <class InputImage>
image_concrete_t<InputImage> clone(InputImage input)
{
static_assert(mln::is_a<InputImage, Image>());
image_concrete_t<InputImage> out = input.concretize();
mln::experimental::copy(std::move(input), out);
return out;
}
} // namespace experimental
} // namespace mln
#pragma once
#include <mln/core/algorithm/clone.hpp>
#include <mln/core/algorithm/copy.hpp>
#include <mln/core/iref.hpp>
#include <mln/core/iterator/filter_iterator.hpp>
#include <mln/core/iterator/transform_iterator.hpp>
......@@ -81,6 +82,39 @@ namespace mln
// return internal::are_indexes_compatible(exact(f), exact(g));
}
// FIXME:
namespace detail
{
namespace impl
{
// Clone by copy construction
template <typename Image>
mln_concrete(Image) clone(const Image& ima, std::true_type _use_copy_construction_)
{
(void)_use_copy_construction_;
mln_concrete(Image) x(ima);
return x;
}
// Clone by deep copy
template <typename Image>
mln_concrete(Image) clone(const Image& ima, std::false_type _use_copy_construction_)
{
(void)_use_copy_construction_;
mln_concrete(Image) x = imconcretize(ima);
mln::copy(ima, x);
return x;
}
} // namespace impl
template <typename I>
[[deprecated]] mln_concrete(I) __clone(const Image<I>& ima) {
return impl::clone(exact(ima), check_t < std::is_convertible<I, mln_concrete(I)>::value and
not image_traits<mln_concrete(I)>::shallow_copy::value > ());
}
} // namespace detail
template <typename InputImage>
inline typename std::enable_if<image_traits<InputImage>::concrete::value, InputImage&&>::type eval(InputImage&& ima)
{
......@@ -92,6 +126,7 @@ namespace mln
mln_concrete(typename std::remove_reference<InputImage>::type)>::type
eval(InputImage&& ima)
{
return clone(std::forward<InputImage>(ima));
// FIXME:
return detail::__clone(std::forward<InputImage>(ima));
}
} // namespace mln
......@@ -10,7 +10,7 @@ TEST(Core, Algorithm_Clone)
using namespace mln::experimental::ops;
const mln::image2d<uint8_t> ima = {{1, 2, 3}, {4, 5, 6}};
auto out = mln::experimental::clone(ima);
auto out = mln::clone(ima);
// Writing does not affect ima
out({0, 0}) = 69;
......
......@@ -117,7 +117,7 @@ TEST(View, filter_twice)
ASSERT_EQ(pix.val(), ima(pix.point()));
}
mln::image2d<int> before = mln::experimental::clone(ima);
mln::image2d<int> before = mln::clone(ima);
mln::fill(u, 1);
{
mln_foreach_new ((auto [old_v, new_v]), mln::ranges::view::zip(before.new_values(), ima.new_values()))
......
Supports Markdown
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