WCBox.h

Classes

WCBox -- Class to define a world coordinate box region of interest in an image. (full description)

class WCBox : public WCRegion

Interface

Public Members
WCBox()
WCBox(const Vector<Quantum<Double> >& blc, const Vector<Quantum<Double> >& trc, const CoordinateSystem& cSys, const Vector<Int>& absRel)
WCBox(const Vector<Quantum<Double> >& blc, const Vector<Quantum<Double> >& trc, const IPosition& pixelAxes, const CoordinateSystem& cSys, const Vector<Int>& absRel)
WCBox(const LCRegion& region, const CoordinateSystem& cSys)
WCBox (const WCBox& other)
virtual ~WCBox()
WCBox& operator= (const WCBox& other)
virtual Bool operator==(const WCRegion& other) const
virtual WCRegion* cloneRegion() const
virtual Bool canExtend() const
WCBox splitBox (const IPosition& axes) const
virtual LCRegion* doToLCRegion (const CoordinateSystem& cSys, const IPosition& latticeShape, const IPosition& pixelAxesMap, const IPosition& outOrder) const
virtual TableRecord toRecord(const String& tableName) const
static WCBox* fromRecord (const TableRecord& rec, const String& tableName)
static String className()
virtual String type() const
Private Members
void checkUnits (const IPosition& pixelAxes, const Vector<Quantum<Double> >& values, const CoordinateSystem& cSys)
void convertPixel(Double& pixel, const Quantum<Double>& value, const Int absRel, const Double refPix, const Int shape, const Bool isBlc) const
static void unitInit()

Description

Prerequisite

Synopsis

The corners of the box are specified in world coordinates, but the region enclosed by those corners is a box in lattice coordinates. Thus, the volume enclosed does not follow world coordinate contours.

All this class does, apart from constructing itself, is know how to save itself to a Record and how to convert itself to an LCRegion. The conversion allows you to apply a WCBox constructed with one CoordinateSystem to another CoordinateSystem. That is, you can apply a WCBox from this image to that image.

The flexibility of the CoordinateSystem class should be kept in mind when using this class. Recall that a CoordinateSystem has world and pixel axes, and that these axes can be independently removed and independently (re)ordered.

During construction, the length of the world coordinate vectors may be smaller than the number world axes in the supplied CoordinateSystem. It is assumed that the units of the world coordinates are the same as those encapsulated in the construction CoordinateSystem and in the same order as specified (either intrinsically, or by the world axes specification vectors).

The following rules are followed during conversion to an LCRegion.

  1. The number of elements in the supplied latticeShape must be equal to the number of pixel axes in the supplied CoordinateSystem.
  2. The order of the pixel axes in the supplied CoordinateSystem is assumed to be the order of the axes in the lattice for which the supplied latticeShape is appropriate.
  3. The CoordinateSystem supplied to the toLCRegion function does not have to be identical in structure to that from which the WCBox was constructed. They can consist of different numbers of world and pixel axes and be in different orders.
  4. For every world axis in the supplied CoordinateSystem that is also present (somewhere) in the construction CoordinateSystem the blc/trc corresponding to that world axis will be converted to pixels appropriate to the supplied CoordinateSystem. The order of this pixel based blc/trc will be the order of the pixel axes of the supplied CoordinateSystem
  5. For every world axis in the supplied CoordinateSystem that is not present in the construction CoordinateSystem, the supplied latticeShape value for the corresponding pixel axis is used, setting blc=0 and trc=latticeShape-1 for that axis.
  6. Once the pixel based blc/trc has been created, then, with the supplied latticeShape, it is used to create the LCBox, which is supplied as a pointer to the base class LCRegion.

Note that when determining whether a world axis from one CoordinateSystemis present on another, it is considered to not be a match if two coordinates of the same type (e.g. DirectionCoordinate) have different specific types (e.g. J2000 and GALACTIC, or TOPO and LSR for a SpectralCoordinate)

Example

Let us give some examples with pseudo-code. cSys is the construction CoordinateSystem and cSys2 is the supplied CoordinateSystem. We list their world axes in the square brackets. The construction blc/trc values don't matter as long as there cSys.nWorldAxes() of them. Similarly, the values of shape don't matter as long as there are cSys2.nPixelAxes() of them.
    cSys = [ra, dec, freq];
    cSys2 = [ra, dec];
    blc = [,,];
    trc = [,,];
    shape = [,];
    WCBox box(blc, trc, cSys);
    LCRegion* pR = box.toLCRegion(cSys2, shape);
    
