casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
WCRegion.h
Go to the documentation of this file.
00001 //# WCRegion.h: Class to define a region of interest in an image
00002 //# Copyright (C) 1998,2000,2001
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: WCRegion.h 20615 2009-06-09 02:16:01Z Malte.Marquarding $
00027 
00028 #ifndef IMAGES_WCREGION_H
00029 #define IMAGES_WCREGION_H
00030 
00031 //# Includes
00032 #include <casa/Containers/Record.h>
00033 #include <coordinates/Coordinates/CoordinateSystem.h>
00034 #include <tables/Tables/TableRecord.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 //# Forward Declarations
00039 class LCRegion;
00040 class RecordInterface;
00041 class IPosition;
00042 class String;
00043 
00044 
00045 // <summary>
00046 // Base class to define world coordinate regions of interest in an image.
00047 // </summary>
00048 
00049 // <use visibility=export>
00050 
00051 // <reviewed reviewer="" date="" tests="">
00052 // </reviewed>
00053 //
00054 // <prerequisite>
00055 //   <li> <linkto class=LCRegion>LCRegion</linkto>
00056 // </prerequisite>
00057 //
00058 // <synopsis> 
00059 // WCRegion is the base class for world coordinate regions.
00060 // The axes in a WCRegion have names (e.g. RA, DEC, FREQ) and
00061 // carry sometimes an associated reference frame with it.
00062 // An WCRegion object is converted to the appropriate
00063 // <linkto class=LCRegion>LCRegion</linkto> object when they
00064 // are used to take a subset from an image.
00065 // LCRegion's are pixel based and are
00066 // used to access the correct pixels in the image.
00067 // The conversion has the following rules:
00068 // <ol>
00069 //  <li> All axes of the region must be axes in the image.
00070 //  <li> An image axis does not have to be an axis in the region.
00071 //   Thus the image can have a higher dimensionality than the region.
00072 //   If that is the case, the region is auto-extended to the image's
00073 //   dimensionality by using the full range for those axes.
00074 //  <li> The order of the axes in region and image do not have to
00075 //   be the same. They get reordered as needed.
00076 // </ol>
00077 // </synopsis> 
00078 //
00079 // <example>
00080 // <srcblock>
00081 // </srcblock>
00082 // </example>
00083 //
00084 // <motivation>
00085 // User should be able to specify their regions in world coordinates
00086 // as well as lattice coordinates.
00087 // </motivation>
00088 //
00089 //# <todo asof="1997/11/11">
00090 //# <li>
00091 //# </todo>
00092 
00093 
00094 class WCRegion
00095 {
00096 public:
00097     WCRegion();
00098 
00099     // Copy constructor (copy semantics).
00100     WCRegion (const WCRegion& other);
00101 
00102     // Destructor
00103     virtual ~WCRegion();
00104 
00105     // Comparison
00106     // <group>
00107     virtual Bool operator==(const WCRegion& other) const;
00108     Bool operator!=(const WCRegion& other) const;
00109     // </group>
00110 
00111     // Clone a WCRegion object.
00112     virtual WCRegion* cloneRegion() const = 0;
00113 
00114     // Return region type.
00115     // Just returns the class name of the derived class.
00116     virtual String type() const = 0;
00117 
00118     // Get the dimensionality (i.e. the number of axes).
00119     // Note that usually all axes have a description, but in some cases
00120     // (e.g. WCLELMask) that may not be the case.
00121     // The default implementation returns the number of axes in the
00122     // axes description.
00123     virtual uInt ndim() const;
00124 
00125     // Get the description of all axes.
00126     const Record& getAxesDesc() const;
00127 
00128     // Get the description of the given axis.
00129     // It is a record containing some fields describing the axis.
00130     const Record& getAxisDesc (uInt axis) const;
00131 
00132     // Return the axis number of the description of an axis in the full
00133     // axes description.
00134     // -1 is returned if not found.
00135     Int axisNr (const Record& desc, const Record& axesDesc) const;
00136 
00137     // Are both axis descriptions equal?
00138     Bool isAxisDescEqual (const Record& desc1, const Record& desc2) const;
00139 
00140     // Can the region extend itself?
00141     // By default it cannot.
00142     virtual Bool canExtend() const;
00143 
00144     // Get or set the comment.
00145     // <group>
00146     const String& comment() const;
00147     void setComment (const String& comment);
00148     // </group>
00149 
00150     // Convert to an LCRegion using the given new coordinate system and shape.
00151     // An exception is thrown if the region's dimensionality is more
00152     // than the length of the shape vector or if an axis in the region
00153     // is unknown in the new coordinate system..
00154     // When less, the default implementation extends the region over the
00155     // remaining axes.
00156     // <br>If the region does not need to have coordinates (like WCLELMask)
00157     // the function has to be overridden.
00158     virtual LCRegion* toLCRegion (const CoordinateSystem& cSys,
00159                                   const IPosition& shape) const;
00160 
00161     // Convert to an LCRegion using the given coordinate system and shape.
00162     // This function is meant for internal use by WCCompound objects.
00163     // <br>pixelAxesMap(i) is the axis in cSys and shape for region axis i.
00164     // <br>outOrder(i) is the axis in the output LCRegion for region axis i.
00165     // <br>The length of pixelAxesMap and outOrder is the dimensionality of
00166     // the output LCRegion. It can be more than the dimensionality of this
00167     // WCRegion object. In that case the region gets extended along the
00168     // latter axes. If the region cannot extend itself, this function
00169     // will create an LCExtension object to extend the region.
00170     // <br>Note that initially pixelAxisMap and outOrder are the same,
00171     // but when called for regions in compound regions they may start
00172     // to differ. 
00173     LCRegion* toLCRegionAxes (const CoordinateSystem& cSys,
00174                               const IPosition& shape,
00175                               const IPosition& pixelAxesMap,
00176                               const IPosition& outOrder) const;
00177 
00178     // Convert the (derived) object to a record.
00179     // The record can be used to make the object persistent.
00180     // The <src>tableName</src> argument can be used by derived
00181     // classes (e.g. LCPagedMask) to put very large objects.
00182     virtual TableRecord toRecord(const String& tableName) const = 0;
00183 
00184     // Convert correct object from a record.
00185     static WCRegion* fromRecord (const TableRecord& rec,
00186                                  const String& tableName);
00187 
00188     // Define the type and class name in the record.
00189     void defineRecordFields (RecordInterface& record,
00190                              const String& className) const;
00191 
00192 protected:
00193     // Assignment (copy semantics) makes only sense for a derived class.
00194     WCRegion& operator= (const WCRegion& other);
00195 
00196     // Add an axis with its description.
00197     // An exception is thrown if the axis already exists in this region.
00198     void addAxisDesc (const Record& axisDesc);
00199 
00200     // Make a description of a pixel axis in the coordinate system.
00201     Record makeAxisDesc (const CoordinateSystem& cSys, uInt pixelAxis) const;
00202 
00203     // Make a description of all pixel axes in the coordinate system
00204     // (in pixel axes order).
00205     Record makeAxesDesc (const CoordinateSystem& cSys) const;
00206 
00207     // Convert to an LCRegion using the given coordinate system and shape.
00208     // <br>pixelAxesMap(i) is the axis in cSys and shape for region axis i.
00209     // <br>outOrder(i) is the axis in the output LCRegion for region axis i.
00210     // <br>They always have the same length.
00211     // If the region can extend itself, the length of pixelAxesMap and
00212     // outOrder can be more than the dimensionality of the region.
00213     // The latter axes in them are the extension axes.
00214     virtual LCRegion* doToLCRegion (const CoordinateSystem& cSys,
00215                                     const IPosition& shape,
00216                                     const IPosition& pixelAxesMap,
00217                                     const IPosition& extendAxes) const = 0;
00218 
00219 // Convert relative to absolute world as needed
00220     void makeWorldAbsolute (Vector<Double>& world,
00221                             const Vector<Int>& absRel,
00222                             const CoordinateSystem& cSys,
00223                             const IPosition& shape) const;
00224 
00225     static void unitInit();
00226 
00227     void checkAxes (
00228         const IPosition& pixelAxes,
00229         const CoordinateSystem& cSys,
00230         const Vector<String>& quantityUnits
00231     ) const;
00232 
00233         static void convertPixel(
00234                 Double& pixel,
00235             const Double& value,
00236             const String& unit,
00237             const Int absRel,
00238             const Double refPix,
00239             const Int shape
00240         );
00241 private:
00242     String itsComment;
00243     Record itsAxesDesc;
00244 };
00245 
00246 
00247 inline Bool WCRegion::operator!= (const WCRegion& other) const
00248 {
00249    return (!operator==(other));
00250 }
00251 inline const String& WCRegion::comment() const
00252 {
00253     return itsComment;
00254 }
00255 inline void WCRegion::setComment (const String& comment)
00256 {
00257     itsComment = comment;
00258 }
00259 inline const Record& WCRegion::getAxesDesc() const
00260 {
00261     return itsAxesDesc;
00262 }
00263 
00264 
00265 
00266 } //# NAMESPACE CASA - END
00267 
00268 #endif