$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
abs_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 #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/times.hh>
43 #include <mln/data/abs.hh>
44 
45 
46 
47 
48 struct f_box1d_t : mln::Function_v2b< f_box1d_t >
49 {
50  f_box1d_t(const mln::box1d& b)
51  : b_(b)
52  {
53  }
54  mln::box1d b_;
55  bool operator()(const mln::point1d& p) const
56  {
57  return b_.has(p);
58  }
59 };
60 
61 struct f_box2d_t : mln::Function_v2b< f_box2d_t >
62 {
63  f_box2d_t(const mln::box2d& b)
64  : b_(b)
65  {
66  }
67  mln::box2d b_;
68  bool operator()(const mln::point2d& p) const
69  {
70  return b_.has(p);
71  }
72 };
73 
74 struct f_box3d_t : mln::Function_v2b< f_box3d_t >
75 {
76  f_box3d_t(const mln::box3d& b)
77  : b_(b)
78  {
79  }
80  mln::box3d b_;
81  bool operator()(const mln::point3d& p) const
82  {
83  return b_.has(p);
84  }
85 };
86 
87 
88 
89 namespace mln
90 {
91  template <typename I>
92  void
93  chck(const Image<I>& ref_)
94  {
95  const I& ref = exact(ref_);
96  I out (ref.domain ());
97 
98  data::abs(ref, out);
99  mln_piter(I) p (ref.domain ());
100  for_all(p)
101  if (ref(p) > 0)
102  mln_assertion (ref(p) == out(p));
103  else
104  mln_assertion (ref(p) == -out(p));
105  }
106 
107  template <typename V>
108  void
109  chk(unsigned sli, unsigned row, unsigned col)
110  {
111  box1d b1(literal::origin, point1d(1));
112  box2d b2(literal::origin, point2d(1,1));
113  box3d b3(literal::origin, point3d(1,1,1));
114  f_box1d_t f_b1(b1);
115  f_box2d_t f_b2(b2);
116  f_box3d_t f_b3(b3);
117 
118  (std::cerr << "in 1d ... ").flush ();
119  {
120  typedef image1d<V> I;
121 
122  for (unsigned i = 1; i < col; ++i)
123  {
124  I ima(i);
125  debug::iota(ima);
126  chck (ima * -1);
127  }
128  }
129  std::cerr << "OK" << std::endl;
130 
131  (std::cerr << "in 2d ... ").flush ();
132  {
133  typedef image2d<V> I;
134 
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 * -1);
141  }
142  }
143  std::cerr << "OK" << std::endl;
144 
145  (std::cerr << "in 3d ... ").flush ();
146  {
147  typedef image3d<V> I;
148 
149  for (unsigned i = 1; i < col; ++i)
150  for (unsigned j = 1; j < row; ++j)
151  for (unsigned k = 1; k < sli; ++k)
152  {
153  I ima(k, j, i);
154  debug::iota(ima);
155  chck (ima * -1);
156  }
157  }
158  std::cerr << "OK" << std::endl;
159  }
160 }
161 
162 
163 
164 
165 
166 int main()
167 {
168  using namespace mln;
169 
170  std::cerr << "Tests data::abs:" << std::endl;
171  std::cerr << "on int:" << std::endl;
172  chk<int>(4, 16, 64);
173  std::cerr << "on int_s8:" << std::endl;
174  chk<value::int_s8>(2, 2, 2);
175  std::cerr << "on int_s16:" << std::endl;
176  chk<value::int_s16>(4, 16, 64);
177 }