aimstil  5.0.5
ImageCPTLinearIterator.h
Go to the documentation of this file.
1 #ifndef TIL_IMAGERLELINEARITERATOR_H
2 #define TIL_IMAGERLELINEARITERATOR_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 template < typename T >
25 class LinearIterator<ImageRLE<T> > : public ImageIterator_label
26 {
27 public: // predeclarations
28 
29  class VirtualVoxel;
30 
31 public: // typedefs
32 
33  typedef T value_type;
35  typedef VirtualVoxel & reference;
36 
37 public: // constructors & destructor
38 
39  //LinearIterator<ImageRLE<T> >() { this->init(); }
40  LinearIterator<ImageRLE<T> >(ImageRLE<T> &im) : m_im(im) { this->init(); }
41  virtual ~LinearIterator<ImageRLE<T> >() {};
42 
43 public: // initialization
44 
45  // Initialize the iterator
46  void init();
47  //void init(ImageRLE<T> &im);
48 
49 public: // classes
50 
51  friend class VirtualVoxel;
52 
53  class VirtualVoxel
54  {
55  public: // friends
56  friend class LinearIterator<ImageRLE<T> >;
57  public:
58  VirtualVoxel() : m_it() {};
59  //VirtualVoxel(LinearIterator<ImageRLE<T> > &it) : m_it(it) {}
60  void operator=(const T &value)
61  {
62  if (value != m_it->getValue())
63  {
64  m_it->setUnsafeValue(value);
65  }
66  }
67 
68  template < typename X >
69  void operator*=(const X & value)
70  {
71  m_it->setUnsafeValue(m_it->getValue() * value);
72  }
73 
74  operator T () { return m_it->getValue(); }
75 
76  private: // set & get
77  void set(LinearIterator<ImageRLE<T> > *it) { m_it = it; }
78  private: // data
80  };
81 
82 public: // functions
83 
84  bool isAtEnd() { return m_isAtEnd; }
85 
86  const T & getValue() const { return m_iRepValue->getValue(); } //{ return m_value.getValue(); }
87 
88  void setUnsafeValue(T value)
89  {
90  m_im.setUnsafeValue(value, *m_iLine, m_iRepValue, m_count);
91  }
92 
93 
94  //m_VirtualVoxel operator*() { return m_VirtualVoxel(*this); }
95  VirtualVoxel & operator*() { return m_virtualVoxel; }
96 
97  //T& operator* () { return m_value.value; }
98 
99  void operator++()
100  {
101  // Check whether value has been changed
102  /*
103  if (m_savedValue != m_value.value)
104  {
105  // If so, insert new value
106  m_im._setUnsafeValue(m_value.value, *m_iLine, m_iRepValue, m_value.repeat);
107  m_savedValue = m_value.value = (*m_iRepValue).value;
108  }
109  */
110  --m_count;
111 
112  // Check whether there are no more pixels remaining
113  if (m_count == 0)
114  {
115  // go to next pixel on the line
116  ++m_iRepValue;
117 
118  // Check whether there are indeed any pixel remaining
119  if (m_iRepValue == m_iLine->end())
120  {
121  // If not, go to next line
122  ++m_iLine;
123 
124  // Check whether there are indeed any line remaining
125  if (m_iLine == m_im.m_data.end())
126  {
127  m_isAtEnd = true;
128  return;
129  }
130  m_iRepValue = m_iLine->begin();
131  }
132  m_count = m_iRepValue->getRepeat();
133  //m_value = *m_iRepValue;
134  //m_savedValue = m_value.value;
135  }
136  }
137 
138 
139 private: // typedefs
140 
141  typedef typename ImageRLE<T>::Line Line;
142  typedef typename ImageRLE<T>::Data Data;
143 
144 private: // functions
145 
146 
147 private: // data
148 
149  // The current stack of point
150  //typename TImage::RepeatedValue m_value;
151 
152  // The current image
153  TImage & m_im;
154 
155  // the current slice
156  int m_lineIndex;
157 
158  // indexes of current processed point
159  typename Line::iterator m_iRepValue;
160  typename Data::iterator m_iLine;
161  // This is a countdown of the number of voxels remaining in the current RepeatedValue.
162  int m_count;
163 
164  // Flag to indicate whether we already scanned the entire image
165  bool m_isAtEnd;
166 
167  // The value we are currently pointing at
168  //T m_savedValue;
169 
170  // We allocate a virtual voxel so that we don't have to create one every time operator*
171  // is called
172  VirtualVoxel m_virtualVoxel;
173 };
174 
175 
176 
177 
178 
179 
180 
181 
182 
183 
184 
185 
186 
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 
197 
198 
199 
200 
201 
202 
203 
204 
205 
206 
207 
209 //
210 // CODE
211 //
213 
214 
215 template < typename T >
217 {
218  /*
219  if (!isAllocated(im))
220  {
221  m_lineIndex = 0;
222  m_isAtEnd = true;
223  return;
224  }
225  */
226 
227  m_lineIndex = 0;
228  m_iLine = m_im.m_data.begin();
229  m_iRepValue = m_iLine->begin();
230  m_count = m_iRepValue->getRepeat();
231  //m_value = *m_iRepValue;
232  m_isAtEnd = false;
233  //m_savedValue = m_value.getValue();
234  m_virtualVoxel.set(this);
235 }
236 
237 } // namespace
238 
239 
240 #endif
241 
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.