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