aimstil  5.0.5
ConstImageCPTLinearIterator.h
Go to the documentation of this file.
1 #ifndef TIL_CONSTIMAGERLELINEARITERATOR_H
2 #define TIL_CONSTIMAGERLELINEARITERATOR_H
3 
4 // includes from STL
5 #include <list>
6 #include <vector>
7 
8 // includes from TIL library
9 #include "til/til_common.h"
10 #include "til/labels.h"
11 
12 
13 // Namespace
14 namespace til {
15 
16 
17 // Predeclaration
18 template < typename T > class ImageRLE;
19 
20 
21 // A class to iterate through all values of an image without having to
22 // know the current position (hence the fastest possible)
23 // Allows to read but not to write to image
24 
25 
26 template < typename T >
28  : public ImageIterator_label
29 {
30 public: // typedefs
31 
32  typedef T value_type;
34  // Actually, not a reference at all, just the return type of operator*
35  // -- which is assumed to be the same thing in the STD... :/
36  typedef T reference;
37 
38 public: // constructors & destructor
39 
40 // ConstLinearIterator<ImageRLE<T> >() { this->init(); }
41  ConstLinearIterator<ImageRLE<T> >(const ImageRLE<T> &im) : m_im(const_cast<ImageRLE<T>&>(im)) { this->init(); }
43 
44 public: // initialization
45 
46  // Initialize the iterator
47  void init();
48  void init(const ImageRLE<T> &im);
49 
50 public: // functions
51 
52  bool isAtEnd() const { return m_flagIsAtEnd; }
53 
54  reference operator*() const { return m_value.getValue(); }
55 
56  void operator++()
57  {
58  --(m_value.getRepeat());
59 
60  // Check whether there are no more pixels remaining
61  if (m_value.getRepeat() == 0)
62  {
63  // go to next pixel on the line
64  ++m_iList;
65 
66  // Check whether there are any pixel remaining
67  if (m_iList == m_iLine->end())
68  {
69  // If not, go to next line
70  ++m_iLine;
71 
72  // Check whether there are indeed any line remaining
73  if (m_iLine == m_im.m_data.end())
74  {
75  m_flagIsAtEnd = true;
76  return;
77  }
78  m_iList = m_iLine->begin();
79  }
80  m_value = *m_iList;
81  }
82  }
83 
84  const ImageRLE<T> & image() const { return m_im; }
85 
86 private: // typedefs
87 
88  typedef typename ImageRLE<T>::Line Line;
89  typedef typename ImageRLE<T>::Data Data;
90 
91 private: // data
92 
93  // The current stack of point
94  typename ImageRLE<T>::RepeatedValue m_value;
95 
96  // The current image
97  ImageRLE<T> & m_im;
98 
99  // the current slice
100  int m_lineIndex;
101 
102  // indexes of current processed point
103  typename Line::const_iterator m_iList;
104  typename Data::const_iterator m_iLine;
105 
106  //
107 
108  bool m_flagIsAtEnd;
109 };
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123 
124 
125 
126 
127 
128 
129 
130 
131 
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 
145 //
146 // CODE
147 //
149 
150 
151 template < typename T >
153 {
154  /*
155  if (!isAllocated(im))
156  {
157  m_lineIndex = 0;
158  m_flagIsAtEnd = true;
159  return;
160  }
161  */
162 
163  m_lineIndex = 0;
164  m_iLine = m_im.m_data.begin();
165  m_iList = (*m_iLine).begin();
166  m_value = *m_iList;
167  m_flagIsAtEnd = false;
168 }
169 
170 } // namespace
171 
172 
173 #endif
174 
175 
Image class using run-length encoded data.
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
General macros, definitions and functions.
Defines empty classes that serves as labels.