$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
transform_full.cc
1 // Copyright (C) 2007, 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 <cmath>
27 
28 #include <mln/core/image/image1d.hh>
29 #include <mln/core/image/image2d.hh>
30 #include <mln/core/image/image3d.hh>
31 #include <mln/core/image/dmorph/sub_image.hh>
32 
33 #include <mln/core/image/dmorph/image_if.hh>
34 #include <mln/fun/p2b/chess.hh>
35 
36 #include <mln/literal/origin.hh>
37 
38 #include <mln/value/int_u8.hh>
39 #include <mln/value/int_u16.hh>
40 
41 #include <mln/value/int_s8.hh>
42 #include <mln/value/int_s16.hh>
43 
44 #include <mln/data/fill.hh>
45 #include <mln/data/transform.hh>
46 
47 #include <mln/debug/iota.hh>
48 
49 #include <mln/arith/plus.hh>
50 
51 
52 
53 
54 struct mysqrt : mln::Function_v2v<mysqrt>
55 {
56  typedef unsigned short result;
57  result operator()(int c) const
58  {
59  return result(c % 42);
60  }
61 };
62 
63 
64 namespace mln
65 {
66  template <typename I>
67  void
68  chck(const Image<I>& ref_)
69  {
70  const I& ref = exact(ref_);
71 
72  mln_ch_value(I, mln_result_(mysqrt)) out;
73  {
74  out = data::transform(ref, mysqrt());
75  mln_piter(I) p (ref.domain ());
76  for_all(p)
77  mln_assertion ((mln_value(I))(ref(p) % 42) == out(p) );
78  }
79  }
80 
81  template <typename V>
82  void
83  chk()
84  {
85  unsigned sli = 4;
86  unsigned row = 16;
87  unsigned col = 64;
88 
89 
90  (std::cerr << "in 1d ... ").flush ();
91  {
92  typedef image1d<V> I;
93  typedef sub_image<I, box1d> J;
94 
95  for (unsigned i = 1; i < col; ++i)
96  {
97  I ima(i);
98  debug::iota(ima);
99  chck (ima);
100  }
101  }
102  std::cerr << "OK" << std::endl;
103 
104  (std::cerr << "in 2d ... ").flush ();
105  {
106  typedef image2d<V> I;
107 
108  for (unsigned i = 1; i < col; ++i)
109  for (unsigned j = 1; j < row; ++j)
110  {
111  I ima(j, i);
112  debug::iota(ima);
113  chck (ima);
114  }
115  }
116  std::cerr << "OK" << std::endl;
117 
118  (std::cerr << "in 3d ... ").flush ();
119  {
120  typedef image3d<V> I;
121 
122  for (unsigned i = 1; i < col; ++i)
123  for (unsigned j = 1; j < row; ++j)
124  for (unsigned k = 1; k < sli; ++k)
125  {
126  I ima(k, j, i);
127  debug::iota(ima);
128  chck (ima);
129  }
130  }
131  std::cerr << "OK" << std::endl;
132  }
133 
134 }
135 
136 
137 
138 
139 
140 int main()
141 {
142  using namespace mln;
143 
144  std::cerr << "Tests data::transform:" << std::endl;
145  std::cerr << "on int:" << std::endl;
146  chk<int>();
147  std::cerr << "on unsigned:" << std::endl;
148  chk<unsigned>();
149  std::cerr << "on int_u8:" << std::endl;
150  chk<value::int_u8>();
151  std::cerr << "on int_u16:" << std::endl;
152  chk<value::int_u16>();
153  std::cerr << "on int_s8:" << std::endl;
154  chk<value::int_s8>();
155  std::cerr << "on int_s16:" << std::endl;
156  chk<value::int_s16>();
157 }