Ilwis-Objects  1.0
GIS and Remote Sensing framework for data access and processing
 All Classes Functions Enumerations Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Ilwis::PixelIterator Class Reference

The PixelIterator class an iterator class that iteratos over all the pixels in an grid (or subsection of it) More...

#include <pixeliterator.h>

Inheritance diagram for Ilwis::PixelIterator:
Ilwis::BlockIterator

Public Types

enum  Flow {
  fXYZ, fYXZ, fXZY, fYZX,
  fZXY, fZYX
}
 

Public Member Functions

bool isValid () const
 isValid tells if an iterator is in a valid state. More...
 
 PixelIterator ()
 The empty constructor for PixelIterator. More...
 
 PixelIterator (const IRasterCoverage &raster, const BoundingBox &box=BoundingBox())
 Constructs a PixelIterator from a raster and a bounding box. More...
 
 PixelIterator (const PixelIterator &iter)
 
 PixelIterator (PixelIterator &&iter)
 Copy constructor. More...
 
PixelIteratoroperator= (const PixelIterator &iter)
 
PixelIteratoroperator= (const PixelIterator &&iter)
 
PixelIteratoroperator++ ()
 Adds 1 to this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow. More...
 
PixelIteratoroperator-- ()
 Substracts 1 from this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow. More...
 
PixelIteratoroperator+= (int n)
 Adds n to this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow. More...
 
PixelIteratoroperator-= (int n)
 Substracts n from this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow. More...
 
double & operator[] (quint32 index)
 Random acces operator. More...
 
QVariant operator() (const QString &column, Coverage::AttributeType attType=Coverage::atCOVERAGE)
 
PixelIteratoroperator() (const Pixel &pix)
 Moves the PixelIterator to the given Pixel. More...
 
PixelIterator operator++ (int)
 Adds 1 to this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow. More...
 
PixelIterator operator-- (int)
 Substracts 1 from this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow. More...
 
PixelIteratoroperator[] (const Pixel &pix)
 Random acces operator. More...
 
bool operator== (const PixelIterator &iter) const
 Checks if this PixelIterator has the same linearPosition as another PixelIterator. More...
 
bool operator!= (const PixelIterator &iter) const
 Checks if this PixelIterator has a different linearPosition as another PixelIterator. More...
 
bool operator< (const PixelIterator &iter) const
 Checks if this PixelIterator has a smaller linearPosition as another PixelIterator. More...
 
bool operator<= (const PixelIterator &iter) const
 Checks if this PixelIterator has a smaller or equal linearPosition as another PixelIterator. More...
 
bool operator> (const PixelIterator &iter) const
 Checks if this PixelIterator has a bigger linearPosition as another PixelIterator. More...
 
bool operator>= (const PixelIterator &iter) const
 Checks if this PixelIterator has a bigger or equal linearPosition as another PixelIterator. More...
 
double & operator* ()
 Query for a reference to the current value of the PixelIterator. More...
 
const double & operator* () const
 Query for a reference to the current vallue of the PixelIterator. More...
 
double * operator-> ()
 Query for the current value of the PixelIterator. More...
 
PixelIterator end () const
 Returns the end position of this PixelIterator, this is 1 past the actual lastblock of the boundingbox. More...
 
void setFlow (Flow flw)
 Changes the flow of this PixelIterator. More...
 
bool contains (const Pixel &pix)
 Checks if a certain pixel is inside this PixelIterator. More...
 
bool xchanged () const
 Checks if the x coordinate has changed in the last step taken all movement and/or position change commands automatically set the x y and z flags when appropiate. More...
 
bool ychanged () const
 Checks if the y coordinate has changed in the last step taken all movement and/or position change commands automatically set the x y and z flags when appropiate. More...
 
bool zchanged () const
 Checks if the z coordinate has changed in the last step taken all movement and/or position change commands automatically set the x y and z flags when appropiate. More...
 
bool isAtEnd () const
 Checks if this PixelIterator is at its endpoint. More...
 
Pixel position () const
 Query for the current non lineair position of this PixelIterator. More...
 
const BoundingBoxbox () const
 Query for the bounding box of this PixelIterator the bounding box decides which part of the raster this PixelIterator should walk, thus its size can never be bigger than the rastersize. More...
 
