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// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/ArrayFwd.h>
32#include <casacore/images/Regions/RegionHandler.h>
33#include <casacore/images/Images/MaskSpecifier.h>
34#include <casacore/images/Images/ImageInfo.h>
35#include <casacore/images/Images/ImageAttrHandler.h>
36#include <casacore/lattices/Lattices/MaskedLattice.h>
37#include <casacore/coordinates/Coordinates/CoordinateSystem.h>
38#include <casacore/tables/LogTables/LoggerHolder.h>
39#include <casacore/tables/Tables/TableRecord.h>
40#include <casacore/casa/Quanta/Unit.h>
41
42namespace casacore { // # NAMESPACE CASACORE - BEGIN
43
44// # Forward Declarations
45template <class T>
47template <class T>
48class COWPtr;
49class ImageRegion;
50class IPosition;
51class TiledShape;
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
143template <class T>
144class ImageInterface : public MaskedLattice<T> {
145 // # Make members of parent class known.
146 public:
147 using MaskedLattice<T>::shape;
148
149 public:
151
152 // Construct for a specific region handler object.
153 ImageInterface(const RegionHandler& regionHandler);
154
155 // Copy constructor (copy semantics).
157
159
160 // Make a copy of the derived object (reference semantics).
161 // <group>
162 virtual MaskedLattice<T>* cloneML() const;
163 virtual ImageInterface<T>* cloneII() const = 0;
164 // </group>
165
166 // Get the image type (returns name of derived class).
167 virtual String imageType() const = 0;
168
169 // Function which changes the shape of the image (N.B. the data is thrown
170 // away - the Image will be filled with nonsense afterwards)
171 virtual void resize(const TiledShape& newShape) = 0;
172
173 // Function which get and set the units associated with the image
174 // pixels (i.e. the "brightness" unit). <src>setUnits()</src> returns
175 // False if it cannot set the unit for some reason (e.g. the underlying
176 // file is not writable).
177 // <group>
178 virtual Bool setUnits(const Unit& newUnits);
179 virtual const Unit& units() const { return unit_p; }
180 // </group>
181
182 // Return the name of the current ImageInterface object. This will generally
183 // be a file name for images that have a persistent form. Any path
184 // before the actual file name can be optionally stripped off.
185 virtual String name(Bool stripPath = False) const = 0;
186
187 // Functions to set or replace the coordinate information in the Image
188 // Returns False on failure, e.g. if the number of axes do not match.
189 // <group>
191 const CoordinateSystem& coordinates() const { return coords_p; }
192 // </group>
193
194 // Function to get a LELCoordinate object containing the coordinates.
196
197 // Get access to the LoggerHolder.
198 // <group>
199 LoggerHolder& logger() { return log_p; }
200 const LoggerHolder& logger() const { return log_p; }
201 // </group>
202
203 // Allow messages to be logged to this ImageInterface.
204 // <group>
205 LogIO& logSink() { return logger().logio(); }
206 const LogIO& logSink() const { return const_cast<ImageInterface<T>*>(this)->logSink(); }
207 // </group>
208
209 // Add the messages from the other image logger to this one.
210 void appendLog(const LoggerHolder& other) { log_p.append(other); }
211
212 // Often we have miscellaneous information we want to attach to an image.
213 // This is where it goes.
214 // <br>
215 // Note that setMiscInfo REPLACES the information with the new information.
216 // It can fail if, e.g., the underlying table is not writable.
217 // <group>
218 const TableRecord& miscInfo() const { return miscInfo_p; }
219 virtual Bool setMiscInfo(const RecordInterface& newInfo);
220 // </group>
221
222 // The ImageInfo object contains some miscellaneous information about the image
223 // which unlike that stored in MiscInfo, has a standard list of things,
224 // such as the restoring beam.
225 //
226 // Note that setImageInfo REPLACES the information with the new information.
227 // It is up to the derived class to make the ImageInfo permanent.
228 // <group>
229 const ImageInfo& imageInfo() const { return imageInfo_p; }
230 // Get non-const access to the ImageInfo.
232 virtual Bool setImageInfo(const ImageInfo& info);
233 // </group>
234
235 // Get access to the attribute handler.
236 // By default an empty handler is returned where no groups can be added to.
237 // <group>
238 virtual ImageAttrHandler& attrHandler(Bool createHandler = False);
240 return const_cast<ImageInterface<T>*>(this)->attrHandler(False);
241 }
242 // </group>
243
244 // Can the image handle region definition?
245 Bool canDefineRegion() const { return regHandPtr_p->canDefineRegion(); }
246
247 // Make a mask which is suitable for the type of image.
248 // Optionally the mask can be initialized with the given value
249 // (by default it will not).
250 // <br>Optionally the mask can be defined as an image region/mask
251 // and turned in the default mask for the image. By default it will.
252 virtual ImageRegion makeMask(const String& name, Bool defineAsRegion = True,
253 Bool setAsDefaultMask = True, Bool initialize = False,
254 Bool value = True);
255
256 // Define a region/mask belonging to the image.
257 // The group type determines if it stored as a region or mask.
258 // If overwrite=False, an exception will be thrown if the region
259 // already exists.
260 // <br>An exception is thrown if canDefineRegion is False.
262 Bool overwrite = False);
263
264 // Does the image have a region with the given name?
265 virtual Bool hasRegion(const String& regionName,
267
268 // Get a region/mask belonging to the image from the given group
269 // (which can be Any).
270 // <br>Optionally an exception is thrown if the region does not exist.
271 // A zero pointer is returned if the region does not exist.
272 // The caller has to delete the <src>ImageRegion</src> object created.
275 Bool throwIfUnknown = True) const;
276
277 // Rename a region.
278 // If a region with the new name already exists, it is deleted or
279 // an exception is thrown (depending on <src>overwrite</src>).
280 // The region name is looked up in the given group(s).
281 // <br>An exception is thrown if the old region name does not exist.
282 virtual void renameRegion(const String& newName, const String& oldName,
284
285 // Remove a region/mask belonging to the image from the given group
286 // (which can be Any).
287 // <br>Optionally an exception is thrown if the region does not exist.
289 Bool throwIfUnknown = True);
290
291 // Get the names of all regions/masks.
293
294 // Use the mask as specified.
295 // If a mask was already in use, it is replaced by the new one.
297
298 // Set the default pixelmask to the mask with the given name
299 // (which has to exist in the "masks" group).
300 // If the image table is writable, the setting is persistent by writing
301 // the name as a keyword.
302 // If the given regionName is the empty string,
303 // the default pixelmask is unset.
304 virtual void setDefaultMask(const String& regionName);
305
306 // Get the name of the default pixelmask.
307 // An empty string is returned if no default pixelmask.
308 virtual String getDefaultMask() const;
309
310 // Get a region belonging to the image.
311 // An exception is thrown if the region does not exist.
312 ImageRegion getRegion(const String& regionName,
314
315 // Make a unique region name from the given root name, thus make it such
316 // that the name is not already in use for a region or mask.
317 // The root name is returned if it is already unique.
318 // Otherwise a number is appended to the root name to make it unique.
319 // The number starts at the given number and is incremented until the name
320 // is unique.
321 String makeUniqueRegionName(const String& rootName, uInt startNumber = 1) const;
322
323 // Check class invariants.
324 virtual Bool ok() const = 0;
325
326 // Save and restore an ImageInterface object to or from a state Record
328 Bool fromRecord(String& error, const RecordInterface& inRec);
329
330 protected:
331 // Assignment (copy semantics) is only useful for derived classes.
333
334 // Restore the image info from the record.
336
337 // Set the image logger variable.
339
340 // Set the image info variable.
342
343 // Set the coordinate system variable.
344 void setCoordsMember(const CoordinateSystem& coords) { coords_p = coords; }
345
346 // Set the unit variable.
347 void setUnitMember(const Unit& unit) { unit_p = unit; }
348
349 // Set the miscinfo variable.
350 void setMiscInfoMember(const RecordInterface& rec) { miscInfo_p.assign(rec); }
351
352 // Get access to the region handler.
354
355 private:
356 // It is the job of the derived class to make these variables valid.
362
363 // The region handling object.
365
366 // The attribute handling object.
368};
369
370// # Declare extern templates for often used types.
371extern template class ImageInterface<Float>;
372extern template class ImageInterface<Complex>;
373
374} // namespace casacore
375
376#ifndef CASACORE_NO_AUTO_TEMPLATES
377#include <casacore/images/Images/ImageInterface.tcc>
378#endif // # CASACORE_NO_AUTO_TEMPLATES
379#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.
LogIO & logio()
Get access to the logger.
MaskedLattice()
Default constructor.
const LatticeRegion & region() const
Get the region used.
GroupType
Define the possible group types (regions or masks).
String: the storage and methods of handling collections of characters.
Definition String.h:355
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
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
RecordInterface()
The default constructor creates an empty record with a variable structure.
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