00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
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   } 
00130 
00131 } 
00132 
00133 
00134 #endif // ! MLN_MAKE_IMAGE_HH