$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
static_window.hh
1 // Copyright (C) 2007, 2008, 2009, 2010, 2011 EPITA Research and Development
2 // 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_STATIC_WINDOW_HH
28 # define MLN_CORE_STATIC_WINDOW_HH
29 
30 // FIXME: Review and update the documentation.
31 
46 # include <mln/core/internal/window_base.hh>
47 # include <mln/core/concept/gdpoint.hh>
48 
49 # include <mln/metal/is_a.hh>
50 # include <mln/util/set.hh>
51 # include <mln/fun/i2v/all_to.hh>
52 # include <mln/norm/linfty.hh>
53 # include <mln/literal/zero.hh>
54 
55 # include "apps/bench/static_array.hh"
56 
57 
58 namespace mln
59 {
60 
61  // Forward declarations.
62  template <typename D, unsigned n> class static_window;
63  template <typename V> class dpsites_fwd_piter;
64  template <typename V> class dpsites_bkd_piter;
65 
66 
67 
68  namespace trait
69  {
70 
71  template <typename D, unsigned n>
72  struct window_< mln::static_window<D, n> >
73  {
74  typedef trait::window::size::fixed size;
75  typedef trait::window::support::regular support;
76  typedef trait::window::definition::unique definition;
77  };
78 
79  } // end of namespace mln::trait
80 
81 
82 
88  template <typename D, unsigned n>
89  class static_window : public internal::window_base< D, static_window<D, n> >
90  {
91  public:
92 
93  enum { length = n };
94 
97 
98 
100 
105  bool is_centered() const;
106 
112  bool is_symmetric() const;
113 
115  void sym();
116 
117 
122 
127 
131  typedef fwd_qiter qiter;
132 
133 
135  unsigned size() const;
136 
139  bool is_empty() const;
140 
141  // /// Clear the window.
142  // void clear();
143 
147  unsigned delta() const;
148 
150  const D& dp(unsigned i) const;
151 
153  bool has(const D& dp) const;
154 
155  // /// Insert a delta-point \p dp.
156  // static_window<D, n>& insert(const D& dp);
157 
158  // /// Insert another window \p win.
159  // template <typename W>
160  // static_window<D, n>& insert(const Window<W>& win);
161 
162  // /// \{ Insertion of a delta-point with different numbers of
163  // /// arguments (coordinates) w.r.t. the dimension.
164  // static_window<D, n>& insert(const mln_coord(D)& dind); // For 1D or index access.
165 
166  // static_window<D, n>& insert(const mln_coord(D)& drow,
167  // const mln_coord(D)& dcol); // For 2D.
168 
169  // static_window<D, n>& insert(const mln_coord(D)& dsli,
170  // const mln_coord(D)& drow,
171  // const mln_coord(D)& dcol); // For 3D.
173 
174 
177 
179  void print(std::ostream& ostr) const;
180 
181  private:
182 
184 
185  unsigned delta_(int i) const; // For indices.
186  unsigned delta_(const Gdpoint<D>& dp) const; // For grids delta-points.
187  };
188 
189 
190 
195  template <typename D, unsigned n>
196  bool operator==(const static_window<D, n>& lhs, const static_window<D, n>& rhs);
197 
198 
199 
200 # ifndef MLN_INCLUDE_ONLY
201 
202  // static_window<D, n>
203 
204  template <typename D, unsigned n>
205  inline
207  : dps_(dps)
208  {
209  // FIXME HERE: Was: mln::metal::is_a<D, Dpoint>::check();
210  // mln::metal::is_a<D, Delta_Point_Site>::check();
211  }
212 
213  template <typename D, unsigned n>
214  inline
215  bool
217  {
218  static_window<D, n> cpy = *this;
219  cpy.sym();
220  return cpy == *this;
221  }
222 
223  template <typename D, unsigned n>
224  inline
225  bool
227  {
228  return this->dps_.has(literal::zero);
229  }
230 
231  template <typename D, unsigned n>
232  inline
233  void
235  {
236  util::static_array<D, n> rev;
237  // FIXME: Can't we use std::copy and reverse_iterators here?
238  for (std::size_t i = 0; i < n; ++i)
239  rev[i] = dps_[n - 1 - i];
240  static_window<D, n> tmp(rev);
241  *this = tmp;
242  }
243 
244  template <typename D, unsigned n>
245  inline
246  bool
248  {
249  return n == 0;
250  }
251 
252  // template <typename D, unsigned n>
253  // inline
254  // void
255  // static_window<D, n>::clear()
256  // {
257  // dps_.clear();
258  // }
259 
260  template <typename D, unsigned n>
261  inline
262  unsigned
264  {
265  unsigned d = 0;
266  for (unsigned i = 0; i < n; ++i)
267  {
268  unsigned dd = delta_(dp(i));
269  if (dd > d)
270  d = dd;
271  }
272  return d;
273  }
274 
275  template <typename D, unsigned n>
276  inline
277  unsigned
278  static_window<D, n>::delta_(int i) const
279  {
280  return i;
281  }
282 
283  template <typename D, unsigned n>
284  inline
285  unsigned
286  static_window<D, n>::delta_(const Gdpoint<D>& dp) const
287  {
288  return norm::linfty(exact(dp).to_vec());
289  }
290 
291  template <typename D, unsigned n>
292  inline
293  unsigned
295  {
296  return n;
297  }
298 
299  template <typename D, unsigned n>
300  inline
301  const D&
302  static_window<D, n>::dp(unsigned i) const
303  {
304  mln_precondition(i < n);
305  return dps_[i];
306  }
307 
308  template <typename D, unsigned n>
309  inline
310  bool
311  static_window<D, n>::has(const D& dp) const
312  {
313  return dps_.has(dp);
314  }
315 
316  // template <typename D, unsigned n>
317  // inline
318  // static_window<D, n>&
319  // static_window<D, n>::insert(const D& dp)
320  // {
321  // dps_.insert(dp);
322  // return *this;
323  // }
324 
325  // template <typename D, unsigned n>
326  // template <typename W>
327  // inline
328  // static_window<D, n>&
329  // static_window<D, n>::insert(const Window<W>& win_)
330  // {
331  // const W& win = exact(win_);
332  // const unsigned n = win.size();
333  // for (unsigned i = 0; i < n; ++i)
334  // dps_.insert(win.dp(i));
335  // return *this;
336  // }
337 
338  // template <typename D, unsigned n>
339  // inline
340  // static_window<D, n>&
341  // static_window<D, n>::insert(const mln_coord(D)& dind)
342  // {
343  // mlc_bool(D::dim == 1)::check();
344  // D dp(dind);
345  // return insert(dp);
346  // }
347 
348  // template <typename D, unsigned n>
349  // inline
350  // static_window<D, n>&
351  // static_window<D, n>::insert(const mln_coord(D)& drow,
352  // const mln_coord(D)& dcol)
353  // {
354  // mlc_bool(D::dim == 2)::check();
355  // D dp(drow, dcol);
356  // return insert(dp);
357  // }
358 
359  // template <typename D, unsigned n>
360  // inline
361  // static_window<D, n>&
362  // static_window<D, n>::insert(const mln_coord(D)& dsli,
363  // const mln_coord(D)& drow,
364  // const mln_coord(D)& dcol)
365  // {
366  // mlc_bool(D::dim == 3)::check();
367  // D dp(dsli, drow, dcol);
368  // return insert(dp);
369  // }
370 
371  template <typename D, unsigned n>
372  inline
375  {
376  return dps_;
377  }
378 
379  template <typename D, unsigned n>
380  inline
381  void
382  static_window<D, n>::print(std::ostream& ostr) const
383  {
384  ostr << dps_;
385  }
386 
387 
388  // Operators.
389 
390  template <typename D, unsigned n>
391  bool
392  operator==(const static_window<D, n>& lhs, const static_window<D, n>& rhs)
393  {
394  return lhs.dps_hook_() == rhs.dps_hook_();
395  }
396 
397 # endif // ! MLN_INCLUDE_ONLY
398 
399 } // end of namespace mln
400 
401 
402 # include <mln/core/dpsites_piter.hh>
403 
404 
405 #endif // ! MLN_CORE_STATIC_WINDOW_HH