casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
WCPolygon.h
Go to the documentation of this file.
00001 //# WCPolygon.h: Class to define a polygonal world coordinate region
00002 //# Copyright (C) 1998,1999,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: WCPolygon.h 20615 2009-06-09 02:16:01Z Malte.Marquarding $
00027 
00028 
00029 #ifndef IMAGES_WCPOLYGON_H
00030 #define IMAGES_WCPOLYGON_H
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <coordinates/Coordinates/CoordinateSystem.h>
00035 #include <images/Regions/WCRegion.h>
00036 #include <lattices/Lattices/RegionType.h>
00037 #include <casa/Arrays/Vector.h>
00038 #include <casa/Quanta/Quantum.h>
00039 
00040 namespace casa { //# NAMESPACE CASA - BEGIN
00041 
00042 //# Forward Declarations
00043 class LCRegion;
00044 class LCPolygon;
00045 class TableRecord;
00046 class IPosition;
00047 
00048 
00049 // <summary>
00050 // Class to define a 2-D polygonal world coordinate region in an image.
00051 // </summary>
00052 //
00053 // <use visibility=export>
00054 //
00055 // <reviewed reviewer="" date="" tests="">
00056 // </reviewed>
00057 //
00058 // <prerequisite>
00059 //   <li> <linkto class=WCRegion>WCRegion</linkto>
00060 //   <li> <linkto class=LCRegion>LCRegion</linkto>
00061 //   <li> <linkto class=CoordinateSystem>CoordinateSystem</linkto>
00062 // </prerequisite>
00063 //
00064 // <synopsis> 
00065 // The corners of the 2-D polygon are given by world coordinates. The
00066 // vertices are connected by straight lines in lattice coordinates.
00067 //
00068 // All this class does, apart from constructing itself, is know
00069 // how to save itself to a <src>Record</src> and how to convert itself
00070 // to an <src>LCRegion</src>.  The conversion allows you to apply
00071 // a <src>WCPolygon</src> constructed with one <src>CoordinateSystem</src> 
00072 // to another <src>CoordinateSystem</src>. That is, you can apply a 
00073 // <src>WCPolygon</src> from this image to that image.
00074 //
00075 // At construction, it is assumed that the units of the world 
00076 // coordinates are the same as those  encapsulated in the 
00077 // construction <src>CoordinateSystem</src>.   You must tell
00078 // the constructor, which world axes the x and vectors
00079 // are associated with.  Make sure you account for reordering.
00080 // For example, if you reordered [ra,dec] to be [dec,ra]
00081 // with the <src>CoordinateSystem::transpose(,)</src> fuction
00082 // and wished the x vector to be ra, and the y vector to
00083 // be dec, then <src>worldAxes=[1,0]</src>.
00084 //
00085 // The <src>CoordinateSystem</src> supplied to the <src>toLCRegion</src> 
00086 // (which returns a pointer to an <src>LCPolygongon</src> object)
00087 // function does not have to be identical in structure to that with
00088 // which the <src>WCPolygon</src> was constructed.  However, each world 
00089 // axis given in the <src>worldAxes</src> vector at construction must be present 
00090 // somewhere (order is unimportant) in the supplied <src>CoordinateSystem</src>.
00091 //
00092 //
00093 // The supplied lattice shape must be 2-D and corresponds to the 
00094 // pixel axes of the two world axes of the supplied
00095 // <src>CoordinateSystem</src> which match those of the construction
00096 // <src>CoordinateSystem</src>.
00097 //
00098 // </synopsis> 
00099 //
00100 // <example>
00101 // Let us give some examples with pseudo-code. 
00102 // cSys is the construction CoordinateSystem 
00103 // and cSys2 is the supplied CoordinateSystem.
00104 // We list their world axes in the square brackets.
00105 // The construction polygon values don't matter.
00106 // Similarly, the values of shape don't matter
00107 // as long as there are 2 of them.
00108 // <srcblock>
00109 // cSys = [ra, dec, freq];
00110 // cSys2 = [ra, dec];
00111 // axes=[0,1];
00112 // shape = [,];
00113 // WCPolygon poly(x, y, axes, cSys);
00114 // LCRegion* pR = poly.toLCRegion(cSys2, shape);
00115 // </srcblock>
00116 // The resultant LCPolygon will have vertices converted
00117 // with the [ra, dec] axes from cSys2
00118 // </example>
00119 //
00120 //
00121 // <example>
00122 // <srcblock>
00123 // cSys = [ra, dec, freq];
00124 // cSys2 = [ra, dec];
00125 // axes=[0,2];
00126 // shape = [,];
00127 // WCPolygon poly(x, y, axes, cSys);
00128 // LCRegion* pR = poly.toLCRegion(cSys2, shape);
00129 // </srcblock>
00130 // This will throw an exception because the [freq] axis
00131 // is missing in cSys2
00132 // </example>
00133 //
00134 // <example>
00135 // In this example we make it a bit harder by
00136 // reordering the pixel axes too.    The new order
00137 // of the pixel axes in terms of the original
00138 // order [0,1,2...] is given after the world axes
00139 //
00140 // <srcblock>
00141 // cSys = [ra, dec, freq];
00142 // cSys2 = [stokes, freq, ra, dec], [3,2,1,0];
00143 // axes=[1,2];
00144 // shape = [,];
00145 // WCPolygon poly(x, y, axes, cSys);
00146 // LCRegion* pR = poly.toLCRegion(cSys2, shape);
00147 // </srcblock>
00148 // The resultant LCPolygon will have vertices converted
00149 // with the [ra, dec] axes from cSys2.  The fact that
00150 // the pixel axes of cSys2 were reordered is  accounted
00151 // for internally, but does not extrude further.
00152 // </example>
00153 //
00154 // <example>
00155 // In this example we make it a bit harder by
00156 // remove a pixel axis.
00157 //
00158 // <srcblock>
00159 // cSys = [ra, dec, freq];
00160 // cSys2 = [stokes, freq, ra, dec];
00161 // cSys2.removePixelAxis(1, cSys2.referencePixel()(1));
00162 // axes=[1,2];
00163 // shape = [,];
00164 // WCPolygon poly(x, y, axes, cSys);
00165 // LCRegion* pR = poly.toLCRegion(cSys2, shape);
00166 // </srcblock>
00167 // This will throw an exception because the removed
00168 // pixel axis, pixel axis  number 1,
00169 // corresponds to the [freq] world axis
00170 // in cSys2, and the [freq] axis is one of those
00171 // specified at construction.   Although the world
00172 // axis is still present, it is not possible to
00173 // convert to a pixel coordinate if the pixel axis
00174 // is not there.
00175 // </example>
00176 //
00177 // <motivation>
00178 // Users must be able to specify regions in world as well as lattice
00179 // coordinates. 
00180 // </motivation>
00181 //
00182 // <note>
00183 //  In all the constructors, you have to specifiy which plane
00184 //  the polygon lies in.  You do this by specifying the *PIXEL AXES*
00185 //  (not the world axes) as this is the natural thing the user
00186 //  will want to specify.
00187 // </note>
00188 //
00189 // <note>
00190 //  For the constructors specifying the world values as simple doubles,
00191 //  it is *ASSUMED* that the units of those doubles are the same as
00192 //  the native units of the <src>CoordinateSystem</src> for each axis.
00193 // </note>
00194 //  
00195 // <note>
00196 //  World coordinates may be specified as absolute or offset.  If the
00197 //  latter, they are offset with respect to the reference pixel of
00198 //  the <src>CoordinateSystem</src>.
00199 //  </note>
00200 //
00201 // <todo asof="1998/05/20">
00202 // <li> 
00203 // </todo>
00204 
00205 class WCPolygon : public WCRegion
00206 {
00207 public:
00208     WCPolygon();
00209 
00210    // Construct from two vectors of world coordinates 
00211    // defining the polygon vertices.  
00212    // <group>
00213    WCPolygon(const Quantum<Vector<Double> >& x,
00214              const Quantum<Vector<Double> >& y,
00215              const IPosition& pixelAxes,
00216              const CoordinateSystem& cSys,
00217              const RegionType::AbsRelType absRel=RegionType::Abs);
00218    // </group>
00219 
00220    // Construct from an <src>LCPolygon</src>. 
00221    WCPolygon(const LCPolygon& polygon,
00222              const IPosition& pixelAxes,
00223              const CoordinateSystem& cSys);
00224 
00225    // Copy constructor (reference semantics).
00226    WCPolygon (const WCPolygon& other);
00227 
00228    // Destructor
00229    virtual ~WCPolygon();
00230 
00231    // Assignment (copy semantics) 
00232    WCPolygon& operator= (const WCPolygon& other);
00233 
00234    // Comparison
00235    virtual Bool operator==(const WCRegion& other) const;
00236 
00237    // Clone a WCPolygon object.
00238    virtual WCRegion* cloneRegion() const;
00239 
00240    // WCPolygon cannot extend a region.
00241    virtual Bool canExtend() const;   
00242 
00243    // Convert to an LCRegion using the given coordinate system.
00244    virtual LCRegion* doToLCRegion (const CoordinateSystem& cSys,
00245                                    const IPosition& latticeShape,
00246                                    const IPosition& pixelAxesMap,
00247                                    const IPosition& outOrder) const;
00248 
00249    // Convert the WCPolygon object to a record.
00250    // The record can be used to make the object persistent.
00251    // The <src>tableName</src> argument can be used by derived
00252    // classes (e.g. LCPagedMask) to put very large objects.
00253    virtual TableRecord toRecord(const String& tableName) const;
00254 
00255    // Convert to a WCPolygon from a record.
00256    static WCPolygon* fromRecord (const TableRecord& rec,
00257                                  const String& tableName);
00258 
00259    // Returns "WCPolygon"
00260    static String className();
00261 
00262    // Return region type.  Returns the class name   
00263    virtual String type() const;    
00264 
00265 
00266 protected:
00267    Quantum<Vector<Double> > itsX;
00268    Quantum<Vector<Double> > itsY;
00269    IPosition itsPixelAxes;   
00270    CoordinateSystem itsCSys;
00271    RegionType::AbsRelType itsAbsRel;
00272    Bool itsNull;
00273 
00274 };
00275 
00276 
00277 
00278 } //# NAMESPACE CASA - END
00279 
00280 #endif