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