casacore
Loading...
Searching...
No Matches
WCPolygon.h
Go to the documentation of this file.
1//# WCPolygon.h: Class to define a polygonal world coordinate region
2//# Copyright (C) 1998,1999,2001
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26
27#ifndef IMAGES_WCPOLYGON_H
28#define IMAGES_WCPOLYGON_H
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/coordinates/Coordinates/CoordinateSystem.h>
33#include <casacore/images/Regions/WCRegion.h>
34#include <casacore/lattices/LRegions/RegionType.h>
35#include <casacore/casa/Arrays/Vector.h>
36#include <casacore/casa/Quanta/Quantum.h>
37
38namespace casacore { //# NAMESPACE CASACORE - BEGIN
39
40//# Forward Declarations
41class LCRegion;
42class LCPolygon;
43class TableRecord;
44class IPosition;
45
46
47// <summary>
48// Class to define a 2-D polygonal world coordinate region in an image.
49// </summary>
50//
51// <use visibility=export>
52//
53// <reviewed reviewer="" date="" tests="">
54// </reviewed>
55//
56// <prerequisite>
57// <li> <linkto class=WCRegion>WCRegion</linkto>
58// <li> <linkto class=LCRegion>LCRegion</linkto>
59// <li> <linkto class=CoordinateSystem>CoordinateSystem</linkto>
60// </prerequisite>
61//
62// <synopsis>
63// The corners of the 2-D polygon are given by world coordinates. The
64// vertices are connected by straight lines in lattice coordinates.
65//
66// All this class does, apart from constructing itself, is know
67// how to save itself to a <src>Record</src> and how to convert itself
68// to an <src>LCRegion</src>. The conversion allows you to apply
69// a <src>WCPolygon</src> constructed with one <src>CoordinateSystem</src>
70// to another <src>CoordinateSystem</src>. That is, you can apply a
71// <src>WCPolygon</src> from this image to that image.
72//
73// At construction, it is assumed that the units of the world
74// coordinates are the same as those encapsulated in the
75// construction <src>CoordinateSystem</src>. You must tell
76// the constructor, which world axes the x and vectors
77// are associated with. Make sure you account for reordering.
78// For example, if you reordered [ra,dec] to be [dec,ra]
79// with the <src>CoordinateSystem::transpose(,)</src> fuction
80// and wished the x vector to be ra, and the y vector to
81// be dec, then <src>worldAxes=[1,0]</src>.
82//
83// The <src>CoordinateSystem</src> supplied to the <src>toLCRegion</src>
84// (which returns a pointer to an <src>LCPolygongon</src> object)
85// function does not have to be identical in structure to that with
86// which the <src>WCPolygon</src> was constructed. However, each world
87// axis given in the <src>worldAxes</src> vector at construction must be present
88// somewhere (order is unimportant) in the supplied <src>CoordinateSystem</src>.
89//
90//
91// The supplied lattice shape must be 2-D and corresponds to the
92// pixel axes of the two world axes of the supplied
93// <src>CoordinateSystem</src> which match those of the construction
94// <src>CoordinateSystem</src>.
95//
96// </synopsis>
97//
98// <example>
99// Let us give some examples with pseudo-code.
100// cSys is the construction CoordinateSystem
101// and cSys2 is the supplied CoordinateSystem.
102// We list their world axes in the square brackets.
103// The construction polygon values don't matter.
104// Similarly, the values of shape don't matter
105// as long as there are 2 of them.
106// <srcblock>
107// cSys = [ra, dec, freq];
108// cSys2 = [ra, dec];
109// axes=[0,1];
110// shape = [,];
111// WCPolygon poly(x, y, axes, cSys);
112// LCRegion* pR = poly.toLCRegion(cSys2, shape);
113// </srcblock>
114// The resultant LCPolygon will have vertices converted
115// with the [ra, dec] axes from cSys2
116// </example>
117//
118//
119// <example>
120// <srcblock>
121// cSys = [ra, dec, freq];
122// cSys2 = [ra, dec];
123// axes=[0,2];
124// shape = [,];
125// WCPolygon poly(x, y, axes, cSys);
126// LCRegion* pR = poly.toLCRegion(cSys2, shape);
127// </srcblock>
128// This will throw an exception because the [freq] axis
129// is missing in cSys2
130// </example>
131//
132// <example>
133// In this example we make it a bit harder by
134// reordering the pixel axes too. The new order
135// of the pixel axes in terms of the original
136// order [0,1,2...] is given after the world axes
137//
138// <srcblock>
139// cSys = [ra, dec, freq];
140// cSys2 = [stokes, freq, ra, dec], [3,2,1,0];
141// axes=[1,2];
142// shape = [,];
143// WCPolygon poly(x, y, axes, cSys);
144// LCRegion* pR = poly.toLCRegion(cSys2, shape);
145// </srcblock>
146// The resultant LCPolygon will have vertices converted
147// with the [ra, dec] axes from cSys2. The fact that
148// the pixel axes of cSys2 were reordered is accounted
149// for internally, but does not extrude further.
150// </example>
151//
152// <example>
153// In this example we make it a bit harder by
154// remove a pixel axis.
155//
156// <srcblock>
157// cSys = [ra, dec, freq];
158// cSys2 = [stokes, freq, ra, dec];
159// cSys2.removePixelAxis(1, cSys2.referencePixel()(1));
160// axes=[1,2];
161// shape = [,];
162// WCPolygon poly(x, y, axes, cSys);
163// LCRegion* pR = poly.toLCRegion(cSys2, shape);
164// </srcblock>
165// This will throw an exception because the removed
166// pixel axis, pixel axis number 1,
167// corresponds to the [freq] world axis
168// in cSys2, and the [freq] axis is one of those
169// specified at construction. Although the world
170// axis is still present, it is not possible to
171// convert to a pixel coordinate if the pixel axis
172// is not there.
173// </example>
174//
175// <motivation>
176// Users must be able to specify regions in world as well as lattice
177// coordinates.
178// </motivation>
179//
180// <note>
181// In all the constructors, you have to specifiy which plane
182// the polygon lies in. You do this by specifying the *PIXEL AXES*
183// (not the world axes) as this is the natural thing the user
184// will want to specify.
185// </note>
186//
187// <note>
188// For the constructors specifying the world values as simple doubles,
189// it is *ASSUMED* that the units of those doubles are the same as
190// the native units of the <src>CoordinateSystem</src> for each axis.
191// </note>
192//
193// <note>
194// World coordinates may be specified as absolute or offset. If the
195// latter, they are offset with respect to the reference pixel of
196// the <src>CoordinateSystem</src>.
197// </note>
198//
199// <todo asof="1998/05/20">
200// <li>
201// </todo>
202
203class WCPolygon : public WCRegion
204{
205public:
207
208 // Construct from two vectors of world coordinates
209 // defining the polygon vertices.
210 // <group>
212 const Quantum<Vector<Double> >& y,
213 const IPosition& pixelAxes,
214 const CoordinateSystem& cSys,
216 // </group>
217
218 // Construct from an <src>LCPolygon</src>.
219 WCPolygon(const LCPolygon& polygon,
220 const IPosition& pixelAxes,
221 const CoordinateSystem& cSys);
222
223 // Copy constructor (reference semantics).
224 WCPolygon (const WCPolygon& other);
225
226 // Destructor
227 virtual ~WCPolygon();
228
229 // Assignment (copy semantics)
231
232 // Comparison
233 virtual Bool operator==(const WCRegion& other) const;
234
235 // Clone a WCPolygon object.
236 virtual WCRegion* cloneRegion() const;
237
238 // WCPolygon cannot extend a region.
239 virtual Bool canExtend() const;
240
241 // Convert to an LCRegion using the given coordinate system.
243 const IPosition& latticeShape,
244 const IPosition& pixelAxesMap,
245 const IPosition& outOrder) const;
246
247 // Convert the WCPolygon object to a record.
248 // The record can be used to make the object persistent.
249 // The <src>tableName</src> argument can be used by derived
250 // classes (e.g. LCPagedMask) to put very large objects.
251 virtual TableRecord toRecord(const String& tableName) const;
252
253 // Convert to a WCPolygon from a record.
254 static WCPolygon* fromRecord (const TableRecord& rec,
255 const String& tableName);
256
257 // Returns "WCPolygon"
259
260 // Return region type. Returns the class name
261 virtual String type() const;
262
263
264protected:
271
272};
273
274
275
276} //# NAMESPACE CASACORE - END
277
278#endif
AbsRelType
Define if a region is absolute or relative.
Definition RegionType.h:73
String: the storage and methods of handling collections of characters.
Definition String.h:223
virtual String type() const
Return region type.
virtual Bool operator==(const WCRegion &other) const
Comparison.
WCPolygon(const WCPolygon &other)
Copy constructor (reference semantics).
WCPolygon & operator=(const WCPolygon &other)
Assignment (copy semantics)
virtual TableRecord toRecord(const String &tableName) const
Convert the WCPolygon object to a record.
WCPolygon(const Quantum< Vector< Double > > &x, const Quantum< Vector< Double > > &y, const IPosition &pixelAxes, const CoordinateSystem &cSys, const RegionType::AbsRelType absRel=RegionType::Abs)
Construct from two vectors of world coordinates defining the polygon vertices.
virtual Bool canExtend() const
WCPolygon cannot extend a region.
RegionType::AbsRelType itsAbsRel
Definition WCPolygon.h:269
static String className()
Returns "WCPolygon".
WCPolygon(const LCPolygon &polygon, const IPosition &pixelAxes, const CoordinateSystem &cSys)
Construct from an LCPolygon.
IPosition itsPixelAxes
Definition WCPolygon.h:267
Quantum< Vector< Double > > itsX
Definition WCPolygon.h:265
static WCPolygon * fromRecord(const TableRecord &rec, const String &tableName)
Convert to a WCPolygon from a record.
virtual WCRegion * cloneRegion() const
Clone a WCPolygon object.
Quantum< Vector< Double > > itsY
Definition WCPolygon.h:266
CoordinateSystem itsCSys
Definition WCPolygon.h:268
virtual LCRegion * doToLCRegion(const CoordinateSystem &cSys, const IPosition &latticeShape, const IPosition &pixelAxesMap, const IPosition &outOrder) const
Convert to an LCRegion using the given coordinate system.
virtual ~WCPolygon()
Destructor.
this file contains all the compiler specific defines
Definition mainpage.dox:28
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40