casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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: ImageRegion.h 20567 2009-04-09 23:12:39Z gervandiepen $
00027 
00028 #ifndef IMAGES_IMAGEREGION_H
00029 #define IMAGES_IMAGEREGION_H
00030 
00031 //# Includes
00032 #include <lattices/Lattices/LattRegionHolder.h>
00033 
00034 namespace casa { //# NAMESPACE CASA - BEGIN
00035 
00036 //# Forward Declarations
00037 class CoordinateSystem;
00038 class IPosition;
00039 class LCRegion;
00040 class LCSlicer;
00041 class WCRegion;
00042 class String;
00043 class TableRecord;
00044 
00045 
00046 // <summary>
00047 // Class to hold a region of interest in an image.
00048 // </summary>
00049 
00050 // <use visibility=export>
00051 
00052 // <reviewed reviewer="" date="" tests="">
00053 // </reviewed>
00054 
00055 // <prerequisite>
00056 //   <li> <linkto class=LCSlicer>LCSlicer</linkto>
00057 //   <li> <linkto class=WCRegion>WCRegion</linkto>
00058 // </prerequisite>
00059 
00060 // <synopsis> 
00061 // The only purpose of ImageRegion is to have a single object for
00062 // the various kinds of regions. It can hold a
00063 // <linkto class=LCRegion>LCRegion</linkto>,
00064 // <linkto class=LCSlicer>LCSlicer</linkto>, and
00065 // <linkto class=WCRegion>WCRegion</linkto>.
00066 // </synopsis> 
00067 
00068 // <example>
00069 // <srcblock>
00070 // </srcblock>
00071 // </example>
00072 
00073 // <motivation>
00074 // It was felt that making an abstract base class LatticeRegion for
00075 // LCRegion and WCRegion would create undesirable dependencies of
00076 // module Lattices on module Coordinates. E.g. it would be impossible
00077 // to have a function toWCRegion.
00078 // Therefore the container class ImageRegion is chosen.
00079 // </motivation>
00080 
00081 //# <todo asof="1997/11/11">
00082 //# <li>
00083 //# </todo>
00084 
00085 class ImageRegion : public LattRegionHolder
00086 {
00087 public:
00088     // Default constructor (has no region at all).
00089     ImageRegion();
00090 
00091     // Construct from a region based on lattice coordinates.
00092     ImageRegion (const LCRegion&);
00093 
00094     // Construct from a slicer based on lattice coordinates.
00095     ImageRegion (const LCSlicer&);
00096 
00097     // Construct from a region based on world coordinates.
00098     ImageRegion (const WCRegion&);
00099 
00100     // Similar constructors as above, but using a pointer.
00101     // It takes over the pointer, so the user should not delete the
00102     // object. It is deleted by the ImageRegion destructor.
00103     // <group>
00104     explicit ImageRegion (LCRegion*);
00105     explicit ImageRegion (LCSlicer*);
00106     explicit ImageRegion (WCRegion*);
00107     // </group>
00108 
00109     // Copy constructor (copy semantics).
00110     ImageRegion (const ImageRegion& other);
00111 
00112     virtual ~ImageRegion();
00113 
00114     // Assignment (copy semantics).
00115     ImageRegion& operator= (const ImageRegion& other);
00116 
00117     // Clone the object.
00118     virtual ImageRegion* clone() const;
00119 
00120     // Comparison
00121     virtual Bool operator==(const LattRegionHolder& other) const;
00122 
00123     // Create an ImageRegion from a lattice expression. Returned pointer
00124     // is created via new(); it is the caller's responsibility to delete it.
00125     // This method was moved from ImageAnalysis.
00126     static ImageRegion* fromLatticeExpression(const String& latticeExpression);
00127 
00128     // Create an ImageRegion from a record. The returned pointer is created via
00129     // new() and so callers are responsible for deleting it. If a null pointer is
00130     // passed in for <src>logger</src> no logging is done, otherwise informational
00131     // messages regarding bounding boxes are emitted to the <src>logger</src> object.
00132     // Moved from ImageAnalysis.
00133     static ImageRegion* fromRecord(
00134         LogIO *const &logger, const CoordinateSystem& coords,
00135         const IPosition& imShape, const Record& regionRecord
00136     );
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     // moved from ImageAnalysis
00194     // TODO: From Ger:
00195     // In fact I doubt if that tweaked function is really needed.
00196     // The fromRecord function in e.g. LCBox use toArrayFloat which converts a double array
00197     // to a float array.
00198     // You should try if the code works fine without doing the tweakrecord.
00199     static  Record * tweakedRegionRecord(Record *Region);
00200 
00201 private:
00202     WCRegion*   itsWC;
00203 };
00204 
00205 
00206 inline const LCRegion& ImageRegion::asLCRegion() const
00207 {
00208     return *asLCRegionPtr();
00209 }
00210 
00211 inline const LCSlicer& ImageRegion::asLCSlicer() const
00212 {
00213     return *asLCSlicerPtr();
00214 }
00215 
00216 inline const WCRegion& ImageRegion::asWCRegion() const
00217 {
00218     return *asWCRegionPtr();
00219 }
00220 
00221 
00222 
00223 } //# NAMESPACE CASA - END
00224 
00225 #endif