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
00030 #include <mln/value/int_u8.hh>
00031 #include <mln/value/int_u16.hh>
00032 #include <mln/value/int_s8.hh>
00033 #include <mln/value/int_s16.hh>
00034
00035 #include <mln/core/image/dmorph/sub_image.hh>
00036 #include <mln/core/image/dmorph/image_if.hh>
00037 #include <mln/fun/p2b/chess.hh>
00038
00039 #include <mln/accu/stat/min.hh>
00040 #include <mln/accu/stat/max.hh>
00041 #include <mln/debug/iota.hh>
00042 #include <mln/debug/println.hh>
00043 #include <mln/data/compute.hh>
00044
00045
00046
00047 struct f_box1d_t : mln::Function_v2b< f_box1d_t >
00048 {
00049 f_box1d_t(const mln::box1d& b)
00050 : b_(b)
00051 {
00052 }
00053 mln::box1d b_;
00054 bool operator()(const mln::point1d& p) const
00055 {
00056 return b_.has(p);
00057 }
00058 };
00059
00060 struct f_box2d_t : mln::Function_v2b< f_box2d_t >
00061 {
00062 f_box2d_t(const mln::box2d& b)
00063 : b_(b)
00064 {
00065 }
00066 mln::box2d b_;
00067 bool operator()(const mln::point2d& p) const
00068 {
00069 return b_.has(p);
00070 }
00071 };
00072
00073 struct f_box3d_t : mln::Function_v2b< f_box3d_t >
00074 {
00075 f_box3d_t(const mln::box3d& b)
00076 : b_(b)
00077 {
00078 }
00079 mln::box3d b_;
00080 bool operator()(const mln::point3d& p) const
00081 {
00082 return b_.has(p);
00083 }
00084 };
00085
00086
00087 namespace mln
00088 {
00089 template <typename I>
00090 void
00091 chk1d(unsigned cols)
00092 {
00093 box1d b1(literal::origin, point1d(1));
00094
00095 image1d<I> ima (cols);
00096 debug::iota (ima);
00097 I real_min = 1;
00098 I real_min2 = 1;
00099 I real_max = (I)(cols % (unsigned) mln_max(I));
00100 I real_max2 = 2;
00101 if (cols >= (unsigned)mln_max(I))
00102 {
00103 real_min = 0;
00104 real_max = mln_max(I) - 1;
00105 }
00106
00107
00108 {
00109 accu::stat::min<I> acu_min;
00110 accu::stat::max<I> acu_max;
00111
00112 I min = data::compute(acu_min, ima);
00113 I max = data::compute(acu_max, ima);
00114 mln_assertion(min == real_min);
00115 mln_assertion(max == real_max);
00116 }
00117
00118 {
00119 sub_image<image1d<I>, box1d> sub_ima (ima, b1);
00120
00121 accu::stat::min<I> acu_min;
00122 accu::stat::max<I> acu_max;
00123
00124 I min = data::compute(acu_min, sub_ima);
00125 I max = data::compute(acu_max, sub_ima);
00126 mln_assertion(min == real_min2);
00127 mln_assertion(max == real_max2);
00128 }
00129
00130 {
00131 f_box1d_t f_b(b1);
00132 image_if<image1d<I>, f_box1d_t> if_ima(ima, f_b);
00133
00134 accu::stat::min<I> acu_min;
00135 accu::stat::max<I> acu_max;
00136
00137 I min = data::compute(acu_min, if_ima);
00138 I max = data::compute(acu_max, if_ima);
00139 mln_assertion(min == real_min2);
00140 mln_assertion(max == real_max2);
00141 }
00142 }
00143
00144 template <typename I>
00145 void
00146 chk2d(unsigned rows, unsigned cols)
00147 {
00148 box2d b2(literal::origin, point2d(1, 1));
00149
00150 image2d<I> ima (rows, cols);
00151 debug::iota (ima);
00152 I real_min = 1;
00153 I real_min2 = 1;
00154 I real_max;
00155 if (rows * cols >= (unsigned)mln_max(I))
00156 {
00157 real_min = 0;
00158 real_max = mln_max(I) - 1;
00159 }
00160 else
00161 {
00162 real_max = (I)(rows * cols);
00163 if ((cols == (unsigned)mln_max(I) - 2) ||
00164 (cols == (unsigned)mln_max(I) - 1))
00165 real_min2 = 0;
00166 }
00167
00168 {
00169 accu::stat::min<I> acu_min;
00170 accu::stat::max<I> acu_max;
00171
00172 I min = data::compute(acu_min, ima);
00173 I max = data::compute(acu_max, ima);
00174
00175 mln_assertion(min == real_min);
00176 mln_assertion(max == real_max);
00177 }
00178
00179 }
00180
00181 template <typename I>
00182 void
00183 chk3d(unsigned slis, unsigned rows, unsigned cols)
00184 {
00185 box3d b3(literal::origin, point3d(1, 1, 1));
00186
00187 image3d<I> ima (slis, rows, cols);
00188 debug::iota (ima);
00189 I real_min = 1;
00190 I real_max;
00191 if (slis * rows * cols >= (unsigned)mln_max(I))
00192 {
00193 real_min = 0;
00194 real_max = mln_max(I) - 1;
00195 }
00196 else
00197 real_max = (I)(slis * rows * cols);
00198 {
00199 accu::stat::min<I> acu_min;
00200 accu::stat::max<I> acu_max;
00201
00202 I min = data::compute(acu_min, ima);
00203 I max = data::compute(acu_max, ima);
00204
00205 mln_assertion(min == real_min);
00206 mln_assertion(max == real_max);
00207 }
00208
00209 }
00210 }
00211
00212
00213 int main()
00214 {
00215 using namespace mln;
00216
00217 unsigned slis_start = 2;
00218 unsigned slis_end = 3;
00219
00220 unsigned rows_start = 2;
00221 unsigned rows_end = 16;
00222
00223 unsigned cols_start = 2;
00224 unsigned cols_end = 256;
00225
00226
00227 std::cerr << "Tests data::compute:" << std::endl;
00228
00229 (std::cerr << "in 1d ... ").flush ();
00230 {
00231 for (unsigned i = cols_start; i < cols_end; ++i)
00232 {
00233 chk1d<int>(i);
00234 chk1d<unsigned>(i);
00235 chk1d<value::int_u8>(i);
00236 chk1d<value::int_u16>(i);
00237 chk1d<value::int_s8>(i);
00238 chk1d<value::int_s16>(i);
00239 }
00240 }
00241 std::cerr << "OK" << std::endl;
00242
00243 (std::cerr << "in 2d ... ").flush ();
00244 {
00245 for (unsigned j = rows_start; j < rows_end; ++j)
00246 for (unsigned i = cols_start; i < cols_end; ++i)
00247 {
00248 chk2d<int>(j, i);
00249 chk2d<unsigned>(j, i);
00250 chk2d<value::int_u8>(j, i);
00251 chk2d<value::int_u16>(j, i);
00252 chk2d<value::int_s8>(j, i);
00253 chk2d<value::int_s16>(j, i);
00254 }
00255 }
00256 std::cerr << "OK" << std::endl;
00257
00258 (std::cerr << "in 3d ... ").flush ();
00259 {
00260 for (unsigned k = slis_start; k < slis_end; ++k)
00261 for (unsigned j = rows_start; j < rows_end; ++j)
00262 for (unsigned i = cols_start; i < cols_end; ++i)
00263 {
00264 chk3d<int>(k, j, i);
00265 chk3d<unsigned>(k, j, i);
00266 chk3d<value::int_u8>(k, j, i);
00267 chk3d<value::int_u16>(k, j, i);
00268 chk3d<value::int_s8>(k, j, i);
00269 }
00270 }
00271 std::cerr << "OK" << std::endl;
00272 }