Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
box_runend_piter.hh
1 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_CORE_BOX_RUNEND_PITER_HH
27 # define MLN_CORE_BOX_RUNEND_PITER_HH
28 
32 
33 # include <mln/core/internal/site_iterator_base.hh>
34 # include <mln/core/site_set/box.hh>
35 
36 
37 #define mln_box_runend_piter(I) typename mln::box_runend_piter<mln_psite(I)>
38 #define mln_box_runend_piter_(I) mln::box_runend_piter<mln_psite_(I)>
39 
40 
41 namespace mln
42 {
43 
48  template <typename P>
50  public internal::site_set_iterator_base< box<P>,
51  box_runend_piter<P> >
52  {
53  typedef box_runend_piter<P> self_;
54  typedef internal::site_set_iterator_base< box<P>, self_ > super_;
55  public:
56 
57  // Make definitions from super class available.
58  enum { dim = super_::dim };
59 
64  box_runend_piter(const box<P>& b);
65 
67  void init_(const box<P>& b);
68 
70 
72  bool is_valid_() const;
73 
75  void invalidate_();
76 
78  void start_();
79 
81  void next_();
82 
84  unsigned run_length() const;
85 
86  private:
87  using super_::p_;
88  using super_::s_;
89  };
90 
91 
92 # ifndef MLN_INCLUDE_ONLY
93 
94 
95  // box_runend_piter<P>
96 
97  template <typename P>
98  inline
100  {
101  }
102 
103  template <typename P>
104  inline
105  box_runend_piter<P>::box_runend_piter(const box<P>& b)
106  {
107  init_(b);
108  }
109 
110  template <typename P>
111  inline
112  void
113  box_runend_piter<P>::init_(const box<P>& b)
114  {
115  this->change_target(b);
116  }
117 
118 
119  template <typename P>
120  inline
121  bool
122  box_runend_piter<P>::is_valid_() const
123  {
124  return p_[0] != static_cast<mln_coord(P)>(s_->pmin()[0] - 1);
125  }
126 
127  template <typename P>
128  inline
129  void
130  box_runend_piter<P>::invalidate_()
131  {
132  p_[0] = static_cast<mln_coord(P)>(s_->pmin()[0] - 1);
133  }
134 
135  template <typename P>
136  inline
137  void
138  box_runend_piter<P>::start_()
139  {
140  p_ = s_->pmax();
141  }
142 
143  template <typename P>
144  inline
145  void
146  box_runend_piter<P>::next_()
147  {
148  // Do we want this run for image in 3d?
149  for (int c = dim - 2; c >= 0; --c)
150  {
151  if (p_[c] != s_->pmin()[c])
152  {
153  --p_[c];
154  break;
155  }
156  else
157  p_[c] = s_->pmax()[c];
158  }
159 
160  if (p_ == s_->pmax())
161  invalidate_();
162  }
163 
164  template <typename P>
165  inline
166  unsigned
168  {
169  return s_->len(dim - 1);
170  }
171 
172 
173 # endif // ! MLN_INCLUDE_ONLY
174 
175 } // end of namespace mln
176 
177 
178 #endif // ! MLN_CORE_BOX_RUNEND_PITER_HH