casacore
Loading...
Searching...
No Matches
TiledCollapser.h
Go to the documentation of this file.
1// # TiledCollapser.h: Abstract base class to collapse chunks for LatticeApply
2// # Copyright (C) 1996,1997,1998
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 LATTICES_TILEDCOLLAPSER_H
27#define LATTICES_TILEDCOLLAPSER_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/ArrayFwd.h>
32#include <casacore/scimath/Mathematics/NumericTraits.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// # Forward Declarations
37class IPosition;
38
39// <summary>
40// Abstract base class to collapse chunks for LatticeApply
41// </summary>
42
43// <use visibility=export>
44
45// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
46// </reviewed>
47
48// <prerequisite>
49// <li> <linkto class=LatticeApply>LatticeApply</linkto>
50// </prerequisite>
51
52// <etymology>
53// </etymology>
54
55// <synopsis>
56// This is an abstract base class for the collapsing of chunks to
57// be used in function <src>tiledApply</src>
58// in class <linkto class=LatticeApply>LatticeApply</linkto>.
59// It is meant for cases where an entire line or plane is not needed
60// (e.g. calculation of maximum). If that is needed (e.g. to calculate moment),
61// it is better to use function <src>LatticeApply::lineApply</src>
62// with class <linkto class=LineCollapser>LineCollapser</linkto>.
63// <p>
64// The user has to derive a concrete class from this base class
65// and implement the (pure) virtual functions.
66// <br> The main function is <src>process</src>, which needs to do the
67// calculation.
68// <br> Other functions make it possible to perform an initial check.
69// <p>
70// The class is Doubly templated. Ths first template type
71// is for the data type you are processing. The second type is
72// for what type you want the results of the processing assigned to.
73// For example, if you are computing sums of squares for statistical
74// purposes, you might use higher precision (FLoat->Double) for this.
75// No check is made that the template types are self-consistent.
76// </synopsis>
77
78// <example>
79// <srcblock>
80// </srcblock>
81// </example>
82
83// <motivation>
84// </motivation>
85
86// <todo asof="1997/08/01">
87// <li>
88// </todo>
89
90template <class T, class U = T>
92 public:
93 // Destructor
94 virtual ~TiledCollapser();
95
96 // The init function for a derived class.
97 // It can be used to check if <src>nOutPixelsPerCollapse</src>
98 // corresponds with the number of pixels produced per collapsed chunk.
99 // <br><src>processAxis</src> is the axis of the line being passed
100 // to the <src>process</src> function.
101 virtual void init(uInt nOutPixelsPerCollapse) = 0;
102
103 // Can the process function in the derived class handle a null mask pointer?
104 // If not, LatticeApply ensures that it'll always pass a mask block,
105 // even if the lattice does not have a mask (in that case that mask block
106 // contains all True values).
107 // <br>The default implementation returns False.
108 // <br>The function is there to make optimization possible when no masks
109 // are involved. On the other side, it allows the casual user to ignore
110 // optimization.
111 virtual Bool canHandleNullMask() const;
112
113 // Create and initialize the accumulator.
114 // The accumulator can be a cube with shape [n1,n2,n3],
115 // where <src>n2</src> is equal to <src>nOutPixelsPerCollapse</src>.
116 // However, one can also use several matrices as accumulator.
117 // <br> The data type of the accumulator can be any. E.g. when
118 // accumulating Float lattices, the accumulator could be of
119 // type Double to have enough precision.
120 // <br>In the <src>endAccumulator</src> function the accumulator
121 // data has to be copied into an Array object with the correct
122 // shape and data type.
123 virtual void initAccumulator(uInt64 n1, uInt64 n3) = 0;
124
125 // Collapse the given input data containing (<src>nrval</src> values
126 // with an increment of <src>inDataIncr</src> elements).
127 // <src>inMask</src> is a Bool block representing a mask with the
128 // same nr of values and increment as the input data. If a mask
129 // value is False, the corresponding input value is masked off.
130 // <br>When function <src>canHandleNullMask</src> returned True,
131 // it is possible that <src>inMask</src> is a null pointer indicating
132 // that the input has no mask, thus all values are valid.
133 // <br>
134 // The result(s) have to be stored in the accumulator at the given indices.
135 // <br><src>startPos</src> gives the lattice position of the first value.
136 // The position of other values can be calculated from index and shape
137 // using function <src>toPositionInArray</src> in class
138 // <linkto class=IPosition>IPosition</linkto>.
139 virtual void process(uInt accumIndex1, uInt accumIndex3, const T* inData, const Bool* inMask,
140 uInt inDataIncr, uInt inMaskIncr, uInt nrval, const IPosition& startPos,
141 const IPosition& shape) = 0;
142
143 // End the accumulator. It should return the accumulator as an
144 // Array of datatype U (e.g. double the precision of type T)
145 // with the given shape. The accumulator should thereafter be deleted when needed.
146 virtual void endAccumulator(Array<U>& result, Array<Bool>& resultMask,
147 const IPosition& shape) = 0;
148};
149
150} // namespace casacore
151
152#ifndef CASACORE_NO_AUTO_TEMPLATES
153#include <casacore/lattices/LatticeMath/TiledCollapser.tcc>
154#endif // # CASACORE_NO_AUTO_TEMPLATES
155#endif
virtual void initAccumulator(uInt64 n1, uInt64 n3)=0
Create and initialize the accumulator.
virtual void endAccumulator(Array< U > &result, Array< Bool > &resultMask, const IPosition &shape)=0
End the accumulator.
virtual ~TiledCollapser()
Destructor.
virtual Bool canHandleNullMask() const
Can the process function in the derived class handle a null mask pointer?
virtual void init(uInt nOutPixelsPerCollapse)=0
The init function for a derived class.
virtual void process(uInt accumIndex1, uInt accumIndex3, const T *inData, const Bool *inMask, uInt inDataIncr, uInt inMaskIncr, uInt nrval, const IPosition &startPos, const IPosition &shape)=0
Collapse the given input data containing (nrval values with an increment of inDataIncr elements).
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
unsigned long long uInt64
Definition aipsxtype.h:37