paste.hpp 1.99 KB
Newer Older
edwin.carlinet's avatar
edwin.carlinet committed
1
#ifndef MLN_CORE_ALGORITHM_PASTE_HPP
Michaël Roynard's avatar
Michaël Roynard committed
2
#define MLN_CORE_ALGORITHM_PASTE_HPP
edwin.carlinet's avatar
edwin.carlinet committed
3

Michaël Roynard's avatar
Michaël Roynard committed
4
#include <mln/core/concept/image.hpp>
edwin.carlinet's avatar
edwin.carlinet committed
5

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

  /// \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
19
  /// mln_foreach (auto px, input.pixels())
edwin.carlinet's avatar
edwin.carlinet committed
20
21
22
23
24
25
26
27
28
29
30
31
  ///    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>
Michaël Roynard's avatar
Michaël Roynard committed
32
  OutputImage& paste(const Image<InputImage>& input, Image<OutputImage>& output);
edwin.carlinet's avatar
edwin.carlinet committed
33
34
35
36

  /// \ingroup Algorithms
  /// \overload
  template <typename InputImage, typename OutputImage>
Michaël Roynard's avatar
Michaël Roynard committed
37
  OutputImage&& paste(const Image<InputImage>& input, Image<OutputImage>&& output);
edwin.carlinet's avatar
edwin.carlinet committed
38

Michaël Roynard's avatar
Michaël Roynard committed
39
40
41
  /******************************************/
  /****          Implementation          ****/
  /******************************************/
edwin.carlinet's avatar
edwin.carlinet committed
42

Edwin Carlinet's avatar
Edwin Carlinet committed
43
44
45
46
47
48
  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
49
      mln_forall (px)
Edwin Carlinet's avatar
Edwin Carlinet committed
50
        out(px->point()) = px->val();
Edwin Carlinet's avatar
Edwin Carlinet committed
51
52
    }
  }
edwin.carlinet's avatar
edwin.carlinet committed
53
54

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

  {
Edwin Carlinet's avatar
Edwin Carlinet committed
58
    impl::paste(exact(input), exact(output_));
edwin.carlinet's avatar
edwin.carlinet committed
59
60
61
62
    return exact(output_);
  }

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

} // end of namespace mln

Michaël Roynard's avatar
Michaël Roynard committed
71
#endif //! MLN_CORE_ALGORITHM_IMFILL_HPP