casacore
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_2_H
29 #define CASA_MATRIXITER_2_H
30 
31 #include "ArrayIter.h"
32 #include "Matrix.h"
33 
34 namespace casacore { //# NAMESPACE CASACORE - BEGIN
35 
36 //
37 // <summary> Iterate a Matrix cursor through another Array. </summary>
38 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
39 // </reviewed>
40 //
41 // MatrixIterator steps a Matrix (the "cursor") through an array.
42 // The cursor "refers" to storage in the array, so that changing the
43 // values in the cursor changes values in the original array.
44 //
45 // This class is derived from ArrayIterator; basically it only adds the
46 // matrix() member function which allows you to access the cursor as a Matrix.
47 //
48 // <note role=tip>
49 // The origin of the cursor, i.e. the subarray that moves through the
50 // larger array, is always zero.
51 // </note>
52 //
53 // In this example we want to make a "moment" map of a cube, i.e. collapse
54 // the "Z" axis by averaging it.
55 // <srcblock>
56 // Cube<float> cube;
57 // MatrixIterator planeIter(cube);
58 // Matrix<float> average(planeIter.matrix().copy()); // init with first plane
59 // planeIter.next(); // advance the iterator
60 // while (! planeIter.pastEnd()) {
61 // average += planeIter.matrix(); // Sum the next plane
62 // planeIter.next();
63 // }
64 // average /= float(cube.shape()(2)); // divide by the number of planes
65 // </srcblock>
66 
67 template<typename T, typename Alloc=std::allocator<T>>
68 class MatrixIterator : public ArrayIterator<T, Alloc>
69 {
70 public:
71  // Iterate by matrices through array "a".
72  // The first 2 axes form the cursor axes.
74 
75  // Iterate by matrices through array "a".
76  // The given axes form the cursor axes.
77  MatrixIterator(Array<T, Alloc> &a, size_t cursorAxis1, size_t cursorAxis2);
78 
79  // Return the matrix at the current position.
80  Matrix<T, Alloc> &matrix() {return *(Matrix<T, Alloc> *)(this->ap_p.get());}
81 
82 private:
83  // Not implemented.
85  // Not implemented.
87 };
88 
89 //
90 // <summary> Iterate a Matrix cursor through a R/O Array. </summary>
91 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
92 // </reviewed>
93 //
94 // ReadOnlyMatrixIterator behaves exactly like MatrixIterator (cf.) only
95 // it should be used on const Arrays.
96 //
97 // <note role=tip> Note that the R/O MatrixIterator is not derived from R/O
98 // ArrayIterator.
99 // </note>
100 //
101 template<class T> class ReadOnlyMatrixIterator
102 {
103 public:
104  // <group>
106  mi(const_cast<Array<T>&>(a)) {}
107 
109  size_t cursorAxis1, size_t cursorAxis2)
110  : mi(const_cast<Array<T>&>(a), cursorAxis1, cursorAxis2) {}
111 
112  void next() {mi.next();}
113  void reset() {mi.origin();}
114  void origin() {mi.origin();}
115 
116  const Array<T> &array() {return mi.array();}
117  const Matrix<T> &matrix() {return mi.matrix();}
118 
119  bool atStart() const {return mi.atStart();}
120  bool pastEnd() const {return mi.pastEnd();}
121  const IPosition &pos() const {return mi.pos();}
122  IPosition endPos() const {return mi.endPos();}
123  size_t ndim() const {return mi.ndim();}
124  // </group>
125 private:
126  // Not implemented.
128  // Not implemented.
130 
132 };
133 
134 
135 } //# NAMESPACE CASACORE - END
136 
137 #include "MatrixIter.tcc"
138 
139 #endif
std::unique_ptr< Array< T, std::allocator< T > > > ap_p
The cursor.
Definition: ArrayIter.h:122
MatrixIterator(Array< T, Alloc > &a)
Iterate by matrices through array "a".
Matrix< T, Alloc > & matrix()
Return the matrix at the current position.
Definition: MatrixIter.h:80
MatrixIterator(const MatrixIterator< T, Alloc > &)=delete
Not implemented.
MatrixIterator< T, Alloc > & operator=(const MatrixIterator< T, Alloc > &)=delete
Not implemented.
MatrixIterator(Array< T, Alloc > &a, size_t cursorAxis1, size_t cursorAxis2)
Iterate by matrices through array "a".
Iterate a Matrix cursor through a R/O Array.
Definition: MatrixIter.h:102
const Matrix< T > & matrix()
Definition: MatrixIter.h:117
const IPosition & pos() const
Definition: MatrixIter.h:121
const Array< T > & array()
Definition: MatrixIter.h:116
ReadOnlyMatrixIterator(const Array< T > &a, size_t cursorAxis1, size_t cursorAxis2)
Definition: MatrixIter.h:108
ReadOnlyMatrixIterator(const Array< T > &a)
Definition: MatrixIter.h:105
ReadOnlyMatrixIterator< T > & operator=(const ReadOnlyMatrixIterator< T > &)=delete
Not implemented.
ReadOnlyMatrixIterator(const ReadOnlyMatrixIterator< T > &)=delete
Not implemented.
this file contains all the compiler specific defines
Definition: mainpage.dox:28