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_BOX_RUNSTART_PITER_HH 00027 # define MLN_CORE_BOX_RUNSTART_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_runstart_piter(I) typename mln::box_runstart_piter<mln_psite(I)> 00038 #define mln_box_runstart_piter_(I) mln::box_runstart_piter<mln_psite(I)> 00039 00040 00041 namespace mln 00042 { 00043 00048 template <typename P> 00049 class box_runstart_piter : 00050 public internal::site_set_iterator_base< box<P>, 00051 box_runstart_piter<P> > 00052 { 00053 typedef box_runstart_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_runstart_piter(const box<P>& b); 00065 00066 box_runstart_piter(); 00067 00069 bool is_valid_() const; 00070 00072 void invalidate_(); 00073 00075 void start_(); 00076 00078 void next_(); 00079 00081 unsigned run_length() const; 00082 00083 private: 00084 using super_::p_; 00085 using super_::s_; 00086 }; 00087 00088 00089 # ifndef MLN_INCLUDE_ONLY 00090 00091 00092 // box_runstart_piter<P> 00093 00094 template <typename P> 00095 inline 00096 box_runstart_piter<P>::box_runstart_piter() 00097 { 00098 } 00099 00100 template <typename P> 00101 inline 00102 box_runstart_piter<P>::box_runstart_piter(const box<P>& b) 00103 { 00104 this->change_target(b); 00105 } 00106 00107 template <typename P> 00108 inline 00109 bool 00110 box_runstart_piter<P>::is_valid_() const 00111 { 00112 return p_[0] != static_cast<mln_coord(P)>(s_->pmax()[0] + 1); 00113 } 00114 00115 template <typename P> 00116 inline 00117 void 00118 box_runstart_piter<P>::invalidate_() 00119 { 00120 p_[0] = static_cast<mln_coord(P)>(s_->pmax()[0] + 1); 00121 } 00122 00123 template <typename P> 00124 inline 00125 void 00126 box_runstart_piter<P>::start_() 00127 { 00128 p_ = s_->pmin(); 00129 } 00130 00131 template <typename P> 00132 inline 00133 void 00134 box_runstart_piter<P>::next_() 00135 { 00136 // Do we want this run for image in 3d? 00137 for (int c = dim - 2; c >= 0; --c) 00138 { 00139 if (p_[c] != s_->pmax()[c]) 00140 { 00141 ++p_[c]; 00142 break; 00143 } 00144 else 00145 p_[c] = s_->pmin()[c]; 00146 } 00147 00148 if (p_ == s_->pmin()) 00149 invalidate_(); 00150 } 00151 00152 template <typename P> 00153 inline 00154 unsigned 00155 box_runstart_piter<P>::run_length() const 00156 { 00157 return s_->len(dim - 1); 00158 } 00159 00160 00161 # endif // ! MLN_INCLUDE_ONLY 00162 00163 } // end of namespace mln 00164 00165 00166 #endif // ! MLN_CORE_BOX_RUNSTART_PITER_HH