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>
67{
68public:
69 // Iterate by matrices through array "a".
70 // The first 2 axes form the cursor axes.
72
73 // Iterate by matrices through array "a".
74 // The given axes form the cursor axes.
75 MatrixIterator(Array<T> &a, size_t cursorAxis1, size_t cursorAxis2);
76
77 // Return the matrix at the current position.
78 Matrix<T> &matrix() {return *(Matrix<T> *)(this->ap_p.get());}
79
80private:
81 // Not implemented.
83 // Not implemented.
85};
86
87//
88// <summary> Iterate a Matrix cursor through a R/O Array. </summary>
89// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
90// </reviewed>
91//
92// ReadOnlyMatrixIterator behaves exactly like MatrixIterator (cf.) only
93// it should be used on const Arrays.
94//
95// <note role=tip> Note that the R/O MatrixIterator is not derived from R/O
96// ArrayIterator.
97// </note>
98//
99template<class T> class ReadOnlyMatrixIterator
100{
101public:
102 // <group>
104 mi(const_cast<Array<T>&>(a)) {}
105
107 size_t cursorAxis1, size_t cursorAxis2)
108 : mi(const_cast<Array<T>&>(a), cursorAxis1, cursorAxis2) {}
109
110 void next() {mi.next();}
111 void reset() {mi.origin();}
112 void origin() {mi.origin();}
113
114 const Array<T> &array() {return mi.array();}
115 const Matrix<T> &matrix() {return mi.matrix();}
116
117 bool atStart() const {return mi.atStart();}
118 bool pastEnd() const {return mi.pastEnd();}
119 const IPosition &pos() const {return mi.pos();}
120 IPosition endPos() const {return mi.endPos();}
121 size_t ndim() const {return mi.ndim();}
122 // </group>
123private:
124 // Not implemented.
126 // Not implemented.
128
130};
131
132
133} //# NAMESPACE CASACORE - END
134
135#include "MatrixIter.tcc"
136
137#endif
std::unique_ptr< Array< T > > ap_p
The cursor.
Definition ArrayIter.h:120
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:78
Iterate a Matrix cursor through a R/O Array.
Definition MatrixIter.h:100
ReadOnlyMatrixIterator< T > & operator=(const ReadOnlyMatrixIterator< T > &)=delete
Not implemented.
const Array< T > & array()
Definition MatrixIter.h:114
const IPosition & pos() const
Definition MatrixIter.h:119
const Matrix< T > & matrix()
Definition MatrixIter.h:115
ReadOnlyMatrixIterator(const Array< T > &a, size_t cursorAxis1, size_t cursorAxis2)
Definition MatrixIter.h:106
ReadOnlyMatrixIterator(const Array< T > &a)
Definition MatrixIter.h:103
ReadOnlyMatrixIterator(const ReadOnlyMatrixIterator< T > &)=delete
Not implemented.
this file contains all the compiler specific defines
Definition mainpage.dox:28