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

box_runend_piter.hh

00001 // Copyright (C) 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_BOX_RUNEND_PITER_HH
00027 # define MLN_CORE_BOX_RUNEND_PITER_HH
00028 
00032 
00033 # include <mln/core/internal/site_iterator_base.hh>
00034 # include <mln/core/site_set/box.hh>
00035 
00036 
00037 #define mln_box_runend_piter(I)  typename mln::box_runend_piter<mln_psite(I)>
00038 #define mln_box_runend_piter_(I)          mln::box_runend_piter<mln_psite_(I)>
00039 
00040 
00041 namespace mln
00042 {
00043 
00048   template <typename P>
00049   class box_runend_piter :
00050     public internal::site_set_iterator_base< box<P>,
00051                                              box_runend_piter<P> >
00052   {
00053     typedef box_runend_piter<P> self_;
00054     typedef internal::site_set_iterator_base< box<P>, self_ > super_;
00055   public:
00056 
00057     // Make definitions from super class available.
00058     enum { dim = super_::dim };
00059 
00064     box_runend_piter(const box<P>& b);
00065 
00067     void init_(const box<P>& b);
00068 
00069     box_runend_piter();
00070 
00072     bool is_valid_() const;
00073 
00075     void invalidate_();
00076 
00078     void start_();
00079 
00081     void next_();
00082 
00084     unsigned run_length() const;
00085 
00086   private:
00087     using super_::p_;
00088     using super_::s_;
00089   };
00090 
00091 
00092 # ifndef MLN_INCLUDE_ONLY
00093 
00094 
00095   // box_runend_piter<P>
00096 
00097   template <typename P>
00098   inline
00099   box_runend_piter<P>::box_runend_piter()
00100   {
00101   }
00102 
00103   template <typename P>
00104   inline
00105   box_runend_piter<P>::box_runend_piter(const box<P>& b)
00106   {
00107     init_(b);
00108   }
00109 
00110   template <typename P>
00111   inline
00112   void
00113   box_runend_piter<P>::init_(const box<P>& b)
00114   {
00115     this->change_target(b);
00116   }
00117 
00118 
00119   template <typename P>
00120   inline
00121   bool
00122   box_runend_piter<P>::is_valid_() const
00123   {
00124     return p_[0] != static_cast<mln_coord(P)>(s_->pmin()[0] - 1);
00125   }
00126 
00127   template <typename P>
00128   inline
00129   void
00130   box_runend_piter<P>::invalidate_()
00131   {
00132     p_[0] = static_cast<mln_coord(P)>(s_->pmin()[0] - 1);
00133   }
00134 
00135   template <typename P>
00136   inline
00137   void
00138   box_runend_piter<P>::start_()
00139   {
00140     p_ = s_->pmax();
00141   }
00142 
00143   template <typename P>
00144   inline
00145   void
00146   box_runend_piter<P>::next_()
00147   {
00148     // Do we want this run for image in 3d?
00149     for (int c = dim - 2; c >= 0; --c)
00150     {
00151       if (p_[c] != s_->pmin()[c])
00152       {
00153         --p_[c];
00154         break;
00155       }
00156       else
00157         p_[c] = s_->pmax()[c];
00158     }
00159 
00160     if (p_ == s_->pmax())
00161       invalidate_();
00162   }
00163 
00164   template <typename P>
00165   inline
00166   unsigned
00167   box_runend_piter<P>::run_length() const
00168   {
00169     return s_->len(dim - 1);
00170   }
00171 
00172 
00173 # endif // ! MLN_INCLUDE_ONLY
00174 
00175 } // end of namespace mln
00176 
00177 
00178 #endif // ! MLN_CORE_BOX_RUNEND_PITER_HH

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