$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends 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  mln_trace("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  }
202 
203  template <typename L, typename R>
204  inline
205  void times_inplace_(L& lhs, const R& rhs)
206  {
207  mln_trace("arith::impl::generic::times_inplace_");
208 
209  mln_piter(R) p(rhs.domain());
210  for_all(p)
211  lhs(p) *= rhs(p);
212 
213  }
214 
215  } // end of namespace mln::arith::impl::generic
216 
217  } // end of namespace mln::arith::impl
218 
219 
220  // Facades.
221 
222  template <typename L, typename R, typename O>
223  inline
224  void times(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output)
225  {
226  mln_trace("arith::times");
227 
228  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
229  mln_precondition(exact(output).domain() == exact(lhs).domain());
230  impl::times_(mln_trait_image_speed(L)(), exact(lhs),
231  mln_trait_image_speed(R)(), exact(rhs),
232  mln_trait_image_speed(O)(), exact(output));
233 
234  }
235 
236  template <typename I, typename V, typename O>
237  inline
238  void times_cst(const Image<I>& input, const V& val, Image<O>& output)
239  {
240  mln_trace("arith::times_cst");
241 
242  mln_precondition(exact(output).domain() == exact(input).domain());
243  times(input, pw::cst(val) | exact(input).domain(), output);
244  // Calls the previous version.
245 
246  }
247 
248  template <typename L, typename R>
249  inline
250  void times_inplace(Image<L>& lhs, const Image<R>& rhs)
251  {
252  mln_trace("arith::times_inplace");
253 
254  mln_precondition(exact(rhs).domain() <= exact(lhs).domain());
255  impl::times_inplace_(mln_trait_image_speed(L)(), exact(lhs),
256  mln_trait_image_speed(R)(), exact(rhs));
257 
258  }
259 
260  template <typename I, typename V>
261  inline
262  void times_cst_inplace(Image<I>& input, const V& val)
263  {
264  mln_trace("arith::times_cst_inplace");
265 
266  mln_precondition(exact(input).is_valid());
267  times_inplace(input, pw::cst(val) | exact(input).domain());
268  // Calls the previous version.
269 
270  }
271 
272  } // end of namespace mln::arith
273 
274 # endif // ! MLN_INCLUDE_ONLY
275 
276 } // end of namespace mln
277 
278 
279 #endif // ! MLN_ARITH_TIMES_HH