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

image.hh

00001 // Copyright (C) 2007, 2008, 2009, 2010, 2011 EPITA Research and
00002 // Development Laboratory (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_MAKE_IMAGE_HH
00028 # define MLN_MAKE_IMAGE_HH
00029 
00036 
00037 # include <mln/core/image/image1d.hh>
00038 # include <mln/core/image/image2d.hh>
00039 # include <mln/core/image/image3d.hh>
00040 # include <mln/opt/at.hh>
00041 
00042 
00043 
00044 namespace mln
00045 {
00046 
00047   namespace make
00048   {
00049 
00056     template <typename V, unsigned L>
00057     mln::image1d<V> image(V (&values)[L]);
00058 
00059 
00066     template <typename V, unsigned R, unsigned C>
00067     mln::image2d<V> image(V (&values)[R][C]);
00068 
00069 
00076     template <typename V, unsigned S, unsigned R, unsigned C>
00077     mln::image3d<V> image(V (&values)[S][R][C]);
00078 
00079 
00080 
00081 # ifndef MLN_INCLUDE_ONLY
00082 
00083     template <typename V, unsigned L>
00084     mln::image1d<V>
00085     image(V (&values)[L])
00086     {
00087       mlc_bool(L != 0)::check();
00088       mln::image1d<V> tmp(L);
00089       const def::coord ninds = static_cast<def::coord>(L);
00090       for (def::coord ind = 0; ind < ninds; ++ind)
00091         tmp(point1d(ind)) = values[ind];
00092       return tmp;
00093     }
00094 
00095     template <typename V, unsigned R, unsigned C>
00096     mln::image2d<V>
00097     image(V (&values)[R][C])
00098     {
00099       mlc_bool(R != 0 && C != 0)::check();
00100       mln::image2d<V> tmp(R, C);
00101       const def::coord
00102         nrows = static_cast<def::coord>(R),
00103         ncols = static_cast<def::coord>(C);
00104       for (def::coord row = 0; row < nrows; ++row)
00105         for (def::coord col = 0; col < ncols; ++col)
00106           opt::at(tmp, row, col) = values[row][col];
00107       return tmp;
00108     }
00109 
00110     template <typename V, unsigned S, unsigned R, unsigned C>
00111     mln::image3d<V>
00112     image(V (&values)[S][R][C])
00113     {
00114       mlc_bool(S != 0 && R != 0 && C != 0)::check();
00115       mln::image3d<V> tmp(S, R, C);
00116       const def::coord
00117         nslis = static_cast<def::coord>(S),
00118         nrows = static_cast<def::coord>(R),
00119         ncols = static_cast<def::coord>(C);
00120       for (def::coord sli = 0; sli < nslis; ++sli)
00121         for (def::coord row = 0; row < nrows; ++row)
00122           for (def::coord col = 0; col < ncols; ++col)
00123             opt::at(tmp, sli, row, col) = values[sli][row][col];
00124       return tmp;
00125     }
00126 
00127 # endif // ! MLN_INCLUDE_ONLY
00128 
00129   } // end of namespace mln::make
00130 
00131 } // end of namespace mln
00132 
00133 
00134 #endif // ! MLN_MAKE_IMAGE_HH

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