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

plus_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 #include <mln/literal/origin.hh>
00034 
00035 #include <mln/value/int_u8.hh>
00036 #include <mln/value/int_s8.hh>
00037 #include <mln/value/int_u16.hh>
00038 #include <mln/value/int_s16.hh>
00039 #include <mln/debug/iota.hh>
00040 
00041 #include <mln/arith/plus.hh>
00042 
00043 
00044 
00045 struct f_box1d_t : mln::Function_v2b< f_box1d_t >
00046 {
00047   f_box1d_t(const mln::box1d& b)
00048     : b_(b)
00049   {
00050   }
00051   mln::box1d b_;
00052   bool operator()(const mln::point1d& p) const
00053   {
00054     return b_.has(p);
00055   }
00056 };
00057 
00058 struct f_box2d_t : mln::Function_v2b< f_box2d_t >
00059 {
00060   f_box2d_t(const mln::box2d& b)
00061     : b_(b)
00062   {
00063   }
00064   mln::box2d b_;
00065   bool operator()(const mln::point2d& p) const
00066   {
00067     return b_.has(p);
00068   }
00069 };
00070 
00071 struct f_box3d_t : mln::Function_v2b< f_box3d_t >
00072 {
00073   f_box3d_t(const mln::box3d& b)
00074     : b_(b)
00075   {
00076   }
00077   mln::box3d b_;
00078   bool operator()(const mln::point3d& p) const
00079   {
00080     return b_.has(p);
00081   }
00082 };
00083 
00084 
00085 
00086 namespace mln
00087 {
00088   template <typename I, typename J>
00089   void
00090   chck(const Image<I>& ref_, const Image<J>& ima_, const mln_value(I) v)
00091   {
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 ((mln_value(I))ima(p) == (ref(p) + v));
00098   }
00099 
00100   template <typename V>
00101   void
00102   chk(const V max)
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 = 2;
00111     unsigned row = 3;
00112     unsigned col = 16;
00113 
00114 
00115     (std::cerr << "in 1d ... ").flush ();
00116     {
00117       typedef image1d<V> I;
00118 
00119       for (V v = 0; v < max; ++v)
00120         for (unsigned i = 1; i < col; ++i)
00121           {
00122             I ima(i);
00123             debug::iota(ima);
00124             chck (ima, ima + v, v);
00125           }
00126     }
00127     std::cerr << "OK" << std::endl;
00128 
00129     (std::cerr << "in 2d ... ").flush ();
00130     {
00131       typedef image2d<V> I;
00132 
00133       for (V v = 0; v < max; ++v)
00134         for (unsigned i = 1; i < col; ++i)
00135           for (unsigned j = 1; j < row; ++j)
00136             {
00137               I ima(j, i);
00138               debug::iota(ima);
00139               chck (ima, ima + v, v);
00140             }
00141     }
00142     std::cerr << "OK" << std::endl;
00143 
00144     (std::cerr << "in 3d ... ").flush ();
00145     {
00146       typedef image3d<V> I;
00147 
00148       for (V v = 0; v < max; ++v)
00149         for (unsigned i = 1; i < col; ++i)
00150           for (unsigned j = 1; j < row; ++j)
00151             for (unsigned k = 1; k < sli; ++k)
00152             {
00153               I ima(k, j, i);
00154               debug::iota(ima);
00155               chck (ima, ima + v, v);
00156             }
00157     }
00158     std::cerr << "OK" << std::endl;
00159 
00160 
00161     (std::cerr << "in subimage 1d ... ").flush ();
00162     {
00163       typedef image1d<V> I;
00164       typedef sub_image<I, box1d> J;
00165 
00166 
00167       for (V v = 0; v < max; ++v)
00168         for (unsigned i = 1; i < col; ++i)
00169           {
00170             I image(i);
00171             J ima(image, b1);
00172             debug::iota(ima);
00173             chck (ima, ima + v, v);
00174           }
00175     }
00176     std::cerr << "OK" << std::endl;
00177 
00178     (std::cerr << "in subimage 2d ... ").flush ();
00179     {
00180       typedef image2d<V> I;
00181       typedef sub_image<I, box2d> J;
00182 
00183 
00184       for (V v = 0; v < max; ++v)
00185         for (unsigned i = 1; i < col; ++i)
00186           for (unsigned j = 1; j < row; ++j)
00187           {
00188             I image(j, i);
00189             J ima(image, b2);
00190             debug::iota(ima);
00191             chck (ima, ima + v, v);
00192           }
00193     }
00194     std::cerr << "OK" << std::endl;
00195 
00196     (std::cerr << "in subimage 3d ... ").flush ();
00197     {
00198       typedef image3d<V> I;
00199       typedef sub_image<I, box3d> J;
00200 
00201 
00202       for (V v = 0; v < max; ++v)
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 image(k, j, i);
00208             J ima(image, b3);
00209             debug::iota(ima);
00210             chck (ima, ima + v, v);
00211           }
00212     }
00213     std::cerr << "OK" << std::endl;
00214   }
00215 
00216 }
00217 
00218 
00219 
00220 
00221 
00222 int main()
00223 {
00224   using namespace mln;
00225 
00226   std::cerr << "Tests arith::plus:" << std::endl;
00227   std::cerr << "on int:" << std::endl;
00228   chk<int>(1000);
00229   std::cerr << "on unsigned:" << std::endl;
00230   chk<unsigned>(1000);
00231   std::cerr << "on int_u8:" << std::endl;
00232   chk<value::int_u8>(16);
00233   std::cerr << "on int_u16:" << std::endl;
00234   chk<value::int_u16>(1000);
00235   std::cerr << "on int_s8:" << std::endl;
00236   chk<value::int_s8>(16);
00237   std::cerr << "on int_s16:" << std::endl;
00238   chk<value::int_s16>(1000);
00239 
00240 }

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