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