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