$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
mln/arith/minus.hh
1 // Copyright (C) 2007, 2008, 2009, 2013 EPITA Research and Development
2 // Laboratory (LRDE).
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_ARITH_MINUS_HH
28 # define MLN_ARITH_MINUS_HH
29 
34 
35 # include <mln/arith/includes.hh>
36 
37 
38 namespace mln
39 {
40 
41 
42  namespace trait
43  {
44 
45  template <typename I>
46  struct set_unary_< op::uminus, Image, I >
47  {
48  typedef mln_trait_op_uminus(mln_value(I)) value;
49  typedef mln_ch_value(I, value) ret;
50  };
51 
52  template <typename L, typename R>
53  struct set_binary_< op::minus, Image, L, Image, R >
54  {
55  typedef mln_trait_op_minus(mln_value(L), mln_value(R)) value;
56  typedef mln_ch_value(L, value) ret;
57  };
58 
59  template <typename I, typename S>
60  struct set_binary_< op::minus, Image, I, mln::value::Scalar, S >
61  {
62  typedef mln_trait_op_minus(mln_value(I), S) value;
63  typedef mln_ch_value(I, value) ret;
64  };
65 
66  } // end of namespace mln::trait
67 
68 
69 
70  template <typename I>
71  mln_trait_op_uminus(I)
72  operator-(const Image<I>& ima);
73 
74 
75  template <typename L, typename R>
76  mln_trait_op_minus(L,R)
77  operator-(const Image<L>& lhs, const Image<R>& rhs);
78 
79 
80  template <typename L, typename R>
81  L&
82  operator-=(Image<L>& lhs, const Image<R>& rhs);
83 
84 
85  template <typename I, typename S>
86  mln_trait_op_minus(I,S)
87  operator-(const Image<I>& ima, const value::Scalar<S>& s);
88 
89 
90  template <typename I, typename S>
91  I&
92  operator-=(Image<I>& ima, const value::Scalar<S>& s);
93 
94 
95 
96  namespace arith
97  {
98 
100 
104  template <typename I>
105  mln_trait_op_uminus(I)
106  uminus(const Image<I>& ima);
107 
108 
110 
117  template <typename L, typename R>
118  mln_trait_op_minus(L, R)
119  minus(const Image<L>& lhs, const Image<R>& rhs);
120 
121 
123 
131  template <typename L, typename R, typename F>
132  mln_ch_value(L, mln_result(F))
133  minus(const Image<L>& lhs, const Image<R>& rhs,
134  const Function_v2v<F>& f);
135 
136 
138 
147  template <typename V, typename L, typename R>
148  mln_ch_value(L, V)
149  minus(const Image<L>& lhs, const Image<R>& rhs);
150 
151 
153 
163  template <typename L, typename R>
164  void
165  minus_inplace(Image<L>& lhs, const Image<R>& rhs);
166 
167 
169 
176  template <typename I, typename V>
177  mln_trait_op_minus(I, V)
178  minus_cst(const Image<I>& input, const V& val);
179 
180 
182 
190  template <typename I, typename V, typename F>
191  mln_ch_value(I, mln_result(F))
192  minus_cst(const Image<I>& input, const V& val,
193  const Function_v2v<F>& f);
194 
195 
197 
203  template <typename I, typename V>
204  I&
205  minus_cst_inplace(Image<I>& input, const V& val);
206 
207 
208  } // end of namespace mln::arith
209 
210 
211 
212 
213 # ifndef MLN_INCLUDE_ONLY
214 
215 
216  template <typename I>
217  inline
218  mln_trait_op_uminus(I)
219  operator-(const Image<I>& ima)
220  {
221  mln_trace("operator::uminus");
222 
223  mln_trait_op_uminus(I) output = arith::uminus(ima);
224 
225  return output;
226  }
227 
228  template <typename L, typename R>
229  inline
230  mln_trait_op_minus(L,R)
231  operator-(const Image<L>& lhs, const Image<R>& rhs)
232  {
233  mln_trace("operator::minus");
234 
235  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
236  mln_trait_op_minus(L,R) output = arith::minus(lhs, rhs);
237 
238  return output;
239  }
240 
241  template <typename L, typename R>
242  inline
243  L&
244  operator-=(Image<L>& lhs, const Image<R>& rhs)
245  {
246  mln_trace("operator::minus_eq");
247 
248  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
249  arith::minus_inplace(lhs, rhs);
250 
251  return exact(lhs);
252  }
253 
254 
255  template <typename I, typename S>
256  inline
257  mln_trait_op_minus(I,S)
258  operator-(const Image<I>& ima, const value::Scalar<S>& s)
259  {
260  mln_trace("operator::minus");
261 
262  mln_precondition(exact(ima).is_valid());
263  mln_trait_op_minus(I,S) output = arith::minus_cst(ima, exact(s));
264 
265  return output;
266  }
267 
268  template <typename I, typename S>
269  inline
270  I&
271  operator-=(Image<I>& ima, const value::Scalar<S>& s)
272  {
273  mln_trace("operator::minus_eq");
274 
275  mln_precondition(exact(ima).is_valid());
277 
278  return exact(ima);
279  }
280 
281 
282 
283  namespace arith
284  {
285 
286  namespace impl
287  {
288 
289  template <typename I, typename O>
290  inline
291  void uminus_(trait::image::speed::any, const I& ima, O& output)
292  {
293  mln_piter(I) p(ima.domain());
294  for_all(p)
295  output(p) = -ima(p);
296  }
297 
298  template <typename I, typename O>
299  inline
300  void uminus_(trait::image::speed::fastest, const I& ima, O& output)
301  {
302  mln_pixter(const I) ip(ima);
303  mln_pixter(O) op(output);
304  for_all_2(ip, op)
305  op.val() = -ip.val();
306  }
307 
308 
309  template <typename L, typename R, typename O>
310  inline
311  void minus_(trait::image::speed::any, const L& lhs,
312  trait::image::speed::any, const R& rhs,
313  O& output)
314  {
315  mln_piter(L) p(lhs.domain());
316  for_all(p)
317  output(p) = lhs(p) - rhs(p);
318  }
319 
320  template <typename L, typename R, typename O>
321  inline
322  void minus_(trait::image::speed::fastest, const L& lhs,
323  trait::image::speed::fastest, const R& rhs,
324  O& output)
325  {
326  mln_pixter(const L) lp(lhs);
327  mln_pixter(const R) rp(rhs);
328  mln_pixter(O) op(output);
329  for_all_3(lp, rp, op)
330  op.val() = lp.val() - rp.val();
331  }
332 
333 
334  template <typename L, typename R, typename F, typename O>
335  inline
336  void minus_(trait::image::speed::any, const L& lhs,
337  trait::image::speed::any, const R& rhs,
338  const F& f, O& output)
339  {
340  mln_piter(L) p(lhs.domain());
341  for_all(p)
342  output(p) = f(lhs(p) - rhs(p));
343  }
344 
345  template <typename L, typename R, typename F, typename O>
346  inline
347  void minus_(trait::image::speed::fastest, const L& lhs,
348  trait::image::speed::fastest, const R& rhs,
349  const F& f, O& output)
350  {
351  mln_pixter(const L) lp(lhs);
352  mln_pixter(const R) rp(rhs);
353  mln_pixter(O) op(output);
354  for_all_3(lp, rp, op)
355  op.val() = f(lp.val() - rp.val());
356  }
357 
358 
359  template <typename L, typename R>
360  inline
361  void minus_inplace_(trait::image::speed::any, L& lhs,
362  trait::image::speed::any, const R& rhs)
363  {
364  mln_piter(L) p(lhs.domain());
365  for_all(p)
366  lhs(p) -= rhs(p);
367  }
368 
369  template <typename L, typename R>
370  inline
371  void minus_inplace_(trait::image::speed::fastest, L& lhs,
372  trait::image::speed::fastest, const R& rhs)
373  {
374  mln_pixter(L) lp(lhs);
375  mln_pixter(const R) rp(rhs);
376  for_all_2(lp, rp)
377  lp.val() -= rp.val();
378  }
379 
380  } // end of namespace mln::arith::impl
381 
382 
383  // Facades.
384 
385 
386  template <typename I>
387  inline
388  mln_trait_op_uminus(I)
389  uminus(const Image<I>& ima)
390  {
391  mln_trace("arith::uminus");
392 
393  mln_trait_op_uminus(I) output;
394  initialize(output, ima);
395  impl::uminus_(mln_trait_image_speed(I)(), exact(ima), output);
396 
397  return output;
398  }
399 
400 
401  template <typename L, typename R>
402  inline
403  mln_trait_op_minus(L, R)
404  minus(const Image<L>& lhs, const Image<R>& rhs)
405  {
406  mln_trace("arith::minus");
407 
408  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
409 
410  mln_trait_op_minus(L, R) output;
411  initialize(output, lhs);
412  impl::minus_(mln_trait_image_speed(L)(), exact(lhs),
413  mln_trait_image_speed(R)(), exact(rhs), output);
414 
415  return output;
416  }
417 
418 
419  template <typename L, typename R, typename F>
420  inline
421  mln_ch_value(L, mln_result(F))
422  minus(const Image<L>& lhs, const Image<R>& rhs, const Function_v2v<F>& f)
423  {
424  mln_trace("arith::minus");
425 
426  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
427 
428  mln_ch_value(L, mln_result(F)) output;
429  initialize(output, lhs);
430  impl::minus_(mln_trait_image_speed(L)(), exact(lhs),
431  mln_trait_image_speed(R)(), exact(rhs), exact(f), output);
432 
433  return output;
434  }
435 
436 
437  template <typename V, typename L, typename R>
438  inline
439  mln_ch_value(L, V)
440  minus(const Image<L>& lhs, const Image<R>& rhs)
441  {
442  mln_trace("arith::minus");
443 
444  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
445 
446  // Calls the previous version.
447  mln_ch_value(L, V) output = minus(lhs, rhs,
448  mln::fun::v2v::cast<V>());
449 
450  return output;
451  }
452 
453 
454  template <typename I, typename V>
455  inline
456  mln_trait_op_minus(I, V)
457  minus_cst(const Image<I>& input, const V& val)
458  {
459  mln_trace("arith::minus_cst");
460 
461  mln_precondition(exact(input).is_valid());
462 
463  // Calls the previous version.
464  mln_trait_op_minus(I, V) output =
465  minus(input, pw::cst(val) | exact(input).domain());
466 
467  return output;
468  }
469 
470 
471  template <typename I, typename V, typename F>
472  inline
473  mln_ch_value(I, mln_result(F))
474  minus_cst(const Image<I>& input, const V& val, const Function_v2v<F>& f)
475  {
476  mln_trace("arith::minus_cst");
477 
478  mln_precondition(exact(input).is_valid());
479 
480  // Calls the previous version.
481  mln_ch_value(I, mln_result(F)) output =
482  minus(input, pw::cst(val) | exact(input).domain(), f);
483 
484  return output;
485  }
486 
487 
488  template <typename L, typename R>
489  inline
490  void
491  minus_inplace(Image<L>& lhs, const Image<R>& rhs)
492  {
493  mln_trace("arith::minus_inplace");
494 
495  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
496 
497  impl::minus_inplace_(mln_trait_image_speed(L)(), exact(lhs),
498  mln_trait_image_speed(R)(), exact(rhs));
499 
500  }
501 
502 
503  template <typename I, typename V>
504  inline
505  I&
506  minus_cst_inplace(Image<I>& input, const V& val)
507  {
508  mln_trace("arith::minus_cst_inplace");
509 
510  mln_precondition(exact(input).is_valid());
511 
512  // Calls the previous version.
513  minus_inplace(input,
514  pw::cst(val) | exact(input).domain());
515 
516  return exact(input);
517  }
518 
519  } // end of namespace mln::arith
520 
521 # endif // ! MLN_INCLUDE_ONLY
522 
523 } // end of namespace mln
524 
525 
526 #endif // ! MLN_ARITH_MINUS_HH