Ilwis-Objects  1.0
GIS and Remote Sensing framework for data access and processing
 All Classes Functions Enumerations Pages
pixeliterator.h
1 #ifndef PixelIterator_H
2 #define PixelIterator_H
3 
4 
5 
6 namespace Ilwis {
7 
8 class Tranquilizer;
9 
10 typedef std::shared_ptr<Tranquilizer> SPTranquilizer;
11 
61 class KERNELSHARED_EXPORT PixelIterator : public std::iterator<std::random_access_iterator_tag, double> {
62 public:
67  enum Flow { fXYZ, fYXZ, fXZY, fYZX, fZXY, fZYX};
68 
75  bool isValid() const{
76  return _isValid;
77  }
78 
79 
85  PixelIterator();
86 
97  PixelIterator(const IRasterCoverage& raster, const BoundingBox& box=BoundingBox());
98 
104  PixelIterator(const PixelIterator& iter);
105 
111 
121  PixelIterator& operator=(const PixelIterator& iter);
122 
132  PixelIterator& operator=(const PixelIterator&& iter);
133 
140  move(1);
141  return *this;
142  }
143 
150  move(-1);
151  return *this;
152  }
153 
161  move(n);
162  return *this;
163  }
164 
172  move(-n);
173  return *this;
174  }
175 
184  double& operator[](quint32 index){
185  _x = 0;
186  _y = 0;
187  _z = 0;
188  _yChanged = _xChanged = _zChanged = true;
189  initPosition();
190  move(index);
191  return this->operator *();
192  }
193 
194  QVariant operator()(const QString& column,Coverage::AttributeType attType=Coverage::atCOVERAGE);
195 
206  PixelIterator &operator ()(const Pixel &pix)
207  {
208  _x = pix.x;
209  _y = pix.y;
210  _z = pix.z;
211  _yChanged = _xChanged = _zChanged = true;
212  initPosition();
213  return *this;
214  }
215 
221  PixelIterator operator++(int);
222 
228  PixelIterator operator--(int);
229 
239  return operator ()(pix);
240  }
241 
247  bool operator==(const PixelIterator& iter) const;
248 
254  bool operator!=(const PixelIterator& iter) const;
255 
261  bool operator<(const PixelIterator& iter) const;
262 
268  bool operator<=(const PixelIterator& iter) const;
269 
275  bool operator>(const PixelIterator& iter) const;
276 
282  bool operator>=(const PixelIterator& iter) const;
283 
288  double& operator*() {
289  return _grid->value(_currentBlock, _localOffset );
290  }
291 
296  const double& operator*() const {
297  return _grid->value(_currentBlock, _localOffset);
298  }
299 
304  double* operator->() {
305  return &(_grid->value(_currentBlock, _localOffset ));
306  }
307 
312  PixelIterator end() const ;
313 
326  void setFlow(Flow flw);
327 
334  bool contains(const Pixel& pix) ;
335 
341  bool xchanged() const;
342 
348  bool ychanged() const;
349 
355  bool zchanged() const;
356 
361  bool isAtEnd() const {
362  return _x == _endx &&
363  _y == _endy &&
364  _z == _endz;
365  }
366 
371  Pixel position() const;
372 
378  const BoundingBox& box() const;
379 
384  quint32 linearPosition() const;
385 
393  int operator -(const PixelIterator &iter2);
394 
402  PixelIterator iter(*this);
403  iter.move(n);
404  return iter;
405  }
406 
411  void setTranquilizer(const SPTranquilizer& trq) {
412  _trq = trq;
413  }
414 
415 protected:
416  PixelIterator(quint64 endpos ) :
417  _grid(0),
418  _x(0),
419  _y(0),
420  _z(0),
421  _localOffset(0),
422  _currentBlock(0),
423  _flow(fXYZ),
424  _isValid(true),
425  _endx(0),
426  _endy(0),
427  _endz(0),
428  _linearposition(endpos),
429  _endposition(endpos),
430  _xChanged(false),
431  _yChanged(false),
432  _zChanged(false)
433  {
434  }
435 
436  void init();
437  void initPosition();
438  //bool move(int n);
439  //bool moveXYZ(int delta) ;
440  void copy(const PixelIterator& iter);
441 
442  IRasterCoverage _raster;
443  Grid *_grid = 0;
444  BoundingBox _box;
445  qint32 _x = 0;
446  qint32 _y = 0;
447  qint32 _z = 0;
448  qint32 _localOffset = 0;
449  qint32 _currentBlock = 0;
450  Flow _flow;
451  bool _isValid;
452  qint32 _endx;
453  qint32 _endy;
454  qint32 _endz;
455  quint64 _linearposition;
456  quint64 _endposition;
457  bool _xChanged =false;
458  bool _yChanged = false;
459  bool _zChanged = false;
460  SPTranquilizer _trq;
461 
462 
463  bool move(int n) {
464 
465  bool ok = false;
466  if (isAtEnd()) {
467  _linearposition = _endposition;
468  return false;
469  }
470  if ( _flow == fXYZ) {
471  ok = moveXYZ(n);
472  }
473  else if ( _flow == fYXZ){
474  }
475 
476  return ok;
477  }
478 
479 
480 private:
481  bool moveXYZ(int delta) {
482  _x += delta;
483  _linearposition += delta;
484  _localOffset += delta;
485  _xChanged = true;
486  _yChanged = _zChanged = false;
487 
488  if ( _x > _endx) {
489  return moveYZ(delta);
490  }
491  return true;
492  }
493 
494  bool moveYZ(int delta);
495 };
496 
497 inline Ilwis::PixelIterator begin(const Ilwis::IRasterCoverage& raster) {
498  return PixelIterator(raster);
499 }
500 
501 inline Ilwis::PixelIterator end(const Ilwis::IRasterCoverage& raster) {
502  PixelIterator iter(raster);
503  return iter.end();
504 }
505 
506 }
507 #endif // PixelIterator_H