$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
border/fill_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/border/fill.hh>
27 #include <mln/data/fill.hh>
28 #include <mln/opt/element.hh>
29 #include <mln/core/image/image1d.hh>
30 #include <mln/core/image/image2d.hh>
31 #include <mln/core/image/image3d.hh>
32 #include <mln/value/int_u8.hh>
33 #include <mln/value/int_u16.hh>
34 #include <mln/value/int_s8.hh>
35 #include <mln/value/int_s16.hh>
36 #include <mln/value/rgb8.hh>
37 #include <mln/value/rgb16.hh>
38 #include <mln/value/float01_8.hh>
39 #include <mln/value/float01_16.hh>
40 #include <mln/debug/println_with_border.hh>
41 
42 
43 using namespace mln;
44 
45 
46 template <typename T>
47 void
48 check1d(unsigned row, unsigned border, T& value, T& v)
49 {
50  image1d<T> ima(row, border);
51  data::fill (ima, v);
52  border::fill (ima, value);
53 
54  unsigned i = 0;
55  for(i = 0; i < border; ++i)
56  mln_assertion (opt::element(ima, i) == value);
57  unsigned bo = border + row;
58  for(; i < bo; ++i)
59  mln_assertion (opt::element(ima, i) == v);
60  bo += border;
61  for(; i < bo; ++i)
62  mln_assertion (opt::element(ima, i) == value);
63 }
64 
65 template <typename T>
66 void
67 check2d(unsigned row, unsigned col, unsigned border, T& value, T& v)
68 {
69  image2d<T> ima(row, col, border);
70  data::fill (ima, v);
71  border::fill (ima, value);
72 
73  unsigned c = col + 2 * border;
74  unsigned r = row + 2 * border;
75  unsigned bo = c * border + border;
76  unsigned i = 0;
77  unsigned u = col + border;
78  unsigned ww = r * c;
79 
80  for(i = 0; i < bo; ++i)
81  mln_assertion (opt::element(ima, i) == value);
82  bo += c * row;
83  for(; i < bo; ++i)
84  {
85  unsigned cur = i % c;
86  if (cur < border || cur >= u)
87  mln_assertion (opt::element(ima, i) == value);
88  else
89  mln_assertion (opt::element(ima, i) == v);
90  }
91  for(; i < ww; ++i)
92  mln_assertion (opt::element(ima, i) == value);
93 }
94 
95 template <typename T>
96 void
97 check3d(unsigned sli, unsigned row, unsigned col, unsigned border, T& value, T& v)
98 {
99  image3d<T> ima(sli, row, col, border);
100  data::fill (ima, v);
101  border::fill (ima, value);
102 
103  unsigned c = col + 2 * border;
104  unsigned r = row + 2 * border;
105  unsigned bo = c * border + border;
106  unsigned i = 0;
107  unsigned u = col + border;
108  unsigned ww = r * c;
109 
110  for(i = 0; i < bo; ++i)
111  mln_assertion (opt::element(ima, i) == value);
112  bo += c * row;
113  for(; i < bo; ++i)
114  {
115  unsigned cur = i % c;
116  if (cur < border || cur >= u)
117  mln_assertion (opt::element(ima, i) == value);
118  else
119  mln_assertion (opt::element(ima, i) == v);
120  }
121  for(; i < ww; ++i)
122  mln_assertion (opt::element(ima, i) == value);
123 }
124 
125 
126 int
127 main (void)
128 {
129  int limits = 10;
130 
131  {
132  typedef int T;
133  T value = (T) -1;
134  T v = 42;
135 
136  for (int i = 1; i < limits; ++i)
137  for (int j = 1; j < limits; ++j)
138  check1d(i, j, value, v);
139 
140  for (int i = 1; i < limits; ++i)
141  for (int j = 1; j < limits; ++j)
142  for (int k = 1; k < limits; ++k)
143  check2d(i, j, k, value, v);
144  }
145 
146  {
147  typedef unsigned T;
148  T value = (T) -1;
149  T v = 42;
150 
151  for (int i = 1; i < limits; ++i)
152  for (int j = 1; j < limits; ++j)
153  check1d(i, j, value, v);
154 
155  for (int i = 1; i < limits; ++i)
156  for (int j = 1; j < limits; ++j)
157  for (int k = 1; k < limits; ++k)
158  check2d(i, j, k, value, v);
159  }
160 
161  {
162  typedef value::int_u8 T;
163  T value = 255;
164  T v = 42;
165 
166  for (int i = 1; i < limits; ++i)
167  for (int j = 1; j < limits; ++j)
168  check1d(i, j, value, v);
169 
170  for (int i = 1; i < limits; ++i)
171  for (int j = 1; j < limits; ++j)
172  for (int k = 1; k < limits; ++k)
173  check2d(i, j, k, value, v);
174  }
175 
176  {
177  typedef value::int_u16 T;
178  T value = 65535;
179  T v = 42;
180 
181  for (int i = 1; i < limits; ++i)
182  for (int j = 1; j < limits; ++j)
183  check1d(i, j, value, v);
184 
185  for (int i = 1; i < limits; ++i)
186  for (int j = 1; j < limits; ++j)
187  for (int k = 1; k < limits; ++k)
188  check2d(i, j, k, value, v);
189  }
190 
191  {
192  typedef value::int_s8 T;
193  T value = 127;
194  T v = 42;
195 
196  for (int i = 1; i < limits; ++i)
197  for (int j = 1; j < limits; ++j)
198  check1d(i, j, value, v);
199 
200  for (int i = 1; i < limits; ++i)
201  for (int j = 1; j < limits; ++j)
202  for (int k = 1; k < limits; ++k)
203  check2d(i, j, k, value, v);
204  }
205 
206  {
207  typedef value::int_s16 T;
208  T value = 32767;
209  T v = 42;
210 
211  for (int i = 1; i < limits; ++i)
212  for (int j = 1; j < limits; ++j)
213  check1d(i, j, value, v);
214 
215  for (int i = 1; i < limits; ++i)
216  for (int j = 1; j < limits; ++j)
217  for (int k = 1; k < limits; ++k)
218  check2d(i, j, k, value, v);
219  }
220 
221  {
222  typedef value::rgb8 T;
223  T value = T(255, 255, 255);
224  T v = T(42, 0, 0);
225 
226  for (int i = 1; i < limits; ++i)
227  for (int j = 1; j < limits; ++j)
228  check1d(i, j, value, v);
229 
230  for (int i = 1; i < limits; ++i)
231  for (int j = 1; j < limits; ++j)
232  for (int k = 1; k < limits; ++k)
233  check2d(i, j, k, value, v);
234  }
235 
236  {
237  typedef value::rgb16 T;
238  T value = T(65535, 65535, 65535);
239  T v = T(42, 0, 0);
240 
241  for (int i = 1; i < limits; ++i)
242  for (int j = 1; j < limits; ++j)
243  check1d(i, j, value, v);
244 
245  for (int i = 1; i < limits; ++i)
246  for (int j = 1; j < limits; ++j)
247  for (int k = 1; k < limits; ++k)
248  check2d(i, j, k, value, v);
249  }
250 
251 
252  {
253  typedef value::float01_8 T;
254  T value = static_cast<T>(0.9999f);
255  T v = static_cast<T>(0.111f);
256 
257  for (int i = 1; i < limits; ++i)
258  for (int j = 1; j < limits; ++j)
259  check1d(i, j, value, v);
260 
261  for (int i = 1; i < limits; ++i)
262  for (int j = 1; j < limits; ++j)
263  for (int k = 1; k < limits; ++k)
264  check2d(i, j, k, value, v);
265  }
266 
267  {
268  typedef value::float01_16 T;
269  T value = static_cast<T>(0.9999f);
270  T v = static_cast<T>(0.111f);
271 
272  for (int i = 1; i < limits; ++i)
273  for (int j = 1; j < limits; ++j)
274  check1d(i, j, value, v);
275 
276  for (int i = 1; i < limits; ++i)
277  for (int j = 1; j < limits; ++j)
278  for (int k = 1; k < limits; ++k)
279  check2d(i, j, k, value, v);
280  }
281 
282 
283 }