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

transform_inplace.cc

00001 // Copyright (C) 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/flat_image.hh>
00030 #include <mln/core/image/dmorph/image_if.hh>
00031 #include <mln/core/image/dmorph/sub_image.hh>
00032 #include <mln/core/image/dmorph/extension_val.hh>
00033 #include <mln/core/routine/duplicate.hh>
00034 
00035 #include <mln/fun/v2v/inc.hh>
00036 #include <mln/fun/v2v/dec.hh>
00037 #include <mln/fun/p2b/chess.hh>
00038 
00039 #include <mln/debug/iota.hh>
00040 
00041 #include <mln/data/transform_inplace.hh>
00042 #include <mln/data/compare.hh>
00043 
00044 
00045 
00046 int main()
00047 {
00048   using namespace mln;
00049   const unsigned size = 50;
00050 
00051 
00052   // image 2d tests
00053   {
00054     typedef int T;
00055     image2d<T> ref(size, size);
00056     debug::iota(ref);
00057 
00058     image2d<T> ima = duplicate(ref);
00059     data::transform_inplace(ima, fun::v2v::inc<T>());
00060     data::transform_inplace(ima, fun::v2v::dec<T>());
00061 
00062     mln_assertion(ima == ref);
00063   }
00064 
00066   {
00067     typedef unsigned short T;
00068     image1d<T> ref(size);
00069     debug::iota(ref);
00070 
00071     image1d<T> ima = duplicate(ref);
00072     data::transform_inplace(ima, fun::v2v::inc<T>());
00073     data::transform_inplace(ima, fun::v2v::dec<T>());
00074 
00075     mln_assertion(ima == ref);
00076   }
00077 
00078 
00080   {
00081     typedef unsigned short T;
00082     image3d<T> ref(size, size, size);
00083     debug::iota(ref);
00084 
00085     image3d<T> ima = duplicate(ref);
00086     data::transform_inplace(ima, fun::v2v::inc<T>());
00087     data::transform_inplace(ima, fun::v2v::dec<T>());
00088 
00089     mln_assertion(ima == ref);
00090   }
00091 
00092   // flat image test
00093   {
00094     typedef short T;
00095     flat_image<T, box2d>
00096       ref(5, make::box2d(size, size)),
00097       ima(5, make::box2d(size, size));
00098 
00099     data::transform_inplace(ima, fun::v2v::inc<T>());
00100     data::transform_inplace(ima, fun::v2v::dec<T>());
00101 
00102     mln_assertion(ima == ref);
00103   }
00104 
00105   // image if test
00106   {
00107     typedef unsigned short T;
00108     typedef image2d<T> I;
00109     typedef image_if<I, fun::p2b::chess> II;
00110 
00111     I ref(size, size);
00112     debug::iota(ref);
00113     II ref_if = ref | fun::p2b::chess();
00114 
00115     I ima = duplicate(ref);
00116     II ima_if = ima | fun::p2b::chess();
00117 
00118     data::transform_inplace(ima_if, fun::v2v::inc<T>());
00119     data::transform_inplace(ima_if, fun::v2v::dec<T>());
00120 
00121     mln_assertion(ima_if == ref_if);
00122   }
00123 
00124   // sub_image test
00125   {
00126     typedef image2d<int> I;
00127     typedef sub_image< image2d<int>, box2d > II;
00128     typedef image2d<unsigned short> III;
00129 
00130     I ref(size, size);
00131     debug::iota(ref);
00132     II sub_ref(ref, make::box2d(4,4, 10,10));
00133 
00134     I ima = duplicate(ref);
00135     II sub_ima(ima, make::box2d(4,4, 10,10));
00136 
00137     data::transform_inplace(sub_ima, fun::v2v::inc<int>());
00138     data::transform_inplace(sub_ima, fun::v2v::dec<int>());
00139 
00140     mln_assertion(sub_ima == sub_ref);
00141   }
00142 
00143   // extended image test
00144   {
00145     typedef int T;
00146     typedef image2d<T> I;
00147     typedef extension_val< image2d<T> > II;
00148 
00149     I ref(size, size);
00150 
00151     I ima = duplicate(ref);
00152     II extend_ima(ima, 5);
00153 
00154     data::transform_inplace(extend_ima, fun::v2v::inc<T>());
00155     data::transform_inplace(extend_ima, fun::v2v::dec<T>());
00156 
00157     mln_assertion(extend_ima == ref);
00158 
00159   }
00160 }

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