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