$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
float01.cc
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 #include <iostream>
27 
28 #include <mln/core/concept/function.hh>
29 #include <mln/value/float01_8.hh>
30 #include <mln/value/float01_16.hh>
31 #include <mln/value/int_u8.hh>
32 
33 
34 namespace mln
35 {
36 
37  using namespace value;
38 
39  float fi(int) { return 0.5f; }
40  int ii(int) { return 1; }
41 
42  float fd(double) { return 0.5f; }
43  int id(double) { return 1; }
44 
45 
46  struct tofloat01 : Function_v2v<tofloat01>
47  {
48 
49  typedef float01_<12> result;
50  result operator()(int_u8 v) const
51  {
52  result ret = static_cast<float>(v) / static_cast<float>(mln_max(int_u8));
53  // std::cout << v << "-> " << ret << std::endl;
54  return ret;
55  }
56  };
57 
58  struct to8bits : Function_v2v<to8bits>
59  {
60 
61  typedef int_u8 result;
62  result operator()(float01_<12> v) const
63  {
64  result ret = static_cast<int>(v.value() * 255);
65  // FIXME: Dead code.
66  //std::cout << v << "-> " << ret << std::endl;
67  return ret;
68  }
69  };
70 
71 } // mln
72 
73 
74 int main()
75 {
76  using namespace mln;
77 
78  value::float01_8 a(0.5);
79  value::float01_16 b(0.5);
80 
81  mln_assertion(approx_equal(b,a));
82 
83  std::cout << b << std::endl;
84  b = b + 0.2f;
85  std::cout << b << std::endl;
86  b = b - 0.2f;
87  std::cout << b << std::endl;
88  b = b * 1.5f;
89  std::cout << b << std::endl;
90  b = b / 4.6f;
91  std::cout << b << std::endl;
92 
93  b = b / 3;
94  std::cout << b << std::endl;
95  b = b * 1;
96  std::cout << b << std::endl;
97 
98  a = fi( static_cast<int>(a) );
99  a = static_cast<float>( ii( static_cast<int>(a) ) );
100  a = fd(a);
101  a = static_cast<float>( id(a) );
102 
103  b = a;
104  a = b;
105  b = 0.34f;
106  std::cout << b << std::endl;
107  b = 0;
108  std::cout << b << std::endl;
109  b = 1;
110  std::cout << b << std::endl;
111 }