Ilwis-Objects
1.0
GIS and Remote Sensing framework for data access and processing
|
The PixelIterator class an iterator class that iteratos over all the pixels in an grid (or subsection of it) More...
#include <pixeliterator.h>
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... | |
PixelIterator & | operator= (const PixelIterator &iter) |
PixelIterator & | operator= (const PixelIterator &&iter) |
PixelIterator & | operator++ () |
Adds 1 to this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow. More... | |
PixelIterator & | operator-- () |
Substracts 1 from this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow. More... | |
PixelIterator & | operator+= (int n) |
Adds n to this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow. More... | |
PixelIterator & | operator-= (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) |
PixelIterator & | operator() (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... | |
PixelIterator & | operator[] (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 BoundingBox & | 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. 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 |
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.
The possible flows, not all are implemented (yet).
atm only xyz works
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
raster | The raster from which this PixelIterator should be created |
box | The 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
iter | The iterator whose values should be duplicated |
PixelIterator::PixelIterator | ( | PixelIterator && | iter | ) |
Copy constructor.
iter | PixelIterator that must be copied |
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.
bool PixelIterator::contains | ( | const Pixel & | pix | ) |
Checks if a certain pixel is inside this PixelIterator.
pix | the pixel to be checked |
PixelIterator PixelIterator::end | ( | ) | const |
Returns the end position of this PixelIterator, this is 1 past the actual lastblock of the boundingbox.
|
inline |
Checks if this PixelIterator is at its endpoint.
|
inline |
isValid tells if an iterator is in a valid state.
An iterator is valid if bounding box and grid are a valid combination.
quint32 PixelIterator::linearPosition | ( | ) | const |
Query for the linearPosition of this PixelIterator.
bool PixelIterator::operator!= | ( | const PixelIterator & | iter | ) | const |
Checks if this PixelIterator has a different linearPosition as another PixelIterator.
iter | another PixelIterator |
|
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.
vox | the Pixel to move to |
|
inline |
Query for a reference to the current value of the PixelIterator.
|
inline |
Query for a reference to the current vallue of the PixelIterator.
|
inline |
Adds n to this PixelIterator and returns it the direction moved in the raster depends on the boundingbox in combination with the flow.
n | the amount to be added |
|
inline |
Adds 1 to this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow.
|
inline |
Adds 1 to this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow.
|
inline |
Adds n to this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow.
n | amount to add to this PixelIterator |
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.
iter2 | another PixelIterator |
|
inline |
Substracts 1 from this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow.
|
inline |
Substracts 1 from this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow.
|
inline |
Substracts n from this PixelIterator the direction moved in the raster depends on the boundingbox in combination with the flow.
n | amount to substract |
|
inline |
Query for the current value of the PixelIterator.
bool PixelIterator::operator< | ( | const PixelIterator & | iter | ) | const |
Checks if this PixelIterator has a smaller linearPosition as another PixelIterator.
iter | another PixelIterator |
bool PixelIterator::operator<= | ( | const PixelIterator & | iter | ) | const |
Checks if this PixelIterator has a smaller or equal linearPosition as another PixelIterator.
iter | another PixelIterator |
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
iter | pixeliterator that must be copied |
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
iter | pixeliterator that must be copied |
bool PixelIterator::operator== | ( | const PixelIterator & | iter | ) | const |
Checks if this PixelIterator has the same linearPosition as another PixelIterator.
iter | another PixelIterator |
bool PixelIterator::operator> | ( | const PixelIterator & | iter | ) | const |
Checks if this PixelIterator has a bigger linearPosition as another PixelIterator.
iter | another PixelIterator |
bool PixelIterator::operator>= | ( | const PixelIterator & | iter | ) | const |
Checks if this PixelIterator has a bigger or equal linearPosition as another PixelIterator.
iter | another PixelIterator |
|
inline |
Random acces operator.
Moves to the specified index and returns a pointer to the value at this index
index | the target index |
|
inline |
Random acces operator.
Moves to the specified voxel, requires a valid voxel
index | the target index |
Pixel PixelIterator::position | ( | ) | const |
Query for 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
flw | the requested flow |
|
inline |
ProgressMeter.
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.
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.
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.