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