$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
set_value.hh
1 // Copyright (C) 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_ACCU_IMAGE_SET_VALUE_HH
27 # define MLN_ACCU_IMAGE_SET_VALUE_HH
28 
32 
33 # include <mln/core/concept/accumulator.hh>
34 # include <mln/core/concept/image.hh>
35 # include <mln/border/resize_equal.hh>
36 
37 
38 namespace mln
39 {
40 
41  namespace accu
42  {
43 
44  namespace image
45  {
46 
47  template <typename I>
48  void
49  set_value(Image<I>& input, const mln_deduce(I, value, result)& res);
50 
51  template <typename I, typename J>
52  void
53  set_value(Image<I>& input, const Image<J>& res);
54 
55 
56 # ifndef MLN_INCLUDE_ONLY
57 
58 
59  // Tests.
60 
61  namespace internal
62  {
63 
64  template <typename I, typename J>
65  inline
66  void
67  set_value_tests(Image<I>& input_, const Image<J>& res_)
68  {
69  I& input = exact(input_);
70  const J& res = exact(res_);
71 
72  mln_precondition(input.is_valid());
73  mln_precondition(res.is_valid());
74 
75  mln_precondition(res.domain() <= input.domain());
76 
77  (void) input;
78  (void) res;
79  }
80 
81  } // end of namespace mln::accu::image::internal
82 
83 
84 
85  namespace impl
86  {
87 
88  // Generic versions.
89 
90  namespace generic
91  {
92 
93  template <typename I>
94  inline
95  void
96  set_value(Image<I>& input_, const mln_deduce(I, value, result)& res)
97  {
98  mln_trace("accu::impl::image::generic::set_value");
99 
100  typedef mln_value(I) A;
101  mlc_is_a(A, Accumulator)::check();
102  mlc_equal(mln_trait_accumulator_has_set_value(A),
103  trait::accumulator::has_set_value::yes)::check();
104 
105  I& input = exact(input_);
106  mln_precondition(input.is_valid());
107 
108  mln_piter(I) p(input.domain());
109  for_all(p)
110  input(p).set_value(res);
111 
112  }
113 
114  template <typename I, typename J>
115  inline
116  void
117  set_value(Image<I>& input_, const Image<J>& res_)
118  {
119  mln_trace("accu::impl::image::generic::set_value");
120 
121  typedef mln_value(I) A;
122  mlc_is_a(A, Accumulator)::check();
123  mlc_equal(mln_trait_accumulator_has_set_value(A),
124  trait::accumulator::has_set_value::yes)::check();
125  mlc_converts_to(mln_value(J), mln_deduce(I, value, result))::check();
126 
127  I& input = exact(input_);
128  const J& res = exact(res_);
129 
130  internal::set_value_tests(input, res);
131 
132  mln_piter(J) p(res.domain());
133  for_all(p)
134  input(p).set_value(res(p));
135 
136  }
137 
138  } // end of namespace mln::accu::image::impl::generic
139 
140 
141  // Fastest versions.
142 
143  template <typename I>
144  inline
145  void
146  set_value_fastest(Image<I>& input_, const mln_deduce(I, value, result)& res)
147  {
148  mln_trace("accu::impl::image::set_value_fastest");
149 
150  typedef mln_value(I) A;
151  mlc_is_a(A, Accumulator)::check();
152  mlc_equal(mln_trait_accumulator_has_set_value(A),
153  trait::accumulator::has_set_value::yes)::check();
154 
155  I& input = exact(input_);
156  mln_precondition(input.is_valid());
157 
158  mln_pixter(I) px(input);
159  for_all(px)
160  px.val().set_value(res);
161 
162  }
163 
164  template <typename I, typename J>
165  inline
166  void
167  set_value_fastest(Image<I>& input_, const Image<J>& res_)
168  {
169  mln_trace("accu::impl::image::set_value_fastest");
170 
171  typedef mln_value(I) A;
172  mlc_is_a(A, Accumulator)::check();
173  mlc_equal(mln_trait_accumulator_has_set_value(A),
174  trait::accumulator::has_set_value::yes)::check();
175  mlc_converts_to(mln_value(J), mln_deduce(I, value, result))::check();
176 
177  I& input = exact(input_);
178  const J& res = exact(res_);
179 
180  internal::set_value_tests(input, res);
181  mln_precondition(res.domain() == input.domain());
182 
183  border::resize_equal(input, res);
184 
185  mln_pixter(I) p_in(input);
186  mln_pixter(const J) p_res(res);
187  for_all_2(p_in, p_res)
188  p_in.val().set_value(p_res.val());
189 
190  }
191 
192  } // end of namespace mln::accu::image::impl
193 
194 
195 
196  // Dispatch.
197 
198  namespace internal
199  {
200 
201  // 'res' as value.
202 
203  template <typename I>
204  inline
205  void
206  set_value_dispatch(trait::image::speed::any,
207  Image<I>& input, const mln_deduce(I, value, result)& res)
208  {
209  impl::generic::set_value(input, res);
210  }
211 
212  template <typename I>
213  void
214  set_value_dispatch(trait::image::speed::fastest,
215  Image<I>& input, const mln_deduce(I, value, result)& res)
216  {
217  impl::set_value_fastest(input, res);
218  }
219 
220  template <typename I>
221  inline
222  void
223  set_value_dispatch(Image<I>& input, const mln_deduce(I, value, result)& res)
224  {
225  set_value_dispatch(mln_trait_image_speed(I)(),
226  input, res);
227  }
228 
229  // 'res' as image.
230 
231  template <typename I, typename J>
232  inline
233  void
234  set_value_dispatch(trait::image::speed::any,
235  trait::image::speed::any,
236  Image<I>& input, const Image<J>& res)
237  {
238  impl::generic::set_value(input, res);
239  }
240 
241  template <typename I, typename J>
242  inline
243  void
244  set_value_dispatch(trait::image::speed::fastest,
245  trait::image::speed::fastest,
246  Image<I>& input, const Image<J>& res)
247  {
248  if (exact(res).domain() == exact(input).domain())
249  impl::set_value_fastest(input, res);
250  else
251  impl::generic::set_value(input, res);
252  }
253 
254  template <typename I, typename J>
255  inline
256  void
257  set_value_dispatch(Image<I>& input, const Image<J>& res)
258  {
259  set_value_dispatch(mln_trait_image_speed(I)(),
260  mln_trait_image_speed(J)(),
261  input, res);
262  }
263 
264  } // end of namespace mln::accu::image::internal
265 
266 
267  // Facades.
268 
269  template <typename I>
270  inline
271  void
272  set_value(Image<I>& input, const mln_deduce(I, value, result)& res)
273  {
274  mln_trace("accu::image::set_value");
275 
276  typedef mln_value(I) A;
277  mlc_is_a(A, Accumulator)::check();
278  mlc_equal(mln_trait_accumulator_has_set_value(A),
279  trait::accumulator::has_set_value::yes)::check();
280 
281  mln_precondition(exact(input).is_valid());
282  internal::set_value_dispatch(input, res);
283 
284  }
285 
286  template <typename I, typename J>
287  inline
288  void
289  set_value(Image<I>& input, const Image<J>& res)
290  {
291  mln_trace("accu::image::set_value");
292 
293  typedef mln_value(I) A;
294  mlc_is_a(A, Accumulator)::check();
295  mlc_equal(mln_trait_accumulator_has_set_value(A),
296  trait::accumulator::has_set_value::yes)::check();
297  mlc_converts_to(mln_value(J), mln_deduce(I, value, result))::check();
298 
299  internal::set_value_tests(input, res);
300  internal::set_value_dispatch(input, res);
301 
302  }
303 
304 # endif // ! MLN_INCLUDE_ONLY
305 
306  } // end of namespace mln::accu::image
307 
308  } // end of namespace mln::accu
309 
310 } // end of namespace mln
311 
312 
313 #endif // ! MLN_ACCU_IMAGE_SET_VALUE_HH