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

complex_neighborhood_piter.hh

00001 // Copyright (C) 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_IMAGE_COMPLEX_NEIGHBORHOOD_PITER_HH
00027 # define MLN_CORE_IMAGE_COMPLEX_NEIGHBORHOOD_PITER_HH
00028 
00031 
00032 # include <mln/core/concept/neighborhood.hh>
00033 # include <mln/core/internal/site_relative_iterator_base.hh>
00034 
00035 // FIXME: These might be factor-able, both between fwd/bkd and nbh/win.
00036 
00037 /* FIXME: Do we really want to inherit from
00038    internal::site_relative_iterator_base?  It might duplicate things,
00039    since most of the implementation of this iterator is delegated to
00040    the underlying complex iter.  Think about introducing base class
00041    replacement.  */
00042 
00043 
00044 namespace mln
00045 {
00046 
00047   /*------------------------------------------.
00048   | complex_neighborhood_fwd_piter<I, G, N>.  |
00049   `------------------------------------------*/
00050 
00052   template <typename I, typename G, typename N>
00053   class complex_neighborhood_fwd_piter
00054     : public internal::site_relative_iterator_base< N,
00055                                                     complex_neighborhood_fwd_piter<I, G, N> >
00056   {
00057     typedef complex_neighborhood_fwd_piter<I, G, N> self_;
00058     typedef internal::site_relative_iterator_base< N, self_ > super_;
00059 
00060   public:
00062     typedef mln_psite(N) psite;
00064     typedef typename N::complex_fwd_iter iter_type;
00065 
00066   public:
00069     complex_neighborhood_fwd_piter();
00070     template <typename Pref>
00071     complex_neighborhood_fwd_piter(const Neighborhood<N>& nbh,
00072                                    const Pref& p_ref);
00074 
00076     template <typename Pref>
00077     void init_(const Neighborhood<N>& nbh, const Pref& p_ref);
00078 
00082     bool is_valid_() const;
00084     void invalidate_();
00085 
00087     void do_start_();
00089     void do_next_();
00090 
00092     template <typename Pref>
00093     void center_at_(const Pref& c);
00094 
00096     psite compute_p_() const;
00098 
00101     const iter_type& iter() const;
00102     iter_type& iter();
00104 
00105   private:
00107     iter_type iter_;
00108   };
00109 
00110 
00112   template <typename I, typename G, typename N>
00113   std::ostream&
00114   operator<<(std::ostream& ostr,
00115              const complex_neighborhood_fwd_piter<I, G, N>& p);
00116 
00117 
00118   /*------------------------------------------.
00119   | complex_neighborhood_bkd_piter<I, G, N>.  |
00120   `------------------------------------------*/
00121 
00123   template <typename I, typename G, typename N>
00124   class complex_neighborhood_bkd_piter
00125     : public internal::site_relative_iterator_base< N,
00126                                                     complex_neighborhood_bkd_piter<I, G, N> >
00127   {
00128     typedef complex_neighborhood_bkd_piter<I, G, N> self_;
00129     typedef internal::site_relative_iterator_base< N, self_ > super_;
00130 
00131   public:
00133     typedef mln_psite(N) psite;
00135     typedef typename N::complex_bkd_iter iter_type;
00136 
00137   public:
00140     complex_neighborhood_bkd_piter();
00141     template <typename Pref>
00142     complex_neighborhood_bkd_piter(const Neighborhood<N>& nbh,
00143                                    const Pref& p_ref);
00145 
00147     template <typename Pref>
00148     void init_(const Neighborhood<N>& nbh, const Pref& p_ref);
00149 
00153     bool is_valid_() const;
00155     void invalidate_();
00156 
00158     void do_start_();
00160     void do_next_();
00161 
00163     template <typename Pref>
00164     void center_at_(const Pref& c);
00165 
00167     psite compute_p_() const;
00169 
00172     const iter_type& iter() const;
00173     iter_type& iter();
00175 
00176   private:
00178     iter_type iter_;
00179   };
00180 
00181 
00183   template <typename I, typename G, typename N>
00184   std::ostream&
00185   operator<<(std::ostream& ostr,
00186              const complex_neighborhood_bkd_piter<I, G, N>& p);
00187 
00188 
00189 
00190 # ifndef MLN_INCLUDE_ONLY
00191 
00192   /*------------------------------------------.
00193   | complex_neighborhood_fwd_piter<I, G, N>.  |
00194   `------------------------------------------*/
00195 
00196   template <typename I, typename G, typename N>
00197   inline
00198   complex_neighborhood_fwd_piter<I, G, N>::complex_neighborhood_fwd_piter()
00199   {
00200   }
00201 
00202   template <typename I, typename G, typename N>
00203   template <typename Pref>
00204   inline
00205   complex_neighborhood_fwd_piter<I, G, N>::complex_neighborhood_fwd_piter(const Neighborhood<N>& nbh,
00206                                                                           const Pref& p_ref)
00207   {
00208     init_(nbh, p_ref);
00209   }
00210 
00211   template <typename I, typename G, typename N>
00212   template <typename Pref>
00213   inline
00214   void
00215   complex_neighborhood_fwd_piter<I, G, N>::init_(const Neighborhood<N>& nbh,
00216                                                  const Pref& p_ref)
00217   {
00218     this->change_target(exact(nbh));
00219     this->center_at(p_ref);
00220     mln_postcondition(!this->is_valid());
00221   }
00222 
00223   template <typename I, typename G, typename N>
00224   inline
00225   bool
00226   complex_neighborhood_fwd_piter<I, G, N>::is_valid_() const
00227   {
00228     return iter_.is_valid();
00229   }
00230 
00231   template <typename I, typename G, typename N>
00232   inline
00233   void
00234   complex_neighborhood_fwd_piter<I, G, N>::invalidate_()
00235   {
00236     iter_.invalidate();
00237   }
00238 
00239   template <typename I, typename G, typename N>
00240   inline
00241   void
00242   complex_neighborhood_fwd_piter<I, G, N>::do_start_()
00243   {
00244     iter_.start();
00245   }
00246 
00247   template <typename I, typename G, typename N>
00248   inline
00249   void
00250   complex_neighborhood_fwd_piter<I, G, N>::do_next_()
00251   {
00252     iter_.next();
00253   }
00254 
00255   template <typename I, typename G, typename N>
00256   template <typename Pref>
00257   inline
00258   void
00259   complex_neighborhood_fwd_piter<I, G, N>::center_at_(const Pref&)
00260   {
00261     iter_.center_at(this->center().face());
00262   }
00263 
00264   template <typename I, typename G, typename N>
00265   inline
00266   mln_psite(N)
00267   complex_neighborhood_fwd_piter<I, G, N>::compute_p_() const
00268   {
00269     return psite(this->center().site_set(), iter_);
00270   }
00271 
00272   template <typename I, typename G, typename N>
00273   inline
00274   const typename N::complex_fwd_iter&
00275   complex_neighborhood_fwd_piter<I, G, N>::iter() const
00276   {
00277     return iter_;
00278   }
00279 
00280   template <typename I, typename G, typename N>
00281   inline
00282   typename N::complex_fwd_iter&
00283   complex_neighborhood_fwd_piter<I, G, N>::iter()
00284   {
00285     return iter_;
00286   }
00287 
00288 
00289   template <typename I, typename G, typename N>
00290   inline
00291   std::ostream&
00292   operator<<(std::ostream& ostr,
00293              const complex_neighborhood_fwd_piter<I, G, N>& p)
00294   {
00295     return ostr << p.unproxy_();
00296   }
00297 
00298 
00299   /*------------------------------------------.
00300   | complex_neighborhood_bkd_piter<I, G, N>.  |
00301   `------------------------------------------*/
00302 
00303   template <typename I, typename G, typename N>
00304   inline
00305   complex_neighborhood_bkd_piter<I, G, N>::complex_neighborhood_bkd_piter()
00306   {
00307   }
00308 
00309   template <typename I, typename G, typename N>
00310   template <typename Pref>
00311   inline
00312   complex_neighborhood_bkd_piter<I, G, N>::complex_neighborhood_bkd_piter(const Neighborhood<N>& nbh,
00313                                                                           const Pref& p_ref)
00314   {
00315     init_(nbh, p_ref);
00316   }
00317 
00318   template <typename I, typename G, typename N>
00319   template <typename Pref>
00320   inline
00321   void
00322   complex_neighborhood_bkd_piter<I, G, N>::init_(const Neighborhood<N>& nbh,
00323                                                  const Pref& p_ref)
00324   {
00325     this->change_target(exact(nbh));
00326     this->center_at(p_ref);
00327     mln_postcondition(!this->is_valid());
00328   }
00329 
00330   template <typename I, typename G, typename N>
00331   inline
00332   bool
00333   complex_neighborhood_bkd_piter<I, G, N>::is_valid_() const
00334   {
00335     return iter_.is_valid();
00336   }
00337 
00338   template <typename I, typename G, typename N>
00339   inline
00340   void
00341   complex_neighborhood_bkd_piter<I, G, N>::invalidate_()
00342   {
00343     iter_.invalidate();
00344   }
00345 
00346   template <typename I, typename G, typename N>
00347   inline
00348   void
00349   complex_neighborhood_bkd_piter<I, G, N>::do_start_()
00350   {
00351     iter_.start();
00352   }
00353 
00354   template <typename I, typename G, typename N>
00355   inline
00356   void
00357   complex_neighborhood_bkd_piter<I, G, N>::do_next_()
00358   {
00359     iter_.next();
00360   }
00361 
00362   template <typename I, typename G, typename N>
00363   template <typename Pref>
00364   inline
00365   void
00366   complex_neighborhood_bkd_piter<I, G, N>::center_at_(const Pref&)
00367   {
00368     iter_.center_at(this->center().face());
00369   }
00370 
00371   template <typename I, typename G, typename N>
00372   inline
00373   mln_psite(N)
00374   complex_neighborhood_bkd_piter<I, G, N>::compute_p_() const
00375   {
00376     return psite(this->center().site_set(), iter_);
00377   }
00378 
00379   template <typename I, typename G, typename N>
00380   inline
00381   const typename N::complex_bkd_iter&
00382   complex_neighborhood_bkd_piter<I, G, N>::iter() const
00383   {
00384     return iter_;
00385   }
00386 
00387   template <typename I, typename G, typename N>
00388   inline
00389   typename N::complex_bkd_iter&
00390   complex_neighborhood_bkd_piter<I, G, N>::iter()
00391   {
00392     return iter_;
00393   }
00394 
00395 
00396   template <typename I, typename G, typename N>
00397   inline
00398   std::ostream&
00399   operator<<(std::ostream& ostr,
00400              const complex_neighborhood_bkd_piter<I, G, N>& p)
00401   {
00402     return ostr << p.unproxy_();
00403   }
00404 
00405 # endif // ! MLN_INCLUDE_ONLY
00406 
00407 } // end of namespace mln
00408 
00409 #endif // ! MLN_CORE_IMAGE_COMPLEX_NEIGHBORHOOD_PITER_HH

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