47 #ifndef _MIRA_IMGITERATOR_H_ 48 #define _MIRA_IMGITERATOR_H_ 50 #include <opencv2/core/core.hpp> 80 if(
m &&
m->isContinuous() )
93 if(
m->isContinuous() )
98 ptrdiff_t ofs = iRow*
m->step + iCol;
108 ptrdiff_t ofsb = ofs *
m->elemSize();
120 return (*
this += -ofs);
127 ptr +=
m->elemSize();
137 ptr -=
m->elemSize();
148 ptrdiff_t ofs =
ptr -
m->data;
149 int y = (int)(ofs/
step(
m));
153 ptrdiff_t
lpos()
const;
155 void seek(ptrdiff_t ofs,
bool relative=
false);
165 return m->rows*
m->cols;
178 std::size_t elemSize =
m->elemSize();
181 if (elemSize == 0 ||
m->total() == 0)
184 if(
m->isContinuous() )
198 ofs0 =
ptr -
m->data;
200 ofs += y*
m->cols + (ofs0 - y*
step(
m))/elemSize;
203 int y1 = std::min(std::max((
int)y, 0),
m->rows-1);
215 std::size_t elemSize =
m->elemSize();
216 if(
m->isContinuous() )
218 ptrdiff_t ofs =
ptr -
m->data;
221 ptrdiff_t y = ofs/
step(
m);
222 return y*
m->cols + (ofs - y*
step(
m))/elemSize;
226 {
return a.
m == b.
m && a.
ptr == b.
ptr; }
229 {
return !(a == b); }
238 {
return a.
ptr <= b.
ptr; }
241 {
return a.
ptr >= b.
ptr; }
245 #define MIRA_GENERATE_IMG_ITERATOR_OPS(IteratorType) \ 247 IteratorType& operator+= (int ofs) { \ 248 Base::operator+= (ofs); \ 252 IteratorType& operator-= (int ofs) { \ 253 Base::operator += (-ofs); \ 257 IteratorType& operator--() { \ 258 Base::operator--(); \ 262 IteratorType operator--(int){ \ 263 IteratorType b = *this; \ 264 Base::operator--(); \ 268 IteratorType& operator++(){ \ 269 Base::operator++(); \ 273 IteratorType operator++(int){ \ 274 IteratorType b = *this; \ 275 Base::operator++(); \ 355 template <
typename T>
356 const T&
at(std::size_t i)
const {
357 return *((T*)
this + i);
360 template <
typename T>
361 T&
at(std::size_t i) {
362 return *((T*)
this + i);
T * operator->()
Dereferences to the Pixel.
Definition: ImgIterator.h:343
Untyped image iterator, that allows to iterate over images or image regions pixel by pixel similar to...
Definition: ImgIterator.h:415
ImgIteratorBase & operator--()
move backward one element
Definition: ImgIterator.h:124
bool operator<=(const ImgIteratorBase &a, const ImgIteratorBase &b)
Definition: ImgIterator.h:237
Point2i pos() const
returns the current iterator position
Definition: ImgIterator.h:144
ptrdiff_t lpos() const
Definition: ImgIterator.h:210
ImgConstIterator()
Definition: ImgIterator.h:301
T * pointer
Definition: ImgIterator.h:329
bool operator<(const ImgIteratorBase &a, const ImgIteratorBase &b)
Definition: ImgIterator.h:231
UntypedImgIteratorValue & reference
Definition: ImgIterator.h:421
General point class template.
Definition: Point.h:135
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
UntypedImgConstIterator(const cv::Mat *m)
Definition: ImgIterator.h:388
void seek(ptrdiff_t ofs, bool relative=false)
Definition: ImgIterator.h:175
Class for 2D, 3D and N-dimensional points.
Point< int, 2 > Point2i
a 2D integer point
Definition: Point.h:229
UntypedImgIteratorValue * pointer
Definition: ImgIterator.h:420
ImgConstIterator(const cv::Mat_< T > *m)
Definition: ImgIterator.h:302
const uchar * sliceStart
Definition: ImgIterator.h:159
UntypedImgIterator(cv::Mat *m)
Definition: ImgIterator.h:426
bool operator>(const ImgIteratorBase &a, const ImgIteratorBase &b)
Definition: ImgIterator.h:234
const value_type * getValue() const
Definition: ImgIterator.h:402
const T * operator->() const
Dereferences to the Pixel.
Definition: ImgIterator.h:310
static std::size_t total(const cv::Mat *m)
Definition: ImgIterator.h:164
std::bidirectional_iterator_tag iterator_category
Definition: ImgIterator.h:383
const T * pointer
Definition: ImgIterator.h:295
const UntypedImgIteratorValue * pointer
Definition: ImgIterator.h:381
ImgIteratorBase(const cv::Mat *iMat)
Definition: ImgIterator.h:77
ImgIteratorBase & operator-=(ptrdiff_t ofs)
shifts the iterator backward by the specified number of elements
Definition: ImgIterator.h:119
Definition: ImgIterator.h:71
static std::size_t step(const cv::Mat *m)
Definition: ImgIterator.h:168
int difference_type
Definition: ImgIterator.h:293
pointer operator->() const
Definition: ImgIterator.h:393
const cv::Mat * m
Definition: ImgIterator.h:157
reference operator*()
Dereferences to the Pixel.
Definition: ImgIterator.h:431
UntypedImgIterator()
Definition: ImgIterator.h:425
ImgIterator(cv::Mat_< T > *m)
Definition: ImgIterator.h:335
bool operator==(const ImgIteratorBase &a, const ImgIteratorBase &b)
Definition: ImgIterator.h:225
Const image iterator that allows to iterate over images or image regions pixel by pixel similar to it...
Definition: ImgIterator.h:287
std::bidirectional_iterator_tag iterator_category
Definition: ImgIterator.h:297
pointer operator->()
Dereferences to the Pixel.
Definition: ImgIterator.h:434
ImgIteratorBase & operator+=(ptrdiff_t ofs)
shifts the iterator forward by the specified number of elements
Definition: ImgIterator.h:105
UntypedImgIteratorValue value_type
Definition: ImgIterator.h:378
bool operator>=(const ImgIteratorBase &a, const ImgIteratorBase &b)
Definition: ImgIterator.h:240
ImgIteratorBase & operator++()
move forward one element
Definition: ImgIterator.h:134
ImgIteratorBase()
Definition: ImgIterator.h:75
reference operator*() const
Definition: ImgIterator.h:392
const T & reference
Definition: ImgIterator.h:296
UntypedImgConstIterator()
Definition: ImgIterator.h:387
ImgIteratorBase(const cv::Mat *iMat, int iRow, int iCol=0)
Definition: ImgIterator.h:88
Untyped const image iterator, that allows to iterate over images or image regions pixel by pixel simi...
Definition: ImgIterator.h:374
const UntypedImgIteratorValue & reference
Definition: ImgIterator.h:382
const T & operator*() const
Dereferences to the Pixel.
Definition: ImgIterator.h:307
bool operator!=(const ImgIteratorBase &a, const ImgIteratorBase &b)
Definition: ImgIterator.h:228
const uchar * sliceEnd
Definition: ImgIterator.h:160
Definition: ImgIterator.h:351
#define MIRA_GENERATE_IMG_ITERATOR_OPS(IteratorType)
Definition: ImgIterator.h:245
T value_type
Definition: ImgIterator.h:292
const T & at(std::size_t i) const
Definition: ImgIterator.h:356
ImgIterator()
Definition: ImgIterator.h:334
value_type * getValue()
Definition: ImgIterator.h:401
T & reference
Definition: ImgIterator.h:330
int difference_type
Definition: ImgIterator.h:379
T & operator*()
Dereferences to the Pixel.
Definition: ImgIterator.h:340
T & at(std::size_t i)
Definition: ImgIterator.h:361
Image iterator that allows to iterate over images or image regions pixel by pixel similar to iterator...
Definition: ImgIterator.h:324
const uchar * ptr
Definition: ImgIterator.h:158