$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
arith/min.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_MIN_HH
28 # define MLN_ARITH_MIN_HH
29 
33 
34 # include <mln/core/concept/image.hh>
35 
36 
37 // Specializations are in:
38 # include <mln/arith/min.spe.hh>
39 
40 namespace mln
41 {
42 
43  namespace arith
44  {
45 
47 
54  template <typename L, typename R>
55  mln_concrete(L)
56  min(const Image<L>& lhs, const Image<R>& rhs);
57 
58 
60 
66  template <typename L, typename R>
67  void min_inplace(Image<L>& lhs, const Image<R>& rhs);
68 
69 
70 # ifndef MLN_INCLUDE_ONLY
71 
72  namespace impl
73  {
74 
75  namespace generic
76  {
77  template <typename L, typename R, typename O>
78  inline
79  void min_(const L& lhs, const R& rhs, O& output)
80  {
81  mln_trace("data::arith::generic::min_");
82 
83  mln_piter(L) p(lhs.domain());
84  for_all(p)
85  output(p) = lhs(p) < rhs(p) ? lhs(p) : rhs(p);
86  }
87 
88  template <typename L, typename R>
89  inline
90  void min_inplace_(L& lhs, const R& rhs)
91  {
92  mln_trace("data::arith::generic::min_inplace_");
93 
94  mln_piter(L) p(lhs.domain());
95  for_all(p)
96  if (rhs(p) < lhs(p))
97  lhs(p) = rhs(p);
98 
99  }
100 
101  } // end of namespace mln::arith::impl::generic
102 
103  } // end of namespace mln::arith::impl
104 
105 
106  // Facades.
107 
108  template <typename L, typename R>
109  inline
110  mln_concrete(L) min(const Image<L>& lhs, const Image<R>& rhs)
111  {
112  mln_trace("arith::min");
113  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
114 
115  mln_concrete(L) output;
116  initialize(output, lhs);
117  impl::min_(mln_trait_image_speed(L)(), exact(lhs),
118  mln_trait_image_speed(R)(), exact(rhs), output);
119 
120  return output;
121  }
122 
123  template <typename L, typename R>
124  inline
125  void min_inplace(Image<L>& lhs, const Image<R>& rhs)
126  {
127  mln_trace("arith::min_inplace");
128 
129  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
130  impl::min_inplace_(mln_trait_image_speed(L)(), exact(lhs),
131  mln_trait_image_speed(R)(), exact(rhs));
132 
133  }
134 
135 # endif // ! MLN_INCLUDE_ONLY
136 
137  } // end of namespace mln::arith
138 
139 } // end of namespace mln
140 
141 
142 #endif // ! MLN_ARITH_MIN_HH