quint32 linearPosition () const
 Query for the linearPosition of this PixelIterator. More...
 
int operator- (const PixelIterator &iter2)
 Substracts another pixeliterator fomr this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow
this might have unexpected results if both iterators have a different flow. More...
 
PixelIterator operator+ (int n)
 Adds n to this PixelIterator and returns it the direction moved in the raster depends on the boundingbox in combination with the flow. More...
 
void setTranquilizer (const SPTranquilizer &trq)
 ProgressMeter. More...
 

Protected Member Functions

 PixelIterator (quint64 endpos)
 
void init ()
 
void initPosition ()
 
void copy (const PixelIterator &iter)
 
bool move (int n)
 

Protected Attributes

IRasterCoverage _raster
 
Grid_grid = 0
 
BoundingBox _box
 
qint32 _x = 0
 
qint32 _y = 0
 
qint32 _z = 0
 
qint32 _localOffset = 0
 
qint32 _currentBlock = 0
 
Flow _flow
 
bool _isValid
 
qint32 _endx
 
qint32 _endy
 
qint32 _endz
 
quint64 _linearposition
 
quint64 _endposition
 
bool _xChanged =false
 
bool _yChanged = false
 
bool _zChanged = false
 
SPTranquilizer _trq
 

Detailed Description

The PixelIterator class an iterator class that iteratos over all the pixels in an grid (or subsection of it)

The pixeliterator is the main access mechanism (together with the blockiterator) to pixels in 2D or 3D gridcoverages. Basically it sees the pixels as one long linear space and moves over it. The movement (flow) can have several directions which resembles directions in the 'real' world. In the default case it moves first over the x dirdction, than the y and finally the z direction. But one could just as well first move in the z direction than x, than y. Internally these movements are translated to offsets in the linear space. The pixel iterator obeys the normal rules for iterators in the STL and thus can be combined with the algorithms in this library.

Here are basically two flavors of the pixeliterator : the pixel iterator itself and the blockiterator. The pixeliterator moves over single pixels, the blockiterator moves over an [n x m x p] size block (some algorithms need this). So how does this work? Suppose you want to count all the pixels in a raster-coverage with a value greater than 100. First the crude way (there are other more elegant ways to do this)

1 PixelIterator iterator(someraster); 2 PixelIterator endlocation = end(someraster); 3 int count = 0; 4 while ( iterator != endlocation){ 5 if (*iterator > 100) 6 ++count; 7 }

In line 1 a new pixeliterator is created. The simplest constructor only needs the raster-coverage as parameter. In line 2 we create the end iterator. By definition (in c++) the end iterator is located at one container cell beyond the last valid location within the container. With the pixel iterator this means +1 layer beyond the last pixel in the last layer. The end method in line 2 is a convenience method that generates an iterator that satisfies this. Line 4 is end-condition for the traversing the raster-coverage. In line 5 the data of a pixel is accessed by using the ‘*’ operator on the iterator. This operator returns a reference to a double (64-bit) numerical value that is the value of the pixels.

A more modern way (using lambda’s)

1 int count = 0; 2 std::for_each (begin(someraster), end(someraster) , [&](double& v)){ 3 if v > 100) ++count; 4 });

It becomes more interesting when we are combining iterators. Suppose in the example above we want to create a new raster-coverage that only contains the pixels with a numerical value greater than 100

1 PixelIterator iterInput(someraster); 2 std::for_each(begin(outputRaster), end(outputRaster) , [&](double& v)){ 3 if v > 100) v = *iterInput; 4 ++iterInput; 5 });

In line 1 we define a iterator for the input, the output operator(invisible) is hidden behind convenience begin() and end() methods. Remember that the ‘*’operator gives a reference to the value of (in this case output) raster-coverage. ‘for_each’ uses this operator to give access to values of the container and exposes this through the double& (so also a reference). We only need to set this value to actually change values in the output raster-coverage. That’s all. Assuming that input and output have the same geometry. The other interesting part is that the pixeliterator integrates with the existing STL library of C++. Giving access to a large number of existing basic algorithms. Suppose You need to copy all of the values of a raster-coverage to a vector(array) and do some operation on it. Due to memory limitations this might not always be a good idea, but there are certainly enough use cases were this is useful.

std::vector<double> data(someraster.size().totalSize()); std::copy(begin(someraster), end(someraster), data.begin());

