paste.hpp 2.71 KB
Newer Older
Edwin Carlinet's avatar
Edwin Carlinet committed
1
#pragma once
Michaël Roynard's avatar
Michaël Roynard committed
2
#include <mln/core/concept/image.hpp>
Edwin Carlinet's avatar
Edwin Carlinet committed
3
#include <mln/core/rangev3/rows.hpp>
edwin.carlinet's avatar
edwin.carlinet committed
4

Michaël Roynard's avatar
Michaël Roynard committed
5
6
namespace mln
{
edwin.carlinet's avatar
edwin.carlinet committed
7
8
9
10
11
12
13
14
15
16
17

  /// \brief \p paste copy each pixel from the input image to the output image.
  ///
  /// \ingroup Algorithms
  ///
  /// Each pixel of the input image is paste to the output image. It implies
  /// that \p input's domain must be included in \p output's domain.

  /// This is equivalent to the following code:
  ///
  /// \code
Edwin Carlinet's avatar
Edwin Carlinet committed
18
  /// mln_foreach (auto px, input.pixels())
edwin.carlinet's avatar
edwin.carlinet committed
19
20
21
22
23
24
25
26
27
28
29
30
  ///    output(px.point()) = px.val()
  /// \endcode
  ///
  /// \param[in] input The input image.
  /// \param[out] output The output image
  ///
  /// \return The output image.
  ///
  /// \pre `output.domain()` includes `input.domain()`
  /// \tparam InputImage is a model of the Forward Image.
  /// \tparam OutputImage is a model of the Writable Point-Accessible Image
  template <typename InputImage, typename OutputImage>
Edwin Carlinet's avatar
Edwin Carlinet committed
31
  [[deprecated]] OutputImage& paste(const Image<InputImage>& input, Image<OutputImage>& output);
edwin.carlinet's avatar
edwin.carlinet committed
32
33
34
35

  /// \ingroup Algorithms
  /// \overload
  template <typename InputImage, typename OutputImage>
Edwin Carlinet's avatar
Edwin Carlinet committed
36
37
38
39
40
41
42
  [[deprecated]] OutputImage&& paste(const Image<InputImage>& input, Image<OutputImage>&& output);

  namespace experimental
  {
    template <class InputImage, class OutputImage>
    void copy(InputImage src, OutputImage dest);
  }
edwin.carlinet's avatar
edwin.carlinet committed
43

Michaël Roynard's avatar
Michaël Roynard committed
44
45
46
  /******************************************/
  /****          Implementation          ****/
  /******************************************/
edwin.carlinet's avatar
edwin.carlinet committed
47

Edwin Carlinet's avatar
Edwin Carlinet committed
48
49
50
51
52
53
  namespace impl
  {
    template <typename I, typename J>
    void paste(const I& ima, J& out)
    {
      mln_pixter(px, ima);
Michaël Roynard's avatar
Michaël Roynard committed
54
      mln_forall (px)
Edwin Carlinet's avatar
Edwin Carlinet committed
55
        out(px->point()) = px->val();
Edwin Carlinet's avatar
Edwin Carlinet committed
56
57
    }
  }
edwin.carlinet's avatar
edwin.carlinet committed
58
59

  template <typename InputImage, typename OutputImage>
Michaël Roynard's avatar
Michaël Roynard committed
60
  OutputImage& paste(const Image<InputImage>& input, Image<OutputImage>& output_)
edwin.carlinet's avatar
edwin.carlinet committed
61
62

  {
Edwin Carlinet's avatar
Edwin Carlinet committed
63
    impl::paste(exact(input), exact(output_));
edwin.carlinet's avatar
edwin.carlinet committed
64
65
66
67
    return exact(output_);
  }

  template <typename InputImage, typename OutputImage>
Michaël Roynard's avatar
Michaël Roynard committed
68
  OutputImage&& paste(const Image<InputImage>& input_, Image<OutputImage>&& output_)
edwin.carlinet's avatar
edwin.carlinet committed
69
  {
Edwin Carlinet's avatar
Edwin Carlinet committed
70
71
    paste(input_, output_);
    return move_exact(output_);
edwin.carlinet's avatar
edwin.carlinet committed
72
73
  }

Edwin Carlinet's avatar
Edwin Carlinet committed
74
75
76
77
78
79
80
81
82
83
84
  namespace experimental
  {
    template <class InputImage, class OutputImage>
    void paste(InputImage src, OutputImage dest)
    {
      // FIXME: Add a precondition about the domain inclusion
      // FIXME: cech OutputImage is accessible
      static_assert(mln::is_a<InputImage, Image>());
      static_assert(mln::is_a<OutputImage, Image>());
      static_assert(std::is_convertible_v<image_value_t<InputImage>, image_value_t<OutputImage>>);

85
86
87
      auto&& pixels = src.new_pixels();
      for (auto row : ranges::rows(pixels))
        for (auto px : row)
Edwin Carlinet's avatar
Edwin Carlinet committed
88
89
90
91
          dest(px.point()) = px.val();
    }

  } // namespace experimental
edwin.carlinet's avatar
edwin.carlinet committed
92

Edwin Carlinet's avatar
Edwin Carlinet committed
93
} // namespace mln