GClasses

GClasses::GCoordVectorIterator Class Reference

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.) More...

#include <GVec.h>

List of all members.

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.
 GCoordVectorIterator (std::vector< size_t > &ranges)
 ~GCoordVectorIterator ()
void reset ()
 Sets the coordinate vector to all zeros.
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.
void reset (std::vector< size_t > &ranges)
 Adjusts the number of dims and ranges, and sets the coordinate vector to all zeros.
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.
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.
bool advanceSampling ()
 Advances in a manner that approximates a uniform sampling of the space, but ultimately visits every coordinate. (Behavior is not defined if dims > 31, or if the largest range is >= (1 << 31).)
size_t dims ()
 Returns the number of dims.
size_t * current ()
 Returns the current coordinate vector.
size_t * ranges ()
 Returns the current ranges.
size_t coordCount ()
 Computes the total number of coordinates.
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.)
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.)
void setRandom (GRand *pRand)
 Jump to a random coordinate in the valid range.

Static Public Member Functions

static void test ()
 Performs unit tests for this class. Throws an exception if any problems are found.

Protected Attributes

size_t m_dims
size_t * m_pCoords
size_t * m_pRanges
size_t m_sampleShift
size_t m_sampleMask

Detailed Description

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.)


Constructor & Destructor Documentation

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 ( )

Member Function Documentation

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. (Behavior is not defined if dims > 31, or if the largest range is >= (1 << 31).)

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.)

size_t GClasses::GCoordVectorIterator::dims ( ) [inline]

Returns the number of dims.

size_t* GClasses::GCoordVectorIterator::ranges ( ) [inline]

Returns the current ranges.

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::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 ( )

Sets the coordinate vector to all zeros.

void GClasses::GCoordVectorIterator::setRandom ( GRand pRand)

Jump to a random coordinate in the valid range.

static void GClasses::GCoordVectorIterator::test ( ) [static]

Performs unit tests for this class. Throws an exception if any problems are found.


Member Data Documentation