casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Gaussian2DParam.h
Go to the documentation of this file.
1 //# Gaussian2DParam.h: Parameter handling for 2 dimensional Gaussian class
2 //# Copyright (C) 2001,2002,2003
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$
28 
29 #ifndef SCIMATH_GAUSSIAN2DPARAM_H
30 #define SCIMATH_GAUSSIAN2DPARAM_H
31 
32 #include <casacore/casa/aips.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 //# Forward declarations
39 template<class T> class Vector;
40 
41 // <summary> Parameter handling for 2 dimensional Gaussian class
42 // </summary>
43 
44 // <use visibility=local>
45 
46 // <reviewed reviewer="mwieringa" date="1996/10/d24" tests="tGaussian2D">
47 // </reviewed>
48 
49 // <prerequisite>
50 // <li> <linkto class="FunctionParam">FunctionParam</linkto> class
51 // <li> <linkto class="Function">Function</linkto> class
52 // </prerequisite>
53 
54 // <etymology>
55 // A 2-dimensional Gaussian's parameters.
56 // </etymology>
57 
58 // <synopsis>
59 
60 // A <src>Gaussian2D</src> is described by a height, center, and width,
61 // and position angle.
62 
63 // The width of the Gaussian (for the constructors or the <src> setWidth
64 // </src> function) is always specified in terms of the full width at half
65 // maximum (FWHM). The major axis is parallel with the y axis when the
66 // position angle is zero. The major axis will always have a larger width
67 // than the minor axis.
68 //
69 // It is not possible to set the width of the major axis (using the <src>
70 // setMajorAxis </src> function) smaller than the width of the current minor
71 // axis. Similarly it is not possible to set the width of the minor axis
72 // (using the <src> setMinorAxis </src> function) to be larger than the
73 // current major axis. Exceptions are thrown if these rules are violated or
74 // if either the major or minor axis is set to a non-positive width. To
75 // set both axis in one hit use the <src> setWidth </src> function. All
76 // these restrictions can be overcome when the parameters interface is used
77 // (see below).
78 //
79 // The position angle is the angle between the y axis and the major axis and
80 // is measured counter-clockwise, so a position angle of 45 degrees rotates
81 // the major axis to the line where <src>y=-x</src>.
82 // The position angle is always
83 // specified and returned in radians. When using the <src> setPA </src>
84 // function its value must be between -2pi and + 2pi, and the returned value
85 // from the <src> pa </src> function will always be a value between 0 and
86 // pi.
87 //
88 // The axial ratio can be used as an alternative to specifying the width of
89 // the minor axis. It is the ratio between the minor and major axis
90 // widths. The axial ratio is constrained to be between zero and one, and
91 // specifying something different (using setAxialRatio) will throw an
92 // exception.
93 //
94 // The peak height of the Gaussian can be specified at construction time or
95 // by using the <src> setHeight </src> function. Alternatively the <src>
96 // setFlux </src> function can be used to implicitly set the peak height by
97 // specifying the integrated area under the Gaussian. The height (or flux)
98 // can be positive, negative or zero, as this class makes no assumptions on
99 // what quantity the height represents.
100 //
101 // <note role=tip> Changing the width of the Gaussian will not affect
102 // its peak height but will change its flux. So you should always set the
103 // width before setting the flux. </note>
104 //
105 // The parameter interface (see
106 // <linkto class="FunctionParam">FunctionParam</linkto> class),
107 // is used to provide an interface to the
108 // <linkto module="Fitting"> Fitting </linkto> classes.
109 //
110 // There are 6 parameters that are used to describe the Gaussian:
111 // <ol>
112 // <li> The height of the Gaussian. This is identical to the value
113 // returned using the <src> height </src> member function.
114 // <li> The center of the Gaussian in the x direction. This is identical to
115 // the value returned using the <src> xCenter </src> member function.
116 // <li> The center of the Gaussian in the y direction. This is identical to
117 // the value returned using the <src> yCenter </src> member function.
118 // <li> The width (FWHM) of the Gaussian on one axis. Initially this will be
119 // the major axis, but if the parameters are adjusted by a Fitting
120 // class, it may become the axis with the smaller width. To aid
121 // convergence of the non-linear fitting routines this parameter is
122 // allowed to be negative. This does not affect the shape of the
123 // Gaussian as the squares of the widths are used when evaluating the
124 // function.
125 // <li> A modified axial ratio. This parameter is the ratio of the width on
126 // the 'other' axis (which initially is the minor axis) and axis given
127 // by parameter 4. Because these internal widths are allowed to be
128 // negative and because there is no constraints on which axis is the
129 // larger one the modified axial ratio is not constrained to be between
130 // zero and one.
131 // <li> The rotation angle. This represents the angle (in radians) between
132 // the axis used by parameter 4, and the y axis, measured
133 // counterclockwise. If parameter 4 represents the major axis width
134 // then this parameter will be identical to the position angle,
135 // otherwise it will be different by 90 degrees. The tight constraints
136 // on the value of the rotation angle enforced by the setPA() function
137 // are relaxed so that any value between -6000 and 6000 is allowed. It
138 // is still interpreted in radians.
139 // </ol>
140 //
141 // An enumeration for the <src>HEIGHT</src>, <src>XCENTER</src>,
142 // <src>YCENTER</src>, <src>YWIDTH</src>, <src>RATIO</src>, <src>PANGLE</src>
143 // parameter index is provided, enabling the setting
144 // and reading of parameters with the <src>[]</src> operator. The
145 // <src>mask()</src> methods can be used to check and set the parameter masks.
146 //
147 // This class is in general used implicitly by the <src>Gaussian2D</src>
148 // class only.
149 //
150 // <note role=tip>
151 // Other points to bear in mind when fitting this class to measured data
152 // are:
153 // <ul>
154 // <li> If you need to fit a circular Gaussian to data you MUST set the
155 // axial ratio to one, and mask the position angle and axial ratio
156 // parameters. This avoids rank deficiency in the fitting routines as
157 // the position angle is meaningless when the major and minor axis are
158 // equal.
159 // <li> If fitting an elliptical Gaussian your initial model should not be a
160 // circular Gaussian.
161 // </ul>
162 // </note>
163 //
164 // </synopsis>
165 
166 // <example>
167 // <srcblock>
168 // Gaussian2D<Double> g(10.0, 0.0, 0.0, 2.0, 1.0, 0.0);
169 // Vector<Double> x(2);
170 // x(0) = 1.0; x(1) = 0.5;
171 // cout << "g(" << x(0) << "," << x(1) << ") = " << g(x) << endl;
172 // </srcblock>
173 // </example>
174 
175 // <motivation>
176 // Gaussian2D objects allow us to represent models of
177 // the sky in a more conventional way than the generic interface used in the
178 // GaussianND class does.
179 // </motivation>
180 
181 // <templating arg=T>
182 // <li> T should have standard numerical operators and exp() function. Current
183 // implementation only tested for real types (and AutoDiff of them).
184 // </templating>
185 
186 // <thrown>
187 // <li> Assertion in debug mode if attempt is made to set a negative width
188 // <li> AipsError if incorrect parameter number specified.
189 // </thrown>
190 
191 // <todo asof="2001/08/19">
192 // <li> Gaussians that know about their DFT's could be required eventually.
193 // </todo>
194 
195 template<class T> class Gaussian2DParam : public Function<T>
196 {
197 public:
198  //# Enumerations
200 
201  //# Constructors
202  // Constructs the two dimensional Gaussians. Defaults:
203  // height=1, center=0, width(FWHM)=1, pa=0.
204  // <group>
205  Gaussian2DParam();
206  Gaussian2DParam(const T &height, const Vector<T> &center,
207  const Vector<T> &width, const T &pa);
208  Gaussian2DParam(const T &height, const T &xCenter, const T &yCenter,
209  const T &majorAxis, const T &axialRatio,
210  const T &pa);
211  // </group>
212 
213  // Copy constructor (deep copy)
214  // <group>
215  Gaussian2DParam(const Gaussian2DParam<T> &other);
216  template <class W>
218  Function<T>(other),
219  fwhm2int(T(1.0)/sqrt(log(T(16.0)))) { majorAxis(); setPA(PA()); }
220  // </group>
221 
222  // Copy assignment (deep copy)
224 
225  // Destructor
226  virtual ~Gaussian2DParam();
227 
228  //# Operators
229 
230  // Variable dimensionality
231  virtual uInt ndim() const { return 2; }
232 
233  //# Member functions
234  // Give name of function
235  virtual const String &name() const { static String x("gaussian2d");
236  return x; }
237 
238  // Get or set the peak height of the Gaussian
239  // <group>
240  T height() const { return param_p[HEIGHT]; }
241  void setHeight(const T &height) { param_p[HEIGHT] = height; }
242  // </group>
243 
244  // Get or set the analytical integrated area underneath the Gaussian.
245  // Use these functions as an alternative to the height functions.
246  // <group>
247  T flux() const;
248  void setFlux(const T &flux);
249  // </group>
250 
251  // Get or set the center ordinate of the Gaussian
252  // <group>
253  Vector<T> center() const;
254  void setCenter(const Vector<T> &center);
255  T xCenter() const { return param_p[XCENTER]; }
256  void setXcenter(const T &cnter) { param_p[XCENTER] = cnter; }
257  T yCenter() const { return param_p[YCENTER]; }
258  void setYcenter(const T &cnter) { param_p[YCENTER] = cnter; }
259  // </group>
260 
261  // Set or get the FWHM of the Gaussian.
262  // <group>
263  Vector<T> width() const;
264  void setWidth(const Vector<T> &width);
265  T majorAxis() const;
266  void setMajorAxis(const T &width);
267  T minorAxis() const;
268  void setMinorAxis(const T &width);
269  T axialRatio() const;
270  void setAxialRatio(const T &axialRatio);
271  // </group>
272 
273  // Set/get the rotation angle (orientation) of the Gaussian. PA is given
274  // in radians counterclockwise.
275  // <group>
276  T PA() const;
277  void setPA(const T &pa);
278  // </group>
279 
280 protected:
281  // Constant to scale halfwidth at 1/e to FWHM
283  // cached vale of the PA
284  mutable T thePA;
285  // cached values of the cos and sine of thePA
286  // <group>
287  mutable T theSpa;
288  mutable T theCpa;
289  // </group>
290  // cached vale of the Xwidth = ratio*theYwidth;
291  mutable T theXwidth;
292 
293  //# Make members of parent classes known.
294 protected:
295  using Function<T>::param_p;
296 public:
298 };
299 
300 
301 } //# NAMESPACE CASACORE - END
302 
303 #ifndef CASACORE_NO_AUTO_TEMPLATES
304 #include <casacore/scimath/Functionals/Gaussian2DParam.tcc>
305 #endif //# CASACORE_NO_AUTO_TEMPLATES
306 #endif
T PA() const
Set/get the rotation angle (orientation) of the Gaussian.
A 1-D Specialization of the Array class.
FunctionParam< T > param_p
The parameters and masks.
Definition: Function.h:340
std::vector< double > Vector
Definition: ds9context.h:24
LatticeExprNode log(const LatticeExprNode &expr)
T height() const
Get or set the peak height of the Gaussian.
Gaussian2DParam()
Constructs the two dimensional Gaussians.
Parameter handling for 2 dimensional Gaussian class.
virtual const String & name() const
Give name of function.
Vector< T > width() const
Set or get the FWHM of the Gaussian.
void setMinorAxis(const T &width)
Gaussian2DParam< T > & operator=(const Gaussian2DParam< T > &other)
Copy assignment (deep copy)
void setXcenter(const T &cnter)
LatticeExprNode pa(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds 180/pi*atan2(left,right)/2.
Numerical functional interface class.
void setMajorAxis(const T &width)
void setWidth(const Vector< T > &width)
LatticeExprNode sqrt(const LatticeExprNode &expr)
Gaussian2DParam(const Gaussian2DParam< W > &other)
void setPA(const T &pa)
void setAxialRatio(const T &axialRatio)
void setHeight(const T &height)
T theXwidth
cached vale of the Xwidth = ratio*theYwidth;
virtual uInt ndim() const
Variable dimensionality.
void setYcenter(const T &cnter)
T theSpa
cached values of the cos and sine of thePA
T flux() const
Get or set the analytical integrated area underneath the Gaussian.
T fwhm2int
Constant to scale halfwidth at 1/e to FWHM.
void setFlux(const T &flux)
String: the storage and methods of handling collections of characters.
Definition: String.h:223
T thePA
cached vale of the PA
Vector< T > center() const
Get or set the center ordinate of the Gaussian.
virtual ~Gaussian2DParam()
Destructor.
void setCenter(const Vector< T > &center)
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