fill_full.cc 9.04 KB
Newer Older
Guillaume Duhamel's avatar
Guillaume Duhamel committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library.  This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING.  If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction.  Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License.  This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.

28
/*! \file tests/border/fill_full.cc
Guillaume Duhamel's avatar
Guillaume Duhamel committed
29
30
31
32
33
34
 *
 * \brief Tests on mln::border::fill.
 */

#include <mln/border/fill.hh>
#include <mln/level/fill.hh>
35
36
37
#include <mln/core/image/image1d.hh>
#include <mln/core/image/image2d.hh>
#include <mln/core/image/image3d.hh>
Guillaume Duhamel's avatar
Guillaume Duhamel committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <mln/value/int_u8.hh>
#include <mln/value/int_u16.hh>
#include <mln/value/int_s8.hh>
#include <mln/value/int_s16.hh>
#include <mln/value/rgb8.hh>
#include <mln/value/rgb16.hh>
#include <mln/value/float01_8.hh>
#include <mln/value/float01_16.hh>
#include <mln/debug/println_with_border.hh>

using namespace mln;


template <typename T>
int
check1d(unsigned row, unsigned border, T& value, T& v)
{
  image1d<T> ima(row, border);
  level::fill (ima, v);
  border::fill (ima, value);

  unsigned i = 0;
  for(i = 0; i < border; ++i)
    mln_assertion (ima[i] == value);
  unsigned bo = border + row;
  for(; i < bo; ++i)
    mln_assertion (ima[i] == v);
  bo += border;
  for(; i < bo; ++i)
    mln_assertion (ima[i] == value);
}

template <typename T>
int
check2d(unsigned row, unsigned col, unsigned border, T& value, T& v)
{
  image2d<T> ima(row, col, border);
  level::fill (ima, v);
  border::fill (ima, value);

  unsigned c = col + 2 * border;
  unsigned r = row + 2 * border;
  unsigned bo = c * border + border;
  unsigned i = 0;
  unsigned u = col + border;
  unsigned ww = r * c;

  for(i = 0; i < bo; ++i)
    mln_assertion (ima[i] == value);
  bo += c * row;
  for(; i < bo; ++i)
    {
      unsigned cur = i % c;
      if (cur < border || cur >= u)
	mln_assertion (ima[i] == value);
      else
	mln_assertion (ima[i] == v);
    }
  for(; i < ww; ++i)
    mln_assertion (ima[i] == value);
}

template <typename T>
int
check3d(unsigned sli, unsigned row, unsigned col, unsigned border, T& value, T& v)
{
  image3d<T> ima(sli, row, col, border);
  level::fill (ima, v);
  border::fill (ima, value);

  unsigned c = col + 2 * border;
  unsigned r = row + 2 * border;
  unsigned bo = c * border + border;
  unsigned i = 0;
  unsigned u = col + border;
  unsigned ww = r * c;

  for(i = 0; i < bo; ++i)
    mln_assertion (ima[i] == value);
  bo += c * row;
  for(; i < bo; ++i)
    {
      unsigned cur = i % c;
      if (cur < border || cur >= u)
	mln_assertion (ima[i] == value);
      else
	mln_assertion (ima[i] == v);
    }
  for(; i < ww; ++i)
    mln_assertion (ima[i] == value);
}


