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