• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

times_full.cc

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
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 #include <mln/value/int_u8.hh>
00039 #include <mln/value/int_u16.hh>
00040 #include <mln/debug/iota.hh>
00041 
00042 #include <mln/arith/times.hh>
00043 
00044 
00045 
00046 struct f_box1d_t : mln::Function_v2b< f_box1d_t >
00047 {
00048   f_box1d_t(const mln::box1d& b)
00049     : b_(b)
00050   {
00051   }
00052   mln::box1d b_;
00053   bool operator()(const mln::point1d& p) const
00054   {
00055     return b_.has(p);
00056   }
00057 };
00058 
00059 struct f_box2d_t : mln::Function_v2b< f_box2d_t >
00060 {
00061   f_box2d_t(const mln::box2d& b)
00062     : b_(b)
00063   {
00064   }
00065   mln::box2d b_;
00066   bool operator()(const mln::point2d& p) const
00067   {
00068     return b_.has(p);
00069   }
00070 };
00071 
00072 struct f_box3d_t : mln::Function_v2b< f_box3d_t >
00073 {
00074   f_box3d_t(const mln::box3d& b)
00075     : b_(b)
00076   {
00077   }
00078   mln::box3d b_;
00079   bool operator()(const mln::point3d& p) const
00080   {
00081     return b_.has(p);
00082   }
00083 };
00084 
00085 
00086 
00087 namespace mln
00088 {
00089   template <typename I, typename J>
00090   void
00091   chck(const Image<I>& ref_, const Image<J>& ima_, const mln_value(I) v)
00092   {
00093     const I& ref = exact(ref_);
00094     const J& ima = exact(ima_);
00095 
00096     mln_piter(I) p (ima.domain ());
00097     for_all(p)
00098       mln_assertion ((mln_value(I))ima(p) == (ref(p) * v));
00099   }
00100 
00101   template <typename V>
00102   void
00103   chk(const V max)
00104   {
00105     box1d b1(literal::origin, point1d(1));
00106     box2d b2(literal::origin, point2d(1,1));
00107     box3d b3(literal::origin, point3d(1,1,1));
00108     f_box1d_t f_b1(b1);
00109     f_box2d_t f_b2(b2);
00110     f_box3d_t f_b3(b3);
00111     unsigned sli = 2;
00112     unsigned row = 3;
00113     unsigned col = 16;
00114 
00115 
00116     (std::cerr << "in 1d ... ").flush ();
00117     {
00118       typedef image1d<V> I;
00119 
00120       for (V v = 0; v < max; ++v)
00121         for (unsigned i = 1; i < col; ++i)
00122           {
00123             I ima(i);
00124             debug::iota(ima);
00125             chck (ima, ima * v, v);
00126           }
00127     }
00128     std::cerr << "OK" << std::endl;
00129 
00130     (std::cerr << "in 2d ... ").flush ();
00131     {
00132       typedef image2d<V> I;
00133 
00134       for (V v = 0; v < max; ++v)
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, ima * v, v);
00141             }
00142     }
00143     std::cerr << "OK" << std::endl;
00144 
00145     (std::cerr << "in 3d ... ").flush ();
00146     {
00147       typedef image3d<V> I;
00148 
00149       for (V v = 0; v < max; ++v)
00150         for (unsigned i = 1; i < col; ++i)
00151           for (unsigned j = 1; j < row; ++j)
00152             for (unsigned k = 1; k < sli; ++k)
00153             {
00154               I ima(k, j, i);
00155               debug::iota(ima);
00156               chck (ima, ima * v, v);
00157             }
00158     }
00159     std::cerr << "OK" << std::endl;
00160 
00161 
00162     (std::cerr << "in subimage 1d ... ").flush ();
00163     {
00164       typedef image1d<V> I;
00165       typedef sub_image<I, box1d> J;
00166 
00167 
00168       for (V v = 0; v < max; ++v)
00169         for (unsigned i = 1; i < col; ++i)
00170           {
00171             I image(i);
00172             J ima(image, b1);
00173             debug::iota(ima);
00174             chck (ima, ima * v, v);
00175           }
00176     }
00177     std::cerr << "OK" << std::endl;
00178 
00179     (std::cerr << "in subimage 2d ... ").flush ();
00180     {
00181       typedef image2d<V> I;
00182       typedef sub_image<I, box2d> J;
00183 
00184 
00185       for (V v = 0; v < max; ++v)
00186         for (unsigned i = 1; i < col; ++i)
00187           for (unsigned j = 1; j < row; ++j)
00188           {
00189             I image(j, i);
00190             J ima(image, b2);
00191             debug::iota(ima);
00192             chck (ima, ima * v, v);
00193           }
00194     }
00195     std::cerr << "OK" << std::endl;
00196 
00197     (std::cerr << "in subimage 3d ... ").flush ();
00198     {
00199       typedef image3d<V> I;
00200       typedef sub_image<I, box3d> J;
00201 
00202 
00203       for (V v = 0; v < max; ++v)
00204         for (unsigned i = 1; i < col; ++i)
00205           for (unsigned j = 1; j < row; ++j)
00206             for (unsigned k = 1; k < sli; ++k)
00207           {
00208             I image(k, j, i);
00209             J ima(image, b3);
00210             debug::iota(ima);
00211             chck (ima, ima * v, v);
00212           }
00213     }
00214     std::cerr << "OK" << std::endl;
00215   }
00216 
00217 }
00218 
00219 
00220 
00221 
00222 
00223 int main()
00224 {
00225   using namespace mln;
00226 
00227   std::cerr << "Tests arith::times:" << std::endl;
00228   std::cerr << "on int:" << std::endl;
00229   chk<int>(1000);
00230   std::cerr << "on unsigned:" << std::endl;
00231   chk<unsigned>(1000);
00232   std::cerr << "on int_u8:" << std::endl;
00233   chk<value::int_u8>(9);
00234   std::cerr << "on int_u16:" << std::endl;
00235   chk<value::int_u16>(1000);
00236   std::cerr << "on int_s8:" << std::endl;
00237   chk<value::int_s8>(5);
00238   std::cerr << "on int_s16:" << std::endl;
00239   chk<value::int_s16>(1000);
00240 
00241 }

Generated on Tue Oct 4 2011 15:24:42 for Milena (Olena) by  doxygen 1.7.1