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

image.hh

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 #ifndef MLN_MAKE_IMAGE_HH
00027 # define MLN_MAKE_IMAGE_HH
00028 
00035 
00036 # include <mln/core/image/image1d.hh>
00037 # include <mln/core/image/image2d.hh>
00038 # include <mln/core/image/image3d.hh>
00039 # include <mln/opt/at.hh>
00040 
00041 
00042 
00043 namespace mln
00044 {
00045 
00046   namespace make
00047   {
00048 
00055     template <typename V, unsigned L>
00056     mln::image1d<V> image(V (&values)[L]);
00057 
00058 
00065     template <typename V, unsigned R, unsigned C>
00066     mln::image2d<V> image(V (&values)[R][C]);
00067 
00068 
00075     template <typename V, unsigned S, unsigned R, unsigned C>
00076     mln::image3d<V> image(V (&values)[S][R][C]);
00077 
00078 
00079 
00080 # ifndef MLN_INCLUDE_ONLY
00081 
00082     template <typename V, unsigned L>
00083     mln::image1d<V>
00084     image(V (&values)[L])
00085     {
00086       mlc_bool(L != 0)::check();
00087       mln::image1d<V> tmp(L);
00088       const def::coord ninds = static_cast<def::coord>(L);
00089       for (def::coord ind = 0; ind < ninds; ++ind)
00090         tmp(point1d(ind)) = values[ind];
00091       return tmp;
00092     }
00093 
00094     template <typename V, unsigned R, unsigned C>
00095     mln::image2d<V>
00096     image(V (&values)[R][C])
00097     {
00098       mlc_bool(R != 0 && C != 0)::check();
00099       mln::image2d<V> tmp(R, C);
00100       const def::coord
00101         nrows = static_cast<def::coord>(R),
00102         ncols = static_cast<def::coord>(C);
00103       for (def::coord row = 0; row < nrows; ++row)
00104         for (def::coord col = 0; col < ncols; ++col)
00105           opt::at(tmp, row, col) = values[row][col];
00106       return tmp;
00107     }
00108 
00109     template <typename V, unsigned S, unsigned R, unsigned C>
00110     mln::image3d<V>
00111     image(V (&values)[S][R][C])
00112     {
00113       mlc_bool(S != 0 && R != 0 && C != 0)::check();
00114       mln::image3d<V> tmp(S, R, C);
00115       const def::coord
00116         nslis = static_cast<def::coord>(S),
00117         nrows = static_cast<def::coord>(R),
00118         ncols = static_cast<def::coord>(C);
00119       for (def::coord sli = 0; sli < nslis; ++sli)
00120         for (def::coord row = 0; row < nrows; ++row)
00121           for (def::coord col = 0; col < ncols; ++col)
00122             opt::at(tmp, sli, row, col) = values[sli][row][col];
00123       return tmp;
00124     }
00125 
00126 # endif // ! MLN_INCLUDE_ONLY
00127 
00128   } // end of namespace mln::make
00129 
00130 } // end of namespace mln
00131 
00132 
00133 #endif // ! MLN_MAKE_IMAGE_HH

Generated on Thu Sep 8 2011 18:31:58 for Milena (Olena) by  doxygen 1.7.1