casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TwoSidedShape.h
Go to the documentation of this file.
1 //# TwoSidedShape.h:
2 //# Copyright (C) 1998,1999,2000,2002
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: aips2-request@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 //# $Id: TwoSidedShape.h 21130 2011-10-18 07:39:05Z gervandiepen $
28 
29 #ifndef COMPONENTS_TWOSIDEDSHAPE_H
30 #define COMPONENTS_TWOSIDEDSHAPE_H
31 
32 #include <casa/aips.h>
35 #include <casa/BasicSL/Complex.h>
36 #include <casa/Quanta/Unit.h>
37 #include <casa/Quanta/Quantum.h>
38 
39 namespace casacore{
40 
41 class DirectionCoordinate;
42 class MDirection;
43 class MVAngle;
44 class RecordInterface;
45 class String;
46 template <class T> class Vector;
47 }
48 
49 namespace casa { //# NAMESPACE CASA - BEGIN
50 
51 
52 // <summary>Base class for component shapes with two sides</summary>
53 
54 // <use visibility=export>
55 
56 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tTwoSidedShape" demos="dTwoSidedShape">
57 // </reviewed>
58 
59 // <prerequisite>
60 // <li> <linkto class=ComponentShape>ComponentShape</linkto>
61 // <li> <linkto class=casacore::Quantum>Quantum</linkto>
62 // </prerequisite>
63 
64 // <synopsis>
65 
66 // This base class adds a common interface for component shapes that have two
67 // sides. These shapes can be parameterised as having a major-axis width,
68 // minor-axis width and a position angle (as well as the reference direction).
69 // Currently there are two shapes which use this parameterisation, the
70 // <linkto class=GaussianShape>Gaussian</linkto> shape and the
71 // <linkto class=DiskShape>disk</linkto> shape. Shapes which do not have this
72 // parameterisation, such as the <linkto class=PointShape>point</linkto> shape,
73 // are derived directly from the
74 // <linkto class=ComponentShape>ComponentShape</linkto> class.
75 
76 // Functions in this class implement a more convenient way of setting the
77 // parameters associated with two-sided shapes than the very flexible, but
78 // clumsy, <src>parameters</src> functions. The width parameters can be set
79 // using the <src>setWidth</src> functions. These functions enforce the rule
80 // that the major-axis width must not be smaller than the minor-axis
81 // width. Hence the axial ratio, which is the minor-axis width divided by the
82 // major-axis width, must always be greater than zero and less than or equal to
83 // one.
84 
85 // The functions in this class also free derived classes from the having to
86 // deal with units. Any angular unit can be used to specify the width of the
87 // shape. The widths returned by the majoraxis, minoraxis & the positionAngle
88 // functions are in the same units as they where specified in, unless the
89 // convertUnit function has been used to specify another unit.
90 
91 // For maximum speed the <src>*InRad</src> functions are provided. These
92 // functions bypass all the computation involving units.
93 
94 // The toRecord and fromRecord functions in this class standardise the record
95 // representation of classes derived from this one. In addition to the type and
96 // direction fields all records, discussed in the
97 // <linkto class=ComponentShape>ComponentShape</linkto> class, there are three
98 // more mandatory fields called; majoraxis, minoraxis & positionangle. These
99 // fields are record representation of casacore::Quantum<casacore::Double> objects and hence
100 // contain a value and unit. eg., A typical record for any of the shapes
101 // derived from this class might be:
102 // <srcblock>
103 // c := [type = 'gaussian',
104 // direction = [type = 'direction',
105 // refer = 'b1950',
106 // m0 = [value = .1, unit = 'rad']
107 // m1 = [value = -.1, unit = 'rad']
108 // ],
109 // majoraxis = [value=.5, unit='arcmin'],
110 // minoraxis = [value=1, unit='arcsec'],
111 // positionangle = [value=10, unit='deg']
112 // ]
113 // </srcblock>
114 // </synopsis>
115 //
116 // <example>
117 
118 // Because this is an abstract base class, an actual instance of this class
119 // cannot be constructed. However the interface it defines can be used inside a
120 // function. This allows functions which have TwoSidedShapes as arguments to
121 // work for any derived class. Hence the printShape function shown below will
122 // work for GaussianShapes and DiskShapes but not for PointShapes.
123 
124 // In this example the printShape function prints out the type of model it is
125 // working with, the reference direction of that model, the major-axis width,
126 // minor-axis width and the position angle. This example is also available in
127 // the <src>dTwoSidedShape.cc</src> file.
128 // <srcblock>
129 // void printShape(const TwoSidedShape& theShape) {
130 // cout << "This is a " << ComponentType::name(theShape.type())
131 // << " shape " << endl
132 // << "with a reference direction of "
133 // << theShape.refDirection().getAngle("deg") << " ("
134 // << theShape.refDirection().getRefString() << ")" << endl
135 // << "and a major axis of " << theShape.majorAxis() << endl
136 // << " minor axis of " << theShape.minorAxis() << endl
137 // << "and position angle of " << theShape.positionAngle() << endl;
138 // }
139 // </srcblock>
140 // </example>
141 //
142 
143 // <motivation>
144 // This base class was created to allow the reuse of a number of common
145 // functions by all derived classes.
146 // </motivation>
147 
148 // <todo asof="1999/110/12">
149 // <li> Use Measures & Quanta in the interface to the visibility functions.
150 // </todo>
151 
152 // <linkfrom anchor="TwoSidedShape" classes="ComponentShape">
153 // <here>TwoSidedShape</here> - a base class for shapes with two sides
154 // </linkfrom>
155 
157 {
158 public:
159 
160  // a virtual destructor is needed so that the actual destructor in the
161  // derived class will be used.
162  virtual ~TwoSidedShape();
163 
164  // return the actual component type.
165  virtual ComponentType::Shape type() const = 0;
166 
167  // set/get the width and orientation of the Shape. The width of the major
168  // must be larger than the width of the minor axes. The position angle is
169  // measured North through East ie a position angle of zero degrees means
170  // that the major axis is North-South and a position angle of 10 degrees
171  // moves the Northern edge to the East. The axial ratio is the ratio of the
172  // minor to major axes widths. Hence it is always between zero and one.
173  // <group>
177  void setWidth(const casacore::Quantum<casacore::Double>& majorAxis,
179  const casacore::Quantum<casacore::Double>& positionAngle);
184  // </group>
185 
186  // set/get the errors on the shape parameters.
187  // <group>
195  // </group>
196 
197  // set/get the width and orientation of the Shape. These are the same as the
198  // above functions except that all widths are in radians.
199  // <group>
200  virtual void setWidthInRad(const casacore::Double majorAxis,
201  const casacore::Double minorAxis,
202  const casacore::Double positionAngle) = 0;
203  virtual casacore::Double majorAxisInRad() const = 0;
204  virtual casacore::Double minorAxisInRad() const = 0;
205  virtual casacore::Double positionAngleInRad() const = 0;
206  // </group>
207 
208  // Calculate the proportion of the flux that is in a pixel of specified size
209  // centered in the specified direction. The returned value will always be
210  // between zero and one (inclusive).
211  virtual casacore::Double sample(const casacore::MDirection& direction,
212  const casacore::MVAngle& pixelLatSize,
213  const casacore::MVAngle& pixelLongSize) const = 0;
214 
215  // Same as the previous function except that many directions can be sampled
216  // at once. The reference frame and pixel size must be the same for all the
217  // specified directions. A default implementation of this function is
218  // available that uses the single pixel sample function described above.
219  // However customised versions of this function will be more efficient as
220  // intermediate values only need to be computed once.
221  virtual void sample(casacore::Vector<casacore::Double>& scale,
223  const casacore::MDirection::Ref& refFrame,
224  const casacore::MVAngle& pixelLatSize,
225  const casacore::MVAngle& pixelLongSize) const = 0;
226 
227  // Return the Fourier transform of the component at the specified point in
228  // the spatial frequency domain. The point is specified by a 3-element vector
229  // (u,v,w) that has units of meters and the frequency of the observation, in
230  // Hertz. These two quantities can be used to derive the required spatial
231  // frequency <src>(s = uvw*freq/c)</src>. The w component is not used in
232  // these functions. The scale factor returned by this function can be used
233  // to scale the flux at the origin of the Fourier plane in order to determine
234  // the visibility at the specified point.
235 
236  // The "origin" of the transform is the reference direction of the
237  // component. This means for symmetric components, where the reference
238  // direction is at the centre, that the Fourier transform will always be
239  // real.
241  const casacore::Double& frequency) const = 0;
242 
243  // Same as the previous function except that many (u,v,w) points can be
244  // sampled at once. The observation frequency is the same for all the
245  // specified points. The uvw casacore::Matrix must have first dimension of three and
246  // the second dimension must match the length of the scale vector. A default
247  // implementation of this function is available that uses the single point
248  // visibility function described above. However customised versions of this
249  // function may be more efficient as intermediate values only need to be
250  // computed once.
252  const casacore::Double& frequency) const = 0;
253 
254  // same as above but with many frequencies
256  const casacore::Vector<casacore::Double>& frequency) const = 0;
257 
258  // determine whether the shape is symmetric or not. Always returns true.
259  virtual casacore::Bool isSymmetric() const;
260 
261  // Return a pointer to a copy of this object upcast to a ComponentShape
262  // object. The class that uses this function is responsible for deleting the
263  // pointer. This is used to implement a virtual copy constructor.
264  virtual ComponentShape* clone() const = 0;
265 
266  // set/get the shape parameters associated with this shape. There are always
267  // three these being in order: the major-axis, the minor-axis and the
268  // position angle. All these angular quantities are specified and returned in
269  // radians. The casacore::Vector supplied to the <src>setParameters</src> and
270  // <src>setErrors</src> functions must have three elements and the Vector
271  // returned by the <src>parameters</src> and <src>errors</src> functions will
272  // have three elements. The errors are nominally 1-sigma in an implicit
273  // Gaussian distribution.
274  // <group>
275  virtual casacore::uInt nParameters() const;
276  virtual void setParameters(const casacore::Vector<casacore::Double>& newParms);
278  virtual void setErrors(const casacore::Vector<casacore::Double>& newParms);
281  virtual void setOptParameters(const casacore::Vector<casacore::Double>& newOptParms);
282  // </group>
283 
284  // This functions convert between a casacore::Record and a shape derived from this
285  // class. These functions define how the object is represented in glish and
286  // this is detailed in the synopsis above. They return false if the record
287  // is malformed and append an error message to the supplied string giving the
288  // reason.
289  // <group>
290  virtual casacore::Bool fromRecord(casacore::String& errorMessage,
291  const casacore::RecordInterface& record);
292  virtual casacore::Bool toRecord(casacore::String& errorMessage,
293  casacore::RecordInterface& record) const;
294  // </group>
295 
296  // Convert the parameters of the component to the specified units. The
297  // supplied record must have three fields, namely 'majoraxis', 'minoraxis' &
298  // 'positionangle'. These fields must contains strings that are angular units
299  // and this function will convert the corresponding parameters to the
300  // specified units. This will have no effect on the shape of this class but
301  // will affect the format of the record returned by the toRecord function,
302  // and the units used in the the Quanta returned by the majoraxis, minoraxis
303  // & positionangle functions.
304  virtual casacore::Bool convertUnit(casacore::String& errorMessage,
305  const casacore::RecordInterface& record);
306 
307  // casacore::Function which checks the internal data of this class for correct
308  // dimensionality and consistent values. Returns true if everything is fine
309  // otherwise returns false.
310  virtual casacore::Bool ok() const;
311 
312  // Convert component shape to absolute pixels (longitude, latitude, major axis,
313  // minor axis, position angle [positive +x -> +y ; rad])
315 
316  // Fill the shape from the vector (longitude, latitude, major axis,
317  // minor axis, position angle [positive +x -> +y ; rad]). The return
318  // is true if the input major axis (in pixels) became the minor
319  // axis (in world coordinates), else false.
321  const casacore::DirectionCoordinate& dirCoord);
322 
323  // Get the string containing the various size quantities of a component.
324  virtual casacore::String sizeToString() const = 0;
325 
326  // casacore::Format the string containing the various size quantities of a component.
329  casacore::Bool includeUncertainties = true, casacore::Quantity majorErr = 0,
330  casacore::Quantity minorErr = 0, casacore::Quantity posanErr = 0);
331 
332 protected:
333  // The constructors and assignment operator are protected as only derived
334  // classes should use them.
335  // <group>
336  //# The default TwoSidedShape is at the J2000 North Pole.
337  TwoSidedShape();
338 
339  //# Construct a TwoSidedShape at the specified direction, and return all all
340  //# widths using the specified units.
341  TwoSidedShape(const casacore::MDirection& direction, const casacore::Unit& majorAxisUnit, const
342  casacore::Unit& minorAxisUnit, const casacore::Unit& paUnit);
343 
344  //# The copy constructor uses copy semantics.
345  TwoSidedShape(const TwoSidedShape& other);
346 
347  //# The assignment operator uses copy semantics.
348  TwoSidedShape& operator=(const TwoSidedShape& other);
349  // </group>
350 
351 private:
358 //
361  const casacore::MDirection& dirRef,
362  const casacore::DirectionCoordinate& dirCoord,
363  const casacore::Vector<casacore::Double>& pixelCen) const;
364 //
366  const casacore::DirectionCoordinate& dirCoord,
367  const casacore::Vector<casacore::Double>& pixelCen) const;
368 
369 };
370 
371 } //# NAMESPACE CASA - END
372 
373 #endif
A Measure: astronomical direction.
Definition: MDirection.h:174
std::vector< double > Vector
Definition: ds9context.h:24
casacore::Unit itsPaUnit
Base class for component shapes with two sides.
const casacore::Quantum< casacore::Double > & minorAxisError() const
TwoSidedShape()
The constructors and assignment operator are protected as only derived classes should use them...
Shape
The shapes of all the components.
casacore::Vector< casacore::Double > widthToCartesian(const casacore::Quantum< casacore::Double > &width, const casacore::Quantum< casacore::Double > &pa, const casacore::MDirection &dirRef, const casacore::DirectionCoordinate &dirCoord, const casacore::Vector< casacore::Double > &pixelCen) const
virtual casacore::Double sample(const casacore::MDirection &direction, const casacore::MVAngle &pixelLatSize, const casacore::MVAngle &pixelLongSize) const =0
Calculate the proportion of the flux that is in a pixel of specified size centered in the specified d...
virtual void setOptParameters(const casacore::Vector< casacore::Double > &newOptParms)
void setErrors(const casacore::Quantum< casacore::Double > &majorAxisError, const casacore::Quantum< casacore::Double > &minorAxisError, const casacore::Quantum< casacore::Double > &positionAngleError)
set/get the errors on the shape parameters.
virtual casacore::DComplex visibility(const casacore::Vector< casacore::Double > &uvw, const casacore::Double &frequency) const =0
Return the Fourier transform of the component at the specified point in the spatial frequency domain...
casacore::Quantum< casacore::Double > itsMajErr
virtual casacore::String sizeToString() const =0
Get the string containing the various size quantities of a component.
casacore::MDirection directionFromCartesian(casacore::Double width, casacore::Double pa, const casacore::DirectionCoordinate &dirCoord, const casacore::Vector< casacore::Double > &pixelCen) const
virtual casacore::uInt nParameters() const
set/get the shape parameters associated with this shape.
const casacore::Quantum< casacore::Double > & majorAxisError() const
virtual ComponentType::Shape type() const =0
return the actual component type.
virtual casacore::Vector< casacore::Double > errors() const
void setWidth(const casacore::Quantum< casacore::Double > &majorAxis, const casacore::Quantum< casacore::Double > &minorAxis, const casacore::Quantum< casacore::Double > &positionAngle)
set/get the width and orientation of the Shape.
defines physical units
Definition: Unit.h:189
casacore::Quantum< casacore::Double > minorAxis() const
virtual casacore::Bool toRecord(casacore::String &errorMessage, casacore::RecordInterface &record) const
Convert the class to an Record representation.
const casacore::Quantum< casacore::Double > & positionAngleError() const
LatticeExprNode pa(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds 180/pi*atan2(left,right)/2.
Base class for component shapes.
Interconvert pixel positions and directions (e.g. RA/DEC).
virtual casacore::Double positionAngleInRad() const =0
double Double
Definition: aipstype.h:55
virtual casacore::Bool ok() const
casacore::Function which checks the internal data of this class for correct dimensionality and consis...
casacore::Quantum< casacore::Double > itsMinErr
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Unit itsMajUnit
casacore::Double axialRatio() const
casacore::Quantum< casacore::Double > itsPaErr
virtual casacore::Vector< casacore::Double > toPixel(const casacore::DirectionCoordinate &dirCoord) const
Convert component shape to absolute pixels (longitude, latitude, major axis, minor axis...
virtual ~TwoSidedShape()
a virtual destructor is needed so that the actual destructor in the derived class will be used...
casacore::Quantum< casacore::Double > positionAngle() const
virtual casacore::Bool isSymmetric() const
determine whether the shape is symmetric or not.
virtual casacore::Vector< casacore::Double > optParameters() const
casacore::Unit itsMinUnit
virtual casacore::Bool fromRecord(casacore::String &errorMessage, const casacore::RecordInterface &record)
This functions convert between a casacore::Record and a shape derived from this class.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual void setWidthInRad(const casacore::Double majorAxis, const casacore::Double minorAxis, const casacore::Double positionAngle)=0
set/get the width and orientation of the Shape.
virtual void setParameters(const casacore::Vector< casacore::Double > &newParms)
casacore::Quantum< casacore::Double > majorAxis() const
Abstract base class for Record classes.
TwoSidedShape & operator=(const TwoSidedShape &other)
virtual ComponentShape * clone() const =0
Return a pointer to a copy of this object upcast to a ComponentShape object.
casacore::Double axialRatioError() const
virtual casacore::Double minorAxisInRad() const =0
Class to handle angle type conversions and I/O.
Definition: MVAngle.h:245
virtual casacore::Vector< casacore::Double > parameters() const
virtual casacore::Bool convertUnit(casacore::String &errorMessage, const casacore::RecordInterface &record)
Convert the parameters of the component to the specified units.
virtual casacore::Double majorAxisInRad() const =0
unsigned int uInt
Definition: aipstype.h:51
virtual casacore::Bool fromPixel(const casacore::Vector< casacore::Double > &parameters, const casacore::DirectionCoordinate &dirCoord)
Fill the shape from the vector (longitude, latitude, major axis, minor axis, position angle [positive...
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42