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