casa
$Rev:20696$
|
Class to allow C++ expressions involving lattices. More...
#include <LatticeExpr.h>
Public Member Functions | |
LatticeExpr () | |
Default constructor. | |
LatticeExpr (const LatticeExprNode &expr) | |
Constructor from an arbitrary LatticeExprNode expression object. | |
LatticeExpr (const LatticeExprNode &expr, const IPosition &latticeShape) | |
LatticeExpr (const LatticeExpr< T > &other) | |
Copy constructor (reference semantics) | |
virtual | ~LatticeExpr () |
Destructor, does nothing. | |
LatticeExpr< T > & | operator= (const LatticeExpr< T > &other) |
Assignment (reference semantics) | |
virtual MaskedLattice< T > * | cloneML () const |
Make a copy of the derived object (reference semantics). | |
virtual Bool | isMasked () const |
Has the object really a mask? | |
virtual const LatticeRegion * | getRegionPtr () const |
Get the region used (always returns 0). | |
virtual Bool | isWritable () const |
Returns False, as the LatticeExpr lattice is not writable. | |
virtual Bool | lock (FileLocker::LockType, uInt nattempts) |
Handle locking of the LatticeExpr which is delegated to all of its parts. | |
virtual void | unlock () |
virtual Bool | hasLock (FileLocker::LockType) const |
virtual void | resync () |
Resynchronize the Lattice object with the lattice file. | |
virtual IPosition | shape () const |
Returns the shape of the Lattice including all degenerate axes (i.e. | |
virtual IPosition | doNiceCursorShape (uInt maxPixels) const |
Return the best cursor shape. | |
virtual LELCoordinates | lelCoordinates () const |
Returns the coordinates of the lattice expression. | |
virtual Bool | doGetSlice (Array< T > &buffer, const Slicer §ion) |
Do the actual get of the data. | |
virtual Bool | doGetMaskSlice (Array< Bool > &buffer, const Slicer §ion) |
Do the actual get of the mask data. | |
virtual void | doPutSlice (const Array< T > &sourceBuffer, const IPosition &where, const IPosition &stride) |
An expression is not writable so this functions throws an exception. | |
virtual void | copyDataTo (Lattice< T > &to) const |
Copy the data from this lattice to the given lattice. | |
virtual void | handleMathTo (Lattice< T > &to, int oper) const |
Handle the Math operators (+=, -=, *=, /=). | |
template<> | |
void | handleMathTo (Lattice< Bool > &, int) const |
Private Member Functions | |
void | init (const LatticeExprNode &expr) |
Initialize the object from the expression. | |
Private Attributes | |
LatticeExprNode | expr_p |
IPosition | shape_p |
LELArray< T > * | lastChunkPtr_p |
Slicer | lastSlicer_p |
Class to allow C++ expressions involving lattices.
Public interface
<h3>Review Status</h3><dl><dt>Date Reviewed:<dd>yyyy/mm/dd</dl>
The name is derived from the fact that this class provides an expression interface to the user which s/he may use to write C++ expressions involving Lattices.
This class provides an interface which allows the C++ programmer to enter expressions such as "sin(a)+b" where "a" and "b" are Lattices.
This class is termed an envelope class, and inside it are the letter classes which do the real work. In reality, the letter classes are actually accessed via a bridging class called LatticeExprNode, which exists to handle type conversions. The letter classes iterate through the Lattices and evaluate the expression for each chunk of the iteration (usually a tile shape).
It is in the LatticeExprNode class that all the available expression operations are defined, so you should look there to see what functionality is available.
A description of the implementation details of these classes can be found in Note 216
ArrayLattice<Float> f1(IPosition (2,nx,ny)); ArrayLattice<Float> f2(IPosition (2,nx,ny)); f2.set(2.0); f1.copyData(2*f2+f2);
In this example, the values of the pixels in Lattice f1 are set to the values resulting from the expression "2*f2 + f2" I.e. the expression is evaluated for each pixel in the Lattices
Note that : 1) the Lattice::copyData function is expecting a Lattice argument. 2) LatticeExpr inherits from Lattice and therefore a LatticeExpr object is a valid argument object type 3) The expression in the copyData call is automatically converted to a LatticeExprNode by the constructors and operators in LatticeExprNode 4) The LatticeExprNode object so created is automatically converted to a LatticeExpr by casting functions in LatticeExprNode.
ArrayLattice<Float> f1(IPosition (2,nx,ny)); ArrayLattice<Float> f2(IPosition (2,nx,ny)); ArrayLattice<Double> d(IPosition (2,nx,ny)); ArrayLattice<Complex> c(IPosition (2,nx,ny)); ArrayLattice<Bool> b(IPosition (2,nx,ny)); f2.set(1.0); d.set(2.0); c.set(Complex(2.0,3.0)); b.set(True); f1.copyData( (3.5*f2) + (cos(d)) - (10/min(d,f2)*(-abs(c))*ntrue(b)) - (C::pi) );
In this rather silly example, we fill Lattice "f1" with the result of the expression. The expression shows the use of constants, unary operations, binary operations, 1D and 2D functions. It also shows how mixed types can be handled. The output Lattice is a Float, whereas mixed into the expression are subexpressions involving Float, Double, Complex and Bool Lattices.
The Lattice expression classes enable the C++ programmer much simpler handling of mathematical expressions involving lattices. In addition, these classes provide the infrastructure on top of which we can build an image calculator for Glish users
Definition at line 141 of file LatticeExpr.h.
casa::LatticeExpr< T >::LatticeExpr | ( | ) |
Default constructor.
casa::LatticeExpr< T >::LatticeExpr | ( | const LatticeExprNode & | expr | ) |
Constructor from an arbitrary LatticeExprNode expression object.
An exception is thrown if the expression data type cannot be converted to the template data type. The shape argument is mandatory if the expression has no shape. If the expression has a shape and if shape is given, it is checked if they are equal.
casa::LatticeExpr< T >::LatticeExpr | ( | const LatticeExprNode & | expr, |
const IPosition & | latticeShape | ||
) |
casa::LatticeExpr< T >::LatticeExpr | ( | const LatticeExpr< T > & | other | ) |
Copy constructor (reference semantics)
virtual casa::LatticeExpr< T >::~LatticeExpr | ( | ) | [virtual] |
Destructor, does nothing.
virtual MaskedLattice<T>* casa::LatticeExpr< T >::cloneML | ( | ) | const [virtual] |
Make a copy of the derived object (reference semantics).
Implements casa::MaskedLattice< T >.
virtual void casa::LatticeExpr< T >::copyDataTo | ( | Lattice< T > & | to | ) | const [virtual] |
Copy the data from this lattice to the given lattice.
Reimplemented from casa::Lattice< T >.
virtual Bool casa::LatticeExpr< T >::doGetMaskSlice | ( | Array< Bool > & | buffer, |
const Slicer & | section | ||
) | [virtual] |
Do the actual get of the mask data.
The return value is always False, thus the buffer does not reference another array.
Reimplemented from casa::MaskedLattice< T >.
virtual Bool casa::LatticeExpr< T >::doGetSlice | ( | Array< T > & | buffer, |
const Slicer & | section | ||
) | [virtual] |
Do the actual get of the data.
The return value is always False, thus the buffer does not reference another array.
Implements casa::Lattice< T >.
virtual IPosition casa::LatticeExpr< T >::doNiceCursorShape | ( | uInt | maxPixels | ) | const [virtual] |
Return the best cursor shape.
Reimplemented from casa::LatticeBase.
virtual void casa::LatticeExpr< T >::doPutSlice | ( | const Array< T > & | sourceBuffer, |
const IPosition & | where, | ||
const IPosition & | stride | ||
) | [virtual] |
An expression is not writable so this functions throws an exception.
Implements casa::Lattice< T >.
virtual const LatticeRegion* casa::LatticeExpr< T >::getRegionPtr | ( | ) | const [virtual] |
Get the region used (always returns 0).
Implements casa::MaskedLattice< T >.
virtual void casa::LatticeExpr< T >::handleMathTo | ( | Lattice< T > & | to, |
int | oper | ||
) | const [virtual] |
Handle the Math operators (+=, -=, *=, /=).
They work similarly to copyData(To). However, they are not defined for Bool types, thus specialized below.
Reimplemented from casa::Lattice< T >.
void casa::LatticeExpr< Bool >::handleMathTo | ( | Lattice< Bool > & | , |
int | |||
) | const [inline] |
Reimplemented from casa::Lattice< T >.
Definition at line 244 of file LatticeExpr.h.
virtual Bool casa::LatticeExpr< T >::hasLock | ( | FileLocker::LockType | ) | const [virtual] |
Reimplemented from casa::LatticeBase.
void casa::LatticeExpr< T >::init | ( | const LatticeExprNode & | expr | ) | [private] |
Initialize the object from the expression.
virtual Bool casa::LatticeExpr< T >::isMasked | ( | ) | const [virtual] |
Has the object really a mask?
Reimplemented from casa::MaskedLattice< T >.
virtual Bool casa::LatticeExpr< T >::isWritable | ( | ) | const [virtual] |
Returns False, as the LatticeExpr lattice is not writable.
Reimplemented from casa::LatticeBase.
virtual LELCoordinates casa::LatticeExpr< T >::lelCoordinates | ( | ) | const [virtual] |
Returns the coordinates of the lattice expression.
Reimplemented from casa::LatticeBase.
virtual Bool casa::LatticeExpr< T >::lock | ( | FileLocker::LockType | , |
uInt | nattempts | ||
) | [virtual] |
Handle locking of the LatticeExpr which is delegated to all of its parts.
hasLock() is True if all parts of the expression return True.
It is strongly recommended to use class LatticeLocker to handle lattice locking. It also contains a more detailed explanation of the locking process.
Reimplemented from casa::LatticeBase.
LatticeExpr<T>& casa::LatticeExpr< T >::operator= | ( | const LatticeExpr< T > & | other | ) |
Assignment (reference semantics)
virtual void casa::LatticeExpr< T >::resync | ( | ) | [virtual] |
Resynchronize the Lattice object with the lattice file.
This function is only useful if no read-locking is used, ie. if the table lock option is UserNoReadLocking or AutoNoReadLocking. In that cases the table system does not acquire a read-lock, thus does not synchronize itself automatically.
By default the function does not do anything at all.
Reimplemented from casa::LatticeBase.
virtual IPosition casa::LatticeExpr< T >::shape | ( | ) | const [virtual] |
Returns the shape of the Lattice including all degenerate axes (i.e.
axes with a length of one)
Implements casa::LatticeBase.
virtual void casa::LatticeExpr< T >::unlock | ( | ) | [virtual] |
Reimplemented from casa::LatticeBase.
LatticeExprNode casa::LatticeExpr< T >::expr_p [private] |
Definition at line 236 of file LatticeExpr.h.
LELArray<T>* casa::LatticeExpr< T >::lastChunkPtr_p [private] |
Definition at line 238 of file LatticeExpr.h.
Slicer casa::LatticeExpr< T >::lastSlicer_p [private] |
Definition at line 239 of file LatticeExpr.h.
IPosition casa::LatticeExpr< T >::shape_p [private] |
Definition at line 237 of file LatticeExpr.h.