or swapping of the pixels of two raster-coverages

swap_ranges(begin(someraster),end(someraster), begin(otherraster));

Note that because the iterator ‘automatically’ moves in layer-index direction all algorithms also work on stacks of raster layers.

Member Enumeration Documentation

The possible flows, not all are implemented (yet).
atm only xyz works

Constructor & Destructor Documentation

PixelIterator::PixelIterator ( )

The empty constructor for PixelIterator.

This constructor creates an empty PixelIterator

PixelIterator::PixelIterator ( const IRasterCoverage raster,
const BoundingBox box = BoundingBox() 
)

Constructs a PixelIterator from a raster and a bounding box.

Constructs a PixelIterator from the raster and the bounding box
The bounding box is the area within the raster which should be walked by the PixelIterator
If one of the parameters was invalid the PixelIterator will also be invalid

Parameters
rasterThe raster from which this PixelIterator should be created
boxThe bounding box which desides what part of the raster should be walked
PixelIterator::PixelIterator ( const PixelIterator iter)

Copy's all the values from the existing PixelIterator onto this one

Parameters
iterThe iterator whose values should be duplicated
PixelIterator::PixelIterator ( PixelIterator &&  iter)

Copy constructor.

Parameters
iterPixelIterator that must be copied

Member Function Documentation

const BoundingBox & PixelIterator::box ( ) const

Query for the bounding box of this PixelIterator the bounding box decides which part of the raster this PixelIterator should walk, thus its size can never be bigger than the rastersize.

Returns
the bounding box of this PixelIterator
bool PixelIterator::contains ( const Pixel pix)

Checks if a certain pixel is inside this PixelIterator.

Parameters
pixthe pixel to be checked
Returns
true when the pixel is in this PixelIterator
PixelIterator PixelIterator::end ( ) const

Returns the end position of this PixelIterator, this is 1 past the actual lastblock of the boundingbox.

Returns
the endvalue of the lineairposition
bool Ilwis::PixelIterator::isAtEnd ( ) const
inline

Checks if this PixelIterator is at its endpoint.

Returns
true if it is at the end
bool Ilwis::PixelIterator::isValid ( ) const
inline

isValid tells if an iterator is in a valid state.

An iterator is valid if bounding box and grid are a valid combination.

Returns
true if the bounding box fits in the grid.
quint32 PixelIterator::linearPosition ( ) const

Query for the linearPosition of this PixelIterator.

Returns
the lineairposition
bool PixelIterator::operator!= ( const PixelIterator iter) const

Checks if this PixelIterator has a different linearPosition as another PixelIterator.

Parameters
iteranother PixelIterator
Returns
true when linearPosition is not equal
PixelIterator& Ilwis::PixelIterator::operator() ( const Pixel pix)
inline

Moves the PixelIterator to the given Pixel.

Moves the PixelIterator to the given Pixel, also adjusts the lineairposition (index) of this iterator
the voxel should have all three coordinates defined.
invalid voxel will cause this iterator to become invalid.

Parameters
voxthe Pixel to move to
Returns
this at the given Pixel
double& Ilwis::PixelIterator::operator* ( )
inline

Query for a reference to the current value of the PixelIterator.

Returns
reference to the currentvalue
const double& Ilwis::PixelIterator::operator* ( ) const
inline

Query for a reference to the current vallue of the PixelIterator.

Returns
reference to the currentvalue
PixelIterator Ilwis::PixelIterator::operator+ ( int  n)
inline

Adds n to this PixelIterator and returns it the direction moved in the raster depends on the boundingbox in combination with the flow.

Parameters
nthe amount to be added
Returns
this iterator moved n
PixelIterator& Ilwis::PixelIterator::operator++ ( )
inline

Adds 1 to this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow.

Returns
This iterator moved 1
PixelIterator PixelIterator::operator++ ( int  )
inline

Adds 1 to this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow.

Returns
this iterator moved 1
PixelIterator& Ilwis::PixelIterator::operator+= ( int  n)
inline

Adds n to this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow.

Parameters
namount to add to this PixelIterator
Returns
this iterator moved n
int PixelIterator::operator- ( const PixelIterator iter2)

Substracts another pixeliterator fomr this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow
this might have unexpected results if both iterators have a different flow.

