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
explicit MatrixIterator(Array<T> &a)
MatrixIterator(Array<T> &a, uInt cursorAxis1, uInt cursorAxis2)
Matrix<T> &matrix()
Private Members
MatrixIterator(const MatrixIterator<T> &)
MatrixIterator<T> &operator=(const MatrixIterator<T> &)

Description

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

MatrixIterator steps a Matrix (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.

This class is derived from ArrayIterator; basically it only adds the matrix() member function which allows you to access the cursor as a Matrix.

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
    

Member Description

explicit MatrixIterator(Array<T> &a)

Iterate by matrices through array "a". The first 2 axes form the cursor axes.

MatrixIterator(Array<T> &a, uInt cursorAxis1, uInt cursorAxis2)

Iterate by matrices through array "a". The given axes form the cursor axes.

Matrix<T> &matrix()

Return the matrix at the current position.

MatrixIterator(const MatrixIterator<T> &)

Not implemented.

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

Not implemented.

template<class T> class ReadOnlyMatrixIterator

Interface

Public Members
ReadOnlyMatrixIterator(const Array<T> &a) : mi(const_cast<Array<T>&>(a))
ReadOnlyMatrixIterator(const Array<T> &a, uInt cursorAxis1, uInt cursorAxis2) : mi(const_cast<Array<T>&>(a), cursorAxis1, cursorAxis2)
void next()
void reset()
void origin()
const Array<T> &array()
const Matrix<T> &matrix()
Bool atStart() const
Bool pastEnd() const
const IPosition &pos() const
IPosition endPos() const
uInt ndim() const
Private Members
ReadOnlyMatrixIterator(const ReadOnlyMatrixIterator<T> &)
ReadOnlyMatrixIterator<T> &operator=(const ReadOnlyMatrixIterator<T> &)

Description

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

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(const_cast<Array<T>&>(a))
ReadOnlyMatrixIterator(const Array<T> &a, uInt cursorAxis1, uInt cursorAxis2) : mi(const_cast<Array<T>&>(a), cursorAxis1, cursorAxis2)
void next()
void reset()
void origin()
const Array<T> &array()
const Matrix<T> &matrix()
Bool atStart() const
Bool pastEnd() const
const IPosition &pos() const
IPosition endPos() const
uInt ndim() const

ReadOnlyMatrixIterator(const ReadOnlyMatrixIterator<T> &)

Not implemented.

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

Not implemented.