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