Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
arith/minus.hh
1 // Copyright (C) 2007, 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_ARITH_MINUS_HH
27 # define MLN_ARITH_MINUS_HH
28 
34 
35 # include <mln/arith/includes.hh>
36 
37 
38 namespace mln
39 {
40 
41 
42  namespace trait
43  {
44 
45  template <typename L, typename R>
46  struct set_binary_< op::minus, Image, L, Image, R >
47  {
48  typedef mln_trait_op_minus(mln_value(L), mln_value(R)) value;
49  typedef mln_ch_value(L, value) ret;
50  };
51 
52  template <typename I, typename S>
53  struct set_binary_< op::minus, Image, I, mln::value::Scalar, S >
54  {
55  typedef mln_trait_op_minus(mln_value(I), S) value;
56  typedef mln_ch_value(I, value) ret;
57  };
58 
59  } // end of namespace mln::trait
60 
61 
62 
63  template <typename L, typename R>
64  mln_trait_op_minus(L,R)
65  operator-(const Image<L>& lhs, const Image<R>& rhs);
66 
67 
68  template <typename L, typename R>
69  L&
70  operator-=(Image<L>& lhs, const Image<R>& rhs);
71 
72 
73  template <typename I, typename S>
74  mln_trait_op_minus(I,S)
75  operator-(const Image<I>& ima, const value::Scalar<S>& s);
76 
77 
78  template <typename I, typename S>
79  I&
80  operator-=(Image<I>& ima, const value::Scalar<S>& s);
81 
82 
83 
84  namespace arith
85  {
86 
88 
95  template <typename L, typename R>
96  mln_trait_op_minus(L, R)
97  minus(const Image<L>& lhs, const Image<R>& rhs);
98 
99 
101 
109  template <typename L, typename R, typename F>
110  mln_ch_value(L, mln_result(F))
111  minus(const Image<L>& lhs, const Image<R>& rhs, const Function_v2v<F>& f);
112 
113 
115 
124  template <typename V, typename L, typename R>
125  mln_ch_value(L, V)
126  minus(const Image<L>& lhs, const Image<R>& rhs);
127 
128 
130 
140  template <typename L, typename R>
141  void
142  minus_inplace(Image<L>& lhs, const Image<R>& rhs);
143 
144 
146 
153  template <typename I, typename V>
154  mln_trait_op_minus(I, V)
155  minus_cst(const Image<I>& input, const V& val);
156 
157 
159 
167  template <typename I, typename V, typename F>
168  mln_ch_value(I, mln_result(F))
169  minus_cst(const Image<I>& input, const V& val, const Function_v2v<F>& f);
170 
171 
173 
179  template <typename I, typename V>
180  I&
181  minus_cst_inplace(Image<I>& input, const V& val);
182 
183 
184  } // end of namespace mln::arith
185 
186 
187 
188 
189 # ifndef MLN_INCLUDE_ONLY
190 
191 
192  template <typename L, typename R>
193  inline
194  mln_trait_op_minus(L,R)
195  operator-(const Image<L>& lhs, const Image<R>& rhs)
196  {
197  trace::entering("operator::minus");
198 
199  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
200  mln_trait_op_minus(L,R) output = arith::minus(lhs, rhs);
201 
202  trace::exiting("operator::minus");
203  return output;
204  }
205 
206  template <typename L, typename R>
207  inline
208  L&
209  operator-=(Image<L>& lhs, const Image<R>& rhs)
210  {
211  trace::entering("operator::minus_eq");
212 
213  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
214  arith::minus_inplace(lhs, rhs);
215 
216  trace::exiting("operator::minus_eq");
217  return exact(lhs);
218  }
219 
220 
221  template <typename I, typename S>
222  inline
223  mln_trait_op_minus(I,S)
224  operator-(const Image<I>& ima, const value::Scalar<S>& s)
225  {
226  trace::entering("operator::minus");
227 
228  mln_precondition(exact(ima).is_valid());
229  mln_trait_op_minus(I,S) output = arith::minus_cst(ima, exact(s));
230 
231  trace::exiting("operator::minus");
232  return output;
233  }
234 
235  template <typename I, typename S>
236  inline
237  I&
238  operator-=(Image<I>& ima, const value::Scalar<S>& s)
239  {
240  trace::entering("operator::minus_eq");
241 
242  mln_precondition(exact(ima).is_valid());
243  arith::minus_cst_inplace(ima, exact(s));
244 
245  trace::exiting("operator::minus_eq");
246  return exact(ima);
247  }
248 
249 
250 
251  namespace arith
252  {
253 
254  namespace impl
255  {
256 
257  template <typename L, typename R, typename O>
258  inline
259  void minus_(trait::image::speed::any, const L& lhs,
260  trait::image::speed::any, const R& rhs, O& output)
261  {
262  mln_piter(L) p(lhs.domain());
263  for_all(p)
264  output(p) = lhs(p) - rhs(p);
265  }
266 
267  template <typename L, typename R, typename F, typename O>
268  inline
269  void minus_(trait::image::speed::any, const L& lhs,
270  trait::image::speed::any, const R& rhs, const F& f, O& output)
271  {
272  mln_piter(L) p(lhs.domain());
273  for_all(p)
274  output(p) = f(lhs(p) - rhs(p));
275  }
276 
277  template <typename L, typename R, typename O>
278  inline
279  void minus_(trait::image::speed::fastest, const L& lhs,
280  trait::image::speed::fastest, const R& rhs, O& output)
281  {
282  mln_pixter(const L) lp(lhs);
283  mln_pixter(const R) rp(rhs);
284  mln_pixter(O) op(output);
285  for_all_3(lp, rp, op)
286  op.val() = lp.val() - rp.val();
287  }
288 
289  template <typename L, typename R, typename F, typename O>
290  inline
291  void minus_(trait::image::speed::fastest, const L& lhs,
292  trait::image::speed::fastest, const R& rhs, const F& f, O& output)
293  {
294  mln_pixter(const L) lp(lhs);
295  mln_pixter(const R) rp(rhs);
296  mln_pixter(O) op(output);
297  for_all_3(lp, rp, op)
298  op.val() = f(lp.val() - rp.val());
299  }
300 
301  template <typename L, typename R>
302  inline
303  void minus_inplace_(trait::image::speed::any, L& lhs,
304  trait::image::speed::any, const R& rhs)
305  {
306  mln_piter(L) p(lhs.domain());
307  for_all(p)
308  lhs(p) -= rhs(p);
309  }
310 
311  template <typename L, typename R>
312  inline
313  void minus_inplace_(trait::image::speed::fastest, L& lhs,
314  trait::image::speed::fastest, const R& rhs)
315  {
316  mln_pixter(L) lp(lhs);
317  mln_pixter(const R) rp(rhs);
318  for_all_2(lp, rp)
319  lp.val() -= rp.val();
320  }
321 
322  } // end of namespace mln::arith::impl
323 
324 
325  // Facades.
326 
327 
328  template <typename L, typename R>
329  inline
330  mln_trait_op_minus(L, R)
331  minus(const Image<L>& lhs, const Image<R>& rhs)
332  {
333  trace::entering("arith::minus");
334 
335  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
336 
337  mln_trait_op_minus(L, R) output;
338  initialize(output, lhs);
339  impl::minus_(mln_trait_image_speed(L)(), exact(lhs),
340  mln_trait_image_speed(R)(), exact(rhs), output);
341 
342  trace::exiting("arith::minus");
343  return output;
344  }
345 
346 
347  template <typename L, typename R, typename F>
348  inline
349  mln_ch_value(L, mln_result(F))
350  minus(const Image<L>& lhs, const Image<R>& rhs, const Function_v2v<F>& f)
351  {
352  trace::entering("arith::minus");
353 
354  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
355 
356  mln_ch_value(L, mln_result(F)) output;
357  initialize(output, lhs);
358  impl::minus_(mln_trait_image_speed(L)(), exact(lhs),
359  mln_trait_image_speed(R)(), exact(rhs), exact(f), output);
360 
361  trace::exiting("arith::minus");
362  return output;
363  }
364 
365 
366  template <typename V, typename L, typename R>
367  inline
368  mln_ch_value(L, V)
369  minus(const Image<L>& lhs, const Image<R>& rhs)
370  {
371  trace::entering("arith::minus");
372 
373  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
374 
375  // Calls the previous version.
376  mln_ch_value(L, V) output = minus(lhs, rhs,
377  mln::fun::v2v::cast<V>());
378 
379  trace::exiting("arith::minus");
380  return output;
381  }
382 
383 
384  template <typename I, typename V>
385  inline
386  mln_trait_op_minus(I, V)
387  minus_cst(const Image<I>& input, const V& val)
388  {
389  trace::entering("arith::minus_cst");
390 
391  mln_precondition(exact(input).is_valid());
392 
393  // Calls the previous version.
394  mln_trait_op_minus(I, V) output = minus(input,
395  pw::cst(val) | exact(input).domain());
396 
397  trace::exiting("arith::minus_cst");
398  return output;
399  }
400 
401 
402  template <typename I, typename V, typename F>
403  inline
404  mln_ch_value(I, mln_result(F))
405  minus_cst(const Image<I>& input, const V& val, const Function_v2v<F>& f)
406  {
407  trace::entering("arith::minus_cst");
408 
409  mln_precondition(exact(input).is_valid());
410 
411  // Calls the previous version.
412  mln_ch_value(I, mln_result(F)) output = minus(input,
413  pw::cst(val) | exact(input).domain(),
414  f);
415 
416  trace::exiting("arith::minus_cst");
417  return output;
418  }
419 
420 
421  template <typename L, typename R>
422  inline
423  void
424  minus_inplace(Image<L>& lhs, const Image<R>& rhs)
425  {
426  trace::entering("arith::minus_inplace");
427 
428  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
429 
430  impl::minus_inplace_(mln_trait_image_speed(L)(), exact(lhs),
431  mln_trait_image_speed(R)(), exact(rhs));
432 
433  trace::exiting("arith::minus_inplace");
434  }
435 
436 
437  template <typename I, typename V>
438  inline
439  I&
440  minus_cst_inplace(Image<I>& input, const V& val)
441  {
442  trace::entering("arith::minus_cst_inplace");
443 
444  mln_precondition(exact(input).is_valid());
445 
446  // Calls the previous version.
447  minus_inplace(input,
448  pw::cst(val) | exact(input).domain());
449 
450  trace::exiting("arith::minus_cst_inplace");
451  return exact(input);
452  }
453 
454  } // end of namespace mln::arith
455 
456 # endif // ! MLN_INCLUDE_ONLY
457 
458 } // end of namespace mln
459 
460 
461 #endif // ! MLN_ARITH_MINUS_HH