$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
arith/div.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_DIV_HH
27 # define MLN_ARITH_DIV_HH
28 
34 
35 # include <mln/arith/includes.hh>
36 
37 // Specializations are in:
38 # include <mln/arith/div.spe.hh>
39 
40 
41 namespace mln
42 {
43 
44 
45  namespace trait
46  {
47 
48  template <typename L, typename R>
49  struct set_binary_< op::div, Image, L, Image, R >
50  {
51  typedef mln_trait_op_div(mln_value(L), mln_value(R)) value;
52  typedef mln_ch_value(L, value) ret;
53  };
54 
55  template <typename I, typename S>
56  struct set_binary_< op::div, Image, I, mln::value::Scalar, S >
57  {
58  typedef mln_trait_op_div(mln_value(I), S) value;
59  typedef mln_ch_value(I, value) ret;
60  };
61 
62  } // end of namespace mln::trait
63 
64 
65 
66  template <typename L, typename R>
67  mln_trait_op_div(L,R)
68  operator/(const Image<L>& lhs, const Image<R>& rhs);
69 
70  template <typename L, typename R>
71  L&
72  operator/=(Image<L>& lhs, const Image<R>& rhs);
73 
74 
75  template <typename I, typename S>
76  mln_trait_op_div(I,S)
77  operator/(const Image<I>& ima, const value::Scalar<S>& s);
78 
79  template <typename I, typename S>
80  I&
81  operator/=(Image<I>& ima, const value::Scalar<S>& s);
82 
83 
84 
85  namespace arith
86  {
87 
89 
96  template <typename L, typename R, typename O>
97  void div(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output);
98 
99 
101 
108  template <typename I, typename V, typename O>
109  void div_cst(const Image<I>& input, const V& val, Image<O>& output);
110 
111 
113 
123  template <typename L, typename R>
124  void div_inplace(Image<L>& lhs, const Image<R>& rhs);
125 
126 
127  } // end of namespace mln::arith
128 
129 
130 
131 
132 # ifndef MLN_INCLUDE_ONLY
133 
134 
135  template <typename L, typename R>
136  inline
137  mln_trait_op_div(L,R)
138  operator/(const Image<L>& lhs, const Image<R>& rhs)
139  {
140  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
141  mln_trait_op_div(L,R) tmp;
142  initialize(tmp, lhs);
143  arith::div(lhs, rhs, tmp);
144  return tmp;
145  }
146 
147  template <typename L, typename R>
148  inline
149  L&
150  operator/=(Image<L>& lhs, const Image<R>& rhs)
151  {
152  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
153  arith::div_inplace(lhs, rhs);
154  return exact(lhs);
155  }
156 
157 
158  template <typename I, typename S>
159  inline
160  mln_trait_op_div(I,S)
161  operator/(const Image<I>& ima, const value::Scalar<S>& s)
162  {
163  mln_precondition(exact(ima).is_valid());
164  mln_precondition(s != 0);
165  mln_trait_op_div(I,S) tmp;
166  initialize(tmp, ima);
167  arith::div_cst(ima, exact(s), tmp);
168  return tmp;
169  }
170 
171  template <typename I, typename S>
172  inline
173  I&
174  operator/=(Image<I>& ima, const value::Scalar<S>& s)
175  {
176  mln_precondition(exact(ima).is_valid());
177  arith::div_cst(ima, exact(s), ima);
178  return exact(ima);
179  }
180 
181 
182 
183  namespace arith
184  {
185 
186  namespace impl
187  {
188 
189  namespace generic
190  {
191 
192  template <typename L, typename R, typename O>
193  inline
194  void div_(const L& lhs, const R& rhs, O& output)
195  {
196  mln_trace("arith::impl::generic::div_");
197 
198  mln_piter(L) p(lhs.domain());
199  for_all(p)
200  output(p) = lhs(p) / rhs(p);
201 
202  }
203 
204  template <typename L, typename R>
205  inline
206  void div_inplace_(L& lhs, const R& rhs)
207  {
208  mln_trace("arith::impl::generic::div_inplace_");
209 
210  mln_piter(R) p(rhs.domain());
211  for_all(p)
212  lhs(p) /= rhs(p);
213 
214  }
215 
216  } // end of namespace mln::arith::impl::generic
217 
218  } // end of namespace mln::arith::impl
219 
220 
221  // Facades.
222 
223  template <typename L, typename R, typename O>
224  inline
225  void div(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output)
226  {
227  mln_trace("arith::div");
228 
229  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
230  mln_precondition(exact(output).domain() == exact(lhs).domain());
231  impl::div_(mln_trait_image_speed(L)(), exact(lhs),
232  mln_trait_image_speed(R)(), exact(rhs),
233  mln_trait_image_speed(O)(), exact(output));
234 
235  }
236 
237  template <typename I, typename V, typename O>
238  inline
239  void div_cst(const Image<I>& input, const V& val, Image<O>& output)
240  {
241  mln_trace("arith::div_cst");
242 
243  mln_precondition(exact(output).domain() == exact(input).domain());
244  div(input, pw::cst(val) | exact(input).domain(), output);
245  // Calls the previous version.
246 
247  }
248 
249  template <typename L, typename R>
250  inline
251  void div_inplace(Image<L>& lhs, const Image<R>& rhs)
252  {
253  mln_trace("arith::div_inplace");
254 
255  mln_precondition(exact(rhs).domain() <= exact(lhs).domain());
256  impl::div_inplace_(mln_trait_image_speed(L)(), exact(lhs),
257  mln_trait_image_speed(R)(), exact(rhs));
258 
259  }
260 
261  template <typename I, typename V>
262  inline
263  void div_cst_inplace(Image<I>& input, const V& val)
264  {
265  mln_trace("arith::div_cst_inplace");
266 
267  mln_precondition(exact(input).is_valid());
268  div_inplace(input, pw::cst(val) | exact(input).domain());
269  // Calls the previous version.
270 
271  }
272 
273  } // end of namespace mln::arith
274 
275 # endif // ! MLN_INCLUDE_ONLY
276 
277 } // end of namespace mln
278 
279 
280 #endif // ! MLN_ARITH_DIV_HH