$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
data/fill_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 
34 #include <mln/literal/origin.hh>
35 
36 #include <mln/value/int_s8.hh>
37 #include <mln/value/int_s16.hh>
38 #include <mln/value/int_u8.hh>
39 #include <mln/value/int_u16.hh>
40 
41 #include <mln/value/rgb8.hh>
42 #include <mln/value/rgb16.hh>
43 
44 
45 #include <mln/debug/iota.hh>
46 
47 #include <mln/data/fill.hh>
48 
49 #include <mln/fun/p2v/iota.hh>
50 
51 
52 
53 
54 
55 
56 struct f_box1d_t : mln::Function_v2b< f_box1d_t >
57 {
58  f_box1d_t(const mln::box1d& b)
59  : b_(b)
60  {
61  }
62  mln::box1d b_;
63  bool operator()(const mln::point1d& p) const
64  {
65  return b_.has(p);
66  }
67 };
68 
69 struct f_box2d_t : mln::Function_v2b< f_box2d_t >
70 {
71  f_box2d_t(const mln::box2d& b)
72  : b_(b)
73  {
74  }
75  mln::box2d b_;
76  bool operator()(const mln::point2d& p) const
77  {
78  return b_.has(p);
79  }
80 };
81 
82 struct f_box3d_t : mln::Function_v2b< f_box3d_t >
83 {
84  f_box3d_t(const mln::box3d& b)
85  : b_(b)
86  {
87  }
88  mln::box3d b_;
89  bool operator()(const mln::point3d& p) const
90  {
91  return b_.has(p);
92  }
93 };
94 
95 
96 
97 namespace mln
98 {
99  template <typename I>
100  void
101  chck(Image<I>& ima_, const mln_value(I) v)
102  {
103  I& ima = exact(ima_);
104 
105  data::fill(ima, v);
106 
107  {
108  mln_piter(I) p (ima.domain ());
109  for_all(p)
110  mln_assertion (ima(p) == v);
111  }
112  }
113 
114  template <typename V>
115  void
116  chk(const V max)
117  {
118  box1d b1(literal::origin, point1d(1));
119  box2d b2(literal::origin, point2d(1,1));
120  box3d b3(literal::origin, point3d(1,1,1));
121  f_box1d_t f_b1(b1);
122  f_box2d_t f_b2(b2);
123  f_box3d_t f_b3(b3);
124  unsigned sli = 2;
125  unsigned row = 3;
126  unsigned col = 16;
127 
128 
129  (std::cerr << "in 1d ... ").flush ();
130  {
131  typedef image1d<V> I;
132 
133  for (V v = 0; v < max; ++v)
134  for (unsigned i = 1; i < col; ++i)
135  {
136  I ima(i);
137  chck (ima, v);
138  }
139  }
140  std::cerr << "OK" << std::endl;
141 
142  (std::cerr << "in 2d ... ").flush ();
143  {
144  typedef image2d<V> I;
145 
146  for (V v = 0; v < max; ++v)
147  for (unsigned i = 1; i < col; ++i)
148  for (unsigned j = 1; j < row; ++j)
149  {
150  I ima(j, i);
151  chck (ima, v);
152  }
153  }
154  std::cerr << "OK" << std::endl;
155 
156  (std::cerr << "in 3d ... ").flush ();
157  {
158  typedef image3d<V> I;
159 
160  for (V v = 0; v < max; ++v)
161  for (unsigned i = 1; i < col; ++i)
162  for (unsigned j = 1; j < row; ++j)
163  for (unsigned k = 1; k < sli; ++k)
164  {
165  I ima(k, j, i);
166  chck (ima, v);
167  }
168  }
169  std::cerr << "OK" << std::endl;
170 
171 
172  (std::cerr << "in subimage 1d ... ").flush ();
173  {
174  typedef image1d<V> I;
175  typedef sub_image<I, box1d> J;
176 
177 
178  for (V v = 0; v < max; ++v)
179  for (unsigned i = 1; i < col; ++i)
180  {
181  I image(i);
182  J ima(image, b1);
183  chck (ima, v);
184  }
185  }
186  std::cerr << "OK" << std::endl;
187 
188  (std::cerr << "in subimage 2d ... ").flush ();
189  {
190  typedef image2d<V> I;
191  typedef sub_image<I, box2d> J;
192 
193 
194  for (V v = 0; v < max; ++v)
195  for (unsigned i = 1; i < col; ++i)
196  for (unsigned j = 1; j < row; ++j)
197  {
198  I image(j, i);
199  J ima(image, b2);
200  chck (ima, v);
201  }
202  }
203  std::cerr << "OK" << std::endl;
204 
205  (std::cerr << "in subimage 3d ... ").flush ();
206  {
207  typedef image3d<V> I;
208  typedef sub_image<I, box3d> J;
209 
210 
211  for (V v = 0; v < max; ++v)
212  for (unsigned i = 1; i < col; ++i)
213  for (unsigned j = 1; j < row; ++j)
214  for (unsigned k = 1; k < sli; ++k)
215  {
216  I image(k, j, i);
217  J ima(image, b3);
218  chck (ima, v);
219  }
220  }
221  std::cerr << "OK" << std::endl;
222  }
223 
224  template <typename V>
225  void
226  chk_rgb(const unsigned min, const unsigned max)
227  {
228  box1d b1(literal::origin, point1d(1));
229  box2d b2(literal::origin, point2d(1,1));
230  box3d b3(literal::origin, point3d(1,1,1));
231  f_box1d_t f_b1(b1);
232  f_box2d_t f_b2(b2);
233  f_box3d_t f_b3(b3);
234  unsigned sli = 2;
235  unsigned row = 3;
236  unsigned col = 16;
237 
238 
239  (std::cerr << "in 1d ... ").flush ();
240  {
241  typedef image1d<V> I;
242 
243  for (unsigned r = min; r < max; ++r)
244  for (unsigned g = min; g < max; ++g)
245  for (unsigned b = min; b < max; ++b)
246  for (unsigned i = 1; i < col; ++i)
247  {
248  I ima(i);
249  chck (ima, V(r,g,b));
250  }
251  }
252  std::cerr << "OK" << std::endl;
253 
254  (std::cerr << "in 2d ... ").flush ();
255  {
256  typedef image2d<V> I;
257 
258  for (unsigned r = min; r < max; ++r)
259  for (unsigned g = min; g < max; ++g)
260  for (unsigned b = min; b < max; ++b)
261  for (unsigned i = 1; i < col; ++i)
262  for (unsigned j = 1; j < row; ++j)
263  {
264  I ima(j, i);
265  chck (ima, V(r,g,b));
266  }
267  }
268  std::cerr << "OK" << std::endl;
269 
270  (std::cerr << "in 3d ... ").flush ();
271  {
272  typedef image3d<V> I;
273 
274  for (unsigned r = min; r < max; ++r)
275  for (unsigned g = min; g < max; ++g)
276  for (unsigned b = min; b < max; ++b)
277  for (unsigned i = 1; i < col; ++i)
278  for (unsigned j = 1; j < row; ++j)
279  for (unsigned k = 1; k < sli; ++k)
280  {
281  I ima(k, j, i);
282  chck (ima, V(r,g,b));
283  }
284  }
285  std::cerr << "OK" << std::endl;
286 
287 
288  (std::cerr << "in subimage 1d ... ").flush ();
289  {
290  typedef image1d<V> I;
291  typedef sub_image<I, box1d> J;
292 
293 
294  for (unsigned r = min; r < max; ++r)
295  for (unsigned g = min; g < max; ++g)
296  for (unsigned b = min; b < max; ++b)
297  for (unsigned i = 1; i < col; ++i)
298  {
299  I image(i);
300  J ima(image, b1);
301  chck (ima, V(r,g,b));
302  }
303  }
304  std::cerr << "OK" << std::endl;
305 
306  (std::cerr << "in subimage 2d ... ").flush ();
307  {
308  typedef image2d<V> I;
309  typedef sub_image<I, box2d> J;
310 
311 
312  for (unsigned r = min; r < max; ++r)
313  for (unsigned g = min; g < max; ++g)
314  for (unsigned b = min; b < max; ++b)
315  for (unsigned i = 1; i < col; ++i)
316  for (unsigned j = 1; j < row; ++j)
317  {
318  I image(j, i);
319  J ima(image, b2);
320  chck (ima, V(r,g,b));
321  }
322  }
323  std::cerr << "OK" << std::endl;
324 
325  (std::cerr << "in subimage 3d ... ").flush ();
326  {
327  typedef image3d<V> I;
328  typedef sub_image<I, box3d> J;
329 
330 
331  for (unsigned r = min; r < max; ++r)
332  for (unsigned g = min; g < max; ++g)
333  for (unsigned b = min; b < max; ++b)
334  for (unsigned i = 1; i < col; ++i)
335  for (unsigned j = 1; j < row; ++j)
336  for (unsigned k = 1; k < sli; ++k)
337  {
338  I image(k, j, i);
339  J ima(image, b3);
340  chck (ima, V(r,g,b));
341  }
342  }
343  std::cerr << "OK" << std::endl;
344  }
345 
346 }
347 
348 
349 int main()
350 {
351  using namespace mln;
352 
353  std::cerr << "Tests data::fill:" << std::endl;
354  std::cerr << "on int:" << std::endl;
355  chk<int>(1000);
356  std::cerr << "on unsigned:" << std::endl;
357  chk<unsigned>(1000);
358  std::cerr << "on int_u8:" << std::endl;
359  chk<value::int_u8>(16);
360  std::cerr << "on int_u16:" << std::endl;
361  chk<value::int_u16>(1000);
362  std::cerr << "on int_s8:" << std::endl;
363  chk<value::int_s8>(16);
364  std::cerr << "on int_s16:" << std::endl;
365  chk<value::int_s16>(1000);
366  std::cerr << "on rgb8:" << std::endl;
367  chk_rgb<value::rgb8>(140, 150);
368  std::cerr << "on rgb16:" << std::endl;
369  chk_rgb<value::rgb16>(60000, 60015);
370 }