$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
graylevel_f.hxx
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_HXX
28 # define MLN_VALUE_GRAYLEVEL_F_HXX
29 
33 
34 # include <mln/value/graylevel_f.hh>
35 
36 
37 namespace mln
38 {
39 
40  namespace value
41  {
42 
43  // graylevel_f.
44 
45  inline
47  {
48  }
49 
50 
51  inline
53  {
54  mln_precondition(val >= 0);
55  mln_precondition(val <= 1);
56  this->v_ = val;
57  }
58 
59  inline
62  {
63  mln_precondition(val >= 0);
64  mln_precondition(val <= 1);
65  this->v_ = val;
66  return *this;
67  }
68 
69  template <unsigned n>
71  {
72  mln_precondition(rhs.to_float() >= 0);
73  mln_precondition(rhs.to_float() <= 1);
74  this->v_ = rhs.to_float();
75  }
76 
77  template <unsigned n>
80  {
81  mln_precondition(rhs.to_float() >= 0);
82  mln_precondition(rhs.to_float() <= 1);
83  this->v_ = rhs.to_float();
84  return *this;
85  }
86 
87  inline
90  {
91  this->v_ = rhs.v_;
92  }
93 
94  inline
97  {
98  mln_precondition(rhs.v_ >= 0);
99  mln_precondition(rhs.v_ <= 1);
100  this->v_ = rhs.v_;
101  return *this;
102  }
103 
104  inline
106  {
107  this->v_ = 0.0f;
108  }
109 
110  inline
111  graylevel_f&
113  {
114  this->v_ = 0.0f;
115  return *this;
116  }
117 
118  inline
120  {
121  this->v_ = 0.5f;
122  }
123 
124  inline
125  graylevel_f&
127  {
128  this->v_ = 0.5f;
129  return *this;
130  }
131 
132  inline
134  {
135  this->v_ = 1.0f;
136  }
137 
138  inline
139  graylevel_f&
141  {
142  this->v_ = 1.0f;
143  return *this;
144  }
145 
146  template <unsigned n>
147  inline
148  graylevel_f::operator graylevel<n>() const
149  {
150  return graylevel<n>(internal::gray_f(*this));
151  }
152 
153  inline
154  float
156  {
157  return this->v_;
158  }
159 
160 
161  // Operators.
162 
163  inline
164  std::ostream& operator<<(std::ostream& ostr, const graylevel_f& g)
165  {
166  return ostr << g.value() << "/gl_f"; // FIXME: Be more explicit!.
167  }
168 
169 
170  template <typename I>
171  inline
172  bool
173  operator==(const Integer<I>& lhs, const graylevel_f& rhs)
174  {
175  return rhs.value() == exact(lhs);
176  }
177 
178  inline
179  bool
180  operator==(const graylevel_f& lhs, const graylevel_f& rhs)
181  {
182  return rhs.value() == lhs.value();
183  }
184 
185 
186  inline
187  mln_trait_op_plus_(graylevel_f, graylevel_f)
188  operator+(const graylevel_f& lhs, const graylevel_f& rhs)
189  {
190  return lhs.value() + rhs.value();
191  }
192 
193 
194  template <unsigned n>
195  inline
196  mln_trait_op_plus(graylevel_f, graylevel<n>)
197  operator+(const graylevel_f& lhs, const graylevel<n>& rhs)
198  {
199  return lhs.value() + graylevel_f(rhs).value();
200  }
201 
202  template <unsigned n>
203  inline
204  mln_trait_op_plus(graylevel_f, graylevel<n>)
205  operator+(const graylevel<n>& lhs, const graylevel_f& rhs)
206  {
207  return rhs.value() + graylevel_f(lhs).value();
208  }
209 
210  template <typename I>
211  inline
212  void
213  operator+(const graylevel_f& lhs, const I& i)
214  {
215  (void) lhs;
216  (void) i;
217  typename
219  }
220 
221  template <typename I>
222  inline
223  void
224  operator+(const I& i, const graylevel_f& rhs)
225  {
226  (void) i;
227  (void) rhs;
228  typename
230  }
231 
232 
233  inline
234  mln_trait_op_minus_(graylevel_f, graylevel_f)
235  operator-(const graylevel_f& lhs, const graylevel_f& rhs)
236  {
237  return lhs.value() - rhs.value();
238  }
239 
240  template <typename I>
241  inline
242  void
243  operator-(const graylevel_f& lhs, const I& i)
244  {
245  (void) lhs;
246  (void) i;
247  typename
249  }
250 
251  template <typename I>
252  inline
253  void
254  operator-(const I& i, const graylevel_f& rhs)
255  {
256  (void) i;
257  (void) rhs;
258  typename
260  }
261 
262 
263  inline
264  mln_trait_op_times_(graylevel_f, graylevel_f)
265  operator*(const graylevel_f& lhs, const graylevel_f& rhs)
266  {
267  return lhs.value() * rhs.value();
268  }
269 
270 
271 
272  template <typename I>
273  inline
274  mln_trait_op_times(graylevel_f, I)
275  operator*(const graylevel_f& lhs, const Integer<I>& rhs)
276  {
277  return lhs.value() * int(exact(rhs));
278  }
279 
280  template <typename F>
281  inline
282  mln_trait_op_times(graylevel_f, F)
283  operator*(const graylevel_f& lhs, const Floating<F>& rhs)
284  {
285  return lhs.value() * exact(rhs);
286  }
287 
288  template <typename F>
289  inline
290  mln_trait_op_times(F, graylevel_f)
291  operator*(const Floating<F>& lhs, const graylevel_f& rhs)
292  {
293  return rhs.value() * exact(lhs);
294  }
295 
296 
297  template <typename S>
298  inline
299  mln_trait_op_times(graylevel_f, S)
300  operator*(const graylevel_f& lhs, const scalar_<S>& rhs)
301  {
302  return lhs.value() * rhs.to_equiv();
303  }
304 
305  template <typename S>
306  inline
307  mln_trait_op_div(graylevel_f, S)
308  operator/(const graylevel_f& lhs, const scalar_<S>& rhs)
309  {
310  mln_precondition(rhs.to_equiv() != S(0));
311  return lhs.value() / rhs.to_equiv();
312  }
313 
314  } // end of namespace mln::value
315 
316 } // end of namespace mln
317 
318 
319 #endif // ! MLN_VALUE_GRAYLEVEL_F_HXX