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