GClasses
|
An iterator for an n-dimensional coordinate vector. For example, suppose you have a 4-dimensional 2x3x2x1 grid, and you want to iterate through its coordinates: (0000, 0010, 0100, 0110, 0200, 0210, 1000, 1010, 1100, 1110, 1200, 1210). This class will iterate over coordinate vectors in this manner. (For 0-dimensional coordinate vectors, it behaves as though the origin is the only valid coordinate.)
#include <GVec.h>
Public Member Functions | |
GCoordVectorIterator (size_t dims, size_t *pRanges) | |
Makes an internal copy of pRanges. If pRanges is NULL, then it sets all the range values to 1. More... | |
GCoordVectorIterator (std::vector< size_t > &ranges) | |
~GCoordVectorIterator () | |
bool | advance () |
Advances to the next coordinate. Returns true if it successfully advances to another valid coordinate. Returns false if there are no more valid coordinates. More... | |
bool | advance (size_t steps) |
Advances by the specified number of steps. Returns false if it wraps past the end of the coordinate space. Returns true otherwise. More... | |
bool | advanceSampling () |
Advances in a manner that approximates a uniform sampling of the space, but ultimately visits every coordinate. More... | |
size_t | coordCount () |
Computes the total number of coordinates. More... | |
size_t * | current () |
Returns the current coordinate vector. More... | |
size_t | currentIndex () |
Returns the index value of the current coordinate in raster order. (This is computed, not counted, so it will be accurate even if you jump to a random coordinate.) More... | |
void | currentNormalized (double *pCoords) |
Returns a coordinate vector that has been normalized so that each element falls between 0 and 1. (The coordinates are also offset slightly to sample the space without bias.) More... | |
size_t | dims () |
Returns the number of dims. More... | |
size_t * | ranges () |
Returns the current ranges. More... | |
void | reset () |
Sets the coordinate vector to all zeros. More... | |
void | reset (size_t dims, size_t *pRanges) |
Adjusts the number of dims and ranges, and sets the coordinate vector to all zeros. If pRanges is NULL, then it sets all the range values to 1. More... | |
void | reset (std::vector< size_t > &ranges) |
Adjusts the number of dims and ranges, and sets the coordinate vector to all zeros. More... | |
void | setRandom (GRand *pRand) |
Jump to a random coordinate in the valid range. More... | |
Static Public Member Functions | |
static void | test () |
Performs unit tests for this class. Throws an exception if any problems are found. More... | |
Protected Attributes | |
size_t | m_dims |
size_t * | m_pCoords |
size_t * | m_pRanges |
size_t | m_sampleMask |
size_t | m_sampleShift |
GClasses::GCoordVectorIterator::GCoordVectorIterator | ( | size_t | dims, |
size_t * | pRanges | ||
) |
Makes an internal copy of pRanges. If pRanges is NULL, then it sets all the range values to 1.
GClasses::GCoordVectorIterator::GCoordVectorIterator | ( | std::vector< size_t > & | ranges | ) |
GClasses::GCoordVectorIterator::~GCoordVectorIterator | ( | ) |
bool GClasses::GCoordVectorIterator::advance | ( | ) |
Advances to the next coordinate. Returns true if it successfully advances to another valid coordinate. Returns false if there are no more valid coordinates.
bool GClasses::GCoordVectorIterator::advance | ( | size_t | steps | ) |
Advances by the specified number of steps. Returns false if it wraps past the end of the coordinate space. Returns true otherwise.
bool GClasses::GCoordVectorIterator::advanceSampling | ( | ) |
Advances in a manner that approximates a uniform sampling of the space, but ultimately visits every coordinate.
size_t GClasses::GCoordVectorIterator::coordCount | ( | ) |
Computes the total number of coordinates.
size_t* GClasses::GCoordVectorIterator::current | ( | ) |
Returns the current coordinate vector.
size_t GClasses::GCoordVectorIterator::currentIndex | ( | ) |
Returns the index value of the current coordinate in raster order. (This is computed, not counted, so it will be accurate even if you jump to a random coordinate.)
void GClasses::GCoordVectorIterator::currentNormalized | ( | double * | pCoords | ) |
Returns a coordinate vector that has been normalized so that each element falls between 0 and 1. (The coordinates are also offset slightly to sample the space without bias.)
|
inline |
Returns the number of dims.
|
inline |
Returns the current ranges.
void GClasses::GCoordVectorIterator::reset | ( | ) |
Sets the coordinate vector to all zeros.
void GClasses::GCoordVectorIterator::reset | ( | size_t | dims, |
size_t * | pRanges | ||
) |
Adjusts the number of dims and ranges, and sets the coordinate vector to all zeros. If pRanges is NULL, then it sets all the range values to 1.
void GClasses::GCoordVectorIterator::reset | ( | std::vector< size_t > & | ranges | ) |
Adjusts the number of dims and ranges, and sets the coordinate vector to all zeros.
void GClasses::GCoordVectorIterator::setRandom | ( | GRand * | pRand | ) |
Jump to a random coordinate in the valid range.
|
static |
Performs unit tests for this class. Throws an exception if any problems are found.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |