TiledCollapser.h

Classes

TiledCollapser -- Abstract base class to collapse chunks for LatticeApply (full description)

template <class T, class U=T> class TiledCollapser

Interface

Public Members
virtual ~TiledCollapser()
virtual void init (uInt nOutPixelsPerCollapse) = 0
virtual Bool canHandleNullMask() const
virtual void initAccumulator (uInt n1, uInt n3) = 0
virtual void process (uInt accumIndex1, uInt accumIndex3, const T* inData, const Bool* inMask, uInt inIncr, uInt nrval, const IPosition& startPos, const IPosition& shape) = 0
virtual void endAccumulator (Array<U>& result, Array<Bool>& resultMask, const IPosition& shape) = 0

Description

Review Status

Date Reviewed:
yyyy/mm/dd

Prerequisite

Etymology

Synopsis

This is an abstract base class for the collapsing of chunks to be used in function tiledApply in class LatticeApply. It is meant for cases where an entire line or plane is not needed (e.g. calculation of maximum). If that is needed (e.g. to calculate moment), it is better to use function LatticeApply::lineApply with class LineCollapser.

The user has to derive a concrete class from this base class and implement the (pure) virtual functions.
The main function is process, which needs to do the calculation.
Other functions make it possible to perform an initial check.

The class is Doubly templated. Ths first template type is for the data type you are processing. The second type is for what type you want the results of the processing assigned to. For example, if you are computing sums of squares for statistical purposes, you might use higher precision (FLoat->Double) for this. No check is made that the template types are self-consistent.

Example


 

Motivation

To Do

Member Description

virtual ~TiledCollapser()

Destructor

virtual void init (uInt nOutPixelsPerCollapse) = 0

The init function for a derived class. It can be used to check if nOutPixelsPerCollapse corresponds with the number of pixels produced per collapsed chunk.
processAxis is the axis of the line being passed to the process function.

virtual Bool canHandleNullMask() const

Can the process function in the derived class handle a null mask pointer? If not, LatticeApply ensures that it'll always pass a mask block, even if the lattice does not have a mask (in that case that mask block contains all True values).
The default implementation returns False.
The function is there to make optimization possible when no masks are involved. On the other side, it allows the casual user to ignore optimization.

virtual void initAccumulator (uInt n1, uInt n3) = 0

Create and initialize the accumulator. The accumulator can be a cube with shape [n1,n2,n3], where n2 is equal to nOutPixelsPerCollapse. However, one can also use several matrices as accumulator.
The data type of the accumulator can be any. E.g. when accumulating Float lattices, the accumulator could be of type Double to have enough precision.
In the endAccumulator function the accumulator data has to be copied into an Array object with the correct shape and data type.

virtual void process (uInt accumIndex1, uInt accumIndex3, const T* inData, const Bool* inMask, uInt inIncr, uInt nrval, const IPosition& startPos, const IPosition& shape) = 0

Collapse the given input data containing (nrval values with an increment of inIncr elements). inMask is a Bool block representing a mask with the same nr of values and increment as the input data. If a mask value is False, the corresponding input value is masked off.
When function canHandleNullMask returned True, it is possible that inMask is a null pointer indicating that the input has no mask, thus all values are valid.
The result(s) have to be stored in the accumulator at the given indices.
startPos gives the lattice position of the first value. The position of other values can be calculated from index and shape using function toPositionInArray in class IPosition.

virtual void endAccumulator (Array<U>& result, Array<Bool>& resultMask, const IPosition& shape) = 0

End the accumulator. It should return the accumulator as an Array of datatype U (e.g. double the precision of type T) with the given shape. The accumulator should thereafter be deleted when needed.