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