• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

dpoints_pixter.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #ifndef MLN_CORE_DPOINTS_PIXTER_HH
00027 # define MLN_CORE_DPOINTS_PIXTER_HH
00028 
00035 
00036 # include <cassert>
00037 # include <vector>
00038 
00039 # include <mln/core/concept/proxy.hh>
00040 # include <mln/core/concept/pixel_iterator.hh>
00041 # include <mln/core/internal/pixel_impl.hh>
00042 # include <mln/metal/converts_to.hh>
00043 
00044 
00045 namespace mln
00046 {
00047 
00048   /*------------------------.
00049   | dpoints_fwd_pixter<I>.  |
00050   `------------------------*/
00051 
00056   template <typename I>
00057   class dpoints_fwd_pixter
00058     : public Pixel_Iterator< dpoints_fwd_pixter<I> >,
00059       public internal::pixel_impl_< I, dpoints_fwd_pixter<I> >
00060   {
00061     typedef typename internal::pixel_impl_< I, dpoints_fwd_pixter<I> > super_;
00062 
00063   public:
00071     template <typename Dps, typename Pref>
00072     dpoints_fwd_pixter(I& image,
00073                        const Dps& dps,
00074                        const Pref& p_ref);
00075 
00081     template <typename Dps, typename Pref>
00082     dpoints_fwd_pixter(const Generalized_Pixel<Pref>& pxl_ref,
00083                        const Dps& dps);
00084 
00088     void start();
00090     void next_();
00091 
00093     void invalidate();
00095     bool is_valid() const;
00096 
00099     void update();
00101 
00103     const mln_value(I)& center_val() const;
00104 
00105   private:
00106     template <typename Dps>
00107     void init_(const Dps& dps);
00108 
00109   private:
00115     std::vector<int> offset_;
00117     typename std::vector<int>::const_iterator i_;
00118 
00124     mln_qlf_value(I)** value_ref_;
00126     const mln_psite(I)* p_ref_;
00128   };
00129 
00130 
00131   /*------------------------.
00132   | dpoints_bkd_pixter<I>.  |
00133   `------------------------*/
00134 
00139   template <typename I>
00140   class dpoints_bkd_pixter
00141     : public Pixel_Iterator< dpoints_bkd_pixter<I> >,
00142       public internal::pixel_impl_< I, dpoints_bkd_pixter<I> >
00143   {
00144     typedef typename internal::pixel_impl_< I, dpoints_bkd_pixter<I> > super_;
00145 
00146   public:
00154     template <typename Dps, typename Pref>
00155     dpoints_bkd_pixter(I& image,
00156                        const Dps& dps,
00157                        const Pref& p_ref);
00158 
00164     template <typename Dps, typename Pref>
00165     dpoints_bkd_pixter(const Generalized_Pixel<Pref>& pxl_ref,
00166                        const Dps& dps);
00167 
00171     void start();
00173     void next_();
00174 
00176     void invalidate();
00178     bool is_valid() const;
00179 
00182     void update();
00184 
00186     const mln_value(I)& center_val() const;
00187 
00188   private:
00189     template <typename Dps>
00190     void init_(const Dps& dps);
00191 
00192   private:
00198     std::vector<int> offset_;
00200     typename std::vector<int>::const_reverse_iterator i_;
00201 
00207     mln_qlf_value(I)** value_ref_;
00209     const mln_psite(I)* p_ref_;
00211   };
00212 
00213 
00214 
00215 #ifndef MLN_INCLUDE_ONLY
00216 
00217   /*------------------------.
00218   | dpoints_fwd_pixter<I>.  |
00219   `------------------------*/
00220 
00221   template <typename I>
00222   template <typename Dps, typename Pref>
00223   inline
00224   dpoints_fwd_pixter<I>::dpoints_fwd_pixter(I& image,
00225                                             const Dps& dps,
00226                                             const Pref& p_ref)
00227     : super_(image)
00228   {
00229     mln_precondition(image.is_valid());
00230 
00231     mlc_converts_to(Pref, const mln_psite(I)&)::check();
00232     p_ref_ = & static_cast< const mln_psite(I)& >(p_ref);
00233 
00234     value_ref_ = 0;
00235     init_(dps);
00236   }
00237 
00238   template <typename I>
00239   template <typename Dps, typename Pref>
00240   inline
00241   dpoints_fwd_pixter<I>::dpoints_fwd_pixter(const Generalized_Pixel<Pref>& pxl_ref_,
00242                                             const Dps& dps)
00243     : super_(internal::force_exact<Pref>(pxl_ref_).ima())
00244   {
00245     const Pref& pxl_ref = internal::force_exact<Pref>(pxl_ref_);
00246     mln_precondition(pxl_ref.ima().is_valid());
00247     p_ref_ = 0;
00248     // Potential promotion from (T**) to (const T**) shall be forced.
00249     value_ref_ = const_cast<mln_qlf_value(I)**>(pxl_ref.address_());
00250     init_(dps);
00251   }
00252 
00253   template <typename I>
00254   inline
00255   const mln_value(I)&
00256   dpoints_fwd_pixter<I>::center_val() const
00257   {
00258     mln_invariant(value_ref_ != 0 || p_ref_ != 0);
00259     if (p_ref_)
00260       return image_(*p_ref_);
00261     else
00262       return **value_ref_;
00263   }
00264 
00265   template <typename I>
00266   template <typename Dps>
00267   inline
00268   void
00269   dpoints_fwd_pixter<I>::init_(const Dps& dps)
00270   {
00271     for (unsigned i = 0; i < dps.size(); ++i)
00272       offset_.push_back(this->image_.delta_index(dps.dp(i)));
00273     // offset_[0] is absolute
00274     // other offsets are relative:
00275     if (dps.size() > 1)
00276       for (unsigned i = dps.size() - 1; i > 0; --i)
00277         offset_[i] -= offset_[i - 1];
00278     invalidate();
00279   }
00280 
00281   template <typename I>
00282   inline
00283   void
00284   dpoints_fwd_pixter<I>::update()
00285   {
00286     if (is_valid())
00287       {
00288         if (p_ref_)
00289           this->value_ptr_ = & image_(*p_ref_) + *i_;
00290         else
00291           this->value_ptr_ = * value_ref_ + *i_;
00292       }
00293   }
00294 
00295   template <typename I>
00296   inline
00297   void
00298   dpoints_fwd_pixter<I>::start()
00299   {
00300     i_ = offset_.begin();
00301     update();
00302   }
00303 
00304   template <typename I>
00305   inline
00306   void
00307   dpoints_fwd_pixter<I>::next_()
00308   {
00309     ++i_;
00310     if (is_valid())
00311       this->value_ptr_ += *i_;
00312   }
00313 
00314   template <typename I>
00315   inline
00316   bool
00317   dpoints_fwd_pixter<I>::is_valid() const
00318   {
00319     return i_ != offset_.end();
00320   }
00321 
00322   template <typename I>
00323   inline
00324   void
00325   dpoints_fwd_pixter<I>::invalidate()
00326   {
00327     i_ = offset_.end();
00328   }
00329 
00330 
00331   /*------------------------.
00332   | dpoints_bkd_pixter<I>.  |
00333   `------------------------*/
00334 
00335   template <typename I>
00336   template <typename Dps, typename Pref>
00337   inline
00338   dpoints_bkd_pixter<I>::dpoints_bkd_pixter(I& image,
00339                                             const Dps& dps,
00340                                             const Pref& p_ref)
00341     : super_(image)
00342   {
00343     mln_precondition(image.is_valid());
00344     internal::get_adr(p_ref_, p_ref);
00345     value_ref_ = 0;
00346     init_(dps);
00347   }
00348 
00349   template <typename I>
00350   template <typename Dps, typename Pref>
00351   inline
00352   dpoints_bkd_pixter<I>::dpoints_bkd_pixter(const Generalized_Pixel<Pref>& pxl_ref_,
00353                                             const Dps& dps)
00354     : super_(internal::force_exact<Pref>(pxl_ref_).ima())
00355   {
00356     const Pref& pxl_ref = internal::force_exact<Pref>(pxl_ref_);
00357     mln_precondition(pxl_ref.ima().is_valid());
00358     p_ref_ = 0;
00359     // Potential promotion from (T**) to (const T**) shall be forced.
00360     value_ref_ = const_cast<mln_qlf_value(I)**>(pxl_ref.address_());
00361     init_(dps);
00362   }
00363 
00364   template <typename I>
00365   inline
00366   const mln_value(I)&
00367   dpoints_bkd_pixter<I>::center_val() const
00368   {
00369     mln_invariant(value_ref_ != 0 || p_ref_ != 0);
00370     if (p_ref_)
00371       return image_(*p_ref_);
00372     else
00373       return **value_ref_;
00374   }
00375 
00376   template <typename I>
00377   template <typename Dps>
00378   inline
00379   void
00380   dpoints_bkd_pixter<I>::init_(const Dps& dps)
00381   {
00382     for (unsigned i = 0; i < dps.size(); ++i)
00383       offset_.push_back(this->image_.delta_index(dps.dp(i)));
00384     // offset_[size() - 1] is absolute
00385     // other offsets are relative:
00386     if (dps.size() > 1)
00387       for (unsigned i = 0; i < dps.size() - 1; ++i)
00388         offset_[i] -= offset_[i + 1];
00389     invalidate();
00390   }
00391 
00392   template <typename I>
00393   inline
00394   void
00395   dpoints_bkd_pixter<I>::update()
00396   {
00397     if (is_valid())
00398       {
00399         if (p_ref_)
00400           this->value_ptr_ = & image_(*p_ref_) + *i_;
00401         else
00402           this->value_ptr_ = * value_ref_ + *i_;
00403       }
00404   }
00405 
00406   template <typename I>
00407   inline
00408   void
00409   dpoints_bkd_pixter<I>::start()
00410   {
00411     i_ = offset_.rbegin();
00412     update();
00413   }
00414 
00415   template <typename I>
00416   inline
00417   void
00418   dpoints_bkd_pixter<I>::next_()
00419   {
00420     ++i_;
00421     if (is_valid())
00422       this->value_ptr_ += *i_;
00423   }
00424 
00425   template <typename I>
00426   inline
00427   bool
00428   dpoints_bkd_pixter<I>::is_valid() const
00429   {
00430     return i_ != offset_.rend();
00431   }
00432 
00433   template <typename I>
00434   inline
00435   void
00436   dpoints_bkd_pixter<I>::invalidate()
00437   {
00438     i_ = offset_.rend();
00439   }
00440 
00441 #endif // ! MLN_INCLUDE_ONLY
00442 
00443 } // end of namespace mln
00444 
00445 
00446 #endif // ! MLN_CORE_DPOINTS_PIXTER_HH

Generated on Tue Oct 4 2011 15:23:42 for Milena (Olena) by  doxygen 1.7.1