ImageInterface.h

Classes

ImageInterface -- A base class for astronomical images. (full description)

template <class T> class ImageInterface: public MaskedLattice<T>

Interface

Public Members
ImageInterface()
ImageInterface (const RegionHandler& regionHandler)
ImageInterface (const ImageInterface& other)
~ImageInterface()
virtual MaskedLattice<T>* cloneML() const
virtual ImageInterface<T>* cloneII() const = 0
virtual String imageType() const = 0
virtual void resize (const TiledShape& newShape) = 0
virtual Bool setUnits (const Unit& newUnits)
virtual const Unit& units() const
virtual String name (Bool stripPath=False) const = 0
virtual Bool setCoordinateInfo (const CoordinateSystem& coords)
const CoordinateSystem& coordinates() const
virtual LELCoordinates lelCoordinates() const
LoggerHolder& logger()
const LoggerHolder& logger() const
LogIO& logSink()
const LogIO& logSink() const
void appendLog (const LoggerHolder& other)
const TableRecord& miscInfo() const
virtual Bool setMiscInfo (const RecordInterface& newInfo)
const ImageInfo& imageInfo() const
virtual Bool setImageInfo (const ImageInfo& info)
Bool canDefineRegion() const
virtual ImageRegion makeMask (const String& name, Bool defineAsRegion = True, Bool setAsDefaultMask = True, Bool initialize = False, Bool value = True)
virtual void defineRegion (const String& name, const ImageRegion& region, RegionHandler::GroupType, Bool overwrite = False)
virtual Bool hasRegion (const String& regionName, RegionHandler::GroupType = RegionHandler::Any) const
virtual ImageRegion* getImageRegionPtr (const String& name, RegionHandler::GroupType = RegionHandler::Any, Bool throwIfUnknown = True) const
virtual void renameRegion (const String& newName, const String& oldName, RegionHandler::GroupType = RegionHandler::Any, Bool overwrite = False)
virtual void removeRegion (const String& name, RegionHandler::GroupType = RegionHandler::Any, Bool throwIfUnknown = True)
virtual Vector<String> regionNames (RegionHandler::GroupType = RegionHandler::Any) const
virtual void useMask (MaskSpecifier = MaskSpecifier())
virtual void setDefaultMask (const String& regionName)
virtual String getDefaultMask() const
ImageRegion getRegion (const String& regionName, RegionHandler::GroupType = RegionHandler::Any) const
String makeUniqueRegionName (const String& rootName, uInt startNumber = 1) const
virtual Bool ok() const = 0
Bool toRecord (String& error, RecordInterface& outRec)
Bool fromRecord (String& error, const RecordInterface& inRec)
Protected Members
ImageInterface& operator= (const ImageInterface& other)
Bool restoreImageInfo (const RecordInterface& rec)
void setLogMember (const LoggerHolder& logger)
void setImageInfoMember (const ImageInfo& imageInfo)
void setCoordsMember (const CoordinateSystem& coords)
void setUnitMember (const Unit& unit)
void setMiscInfoMember (const RecordInterface& rec)

Description

Prerequisite

Etymology

The ImageInterface class name is derived from its role as the cookie cutter Interface base class for Images.

Synopsis

The ImageInterface class is an abstract base class. All Image classes should derive from this class to ensure functions which operate on Images will work for all Image derivations.

An Image is currently defined as an Array of pixels, a Boolean mask, defining which pixels are valid and coordinates to define the reference frame. The only concrete class currently derived from this Interface is PagedImage, which allows the image to be stored on disk, and only reads specified portions of the image into memory.

Example

As this is an abstract base class it is not possible to construct an instance of this object. It can however be used as a function argument.
eg 1. (used in dImageInterface.cc)
    Float sumPixels(const ImageInterface<Float>& image){
      uInt rowLength = image.shape()(0);
      IPosition rowShape(image.ndim());
      rowShape = 1; rowShape(0) = rowLength;
      Float sumPix = 0;
      RO_LatticeIterator<Float> iter(image, rowShape);
      while(!iter.atEnd()){
        sumPix += sum(iter.vectorCursor());
        iter++;
      }
      return sumPix;
    }
    

The main purpose of this class is for programming objects, the following example is of how one would derive from ImageInterface:
eg 2.

    template <class T> class myNewImage : public ImageInterface<T>
    {
    public:
      // default constructor
      myNewImage();
    
      // argumented constructor
      myNewImage(...);
    
      // destructor
      ~myNewImage
      
      // the shape function is forced upon us by the Lattice base class
      IPosition shape() const;
      
      // doGetSlice is another function required of all Lattice objects.
      Bool doGetSlice(<Array<T>& buffer, const Slicer& section);
    
     // etc...
    private:
     // put the actual map data down here.
     // etc...
    };
    

Motivation

The use of abstract base classes to guide inheritance seemed appropriate for Images to ensure that CoordinateSystems and masking get handled uniformly.

To Do

Member Description

ImageInterface()

ImageInterface (const RegionHandler& regionHandler)

Construct for a specific region handler object.

