Convenience class for iterating the pixels of a Channel. The iteration is const
, performing read-only operations on the Channel.
More...
#include <Channel.h>
Public Member Functions | |
ConstIter (const ChannelT< T > &channelT, const Area &area) | |
const T & | v () const |
Returns a reference to the value of the pixel that the Iter currently points to. | |
const T & | v (int32_t xOff, int32_t yOff) const |
Returns a reference to the value of the pixel that the Iter currently points to, offset by (xOff, yOff) pixels. | |
const T & | vClamped (int32_t xOff, int32_t yOff) const |
Returns a reference to the value of the pixel that the Iter currently points to, offset by (xOff, yOff) pixels. Clamps offset to the bounds of the Iter. | |
const int32_t | x () const |
Returns the x coordinate of the pixel the Iter currently points to. | |
const int32_t | y () const |
Returns the y coordinate of the pixel the Iter currently points to. | |
Vec2i | getPos () const |
Returns the coordinate of the pixel the Iter currently points to. | |
bool | pixel () |
Increments which pixel of the current row the Iter points to, and returns false when no pixels remain in the current row. | |
bool | line () |
Increments which row the Iter points to, and returns false when no rows remain in the Channel. | |
int32_t | getWidth () |
Returns the width of the Area the Iter iterates. | |
int32_t | getHeight () |
Returns the height of the Area the Iter iterates. |
Convenience class for iterating the pixels of a Channel. The iteration is const
, performing read-only operations on the Channel.
The ConstIter class can be used to walk the pixels of a Channel using a nested for-loop, where the outer loop calls line(), and the inner calls pixel().
The code below finds the maximum value in the Area area of channel:
Channel::ConstIter iter = channel.getIter( area ); uint8_t maxValue = 0; while( iter.line() ) { while( iter.pixel() ) { if( iter.v() > maxValue ) maxValue = iter.v(); } }
In addition to v(), the Iter provides an accessor which accepts an offset in x & y relative to the current location:
inputIter.v(1, 1); // will return the value of the pixel to the lower right of the current pixel inputIter.v(0, -1); // will return the value of the pixel directly above the current pixel
A final accessor, vClamped() also accepts an x & y relative offset, but will not sample outside of the bounds of the iterator.
inputIter.vClamped(-2,0); // when called on the left edge of a row, // this will simply return the left-most pixel's value
cinder::ChannelT< T >::ConstIter::ConstIter | ( | const ChannelT< T > & | channelT, | |
const Area & | area | |||
) |
const T& cinder::ChannelT< T >::ConstIter::v | ( | ) | const |
Returns a reference to the value of the pixel that the Iter currently points to.
const T& cinder::ChannelT< T >::ConstIter::v | ( | int32_t | xOff, | |
int32_t | yOff | |||
) | const |
Returns a reference to the value of the pixel that the Iter currently points to, offset by (xOff, yOff) pixels.
const T& cinder::ChannelT< T >::ConstIter::vClamped | ( | int32_t | xOff, | |
int32_t | yOff | |||
) | const |
const int32_t cinder::ChannelT< T >::ConstIter::x | ( | ) | const |
Returns the x coordinate of the pixel the Iter currently points to.
const int32_t cinder::ChannelT< T >::ConstIter::y | ( | ) | const |
Returns the y coordinate of the pixel the Iter currently points to.
Vec2i cinder::ChannelT< T >::ConstIter::getPos | ( | ) | const |
Returns the coordinate of the pixel the Iter currently points to.
bool cinder::ChannelT< T >::ConstIter::pixel | ( | ) |
Increments which pixel of the current row the Iter points to, and returns false
when no pixels remain in the current row.
bool cinder::ChannelT< T >::ConstIter::line | ( | ) |
Increments which row the Iter points to, and returns false
when no rows remain in the Channel.
int32_t cinder::ChannelT< T >::ConstIter::getWidth | ( | ) |
Returns the width of the Area the Iter iterates.
int32_t cinder::ChannelT< T >::ConstIter::getHeight | ( | ) |
Returns the height of the Area the Iter iterates.