aimstil  5.0.5
ConstImageNCLinearIterator.h
Go to the documentation of this file.
1 #ifndef TIL_CONSTIMAGENCLINEARITERATOR_H
2 #define TIL_CONSTIMAGENCLINEARITERATOR_H
3 
4 // includes from TIL library
5 #include "til/til_common.h"
6 #include "til/imageIterator.h"
7 #include "til/labels.h"
8 
9 // Namespace
10 namespace til
11 {
12 
13 
14 // Predeclaration
15 template < typename T > class ImageNC;
16 
17 
18 // A class to iterate through all values of an image without having to
19 // know the current position (hence the fastest possible)
20 // Allows to read but not to write to image
21 template < typename T >
22 //class ConstImageNCLinearIterator : public ImageIterator_label
23 class ConstLinearIterator<ImageNC<T> > : public ImageIterator_label
24 {
25 
26 public: // typedefs
27 
28  typedef T value_type;
29  typedef const T & reference;
30  typedef ImageNC<T> TImage;
32  //typedef T StarType;
33 
34 public: // constructors & destructor
35 
36  //ConstLinearIterator<ImageNC<T> >(){ this->init(); }
37  ConstLinearIterator<ImageNC<T> >(const ImageNC<T> &im) : m_im(const_cast<ImageNC<T>&>(im)) { this->init(); }
39 
40 
41 public: // initialization
42 
43  void init();
44  //void init(const ImageNC<T> &im);
45 
46 
47 public: // functions
48 
49  void operator++()
50  {
51  // Check whether current slice is done
52  if (--m_nPixelsLeft == 0)
53  {
54  // We are done: go to next slice
55  ++m_sliceIndex;
56 
57  // Check whether all slices are already done
58  if (m_sliceIndex == m_im.dim()[2])
59  {
60  // Yes: stop
61  m_index = 0;
62  return;
63  }
64  else
65  {
66  // No: initialize variables for the current slice
67  this->initForSlice(m_sliceIndex);
68  }
69  }
70  else
71  {
72  // We are still in the current slice
73  // simply increment the pointer
74  ++m_index;
75  }
76  }
77 
78  bool isAtEnd() const { return (m_index == 0); }
79  reference operator*() const { return *m_index; }
80 
81 protected: // functions
82 
83  T * getIndex() { return m_index; }
84 
85 private: // functions
86 
87  void initForSlice(int i)
88  {
89  m_nPixelsLeft = m_sliceSize;
90  m_index = const_cast<T*>(m_im.getSlicePointer(i));
91  }
92 
93 
94 protected: // data
95 
96  // Pointer to current element
97  T* m_index;
98 
99 
100 private: // data
101 
102  // The current image
103  ImageNC<T> & m_im;
104 
105  // the number of pixels per slice
106  int m_sliceSize;
107 
108  // the number of pixels that still haven't been run into
109  // in the current slice
110  int m_nPixelsLeft;
111 
112  // the current slice
113  int m_sliceIndex;
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 
144 
145 
146 
147 
148 
150 //
151 // CODE
152 //
154 
155 
156 template < typename T >
158 {
159 /*
160  if (!isAllocated(im))
161  {
162  m_index = 0;
163  m_nPixelsLeft = 0;
164  m_sliceSize = 0;
165  m_sliceIndex = 0;
166  return;
167  }*/
168 
169  m_sliceSize = m_im.getSliceSize();
170 
171  // Start at slice 0
172  m_sliceIndex = 0;
173  this->initForSlice(m_sliceIndex);
174 }
175 
176 } // namespace
177 
178 #endif
179 
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.
Image class storing data slice-by-slice.