$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
window2d.hh
1 // Copyright (C) 2007, 2008, 2009, 2010, 2012 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_WINDOW2D_HH
28 # define MLN_CORE_ALIAS_WINDOW2D_HH
29 
34 
35 # include <mln/core/window.hh>
36 # include <mln/core/alias/dpoint2d.hh>
37 # include <mln/metal/math/sqrt.hh>
38 
39 
40 namespace mln
41 {
42 
91 
92  typedef window<mln::dpoint2d> window2d;
94 
97 
109  const window2d& win_c4p();
110 
113 
125  const window2d& win_c8p();
126 
127 
129  template <unsigned S>
130  void from_to_(const bool (&values)[S], window2d& win);
131 
133  template <unsigned R, unsigned C>
134  void from_to_(const bool (&values)[R][C], window2d& win);
135 
136 
137 # ifndef MLN_INCLUDE_ONLY
138 
139  inline const window2d&
140  win_c4p()
141  {
142  static window2d it;
143  if (it.size() == 0)
144  {
145  it
146  .insert( 0, -1)
147  .insert(-1, 0)
148  .insert( 0, 0)
149  .insert(+1, 0)
150  .insert( 0, +1);
151  }
152  return it;
153  }
154 
155  inline const window2d&
156  win_c8p()
157  {
158  static window2d it;
159  if (it.size() == 0)
160  {
161  it
162  .insert(-1, -1)
163  .insert( 0, -1)
164  .insert(+1, -1)
165  .insert(-1, 0)
166  .insert( 0, 0)
167  .insert(+1, 0)
168  .insert(-1, +1)
169  .insert( 0, +1)
170  .insert(+1, +1);
171  }
172  return it;
173  }
174 
175 
176  template <unsigned S>
177  void
178  from_to_(const bool (&values)[S], window2d& win)
179  {
180  enum { H = mlc_sqrt_int(S) / 2 };
181  mlc_bool((2 * H + 1) * (2 * H + 1) == S)::check();
182  win.clear();
183  unsigned i = 0;
184  const def::coord
185  h = static_cast<def::coord>(H),
186  _h = static_cast<def::coord>(-h);
187  for (def::coord row = _h; row <= h; ++row)
188  for (def::coord col = _h; col <= h; ++col)
189  if (values[i++])
190  win.insert(row, col);
191  }
192 
193  template <unsigned R, unsigned C>
194  void
195  from_to_(const bool (&values)[R][C], window2d& win)
196  {
197  mlc_bool(R % 2 == 1)::check();
198  mlc_bool(C % 2 == 1)::check();
199  win.clear();
200  const def::coord
201  drow = static_cast<def::coord>(R / 2),
202  _drow = static_cast<def::coord>(- drow),
203  dcol = static_cast<def::coord>(C / 2),
204  _dcol = static_cast<def::coord>(- dcol);
205  for (def::coord row = _drow; row <= drow; ++row)
206  for (def::coord col = _dcol; col <= dcol; ++col)
207  if (values[row + drow][col + dcol])
208  win.insert(row, col);
209  }
210 
211 # endif // ! MLN_INCLUDE_ONLY
212 
213 } // end of namespace mln
214 
215 
216 #endif // ! MLN_CORE_ALIAS_WINDOW2D_HH