casacore
Loading...
Searching...
No Matches
MatrixIter.h
Go to the documentation of this file.
1// # MatrixIter.h: Iterate a matrix cursor through another array
2// # Copyright (C) 1993,1994,1995,1999
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_MATRIXITER_2_H
27#define CASA_MATRIXITER_2_H
28
29#include "ArrayIter.h"
30#include "Matrix.h"
31
32namespace casacore { // # NAMESPACE CASACORE - BEGIN
33
34//
35// <summary> Iterate a Matrix cursor through another Array. </summary>
36// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
37// </reviewed>
38//
39// MatrixIterator steps a Matrix (the "cursor") through an array.
40// The cursor "refers" to storage in the array, so that changing the
41// values in the cursor changes values in the original array.
42//
43// This class is derived from ArrayIterator; basically it only adds the
44// matrix() member function which allows you to access the cursor as a Matrix.
45//
46// <note role=tip>
47// The origin of the cursor, i.e. the subarray that moves through the
48// larger array, is always zero.
49// </note>
50//
51// In this example we want to make a "moment" map of a cube, i.e. collapse
52// the "Z" axis by averaging it.
53// <srcblock>
54// Cube<float> cube;
55// MatrixIterator planeIter(cube);
56// Matrix<float> average(planeIter.matrix().copy()); // init with first plane
57// planeIter.next(); // advance the iterator
58// while (! planeIter.pastEnd()) {
59// average += planeIter.matrix(); // Sum the next plane
60// planeIter.next();
61// }
62// average /= float(cube.shape()(2)); // divide by the number of planes
63// </srcblock>
64
65template <typename T>
66class MatrixIterator : public ArrayIterator<T> {
67 public:
68 // Iterate by matrices through array "a".
69 // The first 2 axes form the cursor axes.
71
72 // Iterate by matrices through array "a".
73 // The given axes form the cursor axes.
74 MatrixIterator(Array<T> &a, size_t cursorAxis1, size_t cursorAxis2);
75
76 // Return the matrix at the current position.
77 Matrix<T> &matrix() { return *(Matrix<T> *)(this->ap_p.get()); }
78
79 private:
80 // Not implemented.
82 // Not implemented.
84};
85
86//
87// <summary> Iterate a Matrix cursor through a R/O Array. </summary>
88// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
89// </reviewed>
90//
91// ReadOnlyMatrixIterator behaves exactly like MatrixIterator (cf.) only
92// it should be used on const Arrays.
93//
94// <note role=tip> Note that the R/O MatrixIterator is not derived from R/O
95// ArrayIterator.
96// </note>
97//
98template <class T>
100 public:
101 // <group>
102 ReadOnlyMatrixIterator(const Array<T> &a) : mi(const_cast<Array<T> &>(a)) {}
103
104 ReadOnlyMatrixIterator(const Array<T> &a, size_t cursorAxis1, size_t cursorAxis2)
105 : mi(const_cast<Array<T> &>(a), cursorAxis1, cursorAxis2) {}
106
107 void next() { mi.next(); }
108 void reset() { mi.origin(); }
109 void origin() { mi.origin(); }
110
111 const Array<T> &array() { return mi.array(); }
112 const Matrix<T> &matrix() { return mi.matrix(); }
113
114 bool atStart() const { return mi.atStart(); }
115 bool pastEnd() const { return mi.pastEnd(); }
116 const IPosition &pos() const { return mi.pos(); }
117 IPosition endPos() const { return mi.endPos(); }
118 size_t ndim() const { return mi.ndim(); }
119 // </group>
120 private:
121 // Not implemented.
123 // Not implemented.
125
127};
128
129} // namespace casacore
130
131#include "MatrixIter.tcc"
132
133#endif
std::unique_ptr< Array< T > > ap_p
The cursor.
Definition ArrayIter.h:117
ArrayIterator(const Array< T > &arr, size_t byDim=1)
Step through array "arr" over the first byDim axes (using a cursor of dimensionality "byDim").
MatrixIterator< T > & operator=(const MatrixIterator< T > &)=delete
Not implemented.
MatrixIterator(Array< T > &a)
Iterate by matrices through array "a".
MatrixIterator(Array< T > &a, size_t cursorAxis1, size_t cursorAxis2)
Iterate by matrices through array "a".
MatrixIterator(const MatrixIterator< T > &)=delete
Not implemented.
Matrix< T > & matrix()
Return the matrix at the current position.
Definition MatrixIter.h:77
ReadOnlyMatrixIterator< T > & operator=(const ReadOnlyMatrixIterator< T > &)=delete
Not implemented.
const Array< T > & array()
Definition MatrixIter.h:111
const IPosition & pos() const
Definition MatrixIter.h:116
const Matrix< T > & matrix()
Definition MatrixIter.h:112
ReadOnlyMatrixIterator(const Array< T > &a, size_t cursorAxis1, size_t cursorAxis2)
Definition MatrixIter.h:104
ReadOnlyMatrixIterator(const Array< T > &a)
Definition MatrixIter.h:102
ReadOnlyMatrixIterator(const ReadOnlyMatrixIterator< T > &)=delete
Not implemented.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28