ImageInterface (const ImageInterface& other)

Copy constructor (copy semantics).

~ImageInterface()

virtual MaskedLattice<T>* cloneML() const
virtual ImageInterface<T>* cloneII() const = 0

Make a copy of the derived object (reference semantics).

virtual String imageType() const = 0

Get the image type (returns name of derived class).

virtual void resize (const TiledShape& newShape) = 0

Function which changes the shape of the image (N.B. the data is thrown away - the Image will be filled with nonsense afterwards)

virtual Bool setUnits (const Unit& newUnits)
virtual const Unit& units() const

Function which get and set the units associated with the image pixels (i.e. the "brightness" unit). setUnits() returns False if it cannot set the unit for some reason (e.g. the underlying file is not writable).

virtual String name (Bool stripPath=False) const = 0

Return the name of the current ImageInterface object. This will generally be a file name for images that have a persistent form. Any path before the actual file name can be optionally stripped off.

virtual Bool setCoordinateInfo (const CoordinateSystem& coords)
const CoordinateSystem& coordinates() const

Functions to set or replace the coordinate information in the Image Returns False on failure, e.g. if the number of axes do not match.

virtual LELCoordinates lelCoordinates() const

Function to get a LELCoordinate object containing the coordinates.

LoggerHolder& logger()
const LoggerHolder& logger() const

Get access to the LoggerHolder.

LogIO& logSink()
const LogIO& logSink() const

Allow messages to be logged to this ImageInterface.

void appendLog (const LoggerHolder& other)

Add the messages from the other image logger to this one.

const TableRecord& miscInfo() const
virtual Bool setMiscInfo (const RecordInterface& newInfo)

Often we have miscellaneous information we want to attach to an image. This is where it goes.
Note that setMiscInfo REPLACES the information with the new information. It can fail if, e.g., the underlying table is not writable.

const ImageInfo& imageInfo() const
virtual Bool setImageInfo (const ImageInfo& info)

The ImageInfo object contains some miscellaneous information about the image which unlike that stored in MiscInfo, has a standard list of things, such as the restoring beam.

Note that setImageInfo REPLACES the information with the new information. It is up to the derived class to make the ImageInfo permanent.

Bool canDefineRegion() const

Can the image handle region definition?

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. Optionally the mask can be initialized with the given value (by default it will not).
Optionally the mask can be defined as an image region/mask and turned in the default mask for the image. By default it will.

virtual void defineRegion (const String& name, const ImageRegion& region, RegionHandler::GroupType, Bool overwrite = False)

Define a region/mask belonging to the image. The group type determines if it stored as a region or mask. If overwrite=False, an exception will be thrown if the region already exists.
An exception is thrown if canDefineRegion is False.

virtual Bool hasRegion (const String& regionName, RegionHandler::GroupType = RegionHandler::Any) const

Does the image have a region with the given name?

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).
Optionally an exception is thrown if the region does not exist. A zero pointer is returned if the region does not exist. The caller has to delete the ImageRegion object created.

virtual void renameRegion (const String& newName, const String& oldName, RegionHandler::GroupType = RegionHandler::Any, Bool overwrite = False)

Rename a region. If a region with the new name already exists, it is deleted or an exception is thrown (depending on overwrite). The region name is looked up in the given group(s).
An exception is thrown if the old region name does not exist.

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).
Optionally an exception is thrown if the region does not exist.

virtual Vector<String> regionNames (RegionHandler::GroupType = RegionHandler::Any) const

Get the names of all regions/masks.

virtual void useMask (MaskSpecifier = MaskSpecifier())

Use the mask as specified. If a mask was already in use, it is replaced by the new one.

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). If the image table is writable, the setting is persistent by writing the name as a keyword. If the given regionName is the empty string, the default pixelmask is unset.

virtual String getDefaultMask() const

Get the name of the default pixelmask. An empty string is returned if no default pixelmask.

ImageRegion getRegion (const String& regionName, RegionHandler::GroupType = RegionHandler::Any) const

Get a region belonging to the image. An exception is thrown if the region does not exist.

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 use for a region or mask. The root name is returned if it is already unique. Otherwise a number is appended to the root name to make it unique. The number starts at the given number and is incremented until the name is unique.

virtual Bool ok() const = 0

Check class invariants.

Bool toRecord (String& error, RecordInterface& outRec)

Save and restore an ImageInterface object to or from a state Record

Bool fromRecord (String& error, const RecordInterface& inRec)

ImageInterface& operator= (const ImageInterface& other)

Assignment (copy semantics) is only useful for derived classes.

Bool restoreImageInfo (const RecordInterface& rec)

Restore the image info from the record.

void setLogMember (const LoggerHolder& logger)

Set the image logger variable.

void setImageInfoMember (const ImageInfo& imageInfo)

Set the image info variable.

void setCoordsMember (const CoordinateSystem& coords)

Set the coordinate system variable.

void setUnitMember (const Unit& unit)

Set the unit variable.

void setMiscInfoMember (const RecordInterface& rec)

Set the miscinfo variable.