casacore
Loading...
Searching...
No Matches
TempImage.h
Go to the documentation of this file.
1//# TempImage.h: Temporary astronomical images
2//# Copyright (C) 1998,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_TEMPIMAGE_H
27#define IMAGES_TEMPIMAGE_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/images/Images/ImageInterface.h>
33#include <casacore/lattices/Lattices/TiledShape.h>
34#include <casacore/lattices/Lattices/TempLattice.h>
35
36
37namespace casacore { //# NAMESPACE CASACORE - BEGIN
38
39// <summary>
40// Temporary astronomical images.
41// </summary>
42
43// <use visibility=export>
44
45// <reviewed reviewer="" date="" tests="tTempImage.cc" demos="">
46// </reviewed>
47
48// <prerequisite>
49// <li> <linkto class=CoordinateSystem>CoordinateSystem</linkto>
50// <li> <linkto class=ImageInterface>ImageInterface</linkto>
51// <li> <linkto class=TempLattice>TempLattice</linkto>
52// </prerequisite>
53
54// <etymology>
55// The TempImage name comes from its role as the Image class for temporary
56// storage.
57// </etymology>
58
59// <synopsis>
60// The class <src>TempImage</src> is useful for storing temporary images
61// for which it is not known whether they can be held in memory.
62// It uses class <linkto class=TempLattice>TempLattice</linkto> to
63// hold the image in memory when it is small enough. Otherwise it is
64// held in a temporary file. Similarly to <src>TempLattice</src>
65// one can give the maximum memory to use to control when the image
66// can be held in memory.
67// <br>
68// The other Image information like coordinates, units, and miscinfo
69// is held in member variables and disappears when the TempImage object
70// is destructed.
71// <p>
72// It is possibly to temporarily close a TempImage, which only takes effect
73// when it is created as a PagedArray. In this way it is possible to reduce
74// the number of open files in case a lot of TempImage objects are used.
75// A temporarily closed TempImage will be reopened automatically when needed.
76// It can also be reopened explicitly.
77// </synopsis>
78
79// <example>
80// <srcblock>
81// </srcblock>
82// </example>
83
84// <motivation>
85// The size of astronomical data can be very large. The ability to fit an
86// entire image into random access memory cannot be guaranteed. Paging from
87// disk pieces of the image appeared to be the way to deal with this problem.
88// </motivation>
89
90//# <todo asof="1998/10/27">
91//# <li> Maybe move applyMask, maskPtr_p, etc to base class ImageInterface
92//# </todo>
93
94
95template<class T> class TempImage: public ImageInterface<T>
96{
97public:
98 // The default constructor creates an empty image.
100
101 // Construct a temporary Image from shape and coordinate information.
102 // If the image is sufficiently small, it is kept in memory.
103 // Otherwise it is kept in a temporary disk table. It can
104 // be forced to disk by setting maxMemoryinMB=0.
105 // The algorithm is the same as in class
106 // <linkto class=TempLattice>TempLattice</linkto>.
107 TempImage (const TiledShape& mapShape,
108 const CoordinateSystem& coordinateInfo,
109 Int maxMemoryInMB=-1);
110
111 TempImage (const TiledShape& mapShape,
112 const CoordinateSystem& coordinateInfo,
113 Double maxMemoryInMB);
114
115 // Copy constructor (reference semantics).
116 TempImage (const TempImage<T>& other);
117
118 // Destructor
120
121 // Assignment operator (reference semantics).
123
124 // Make a copy of the object (reference semantics).
125 virtual ImageInterface<T>* cloneII() const;
126
127 // Get the image type (returns name of derived class).
128 virtual String imageType() const;
129
130 // Is the TempImage paged to disk?
131 virtual Bool isPaged() const;
132
133 // Can the lattice data be referenced as an array section?
134 virtual Bool canReferenceArray() const;
135
136 // Is the TempImage writable?
137 virtual Bool isWritable() const;
138
139 // Set the default pixelmask to the mask with the given name
140 // (which has to exist in the "masks" group).
141 // If the image table is writable, the setting is persistent by writing
142 // the name as a keyword.
143 // If the given regionName is the empty string,
144 // the default pixelmask is unset.
145 virtual void setDefaultMask (const String& maskName);
146
147 // Delete the pixel mask attached to the TempImage.
148 // Does nothing if there isn't one
150 { setDefaultMask (""); }
151
152 // Use the mask as specified.
153 // If a mask was already in use, it is replaced by the new one.
155
156 // Remove a region/mask belonging to the image from the given group
157 // (which can be Any).
158 // If a mask removed is the default mask, the image gets unmasked.
159 // <br>Optionally an exception is thrown if the region does not exist.
160 virtual void removeRegion (const String& name,
162 Bool throwIfUnknown = True);
163
164 // Attach a mask to the TempImage.
165 // It replaces a probably already attached mask.
166 // It has to have the same shape as the image.
167 virtual void attachMask (const Lattice<Bool>& mask);
168
169 // It a mask attached to the image?
170 virtual Bool isMasked() const;
171
172 // Does the image object use a pixelmask?
173 // This is similar to <src>isMasked()</src>.
174 virtual Bool hasPixelMask() const;
175
176 // Get access to the pixelmask used.
177 // An exception is thrown if the image does not use a pixelmask.
178 // <group>
179 virtual const Lattice<Bool>& pixelMask() const;
181 // </group>
182
183 // Get a section of the mask.
184 // It throws an exception if there is no mask.
185 virtual Bool doGetMaskSlice (Array<Bool>& buffer, const Slicer& section);
186
187 // Flush the data.
188 virtual void flush();
189
190 // Close the TempImage temporarily (if it is paged to disk).
191 // Note that a possible mask is not closed.
192 // It'll be reopened automatically when needed or when
193 // <src>reopen</src> is called explicitly.
194 virtual void tempClose();
195
196 // If needed, reopen a temporarily closed TempLattice.
197 virtual void reopen();
198
199 // Function which changes the shape of the image (N.B. the data is thrown
200 // away - the Image will be filled with nonsense afterwards)
201 virtual void resize (const TiledShape& newShape);
202
203 // Return the name of the current TempImage object.
204 // It is always "Temporary_Image"
205 virtual String name (Bool stripPath=False) const;
206
207 // Return the shape of the image
208 virtual IPosition shape() const;
209
210 // Function which sets all of the elements in the Lattice to a value.
211 virtual void set (const T& value);
212
213 // Replace every element, x, of the lattice with the result of f(x).
214 // You must pass in the address of the function -- so the function
215 // must be declared and defined in the scope of your program.
216 // Both versions of apply require a function that accepts a single
217 // argument of type T (the Lattice template actual type) and returns
218 // a result of the same type. The first apply expects a function with
219 // an argument passed by value; the second expects the argument to
220 // be passed by const reference. The first form ought to run faster
221 // for the built-in types, which may be an issue for large images
222 // stored in memory, where disk access is not an issue.
223 // <group>
224 virtual void apply (T (*function)(T));
225 virtual void apply (T (*function)(const T&));
226 virtual void apply (const Functional<T,T>& function);
227 // </group>
228
229 // Get or put a single pixel.
230 // Note that the function operator () can also be used to get a pixel.
231 // <group>
232 virtual T getAt (const IPosition& where) const;
233 virtual void putAt (const T& value, const IPosition& where);
234 // </group>
235
236 // This is the implementations of the letters for the envelope Iterator
237 // class <note> Not for public use </note>
239 (const LatticeNavigator& navigator,
240 Bool useRef) const;
241
242 // Returns the maximum recommended number of pixels for a cursor.
243 // This is the number of pixels in a tile.
244 virtual uInt advisedMaxPixels() const;
245
246 // Help the user pick a cursor for most efficient access.
247 virtual IPosition doNiceCursorShape (uInt maxPixels) const;
248
249 // Maximum size - not necessarily all used. In pixels.
250 virtual uInt maximumCacheSize() const;
251
252 // Set the maximum (allowed) cache size as indicated.
253 virtual void setMaximumCacheSize (uInt howManyPixels);
254
255 // Set the cache size as to "fit" the indicated path.
256 virtual void setCacheSizeFromPath (const IPosition& sliceShape,
257 const IPosition& windowStart,
258 const IPosition& windowLength,
259 const IPosition& axisPath);
260
261 // Set the actual cache size for this Array to be be big enough for the
262 // indicated number of tiles. This cache is not shared with PagedArrays
263 // in other rows and is always clipped to be less than the maximum value
264 // set using the setMaximumCacheSize member function.
265 // tiles. Tiles are cached using a first in first out algorithm.
266 virtual void setCacheSizeInTiles (uInt howManyTiles);
267
268 // Clears and frees up the caches, but the maximum allowed cache size is
269 // unchanged from when setCacheSize was called
270 virtual void clearCache();
271
272 // Report on cache success.
273 virtual void showCacheStatistics (ostream& os) const;
274
275 // Check for symmetry in data members.
276 virtual Bool ok() const;
277
278protected:
279 // Get the region used (it always returns 0).
280 virtual const LatticeRegion* getRegionPtr() const;
281
282 // Function which extracts an array from the map.
283 virtual Bool doGetSlice (Array<T>& buffer, const Slicer& theSlice);
284
285 // Function to replace the values in the map with soureBuffer.
286 virtual void doPutSlice (const Array<T>& sourceBuffer,
287 const IPosition& where,
288 const IPosition& stride);
289
290
291private:
293 void applyMask (const String& maskName);
294
297
298 //# Make members of parent class known.
299public:
300 using ImageInterface<T>::logger;
306protected:
308};
309
310//# Declare extern templates for often used types.
311 extern template class TempImage<Float>;
312 extern template class TempImage<Complex>;
313
314} //# NAMESPACE CASACORE - END
315
316#ifndef CASACORE_NO_AUTO_TEMPLATES
317#include <casacore/images/Images/TempImage.tcc>
318#endif //# CASACORE_NO_AUTO_TEMPLATES
319#endif
void setCoordsMember(const CoordinateSystem &coords)
Set the coordinate system variable.
LoggerHolder & logger()
Get access to the LoggerHolder.
virtual String getDefaultMask() const
Get the name of the default pixelmask.
virtual ImageRegion * getImageRegionPtr(const String &name, RegionHandler::GroupType=RegionHandler::Any, Bool throwIfUnknown=True) const
Get a region/mask belonging to the image from the given group (which can be Any).
virtual Bool hasRegion(const String &regionName, RegionHandler::GroupType=RegionHandler::Any) const
Does the image have a region with the given name?
virtual Bool setCoordinateInfo(const CoordinateSystem &coords)
Functions to set or replace the coordinate information in the Image Returns False on failure,...
const CoordinateSystem & coordinates() const
GroupType
Define the possible group types (regions or masks).
String: the storage and methods of handling collections of characters.
Definition String.h:223
virtual void removeRegion(const String &name, RegionHandler::GroupType=RegionHandler::Any, Bool throwIfUnknown=True)
Remove a region/mask belonging to the image from the given group (which can be Any).
~TempImage()
Destructor.
virtual void flush()
Flush the data.
virtual void setMaximumCacheSize(uInt howManyPixels)
Set the maximum (allowed) cache size as indicated.
virtual String imageType() const
Get the image type (returns name of derived class).
TempImage()
The default constructor creates an empty image.
virtual void set(const T &value)
Function which sets all of the elements in the Lattice to a value.
virtual const LatticeRegion * getRegionPtr() const
Get the region used (it always returns 0).
TempLattice< T > * mapPtr_p
Definition TempImage.h:295
virtual Bool doGetSlice(Array< T > &buffer, const Slicer &theSlice)
Function which extracts an array from the map.
virtual T getAt(const IPosition &where) const
Get or put a single pixel.
virtual void reopen()
If needed, reopen a temporarily closed TempLattice.
void removeMask()
Delete the pixel mask attached to the TempImage.
Definition TempImage.h:149
virtual void attachMask(const Lattice< Bool > &mask)
Attach a mask to the TempImage.
virtual void setCacheSizeFromPath(const IPosition &sliceShape, const IPosition &windowStart, const IPosition &windowLength, const IPosition &axisPath)
Set the cache size as to "fit" the indicated path.
TempImage< T > & operator=(const TempImage< T > &other)
Assignment operator (reference semantics).
virtual void doPutSlice(const Array< T > &sourceBuffer, const IPosition &where, const IPosition &stride)
Function to replace the values in the map with soureBuffer.
void applyMaskSpecifier(const MaskSpecifier &)
virtual Bool canReferenceArray() const
Can the lattice data be referenced as an array section?
virtual uInt advisedMaxPixels() const
Returns the maximum recommended number of pixels for a cursor.
virtual void useMask(MaskSpecifier=MaskSpecifier())
Use the mask as specified.
virtual void putAt(const T &value, const IPosition &where)
Put the value of a single element.
virtual Lattice< Bool > & pixelMask()
virtual Bool doGetMaskSlice(Array< Bool > &buffer, const Slicer &section)
Get a section of the mask.
virtual uInt maximumCacheSize() const
Maximum size - not necessarily all used.
TempImage(const TempImage< T > &other)
Copy constructor (reference semantics).
virtual LatticeIterInterface< T > * makeIter(const LatticeNavigator &navigator, Bool useRef) const
This is the implementations of the letters for the envelope Iterator class Note: Not for public use
virtual void apply(const Functional< T, T > &function)
virtual void apply(T(*function)(const T &))
virtual Bool isMasked() const
It a mask attached to the image?
virtual ImageInterface< T > * cloneII() const
Make a copy of the object (reference semantics).
virtual void setCacheSizeInTiles(uInt howManyTiles)
Set the actual cache size for this Array to be be big enough for the indicated number of tiles.
virtual Bool isWritable() const
Is the TempImage writable?
virtual void clearCache()
Clears and frees up the caches, but the maximum allowed cache size is unchanged from when setCacheSiz...
virtual void apply(T(*function)(T))
Replace every element, x, of the lattice with the result of f(x).
virtual Bool ok() const
Check for symmetry in data members.
virtual Bool hasPixelMask() const
Does the image object use a pixelmask? This is similar to isMasked().
virtual String name(Bool stripPath=False) const
Return the name of the current TempImage object.
virtual IPosition shape() const
Return the shape of the image.
virtual void showCacheStatistics(ostream &os) const
Report on cache success.
TempImage(const TiledShape &mapShape, const CoordinateSystem &coordinateInfo, Double maxMemoryInMB)
Lattice< Bool > * maskPtr_p
Definition TempImage.h:296
virtual const Lattice< Bool > & pixelMask() const
Get access to the pixelmask used.
virtual void resize(const TiledShape &newShape)
Function which changes the shape of the image (N.B.
virtual IPosition doNiceCursorShape(uInt maxPixels) const
Help the user pick a cursor for most efficient access.
virtual Bool isPaged() const
Is the TempImage paged to disk?
TempImage(const TiledShape &mapShape, const CoordinateSystem &coordinateInfo, Int maxMemoryInMB=-1)
Construct a temporary Image from shape and coordinate information.
virtual void tempClose()
Close the TempImage temporarily (if it is paged to disk).
void applyMask(const String &maskName)
virtual void setDefaultMask(const String &maskName)
Set the default pixelmask to the mask with the given name (which has to exist in the "masks" group).
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
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
const Bool True
Definition aipstype.h:41
double Double
Definition aipstype.h:53