$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
apply_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 <mln/core/image/image1d.hh>
27 #include <mln/core/image/image2d.hh>
28 #include <mln/core/image/image3d.hh>
29 
30 #include <mln/value/int_u8.hh>
31 #include <mln/value/int_u16.hh>
32 #include <mln/value/int_s8.hh>
33 #include <mln/value/int_s16.hh>
34 
35 
36 #include <mln/core/routine/duplicate.hh>
37 #include <mln/data/apply.hh>
38 #include <mln/debug/iota.hh>
39 
40 #include <mln/debug/println.hh>
41 
42 struct qrde : mln::Function_v2v<qrde>
43 {
44  typedef unsigned short result;
45  result operator()(int c) const
46  {
47  return result(c % 42);
48  }
49 };
50 
51 
52 namespace mln
53 {
54  template <typename I>
55  void
56  chck(I& ref)
57  {
58  I out = duplicate (ref);
59 
60  mln_piter(I) p (ref.domain ());
61 
62  {
63  data::apply(out, qrde());
64 
65  for_all(p)
66  mln_assertion((mln_value(I))(ref(p) % 42) == out(p));
67  }
68 
69  }
70 
71  template <typename I>
72  void
73  chk1d(unsigned cols)
74  {
75  image1d<I> ima (cols);
76  debug::iota (ima);
77  chck(ima);
78  }
79 
80  template <typename I>
81  void
82  chk2d(unsigned rows,
83  unsigned cols)
84  {
85  image2d<I> ima (rows, cols);
86  debug::iota (ima);
87  chck(ima);
88  }
89 
90  template <typename I>
91  void
92  chk3d(unsigned slis,
93  unsigned rows,
94  unsigned cols)
95  {
96  image3d<I> ima (slis, rows, cols);
97  debug::iota (ima);
98  chck(ima);
99  }
100 
101 }
102 
103 
104 int main()
105 {
106  using namespace mln;
107 
108  unsigned slis_start = 1;
109  unsigned slis_end = 3;
110 
111  unsigned rows_start = 1;
112  unsigned rows_end = 8;
113 
114  unsigned cols_start = 2;
115  unsigned cols_end = 256;
116 
117 
118  std::cerr << "Tests data::apply" << std::endl;
119 
120  (std::cerr << "in 1d ... ").flush ();
121  {
122  for (unsigned i = cols_start; i < cols_end; ++i)
123  {
124  chk1d<int>(i);
125  chk1d<unsigned>(i);
126  chk1d<value::int_u8>(i);
127  chk1d<value::int_u16>(i);
128  chk1d<value::int_s8>(i);
129  chk1d<value::int_s16>(i);
130  }
131  }
132  std::cerr << "OK" << std::endl;
133 
134  (std::cerr << "in 2d ... ").flush ();
135  {
136  for (unsigned h = rows_start; h < rows_end; ++h)
137  for (unsigned i = cols_start; i < cols_end; ++i)
138  {
139  chk2d<int>(h, i);
140  chk2d<unsigned>(h, i);
141  chk2d<value::int_u8>(h, i);
142  chk2d<value::int_u16>(h, i);
143  chk2d<value::int_s8>(h, i);
144  chk2d<value::int_s16>(h, i);
145  }
146  }
147  std::cerr << "OK" << std::endl;
148 
149 
150  (std::cerr << "in 3d ... ").flush ();
151  {
152  for (unsigned g = slis_start; g < slis_end; ++g)
153  for (unsigned h = rows_start; h < rows_end; ++h)
154  for (unsigned i = cols_start; i < cols_end; ++i)
155  {
156  chk3d<int>(g, h, i);
157  chk3d<unsigned>(g, h, i);
158  chk3d<value::int_u8>(g, h, i);
159  chk3d<value::int_u16>(g, h, i);
160  chk3d<value::int_s8>(g, h, i);
161  chk3d<value::int_s16>(g, h, i);
162  }
163  }
164  std::cerr << "OK" << std::endl;
165 }