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

apply_full.cc

00001 // Copyright (C) 2007, 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 
00030 #include <mln/value/int_u8.hh>
00031 #include <mln/value/int_u16.hh>
00032 #include <mln/value/int_s8.hh>
00033 #include <mln/value/int_s16.hh>
00034 
00035 
00036 #include <mln/core/routine/duplicate.hh>
00037 #include <mln/data/apply.hh>
00038 #include <mln/debug/iota.hh>
00039 
00040 #include <mln/debug/println.hh>
00041 
00042 struct qrde : mln::Function_v2v<qrde>
00043 {
00044   typedef unsigned short result;
00045   result operator()(int c) const
00046   {
00047     return result(c % 42);
00048   }
00049 };
00050 
00051 
00052 namespace mln
00053 {
00054   template <typename I>
00055   void
00056   chck(I& ref)
00057   {
00058     I out = duplicate (ref);
00059 
00060     mln_piter(I) p (ref.domain ());
00061 
00062     {
00063       data::apply(out, qrde());
00064 
00065       for_all(p)
00066         mln_assertion((mln_value(I))(ref(p) % 42) == out(p));
00067     }
00068 
00069   }
00070 
00071   template <typename I>
00072   void
00073   chk1d(unsigned cols)
00074   {
00075     image1d<I> ima (cols);
00076     debug::iota (ima);
00077     chck(ima);
00078   }
00079 
00080   template <typename I>
00081   void
00082   chk2d(unsigned rows,
00083         unsigned cols)
00084   {
00085     image2d<I> ima (rows, cols);
00086     debug::iota (ima);
00087     chck(ima);
00088   }
00089 
00090   template <typename I>
00091   void
00092   chk3d(unsigned slis,
00093         unsigned rows,
00094         unsigned cols)
00095   {
00096     image3d<I> ima (slis, rows, cols);
00097     debug::iota (ima);
00098     chck(ima);
00099   }
00100 
00101 }
00102 
00103 
00104 int main()
00105 {
00106   using namespace mln;
00107 
00108   unsigned slis_start = 1;
00109   unsigned slis_end   = 3;
00110 
00111   unsigned rows_start = 1;
00112   unsigned rows_end   = 8;
00113 
00114   unsigned cols_start = 2;
00115   unsigned cols_end = 256;
00116 
00117 
00118   std::cerr << "Tests data::apply" << std::endl;
00119 
00120   (std::cerr << "in 1d ... ").flush ();
00121   {
00122     for (unsigned i = cols_start; i < cols_end; ++i)
00123       {
00124         chk1d<int>(i);
00125         chk1d<unsigned>(i);
00126         chk1d<value::int_u8>(i);
00127         chk1d<value::int_u16>(i);
00128         chk1d<value::int_s8>(i);
00129         chk1d<value::int_s16>(i);
00130       }
00131   }
00132   std::cerr << "OK" << std::endl;
00133 
00134   (std::cerr << "in 2d ... ").flush ();
00135   {
00136     for (unsigned h = rows_start; h < rows_end; ++h)
00137       for (unsigned i = cols_start; i < cols_end; ++i)
00138         {
00139           chk2d<int>(h, i);
00140           chk2d<unsigned>(h, i);
00141           chk2d<value::int_u8>(h, i);
00142           chk2d<value::int_u16>(h, i);
00143           chk2d<value::int_s8>(h, i);
00144           chk2d<value::int_s16>(h, i);
00145         }
00146   }
00147   std::cerr << "OK" << std::endl;
00148 
00149 
00150   (std::cerr << "in 3d ... ").flush ();
00151   {
00152     for (unsigned g = slis_start; g < slis_end; ++g)
00153       for (unsigned h = rows_start; h < rows_end; ++h)
00154         for (unsigned i = cols_start; i < cols_end; ++i)
00155           {
00156             chk3d<int>(g, h, i);
00157             chk3d<unsigned>(g, h, i);
00158             chk3d<value::int_u8>(g, h, i);
00159             chk3d<value::int_u16>(g, h, i);
00160             chk3d<value::int_s8>(g, h, i);
00161             chk3d<value::int_s16>(g, h, i);
00162           }
00163   }
00164   std::cerr << "OK" << std::endl;
00165 }

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