casacore
Loading...
Searching...
No Matches
ImageExpr.h
Go to the documentation of this file.
1// # ImageExpr.h: contains expressions involving images
2// # Copyright (C) 1994,1995,1996,1997,1999,2000,2001,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 IMAGES_IMAGEEXPR_H
27#define IMAGES_IMAGEEXPR_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/ArrayFwd.h>
32#include <casacore/images/Images/ImageInterface.h>
33#include <casacore/lattices/LEL/LatticeExpr.h>
34#include <casacore/casa/Containers/Record.h>
35#include <casacore/casa/Quanta/Unit.h>
36
37namespace casacore { // # NAMESPACE CASACORE - BEGIN
38
39// # Forward Declarations
40class JsonKVMap;
41class IPosition;
42class Slicer;
44template <class T>
46class String;
47
48// <summary>
49// Hold mathematical expressions involving ImageInterface objects
50// </summary>
51//
52// <use visibility=export>
53//
54// <reviewed reviewer="" date="" tests="tImageExpr.cc">
55// </reviewed>
56//
57// <prerequisite>
58// <li> LatticeExpr
59// <li> ImageInterface
60// </prerequisite>
61//
62// <etymology>
63// This class holds a LatticeExpr object but inherits from
64// ImageInterface hence ImageExpr
65// </etymology>
66//
67// <synopsis>
68// An ImageExpr object holds a LatticeExpr object which can be used
69// to evaluate mathematical expressions involving Lattices. ImageExpr
70// exists so that direct manipulation of LatticeExpr objects by methods
71// expecting an ImageInterface, rather than a Lattice can occur.
72//
73// The ImageExpr object is constructed from a LatticeExpr object, but
74// only if the latter has true Coordinates associated with it.
75// The ImageExpr object is not writable, so the ImageExpr object
76// functions like a read only ImageInterface.
77// </synopsis>
78//
79// <example>
80// <srcblock>
81// PagedImage<Float> a("imageB"); // Open PagedImages
82// PagedImage<Float> b("imageB");
83//
84// LatticeExprNode node(a+b); // Create ImageExpr
85// LatticeExpr<Float> lExpr(node);
86// ImageExpr<Float> iExpr(lExpr);
87//
88// LogOrigin or("imageImpl", "main()", WHERE); // Create statistics object
89// LogIO logger(or);
90// ImageStatistics<Float> stats(iExpr, logger);
91// Bool ok = stats.display(); // Display statistics
92//
93// </srcblock>
94// The ImageExpr object is evaluated during the call to
95// <src>stats.dislay()</src>. Previously, the expression tree
96// has been constructed, but not evaluated.
97// </example>
98//
99// <motivation>
100// This enables one to evaluate expressions but not to have to write them
101// out to an output image.
102// </motivation>
103//
104// <todo asof="1998/02/09">
105// </todo>
106
107template <class T>
108class ImageExpr : public ImageInterface<T> {
109 public:
110 // The default constructor
112
113 // Construct an ImageExpr from a LatticeExpr.
114 // The expr given should be the original expression string.
115 // The fileName argument is meant for ImageOpener.
116 // The coordinates are taken from the expression, usually the first image.
117 // An exception is thrown if the expression has no coordinates.
118 ImageExpr(const LatticeExpr<T>& latticeExpr, const String& expr,
119 const String& fileName = String());
120 ImageExpr(const LatticeExpr<T>& latticeExpr, const String& expr, const String& fileName,
121 const JsonKVMap&);
122
123 // Same as previous constructor, but the coordinates are taken from the
124 // given LELImageCoord object.
125 ImageExpr(const LatticeExpr<T>& latticeExpr, const String& expr, const String& fileName,
126 const LELImageCoord& imCoord);
127
128 // Copy constructor (reference semantics)
129 ImageExpr(const ImageExpr<T>& other);
130
131 // Destructor does nothing
133
134 // Assignment (reference semantics)
136
137 // Make a copy of the object (reference semantics).
138 virtual ImageInterface<T>* cloneII() const;
139
140 // Save the image in an AipsIO file with the given name.
141 // It can be opened by ImageOpener::openExpr.
142 virtual void save(const String& fileName) const;
143
144 // Set the file name.
146
147 // Replace the miscinfo in the ImageExpr, which writes the image.expr file.
148 // It can fail if, e.g., the directory to write to is not writable.
149 virtual Bool setMiscInfo(const RecordInterface& newInfo);
150
151 // Get the image type (returns name of derived class).
152 virtual String imageType() const;
153
154 // Has the object really a mask?
155 virtual Bool isMasked() const;
156
157 // Get the region used.
158 virtual const LatticeRegion* getRegionPtr() const;
159
160 // return the shape of the ImageExpr
161 virtual IPosition shape() const;
162
163 // Function which changes the shape of the ImageExpr.
164 // Throws an exception as ImageExpr is not writable.
165 virtual void resize(const TiledShape& newShape);
166
167 // Do the actual get of the mask data.
168 // The return value is always False, thus the buffer does not reference
169 // another array.
170 virtual Bool doGetMaskSlice(Array<Bool>& buffer, const Slicer& section);
171
172 // Do the actual get of the data.
173 virtual Bool doGetSlice(Array<T>& buffer, const Slicer& theSlice);
174
175 // putSlice is not possible on an expression, so it throws an exception.
176 virtual void doPutSlice(const Array<T>& sourceBuffer, const IPosition& where,
177 const IPosition& stride);
178
179 // If the object is persistent, the file name is given.
180 // Otherwise it returns the expression string given in the constructor.
181 virtual String name(Bool stripPath = False) const;
182
183 // Check class invariants.
184 virtual Bool ok() const;
185
186 // These are the implementations of the LatticeIterator letters.
187 // <note> not for public use </note>
188 virtual LatticeIterInterface<T>* makeIter(const LatticeNavigator& navigator, Bool useRef) const;
189
190 // Returns False, as the ImageExpr is not writable.
191 virtual Bool isWritable() const;
192
193 // Is the lattice persistent and can it be loaded by other processes as well?
194 virtual Bool isPersistent() const;
195
196 // Help the user pick a cursor for most efficient access if they only want
197 // pixel values and don't care about the order or dimension of the
198 // cursor.
199 virtual IPosition doNiceCursorShape(uInt maxPixels) const;
200
201 // Handle the (un)locking and syncing.
202 // <group>
203 virtual Bool lock(FileLocker::LockType, uInt nattempts);
204 virtual void unlock();
206 virtual void resync();
207 virtual void tempClose();
208 virtual void reopen();
209 // </group>
210
211 // Get the lattice expression.
212 const LatticeExpr<T>& expression() const { return latticeExpr_p; }
213
214 private:
215 void init(const LatticeExpr<T>& latticeExpr, const String& expr, const String& fileName,
216 const JsonKVMap&);
217
218 // # Data members
223};
224
225} // namespace casacore
226
227#ifndef CASACORE_NO_AUTO_TEMPLATES
228#include <casacore/images/Images/ImageExpr.tcc>
229#endif // # CASACORE_NO_AUTO_TEMPLATES
230#endif
LockType
Define the possible lock types.
Definition FileLocker.h:89
virtual Bool hasLock(FileLocker::LockType) const
virtual String imageType() const
Get the image type (returns name of derived class).
virtual void tempClose()
Temporarily close the lattice.
virtual Bool isPersistent() const
Is the lattice persistent and can it be loaded by other processes as well?
ImageExpr()
The default constructor.
virtual Bool ok() const
Check class invariants.
ImageExpr< T > & operator=(const ImageExpr< T > &other)
Assignment (reference semantics).
virtual Bool lock(FileLocker::LockType, uInt nattempts)
Handle the (un)locking and syncing.
virtual const LatticeRegion * getRegionPtr() const
Get the region used.
~ImageExpr()
Destructor does nothing.
virtual Bool doGetMaskSlice(Array< Bool > &buffer, const Slicer &section)
Do the actual get of the mask data.
ImageExpr(const LatticeExpr< T > &latticeExpr, const String &expr, const String &fileName, const JsonKVMap &)
ImageExpr(const LatticeExpr< T > &latticeExpr, const String &expr, const String &fileName=String())
Construct an ImageExpr from a LatticeExpr.
virtual IPosition doNiceCursorShape(uInt maxPixels) const
Help the user pick a cursor for most efficient access if they only want pixel values and don't care a...
const LatticeExpr< T > & expression() const
Get the lattice expression.
Definition ImageExpr.h:212
void setFileName(const String &name)
Set the file name.
Definition ImageExpr.h:145
virtual void reopen()
Explicitly reopen the temporarily closed lattice.
LatticeExpr< T > latticeExpr_p
Definition ImageExpr.h:219
virtual Bool isWritable() const
Returns False, as the ImageExpr is not writable.
virtual void unlock()
ImageExpr(const LatticeExpr< T > &latticeExpr, const String &expr, const String &fileName, const LELImageCoord &imCoord)
Same as previous constructor, but the coordinates are taken from the given LELImageCoord object.
virtual Bool doGetSlice(Array< T > &buffer, const Slicer &theSlice)
Do the actual get of the data.
virtual void resync()
Resynchronize the Lattice object with the lattice file.
virtual void resize(const TiledShape &newShape)
Function which changes the shape of the ImageExpr.
virtual ImageInterface< T > * cloneII() const
Make a copy of the object (reference semantics).
virtual String name(Bool stripPath=False) const
If the object is persistent, the file name is given.
void init(const LatticeExpr< T > &latticeExpr, const String &expr, const String &fileName, const JsonKVMap &)
virtual LatticeIterInterface< T > * makeIter(const LatticeNavigator &navigator, Bool useRef) const
These are the implementations of the LatticeIterator letters.
virtual Bool setMiscInfo(const RecordInterface &newInfo)
Replace the miscinfo in the ImageExpr, which writes the image.expr file.
virtual void doPutSlice(const Array< T > &sourceBuffer, const IPosition &where, const IPosition &stride)
putSlice is not possible on an expression, so it throws an exception.
ImageExpr(const ImageExpr< T > &other)
Copy constructor (reference semantics).
virtual IPosition shape() const
return the shape of the ImageExpr
virtual void save(const String &fileName) const
Save the image in an AipsIO file with the given name.
virtual Bool isMasked() const
Has the object really a mask?
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
RecordInterface()
The default constructor creates an empty record with a variable structure.
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40