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

abs_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 #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 
00039 
00040 #include <mln/debug/iota.hh>
00041 
00042 #include <mln/arith/times.hh>
00043 #include <mln/data/abs.hh>
00044 
00045 
00046 
00047 
00048 struct f_box1d_t : mln::Function_v2b< f_box1d_t >
00049 {
00050   f_box1d_t(const mln::box1d& b)
00051     : b_(b)
00052   {
00053   }
00054   mln::box1d b_;
00055   bool operator()(const mln::point1d& p) const
00056   {
00057     return b_.has(p);
00058   }
00059 };
00060 
00061 struct f_box2d_t : mln::Function_v2b< f_box2d_t >
00062 {
00063   f_box2d_t(const mln::box2d& b)
00064     : b_(b)
00065   {
00066   }
00067   mln::box2d b_;
00068   bool operator()(const mln::point2d& p) const
00069   {
00070     return b_.has(p);
00071   }
00072 };
00073 
00074 struct f_box3d_t : mln::Function_v2b< f_box3d_t >
00075 {
00076   f_box3d_t(const mln::box3d& b)
00077     : b_(b)
00078   {
00079   }
00080   mln::box3d b_;
00081   bool operator()(const mln::point3d& p) const
00082   {
00083     return b_.has(p);
00084   }
00085 };
00086 
00087 
00088 
00089 namespace mln
00090 {
00091   template <typename I>
00092   void
00093   chck(const Image<I>& ref_)
00094   {
00095     const I& ref = exact(ref_);
00096     I out (ref.domain ());
00097 
00098     data::abs(ref, out);
00099     mln_piter(I) p (ref.domain ());
00100     for_all(p)
00101       if (ref(p) > 0)
00102         mln_assertion (ref(p) == out(p));
00103       else
00104         mln_assertion (ref(p) == -out(p));
00105   }
00106 
00107   template <typename V>
00108   void
00109   chk(unsigned sli, unsigned row, unsigned col)
00110   {
00111     box1d b1(literal::origin, point1d(1));
00112     box2d b2(literal::origin, point2d(1,1));
00113     box3d b3(literal::origin, point3d(1,1,1));
00114     f_box1d_t f_b1(b1);
00115     f_box2d_t f_b2(b2);
00116     f_box3d_t f_b3(b3);
00117 
00118     (std::cerr << "in 1d ... ").flush ();
00119     {
00120       typedef image1d<V> I;
00121 
00122       for (unsigned i = 1; i < col; ++i)
00123         {
00124           I ima(i);
00125           debug::iota(ima);
00126           chck (ima * -1);
00127         }
00128     }
00129     std::cerr << "OK" << std::endl;
00130 
00131     (std::cerr << "in 2d ... ").flush ();
00132     {
00133       typedef image2d<V> I;
00134 
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 * -1);
00141           }
00142     }
00143     std::cerr << "OK" << std::endl;
00144 
00145     (std::cerr << "in 3d ... ").flush ();
00146     {
00147       typedef image3d<V> I;
00148 
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 * -1);
00156             }
00157     }
00158     std::cerr << "OK" << std::endl;
00159   }
00160 }
00161 
00162 
00163 
00164 
00165 
00166 int main()
00167 {
00168   using namespace mln;
00169 
00170   std::cerr << "Tests data::abs:" << std::endl;
00171   std::cerr << "on int:" << std::endl;
00172   chk<int>(4, 16, 64);
00173   std::cerr << "on int_s8:" << std::endl;
00174   chk<value::int_s8>(2, 2, 2);
00175   std::cerr << "on int_s16:" << std::endl;
00176   chk<value::int_s16>(4, 16, 64);
00177 }

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