TwoSidedShape.h

Classes

TwoSidedShape -- Base class for component shapes with two sides (full description)

class TwoSidedShape: public ComponentShape

Interface

Public Members
virtual ~TwoSidedShape()
virtual ComponentType::Shape type() const = 0
void setWidth(const Quantum<Double>& majorAxis, const Quantum<Double>& minorAxis, const Quantum<Double>& positionAngle)
void setWidth(const Quantum<Double>& majorAxis, const Double axialRatio, const Quantum<Double>& positionAngle)
Quantum<Double> majorAxis() const
Quantum<Double> minorAxis() const
Quantum<Double> positionAngle() const
Double axialRatio() const
void setErrors(const Quantum<Double>& majorAxisError, const Quantum<Double>& minorAxisError, const Quantum<Double>& positionAngleError)
const Quantum<Double>& majorAxisError() const
const Quantum<Double>& minorAxisError() const
const Quantum<Double>& positionAngleError() const
Double axialRatioError() const
virtual void setWidthInRad(const Double majorAxis, const Double minorAxis, const Double positionAngle) = 0
virtual Double majorAxisInRad() const = 0
virtual Double minorAxisInRad() const = 0
virtual Double positionAngleInRad() const = 0
virtual Double sample(const MDirection& direction, const MVAngle& pixelLatSize, const MVAngle& pixelLongSize) const = 0
virtual void sample(Vector<Double>& scale, const Vector<MDirection::MVType>& directions, const MDirection::Ref& refFrame, const Ref& pixelLatSize, const Ref& pixelLongSize) const = 0
virtual DComplex visibility(const Vector<Double>& uvw, const Double& frequency) const = 0
virtual void visibility(Vector<DComplex>& scale, const Matrix<Double>& uvw, const Double& frequency) const = 0
virtual Bool isSymmetric() const
virtual ComponentShape* clone() const = 0
virtual uInt nParameters() const
virtual void setParameters(const Vector<Double>& newParms)
virtual Vector<Double> parameters() const
virtual void setErrors(const Vector<Double>& newParms)
virtual Vector<Double> errors() const
virtual Bool fromRecord(String& errorMessage, const RecordInterface& record)
virtual Bool toRecord(String& errorMessage, RecordInterface& record) const
virtual Bool convertUnit(String& errorMessage, const RecordInterface& record)
virtual Bool ok() const
virtual Vector<Double> toPixel (const DirectionCoordinate& dirCoord) const
virtual Bool fromPixel (const Vector<Double>& parameters, const DirectionCoordinate& dirCoord)
Protected Members
TwoSidedShape()
TwoSidedShape(const MDirection& direction, const Unit& majorAxisUnit, const Unit& minorAxisUnit, const Unit& paUnit)
TwoSidedShape(const TwoSidedShape& other)
TwoSidedShape& operator=(const TwoSidedShape& other)
Private Members
Vector<Double> widthToCartesian (const Quantum<Double>& width, const Quantum<Double>& pa, const MDirection& dirRef, const DirectionCoordinate& dirCoord, const Vector<Double>& pixelCen) const
MDirection directionFromCartesian (Double width, Double pa, const DirectionCoordinate& dirCoord, const Vector<Double>& pixelCen) const
See Also
DiskShape - a uniform brightness disk shape.
GaussianShape - a Gaussian variation in the sky brightness

Description

Review Status

Date Reviewed:
yyyy/mm/dd
Programs:
Demos:
Tests:

Prerequisite

Synopsis

This base class adds a common interface for component shapes that have two sides. These shapes can be parameterised as having a major-axis width, minor-axis width and a position angle (as well as the reference direction). Currently there are two shapes which use this parameterisation, the Gaussian shape and the disk shape. Shapes which do not have this parameterisation, such as the point shape, are derived directly from the ComponentShape class.

Functions in this class implement a more convenient way of setting the parameters associated with two-sided shapes than the very flexible, but clumsy, parameters functions. The width parameters can be set using the setWidth functions. These functions enforce the rule that the major-axis width must not be smaller than the minor-axis width. Hence the axial ratio, which is the minor-axis width divided by the major-axis width, must always be greater than zero and less than or equal to one.

