$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
window3d.hh
1 // Copyright (C) 2007, 2008, 2009, 2012, 2013 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_CORE_ALIAS_WINDOW3D_HH
28 # define MLN_CORE_ALIAS_WINDOW3D_HH
29 
34 
35 # include <cmath>
36 # include <mln/core/window.hh>
37 # include <mln/core/alias/dpoint3d.hh>
38 # include <mln/convert/from_to.hh>
39 
40 
41 namespace mln
42 {
43 
92 
93  typedef window<mln::dpoint3d> window3d;
95 
98 
119  const window3d& win_c4p_3d();
120 
123 
143  const window3d& win_c8p_3d();
144 
145 
147  template <unsigned M>
148  void from_to_(bool const (&values)[M], window3d& win);
149 
150 
151 
152 # ifndef MLN_INCLUDE_ONLY
153 
154  inline const window3d&
155  win_c4p_3d()
156  {
157  static window3d it;
158  if (it.size() == 0)
159  {
160  it
161  .insert(0, 0, -1)
162  .insert(0, -1, 0)
163  .insert(0, 0, 0)
164  .insert(0, +1, 0)
165  .insert(0, 0, +1);
166  }
167  return it;
168  }
169 
170  inline const window3d&
171  win_c8p_3d()
172  {
173  static window3d it;
174  if (it.size() == 0)
175  {
176  it
177  .insert(0, -1, -1)
178  .insert(0, 0, -1)
179  .insert(0, +1, -1)
180  .insert(0, -1, 0)
181  .insert(0, 0, 0)
182  .insert(0, +1, 0)
183  .insert(0, -1, +1)
184  .insert(0, 0, +1)
185  .insert(0, +1, +1);
186  }
187  return it;
188  }
189 
190 
191  // Conversion
192 
193  template <unsigned M>
194  void
195  from_to_(bool const (&values)[M], window3d& win)
196  {
197  const int h = unsigned(std::pow(float(M), float(1. / 3.))) / 2;
198  mln_precondition((2 * h + 1) * (2 * h + 1) * (2 * h + 1) == M);
199  win.clear();
200  unsigned i = 0;
201  for (int sli = - h; sli <= h; ++sli)
202  for (int row = - h; row <= h; ++row)
203  for (int col = - h; col <= h; ++col)
204  if (values[i++])
205  win.insert(sli, row, col);
206  }
207 
208 # endif // ! MLN_INCLUDE_ONLY
209 
210 
211 } // end of namespace mln
212 
213 
214 #endif // ! MLN_CORE_ALIAS_WINDOW3D_HH