$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
gray_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_INTERNAL_GRAY_F_HXX
28 # define MLN_VALUE_INTERNAL_GRAY_F_HXX
29 
33 
34 # include <mln/value/internal/gray_f.hh>
35 
36 # include <mln/math/round.hh>
37 
38 
39 namespace mln
40 {
41 
42  namespace value
43  {
44 
45  namespace internal
46  {
47 
48  // gray_f.
49 
50  inline
52  {
53  }
54 
55  inline
57  : Floating<gray_f>()
58  {
59  this->v_ = g.v_;
60  }
61 
62  inline
63  gray_f&
65  {
66  this->v_ = g.v_;
67  return *this;
68  }
69 
70  template <unsigned n>
72  {
73  static const float denom =
75  this->v_ = float(rhs.value()) / denom;
76  }
77 
78  template <unsigned n>
79  gray_f&
81  {
82  static const float denom =
84  this->v_ = float(rhs.value()) / denom;
85  return *this;
86  }
87 
88  inline
89  gray_f::gray_f(float val)
90  {
91  this->v_ = val;
92  }
93 
94  inline
95  gray_f&
96  gray_f::operator=(float val)
97  {
98  this->v_ = val;
99  return *this;
100  }
101 
102  inline
104  {
105  this->v_ = rhs.value();
106  }
107 
108  inline
109  gray_f&
111  {
112  this->v_ = rhs.value();
113  return *this;
114  }
115 
116  template <unsigned m>
117  inline
118  gray_f::operator graylevel<m>() const
119  {
120  return graylevel<m>(math::round<int>(this->v_
121  * (mlc_pow_int(2, m) - 1)));
122  }
123 
124 
125  template <unsigned m>
126  inline
127  gray_f::operator gray_<m>() const
128  {
129  return gray_<m>(math::round<int>(this->v_
130  * (mlc_pow_int(2, m) - 1)));
131  }
132 
133  inline
134  gray_f::operator graylevel_f() const
135  {
136  return graylevel_f(this->v_);
137  }
138 
139  inline
140  float
142  {
143  return this->v_;
144  }
145 
146  // Operators.
147 
148  inline
149  std::ostream& operator<<(std::ostream& ostr, const gray_f& g)
150  {
151  return ostr << g.value() << "/gray_f"; // FIXME: Be more explicit!
152  }
153 
154  } // end of namespace mln::value::internal
155 
156  } // end of namespace mln::value
157 
158 } // end of namespace mln
159 
160 #endif // ! MLN_VALUE_INTERNAL_GRAY_F_HXX