$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
duplicate_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/debug/iota.hh>
29 #include <mln/border/duplicate.hh>
30 #include <mln/value/int_u8.hh>
31 #include <mln/value/int_s8.hh>
32 #include <mln/opt/element.hh>
33 
34 namespace mln
35 {
36 
37  template <typename T>
38  void chck1d(int cols, int border, T ref[])
39  {
40  int c = cols + 2 * border;
41 
42  image1d<T> ima(cols, border);
43  debug::iota(ima);
44  border::duplicate(ima);
45 
46  for (int i = 0; i < c; ++i)
47  mln_assertion(opt::element(ima, i) == ref[i]);
48  }
49 
50  template <typename T>
51  void chck2d(int rows, int cols, int border, T ref[])
52  {
53  int r = rows + 2 * border;
54  int c = cols + 2 * border;
55 
56  image2d<T> ima(rows, cols, border);
57  debug::iota(ima);
58  border::duplicate(ima);
59 
60  for (int i = 0; i < c * r; ++i)
61  mln_assertion(opt::element(ima, i) == ref[i]);
62  }
63 
64 }
65 
66 
67 int
68 main(void)
69 {
70  using namespace mln;
71 
72  std::cerr << "Tests border::duplicate:" << std::endl;
73 
74  {
75  std::cerr << " in 1d :" << std::endl;
76 
77  {
78  (std::cerr << " on int_u8 with border = 3 ... ").flush ();
79 
80  typedef value::int_u8 T;
81  int border = 3;
82  int cols = 2;
83  T ref[8] = {1, 1, 1, 1, 2, 2, 2, 2};
84 
85  chck1d(cols, border, ref);
86  std::cerr << "OK" << std::endl;
87  }
88 
89  {
90  (std::cerr << " on int with border = 2 ... ").flush ();
91 
92  typedef int T;
93  int border = 2;
94  int cols = 3;
95  T ref[7] = {1, 1, 1, 2, 3, 3, 3};
96 
97  chck1d(cols, border, ref);
98  std::cerr << "OK" << std::endl;
99  }
100 
101  {
102  (std::cerr << " on int_s8 with border = 1 ... ").flush ();
103 
104  typedef value::int_s8 T;
105  int border = 1;
106  int cols = 2;
107  T ref[4] = {1, 1, 2, 2};
108 
109  chck1d(cols, border, ref);
110  std::cerr << "OK" << std::endl;
111  }
112 
113  {
114  (std::cerr << " on int with border = 0 ... ").flush ();
115  typedef int T;
116  int border = 0;
117  int cols = 4;
118  T ref[4] = {1, 2, 3, 4};
119 
120  chck1d(cols, border, ref);
121  std::cerr << "OK" << std::endl;
122  }
123  } // end of 1d
124 
125 
126  {
127  std::cerr << " in 2d :" << std::endl;
128 
129  {
130  (std::cerr << " on int with border = 3 ... ").flush ();
131  typedef int T;
132  int border = 3;
133  int rows = 4;
134  int cols = 5;
135  T ref[110] =
136  {
137  1, 1, 1, 1, 2, 3, 4, 5, 5, 5, 5,
138  1, 1, 1, 1, 2, 3, 4, 5, 5, 5, 5,
139  1, 1, 1, 1, 2, 3, 4, 5, 5, 5, 5,
140  1, 1, 1, 1, 2, 3, 4, 5, 5, 5, 5,
141  6, 6, 6, 6, 7, 8, 9, 10, 10, 10, 10,
142  11, 11, 11, 11, 12, 13, 14, 15, 15, 15, 15,
143  16, 16, 16, 16, 17, 18, 19, 20, 20, 20, 20,
144  16, 16, 16, 16, 17, 18, 19, 20, 20, 20, 20,
145  16, 16, 16, 16, 17, 18, 19, 20, 20, 20, 20,
146  16, 16, 16, 16, 17, 18, 19, 20, 20, 20, 20
147  };
148 
149  chck2d(rows, cols, border, ref);
150  std::cerr << "OK" << std::endl;
151  }
152 
153  {
154  (std::cerr << " on int_u8 with border = 3 ... ").flush ();
155  typedef value::int_u8 T;
156  int border = 2;
157  int rows = 4;
158  int cols = 5;
159  T ref[72] =
160  {
161  1, 1, 1, 2, 3, 4, 5, 5, 5,
162  1, 1, 1, 2, 3, 4, 5, 5, 5,
163  1, 1, 1, 2, 3, 4, 5, 5, 5,
164  6, 6, 6, 7, 8, 9, 10, 10, 10,
165  11, 11, 11, 12, 13, 14, 15, 15, 15,
166  16, 16, 16, 17, 18, 19, 20, 20, 20,
167  16, 16, 16, 17, 18, 19, 20, 20, 20,
168  16, 16, 16, 17, 18, 19, 20, 20, 20
169  };
170 
171  chck2d(rows, cols, border, ref);
172  std::cerr << "OK" << std::endl;
173  }
174 
175  {
176  (std::cerr << " on int_s8 with border = 1 ... ").flush ();
177  typedef value::int_s8 T;
178  int border = 1;
179  int rows = 4;
180  int cols = 5;
181  T ref[49] =
182  {
183  1, 1, 2, 3, 4, 5, 5,
184  1, 1, 2, 3, 4, 5, 5,
185  6, 6, 7, 8, 9, 10, 10,
186  11, 11, 12, 13, 14, 15, 15,
187  16, 16, 17, 18, 19, 20, 20,
188  16, 16, 17, 18, 19, 20, 20
189  };
190 
191  chck2d(rows, cols, border, ref);
192  std::cerr << "OK" << std::endl;
193  }
194 
195  {
196  (std::cerr << " on int with border = 0 ... ").flush ();
197  typedef int T;
198  int border = 0;
199  int rows = 4;
200  int cols = 5;
201  T ref[20] =
202  {
203  1, 2, 3, 4, 5,
204  6, 7, 8, 9, 10,
205  11, 12, 13, 14, 15,
206  16, 17, 18, 19, 20
207  };
208 
209  chck2d(rows, cols, border, ref);
210  std::cerr << "OK" << std::endl;
211  }
212 
213  } // end of 2d
214 
215 }