$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
plus_full.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 <mln/core/image/image1d.hh>
27 #include <mln/core/image/image2d.hh>
28 #include <mln/core/image/image3d.hh>
29 #include <mln/core/image/dmorph/sub_image.hh>
30 
31 #include <mln/core/image/dmorph/image_if.hh>
32 #include <mln/fun/p2b/chess.hh>
33 #include <mln/literal/origin.hh>
34 
35 #include <mln/value/int_u8.hh>
36 #include <mln/value/int_s8.hh>
37 #include <mln/value/int_u16.hh>
38 #include <mln/value/int_s16.hh>
39 #include <mln/debug/iota.hh>
40 
41 #include <mln/arith/plus.hh>
42 
43 
44 
45 struct f_box1d_t : mln::Function_v2b< f_box1d_t >
46 {
47  f_box1d_t(const mln::box1d& b)
48  : b_(b)
49  {
50  }
51  mln::box1d b_;
52  bool operator()(const mln::point1d& p) const
53  {
54  return b_.has(p);
55  }
56 };
57 
58 struct f_box2d_t : mln::Function_v2b< f_box2d_t >
59 {
60  f_box2d_t(const mln::box2d& b)
61  : b_(b)
62  {
63  }
64  mln::box2d b_;
65  bool operator()(const mln::point2d& p) const
66  {
67  return b_.has(p);
68  }
69 };
70 
71 struct f_box3d_t : mln::Function_v2b< f_box3d_t >
72 {
73  f_box3d_t(const mln::box3d& b)
74  : b_(b)
75  {
76  }
77  mln::box3d b_;
78  bool operator()(const mln::point3d& p) const
79  {
80  return b_.has(p);
81  }
82 };
83 
84 
85 
86 namespace mln
87 {
88  template <typename I, typename J>
89  void
90  chck(const Image<I>& ref_, const Image<J>& ima_, const mln_value(I) v)
91  {
92  const I& ref = exact(ref_);
93  const J& ima = exact(ima_);
94 
95  mln_piter(I) p (ima.domain ());
96  for_all(p)
97  mln_assertion ((mln_value(I))ima(p) == (ref(p) + v));
98  }
99 
100  template <typename V>
101  void
102  chk(const V max)
103  {
104  box1d b1(literal::origin, point1d(1));
105  box2d b2(literal::origin, point2d(1,1));
106  box3d b3(literal::origin, point3d(1,1,1));
107  f_box1d_t f_b1(b1);
108  f_box2d_t f_b2(b2);
109  f_box3d_t f_b3(b3);
110  unsigned sli = 2;
111  unsigned row = 3;
112  unsigned col = 16;
113 
114 
115  (std::cerr << "in 1d ... ").flush ();
116  {
117  typedef image1d<V> I;
118 
119  for (V v = 0; v < max; ++v)
120  for (unsigned i = 1; i < col; ++i)
121  {
122  I ima(i);
123  debug::iota(ima);
124  chck (ima, ima + v, v);
125  }
126  }
127  std::cerr << "OK" << std::endl;
128 
129  (std::cerr << "in 2d ... ").flush ();
130  {
131  typedef image2d<V> I;
132 
133  for (V v = 0; v < max; ++v)
134  for (unsigned i = 1; i < col; ++i)
135  for (unsigned j = 1; j < row; ++j)
136  {
137  I ima(j, i);
138  debug::iota(ima);
139  chck (ima, ima + v, v);
140  }
141  }
142  std::cerr << "OK" << std::endl;
143 
144  (std::cerr << "in 3d ... ").flush ();
145  {
146  typedef image3d<V> I;
147 
148  for (V v = 0; v < max; ++v)
149  for (unsigned i = 1; i < col; ++i)
150  for (unsigned j = 1; j < row; ++j)
151  for (unsigned k = 1; k < sli; ++k)
152  {
153  I ima(k, j, i);
154  debug::iota(ima);
155  chck (ima, ima + v, v);
156  }
157  }
158  std::cerr << "OK" << std::endl;
159 
160 
161  (std::cerr << "in subimage 1d ... ").flush ();
162  {
163  typedef image1d<V> I;
164  typedef sub_image<I, box1d> J;
165 
166 
167  for (V v = 0; v < max; ++v)
168  for (unsigned i = 1; i < col; ++i)
169  {
170  I image(i);
171  J ima(image, b1);
172  debug::iota(ima);
173  chck (ima, ima + v, v);
174  }
175  }
176  std::cerr << "OK" << std::endl;
177 
178  (std::cerr << "in subimage 2d ... ").flush ();
179  {
180  typedef image2d<V> I;
181  typedef sub_image<I, box2d> J;
182 
183 
184  for (V v = 0; v < max; ++v)
185  for (unsigned i = 1; i < col; ++i)
186  for (unsigned j = 1; j < row; ++j)
187  {
188  I image(j, i);
189  J ima(image, b2);
190  debug::iota(ima);
191  chck (ima, ima + v, v);
192  }
193  }
194  std::cerr << "OK" << std::endl;
195 
196  (std::cerr << "in subimage 3d ... ").flush ();
197  {
198  typedef image3d<V> I;
199  typedef sub_image<I, box3d> J;
200 
201 
202  for (V v = 0; v < max; ++v)
203  for (unsigned i = 1; i < col; ++i)
204  for (unsigned j = 1; j < row; ++j)
205  for (unsigned k = 1; k < sli; ++k)
206  {
207  I image(k, j, i);
208  J ima(image, b3);
209  debug::iota(ima);
210  chck (ima, ima + v, v);
211  }
212  }
213  std::cerr << "OK" << std::endl;
214  }
215 
216 }
217 
218 
219 
220 
221 
222 int main()
223 {
224  using namespace mln;
225 
226  std::cerr << "Tests arith::plus:" << std::endl;
227  std::cerr << "on int:" << std::endl;
228  chk<int>(1000);
229  std::cerr << "on unsigned:" << std::endl;
230  chk<unsigned>(1000);
231  std::cerr << "on int_u8:" << std::endl;
232  chk<value::int_u8>(16);
233  std::cerr << "on int_u16:" << std::endl;
234  chk<value::int_u16>(1000);
235  std::cerr << "on int_s8:" << std::endl;
236  chk<value::int_s8>(16);
237  std::cerr << "on int_s16:" << std::endl;
238  chk<value::int_s16>(1000);
239 
240 }