casacore
Loading...
Searching...
No Matches
WCBox.h
Go to the documentation of this file.
1// # WCBox.h: Class to define a box shaped WC 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_WCBOX_H
27#define IMAGES_WCBOX_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 TableRecord;
42class IPosition;
43
44// <summary>
45// Class to define a world coordinate box region of interest in an image.
46// </summary>
47//
48// <use visibility=export>
49//
50// <reviewed reviewer="" date="" tests="">
51// </reviewed>
52//
53// <prerequisite>
54// <li> <linkto class=WCRegion>WCRegion</linkto>
55// <li> <linkto class=LCRegion>LCRegion</linkto>
56// <li> <linkto class=CoordinateSystem>CoordinateSystem</linkto>
57// </prerequisite>
58//
59// <synopsis>
60// The corners of the box are specified in world coordinates, but the
61// region enclosed by those corners is a box in lattice coordinates.
62// Thus, the volume enclosed does not follow world coordinate contours.
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>WCBox</src> constructed with one <src>CoordinateSystem</src>
68// to another <src>CoordinateSystem</src>. That is, you can apply a
69// <src>WCBox</src> from this image to that image.
70//
71// The flexibility of the <src>CoordinateSystem</src> class should
72// be kept in mind when using this class. Recall that a
73// <src>CoordinateSystem</src> has world and pixel axes, and
74// that these axes can be independently removed and independently
75// (re)ordered.
76//
77// During construction, the length of the world coordinate vectors may be
78// smaller than the number world axes in the supplied <src>CoordinateSystem</src>.
79// It is assumed that the units of the world coordinates are the same as those
80// encapsulated in the construction <src>CoordinateSystem</src> and in the same
81// order as specified (either intrinsically, or by the world axes
82// specification vectors).
83//
84// The following rules are followed during conversion to an <src>LCRegion</src>.
85// <ol>
86// <li> The number of elements in the supplied <src>latticeShape</src> must be equal
87// to the number of pixel axes in the supplied <src>CoordinateSystem</src>.
88// <li> The order of the pixel axes in the supplied <src>CoordinateSystem</src>
89// is assumed to be the order of the axes in the lattice for which the
90// supplied <src>latticeShape</src> is appropriate.
91// <li> The <src>CoordinateSystem</src> supplied to the <src>toLCRegion</src>
92// function does not have to be identical in structure to that from
93// which the <src>WCBox</src> was constructed. They can consist
94// of different numbers of world and pixel axes and be in different
95// orders.
96// <li> For every world axis in the supplied <src>CoordinateSystem</src>
97// that is also present (somewhere) in the construction <src>CoordinateSystem</src>
98// the blc/trc corresponding to that world axis will be
99// converted to pixels appropriate to the supplied <src>CoordinateSystem</src>.
100// The order of this pixel based blc/trc will be the order of the pixel axes of
101// the supplied <src>CoordinateSystem</src>
102// <li> For every world axis in the supplied <src>CoordinateSystem</src>
103// that is not present in the construction <src>CoordinateSystem</src>,
104// the supplied <src>latticeShape</src> value for the corresponding
105// pixel axis is used, setting <src>blc=0</src> and <src>trc=latticeShape-1</src>
106// for that axis.
107// <li> Once the pixel based blc/trc has been created, then, with
108// the supplied <src>latticeShape</src>, it is used to create the
109// <src>LCBox</src>, which is supplied as a pointer to the base
110// class <src>LCRegion</src>.
111// </ol>
112//
113// Note that when determining whether a world axis from one
114// <src>CoordinateSystem</src>is present on another, it is
115// considered to not be a match if two coordinates of the
116// same type (e.g. <src>DirectionCoordinate</src>) have different
117// specific types (e.g. J2000 and GALACTIC, or TOPO and LSR for
118// a <src>SpectralCoordinate</src>)
119// </synopsis>
120//
121// <example>
122// Let us give some examples with pseudo-code.
123// cSys is the construction CoordinateSystem
124// and cSys2 is the supplied CoordinateSystem.
125// We list their world axes in the square brackets.
126// The construction blc/trc values don't matter
127// as long as there cSys.nWorldAxes() of them.
128// Similarly, the values of shape don't matter
129// as long as there are cSys2.nPixelAxes() of them.
130// <srcblock>
131// cSys = [ra, dec, freq];
132// cSys2 = [ra, dec];
133// blc = [,,];
134// trc = [,,];
135// shape = [,];
136// WCBox box(blc, trc, cSys);
137// LCRegion* pR = box.toLCRegion(cSys2, shape);
138// </srcblock>
139// The resultant LCBox will have corners converted
140// according to
141// <srcblock>
142// blcLC(0) <- blc(0);
143// blcLC(1) <- blc(1);
144// trcLC(0) <- trc(0);
145// trcLC(1) <- trc(1);
146// </srcblock>
147//
148// </example>
149//
150// <example>
151// <srcblock>
152// cSys = [ra, dec, freq];
153// cSys2 = [freq, stokes];
154// blc = [,,];
155// trc = [,,];
156// shape = [,];
157// WCBox box(blc, trc, cSys);
158// LCRegion* pR = box.toLCRegion(cSys2, shape);
159// </srcblock>
160//
161// The resultant LCBox will have corners converted
162// according to
163//
164// <srcblock>
165// blcLC(0) <- blc(2);
166// blcLC(1) = 0;
167// trcLC(0) <- trc(2);
168// trcLC(1) = shape(1) - 1;
169// </srcblock>
170//
171// </example>
172//
173// <example>
174// <srcblock>
175// cSys = [ra, dec];
176// cSys2 = [ra, dec, freq];
177// blc = [,];
178// trc = [,];
179// shape = [,,];
180// WCBox box(blc, trc, cSys);
181// LCRegion* pR = box.toLCRegion(cSys2, shape);
182// </srcblock>
183//
184// The resultant LCBox will have corners converted
185// according to
186//
187// <srcblock>
188// blcLC(0) <- blc(0);
189// blcLC(1) <- blc(1);
190// blcLC(2) = 0l
191// trcLC(0) <- trc(0);
192// trcLC(1) <- trc(1);
193// trcLC(2) = shape(2)-1;
194// </srcblock>
195//
196// </example>
197//
198// <example>
199// <srcblock>
200// cSys = [ra, dec, freq];
201// cSys2 = [freq, ra, dec];
202// blc = [,,];
203// trc = [,,];
204// shape = [,,];
205// WCBox box(blc, trc, cSys);
206// LCRegion* pR = box.toLCRegion(cSys2, shape);
207// </srcblock>
208//
209// The resultant LCBox will have corners converted
210// according to
211//
212// <srcblock>
213// blcLC(0) <- blc(2);
214// blcLC(1) <- blc(0);
215// blcLC(2) <- blc(1);
216// trcLC(0) <- trc(2);
217// trcLC(1) <- trc(0);
218// trcLC(2) <- trc(1);
219// </srcblock>
220//
221// </example>
222//
223// <example>
224// In this example we make it a bit harder by
225// reordering the pixel axes too. The new order
226// of the pixel axes in terms of the original
227// order [0,1,2] is given after the world axes
228//
229// <srcblock>
230// cSys = [ra, dec, freq], [0, 1, 2];
231// cSys2 = [freq, ra, dec, stokes], [3, 0, 2, 1];
232// blc = [,,];
233// trc = [,,];
234// shape = [,,,];
235// WCBox box(blc, trc, cSys);
236// LCRegion* pR = box.toLCRegion(cSys2, shape);
237// </srcblock>
238//
239// Take the first world axis of cSys2 as an example.
240// First, "freq" is found as the world axis number
241// 2 in cSys. Then, when it is converted to
242// a pixel coordinate, it will turn up as
243// the value on pixel axis 1. The supplied shape
244// must be appropriate to a [stokes, freq, dec, ra] lattice.
245// The resultant LCBox will therefore have corners
246// converted according to
247//
248// <srcblock>
249// blcLC(0) = 0
250// blcLC(1) <- blc(2);
251// blcLC(2) <- blc(1);
252// blcLC(3) <- blc(0);
253//
254// trcLC(0) = shape(0)-1;
255// trcLC(1) <- trc(2);
256// trcLC(2) <- trc(1);
257// trcLC(3) <- trc(0);
258// </srcblock>
259// </example>
260//
261// <motivation>
262// Users must be able to specify regions in world as well as lattice
263// coordinates.
264// </motivation>
265//
266// <note>
267// In all of the constructors, the order of the specified world
268// coordinates is that of the *PIXEL AXES* (not world axes) in the
269// <src>CoordinateSystem</src>. This is the natural order for a user to want
270// to specify them in.
271// </note>
272//
273// <note>
274// For the constructors specifying the world values as simple doubles,
275// it is *ASSUMED* that the units of those doubles are the same as
276// the native units of the <src>CoordinateSystem</src> for each axis.
277// </note>
278//
279// <note>
280// World coordinates may be specified as absolute or offset. If the
281// latter, they are offset with respect to the reference pixel of
282// the <src>CoordinateSystem</src>.
283// </note>
284// <todo asof="1998/05/20">
285// <li> Implement offset coordinates
286// </todo>
287
288class WCBox : public WCRegion {
289 public:
291
292 // Construct from vectors of world coordinates
293 // defining the box corners. It is assumed that the
294 // order of the values is in the order of the pixel axes
295 // in the given coordinate system.
296 // <group>
298 const CoordinateSystem& cSys, const Vector<Int>& absRel);
299 // </group>
300
301 // Construct from vectors of world coordinates
302 // defining the box corners. You specify the pixel
303 // axis order of the world values.
304 // <group>
306 const IPosition& pixelAxes, const CoordinateSystem& cSys, const Vector<Int>& absRel);
307 // </group>
308
309 // Construct from the bounding box of an <src>LCRegion</src>.
310 WCBox(const LCRegion& region, const CoordinateSystem& cSys);
311
312 // Copy constructor (reference semantics [except for <src>CoordinateSystem</src>])
313 WCBox(const WCBox& other);
314
315 // Destructor
316 virtual ~WCBox();
317
318 // Assignment (copy semantics)
319 WCBox& operator=(const WCBox& other);
320
321 // Comparison
322 virtual Bool operator==(const WCRegion& other) const;
323
324 // Clone a WCBox object.
325 virtual WCRegion* cloneRegion() const;
326
327 // WCBox can extend a region.
328 virtual Bool canExtend() const;
329
330 // Make a new box from the given axesin this box.
331 WCBox splitBox(const IPosition& axes) const;
332
333 // Convert to an LCRegion using the supplied <src>CoordinateSystem</src>
334 // and shape.
335 virtual LCRegion* doToLCRegion(const CoordinateSystem& cSys, const IPosition& latticeShape,
336 const IPosition& pixelAxesMap, const IPosition& outOrder) const;
337
338 // Convert the WCBox object to a record.
339 // The record can be used to make the object persistent.
340 // The <src>tableName</src> argument can be used by derived
341 // classes (e.g. LCPagedMask) to put very large objects.
342 virtual TableRecord toRecord(const String& tableName) const;
343
344 // Convert to a WCBox from a record.
345 static WCBox* fromRecord(const TableRecord& rec, const String& tableName);
346
347 // Returns WCBox
349
350 // Return region type. Returns the class name
351 virtual String type() const;
352
353 private:
360
361 // Check units of quanta are consistent with CoordinateSystem
362 void checkUnits(const IPosition& pixelAxes, const Vector<Quantum<Double>>& values,
363 const CoordinateSystem& cSys);
364
365 // Convert relative pixels to absolute or fill in defaults
366 void convertPixel(Double& pixel, const Quantum<Double>& value, const Int absRel,
367 const Double refPix, const Int shape, const Bool isBlc) const;
368};
369
370} // namespace casacore
371
372#endif
String: the storage and methods of handling collections of characters.
Definition String.h:355
virtual Bool canExtend() const
WCBox can extend a region.
WCBox splitBox(const IPosition &axes) const
Make a new box from the given axesin this box.
IPosition itsPixelAxes
Definition WCBox.h:356
virtual Bool operator==(const WCRegion &other) const
Comparison.
CoordinateSystem itsCSys
Definition WCBox.h:357
virtual TableRecord toRecord(const String &tableName) const
Convert the WCBox object to a record.
Vector< Quantum< Double > > itsBlc
Definition WCBox.h:354
static WCBox * fromRecord(const TableRecord &rec, const String &tableName)
Convert to a WCBox from a record.
virtual LCRegion * doToLCRegion(const CoordinateSystem &cSys, const IPosition &latticeShape, const IPosition &pixelAxesMap, const IPosition &outOrder) const
Convert to an LCRegion using the supplied CoordinateSystem and shape.
void checkUnits(const IPosition &pixelAxes, const Vector< Quantum< Double > > &values, const CoordinateSystem &cSys)
Check units of quanta are consistent with CoordinateSystem.
WCBox(const LCRegion &region, const CoordinateSystem &cSys)
Construct from the bounding box of an LCRegion.
WCBox(const Vector< Quantum< Double > > &blc, const Vector< Quantum< Double > > &trc, const CoordinateSystem &cSys, const Vector< Int > &absRel)
Construct from vectors of world coordinates defining the box corners.
virtual WCRegion * cloneRegion() const
Clone a WCBox object.
virtual ~WCBox()
Destructor.
WCBox(const WCBox &other)
Copy constructor (reference semantics [except for CoordinateSystem]).
WCBox(const Vector< Quantum< Double > > &blc, const Vector< Quantum< Double > > &trc, const IPosition &pixelAxes, const CoordinateSystem &cSys, const Vector< Int > &absRel)
Construct from vectors of world coordinates defining the box corners.
Vector< Int > itsAbsRel
Definition WCBox.h:358
virtual String type() const
Return region type.
void convertPixel(Double &pixel, const Quantum< Double > &value, const Int absRel, const Double refPix, const Int shape, const Bool isBlc) const
Convert relative pixels to absolute or fill in defaults.
Vector< Quantum< Double > > itsTrc
Definition WCBox.h:355
static String className()
Returns WCBox.
WCBox & operator=(const WCBox &other)
Assignment (copy semantics).
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360
double Double
Definition aipstype.h:53