casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: aips2-request@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 //# $Id$
27 
28 #ifndef CASA_MATRIXITER_H
29 #define CASA_MATRIXITER_H
30 
31 
32 #include <casacore/casa/aips.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 //
39 // <summary> Iterate a Matrix cursor through another Array. </summary>
40 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
41 // </reviewed>
42 //
43 // MatrixIterator steps a Matrix (the "cursor") through an array.
44 // The cursor "refers" to storage in the array, so that changing the
45 // values in the cursor changes values in the original array.
46 //
47 // This class is derived from ArrayIterator; basically it only adds the
48 // matrix() member function which allows you to access the cursor as a Matrix.
49 //
50 // <note role=tip>
51 // The origin of the cursor, i.e. the subarray that moves through the
52 // larger array, is always zero.
53 // </note>
54 //
55 // In this example we want to make a "moment" map of a cube, i.e. collapse
56 // the "Z" axis by averaging it.
57 // <srcblock>
58 // Cube<Float> cube;
59 // MatrixIterator planeIter(cube);
60 // Matrix<Float> average(planeIter.matrix().copy()); // init with first plane
61 // planeIter.next(); // advance the iterator
62 // while (! planeIter.pastEnd()) {
63 // average += planeIter.matrix(); // Sum the next plane
64 // planeIter.next();
65 // }
66 // average /= Float(cube.shape()(2)); // divide by the number of planes
67 // </srcblock>
68 
69 template<class T> class MatrixIterator : public ArrayIterator<T>
70 {
71 public:
72  // Iterate by matrices through array "a".
73  // The first 2 axes form the cursor axes.
74  explicit MatrixIterator(Array<T> &a);
75 
76  // Iterate by matrices through array "a".
77  // The given axes form the cursor axes.
78  MatrixIterator(Array<T> &a, uInt cursorAxis1, uInt cursorAxis2);
79 
80  // Return the matrix at the current position.
81  Matrix<T> &matrix() {return *(Matrix<T> *)(this->ap_p);}
82 
83 private:
84  // Not implemented.
86  // Not implemented.
88 };
89 
90 //
91 // <summary> Iterate a Matrix cursor through a R/O Array. </summary>
92 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
93 // </reviewed>
94 //
95 // ReadOnlyMatrixIterator behaves exactly like MatrixIterator (cf.) only
96 // it should be used on const Arrays.
97 //
98 // <note role=tip> Note that the R/O MatrixIterator is not derived from R/O
99 // ArrayIterator.
100 // </note>
101 //
102 template<class T> class ReadOnlyMatrixIterator
103 {
104 public:
105  // <group>
107  mi(const_cast<Array<T>&>(a)) {}
108 
110  uInt cursorAxis1, uInt cursorAxis2)
111  : mi(const_cast<Array<T>&>(a), cursorAxis1, cursorAxis2) {}
112 
113  void next() {mi.next();}
114  void reset() {mi.origin();}
115  void origin() {mi.origin();}
116 
117  const Array<T> &array() {return mi.array();}
118  const Matrix<T> &matrix() {return mi.matrix();}
119 
120  Bool atStart() const {return mi.atStart();}
121  Bool pastEnd() const {return mi.pastEnd();}
122  const IPosition &pos() const {return mi.pos();}
123  IPosition endPos() const {return mi.endPos();}
124  uInt ndim() const {return mi.ndim();}
125  // </group>
126 private:
127  // Not implemented.
129  // Not implemented.
131 
133 };
134 
135 
136 } //# NAMESPACE CASACORE - END
137 
138 #ifndef CASACORE_NO_AUTO_TEMPLATES
139 #include <casacore/casa/Arrays/MatrixIter.tcc>
140 #endif //# CASACORE_NO_AUTO_TEMPLATES
141 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
const IPosition & pos() const
Definition: MatrixIter.h:122
MatrixIterator(Array< T > &a)
Iterate by matrices through array &quot;a&quot;.
const Matrix< T > & matrix()
Definition: MatrixIter.h:118
Iterate a Matrix cursor through another Array.
Definition: MatrixIter.h:69
Iterate a Matrix cursor through a R/O Array.
Definition: MatrixIter.h:102
Matrix< T > & matrix()
Return the matrix at the current position.
Definition: MatrixIter.h:81
A 2-D Specialization of the Array class.
Iterate an Array cursor through another Array.
Definition: Array.h:51
ReadOnlyMatrixIterator(const Array< T > &a, uInt cursorAxis1, uInt cursorAxis2)
Definition: MatrixIter.h:109
Array< T > * ap_p
A pointer to the cursor.
Definition: ArrayIter.h:125
const Array< T > & array()
Definition: MatrixIter.h:117
MatrixIterator< T > & operator=(const MatrixIterator< T > &)
Not implemented.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
ReadOnlyMatrixIterator< T > & operator=(const ReadOnlyMatrixIterator< T > &)
Not implemented.
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
ReadOnlyMatrixIterator(const Array< T > &a)
Definition: MatrixIter.h:106
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42