$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fill_with_image.hh
1 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_DATA_FILL_WITH_IMAGE_HH
27 # define MLN_DATA_FILL_WITH_IMAGE_HH
28 
34 
35 # include <mln/core/concept/image.hh>
36 
37 
38 // Specializations are in:
39 # include <mln/data/fill_with_image.spe.hh>
40 
41 
42 namespace mln
43 {
44 
45  namespace data
46  {
47 
58  template <typename I, typename J>
59  void fill_with_image(Image<I>& ima, const Image<J>& data);
60 
61 
62 
63 # ifndef MLN_INCLUDE_ONLY
64 
65  namespace internal
66  {
67 
68  template <typename I, typename J>
69  inline
70  void fill_with_image_tests(Image<I>& ima, const Image<J>& data)
71  {
72  // Avoid a warning about an undefined variable when NDEBUG
73  // is not defined.
74  (void)ima;
75  (void)data;
76 
77  mlc_is(mln_trait_image_pw_io(I),
78  mln::trait::image::pw_io::read_write)::check();
79  mlc_converts_to(mln_value(J), mln_value(I))::check();
80  mln_precondition(exact(ima).is_valid());
81  mln_precondition(exact(data).is_valid());
82  mln_precondition(exact(ima).domain() <= exact(data).domain());
83  }
84 
85  } // end of namespace mln::data::internal
86 
87 
88  namespace impl
89  {
90 
91  namespace generic
92  {
93 
98  //
99  template <typename I, typename J>
100  void fill_with_image(Image<I>& ima_, const Image<J>& data_)
101  {
102  mln_trace("data::impl::generic::fill_with_image");
103  I& ima = exact(ima_);
104  const J& data = exact(data_);
105 
106  data::internal::fill_with_image_tests(ima, data);
107 
108  mln_piter(I) p(ima.domain());
109  for_all(p)
110  ima(p) = static_cast<mln_value(I)>(data(p));
111 
112  }
113 
114  } // end if namespace mln::data::impl::generic
115 
116  } // end of namespace mln::data::impl
117 
118 
119  // Facade.
120 
121  template <typename I, typename J>
122  inline
123  void fill_with_image(Image<I>& ima, const Image<J>& data)
124  {
125  mln_trace("data::fill_with_image");
126 
127  internal::fill_with_image_(ima, data);
128 
129  }
130 
131 # endif // ! MLN_INCLUDE_ONLY
132 
133  } // end of namespace mln::data
134 
135 } // end of namespace mln
136 
137 
138 #endif // ! MLN_DATA_FILL_WITH_IMAGE_HH