int
main (void)
{
  int limits = 10;

136
137
  std::cerr << "Tests border::fill:" << std::endl;

Guillaume Duhamel's avatar
Guillaume Duhamel committed
138
  {
139
    std::cerr << "  on int:" << std::endl;
Guillaume Duhamel's avatar
Guillaume Duhamel committed
140
141
142
143
144

    typedef int T;
    T value = (T) -1;
    T v = 42;

145
    (std::cerr << "    in 1d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
146
147
148
149
150
151
152
153

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	    check1d(i, j, value, v);

    std::cerr << "OK" << std::endl;


154
    (std::cerr << "    in 2d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
155
156
157
158
159
160
161
162
163
164

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	for (int k = 1; k < limits; ++k)
	    check2d(i, j, k, value, v);

    std::cerr << "OK" << std::endl;
  }

  {
165
    std::cerr << "  on unsigned:" << std::endl;
Guillaume Duhamel's avatar
Guillaume Duhamel committed
166
167
168
169
170

    typedef unsigned T;
    T value = (T) -1;
    T v = 42;

171
    (std::cerr << "    in 1d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
172
173
174
175
176
177
178
179

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	    check1d(i, j, value, v);

    std::cerr << "OK" << std::endl;


180
    (std::cerr << "    in 2d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
181
182
183
184
185
186
187
188
189
190

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	for (int k = 1; k < limits; ++k)
	    check2d(i, j, k, value, v);

    std::cerr << "OK" << std::endl;
  }

  {
191
    std::cerr << "  on int_u8:" << std::endl;
Guillaume Duhamel's avatar
Guillaume Duhamel committed
192
193
194
195
196

    typedef value::int_u8 T;
    T value = 255;
    T v = 42;

197
    (std::cerr << "    in 1d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
198
199
200
201
202
203
204
205

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	    check1d(i, j, value, v);

    std::cerr << "OK" << std::endl;


206
    (std::cerr << "    in 2d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
207
208
209
210
211
212
213
214
215
216

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	for (int k = 1; k < limits; ++k)
	    check2d(i, j, k, value, v);

    std::cerr << "OK" << std::endl;
  }

  {
217
    std::cerr << "  on int_u16:"  << std::endl;
Guillaume Duhamel's avatar
Guillaume Duhamel committed
218
219
220
221
222

    typedef value::int_u16 T;
    T value = 65535;
    T v = 42;

223
    (std::cerr << "    in 1d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
224
225
226
227
228
229
230
231

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	    check1d(i, j, value, v);

    std::cerr << "OK" << std::endl;


232
    (std::cerr << "    in 2d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
233
234
235
236
237
238
239
240
241
242

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	for (int k = 1; k < limits; ++k)
	    check2d(i, j, k, value, v);

    std::cerr << "OK" << std::endl;
  }

  {
243
    std::cerr << "  on int_s8:" << std::endl;
Guillaume Duhamel's avatar
Guillaume Duhamel committed
244
245
246
247
248

    typedef value::int_s8 T;
    T value = 127;
    T v = 42;

249
    (std::cerr << "    in 1d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
250
251
252
253
254
255
256
257

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	    check1d(i, j, value, v);

    std::cerr << "OK" << std::endl;


258
    (std::cerr << "    in 2d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
259
260
261
262
263
264
265
266
267
268

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	for (int k = 1; k < limits; ++k)
	    check2d(i, j, k, value, v);

    std::cerr << "OK" << std::endl;
  }

  {
269
    std::cerr << "  on int_s16:"  << std::endl;
Guillaume Duhamel's avatar
Guillaume Duhamel committed
270
271
272
273
274

    typedef value::int_s16 T;
    T value = 32767;
    T v = 42;

275
    (std::cerr << "    in 1d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
276
277
278
279
280
281
282
283

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	    check1d(i, j, value, v);

    std::cerr << "OK" << std::endl;


284
    (std::cerr << "    in 2d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
285
286
287
288
289
290
291
292
293
294

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	for (int k = 1; k < limits; ++k)
	    check2d(i, j, k, value, v);

    std::cerr << "OK" << std::endl;
  }

  {
295
    std::cerr << "  on rgb8:"  << std::endl;
Guillaume Duhamel's avatar
Guillaume Duhamel committed
296
297
298
299
300

    typedef value::rgb8 T;
    T value = T(255, 255, 255);
    T v = T(42, 0, 0);

301
    (std::cerr << "    in 1d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
302
303
304
305
306
307
308
309

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	    check1d(i, j, value, v);

    std::cerr << "OK" << std::endl;


310
    (std::cerr << "    in 2d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
311
312
313
314
315
316
317
318
319
320

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	for (int k = 1; k < limits; ++k)
	    check2d(i, j, k, value, v);

    std::cerr << "OK" << std::endl;
  }

  {
321
    std::cerr << "  on rgb16:" << std::endl;
Guillaume Duhamel's avatar
Guillaume Duhamel committed
322
323
324
325
326

    typedef value::rgb16 T;
    T value = T(65535, 65535, 65535);
    T v = T(42, 0, 0);

327
    (std::cerr << "    in 1d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
328
329
330
331
332
333
334
335

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	    check1d(i, j, value, v);

    std::cerr << "OK" << std::endl;


336
    (std::cerr << "    in 2d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
337
338
339
340
341
342
343
344
345
346
347

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	for (int k = 1; k < limits; ++k)
	    check2d(i, j, k, value, v);

    std::cerr << "OK" << std::endl;
  }


  {
348
    std::cerr << "  on float01_8:" << std::endl;
Guillaume Duhamel's avatar
Guillaume Duhamel committed
349
350
351
352
353

    typedef value::float01_8 T;
    T value = T(0.9999);
    T v = T(0.111);

354
    (std::cerr << "    in 1d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
355
356
357
358
359
360
361
362

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	    check1d(i, j, value, v);

    std::cerr << "OK" << std::endl;


363
    (std::cerr << "    in 2d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
364
365
366
367
368
369
370
371
372
373

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	for (int k = 1; k < limits; ++k)
	    check2d(i, j, k, value, v);

    std::cerr << "OK" << std::endl;
  }

  {
374
    std::cerr << "  on float01_16:" << std::endl;
Guillaume Duhamel's avatar
Guillaume Duhamel committed
375
376
377
378
379

    typedef value::float01_16 T;
    T value = T(0.9999);
    T v = T(0.111);

380
    (std::cerr << "    in 1d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
381
382
383
384
385
386
387
388

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	    check1d(i, j, value, v);

    std::cerr << "OK" << std::endl;


389
    (std::cerr << "    in 2d ... ").flush ();
Guillaume Duhamel's avatar
Guillaume Duhamel committed
390
391
392
393
394
395
396
397
398
399
400

    for (int i = 1; i < limits; ++i)
      for (int j = 1; j < limits; ++j)
	for (int k = 1; k < limits; ++k)
	    check2d(i, j, k, value, v);

    std::cerr << "OK" << std::endl;
  }


}