MatrixIter.h

Classes

MatrixIterator -- Iterate a Matrix cursor through another Array. (full description)
ReadOnlyMatrixIterator -- Iterate a Matrix cursor through a R/O Array. (full description)

template<class T> class MatrixIterator : public ArrayIterator<T>

Interface

Public Members
MatrixIterator(Array<T> &a)
MatrixIterator(const MatrixIterator<T> &)
MatrixIterator<T> &operator=(const MatrixIterator<T> &)
Matrix<T> &matrix()

Description

MatrixIterator steps a Vector (the "cursor") through an array. The cursor "refers" to storage in the array, so that changing the values in the cursor changes values in the original array. Like with ArrayPositionIterator, the cursor presently only moves through the array from bottom to top in the obvious way; however one may of course iterate through a slice ("array section"). This class is derived from ArrayIterator; basically it only adds the vector() member function which allows you to access the cursor as a Vector.

Tip The origin of the cursor, i.e. the subarray that moves through the larger array, is always zero.
In this example we want to make a "moment" map of a cube, i.e. collapse the "Z" axis by averaging it.

    Cube<Float> cube;
    MatrixIterator planeIter(cube);
    Matrix<Float> average(planeIter.matrix().copy()); // init with first plane
    planeIter.next(); // advance the iterator
    while (! planeIter.pastEnd()) {
        average += planeIter.matrix(); // Sum the next plane
        planeIter.next();
    }
    average /= Float(cube.shape()(2));  // divide by the number of planes
    
Tip All ArrayIterator classes should be redone.

Member Description

MatrixIterator(Array<T> &a)

Iterate by matrices through array "a".

MatrixIterator(const MatrixIterator<T> &)

Not implemented.

MatrixIterator<T> &operator=(const MatrixIterator<T> &)

Not implemented.

Matrix<T> &matrix()

Return the matrix at the current position.


template<class T> class ReadOnlyMatrixIterator

Interface

ReadOnlyMatrixIterator(const Array<T> &a) : mi((Array<T> &)a)
ReadOnlyMatrixIterator(const ReadOnlyMatrixIterator<T> &)
ReadOnlyMatrixIterator<T> &operator=(const ReadOnlyMatrixIterator<T> &)
void next()
void origin()
const Array<T> &array()
const Matrix<T> &matrix()
Bool atStart() const
Bool pastEnd() const
const IPosition &pos() const
uInt ndim() const
uInt dimIter() const
uInt nSteps() const

Description

ReadOnlyMatrixIterator behaves exactly like MatrixIterator (cf.) only it should be used on const Arrays.

Tip Note that the R/O MatrixIterator is not derived from R/O ArrayIterator.

Member Description

ReadOnlyMatrixIterator(const Array<T> &a) : mi((Array<T> &)a)
ReadOnlyMatrixIterator(const ReadOnlyMatrixIterator<T> &)
ReadOnlyMatrixIterator<T> &operator=(const ReadOnlyMatrixIterator<T> &)
void next()
void origin()
const Array<T> &array()
const Matrix<T> &matrix()
Bool atStart() const
Bool pastEnd() const
const IPosition &pos() const
uInt ndim() const
uInt dimIter() const
uInt nSteps() const