Image Component Library (ICL)
MatrixSubRectIterator.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLMath/src/ICLMath/MatrixSubRectIterator.h **
10 ** Module : ICLMath **
11 ** Authors: Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 #include <iterator>
35 
36 namespace icl{
37  namespace math{
39 
69  template <typename Type>
70  class MatrixSubRectIterator : public std::iterator<std::forward_iterator_tag, Type>{
71  protected:
72  inline void init () {
75  if (m_subRectWidth > 0){
77  }
79  }
80 
81  public:
82 
83  static inline const MatrixSubRectIterator<Type> create_end_iterator(const Type *dataOrigin, int matrixWidth, int subRectX,
84  int subRectY, int subRectWidth, int subRectHeight){
85  MatrixSubRectIterator<Type> i(const_cast<Type*>(dataOrigin),matrixWidth,subRectX, subRectY, subRectWidth,subRectHeight);
86  i.m_dataCurr = i.m_dataEnd - subRectWidth + matrixWidth;
87  i.m_currLineEnd = i.m_dataCurr + subRectWidth;
88  return i;
89  }
90 
92  inline MatrixSubRectIterator():
95  m_dataOrigin(0), m_dataCurr(0) {init();}
96 
105  inline MatrixSubRectIterator(Type *ptData,int matrixWidth,int subRectX, int subRectY, int subRectWidth, int subRectHeight):
106  m_matrixWidth(matrixWidth),m_subRectWidth(subRectWidth),m_subRectHeight(subRectHeight),
107  m_dataOrigin(ptData),m_dataCurr(ptData+subRectX+subRectY*matrixWidth) {init();}
108 
113  m_lineStep = other.m_lineStep;
114  m_dataOrigin = other.m_dataOrigin;
115  m_dataCurr = other.m_dataCurr;
116  m_dataEnd = other.m_dataEnd;
118  return *this;
119  }
120 
121  inline const MatrixSubRectIterator& operator=(const MatrixSubRectIterator &other) const{
122  return (*const_cast<MatrixSubRectIterator*>(this)).assign(other);
123  }
124 
126 
129  inline const Type &operator*() const { return *m_dataCurr; }
130 
132 
135  inline Type &operator*(){ return *m_dataCurr; }
136 
138 
168  }else{
169  m_dataCurr++;
170  }
171  return *this;
172  }
173 
175  inline const MatrixSubRectIterator& operator++() const{
176  return ++(*const_cast<MatrixSubRectIterator*>(this));
177  }
178 
185  MatrixSubRectIterator current (*this);
186  ++(*this); // call prefix operator
187  return current; // return previous
188  }
189 
191  inline const MatrixSubRectIterator operator++(int) const{
192  return (*const_cast<MatrixSubRectIterator*>(this))++;
193  }
194 
195 
197 
201  inline bool inSubRect() const{
202  return m_dataCurr < m_dataEnd;
203  }
204 
205 
206 
208  inline bool operator!=(const MatrixSubRectIterator<Type> &it) const{
209  return m_dataCurr != it.m_dataCurr;
210  }
212  inline bool operator==(const MatrixSubRectIterator<Type> &it) const{
213  return m_dataCurr == it.m_dataCurr;
214  }
216  inline bool operator<(const MatrixSubRectIterator<Type> &it) const{
217  return m_dataCurr < it.m_dataCurr;
218  }
220  inline bool operator>(const MatrixSubRectIterator<Type> &it) const{
221  return m_dataCurr > it.m_dataCurr;
222  }
224  inline bool operator<=(const MatrixSubRectIterator<Type> &it) const{
225  return m_dataCurr <= it.m_dataCurr;
226  }
228  inline bool operator>=(const MatrixSubRectIterator<Type> &it) const{
229  return m_dataCurr >= it.m_dataCurr;
230  }
231 
232 
234 
236  inline int getSubRectWidth() const{
237  return m_subRectWidth;
238  }
239 
240  inline int getSubRectHeight() const{
241  return m_subRectHeight;
242  }
243 
245 
249  inline void incRow(int numLines=1) const {
250  m_dataCurr += numLines * m_matrixWidth;
251  m_currLineEnd += numLines * m_matrixWidth;
252  }
253 
255 
256  inline int x(){
258  }
259 
261 
262  inline int y(){
264  }
265 
266  protected:
269 
272 
275 
278 
280  mutable Type *m_dataCurr;
281 
283  Type *m_dataEnd;
284 
286  mutable Type *m_currLineEnd;
287 
288  };
289  } // namespace math
290 }
const Type & operator *() const
retuns a reference of the current pixel value (const)
Definition: MatrixSubRectIterator.h:129
MatrixSubRectIterator()
Default Constructor.
Definition: MatrixSubRectIterator.h:93
undocument this line if you encounter any issues!
Definition: Any.h:37
int y()
returns the current y position of the iterator (wrt matrix origin)
Definition: MatrixSubRectIterator.h:262
int m_matrixWidth
corresponding matrix width
Definition: MatrixSubRectIterator.h:268
bool operator<=(const MatrixSubRectIterator< Type > &it) const
compare two iterators
Definition: MatrixSubRectIterator.h:224
bool operator<(const MatrixSubRectIterator< Type > &it) const
compare two iterators
Definition: MatrixSubRectIterator.h:216
const MatrixSubRectIterator operator++(int) const
const version of post increment operator
Definition: MatrixSubRectIterator.h:191
Type * m_dataCurr
pointer to the current data element
Definition: MatrixSubRectIterator.h:280
int m_subRectHeight
Definition: MatrixSubRectIterator.h:271
Type * m_dataOrigin
pointer to the upper matrix data origin (upper left element)
Definition: MatrixSubRectIterator.h:277
void init()
Definition: MatrixSubRectIterator.h:72
static const MatrixSubRectIterator< Type > create_end_iterator(const Type *dataOrigin, int matrixWidth, int subRectX, int subRectY, int subRectWidth, int subRectHeight)
Definition: MatrixSubRectIterator.h:83
Type * m_currLineEnd
pointer to the first invalid element of the current line
Definition: MatrixSubRectIterator.h:286
bool operator!=(const MatrixSubRectIterator< Type > &it) const
compare two iterators
Definition: MatrixSubRectIterator.h:208
const MatrixSubRectIterator & operator++() const
const version of pre increment operator
Definition: MatrixSubRectIterator.h:175
int m_subRectWidth
sub rect size of the iterator
Definition: MatrixSubRectIterator.h:271
Type * m_dataEnd
pointer to the first element behind the subrect
Definition: MatrixSubRectIterator.h:283
bool operator>(const MatrixSubRectIterator< Type > &it) const
compare two iterators
Definition: MatrixSubRectIterator.h:220
const MatrixSubRectIterator & operator=(const MatrixSubRectIterator &other) const
Definition: MatrixSubRectIterator.h:121
int x()
returns the current x position of the iterator (wrt matrix origin);
Definition: MatrixSubRectIterator.h:256
Iterator class used to iterate through a sub rect of 2D data.
Definition: MatrixSubRectIterator.h:70
#define ICL_UNLIKELY(expr)
Definition: Macros.h:163
int getSubRectWidth() const
returns the length of each row processed by this iterator
Definition: MatrixSubRectIterator.h:236
MatrixSubRectIterator(Type *ptData, int matrixWidth, int subRectX, int subRectY, int subRectWidth, int subRectHeight)
Definition: MatrixSubRectIterator.h:105
void incRow(int numLines=1) const
move the pixel vertically forward
Definition: MatrixSubRectIterator.h:249
MatrixSubRectIterator & operator++()
moves to the next iterator position (Prefix ++it)
Definition: MatrixSubRectIterator.h:164
MatrixSubRectIterator & assign(const MatrixSubRectIterator &other)
Definition: MatrixSubRectIterator.h:109
int m_lineStep
result of m_matrixWidth - m_subRectWidth
Definition: MatrixSubRectIterator.h:274
bool inSubRect() const
to check if iterator is still inside the ROI
Definition: MatrixSubRectIterator.h:201
int getSubRectHeight() const
Definition: MatrixSubRectIterator.h:240
bool operator==(const MatrixSubRectIterator< Type > &it) const
compare two iterators
Definition: MatrixSubRectIterator.h:212
bool operator>=(const MatrixSubRectIterator< Type > &it) const
compare two iterators
Definition: MatrixSubRectIterator.h:228
MatrixSubRectIterator operator++(int)
Definition: MatrixSubRectIterator.h:184