The functions in this class also free derived classes from the having to deal with units. Any angular unit can be used to specify the width of the shape. The widths returned by the majoraxis, minoraxis & the positionAngle functions are in the same units as they where specified in, unless the convertUnit function has been used to specify another unit.

For maximum speed the *InRad functions are provided. These functions bypass all the computation involving units.

The toRecord and fromRecord functions in this class standardise the record representation of classes derived from this one. In addition to the type and direction fields all records, discussed in the ComponentShape class, there are three more mandatory fields called; majoraxis, minoraxis & positionangle. These fields are record representation of Quantum objects and hence contain a value and unit. eg., A typical record for any of the shapes derived from this class might be:

    c := [type = 'gaussian',
          direction = [type = 'direction',
                       refer = 'b1950',
                       m0 = [value = .1, unit = 'rad']
                       m1 = [value = -.1, unit = 'rad']
                      ],
          majoraxis = [value=.5, unit='arcmin'],
          minoraxis = [value=1, unit='arcsec'],
          positionangle = [value=10, unit='deg']
         ]
    

Example

Because this is an abstract base class, an actual instance of this class cannot be constructed. However the interface it defines can be used inside a function. This allows functions which have TwoSidedShapes as arguments to work for any derived class. Hence the printShape function shown below will work for GaussianShapes and DiskShapes but not for PointShapes.

In this example the printShape function prints out the type of model it is working with, the reference direction of that model, the major-axis width, minor-axis width and the position angle. This example is also available in the dTwoSidedShape.cc file.

  void printShape(const TwoSidedShape& theShape) {
    cout << "This is a " << ComponentType::name(theShape.type())
         << " shape " << endl 
         << "with a reference direction of "
         << theShape.refDirection().getAngle("deg") << " ("
         << theShape.refDirection().getRefString() << ")" << endl
         << "and a major axis of " << theShape.majorAxis() << endl
         << "      minor axis of " << theShape.minorAxis() << endl
         << "and   position angle of " << theShape.positionAngle() << endl;
  }

Motivation

This base class was created to allow the reuse of a number of common functions by all derived classes.

To Do

Member Description

virtual ~TwoSidedShape()

a virtual destructor is needed so that the actual destructor in the derived class will be used.

virtual ComponentType::Shape type() const = 0

return the actual component type.

void setWidth(const Quantum<Double>& majorAxis, const Quantum<Double>& minorAxis, const Quantum<Double>& positionAngle)
void setWidth(const Quantum<Double>& majorAxis, const Double axialRatio, const Quantum<Double>& positionAngle)
Quantum<Double> majorAxis() const
Quantum<Double> minorAxis() const
Quantum<Double> positionAngle() const
Double axialRatio() const

set/get the width and orientation of the Shape. The width of the major must be larger than the width of the minor axes. The position angle is measured North through East ie a position angle of zero degrees means that the major axis is North-South and a position angle of 10 degrees moves the Northern edge to the East. The axial ratio is the ratio of the minor to major axes widths. Hence it is always between zero and one.

void setErrors(const Quantum<Double>& majorAxisError, const Quantum<Double>& minorAxisError, const Quantum<Double>& positionAngleError)
const Quantum<Double>& majorAxisError() const
const Quantum<Double>& minorAxisError() const
const Quantum<Double>& positionAngleError() const
Double axialRatioError() const

set/get the errors on the shape parameters.

virtual void setWidthInRad(const Double majorAxis, const Double minorAxis, const Double positionAngle) = 0
virtual Double majorAxisInRad() const = 0
virtual Double minorAxisInRad() const = 0
virtual Double positionAngleInRad() const = 0

set/get the width and orientation of the Shape. These are the same as the above functions except that all widths are in radians.

virtual Double sample(const MDirection& direction, const MVAngle& pixelLatSize, const MVAngle& pixelLongSize) const = 0

Calculate the proportion of the flux that is in a pixel of specified size centered in the specified direction. The returned value will always be between zero and one (inclusive).

virtual void sample(Vector<Double>& scale, const Vector<MDirection::MVType>& directions, const MDirection::Ref& refFrame, const Ref& pixelLatSize, const Ref& pixelLongSize) const = 0

Same as the previous function except that many directions can be sampled at once. The reference frame and pixel size must be the same for all the specified directions. A default implementation of this function is available that uses the single pixel sample function described above. However customised versions of this function will be more efficient as intermediate values only need to be computed once.

