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 <cmath>
00027 
00028 #include <mln/core/image/image1d.hh>
00029 #include <mln/core/image/image2d.hh>
00030 #include <mln/core/image/image3d.hh>
00031 #include <mln/core/image/dmorph/sub_image.hh>
00032 
00033 #include <mln/core/image/dmorph/image_if.hh>
00034 #include <mln/fun/p2b/chess.hh>
00035 
00036 #include <mln/literal/origin.hh>
00037 
00038 #include <mln/value/int_u8.hh>
00039 #include <mln/value/int_u16.hh>
00040 
00041 #include <mln/value/int_s8.hh>
00042 #include <mln/value/int_s16.hh>
00043 
00044 #include <mln/data/fill.hh>
00045 #include <mln/data/transform.hh>
00046 
00047 #include <mln/debug/iota.hh>
00048 
00049 #include <mln/arith/plus.hh>
00050 
00051 
00052 
00053 
00054 struct mysqrt : mln::Function_v2v<mysqrt>
00055 {
00056   typedef unsigned short result;
00057   result operator()(int c) const
00058   {
00059     return result(c % 42);
00060   }
00061 };
00062 
00063 
00064 namespace mln
00065 {
00066   template <typename I>
00067   void
00068   chck(const Image<I>& ref_)
00069   {
00070     const I& ref = exact(ref_);
00071 
00072     mln_ch_value(I, mln_result_(mysqrt)) out;
00073     {
00074       out = data::transform(ref, mysqrt());
00075       mln_piter(I) p (ref.domain ());
00076       for_all(p)
00077         mln_assertion ((mln_value(I))(ref(p) % 42) == out(p) );
00078     }
00079   }
00080 
00081   template <typename V>
00082   void
00083   chk()
00084   {
00085     unsigned sli = 4;
00086     unsigned row = 16;
00087     unsigned col = 64;
00088 
00089 
00090     (std::cerr << "in 1d ... ").flush ();
00091     {
00092       typedef image1d<V> I;
00093       typedef sub_image<I, box1d> J;
00094 
00095       for (unsigned i = 1; i < col; ++i)
00096         {
00097           I ima(i);
00098           debug::iota(ima);
00099           chck (ima);
00100         }
00101     }
00102     std::cerr << "OK" << std::endl;
00103 
00104     (std::cerr << "in 2d ... ").flush ();
00105     {
00106       typedef image2d<V> I;
00107 
00108       for (unsigned i = 1; i < col; ++i)
00109         for (unsigned j = 1; j < row; ++j)
00110           {
00111             I ima(j, i);
00112             debug::iota(ima);
00113             chck (ima);
00114           }
00115     }
00116     std::cerr << "OK" << std::endl;
00117 
00118     (std::cerr << "in 3d ... ").flush ();
00119     {
00120       typedef image3d<V> I;
00121 
00122       for (unsigned i = 1; i < col; ++i)
00123         for (unsigned j = 1; j < row; ++j)
00124           for (unsigned k = 1; k < sli; ++k)
00125             {
00126               I ima(k, j, i);
00127               debug::iota(ima);
00128               chck (ima);
00129             }
00130     }
00131     std::cerr << "OK" << std::endl;
00132   }
00133 
00134 }
00135 
00136 
00137 
00138 
00139 
00140 int main()
00141 {
00142   using namespace mln;
00143 
00144   std::cerr << "Tests data::transform:" << std::endl;
00145   std::cerr << "on int:" << std::endl;
00146   chk<int>();
00147   std::cerr << "on unsigned:" << std::endl;
00148   chk<unsigned>();
00149   std::cerr << "on int_u8:" << std::endl;
00150   chk<value::int_u8>();
00151   std::cerr << "on int_u16:" << std::endl;
00152   chk<value::int_u16>();
00153   std::cerr << "on int_s8:" << std::endl;
00154   chk<value::int_s8>();
00155   std::cerr << "on int_s16:" << std::endl;
00156   chk<value::int_s16>();
00157 }