$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
static_dpoints_pixter.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_DPOINTS_PIXTER_HH
28 # define MLN_CORE_STATIC_DPOINTS_PIXTER_HH
29 
30 // FIXME: Review and update the documentation.
31 
38 
39 # include <cassert>
40 # include <vector>
41 
42 # include <mln/core/concept/proxy.hh>
43 # include <mln/core/concept/pixel_iterator.hh>
44 # include <mln/core/internal/pixel_impl.hh>
45 # include <mln/metal/converts_to.hh>
46 
47 # include "apps/bench/static_array.hh"
48 
49 namespace mln
50 {
51 
52  /*----------------------------------.
53  | static_dpoints_fwd_pixter<I, W>. |
54  `----------------------------------*/
55 
60  template <typename I, typename W>
62  : public Pixel_Iterator< static_dpoints_fwd_pixter<I, W> >,
63  public internal::pixel_impl_< I, static_dpoints_fwd_pixter<I, W> >
64  {
66 
67  public:
75  template <typename Dps, typename Pref>
77  const Dps& dps,
78  const Pref& p_ref);
79 
85  template <typename Dps, typename Pref>
87  const Dps& dps);
88 
92  void start();
94  void next_();
95 
97  void invalidate();
99  bool is_valid() const;
100 
103  void update();
105 
107  const mln_value(I)& center_val() const;
108 
109  private:
110  template <typename Dps>
111  void init_(const Dps& dps);
112 
113  private:
114  enum { n = W::length };
115 
123  std::size_t i_;
124 
130  mln_qlf_value(I)** value_ref_;
132  const mln_psite(I)* p_ref_;
134  };
135 
136 
137  /*----------------------------------.
138  | static_dpoints_bkd_pixter<I, W>. |
139  `----------------------------------*/
140 
145  template <typename I, typename W>
147  : public Pixel_Iterator< static_dpoints_bkd_pixter<I, W> >,
148  public internal::pixel_impl_< I, static_dpoints_bkd_pixter<I, W> >
149  {
151 
152  public:
160  template <typename Dps, typename Pref>
162  const Dps& dps,
163  const Pref& p_ref);
164 
170  template <typename Dps, typename Pref>
172  const Dps& dps);
173 
177  void start();
179  void next_();
180 
182  void invalidate();
184  bool is_valid() const;
185 
188  void update();
190 
192  const mln_value(I)& center_val() const;
193 
194  private:
195  template <typename Dps>
196  void init_(const Dps& dps);
197 
198  private:
199  enum { n = W::length };
200 
208  std::size_t i_;
209 
215  mln_qlf_value(I)** value_ref_;
217  const mln_psite(I)* p_ref_;
219  };
220 
221 
222 
223 #ifndef MLN_INCLUDE_ONLY
224 
225  /*----------------------------------.
226  | static_dpoints_fwd_pixter<I, W>. |
227  `----------------------------------*/
228 
229  template <typename I, typename W>
230  template <typename Dps, typename Pref>
231  inline
233  const Dps& dps,
234  const Pref& p_ref)
235  : super_(image)
236  {
237  mln_precondition(image.is_valid());
238 
239  mlc_converts_to(Pref, const mln_psite(I)&)::check();
240  p_ref_ = & static_cast< const mln_psite(I)& >(p_ref);
241 
242  value_ref_ = 0;
243  init_(dps);
244  }
245 
246  template <typename I, typename W>
247  template <typename Dps, typename Pref>
248  inline
249  static_dpoints_fwd_pixter<I, W>::static_dpoints_fwd_pixter(const Generalized_Pixel<Pref>& pxl_ref_,
250  const Dps& dps)
251  : super_(internal::force_exact<Pref>(pxl_ref_).ima())
252  {
253  const Pref& pxl_ref = internal::force_exact<Pref>(pxl_ref_);
254  mln_precondition(pxl_ref.ima().is_valid());
255  p_ref_ = 0;
256  // Potential promotion from (T**) to (const T**) shall be forced.
257  value_ref_ = const_cast<mln_qlf_value(I)**>(pxl_ref.address_());
258  init_(dps);
259  }
260 
261  template <typename I, typename W>
262  inline
263  const mln_value(I)&
265  {
266  mln_invariant(value_ref_ != 0 || p_ref_ != 0);
267  if (p_ref_)
268  return this->image_(*p_ref_);
269  else
270  return **value_ref_;
271  }
272 
273  template <typename I, typename W>
274  template <typename Dps>
275  inline
276  void
277  static_dpoints_fwd_pixter<I, W>::init_(const Dps& dps)
278  {
279  for (unsigned i = 0; i < dps.size(); ++i)
280  offset_[i] = this->image_.delta_offset(dps.dp(i));
281  // offset_[0] is absolute
282  // other offsets are relative:
283  if (dps.size() > 1)
284  for (unsigned i = dps.size() - 1; i > 0; --i)
285  offset_[i] -= offset_[i - 1];
286  invalidate();
287  }
288 
289  template <typename I, typename W>
290  inline
291  void
293  {
294  if (is_valid())
295  {
296  if (p_ref_)
297  this->value_ptr_ = & this->image_(*p_ref_) + offset_[i_];
298  else
299  this->value_ptr_ = * value_ref_ + offset_[i_];
300  }
301  }
302 
303  template <typename I, typename W>
304  inline
305  void
307  {
308  i_ = 0;
309  update();
310  }
311 
312  template <typename I, typename W>
313  inline
314  void
316  {
317  ++i_;
318  if (is_valid())
319  this->value_ptr_ += offset_[i_];
320  }
321 
322  template <typename I, typename W>
323  inline
324  bool
326  {
327  return i_ < n;
328  }
329 
330  template <typename I, typename W>
331  inline
332  void
334  {
335  i_ = n;
336  }
337 
338 
339  /*----------------------------------.
340  | static_dpoints_bkd_pixter<I, W>. |
341  `----------------------------------*/
342 
343  template <typename I, typename W>
344  template <typename Dps, typename Pref>
345  inline
347  const Dps& dps,
348  const Pref& p_ref)
349  : super_(image)
350  {
351  mln_precondition(image.is_valid());
352  internal::get_adr(p_ref_, p_ref);
353  value_ref_ = 0;
354  init_(dps);
355  }
356 
357  template <typename I, typename W>
358  template <typename Dps, typename Pref>
359  inline
360  static_dpoints_bkd_pixter<I, W>::static_dpoints_bkd_pixter(const Generalized_Pixel<Pref>& pxl_ref_,
361  const Dps& dps)
362  : super_(internal::force_exact<Pref>(pxl_ref_).ima())
363  {
364  const Pref& pxl_ref = internal::force_exact<Pref>(pxl_ref_);
365  mln_precondition(pxl_ref.ima().is_valid());
366  p_ref_ = 0;
367  // Potential promotion from (T**) to (const T**) shall be forced.
368  value_ref_ = const_cast<mln_qlf_value(I)**>(pxl_ref.address_());
369  init_(dps);
370  }
371 
372  template <typename I, typename W>
373  inline
374  const mln_value(I)&
376  {
377  mln_invariant(value_ref_ != 0 || p_ref_ != 0);
378  if (p_ref_)
379  return this->image_(*p_ref_);
380  else
381  return **value_ref_;
382  }
383 
384  template <typename I, typename W>
385  template <typename Dps>
386  inline
387  void
388  static_dpoints_bkd_pixter<I, W>::init_(const Dps& dps)
389  {
390  for (unsigned i = 0; i < dps.size(); ++i)
391  offset_[i] = this->image_.delta_offset(dps.dp(i));
392  // offset_[size() - 1] is absolute
393  // other offsets are relative:
394  if (dps.size() > 1)
395  for (unsigned i = 0; i < dps.size() - 1; ++i)
396  offset_[i] -= offset_[i + 1];
397  invalidate();
398  }
399 
400  template <typename I, typename W>
401  inline
402  void
404  {
405  if (is_valid())
406  {
407  if (p_ref_)
408  this->value_ptr_ = & this->image_(*p_ref_) + offset_[n - 1 - i_];
409  else
410  this->value_ptr_ = * value_ref_ + offset_[n - 1 - i_];
411  }
412  }
413 
414  template <typename I, typename W>
415  inline
416  void
418  {
419  i_ = 0;
420  update();
421  }
422 
423  template <typename I, typename W>
424  inline
425  void
427  {
428  ++i_;
429  if (is_valid())
430  this->value_ptr_ += offset_[n - 1 - i_];
431  }
432 
433  template <typename I, typename W>
434  inline
435  bool
437  {
438  return i_ < n;
439  }
440 
441  template <typename I, typename W>
442  inline
443  void
445  {
446  i_ = n;
447  }
448 
449 #endif // ! MLN_INCLUDE_ONLY
450 
451 } // end of namespace mln
452 
453 
454 #endif // ! MLN_CORE_STATIC_DPOINTS_PIXTER_HH