$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
gray_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_INTERNAL_GRAY_F_HH
28 # define MLN_VALUE_INTERNAL_GRAY_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/graylevel_f.hh>
54 # else
55 # define MLN_INCLUDE_ONLY
56 # include <mln/value/graylevel_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  namespace value
74  {
77  namespace internal
78  {
79  template <unsigned n> class gray_;
80  struct gray_f;
81  }
82 
83  template <unsigned n> struct graylevel;
84  struct graylevel_f;
85  struct float01_f;
87  }
88 
89 
90 
91  namespace trait
92  {
93 
94 
95  template < template <class, class> class Name>
96  struct set_precise_binary_< Name, mln::value::internal::gray_f, mln::value::internal::gray_f >
97  {
99  };
100 
101  template <>
102  struct set_precise_binary_< op::greater, mln::value::internal::gray_f, mln::value::internal::gray_f >
103  {
104  typedef bool ret;
105  };
106 
107  template <>
108  struct set_precise_binary_< op::eq, mln::value::internal::gray_f, mln::value::internal::gray_f >
109  {
110  typedef bool ret;
111  };
112 
113  /* FIXME: Dead code? */
114  // Necessary??
115 // template <typename F>
116 // struct set_binary_< op::eq,
117 // mln::value::Floating, mln::value::internal::gray_f,
118 // mln::value::Floating, F >
119 // {
120 // typedef bool ret;
121 // };
122 
124  template <typename T> struct value_;
125 
126  // 'gray_f' as a value.
127  template <>
128  struct value_<mln::value::internal::gray_f>
129  {
130  private:
131  typedef mln::value::internal::gray_f self_;
132  typedef float equiv_;
133 
134  public:
135 
136  enum {
137  nbits = mln_nbits(equiv_),
138  card = 0
139  };
140 
141  typedef trait::value::nature::floating nature;
142  typedef trait::value::kind::gray kind;
143  typedef mln_trait_value_quant_(equiv_) quant;
144 
145  static equiv_ min() { return 0; }
146  static equiv_ max() { return 1; }
147  static equiv_ epsilon() { return mln_epsilon(equiv_); }
148 
149  typedef float sum;
150  };
151 
152  } // end of namespace mln::trait
153 
154 
155 
156  namespace value
157  {
158 
159  namespace internal
160  {
161 
163  struct gray_f
164  :
165  public Floating< gray_f >,
166 
167  public internal::value_like_< float, // Equivalent.
168  float, // Encoding.
169  gray_f, // Interoperation.
170  gray_f > // Exact.
171  {
173  gray_f();
174 
176  gray_f(const gray_f& rhs);
177  gray_f& operator=(const gray_f& rhs);
179 
181  template <unsigned n>
182  gray_f(const gray_<n>& rhs);
183  template <unsigned n>
184  gray_f& operator=(const gray_<n>& rhs);
186 
188  gray_f(float val);
189  gray_f& operator=(float val);
191 
193  gray_f(const graylevel_f& val);
194  gray_f& operator=(const graylevel_f& val);
196 
198  template <unsigned m>
199  operator graylevel<m>() const;
200 
202  template <unsigned m>
203  operator gray_<m>() const;
204 
206  operator graylevel_f() const;
207 
209  float value() const;
210  };
211 
212  // Operators.
213 
215  std::ostream& operator<<(std::ostream& ostr, const gray_f& g);
216 
217  } // end of namespace mln::value::internal
218 
219  } // end of namespace mln::value
220 
221 } // end of namespace mln
222 
223 
224 # ifndef MLN_INCLUDE_ONLY
225 # include <mln/value/internal/gray_f.hxx>
226 # include <mln/value/graylevel_f.hxx>
227 # endif // ! MLN_INCLUDE_ONLY
228 
229 
230 #endif // ! MLN_VALUE_INTERNAL_GRAY_F_HH