Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
window3d.hh
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_CORE_ALIAS_WINDOW3D_HH
27 # define MLN_CORE_ALIAS_WINDOW3D_HH
28 
33 
34 # include <cmath>
35 # include <mln/core/window.hh>
36 # include <mln/core/alias/dpoint3d.hh>
37 # include <mln/convert/from_to.hh>
38 
39 
40 namespace mln
41 {
42 
47  //
49 
52 
73  const window3d& win_c4p_3d();
74 
77 
97  const window3d& win_c8p_3d();
98 
99 
100 
101  namespace convert
102  {
103 
104  namespace over_load
105  {
106 
107  template <unsigned M>
108  void from_to_(bool const (&values)[M], window3d& win);
109 
110  } // end of namespace mln::convert::over_load
111 
112  } // end of namespace mln::convert
113 
114 
115 
116 # ifndef MLN_INCLUDE_ONLY
117 
118  inline const window3d&
120  {
121  static window3d it;
122  if (it.size() == 0)
123  {
124  it
125  .insert(0, 0, -1)
126  .insert(0, -1, 0)
127  .insert(0, 0, 0)
128  .insert(0, +1, 0)
129  .insert(0, 0, +1);
130  }
131  return it;
132  }
133 
134  inline const window3d&
136  {
137  static window3d it;
138  if (it.size() == 0)
139  {
140  it
141  .insert(0, -1, -1)
142  .insert(0, 0, -1)
143  .insert(0, +1, -1)
144  .insert(0, -1, 0)
145  .insert(0, 0, 0)
146  .insert(0, +1, 0)
147  .insert(0, -1, +1)
148  .insert(0, 0, +1)
149  .insert(0, +1, +1);
150  }
151  return it;
152  }
153 
154  namespace convert
155  {
156 
157  namespace over_load
158  {
159 
160  template <unsigned M>
161  void
162  from_to_(bool const (&values)[M], window3d& win)
163  {
164  const int h = unsigned(std::pow(float(M), float(1. / 3.))) / 2;
165  mln_precondition((2 * h + 1) * (2 * h + 1) * (2 * h + 1) == M);
166  win.clear();
167  unsigned i = 0;
168  for (int sli = - h; sli <= h; ++sli)
169  for (int row = - h; row <= h; ++row)
170  for (int col = - h; col <= h; ++col)
171  if (values[i++])
172  win.insert(sli, row, col);
173  }
174 
175  } // end of namespace mln::convert::over_load
176 
177  } // end of namespace mln::convert
178 
179 # endif // ! MLN_INCLUDE_ONLY
180 
181 
182 } // end of namespace mln
183 
184 
185 #endif // ! MLN_CORE_ALIAS_WINDOW3D_HH