Parameters
iter2another PixelIterator
Returns
this iterator moved -iter2.linearPosition()
PixelIterator& Ilwis::PixelIterator::operator-- ( )
inline

Substracts 1 from this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow.

Returns
This iterator moved -1
PixelIterator PixelIterator::operator-- ( int  )
inline

Substracts 1 from this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow.

Returns
this iterator moved -1
PixelIterator& Ilwis::PixelIterator::operator-= ( int  n)
inline

Substracts n from this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow.

Parameters
namount to substract
Returns
this iterator moved -n
double* Ilwis::PixelIterator::operator-> ( )
inline

Query for the current value of the PixelIterator.

Returns
->value(this(current))
bool PixelIterator::operator< ( const PixelIterator iter) const

Checks if this PixelIterator has a smaller linearPosition as another PixelIterator.

Parameters
iteranother PixelIterator
Returns
true when linearPosition(this)<linearPosition(iter)
bool PixelIterator::operator<= ( const PixelIterator iter) const

Checks if this PixelIterator has a smaller or equal linearPosition as another PixelIterator.

Parameters
iteranother PixelIterator
Returns
true when linearPosition(this)<=linearPosition(iter)
PixelIterator & PixelIterator::operator= ( const PixelIterator iter)

override of the operator=
copies the values of the supplied iterator onto this one
so: this=iter;
results in this getting the same values as iter

Parameters
iterpixeliterator that must be copied
Returns
this, with the modified values
PixelIterator & PixelIterator::operator= ( const PixelIterator &&  iter)

override of the operator=
copies the values of the supplied iterator onto this one
so: this=iter;
results in this getting the same values as iter

Parameters
iterpixeliterator that must be copied
Returns
this, with the modified values
bool PixelIterator::operator== ( const PixelIterator iter) const

Checks if this PixelIterator has the same linearPosition as another PixelIterator.

Parameters
iteranother PixelIterator
Returns
true when linearPosition is equal
bool PixelIterator::operator> ( const PixelIterator iter) const

Checks if this PixelIterator has a bigger linearPosition as another PixelIterator.

Parameters
iteranother PixelIterator
Returns
true when linearPosition(this)>linearPosition(iter)
bool PixelIterator::operator>= ( const PixelIterator iter) const

Checks if this PixelIterator has a bigger or equal linearPosition as another PixelIterator.

Parameters
iteranother PixelIterator
Returns
true when linearPosition(this)>=linearPosition(iter)
double& Ilwis::PixelIterator::operator[] ( quint32  index)
inline

Random acces operator.

Moves to the specified index and returns a pointer to the value at this index

Parameters
indexthe target index
Returns
the value at the index
PixelIterator& Ilwis::PixelIterator::operator[] ( const Pixel pix)
inline

Random acces operator.

Moves to the specified voxel, requires a valid voxel

Parameters
indexthe target index
Returns
this iterator at the specified voxel
Pixel PixelIterator::position ( ) const

Query for the current non lineair position of this PixelIterator.

Returns
a Pixel with the current non lineair position of this PixelIterator
void PixelIterator::setFlow ( Flow  flw)

Changes the flow of this PixelIterator.

Changes the flow according to the submitted value for flw,
if flw =fXYZ
this means that the pixeliterator will start at the first row in x direction,
at the end of this row, it will go 1 in y direction and start over in x direction,
at the end of the y row, it will go 1 in z direction and start over

note at this moment only the xyz flow is implemented

Parameters
flwthe requested flow
void Ilwis::PixelIterator::setTranquilizer ( const SPTranquilizer &  trq)
inline

ProgressMeter.

Parameters
trq
bool PixelIterator::xchanged ( ) const

Checks if the x coordinate has changed in the last step taken all movement and/or position change commands automatically set the x y and z flags when appropiate.

Returns
true if the x has changed
bool PixelIterator::ychanged ( ) const

Checks if the y coordinate has changed in the last step taken all movement and/or position change commands automatically set the x y and z flags when appropiate.

Returns
true if the y has changed
bool PixelIterator::zchanged ( ) const

Checks if the z coordinate has changed in the last step taken all movement and/or position change commands automatically set the x y and z flags when appropiate.

Returns
true if the z has changed

The documentation for this class was generated from the following files: