$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
compare_full.cc
1 // Copyright (C) 2007, 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/core/image/image3d.hh>
29 
30 #include <mln/value/int_u8.hh>
31 #include <mln/value/int_u16.hh>
32 #include <mln/value/int_s8.hh>
33 #include <mln/value/int_s16.hh>
34 
35 #include <mln/data/compare.hh>
36 
37 #include <mln/debug/iota.hh>
38 #include <mln/arith/plus.hh>
39 #include <mln/arith/minus.hh>
40 
41 
42 struct f_box1d_t : mln::Function_v2b< f_box1d_t >
43 {
44  f_box1d_t(const mln::box1d& b)
45  : b_(b)
46  {
47  }
48  mln::box1d b_;
49  bool operator()(const mln::point1d& p) const
50  {
51  return b_.has(p);
52  }
53 };
54 
55 struct f_box2d_t : mln::Function_v2b< f_box2d_t >
56 {
57  f_box2d_t(const mln::box2d& b)
58  : b_(b)
59  {
60  }
61  mln::box2d b_;
62  bool operator()(const mln::point2d& p) const
63  {
64  return b_.has(p);
65  }
66 };
67 
68 struct f_box3d_t : mln::Function_v2b< f_box3d_t >
69 {
70  f_box3d_t(const mln::box3d& b)
71  : b_(b)
72  {
73  }
74  mln::box3d b_;
75  bool operator()(const mln::point3d& p) const
76  {
77  return b_.has(p);
78  }
79 };
80 
81 
82 namespace mln
83 {
84  template<typename I, typename J>
85  void
86  test_less(I& lhs, J& rhs)
87  {
88  mln_assertion(! (lhs == rhs));
89  mln_assertion( (lhs <= rhs));
90  mln_assertion( (lhs < rhs));
91  mln_assertion(! (lhs >= rhs));
92  mln_assertion(! (lhs > rhs));
93 
94  mln_assertion(! (rhs == lhs));
95  mln_assertion(! (rhs <= lhs));
96  mln_assertion(! (rhs < lhs));
97  mln_assertion( (rhs >= lhs));
98  mln_assertion( (rhs > lhs));
99  }
100 
101  template<typename I, typename J>
102  void
103  test_more(I& lhs, J& rhs)
104  {
105  mln_assertion(! (lhs == rhs));
106  mln_assertion( (lhs <= rhs));
107  mln_assertion( (lhs < rhs));
108  mln_assertion(! (lhs >= rhs));
109  mln_assertion(! (lhs > rhs));
110 
111  mln_assertion(! (rhs == lhs));
112  mln_assertion(! (rhs <= lhs));
113  mln_assertion(! (rhs < lhs));
114  mln_assertion( (rhs >= lhs));
115  mln_assertion( (rhs > lhs));
116  }
117 
118  template<typename I, typename J>
119  void
120  test_equal(I& lhs, J& rhs)
121  {
122  mln_assertion( (lhs == rhs));
123  mln_assertion( (lhs <= rhs));
124  mln_assertion(! (lhs < rhs));
125  mln_assertion( (lhs >= rhs));
126  mln_assertion(! (lhs > rhs));
127 
128  mln_assertion( (rhs == lhs));
129  mln_assertion( (rhs <= lhs));
130  mln_assertion(! (rhs < lhs));
131  mln_assertion( (rhs >= lhs));
132  mln_assertion(! (rhs > lhs));
133  }
134 
135  template <typename I>
136  void
137  chk1d(unsigned cols)
138  {
139  image1d<I> lhs (cols);
140  image1d<I> rhs (cols);
141  debug::iota (lhs);
142  debug::iota (rhs);
143 
144  test_equal(lhs, rhs);
145  image1d<int> lhs2 = lhs + 0;
146  image1d<int> rhs2 = rhs + 1;
147  test_less(lhs2, rhs2);
148  image1d<int> lhs3 = lhs - 1;
149  image1d<int> rhs3 = rhs + 0;
150  test_more(lhs3, rhs3);
151  }
152 
153  template <typename I>
154  void
155  chk2d(unsigned rows, unsigned cols)
156  {
157  image2d<I> lhs (rows, cols);
158  image2d<I> rhs (rows, cols);
159  debug::iota (lhs);
160  debug::iota (rhs);
161 
162  test_equal(lhs, rhs);
163  image2d<int> lhs2 = lhs + 0;
164  image2d<int> rhs2 = rhs + 1;
165  test_less(lhs2, rhs2);
166  image2d<int> lhs3 = lhs - 1;
167  image2d<int> rhs3 = rhs + 0;
168  test_more(lhs3, rhs3);
169  }
170 
171  template <typename I>
172  void
173  chk3d(unsigned slis, unsigned rows, unsigned cols)
174  {
175  image3d<I> lhs (slis, rows, cols);
176  image3d<I> rhs (slis, rows, cols);
177  debug::iota (lhs);
178  debug::iota (rhs);
179 
180  test_equal(lhs, rhs);
181  image3d<int> lhs2 = lhs + 0;
182  image3d<int> rhs2 = rhs + 1;
183  test_less(lhs2, rhs2);
184  image3d<int> lhs3 = lhs - 1;
185  image3d<int> rhs3 = rhs + 0;
186  test_more(lhs3, rhs3);
187  }
188 }
189 
190 
191 
192 
193 int main()
194 {
195  using namespace mln;
196 
197  unsigned slis_start = 1;
198  unsigned slis_end = 3;
199 
200  unsigned rows_start = 1;
201  unsigned rows_end = 16;
202 
203  unsigned cols_start = 1;
204  unsigned cols_end = 32;
205 
206  std::cerr << "Tests data::compare" << std::endl;
207 
208  (std::cerr << "in 1d ... ").flush ();
209  {
210  for (unsigned i = cols_start; i < cols_end; ++i)
211  {
212  chk1d<int>(i);
213  chk1d<unsigned>(i);
214  chk1d<value::int_u8>(i);
215  chk1d<value::int_u16>(i);
216  chk1d<value::int_s8>(i);
217  chk1d<value::int_s16>(i);
218  }
219  }
220  std::cerr << "OK" << std::endl;
221 
222  (std::cerr << "in 2d ... ").flush ();
223  {
224  for (unsigned j = rows_start; j < rows_end; ++j)
225  for (unsigned i = cols_start; i < cols_end; ++i)
226  {
227  chk2d<int>(j, i);
228  chk2d<unsigned>(j, i);
229  chk2d<value::int_u8>(j, i);
230  chk2d<value::int_u16>(j, i);
231  chk2d<value::int_s8>(j, i);
232  chk2d<value::int_s16>(j, i);
233  }
234  }
235  std::cerr << "OK" << std::endl;
236 
237  (std::cerr << "in 3d ... ").flush ();
238  {
239  for (unsigned k = slis_start; k < slis_end; ++k)
240  for (unsigned j = rows_start; j < rows_end; ++j)
241  for (unsigned i = cols_start; i < cols_end; ++i)
242  {
243  chk3d<int>(k, j, i);
244  chk3d<unsigned>(k, j, i);
245  chk3d<value::int_u8>(k, j, i);
246  chk3d<value::int_u16>(k, j, i);
247  chk3d<value::int_s8>(k, j, i);
248  chk3d<value::int_s16>(k, j, i);
249  }
250  }
251  std::cerr << "OK" << std::endl;
252 }