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 #include <mln/core/image/dmorph/image_if.hh>
00031
00032 #include <mln/fun/p2b/chess.hh>
00033 #include <mln/literal/origin.hh>
00034 #include <mln/value/int_u8.hh>
00035 #include <mln/value/int_s8.hh>
00036 #include <mln/value/int_s16.hh>
00037
00038 #include <mln/debug/iota.hh>
00039 #include <mln/arith/revert.hh>
00040
00041
00042
00043
00044 struct f_box1d_t : mln::Function_v2b< f_box1d_t >
00045 {
00046 f_box1d_t(const mln::box1d& b)
00047 : b_(b)
00048 {
00049 }
00050 mln::box1d b_;
00051 bool operator()(const mln::point1d& p) const
00052 {
00053 return b_.has(p);
00054 }
00055 };
00056
00057 struct f_box2d_t : mln::Function_v2b< f_box2d_t >
00058 {
00059 f_box2d_t(const mln::box2d& b)
00060 : b_(b)
00061 {
00062 }
00063 mln::box2d b_;
00064 bool operator()(const mln::point2d& p) const
00065 {
00066 return b_.has(p);
00067 }
00068 };
00069
00070 struct f_box3d_t : mln::Function_v2b< f_box3d_t >
00071 {
00072 f_box3d_t(const mln::box3d& b)
00073 : b_(b)
00074 {
00075 }
00076 mln::box3d b_;
00077 bool operator()(const mln::point3d& p) const
00078 {
00079 return b_.has(p);
00080 }
00081 };
00082
00083
00084
00085 namespace mln
00086 {
00087 template <typename I, typename J>
00088 void
00089 chck(const Image<I>& ref_, const Image<J>& ima_)
00090 {
00091 typedef mln_value(I) V;
00092 const I& ref = exact(ref_);
00093 const J& ima = exact(ima_);
00094
00095 mln_piter(I) p (ima.domain ());
00096 for_all(p)
00097 mln_assertion (ima(p) == mln_value(J)(mln_min(V) + mln_max(V) - ref(p)));
00098 }
00099
00100 template <typename V>
00101 void
00102 chk()
00103 {
00104 box1d b1(literal::origin, point1d(1));
00105 box2d b2(literal::origin, point2d(1,1));
00106 box3d b3(literal::origin, point3d(1,1,1));
00107 f_box1d_t f_b1(b1);
00108 f_box2d_t f_b2(b2);
00109 f_box3d_t f_b3(b3);
00110 unsigned sli = 5;
00111 unsigned row = 10;
00112 unsigned col = 100;
00113
00114
00115 {
00116 typedef image1d<V> I;
00117
00118
00119 for (unsigned i = 1; i < col; ++i)
00120 {
00121 I ref(i);
00122 debug::iota(ref);
00123 I ima(i);
00124 debug::iota(ima);
00125 arith::revert_inplace(ima);
00126 chck (ref, ima);
00127 }
00128 }
00129 {
00130 typedef image2d<V> I;
00131
00132
00133 for (unsigned i = 1; i < col; ++i)
00134 for (unsigned j = 1; j < row; ++j)
00135 {
00136 I ref(j, i);
00137 debug::iota(ref);
00138 I ima(j, i);
00139 debug::iota(ima);
00140 arith::revert_inplace(ima);
00141 chck (ref, ima);
00142 }
00143 }
00144 {
00145 typedef image3d<V> I;
00146
00147
00148 for (unsigned i = 1; i < col; ++i)
00149 for (unsigned j = 1; j < row; ++j)
00150 for (unsigned k = 1; k < sli; ++k)
00151 {
00152 I ref(k, j, i);
00153 debug::iota(ref);
00154 I ima(k, j, i);
00155 debug::iota(ima);
00156 arith::revert_inplace(ima);
00157 chck (ref, ima);
00158 }
00159 }
00160 {
00161 typedef image1d<V> I;
00162 typedef sub_image<I, box1d> J;
00163
00164
00165
00166 for (unsigned i = 1; i < col; ++i)
00167 {
00168 I refima(i);
00169 J ref(refima, b1);
00170 debug::iota(ref);
00171
00172 I image(i);
00173 J ima(image, b1);
00174 debug::iota(ima);
00175 arith::revert_inplace(ima);
00176 chck (ref, ima);
00177 }
00178 }
00179 {
00180 typedef image2d<V> I;
00181 typedef sub_image<I, box2d> J;
00182
00183
00184 for (unsigned i = 1; i < col; ++i)
00185 for (unsigned j = 1; j < row; ++j)
00186 {
00187 I refima(j, i);
00188 J ref(refima, b2);
00189 debug::iota(ref);
00190
00191 I image(j, i);
00192 J ima(image, b2);
00193 debug::iota(ima);
00194 arith::revert_inplace(ima);
00195 chck (ref, ima);
00196 }
00197 }
00198 {
00199 typedef image3d<V> I;
00200 typedef sub_image<I, box3d> J;
00201
00202
00203 for (unsigned i = 1; i < col; ++i)
00204 for (unsigned j = 1; j < row; ++j)
00205 for (unsigned k = 1; k < sli; ++k)
00206 {
00207 I refima(k, j, i);
00208 J ref(refima, b3);
00209 debug::iota(ref);
00210
00211 I image(k, j, i);
00212 J ima(image, b3);
00213 debug::iota(ima);
00214 arith::revert_inplace(ima);
00215 chck (ref, ima);
00216 }
00217 }
00218 }
00219
00220 }
00221
00222
00223
00224
00225
00226 int main()
00227 {
00228 using namespace mln;
00229
00230 chk<int>();
00231 chk<value::int_s8>();
00232 chk<value::int_s16>();
00233 chk<value::int_u8>();
00234 chk<unsigned>();
00235 }