casacore
Loading...
Searching...
No Matches
LatticeExpr.h
Go to the documentation of this file.
1//# LatticeExpr.h: LatticeExpr.h
2//# Copyright (C) 1997,1998,1999,2000,2003
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_LATTICEEXPR_H
27#define LATTICES_LATTICEEXPR_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/lattices/Lattices/MaskedLattice.h>
33#include <casacore/lattices/LEL/LatticeExprNode.h>
34#include <casacore/lattices/LRegions/LatticeRegion.h>
35#include <casacore/casa/Arrays/Slicer.h>
36#include <casacore/casa/Arrays/ArrayFwd.h>
37
38namespace casacore { //# NAMESPACE CASACORE - BEGIN
39
40//# Forward Declarations
41template <class T> class LELArray;
42
43
44// <summary> Class to allow C++ expressions involving lattices </summary>
45
46// <use visibility=export>
47
48// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
49// </reviewed>
50
51// <prerequisite>
52// <li> <linkto class="Lattice"> Lattice</linkto>
53// <li> <linkto class="LatticeExprNode"> LatticeExprNode</linkto>
54//
55// </prerequisite>
56//
57// <etymology>
58// The name is derived from the fact that this class provides
59// an expression interface to the user which s/he may use to
60// write C++ expressions involving Lattices.
61// </etymology>
62//
63// <synopsis>
64// This class provides an interface which allows the C++ programmer
65// to enter expressions such as "sin(a)+b" where "a" and "b"
66// are Lattices.
67//
68// This class is termed an envelope class, and inside it are the
69// letter classes which do the real work. In reality, the letter
70// classes are actually accessed via a bridging class called
71// LatticeExprNode, which exists to handle type conversions.
72// The letter classes iterate through the Lattices and evaluate the
73// expression for each chunk of the iteration (usually a tile shape).
74//
75// It is in the LatticeExprNode class that all the available expression
76// operations are defined, so you should look there to see what
77// functionality is available.
78//
79// A description of the implementation details of these classes can
80// be found in
81// <a href="../notes/216.html">Note 216</a>
82// </synopsis>
83//
84// <example>
85// <srcblock>
86// ArrayLattice<Float> f1(IPosition (2,nx,ny));
87// ArrayLattice<Float> f2(IPosition (2,nx,ny));
88// f2.set(2.0);
89// f1.copyData(2*f2+f2);
90// </srcblock>
91//
92// In this example, the values of the pixels in Lattice f1 are set
93// to the values resulting from the expression "2*f2 + f2"
94// I.e. the expression is evaluated for each pixel in the Lattices
95//
96// Note that :
97// 1) the Lattice::copyData function is expecting a Lattice argument.
98// 2) LatticeExpr inherits from Lattice and therefore a LatticeExpr
99// object is a valid argument object type
100// 3) The expression in the copyData call is automatically converted to
101// a LatticeExprNode by the constructors and operators in LatticeExprNode
102// 4) The LatticeExprNode object so created is automatically converted
103// to a LatticeExpr by casting functions in LatticeExprNode.
104// </example>
105//
106// <example>
107// <srcblock>
108// ArrayLattice<Float> f1(IPosition (2,nx,ny));
109// ArrayLattice<Float> f2(IPosition (2,nx,ny));
110// ArrayLattice<Double> d(IPosition (2,nx,ny));
111// ArrayLattice<Complex> c(IPosition (2,nx,ny));
112// ArrayLattice<Bool> b(IPosition (2,nx,ny));
113//
114// f2.set(1.0); d.set(2.0); c.set(Complex(2.0,3.0)); b.set(True);
115// f1.copyData( (3.5*f2) + (cos(d)) - (10/min(d,f2)*(-abs(c))*ntrue(b)) - (C::pi) );
116// </srcblock>
117//
118// In this rather silly example, we fill Lattice "f1" with the result of the
119// expression. The expression shows the use of constants, unary operations,
120// binary operations, 1D and 2D functions. It also shows how mixed types can
121// be handled. The output Lattice is a Float, whereas mixed into the
122// expression are subexpressions involving Float, Double, Complex and Bool
123// Lattices.
124//
125// </example>
126//
127// <motivation>
128// The Lattice expression classes enable the C++ programmer much simpler
129// handling of mathematical expressions involving lattices. In addition,
130// these classes provide the infrastructure on top of which we can build
131// an image calculator for Glish users
132// </motivation>
133
134// <todo asof="1997/01/15">
135// <li> masks
136// <li> regions
137// </todo>
138
139
140template <class T> class LatticeExpr : public MaskedLattice<T>
141{
142public:
143
144 // Default constructor
146
147 // Constructor from an arbitrary LatticeExprNode expression object.
148 // An exception is thrown if the expression data type cannot be
149 // converted to the template data type.
150 // The shape argument is mandatory if the expression has no shape.
151 // If the expression has a shape and if shape is given, it is checked
152 // if they are equal.
154 LatticeExpr (const LatticeExprNode& expr, const IPosition& latticeShape);
155
156 // Copy constructor (reference semantics)
158
159 // Destructor, does nothing
160 virtual ~LatticeExpr();
161
162 // Assignment (reference semantics)
164
165 // Make a copy of the derived object (reference semantics).
166 virtual MaskedLattice<T>* cloneML() const;
167
168 // Has the object really a mask?
169 virtual Bool isMasked() const;
170
171 // Get the region used (always returns 0).
172 virtual const LatticeRegion* getRegionPtr() const;
173
174 // Returns False, as the LatticeExpr lattice is not writable.
175 virtual Bool isWritable() const;
176
177 // Handle locking of the LatticeExpr which is delegated to all of its parts.
178 // <br>hasLock() is True if all parts of the expression return True.
179 // <br>It is strongly recommended to use class
180 // <linkto class=LatticeLocker>LatticeLocker</linkto> to
181 // handle lattice locking. It also contains a more detailed
182 // explanation of the locking process.
183 // <group>
184 virtual Bool lock (FileLocker::LockType, uInt nattempts);
185 virtual void unlock();
187 // </group>
188
189 // Resynchronize the Lattice object with the lattice file.
190 // This function is only useful if no read-locking is used, ie.
191 // if the table lock option is UserNoReadLocking or AutoNoReadLocking.
192 // In that cases the table system does not acquire a read-lock, thus
193 // does not synchronize itself automatically.
194 // <br>By default the function does not do anything at all.
195 virtual void resync();
196
197 // Returns the shape of the Lattice including all degenerate axes
198 // (i.e. axes with a length of one)
199 virtual IPosition shape() const;
200
201 // Return the best cursor shape.
202 virtual IPosition doNiceCursorShape (uInt maxPixels) const;
203
204 // Returns the coordinates of the lattice expression.
206
207 // Do the actual get of the data.
208 // The return value is always False, thus the buffer does not reference
209 // another array.
210 virtual Bool doGetSlice (Array<T>& buffer, const Slicer& section);
211
212 // Do the actual get of the mask data.
213 // The return value is always False, thus the buffer does not reference
214 // another array.
215 virtual Bool doGetMaskSlice (Array<Bool>& buffer, const Slicer& section);
216
217 // An expression is not writable so this functions throws an exception.
218 virtual void doPutSlice (const Array<T>& sourceBuffer,
219 const IPosition& where,
220 const IPosition& stride);
221
222 // Copy the data from this lattice to the given lattice.
223 virtual void copyDataTo (Lattice<T>& to) const;
224
225 // Handle the Math operators (+=, -=, *=, /=).
226 // They work similarly to copyData(To).
227 // However, they are not defined for Bool types, thus specialized below.
228 virtual void handleMathTo (Lattice<T>& to, int oper) const;
229
230private:
231 // Initialize the object from the expression.
232 void init (const LatticeExprNode& expr);
233
234
235 LatticeExprNode expr_p; //# its shape can be undefined
236 IPosition shape_p; //# this shape is always defined
239};
240
241
242template<> inline
244 { throwBoolMath(); }
245
246
247
248} //# NAMESPACE CASACORE - END
249
250#ifndef CASACORE_NO_AUTO_TEMPLATES
251#include <casacore/lattices/LEL/LatticeExpr.tcc>
252#endif //# CASACORE_NO_AUTO_TEMPLATES
253#endif
LockType
Define the possible lock types.
Definition FileLocker.h:93
virtual void resync()
Resynchronize the Lattice object with the lattice file.
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 MaskedLattice< T > * cloneML() const
Make a copy of the derived object (reference semantics).
virtual IPosition doNiceCursorShape(uInt maxPixels) const
Return the best cursor shape.
virtual Bool doGetMaskSlice(Array< Bool > &buffer, const Slicer &section)
Do the actual get of the mask data.
virtual Bool doGetSlice(Array< T > &buffer, const Slicer &section)
Do the actual get of the data.
virtual void copyDataTo(Lattice< T > &to) const
Copy the data from this lattice to the given lattice.
LELArray< T > * lastChunkPtr_p
virtual ~LatticeExpr()
Destructor, does nothing.
virtual Bool isWritable() const
Returns False, as the LatticeExpr lattice is not writable.
LatticeExpr(const LatticeExpr< T > &other)
Copy constructor (reference semantics)
LatticeExpr(const LatticeExprNode &expr)
Constructor from an arbitrary LatticeExprNode expression object.
virtual LELCoordinates lelCoordinates() const
Returns the coordinates of the lattice expression.
LatticeExpr(const LatticeExprNode &expr, const IPosition &latticeShape)
LatticeExprNode expr_p
LatticeExpr< T > & operator=(const LatticeExpr< T > &other)
Assignment (reference semantics)
virtual Bool hasLock(FileLocker::LockType) const
virtual Bool isMasked() const
Has the object really a mask?
virtual IPosition shape() const
Returns the shape of the Lattice including all degenerate axes (i.e.
void init(const LatticeExprNode &expr)
Initialize the object from the expression.
virtual void handleMathTo(Lattice< T > &to, int oper) const
Handle the Math operators (+=, -=, *=, /=).
virtual Bool lock(FileLocker::LockType, uInt nattempts)
Handle locking of the LatticeExpr which is delegated to all of its parts.
LatticeExpr()
Default constructor.
virtual const LatticeRegion * getRegionPtr() const
Get the region used (always returns 0).
virtual void unlock()
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40