$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
graylevel_f.hh
1 // Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013 EPITA Research and
2 // Development 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_VALUE_GRAYLEVEL_F_HH
28 # define MLN_VALUE_GRAYLEVEL_F_HH
29 
33 
34 # include <iostream>
35 
36 # include <mln/value/ops.hh>
37 
38 # include <mln/core/contract.hh>
39 # include <mln/metal/math/pow.hh>
40 # include <mln/metal/bexpr.hh>
41 # include <mln/literal/ops.hh>
42 
43 # include <mln/value/float01_f.hh>
44 # include <mln/trait/value_.hh>
45 
46 /* Because of mutual dependencies between the implementations of
47  mln::value::graylevel_f and mln::value::internal::gray_f, we have
48  to ensure that only the interfaces of the required classes are
49  included here. Implementations are included later, at the bottom of
50  this file. */
51 
52 # ifdef MLN_INCLUDE_ONLY
53 # include <mln/value/internal/gray_f.hh>
54 # else
55 # define MLN_INCLUDE_ONLY
56 # include <mln/value/internal/gray_f.hh>
57 # undef MLN_INCLUDE_ONLY
58 # endif
59 
60 
61 namespace mln
62 {
63 
64  namespace literal
65  {
68  struct black_t;
69  struct medium_gray_t;
70  struct white_t;
72  }
73 
74  namespace value
75  {
78  namespace internal
79  {
80  struct gray_f;
81  }
82 
83  struct graylevel_f;
84  template <unsigned n> struct graylevel;
85  struct float01_f;
87  }
88 
89 
90 
91  namespace trait
92  {
93 
94  template <>
95  struct set_precise_binary_< op::plus, mln::value::graylevel_f, mln::value::graylevel_f >
96  {
98  };
99 
100  template <unsigned n>
101  struct set_precise_binary_< op::plus, mln::value::graylevel_f, mln::value::graylevel<n> >
102  {
104  };
105  template <unsigned n>
106  struct set_precise_binary_< op::plus, mln::value::graylevel<n>, mln::value::graylevel_f >
107  {
109  };
110 
111  template <>
112  struct set_precise_binary_< op::minus, mln::value::graylevel_f, mln::value::graylevel_f >
113  {
115  };
116 
117  template <>
118  struct set_precise_binary_< op::times, mln::value::graylevel_f, mln::value::graylevel_f >
119  {
121  };
122 
123  template <>
124  struct set_precise_binary_< op::div, mln::value::graylevel_f, mln::value::graylevel_f >
125  {
127  };
128 
129  template < typename I >
130  struct set_binary_< op::times,
133  {
135  };
136 
137  template < typename I >
138  struct set_binary_< op::times,
141  {
143  };
144 
145 
146  template < typename F >
147  struct set_binary_< op::times,
150  {
152  };
153 
154  template < typename F >
155  struct set_binary_< op::times,
158  {
160  };
161 
162 
163  template < typename S >
164  struct set_precise_binary_< op::times, mln::value::graylevel_f, mln::value::scalar_<S> >
165  {
167  };
168 
169  template < typename S >
170  struct set_precise_binary_< op::div, mln::value::graylevel_f, mln::value::scalar_<S> >
171  {
173  };
174 
175 
177  template <typename T> struct value_;
178 
179  // 'graylevel_f' as a value.
180  template <>
181  struct value_<mln::value::graylevel_f>
182  {
183  private:
184  typedef mln::value::graylevel_f self_;
185  typedef mln::value::float01_f equiv_;
186 
187  public:
188 
189  enum {
190  dim = 1,
191  nbits = mln_nbits(equiv_),
192  card = 0
193  };
194 
195  typedef trait::value::nature::floating nature;
196  typedef trait::value::kind::gray kind;
197  typedef mln_trait_value_quant_(equiv_) quant;
198 
199  static const equiv_ min() { return 0; }
200  static const equiv_ max() { return 1; }
201  static const equiv_ epsilon() { return mln_epsilon(equiv_); }
202 
203  typedef float comp;
204 
205  typedef float sum;
206  };
207 
208  } // end of namespace mln::trait
209 
210 
211  namespace value
212  {
213 
215  struct graylevel_f
216  :
217  public Floating< graylevel_f >,
218 
219  public internal::value_like_< float01_f, // Equivalent.
220  mln_enc_(float01_f),// Encoding.
221  internal::gray_f, // Interoperation.
222  graylevel_f > // Exact.
223  {
225  graylevel_f();
227  graylevel_f(const graylevel_f& rhs);
229  graylevel_f& operator=(const graylevel_f& rhs);
230 
231 
233  graylevel_f(float val);
235  graylevel_f& operator=(float val);
236 
238  template <unsigned n>
239  graylevel_f(const graylevel<n>& rhs);
241  template <unsigned n>
242  graylevel_f& operator=(const graylevel<n>& rhs);
243 
250 
253  graylevel_f& operator=(const mln::literal::black_t&);
254  graylevel_f& operator=(const mln::literal::medium_gray_t&);
255  graylevel_f& operator=(const mln::literal::white_t&);
257 
259  template <unsigned n>
260  operator graylevel<n>() const;
261 
263  float value() const;
264  };
265 
266 
267  // Operators.
268 
270  std::ostream& operator<<(std::ostream& ostr, const graylevel_f& g);
271 
272 
273  // Integer<I> == graylevel_f.
274  template <typename I>
275  bool
276  operator==(const Integer<I>& lhs, const graylevel_f& rhs);
277 
278  // graylevel_f == graylevel_f.
279  // Op glf == glf
280  bool
281  operator==(const graylevel_f& lhs, const graylevel_f& rhs);
282 
283 
284  // graylevel_f + graylevel_f.
285  mln_trait_op_plus_(graylevel_f, graylevel_f)
286  operator+(const graylevel_f& lhs, const graylevel_f& rhs);
287 
288  // graylevel_f + graylevel<n>.
289  template <unsigned n>
290  mln_trait_op_plus(graylevel_f, graylevel<n>)
291  operator+(const graylevel_f& lhs, const graylevel<n>& rhs);
292  // graylevel<n> + graylevel_f.
293  template <unsigned n>
294  mln_trait_op_plus(graylevel_f, graylevel<n>)
295  operator+(const graylevel<n>& lhs, const graylevel_f& rhs);
296 
297  // graylevel_f + another type
298  template <typename I>
299  void
300  operator+(const graylevel_f& lhs, const I& i);
301  // another type + graylevel_f
302  template <typename I>
303  void
304  operator+(const I& i, const graylevel_f& rhs);
305 
306 
307  // graylevel_f - graylevel_f.
308  mln_trait_op_minus_(graylevel_f, graylevel_f)
309  operator-(const graylevel_f& lhs, const graylevel_f& rhs);
310 
311  // graylevel_f - another type
312  template <typename I>
313  void
314  operator-(const graylevel_f& lhs, const I& i);
315  // another type - graylevel_f
316  template <typename I>
317  void
318  operator-(const I& i, const graylevel_f& rhs);
319 
320 
321  // graylevel_f * graylevel_f.
322  mln_trait_op_times_(graylevel_f, graylevel_f)
323  operator*(const graylevel_f& lhs, const graylevel_f& rhs);
324 
325 
326  /* FIXME: These operators are apparently implemented nowhere.
327  Implement them or remove these declarations. */
328 #if 0
329  // With Builtins.
330 
331  // graylevel_f * T.
332  template <unsigned n, typename T>
333  mln_trait_op_times(graylevel_f, T)
334  operator*(const graylevel_f& lhs, const T& rhs);
335 
336  // T * graylevel_f.
337  template <unsigned n, typename T>
338  mln_trait_op_times(graylevel_f, T)
339  operator*(const T& lhs, const graylevel_f& rhs);
340 
341  // graylevel_f / T.
342  template <unsigned n, typename T>
343  internal::gray_f
344  operator/(const graylevel_f& lhs, const T& rhs);
345 #endif
346 
347 
348  // With Integer.
349 
350  // graylevel_f * Integer<I>.
351  template <typename I>
352  mln_trait_op_times(graylevel_f, I)
353  operator*(const graylevel_f& lhs, const Integer<I>& rhs);
354 
355  // Integer<I> * graylevel_f.
356  template <typename I>
357  mln_trait_op_times(I, graylevel_f)
358  operator*(const Integer<I>& lhs, const graylevel_f& rhs);
359 
360 
361  /* FIXME: These operators are apparently implemented nowhere.
362  Implement them or remove these declarations. */
363 #if 0
364  // graylevel_f / Integer<I>.
365  template <typename I>
366  mln_trait_op_div(graylevel_f, I)
367  operator/(const graylevel_f& lhs, const Integer<I>& rhs);
368 
369  // Integer<I> / graylevel_f.
370  template <typename I>
371  mln_trait_op_div(I, graylevel_f)
372  operator/(const Integer<I>& lhs, const graylevel_f& rhs);
373 #endif
374 
375 
376  // With Floating.
377 
378  // graylevel_f * Floating<F>.
379  template <typename F>
380  mln_trait_op_times(graylevel_f, F)
381  operator*(const graylevel_f& lhs, const Floating<F>& rhs);
382 
383  // Floating<F> * graylevel_f.
384  template <typename F>
385  mln_trait_op_times(F, graylevel_f)
386  operator*(const Floating<F>& lhs, const graylevel_f& rhs);
387 
388 
389  /* FIXME: These operators are apparently implemented nowhere.
390  Implement them or remove these declarations. */
391 #if 0
392  // graylevel_f / Floating<F>.
393  template <typename F>
394  mln_trait_op_div(graylevel_f, F)
395  operator/(const graylevel_f& lhs, const Floating<F>& rhs);
396 
397  // Floating<F> / graylevel_f.
398  template <typename F>
399  mln_trait_op_div(F, graylevel_f)
400  operator/(const Floating<F>& lhs, const graylevel_f& rhs);
401 #endif
402 
403 
404  // With scalar_.
405 
406  // graylevel * scalar_<S>
407  template <typename S>
408  mln_trait_op_times(graylevel_f, S)
409  operator*(const graylevel_f& lhs, const scalar_<S>& rhs);
410 
411  // graylevel / scalar_<S>
412  template <typename S>
413  mln_trait_op_div(graylevel_f, S)
414  operator/(const graylevel_f& lhs, const scalar_<S>& rhs);
415 
416  } // end of namespace mln::value
417 
418 } // end of namespace mln
419 
420 
421 # ifndef MLN_INCLUDE_ONLY
422 # include <mln/value/graylevel_f.hxx>
423 # include <mln/value/internal/gray_f.hxx>
424 # endif // ! MLN_INCLUDE_ONLY
425 
426 
427 #endif // ! MLN_VALUE_GRAYLEVEL_F_HH