casacore
Loading...
Searching...
No Matches
ImageInterface.h
Go to the documentation of this file.
1//# ImageInterface.h: a base class for astronomical images
2//# Copyright (C) 1996,1997,1998,1999,2000,2001
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_IMAGEINTERFACE_H
27#define IMAGES_IMAGEINTERFACE_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/casa/Arrays/ArrayFwd.h>
33#include <casacore/images/Regions/RegionHandler.h>
34#include <casacore/images/Images/MaskSpecifier.h>
35#include <casacore/images/Images/ImageInfo.h>
36#include <casacore/images/Images/ImageAttrHandler.h>
37#include <casacore/lattices/Lattices/MaskedLattice.h>
38#include <casacore/coordinates/Coordinates/CoordinateSystem.h>
39#include <casacore/tables/LogTables/LoggerHolder.h>
40#include <casacore/tables/Tables/TableRecord.h>
41#include <casacore/casa/Quanta/Unit.h>
42
43namespace casacore { //# NAMESPACE CASACORE - BEGIN
44
45//# Forward Declarations
46template <class T> class LatticeIterInterface;
47template <class T> class COWPtr;
48class ImageRegion;
49class IPosition;
50class TiledShape;
51
52
53// <summary>
54// A base class for astronomical images.
55// </summary>
56
57// <use visibility=export>
58
59// <reviewed reviewer="" date="" tests="" demos="">
60// </reviewed>
61
62// <prerequisite>
63// <li> <linkto class=Lattice>Lattices</linkto>
64// <li> <linkto class=CoordinateSystem>CoordinateSystem</linkto>
65// </prerequisite>
66
67// <etymology>
68// The ImageInterface class name is derived from its role as the cookie cutter
69// Interface base class for Images.
70// </etymology>
71
72// <synopsis>
73// The ImageInterface class is an abstract base class. All Image classes
74// should derive from this class to ensure functions which operate on Images
75// will work for all Image derivations.
76//
77// An Image is currently defined as an Array of pixels, a Boolean mask,
78// defining which pixels are valid and coordinates to define the reference
79// frame. The only concrete class currently derived from this Interface is
80// PagedImage, which allows the image to be stored on disk, and only reads
81// specified portions of the image into memory.
82// </synopsis>
83
84// <example>
85// As this is an abstract base class it is not possible to construct an
86// instance of this object. It can however be used as a function argument.<br>
87// eg 1. (used in dImageInterface.cc)
88// <srcblock>
89// Float sumPixels(const ImageInterface<Float>& image){
90// uInt rowLength = image.shape()(0);
91// IPosition rowShape(image.ndim());
92// rowShape = 1; rowShape(0) = rowLength;
93// Float sumPix = 0;
94// RO_LatticeIterator<Float> iter(image, rowShape);
95// while(!iter.atEnd()){
96// sumPix += sum(iter.vectorCursor());
97// iter++;
98// }
99// return sumPix;
100// }
101// </srcblock>
102//
103// The main purpose of this class is for programming objects, the following
104// example is of how one would derive from ImageInterface: <br>
105// eg 2.
106// <srcblock>
107// template <class T> class myNewImage : public ImageInterface<T>
108// {
109// public:
110// // default constructor
111// myNewImage();
112//
113// // argumented constructor
114// myNewImage(...);
115//
116// // destructor
117// ~myNewImage
118//
119// // the shape function is forced upon us by the Lattice base class
120// IPosition shape() const;
121//
122// // doGetSlice is another function required of all Lattice objects.
123// Bool doGetSlice(<Array<T>& buffer, const Slicer& section);
124//
125// // etc...
126// private:
127// // put the actual map data down here.
128// // etc...
129// };
130// </srcblock>
131// </example>
132
133// <motivation>
134// The use of abstract base classes to guide inheritance seemed appropriate
135// for Images to ensure that CoordinateSystems and masking get handled
136// uniformly.
137// </motivation>
138
139// <todo asof="1995/04/25">
140// <li> replace ImageCoordinates
141// </todo>
142
143
144template <class T> class ImageInterface: public MaskedLattice<T>
145{
146 //# Make members of parent class known.
147public:
148 using MaskedLattice<T>::shape;
149
150public:
152
153 // Construct for a specific region handler object.
154 ImageInterface (const RegionHandler& regionHandler);
155
156 // Copy constructor (copy semantics).
158
160
161 // Make a copy of the derived object (reference semantics).
162 // <group>
163 virtual MaskedLattice<T>* cloneML() const;
164 virtual ImageInterface<T>* cloneII() const = 0;
165 // </group>
166
167 // Get the image type (returns name of derived class).
168 virtual String imageType() const = 0;
169
170 // Function which changes the shape of the image (N.B. the data is thrown
171 // away - the Image will be filled with nonsense afterwards)
172 virtual void resize (const TiledShape& newShape) = 0;
173
174 // Function which get and set the units associated with the image
175 // pixels (i.e. the "brightness" unit). <src>setUnits()</src> returns
176 // False if it cannot set the unit for some reason (e.g. the underlying
177 // file is not writable).
178 // <group>
179 virtual Bool setUnits (const Unit& newUnits);
180 virtual const Unit& units() const
181 { return unit_p; }
182 // </group>
183
184 // Return the name of the current ImageInterface object. This will generally
185 // be a file name for images that have a persistent form. Any path
186 // before the actual file name can be optionally stripped off.
187 virtual String name (Bool stripPath=False) const = 0;
188
189 // Functions to set or replace the coordinate information in the Image
190 // Returns False on failure, e.g. if the number of axes do not match.
191 // <group>
192 virtual Bool setCoordinateInfo (const CoordinateSystem& coords);
194 { return coords_p; }
195 // </group>
196
197 // Function to get a LELCoordinate object containing the coordinates.
199
200 // Get access to the LoggerHolder.
201 // <group>
203 { return log_p; }
204 const LoggerHolder& logger() const
205 { return log_p; }
206 // </group>
207
208 // Allow messages to be logged to this ImageInterface.
209 // <group>
211 { return logger().logio(); }
212 const LogIO& logSink() const
213 { return const_cast<ImageInterface<T>*>(this)->logSink(); }
214 // </group>
215
216 // Add the messages from the other image logger to this one.
217 void appendLog (const LoggerHolder& other)
218 { log_p.append (other); }
219
220 // Often we have miscellaneous information we want to attach to an image.
221 // This is where it goes.
222 // <br>
223 // Note that setMiscInfo REPLACES the information with the new information.
224 // It can fail if, e.g., the underlying table is not writable.
225 // <group>
226 const TableRecord& miscInfo() const
227 { return miscInfo_p; }
228 virtual Bool setMiscInfo (const RecordInterface& newInfo);
229 // </group>
230
231 // The ImageInfo object contains some miscellaneous information about the image
232 // which unlike that stored in MiscInfo, has a standard list of things,
233 // such as the restoring beam.
234 //
235 // Note that setImageInfo REPLACES the information with the new information.
236 // It is up to the derived class to make the ImageInfo permanent.
237 // <group>
238 const ImageInfo& imageInfo() const
239 { return imageInfo_p; }
240 // Get non-const access to the ImageInfo.
243 virtual Bool setImageInfo (const ImageInfo& info);
244 // </group>
245
246 // Get access to the attribute handler.
247 // By default an empty handler is returned where no groups can be added to.
248 // <group>
249 virtual ImageAttrHandler& attrHandler (Bool createHandler=False);
251 { return const_cast<ImageInterface<T>*>(this)->attrHandler(False); }
252 // </group>
253
254 // Can the image handle region definition?
257
258 // Make a mask which is suitable for the type of image.
259 // Optionally the mask can be initialized with the given value
260 // (by default it will not).
261 // <br>Optionally the mask can be defined as an image region/mask
262 // and turned in the default mask for the image. By default it will.
264 Bool defineAsRegion = True,
265 Bool setAsDefaultMask = True,
266 Bool initialize = False,
267 Bool value = True);
268
269 // Define a region/mask belonging to the image.
270 // The group type determines if it stored as a region or mask.
271 // If overwrite=False, an exception will be thrown if the region
272 // already exists.
273 // <br>An exception is thrown if canDefineRegion is False.
274 virtual void defineRegion (const String& name, const ImageRegion& region,
276 Bool overwrite = False);
277
278 // Does the image have a region with the given name?
279 virtual Bool hasRegion (const String& regionName,
281
282 // Get a region/mask belonging to the image from the given group
283 // (which can be Any).
284 // <br>Optionally an exception is thrown if the region does not exist.
285 // A zero pointer is returned if the region does not exist.
286 // The caller has to delete the <src>ImageRegion</src> object created.
288 (const String& name,
290 Bool throwIfUnknown = True) const;
291
292 // Rename a region.
293 // If a region with the new name already exists, it is deleted or
294 // an exception is thrown (depending on <src>overwrite</src>).
295 // The region name is looked up in the given group(s).
296 // <br>An exception is thrown if the old region name does not exist.
297 virtual void renameRegion (const String& newName,
298 const String& oldName,
300 Bool overwrite = False);
301
302 // Remove a region/mask belonging to the image from the given group
303 // (which can be Any).
304 // <br>Optionally an exception is thrown if the region does not exist.
305 virtual void removeRegion (const String& name,
307 Bool throwIfUnknown = True);
308
309 // Get the names of all regions/masks.
312
313 // Use the mask as specified.
314 // If a mask was already in use, it is replaced by the new one.
316
317 // Set the default pixelmask to the mask with the given name
318 // (which has to exist in the "masks" group).
319 // If the image table is writable, the setting is persistent by writing
320 // the name as a keyword.
321 // If the given regionName is the empty string,
322 // the default pixelmask is unset.
323 virtual void setDefaultMask (const String& regionName);
324
325 // Get the name of the default pixelmask.
326 // An empty string is returned if no default pixelmask.
327 virtual String getDefaultMask() const;
328
329 // Get a region belonging to the image.
330 // An exception is thrown if the region does not exist.
331 ImageRegion getRegion (const String& regionName,
333
334 // Make a unique region name from the given root name, thus make it such
335 // that the name is not already in use for a region or mask.
336 // The root name is returned if it is already unique.
337 // Otherwise a number is appended to the root name to make it unique.
338 // The number starts at the given number and is incremented until the name
339 // is unique.
341 uInt startNumber = 1) const;
342
343 // Check class invariants.
344 virtual Bool ok() const = 0;
345
346 // Save and restore an ImageInterface object to or from a state Record
348 Bool fromRecord (String& error, const RecordInterface& inRec);
349
350protected:
351 // Assignment (copy semantics) is only useful for derived classes.
353
354 // Restore the image info from the record.
356
357 // Set the image logger variable.
359 { log_p = logger; }
360
361 // Set the image info variable.
363
364 // Set the coordinate system variable.
366 { coords_p = coords; }
367
368 // Set the unit variable.
369 void setUnitMember (const Unit& unit)
370 { unit_p = unit; }
371
372 // Set the miscinfo variable.
374 { miscInfo_p.assign (rec); }
375
376 // Get access to the region handler.
379
380private:
381 // It is the job of the derived class to make these variables valid.
387
388 // The region handling object.
390
391 // The attribute handling object.
393};
394
395
396//# Declare extern templates for often used types.
397 extern template class ImageInterface<Float>;
398 extern template class ImageInterface<Complex>;
399
400
401} //# NAMESPACE CASACORE - END
402
403#ifndef CASACORE_NO_AUTO_TEMPLATES
404#include <casacore/images/Images/ImageInterface.tcc>
405#endif //# CASACORE_NO_AUTO_TEMPLATES
406#endif
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).
const LoggerHolder & logger() const
LogIO & logSink()
Allow messages to be logged to this ImageInterface.
void appendLog(const LoggerHolder &other)
Add the messages from the other image logger to this one.
void setCoordsMember(const CoordinateSystem &coords)
Set the coordinate system variable.
LoggerHolder & logger()
Get access to the LoggerHolder.
virtual ImageAttrHandler & attrHandler(Bool createHandler=False)
Get access to the attribute handler.
virtual Bool setUnits(const Unit &newUnits)
Function which get and set the units associated with the image pixels (i.e.
ImageInfo & rwImageInfo()
Get non-const access to the ImageInfo.
ImageInterface(const RegionHandler &regionHandler)
Construct for a specific region handler object.
void setLogMember(const LoggerHolder &logger)
Set the image logger variable.
virtual void resize(const TiledShape &newShape)=0
Function which changes the shape of the image (N.B.
virtual void defineRegion(const String &name, const ImageRegion &region, RegionHandler::GroupType, Bool overwrite=False)
Define a region/mask belonging to the image.
virtual ImageInterface< T > * cloneII() const =0
virtual Bool setImageInfo(const ImageInfo &info)
const LogIO & logSink() const
virtual const Unit & units() const
virtual String imageType() const =0
Get the image type (returns name of derived class).
virtual ImageRegion makeMask(const String &name, Bool defineAsRegion=True, Bool setAsDefaultMask=True, Bool initialize=False, Bool value=True)
Make a mask which is suitable for the type of image.
Bool canDefineRegion() const
Can the image handle region definition?
const ImageInfo & imageInfo() const
The ImageInfo object contains some miscellaneous information about the image which unlike that stored...
virtual MaskedLattice< T > * cloneML() const
Make a copy of the derived object (reference semantics).
ImageAttrHandler & roAttrHandler() const
ImageAttrHandler itsBaseAttrHandler
The attribute handling object.
virtual String name(Bool stripPath=False) const =0
Return the name of the current ImageInterface object.
RegionHandler * getRegionHandler()
Get access to the region handler.
virtual String getDefaultMask() const
Get the name of the default pixelmask.
ImageRegion getRegion(const String &regionName, RegionHandler::GroupType=RegionHandler::Any) const
Get a region belonging to the image.
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).
RegionHandler * regHandPtr_p
The region handling object.
void setImageInfoMember(const ImageInfo &imageInfo)
Set the image info variable.
virtual void useMask(MaskSpecifier=MaskSpecifier())
Use the mask as specified.
virtual Bool ok() const =0
Check class invariants.
ImageInterface & operator=(const ImageInterface &other)
Assignment (copy semantics) is only useful for derived classes.
virtual Bool setMiscInfo(const RecordInterface &newInfo)
virtual Bool hasRegion(const String &regionName, RegionHandler::GroupType=RegionHandler::Any) const
Does the image have a region with the given name?
virtual LELCoordinates lelCoordinates() const
Function to get a LELCoordinate object containing the coordinates.
virtual Bool setCoordinateInfo(const CoordinateSystem &coords)
Functions to set or replace the coordinate information in the Image Returns False on failure,...
void setMiscInfoMember(const RecordInterface &rec)
Set the miscinfo variable.
ImageInterface(const ImageInterface &other)
Copy constructor (copy semantics).
const CoordinateSystem & coordinates() const
Bool fromRecord(String &error, const RecordInterface &inRec)
String makeUniqueRegionName(const String &rootName, uInt startNumber=1) const
Make a unique region name from the given root name, thus make it such that the name is not already in...
virtual void setDefaultMask(const String &regionName)
Set the default pixelmask to the mask with the given name (which has to exist in the "masks" group).
virtual void renameRegion(const String &newName, const String &oldName, RegionHandler::GroupType=RegionHandler::Any, Bool overwrite=False)
Rename a region.
const TableRecord & miscInfo() const
Often we have miscellaneous information we want to attach to an image.
virtual Vector< String > regionNames(RegionHandler::GroupType=RegionHandler::Any) const
Get the names of all regions/masks.
Bool toRecord(String &error, RecordInterface &outRec)
Save and restore an ImageInterface object to or from a state Record.
Bool restoreImageInfo(const RecordInterface &rec)
Restore the image info from the record.
void setUnitMember(const Unit &unit)
Set the unit variable.
CoordinateSystem coords_p
It is the job of the derived class to make these variables valid.
virtual IPosition shape() const =0
Return the shape of the Lattice including all degenerate axes (ie.
void append(const LoggerHolder &other)
Append the entries of the other logger to this one.
LogIO & logio()
Get access to the logger.
const LatticeRegion & region() const
Get the region used.
GroupType
Define the possible group types (regions or masks).
virtual Bool canDefineRegion() const
Can the class indeed define and handle regions? The default implementation returns False.
String: the storage and methods of handling collections of characters.
Definition String.h:223
virtual void assign(const RecordInterface &that)
Assign that RecordInterface object to this one.
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
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
const Bool True
Definition aipstype.h:41