$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
make/image.hh
1 // Copyright (C) 2007, 2008, 2009, 2010, 2011 EPITA Research and
2 // Development Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_MAKE_IMAGE_HH
28 # define MLN_MAKE_IMAGE_HH
29 
36 
37 # include <mln/core/image/image1d.hh>
38 # include <mln/core/image/image2d.hh>
39 # include <mln/core/image/image3d.hh>
40 # include <mln/opt/at.hh>
41 
42 
43 
44 namespace mln
45 {
46 
47  namespace make
48  {
49 
56  template <typename V, unsigned L>
57  mln::image1d<V> image(V (&values)[L]);
58 
59 
66  template <typename V, unsigned R, unsigned C>
67  mln::image2d<V> image(V (&values)[R][C]);
68 
69 
76  template <typename V, unsigned S, unsigned R, unsigned C>
77  mln::image3d<V> image(V (&values)[S][R][C]);
78 
79 
80 
81 # ifndef MLN_INCLUDE_ONLY
82 
83  template <typename V, unsigned L>
85  image(V (&values)[L])
86  {
87  mlc_bool(L != 0)::check();
88  mln::image1d<V> tmp(L);
89  const def::coord ninds = static_cast<def::coord>(L);
90  for (def::coord ind = 0; ind < ninds; ++ind)
91  tmp(point1d(ind)) = values[ind];
92  return tmp;
93  }
94 
95  template <typename V, unsigned R, unsigned C>
97  image(V (&values)[R][C])
98  {
99  mlc_bool(R != 0 && C != 0)::check();
100  mln::image2d<V> tmp(R, C);
101  const def::coord
102  nrows = static_cast<def::coord>(R),
103  ncols = static_cast<def::coord>(C);
104  for (def::coord row = 0; row < nrows; ++row)
105  for (def::coord col = 0; col < ncols; ++col)
106  opt::at(tmp, row, col) = values[row][col];
107  return tmp;
108  }
109 
110  template <typename V, unsigned S, unsigned R, unsigned C>
112  image(V (&values)[S][R][C])
113  {
114  mlc_bool(S != 0 && R != 0 && C != 0)::check();
115  mln::image3d<V> tmp(S, R, C);
116  const def::coord
117  nslis = static_cast<def::coord>(S),
118  nrows = static_cast<def::coord>(R),
119  ncols = static_cast<def::coord>(C);
120  for (def::coord sli = 0; sli < nslis; ++sli)
121  for (def::coord row = 0; row < nrows; ++row)
122  for (def::coord col = 0; col < ncols; ++col)
123  opt::at(tmp, sli, row, col) = values[sli][row][col];
124  return tmp;
125  }
126 
127 # endif // ! MLN_INCLUDE_ONLY
128 
129  } // end of namespace mln::make
130 
131 } // end of namespace mln
132 
133 
134 #endif // ! MLN_MAKE_IMAGE_HH