00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <mln/core/image/image1d.hh>
00027 #include <mln/core/image/image2d.hh>
00028 #include <mln/core/image/image3d.hh>
00029 #include <mln/core/image/dmorph/sub_image.hh>
00030
00031 #include <mln/core/image/dmorph/image_if.hh>
00032 #include <mln/fun/p2b/chess.hh>
00033
00034 #include <mln/literal/origin.hh>
00035
00036 #include <mln/value/int_s8.hh>
00037 #include <mln/value/int_s16.hh>
00038
00039
00040 #include <mln/debug/iota.hh>
00041
00042 #include <mln/arith/times.hh>
00043 #include <mln/data/abs.hh>
00044
00045
00046
00047
00048 struct f_box1d_t : mln::Function_v2b< f_box1d_t >
00049 {
00050 f_box1d_t(const mln::box1d& b)
00051 : b_(b)
00052 {
00053 }
00054 mln::box1d b_;
00055 bool operator()(const mln::point1d& p) const
00056 {
00057 return b_.has(p);
00058 }
00059 };
00060
00061 struct f_box2d_t : mln::Function_v2b< f_box2d_t >
00062 {
00063 f_box2d_t(const mln::box2d& b)
00064 : b_(b)
00065 {
00066 }
00067 mln::box2d b_;
00068 bool operator()(const mln::point2d& p) const
00069 {
00070 return b_.has(p);
00071 }
00072 };
00073
00074 struct f_box3d_t : mln::Function_v2b< f_box3d_t >
00075 {
00076 f_box3d_t(const mln::box3d& b)
00077 : b_(b)
00078 {
00079 }
00080 mln::box3d b_;
00081 bool operator()(const mln::point3d& p) const
00082 {
00083 return b_.has(p);
00084 }
00085 };
00086
00087
00088
00089 namespace mln
00090 {
00091 template <typename I>
00092 void
00093 chck(const Image<I>& ref_)
00094 {
00095 const I& ref = exact(ref_);
00096 I out (ref.domain ());
00097
00098 data::abs(ref, out);
00099 mln_piter(I) p (ref.domain ());
00100 for_all(p)
00101 if (ref(p) > 0)
00102 mln_assertion (ref(p) == out(p));
00103 else
00104 mln_assertion (ref(p) == -out(p));
00105 }
00106
00107 template <typename V>
00108 void
00109 chk(unsigned sli, unsigned row, unsigned col)
00110 {
00111 box1d b1(literal::origin, point1d(1));
00112 box2d b2(literal::origin, point2d(1,1));
00113 box3d b3(literal::origin, point3d(1,1,1));
00114 f_box1d_t f_b1(b1);
00115 f_box2d_t f_b2(b2);
00116 f_box3d_t f_b3(b3);
00117
00118 (std::cerr << "in 1d ... ").flush ();
00119 {
00120 typedef image1d<V> I;
00121
00122 for (unsigned i = 1; i < col; ++i)
00123 {
00124 I ima(i);
00125 debug::iota(ima);
00126 chck (ima * -1);
00127 }
00128 }
00129 std::cerr << "OK" << std::endl;
00130
00131 (std::cerr << "in 2d ... ").flush ();
00132 {
00133 typedef image2d<V> I;
00134
00135 for (unsigned i = 1; i < col; ++i)
00136 for (unsigned j = 1; j < row; ++j)
00137 {
00138 I ima(j, i);
00139 debug::iota(ima);
00140 chck (ima * -1);
00141 }
00142 }
00143 std::cerr << "OK" << std::endl;
00144
00145 (std::cerr << "in 3d ... ").flush ();
00146 {
00147 typedef image3d<V> I;
00148
00149 for (unsigned i = 1; i < col; ++i)
00150 for (unsigned j = 1; j < row; ++j)
00151 for (unsigned k = 1; k < sli; ++k)
00152 {
00153 I ima(k, j, i);
00154 debug::iota(ima);
00155 chck (ima * -1);
00156 }
00157 }
00158 std::cerr << "OK" << std::endl;
00159 }
00160 }
00161
00162
00163
00164
00165
00166 int main()
00167 {
00168 using namespace mln;
00169
00170 std::cerr << "Tests data::abs:" << std::endl;
00171 std::cerr << "on int:" << std::endl;
00172 chk<int>(4, 16, 64);
00173 std::cerr << "on int_s8:" << std::endl;
00174 chk<value::int_s8>(2, 2, 2);
00175 std::cerr << "on int_s16:" << std::endl;
00176 chk<value::int_s16>(4, 16, 64);
00177 }