$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
box_runstart_piter.hh
1 // Copyright (C) 2007, 2008, 2009, 2012 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_RUNSTART_PITER_HH
28 # define MLN_CORE_BOX_RUNSTART_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_runstart_piter(I) typename mln::box_runstart_piter<mln_psite(I)>
39 #define mln_box_runstart_piter_(I) mln::box_runstart_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_runstart_piter<P> >
55  {
58  public:
59 
60  // Make definitions from super class available.
61  enum { dim = super_::dim };
62 
67  box_runstart_piter(const box<P>& b);
68 
71  void init_(const box<P>& b);
73 
75 
76 
78 
80  bool is_valid_() const;
81 
83  void invalidate_();
84 
86  void start_();
87 
89  void next_();
90 
92 
93 
95  unsigned run_length() const;
96 
97  private:
98  using super_::p_;
99  using super_::s_;
100  };
101 
102 
103 # ifndef MLN_INCLUDE_ONLY
104 
105 
106  // box_runstart_piter<P>
107 
108  template <typename P>
109  inline
111  {
112  }
113 
114  template <typename P>
115  inline
117  {
118  init_(b);
119  }
120 
121  template <typename P>
122  inline
123  void
124  box_runstart_piter<P>::init_(const box<P>& b)
125  {
126  this->change_target(b);
127  }
128 
129 
130  template <typename P>
131  inline
132  bool
133  box_runstart_piter<P>::is_valid_() const
134  {
135  return p_[0] != static_cast<mln_coord(P)>(s_->pmax()[0] + 1);
136  }
137 
138  template <typename P>
139  inline
140  void
141  box_runstart_piter<P>::invalidate_()
142  {
143  p_[0] = static_cast<mln_coord(P)>(s_->pmax()[0] + 1);
144  }
145 
146  template <typename P>
147  inline
148  void
149  box_runstart_piter<P>::start_()
150  {
151  p_ = s_->pmin();
152  }
153 
154  template <typename P>
155  inline
156  void
157  box_runstart_piter<P>::next_()
158  {
159  // Do we want this run for image in 3d?
160  /* FIXME: `dim - 2' is probably the wrong (= not generic) way to
161  express the manipulated dimension anyway. */
162  for (int c = dim - 2; c >= 0; --c)
163  {
164  if (p_[c] != s_->pmax()[c])
165  {
166  ++p_[c];
167  break;
168  }
169  else
170  p_[c] = s_->pmin()[c];
171  }
172 
173  if (p_ == s_->pmin())
174  invalidate_();
175  }
176 
177  template <typename P>
178  inline
179  unsigned
181  {
182  return s_->len(dim - 1);
183  }
184 
185 
186 # endif // ! MLN_INCLUDE_ONLY
187 
188 } // end of namespace mln
189 
190 
191 #endif // ! MLN_CORE_BOX_RUNSTART_PITER_HH