Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
arith/times.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_TIMES_HH
27 # define MLN_ARITH_TIMES_HH
28 
34 
35 # include <mln/arith/includes.hh>
36 
37 
38 // Specializations are in:
39 # include <mln/arith/times.spe.hh>
40 
41 namespace mln
42 {
43 
44 
45  namespace trait
46  {
47 
48  template <typename L, typename R>
49  struct set_binary_< op::times, Image, L, Image, R >
50  {
51  typedef mln_trait_op_times(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::times, Image, I, mln::value::Scalar, S >
57  {
58  typedef mln_trait_op_times(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_times(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_times(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 times(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output);
98 
99 
101 
108  template <typename I, typename V, typename O>
109  void times_cst(const Image<I>& input, const V& val, Image<O>& output);
110 
111 
113 
123  template <typename L, typename R>
124  void times_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_times(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_times(L,R) tmp;
142  initialize(tmp, lhs);
143  arith::times(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::times_inplace(lhs, rhs);
154  return exact(lhs);
155  }
156 
157 
158  template <typename I, typename S>
159  inline
160  mln_trait_op_times(I,S)
161  operator*(const Image<I>& ima, const value::Scalar<S>& s)
162  {
163  mln_precondition(exact(ima).is_valid());
164  mln_trait_op_times(I,S) tmp;
165  initialize(tmp, ima);
166  arith::times_cst(ima, exact(s), tmp);
167  return tmp;
168  }
169 
170  template <typename I, typename S>
171  inline
172  I&
173  operator*=(Image<I>& ima, const value::Scalar<S>& s)
174  {
175  mln_precondition(exact(ima).is_valid());
176  arith::times_cst(ima, exact(s), ima);
177  return exact(ima);
178  }
179 
180 
181 
182  namespace arith
183  {
184 
185  namespace impl
186  {
187 
188  namespace generic
189  {
190 
191  template <typename L, typename R, typename O>
192  inline
193  void times_(const L& lhs, const R& rhs, O& output)
194  {
195  trace::entering("arith::impl::generic::times_");
196 
197  mln_piter(L) p(lhs.domain());
198  for_all(p)
199  output(p) = lhs(p) * rhs(p);
200 
201  trace::exiting("arith::impl::generic::times_");
202  }
203 
204  template <typename L, typename R>
205  inline
206  void times_inplace_(L& lhs, const R& rhs)
207  {
208  trace::entering("arith::impl::generic::times_inplace_");
209 
210  mln_piter(R) p(rhs.domain());
211  for_all(p)
212  lhs(p) *= rhs(p);
213 
214  trace::exiting("arith::impl::generic::times_inplace_");
215  }
216 
217  } // end of namespace mln::arith::impl::generic
218 
219  } // end of namespace mln::arith::impl
220 
221 
222  // Facades.
223 
224  template <typename L, typename R, typename O>
225  inline
226  void times(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output)
227  {
228  trace::entering("arith::times");
229 
230  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
231  mln_precondition(exact(output).domain() == exact(lhs).domain());
232  impl::times_(mln_trait_image_speed(L)(), exact(lhs),
233  mln_trait_image_speed(R)(), exact(rhs),
234  mln_trait_image_speed(O)(), exact(output));
235 
236  trace::exiting("arith::times");
237  }
238 
239  template <typename I, typename V, typename O>
240  inline
241  void times_cst(const Image<I>& input, const V& val, Image<O>& output)
242  {
243  trace::entering("arith::times_cst");
244 
245  mln_precondition(exact(output).domain() == exact(input).domain());
246  times(input, pw::cst(val) | exact(input).domain(), output);
247  // Calls the previous version.
248 
249  trace::exiting("arith::times_cst");
250  }
251 
252  template <typename L, typename R>
253  inline
254  void times_inplace(Image<L>& lhs, const Image<R>& rhs)
255  {
256  trace::entering("arith::times_inplace");
257 
258  mln_precondition(exact(rhs).domain() <= exact(lhs).domain());
259  impl::times_inplace_(mln_trait_image_speed(L)(), exact(lhs),
260  mln_trait_image_speed(R)(), exact(rhs));
261 
262  trace::exiting("arith::times_inplace");
263  }
264 
265  template <typename I, typename V>
266  inline
267  void times_cst_inplace(Image<I>& input, const V& val)
268  {
269  trace::entering("arith::times_cst_inplace");
270 
271  mln_precondition(exact(input).is_valid());
272  times_inplace(input, pw::cst(val) | exact(input).domain());
273  // Calls the previous version.
274 
275  trace::exiting("arith::times_cst_inplace");
276  }
277 
278  } // end of namespace mln::arith
279 
280 # endif // ! MLN_INCLUDE_ONLY
281 
282 } // end of namespace mln
283 
284 
285 #endif // ! MLN_ARITH_TIMES_HH