The resultant LCBox will have corners converted according to
    blcLC(0) <- blc(0);
    blcLC(1) <- blc(1);
    trcLC(0) <- trc(0);
    trcLC(1) <- trc(1);
    

Example

    cSys = [ra, dec, freq];
    cSys2 = [freq, stokes];
    blc = [,,];
    trc = [,,];
    shape = [,];
    WCBox box(blc, trc, cSys);
    LCRegion* pR = box.toLCRegion(cSys2, shape);
    

The resultant LCBox will have corners converted according to

    blcLC(0) <- blc(2);
    blcLC(1) = 0;
    trcLC(0) <- trc(2);
    trcLC(1) = shape(1) - 1;
    

Example

    cSys = [ra, dec];
    cSys2 = [ra, dec, freq];
    blc = [,];
    trc = [,];
    shape = [,,];
    WCBox box(blc, trc, cSys);
    LCRegion* pR = box.toLCRegion(cSys2, shape);
    

The resultant LCBox will have corners converted according to

    blcLC(0) <- blc(0);
    blcLC(1) <- blc(1);
    blcLC(2) = 0l
    trcLC(0) <- trc(0);
    trcLC(1) <- trc(1);
    trcLC(2) = shape(2)-1;
    

Example

    cSys = [ra, dec, freq];
    cSys2 = [freq, ra, dec];
    blc = [,,];
    trc = [,,];
    shape = [,,];
    WCBox box(blc, trc, cSys);
    LCRegion* pR = box.toLCRegion(cSys2, shape);
    

The resultant LCBox will have corners converted according to

    blcLC(0) <- blc(2);
    blcLC(1) <- blc(0);
    blcLC(2) <- blc(1);
    trcLC(0) <- trc(2);
    trcLC(1) <- trc(0);
    trcLC(2) <- trc(1);
    

Example

In this example we make it a bit harder by reordering the pixel axes too. The new order of the pixel axes in terms of the original order [0,1,2] is given after the world axes

    cSys = [ra, dec, freq], [0, 1, 2];
    cSys2 = [freq, ra, dec, stokes], [3, 0, 2, 1];
    blc = [,,];
    trc = [,,];
    shape = [,,,];
    WCBox box(blc, trc, cSys);
    LCRegion* pR = box.toLCRegion(cSys2, shape);
    

Take the first world axis of cSys2 as an example. First, "freq" is found as the world axis number 2 in cSys. Then, when it is converted to a pixel coordinate, it will turn up as the value on pixel axis 1. The supplied shape must be appropriate to a [stokes, freq, dec, ra] lattice. The resultant LCBox will therefore have corners converted according to

    blcLC(0) = 0
    blcLC(1) <- blc(2);
    blcLC(2) <- blc(1);
    blcLC(3) <- blc(0);
    
    trcLC(0) = shape(0)-1;
    trcLC(1) <- trc(2);
    trcLC(2) <- trc(1);
    trcLC(3) <- trc(0);
    

Motivation

Users must be able to specify regions in world as well as lattice coordinates.

In all of the constructors, the order of the specified world coordinates is that of the *PIXEL AXES* (not world axes) in the CoordinateSystem. This is the natural order for a user to want to specify them in.

For the constructors specifying the world values as simple doubles, it is *ASSUMED* that the units of those doubles are the same as the native units of the CoordinateSystem for each axis.

World coordinates may be specified as absolute or offset. If the latter, they are offset with respect to the reference pixel of the CoordinateSystem.

To Do

Member Description

WCBox()

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. It is assumed that the order of the values is in the order of the pixel axes in the given coordinate system.

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. You specify the pixel axis order of the world values.

WCBox(const LCRegion& region, const CoordinateSystem& cSys)

Construct from the bounding box of an LCRegion.

WCBox (const WCBox& other)

Copy constructor (reference semantics [except for CoordinateSystem])

virtual ~WCBox()

Destructor

WCBox& operator= (const WCBox& other)

Assignment (copy semantics)

virtual Bool operator==(const WCRegion& other) const

Comparison

virtual WCRegion* cloneRegion() const

Clone a WCBox object.

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.

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.

virtual TableRecord toRecord(const String& tableName) const

Convert the WCBox object to a record. The record can be used to make the object persistent. The tableName argument can be used by derived classes (e.g. LCPagedMask) to put very large objects.

static WCBox* fromRecord (const TableRecord& rec, const String& tableName)

Convert to a WCBox from a record.

static String className()

Returns WCBox

virtual String type() const

Return region type. Returns the class name

void checkUnits (const IPosition& pixelAxes, const Vector<Quantum<Double> >& values, const CoordinateSystem& cSys)

Check units of quanta are consistent with CoordinateSystem

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

static void unitInit()