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

pixel_iterator_base.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_INTERNAL_PIXEL_ITERATOR_BASE_HH
00027 # define MLN_CORE_INTERNAL_PIXEL_ITERATOR_BASE_HH
00028 
00032 
00033 # include <mln/core/concept/pixel_iterator.hh>
00034 # include <mln/core/internal/pixel_impl.hh>
00035 # include <mln/core/trait/qlf_value.hh>
00036 
00037 
00038 namespace mln
00039 {
00040 
00041   namespace internal
00042   {
00043 
00044     /*---------------------------------------.
00045     | internal::pixel_iterator_base_<I, E>.  |
00046     `---------------------------------------*/
00047 
00049     template <typename I, typename E>
00050     class pixel_iterator_base_ : public Pixel_Iterator<E>,
00051                                  public internal::pixel_impl_<I, E>
00052     {
00053       typedef internal::pixel_impl_<I, E> super_;
00054 
00055     protected:
00057       pixel_iterator_base_(I& image);
00058 
00059     protected:
00060 
00062       mln_qlf_value(I)* boi_;
00063 
00065       mln_qlf_value(I)* eoi_;
00066 
00068       void start_();
00069     };
00070 
00071 
00072     /*-----------------------------------------------.
00073     | internal::forward_pixel_iterator_base_<I, E>.  |
00074     `-----------------------------------------------*/
00075 
00077     template <typename I, typename E>
00078     class forward_pixel_iterator_base_ : public pixel_iterator_base_<I, E>
00079     {
00080       typedef pixel_iterator_base_<I, E> super_;
00081 
00082     public:
00083 
00087       void start();
00089       void invalidate();
00091       bool is_valid() const;
00093 
00094     protected:
00095 
00097       forward_pixel_iterator_base_(I& image);
00098     };
00099 
00100 
00101     /*------------------------------------------------.
00102     | internal::backward_pixel_iterator_base_<I, E>.  |
00103     `------------------------------------------------*/
00104 
00106     template <typename I, typename E>
00107     class backward_pixel_iterator_base_ : public pixel_iterator_base_<I, E>
00108     {
00109       typedef pixel_iterator_base_<I, E> super_;
00110 
00111     public:
00115       void start();
00117       void invalidate();
00119       bool is_valid() const;
00121 
00122     protected:
00123 
00125       backward_pixel_iterator_base_(I& image);
00126     };
00127 
00128 
00129 
00130 #ifndef MLN_INCLUDE_ONLY
00131 
00132 
00133     /*---------------------------------------.
00134     | internal::pixel_iterator_base_<I, E>.  |
00135     `---------------------------------------*/
00136 
00137     template <typename I, typename E>
00138     inline
00139     pixel_iterator_base_<I, E>::pixel_iterator_base_(I& image)
00140       : super_(image)
00141     {
00142       mln_precondition(image.is_valid());
00143       I& ima = this->image_;
00144       boi_ = & ima( ima.domain().pmin() ) - 1;
00145       eoi_ = & ima( ima.domain().pmax() ) + 1;
00146       exact(*this).invalidate();
00147     }
00148 
00149     template <typename I, typename E>
00150     inline
00151     void
00152     pixel_iterator_base_<I, E>::start_()
00153     {
00154       // Default impl is no-op.
00155     }
00156 
00157 
00158     /*-----------------------------------------------.
00159     | internal::forward_pixel_iterator_base_<I, E>.  |
00160     `-----------------------------------------------*/
00161 
00162     template <typename I, typename E>
00163     inline
00164     forward_pixel_iterator_base_<I, E>::forward_pixel_iterator_base_(I& image)
00165       : super_(image)
00166     {
00167     }
00168 
00169     template <typename I, typename E>
00170     inline
00171     void
00172     forward_pixel_iterator_base_<I, E>::start()
00173     {
00174       this->value_ptr_ = this->boi_ + 1;
00175       exact(this)->start_();
00176     }
00177 
00178     template <typename I, typename E>
00179     inline
00180     void
00181     forward_pixel_iterator_base_<I, E>::invalidate()
00182     {
00183       this->value_ptr_ = this->eoi_;
00184     }
00185 
00186     template <typename I, typename E>
00187     inline
00188     bool
00189     forward_pixel_iterator_base_<I, E>::is_valid() const
00190     {
00191       return this->value_ptr_ != this->eoi_;
00192     }
00193 
00194 
00195     /*------------------------------------------------.
00196     | internal::backward_pixel_iterator_base_<I, E>.  |
00197     `------------------------------------------------*/
00198 
00199     template <typename I, typename E>
00200     inline
00201     backward_pixel_iterator_base_<I, E>::backward_pixel_iterator_base_(I& image)
00202       : super_(image)
00203     {
00204     }
00205 
00206     template <typename I, typename E>
00207     inline
00208     void
00209     backward_pixel_iterator_base_<I, E>::start()
00210     {
00211       this->value_ptr_ = this->eoi_ - 1;
00212       exact(this)->start_();
00213     }
00214 
00215     template <typename I, typename E>
00216     inline
00217     void
00218     backward_pixel_iterator_base_<I, E>::invalidate()
00219     {
00220       this->value_ptr_ = this->boi_;
00221     }
00222 
00223     template <typename I, typename E>
00224     inline
00225     bool
00226     backward_pixel_iterator_base_<I, E>::is_valid() const
00227     {
00228       return this->value_ptr_ != this->boi_;
00229     }
00230 
00231 #endif // ! MLN_INCLUDE_ONLY
00232 
00233   } // end of namespace internal
00234 
00235 } // end of namespace mln
00236 
00237 
00238 #endif // ! MLN_CORE_INTERNAL_PIXEL_ITERATOR_BASE_HH

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