$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tests/data/paste.cc
1 // Copyright (C) 2007, 2008, 2009, 2013 EPITA Research and Development
2 // Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #include <mln/core/image/image1d.hh>
28 #include <mln/core/image/image2d.hh>
29 #include <mln/core/image/image3d.hh>
30 #include <mln/pw/image.hh>
31 #include <mln/core/image/flat_image.hh>
32 #include <mln/core/image/vmorph/cast_image.hh>
33 #include <mln/core/image/dmorph/image_if.hh>
34 #include <mln/core/image/dmorph/sub_image.hh>
35 #include <mln/core/image/dmorph/extension_val.hh>
36 
37 #include <mln/data/fill.hh>
38 #include <mln/data/paste.hh>
39 #include <mln/data/compare.hh>
40 
41 #include <mln/fun/p2b/chess.hh>
42 #include <mln/fun/p2v/iota.hh>
43 
44 #include <mln/debug/iota.hh>
45 #include <mln/debug/println.hh>
46 
47 
48 int main()
49 {
50  using namespace mln;
51  const unsigned size = 50;
52 
53  // tests in two dimension
54  {
55  box2d b(point2d(1,2), point2d(2,4));
56  image2d<int> ima(b, 2);
57  debug::iota(ima);
58 
59  box2d b2(point2d(-1,-2), point2d(3,6));
60  image2d<int> ima2(b2, 0);
61  debug::iota(ima2);
62 
63  image2d<int> ima3(b, 2);
64 
65  data::paste(ima, ima2); // Not so fast version...
66  mln_assertion(ima == (ima2 | b));
67 
68  data::paste(ima, ima3); // Fast version...
69  mln_assertion(ima == ima3);
70  }
71 
72  // tests in three dimension
73  {
74  box3d b(point3d(1,2, 1), point3d(2,4, 3));
75  image3d<int> ima(b, 2);
76  debug::iota(ima);
77 
78  box3d b2(point3d(-1,-2, -1), point3d(3,6, 3));
79  image3d<int> ima2(b2, 2);
80  debug::iota(ima2);
81 
82  image3d<int> ima3(b, 2);
83 
84  data::paste(ima, ima2); // Not so fast version...
85  mln_assertion(ima == (ima2 | b));
86 
87  data::paste(ima, ima3); // Fast version...
88  mln_assertion(ima == ima3);
89  }
90 
92  {
93  image1d<unsigned short> ima(size);
94  image1d<unsigned short> out(size);
95 
96  debug::iota(ima);
97  data::paste(ima, out);
98 
99  mln_assertion(ima == out);
100  }
101 
102 
104  {
105  fun::p2v::iota f;
106  const pw::image<fun::p2v::iota, box2d> ima(f, make::box2d(2,2, 5,5));
107  image2d<short unsigned int> out(8, 8);
108 
109  data::fill(out, (short unsigned int)0);
110  data::paste(ima, out);
111  }
112 
113  // flat image test
114  {
115  flat_image<short, box2d> ima(5, make::box2d(size, size));
116  image2d<unsigned short> out(size, size);
117 
118  data::fill_with_value(ima, 51);
119  data::paste(ima, out);
120 
121  mln_assertion(ima == out);
122  }
123 
124  // image if test
125  {
126  typedef image2d<unsigned short> I;
127  typedef fun::p2b::chess F;
128  F f;
129  typedef image_if<I, F> II;
130 
131  I ima(size, size);
132  I out(size, size);
133  II ima_if = ima | f;
134 
135  data::fill_with_value(ima, 0);
136  debug::iota(ima);
137  data::paste(ima_if, out);
138 
139  mln_assertion(ima_if == (out | f));
140  }
141 
142  // cast image test
143  {
144  typedef image2d<unsigned short> I;
145  typedef cast_image_<int, I> II;
146  typedef image2d<unsigned short> III;
147 
148  I in(size, size);
149  II cast(in);
150  III out(size, size);
151 
152  data::fill(in, (unsigned short)51);
153  data::fill(out, (unsigned short)42);
154 
155  data::paste(cast, out);
156 
157  mln_assertion(cast == out);
158  }
159 
160  // sub_image test
161  {
162  typedef image2d<int> I;
163  typedef sub_image< image2d<int>, box2d > II;
164  typedef image2d<unsigned short> III;
165 
166  I ima(size, size);
167  II sub_ima(ima, make::box2d(4,4, 10,10));
168  III out(size, size);
169 
170  data::fill(ima, 51);
171  data::paste(sub_ima, out);
172 
173  II::piter p(sub_ima.domain());
174  for_all(p)
175  mln_assertion(sub_ima(p) == out(p));
176  }
177 
178  // extended image test
179  {
180  typedef image2d<int> I;
181  typedef extension_val< image2d<int> > II;
182  typedef image2d<unsigned short> III;
183 
184  I ima(size, size);
185  II extend_ima(ima, 5);
186  III out(size, size);
187 
188  data::fill(ima, 51);
189  data::paste(extend_ima, out);
190 
191  II::piter p(extend_ima.domain());
192  for_all(p)
193  mln_assertion(extend_ima(p) == out(p));
194  }
195 }