ImageRegion.h

Go to the documentation of this file.
00001 //# ImageRegion.h: Class to hold a region of interest in an image
00002 //# Copyright (C) 1998,1999,2000
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 
00028 #ifndef IMAGES_IMAGEREGION_H
00029 #define IMAGES_IMAGEREGION_H
00030 
00031 //# Includes
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/lattices/LRegions/LattRegionHolder.h>
00034 
00035 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00036 
00037 //# Forward Declarations
00038 class CoordinateSystem;
00039 class IPosition;
00040 class LCRegion;
00041 class LCSlicer;
00042 class WCRegion;
00043 class String;
00044 class TableRecord;
00045 
00046 
00047 // <summary>
00048 // Class to hold a region of interest in an image.
00049 // </summary>
00050 
00051 // <use visibility=export>
00052 
00053 // <reviewed reviewer="" date="" tests="">
00054 // </reviewed>
00055 
00056 // <prerequisite>
00057 //   <li> <linkto class=LCSlicer>LCSlicer</linkto>
00058 //   <li> <linkto class=WCRegion>WCRegion</linkto>
00059 // </prerequisite>
00060 
00061 // <synopsis> 
00062 // The only purpose of ImageRegion is to have a single object for
00063 // the various kinds of regions. It can hold a
00064 // <linkto class=LCRegion>LCRegion</linkto>,
00065 // <linkto class=LCSlicer>LCSlicer</linkto>, and
00066 // <linkto class=WCRegion>WCRegion</linkto>.
00067 // </synopsis> 
00068 
00069 // <example>
00070 // <srcblock>
00071 // </srcblock>
00072 // </example>
00073 
00074 // <motivation>
00075 // It was felt that making an abstract base class LatticeRegion for
00076 // LCRegion and WCRegion would create undesirable dependencies of
00077 // module Lattices on module Coordinates. E.g. it would be impossible
00078 // to have a function toWCRegion.
00079 // Therefore the container class ImageRegion is chosen.
00080 // </motivation>
00081 
00082 //# <todo asof="1997/11/11">
00083 //# <li>
00084 //# </todo>
00085 
00086 class ImageRegion : public LattRegionHolder
00087 {
00088 public:
00089     // Default constructor (has no region at all).
00090     ImageRegion();
00091 
00092     // Construct from a region based on lattice coordinates.
00093     ImageRegion (const LCRegion&);
00094 
00095     // Construct from a slicer based on lattice coordinates.
00096     ImageRegion (const LCSlicer&);
00097 
00098     // Construct from a region based on world coordinates.
00099     ImageRegion (const WCRegion&);
00100 
00101     // Similar constructors as above, but using a pointer.
00102     // It takes over the pointer, so the user should not delete the
00103     // object. It is deleted by the ImageRegion destructor.
00104     // <group>
00105     explicit ImageRegion (LCRegion*);
00106     explicit ImageRegion (LCSlicer*);
00107     explicit ImageRegion (WCRegion*);
00108     // </group>
00109 
00110     // Copy constructor (copy semantics).
00111     ImageRegion (const ImageRegion& other);
00112 
00113     virtual ~ImageRegion();
00114 
00115     // Assignment (copy semantics).
00116     ImageRegion& operator= (const ImageRegion& other);
00117 
00118     // Clone the object.
00119     virtual ImageRegion* clone() const;
00120 
00121     // Comparison
00122     virtual Bool operator==(const LattRegionHolder& other) const;
00123 
00124     // Create an ImageRegion from a lattice expression. Returned pointer
00125     // is created via new(); it is the caller's responsibility to delete it.
00126     static ImageRegion* fromLatticeExpression(const String& latticeExpression);
00127 
00128     // Create an ImageRegion from a record. The returned pointer is created via
00129     // new(). It's the callers responsibility to delete it.
00130     // If a null pointer is passed in for <src>logger</src> no logging is done,
00131     // otherwise informational messages regarding bounding boxes are emitted
00132     // to the <src>logger</src> object.
00133     static ImageRegion* fromRecord (LogIO *logger,
00134                                     const CoordinateSystem& coords,
00135                                     const IPosition& imShape,
00136                                     const Record& regionRecord);
00137 
00138     // Test if the underlying region is an WCRegion.
00139     virtual Bool isWCRegion() const;
00140 
00141     // Get the region as a pointer to WCRegion.
00142     // An exception is thrown if the region is not the correct type.
00143     // Functions <src>isWCRegion()</src> can be used to test the type.
00144     virtual const WCRegion* asWCRegionPtr() const;
00145 
00146     // Get the region as an LCSlicer or WCRegion.
00147     // An exception is thrown if the region is not the correct type.
00148     // Functions <src>isWCRegion()</src>, etc. can be used to test the type.
00149     // <group>
00150     const LCRegion& asLCRegion() const;
00151     const LCSlicer& asLCSlicer() const;
00152     const WCRegion& asWCRegion() const;
00153     // </group>
00154 
00155     // Get the region as a writable mask.
00156     // It throws an exception if the region is not an LCRegion or if
00157     // its mask is not writable.
00158     LCRegion& asMask();
00159 
00160     // Convert to a LatticeRegion using the given coordinate system
00161     // (with reference pixel) and shape.
00162     // It will also make the region complete (absolute and non-fractional).
00163     virtual LatticeRegion toLatticeRegion (const CoordinateSystem& cSys,
00164                                            const IPosition& shape) const;
00165 
00166     // Convert to an LCRegion using the given coordinate system
00167     // (with reference pixel) and shape.
00168     // It will also make the region complete (absolute and non-fractional).
00169     // An exception is thrown if the region type is a LCSlicer.
00170     // The axes argument tells which axes to use from the coordinate
00171     // system and shape.
00172     LCRegion* toLCRegion (const CoordinateSystem& cSys,
00173                           const IPosition& shape) const;
00174 
00175     // Convert the (derived) object to a record.
00176     // The record can be used to make the object persistent.
00177     TableRecord toRecord (const String& tableName) const;
00178 
00179     // Convert correct object from a record.
00180     static ImageRegion* fromRecord (const TableRecord&,
00181                                     const String& tableName);
00182 
00183     // Form a compound from this and the other region.
00184     // <group>
00185     virtual LattRegionHolder* makeUnion (const LattRegionHolder& other) const;
00186     virtual LattRegionHolder* makeIntersection
00187                                         (const LattRegionHolder& other) const;
00188     virtual LattRegionHolder* makeDifference
00189                                         (const LattRegionHolder& other) const;
00190     virtual LattRegionHolder* makeComplement() const;
00191     // </group>
00192 
00193 private:
00194     WCRegion*   itsWC;
00195 };
00196 
00197 
00198 inline const LCRegion& ImageRegion::asLCRegion() const
00199 {
00200     return *asLCRegionPtr();
00201 }
00202 
00203 inline const LCSlicer& ImageRegion::asLCSlicer() const
00204 {
00205     return *asLCSlicerPtr();
00206 }
00207 
00208 inline const WCRegion& ImageRegion::asWCRegion() const
00209 {
00210     return *asWCRegionPtr();
00211 }
00212 
00213 
00214 
00215 } //# NAMESPACE CASACORE - END
00216 
00217 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1