$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
paste_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_u8.hh>
37 #include <mln/value/int_u16.hh>
38 
39 #include <mln/value/int_s8.hh>
40 #include <mln/value/int_s16.hh>
41 
42 
43 #include <mln/debug/iota.hh>
44 
45 #include <mln/data/saturate.hh>
46 #include <mln/data/paste.hh>
47 
48 
49 
50 struct f_box1d_t : mln::Function_v2b< f_box1d_t >
51 {
52  f_box1d_t(const mln::box1d& b)
53  : b_(b)
54  {
55  }
56  mln::box1d b_;
57  bool operator()(const mln::point1d& p) const
58  {
59  return b_.has(p);
60  }
61 };
62 
63 struct f_box2d_t : mln::Function_v2b< f_box2d_t >
64 {
65  f_box2d_t(const mln::box2d& b)
66  : b_(b)
67  {
68  }
69  mln::box2d b_;
70  bool operator()(const mln::point2d& p) const
71  {
72  return b_.has(p);
73  }
74 };
75 
76 struct f_box3d_t : mln::Function_v2b< f_box3d_t >
77 {
78  f_box3d_t(const mln::box3d& b)
79  : b_(b)
80  {
81  }
82  mln::box3d b_;
83  bool operator()(const mln::point3d& p) const
84  {
85  return b_.has(p);
86  }
87 };
88 
89 
90 
91 namespace mln
92 {
93  template <typename I, typename J>
94  void
95  chck(Image<I>& input_, Image<J>& output_)
96  {
97  typedef mln_value(I) T;
98  typedef mln_value(J) V;
99  unsigned max_i = mln_max (T);
100  unsigned max_j = mln_max (V);
101  I& input = exact(input_);
102  J& output = exact(output_);
103 
104  if (max_i > max_j)
105  data::saturate_inplace(input, 0, (T)max_j);
106 
107  data::paste(input, output);
108 
109  mln_piter(I) p (input.domain ());
110  for_all(p)
111  mln_assertion ((V)(input(p)) == output(p));
112  }
113 
114  template <typename I, typename J>
115  void
116  chk1d(unsigned cols)
117  {
118  box1d b1(literal::origin, point1d(1));
119  f_box1d_t f_b1(b1);
120 
121  {
122  image1d<I> input (cols);
123  debug::iota(input);
124  image1d<J> output (cols);
125  chck(input, output);
126  }
127 
128  {
129  image1d<I> in (cols);
130  sub_image<image1d<I>, box1d> input (in, b1);
131  debug::iota(input);
132  image1d<J> output (cols);
133  chck(input, output);
134  }
135 
137 // {
138 // image1d<I> in (cols);
139 // image_if<image1d<I>, f_box1d_t> input(in, f_b1);
140 // debug::iota(input);
141 // image1d<J> output (cols);
142 // chck(input, output);
143 // }
144  }
145 
146  template <typename I, typename J>
147  void
148  chk2d(unsigned rows, unsigned cols)
149  {
150  box2d b2(literal::origin, point2d(1, 1));
151  f_box2d_t f_b2(b2);
152 
153  {
154  image2d<I> input (rows, cols);
155  debug::iota(input);
156  image2d<J> output (rows, cols);
157  chck(input, output);
158  }
159 
160  {
161  image2d<I> in (rows, cols);
162  sub_image<image2d<I>, box2d> input (in, b2);
163  debug::iota(input);
164  image2d<J> output (rows, cols);
165  chck(input, output);
166  }
167 
169 // {
170 // image2d<I> in (rows, cols);
171 // image_if<image2d<I>, f_box2d_t> input(in, f_b2);
172 // debug::iota(input);
173 // image2d<J> output (rows, cols);
174 // chck(input, output);
175 // }
176  }
177 
178  template <typename I, typename J>
179  void
180  chk3d(unsigned slis, unsigned rows, unsigned cols)
181  {
182  box3d b3(literal::origin, point3d(1, 1, 1));
183  f_box3d_t f_b3(b3);
184 
185  {
186  image3d<I> input (slis, rows, cols);
187  debug::iota(input);
188  image3d<J> output (slis, rows, cols);
189  chck(input, output);
190  }
191 
192  {
193  image3d<I> in (slis, rows, cols);
194  sub_image<image3d<I>, box3d> input (in, b3);
195  debug::iota(input);
196  image3d<J> output (slis, rows, cols);
197  chck(input, output);
198  }
199 
201 // {
202 // image3d<I> in (slis, rows, cols);
203 // image_if<image3d<I>, f_box3d_t> input(in, f_b3);
204 // debug::iota(input);
205 // image3d<J> output (slis, rows, cols);
206 // chck(input, output);
207 // }
208  }
209 
210 
211  template <typename I, typename J>
212  void
213  chk(unsigned slis, unsigned rows, unsigned cols)
214  {
215  (std::cerr << " in 1d ... ").flush ();
216  {
217  for (unsigned i = 2; i < cols; ++i)
218  chk1d<I, J>(i);
219  }
220  std::cerr << "OK" << std::endl;
221 
222  (std::cerr << " in 2d ... ").flush ();
223  {
224  for (unsigned j = 2; j < rows; ++j)
225  for (unsigned i = 2; i < cols; ++i)
226  chk2d<I, J>(j, i);
227  }
228  std::cerr << "OK" << std::endl;
229 
230  (std::cerr << " in 3d ... ").flush ();
231  {
232  for (unsigned k = 2; k < slis; ++k)
233  for (unsigned j = 2; j < rows; ++j)
234  for (unsigned i = 2; i < cols; ++i)
235  chk3d<I, J>(k, j, i);
236  }
237  std::cerr << "OK" << std::endl;
238  }
239 
240  template <typename I>
241  void
242  ch(unsigned slis, unsigned rows, unsigned cols)
243  {
244  std::cerr << " into int:" << std::endl;
245  chk<I, int>(slis, rows, cols);
246  std::cerr << " into unsigned:" << std::endl;
247  chk<I, unsigned>(slis, rows, cols);
248  std::cerr << " into int_u8:" << std::endl;
249  chk<I, value::int_u8>(slis, rows, cols);
250  std::cerr << " into int_u16:" << std::endl;
251  chk<I, value::int_u16>(slis, rows, cols);
252  std::cerr << " into int_s8:" << std::endl;
253  chk<I, value::int_s8>(slis, rows, cols);
254  std::cerr << " into int_s16:" << std::endl;
255  chk<I, value::int_s16>(slis, rows, cols);
256  }
257 }
258 
259 
260 int main()
261 {
262  using namespace mln;
263 
264  unsigned slis = 4;
265  unsigned rows = 4;
266  unsigned cols = 16;
267 
268  std::cerr << "Tests data::paste:" << std::endl;
269  std::cerr << "on int:" << std::endl;
270  ch<int>(slis, rows, cols);
271  std::cerr << "on unsigned:" << std::endl;
272  ch<unsigned>(slis, rows, cols);
273 }