virtual DComplex visibility(const Vector<Double>& uvw, const Double& frequency) const = 0

Return the Fourier transform of the component at the specified point in the spatial frequency domain. The point is specified by a 3-element vector (u,v,w) that has units of meters and the frequency of the observation, in Hertz. These two quantities can be used to derive the required spatial frequency (s = uvw*freq/c). The w component is not used in these functions. The scale factor returned by this function can be used to scale the flux at the origin of the Fourier plane in order to determine the visibility at the specified point.

The "origin" of the transform is the reference direction of the component. This means for symmetric components, where the reference direction is at the centre, that the Fourier transform will always be real.

virtual void visibility(Vector<DComplex>& scale, const Matrix<Double>& uvw, const Double& frequency) const = 0

Same as the previous function except that many (u,v,w) points can be sampled at once. The observation frequency is the same for all the specified points. The uvw Matrix must have first dimension of three and the second dimension must match the length of the scale vector. A default implementation of this function is available that uses the single point visibility function described above. However customised versions of this function may be more efficient as intermediate values only need to be computed once.

virtual Bool isSymmetric() const

determine whether the shape is symmetric or not. Always returns True.

virtual ComponentShape* clone() const = 0

Return a pointer to a copy of this object upcast to a ComponentShape object. The class that uses this function is responsible for deleting the pointer. This is used to implement a virtual copy constructor.

virtual uInt nParameters() const
virtual void setParameters(const Vector<Double>& newParms)
virtual Vector<Double> parameters() const
virtual void setErrors(const Vector<Double>& newParms)
virtual Vector<Double> errors() const

set/get the shape parameters associated with this shape. There are always three these being in order: the major-axis, the minor-axis and the position angle. All these angular quantities are specified and returned in radians. The Vector supplied to the setParameters and setErrors functions must have three elements and the Vector returned by the parameters and errors functions will have three elements. The errors are nominally 1-sigma in an implicit Gaussian distribution.

virtual Bool fromRecord(String& errorMessage, const RecordInterface& record)
virtual Bool toRecord(String& errorMessage, RecordInterface& record) const

This functions convert between a Record and a shape derived from this class. These functions define how the object is represented in glish and this is detailed in the synopsis above. They return False if the record is malformed and append an error message to the supplied string giving the reason.

virtual Bool convertUnit(String& errorMessage, const RecordInterface& record)

Convert the parameters of the component to the specified units. The supplied record must have three fields, namely 'majoraxis', 'minoraxis' & 'positionangle'. These fields must contains strings that are angular units and this function will convert the corresponding parameters to the specified units. This will have no effect on the shape of this class but will affect the format of the record returned by the toRecord function, and the units used in the the Quanta returned by the majoraxis, minoraxis & positionangle functions.

virtual Bool ok() const

Function which checks the internal data of this class for correct dimensionality and consistent values. Returns True if everything is fine otherwise returns False.

virtual Vector<Double> toPixel (const DirectionCoordinate& dirCoord) const

Convert component shape to absolute pixels (longitude, latitude, major axis, minor axis, position angle [positive +x -> +y ; rad])

virtual Bool fromPixel (const Vector<Double>& parameters, const DirectionCoordinate& dirCoord)

Fill the shape from the vector (longitude, latitude, major axis, minor axis, position angle [positive +x -> +y ; rad]). The return is True if the input major axis (in pixels) became the minor axis (in world coordinates), else False.

TwoSidedShape()

The constructors and assignment operator are protected as only derived classes should use them.

TwoSidedShape(const MDirection& direction, const Unit& majorAxisUnit, const Unit& minorAxisUnit, const Unit& paUnit)

The constructors and assignment operator are protected as only derived classes should use them.

TwoSidedShape(const TwoSidedShape& other)

The constructors and assignment operator are protected as only derived classes should use them.

TwoSidedShape& operator=(const TwoSidedShape& other)

The constructors and assignment operator are protected as only derived classes should use them.

Vector<Double> widthToCartesian (const Quantum<Double>& width, const Quantum<Double>& pa, const MDirection& dirRef, const DirectionCoordinate& dirCoord, const Vector<Double>& pixelCen) const

MDirection directionFromCartesian (Double width, Double pa, const DirectionCoordinate& dirCoord, const Vector<Double>& pixelCen) const