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#ifndef IMAGES_WCPOLYGON_H
27#define IMAGES_WCPOLYGON_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/coordinates/Coordinates/CoordinateSystem.h>
32#include <casacore/images/Regions/WCRegion.h>
33#include <casacore/lattices/LRegions/RegionType.h>
34#include <casacore/casa/Arrays/Vector.h>
35#include <casacore/casa/Quanta/Quantum.h>
36
37namespace casacore { // # NAMESPACE CASACORE - BEGIN
38
39// # Forward Declarations
40class LCRegion;
41class LCPolygon;
42class TableRecord;
43class IPosition;
44
45// <summary>
46// Class to define a 2-D polygonal world coordinate region in an image.
47// </summary>
48//
49// <use visibility=export>
50//
51// <reviewed reviewer="" date="" tests="">
52// </reviewed>
53//
54// <prerequisite>
55// <li> <linkto class=WCRegion>WCRegion</linkto>
56// <li> <linkto class=LCRegion>LCRegion</linkto>
57// <li> <linkto class=CoordinateSystem>CoordinateSystem</linkto>
58// </prerequisite>
59//
60// <synopsis>
61// The corners of the 2-D polygon are given by world coordinates. The
62// vertices are connected by straight lines in lattice coordinates.
63//
64// All this class does, apart from constructing itself, is know
65// how to save itself to a <src>Record</src> and how to convert itself
66// to an <src>LCRegion</src>. The conversion allows you to apply
67// a <src>WCPolygon</src> constructed with one <src>CoordinateSystem</src>
68// to another <src>CoordinateSystem</src>. That is, you can apply a
69// <src>WCPolygon</src> from this image to that image.
70//
71// At construction, it is assumed that the units of the world
72// coordinates are the same as those encapsulated in the
73// construction <src>CoordinateSystem</src>. You must tell
74// the constructor, which world axes the x and vectors
75// are associated with. Make sure you account for reordering.
76// For example, if you reordered [ra,dec] to be [dec,ra]
77// with the <src>CoordinateSystem::transpose(,)</src> fuction
78// and wished the x vector to be ra, and the y vector to
79// be dec, then <src>worldAxes=[1,0]</src>.
80//
81// The <src>CoordinateSystem</src> supplied to the <src>toLCRegion</src>
82// (which returns a pointer to an <src>LCPolygongon</src> object)
83// function does not have to be identical in structure to that with
84// which the <src>WCPolygon</src> was constructed. However, each world
85// axis given in the <src>worldAxes</src> vector at construction must be present
86// somewhere (order is unimportant) in the supplied <src>CoordinateSystem</src>.
87//
88//
89// The supplied lattice shape must be 2-D and corresponds to the
90// pixel axes of the two world axes of the supplied
91// <src>CoordinateSystem</src> which match those of the construction
92// <src>CoordinateSystem</src>.
93//
94// </synopsis>
95//
96// <example>
97// Let us give some examples with pseudo-code.
98// cSys is the construction CoordinateSystem
99// and cSys2 is the supplied CoordinateSystem.
100// We list their world axes in the square brackets.
101// The construction polygon values don't matter.
102// Similarly, the values of shape don't matter
103// as long as there are 2 of them.
104// <srcblock>
105// cSys = [ra, dec, freq];
106// cSys2 = [ra, dec];
107// axes=[0,1];
108// shape = [,];
109// WCPolygon poly(x, y, axes, cSys);
110// LCRegion* pR = poly.toLCRegion(cSys2, shape);
111// </srcblock>
112// The resultant LCPolygon will have vertices converted
113// with the [ra, dec] axes from cSys2
114// </example>
115//
116//
117// <example>
118// <srcblock>
119// cSys = [ra, dec, freq];
120// cSys2 = [ra, dec];
121// axes=[0,2];
122// shape = [,];
123// WCPolygon poly(x, y, axes, cSys);
124// LCRegion* pR = poly.toLCRegion(cSys2, shape);
125// </srcblock>
126// This will throw an exception because the [freq] axis
127// is missing in cSys2
128// </example>
129//
130// <example>
131// In this example we make it a bit harder by
132// reordering the pixel axes too. The new order
133// of the pixel axes in terms of the original
134// order [0,1,2...] is given after the world axes
135//
136// <srcblock>
137// cSys = [ra, dec, freq];
138// cSys2 = [stokes, freq, ra, dec], [3,2,1,0];
139// axes=[1,2];
140// shape = [,];
141// WCPolygon poly(x, y, axes, cSys);
142// LCRegion* pR = poly.toLCRegion(cSys2, shape);
143// </srcblock>
144// The resultant LCPolygon will have vertices converted
145// with the [ra, dec] axes from cSys2. The fact that
146// the pixel axes of cSys2 were reordered is accounted
147// for internally, but does not extrude further.
148// </example>
149//
150// <example>
151// In this example we make it a bit harder by
152// remove a pixel axis.
153//
154// <srcblock>
155// cSys = [ra, dec, freq];
156// cSys2 = [stokes, freq, ra, dec];
157// cSys2.removePixelAxis(1, cSys2.referencePixel()(1));
158// axes=[1,2];
159// shape = [,];
160// WCPolygon poly(x, y, axes, cSys);
161// LCRegion* pR = poly.toLCRegion(cSys2, shape);
162// </srcblock>
163// This will throw an exception because the removed
164// pixel axis, pixel axis number 1,
165// corresponds to the [freq] world axis
166// in cSys2, and the [freq] axis is one of those
167// specified at construction. Although the world
168// axis is still present, it is not possible to
169// convert to a pixel coordinate if the pixel axis
170// is not there.
171// </example>
172//
173// <motivation>
174// Users must be able to specify regions in world as well as lattice
175// coordinates.
176// </motivation>
177//
178// <note>
179// In all the constructors, you have to specifiy which plane
180// the polygon lies in. You do this by specifying the *PIXEL AXES*
181// (not the world axes) as this is the natural thing the user
182// will want to specify.
183// </note>
184//
185// <note>
186// For the constructors specifying the world values as simple doubles,
187// it is *ASSUMED* that the units of those doubles are the same as
188// the native units of the <src>CoordinateSystem</src> for each axis.
189// </note>
190//
191// <note>
192// World coordinates may be specified as absolute or offset. If the
193// latter, they are offset with respect to the reference pixel of
194// the <src>CoordinateSystem</src>.
195// </note>
196//
197// <todo asof="1998/05/20">
198// <li>
199// </todo>
200
201class WCPolygon : public WCRegion {
202 public:
204
205 // Construct from two vectors of world coordinates
206 // defining the polygon vertices.
207 // <group>
209 const IPosition& pixelAxes, const CoordinateSystem& cSys,
211 // </group>
212
213 // Construct from an <src>LCPolygon</src>.
214 WCPolygon(const LCPolygon& polygon, const IPosition& pixelAxes, const CoordinateSystem& cSys);
215
216 // Copy constructor (reference semantics).
217 WCPolygon(const WCPolygon& other);
218
219 // Destructor
220 virtual ~WCPolygon();
221
222 // Assignment (copy semantics)
224
225 // Comparison
226 virtual Bool operator==(const WCRegion& other) const;
227
228 // Clone a WCPolygon object.
229 virtual WCRegion* cloneRegion() const;
230
231 // WCPolygon cannot extend a region.
232 virtual Bool canExtend() const;
233
234 // Convert to an LCRegion using the given coordinate system.
235 virtual LCRegion* doToLCRegion(const CoordinateSystem& cSys, const IPosition& latticeShape,
236 const IPosition& pixelAxesMap, const IPosition& outOrder) const;
237
238 // Convert the WCPolygon object to a record.
239 // The record can be used to make the object persistent.
240 // The <src>tableName</src> argument can be used by derived
241 // classes (e.g. LCPagedMask) to put very large objects.
242 virtual TableRecord toRecord(const String& tableName) const;
243
244 // Convert to a WCPolygon from a record.
245 static WCPolygon* fromRecord(const TableRecord& rec, const String& tableName);
246
247 // Returns "WCPolygon"
249
250 // Return region type. Returns the class name
251 virtual String type() const;
252
253 protected:
260};
261
262} // namespace casacore
263
264#endif
AbsRelType
Define if a region is absolute or relative.
Definition RegionType.h:71
String: the storage and methods of handling collections of characters.
Definition String.h:355
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:258
static String className()
Returns "WCPolygon".
WCPolygon(const LCPolygon &polygon, const IPosition &pixelAxes, const CoordinateSystem &cSys)
Construct from an LCPolygon.
IPosition itsPixelAxes
Definition WCPolygon.h:256
Quantum< Vector< Double > > itsX
Definition WCPolygon.h:254
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:255
CoordinateSystem itsCSys
Definition WCPolygon.h:257
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.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40