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

Generated on Thu Sep 8 2011 18:31:42 for Milena (Olena) by  doxygen 1.7.1