casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ComponentShape.h
Go to the documentation of this file.
1 //# ComponentShape.h: Base class for component shapes
2 //# Copyright (C) 1998,1999,2000,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: 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 //# $Id: ComponentShape.h 21130 2011-10-18 07:39:05Z gervandiepen $
27 
28 #ifndef COMPONENTS_COMPONENTSHAPE_H
29 #define COMPONENTS_COMPONENTSHAPE_H
30 
31 #include <casa/aips.h>
34 #include <casa/Quanta/Quantum.h>
37 
38 namespace casacore{
39 
40 class DirectionCoordinate;
41 class MVAngle;
42 class RecordInterface;
43 class String;
44 template <class T> class Matrix;
45 template <class T> class MeasRef;
46 template <class T> class Vector;
47 }
48 
49 namespace casa { //# NAMESPACE CASA - BEGIN
50 
51 
52 // <summary>Base class for component shapes</summary>
53 
54 // <use visibility=export>
55 
56 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tComponentShape" demos="dPointShape">
57 // </reviewed>
58 
59 // <prerequisite>
60 // <li> <linkto class=casacore::MDirection>MDirection</linkto>
61 // </prerequisite>
62 //
63 // <synopsis>
64 
65 // This abstract base class defines the interface for classes which
66 // define the shape of a component. The most fundamental derived class is the
67 // <linkto class=PointShape>point</linkto> shape class but the
68 // <linkto class=GaussianShape>Gaussian</linkto> shape,
69 // <linkto class=DiskShape>disk</linkto> shape and
70 // <linkto class=LimbDarkenedDiskShape>limbdarkeneddisk classes are also
71 // available. These classes model the spatial distribution of emission from the
72 // sky.
73 
74 // Classes derived from the <linkto class=SpectralModel>SpectralModel</linkto>
75 // class are used to model the spectral characteristics and the
76 // <linkto class=Flux>Flux</linkto> class is used to model the flux. The
77 // <linkto class=SkyComponent>SkyComponent</linkto> class incorporates these
78 // three characteristics (flux, shape & spectrum) and the
79 // <linkto class=ComponentList>ComponentList</linkto> class handles groups of
80 // SkyComponent objects.
81 
82 // This base class parameterises shapes with two quantities.
83 // <dl>
84 // <dt><em> A reference direction.</em>
85 // <dd> This is specified using an <linkto class=casacore::MDirection>MDirection</linkto>
86 // object and indicates the direction on a defined reference point
87 // within the shape. Usually this reference point is the centre of the
88 // shape.
89 // <dt> <em>A casacore::Vector of parameters.</em>
90 // <dd> This contains other parameters that the are defined differently for
91 // different shapes. The length of the vector may vary for different
92 // component shapes.
93 // </dl>
94 //
95 // The basic operation of classes using this interface is to model the flux as
96 // a function of direction on the sky. Classes derived from this one do not
97 // know what the flux of the component. Instead the sample and visibility
98 // functions return factors that are used to scale the flux and calculate the
99 // amount of flux at a specified point on the sky or on the (u,v) plane.
100 
101 // Any allowed direction reference frame can be used. However the reference
102 // frame must be adequately specified in order to allow conversions to other
103 // reference frames. For example if the reference frame code for a component is
104 // casacore::MDirection::AZEL then the reference frame must also contain the time and
105 // position, on the earth, that the specified azimuth and elevation to refer
106 // to. This way the sample functions can convert the direction to a value in
107 // the J2000 reference frame (if you specify the sample direction in the J2000
108 // frame).
109 
110 // </synopsis>
111 
112 // <example>
113 
114 // Because this is an abstract base class, an actual instance of this class
115 // cannot be constructed. However the interface it defines can be used inside a
116 // function. This is always recommended as it allows functions which have
117 // ComponentShapes as arguments to work for any derived class.
118 
119 // In this example the printShape function prints out the type of model it is
120 // working with and the reference direction of that model. This example is also
121 // available in the <src>dPointShape.cc</src> file.
122 
123 // <srcblock>
124 // void printShape(const ComponentShape& theShape) {
125 // cout << "This is a " << ComponentType::name(theShape.type())
126 // << " shape " << endl
127 // << "with a reference direction of "
128 // << theShape.refDirection() << endl;
129 // }
130 // </srcblock>
131 // </example>
132 
133 // <motivation>
134 // The Shape base class was split from the SkyCompRep base class so that mixing
135 // components with different spatial and spectral shapes did not result in a
136 // combinatorial explosion in the number of classes required.
137 // </motivation>
138 //
139 // <todo asof="1999/11/11">
140 // <li> Use Measures & Quanta in the interface to the visibility functions.
141 // </todo>
142 
144 {
145 public:
146  // a virtual destructor is needed so that the actual destructor in the
147  // derived class will be used.
148  virtual ~ComponentShape();
149 
150  // return the actual shape. The ident function returns it as a String.
151  // <group>
152  virtual ComponentType::Shape type() const = 0;
153  virtual const casacore::String& ident() const;
154  // </group>
155 
156  // set/get the reference direction
157  // <group>
158  void setRefDirection(const casacore::MDirection& newRefDir);
159  const casacore::MDirection& refDirection() const;
160  // </group>
161 
162  // set/get the error in the reference direction. Values must be positive
163  // angular quantities otherwise an casacore::AipsError exception is thrown. The errors
164  // are usually interpreted as the 1-sigma bounds in latitude/longitude and
165  // implicitly assume a Gaussian distribution.
166  // <group>
167  void setRefDirectionError(const casacore::Quantum<casacore::Double>& newRefDirErrLat,
168  const casacore::Quantum<casacore::Double>& newRefDirErrLong);
171  // </group>
172 
173  // copy direction info from that object to this object
174  void copyDirectionInfo(const ComponentShape& that);
175 
176  // Calculate the proportion of the flux that is in a pixel of specified size
177  // centered in the specified direction. The returned value will always be
178  // between zero and one (inclusive).
179  virtual casacore::Double sample(const casacore::MDirection& direction,
180  const casacore::MVAngle& pixelLatSize,
181  const casacore::MVAngle& pixelLongSize) const = 0;
182 
183  // Same as the previous function except that many directions can be sampled
184  // at once. The reference frame and pixel size must be the same for all the
185  // specified directions. A default implementation of this function is
186  // available that uses the single pixel sample function described above.
187  // However customised versions of this function will be more efficient as
188  // intermediate values only need to be computed once.
189  virtual void sample(casacore::Vector<casacore::Double>& scale,
191  const casacore::MDirection::Ref& refFrame,
192  const casacore::MVAngle& pixelLatSize,
193  const casacore::MVAngle& pixelLongSize) const = 0;
194 
195  // Return the Fourier transform of the component at the specified point in
196  // the spatial frequency domain. The point is specified by a 3-element vector
197  // (u,v,w) that has units of meters and the frequency of the observation, in
198  // Hertz. These two quantities can be used to derive the required spatial
199  // frequency <src>(s = uvw*freq/c)</src>. The w component is not used in
200  // these functions. The scale factor returned by this function can be used
201  // to scale the flux at the origin of the Fourier plane in order to determine
202  // the visibility at the specified point.
203 
204  // The "origin" of the transform is the reference direction of the
205  // component. This means for symmetric components, where the reference
206  // direction is at the centre, that the Fourier transform will always be
207  // real.
209  const casacore::Double& frequency) const = 0;
210 
211  // Same as the previous function except that many (u,v,w) points can be
212  // sampled at once. The observation frequency is the same for all the
213  // specified points. The uvw casacore::Matrix must have first dimension of three and
214  // the second dimension must match the length of the scale vector. A default
215  // implementation of this function is available that uses the single point
216  // visibility function described above. However customised versions of this
217  // function may be more efficient as intermediate values only need to be
218  // computed once.
220  const casacore::Double& frequency) const = 0;
221 
222  //Same as above except for lots of frequencies too...scale rows is uvw points, columns
223  // is frequency values
225  const casacore::Vector<casacore::Double>& frequency) const = 0;
226 
227  // determine whether the shape is symmetric or not. If it is then all the
228  // scale factors returned by the visibility functions will be real numbers.
229  virtual casacore::Bool isSymmetric() const = 0;
230 
231  // Return a pointer to a copy of the derived object upcast to a
232  // ComponentShape object. The class that uses this function is responsible
233  // for deleting the pointer. This is used to implement a virtual copy
234  // constructor.
235  virtual ComponentShape* clone() const = 0;
236 
237  // return the number of parameters in this shape and set/get them. The error
238  // functions provide a way to set/get the error (nominally 1-sigma in an
239  // implicit Gaussian distribution) in the corresponding parameter.
240  // <group>
241  virtual casacore::uInt nParameters() const = 0;
242  virtual void setParameters(const casacore::Vector<casacore::Double>& newParms) = 0;
244  virtual void setErrors(const casacore::Vector<casacore::Double>& newErrs) = 0;
245  virtual casacore::Vector<casacore::Double> errors() const = 0;
247  virtual void setOptParameters(const casacore::Vector<casacore::Double>& newOptParms) = 0;
248  // </group>
249 
250  // These functions convert between a record and a ComponentShape. This way
251  // derived classes can interpret fields in the record in a class specific
252  // way. They return false if the record is malformed and append an error
253  // message to the supplied string giving the reason. These functions define
254  // how the shape is represented in glish. All records should have 'type' &
255  // 'direction' fields which contain respectively; a string indicating which
256  // shape is actually used, and a record representation of a direction
257  // measure. The interpretation of all other fields depends on the specific
258  // component shape used.
259  // <group>
260  virtual casacore::Bool fromRecord(casacore::String& errorMessage,
261  const casacore::RecordInterface& record) = 0;
262  virtual casacore::Bool toRecord(casacore::String& errorMessage,
263  casacore::RecordInterface& record) const = 0;
264  // </group>
265 
266  // Convert the parameters of the shape to the specified units. The Record
267  // must contain the same fields that the to/from casacore::Record functions have (with
268  // the exception of the direction & type fields). These fields will contain
269  // strings (and not record representations of Quantums) that specify the new
270  // units for these parameters. The new units must have the same dimensions as
271  // the existing ones. If there is any problem parsing the record then an
272  // error message is appended to the supplied string and the function returns
273  // false.
274  virtual casacore::Bool convertUnit(casacore::String& errorMessage,
275  const casacore::RecordInterface& record) = 0;
276 
277  // Return the shape that the supplied record represents. The
278  // shape is determined by parsing a 'type' field in the supplied
279  // record. Returns ComponentType::UNKNOWN_SHAPE if the type field
280  // (which contains a string) could not be translated into a known
281  // shape. It then appends an appropriate error message to the errorMessage
282  // String.
283  static ComponentType::Shape getType(casacore::String& errorMessage,
284  const casacore::RecordInterface& record);
285 
286  // Convert component shape to absolute pixels. The returned
287  // vector is the longitude and latitude location in absolute pixels.
289 
290  // Fill the shape direction from the vector (longitude and latitude
291  // in absolute pixels). The return value is always true.
293  const casacore::DirectionCoordinate& dirCoord);
294 
295  // casacore::Function which checks the internal data of this class for correct
296  // dimensionality and consistant values. Returns true if everything is fine
297  // otherwise returns false.
298  virtual casacore::Bool ok() const;
299 
300  // Return a pointer to the object. All subclasses must implement.
301  virtual const ComponentShape* getPtr() const = 0;
302 
303  // Return a nicely formatted string describing the component's size.
304  // All subclasses must implement.
305  virtual casacore::String sizeToString() const = 0;
306 
307 protected:
308  // The constructors and assignment operator are protected as only derived
309  // classes should use them.
310  // <group>
311  //# The default ComponentShape direction is at the J2000 North Pole.
312  ComponentShape();
313 
314  //# Construct a ComponentShape at the specified direction.
315  ComponentShape(const casacore::MDirection& direction);
316 
317  //# The copy constructor uses copy semantics.
318  ComponentShape(const ComponentShape& other);
319 
320  //# The assignment operator uses copy semantics.
321  ComponentShape& operator=(const ComponentShape& other);
322  // </group>
323 
324  //# Try and decide if the two reference directions are different, as the
325  //# casacore::MeasRef<T>::operator== function is too restrictive.
328 
329  // returns true if the quantum is not a non-negative angular quantity
331 
332  // Turns the specified field in the specified record into an casacore::Quantum
333  // with angular units
335  casacore::String& errorMessage,
336  const casacore::String& fieldString,
337  const casacore::RecordInterface& record);
338 
339 private:
340  //# The reference direction of the component
342  //# The errors in the reference direction of the component in radians
345 };
346 
347 } //# NAMESPACE CASA - END
348 
349 #endif
const casacore::Quantum< casacore::Double > & refDirectionErrorLong() const
A Measure: astronomical direction.
Definition: MDirection.h:174
void setRefDirection(const casacore::MDirection &newRefDir)
std::vector< double > Vector
Definition: ds9context.h:24
virtual ~ComponentShape()
casacore::MDirection itsDir
virtual casacore::DComplex visibility(const casacore::Vector< casacore::Double > &uvw, const casacore::Double &frequency) const =0
void copyDirectionInfo(const ComponentShape &that)
virtual ComponentShape * clone() const =0
Shape
The shapes of all the components.
void setRefDirectionError(const casacore::Quantum< casacore::Double > &newRefDirErrLat, const casacore::Quantum< casacore::Double > &newRefDirErrLong)
virtual casacore::Vector< casacore::Double > parameters() const =0
virtual casacore::Bool convertUnit(casacore::String &errorMessage, const casacore::RecordInterface &record)=0
Interface class for converting to/from records.
const casacore::Quantum< casacore::Double > & refDirectionErrorLat() const
virtual casacore::Double sample(const casacore::MDirection &direction, const casacore::MVAngle &pixelLatSize, const casacore::MVAngle &pixelLongSize) const =0
virtual casacore::String sizeToString() const =0
virtual casacore::Bool ok() const
static casacore::Bool fromAngQRecord(casacore::Quantum< casacore::Double > &returnValue, casacore::String &errorMessage, const casacore::String &fieldString, const casacore::RecordInterface &record)
casacore::Quantum< casacore::Double > itsDirErrLat
ComponentShape & operator=(const ComponentShape &other)
virtual casacore::Vector< casacore::Double > toPixel(const casacore::DirectionCoordinate &dirCoord) const
virtual void setErrors(const casacore::Vector< casacore::Double > &newErrs)=0
virtual casacore::Bool fromPixel(const casacore::Vector< casacore::Double > &parameters, const casacore::DirectionCoordinate &dirCoord)
virtual casacore::Bool fromRecord(casacore::String &errorMessage, const casacore::RecordInterface &record)=0
Initialise the class from a Record representation.
virtual const ComponentShape * getPtr() const =0
Base class for component shapes.
Interconvert pixel positions and directions (e.g. RA/DEC).
double Double
Definition: aipstype.h:55
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
static casacore::Bool differentRefs(const casacore::MeasRef< casacore::MDirection > &ref1, const casacore::MeasRef< casacore::MDirection > &ref2)
virtual const casacore::String & ident() const
Specify the identification of the record (e.g.
static casacore::Bool badError(const casacore::Quantum< casacore::Double > &quantum)
virtual casacore::Bool toRecord(casacore::String &errorMessage, casacore::RecordInterface &record) const =0
Convert the class to an Record representation.
static ComponentType::Shape getType(casacore::String &errorMessage, const casacore::RecordInterface &record)
virtual ComponentType::Shape type() const =0
virtual void setOptParameters(const casacore::Vector< casacore::Double > &newOptParms)=0
casacore::Quantum< casacore::Double > itsDirErrLong
virtual casacore::Vector< casacore::Double > optParameters() const =0
virtual casacore::uInt nParameters() const =0
const casacore::MDirection & refDirection() const
virtual casacore::Bool isSymmetric() const =0
virtual casacore::Vector< casacore::Double > errors() const =0
String: the storage and methods of handling collections of characters.
Definition: String.h:223
Abstract base class for Record classes.
virtual void setParameters(const casacore::Vector< casacore::Double > &newParms)=0
Class to handle angle type conversions and I/O.
Definition: MVAngle.h:245
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42