casacore
Loading...
Searching...
No Matches
Gaussian2D.h
Go to the documentation of this file.
1// # Gaussian2D.h: A two-dimensional Gaussian class
2// # Copyright (C) 1995,1996,1997,2001,2002,2005
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: casa-feedback@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#ifndef SCIMATH_GAUSSIAN2D_H
27#define SCIMATH_GAUSSIAN2D_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/ArrayFwd.h>
32#include <casacore/scimath/Functionals/Gaussian2DParam.h>
33#include <casacore/scimath/Functionals/Function.h>
34#include <casacore/scimath/Mathematics/AutoDiff.h>
35#include <casacore/scimath/Mathematics/AutoDiffMath.h>
36
37namespace casacore { // # NAMESPACE CASACORE - BEGIN
38
39// <summary> A two dimensional Gaussian class.</summary>
40
41// <use visibility=export>
42
43// <reviewed reviewer="tcornwel" date="1996/02/22" tests="tGaussian2D"
44// demos="">
45// </reviewed>
46
47// <prerequisite>
48// <li> <linkto class="Gaussian2DParam">Gaussian2DParam</linkto>
49// <li> <linkto class="Function">Function</linkto>
50// </prerequisite>
51
52// <etymology>
53// A Gaussian2D functional is designed exclusively for calculating a
54// Gaussian (or Normal) distribution in two dimensions. Other classes exist
55// for calculating these functions in two
56// (<linkto class=Gaussian1D>Gaussian1D</linkto>) and N
57// (<linkto class=GaussianND>GaussianND</linkto>) dimensions.
58// </etymology>
59
60// <synopsis>
61// A <src>Gaussian2D</src> is described by a height, center, and width,
62// and position angle. Its fundamental operation is evaluating itself
63// at some <src>(x,y)</src>
64// coordinate. Its parameters (height, center and width, position angle) may
65// be changed at run time.
66//
67// The width of the Gaussian (for the constructors or the <src> setWidth
68// </src> function) is always specified in terms of the full width at half
69// maximum (FWHM). The major axis is parallel with the y axis when the
70// position angle is zero. The major axis will always have a larger width
71// than the minor axis.
72//
73// It is not possible to set the width of the major axis (using the <src>
74// setMajorAxis </src> function) smaller than the width of the current minor
75// axis. Similarly it is not possible to set the width of the minor axis
76// (using the <src> setMinorAxis </src> function) to be larger than the
77// current major axis. Exceptions are thrown if these rules are violated or
78// if the either the major or minor axis is set to a non-positive width. To
79// set both axis in one hit use the <src> setWidth </src> function. All
80// these restrictions can be overcome when the parameters interface is used
81// (see below).
82//
83// The position angle is the angle between the y axis and the major axis and
84// is measured counterclockwise, so a position angle of 45 degrees rotates
85// the major axis to the line where y=-x. The position angle is always
86// specified and returned in radians. When using the <src> setPA </src>
87// function its value must be between -2pi and + 2pi, and the returned value
88// from the <src> pa </src> function will always be a value between 0 and
89// pi.
90//
91// The axial ratio can be used as an alternative to specifying the width of
92// the minor axis. It is the ratio between the minor and major axis
93// widths. The axial ratio is constrained to be between zero and one, and
94// specifying something different (using setAxialRatio) will throw an
95// exception.
96//
97// The peak height of the Gaussian can be specified at construction time or
98// by using the <src> setHeight </src> function. Alternatively the <src>
99// setFlux </src> function can be used to implicitly set the peak height by
100// specifying the integrated area under the Gaussian. The height (or flux)
101// can be positive, negative or zero, as this class makes no assumptions on
102// what quantity the height represents.
103//
104// <note role=tip> Changing the width of the Gaussian will not affect
105// its peak height but will change its flux. So you should always set the
106// width before setting the flux. </note>
107//
108// The parameter interface (see
109// <linkto class="Gaussian2DParam">Gaussian2DParam</linkto> class),
110// is used to provide an interface to the
111// <linkto module="Fitting">Fitting</linkto> classes.
112//
113// There are 6 parameters that are used to describe the Gaussian:
114// <ol>
115// <li> The height of the Gaussian. This is identical to the value
116// returned using the <src> height </src> member function.
117// <li> The center of the Gaussian in the x direction. This is identical to
118// the value returned using the <src> xCenter </src> member function.
119// <li> The center of the Gaussian in the y direction. This is identical to
120// the value returned using the <src> yCenter </src> member function.
121// <li> The width (FWHM) of the Gaussian on one axis. Initially this will be
122// the major axis, but if the parameters are adjusted by a Fitting
123// class, it may become the axis with the smaller width. To aid
124// convergence of the non-linear fitting routines this parameter is
125// allowed to be negative. This does not affect the shape of the
126// Gaussian as the squares of the widths are used when evaluating the
127// function.
128// <li> A modified axial ratio. This parameter is the ratio of the width on
129// the 'other' axis (which initially is the minor axis) and axis given
130// by parameter YWIDTH. Because these internal widths are allowed to be
131// negative and because there is no constraints on which axis is the
132// larger one the modified axial ratio is not constrained to be between
133// zero and one.
134// <li> The position angle. This represents the angle (in radians) between
135// the axis used by parameter 4, and the y axis, measured
136// counterclockwise. If parameter 4 represents the major axis width
137// then this parameter will be identical to the position angle,
138// otherwise it will be different by 90 degrees. The tight constraints
139// on the value of the rotation angle enforced by the setPA() function
140// are relaxed so that any value between -6000 and 6000 is allowed. It
141// is still interpreted in radians.
142// </ol>
143//
144// An enumeration for the parameter index is provided, enabling the setting
145// and reading of parameters with the <src>[]</src> operator. The
146// <src>mask()</src> methods can be used to check and set the parameter masks.
147//
148// </synopsis>
149
150// <example>
151// <srcblock>
152// Gaussian2D<Double> g(10.0, 0.0, 0.0, 2.0, 1.0, 0.0);
153// Vector<Double> x(2);
154// x(0) = 1.0; x(1) = 0.5;
155// cout << "g(" << x(0) << "," << x(1) << ") = " << g(x) << endl;
156// </srcblock>
157// </example>
158
159// <templating arg=T>
160// <li> T should have standard numerical operators and exp() function. Current
161// implementation only tested for real types.
162// <li> To obtain derivatives, the derivatives should be defined.
163// </templating>
164
165// <thrown>
166// <li> Assertion in debug mode if attempt is made to set a negative width
167// <li> AipsError if incorrect parameter number specified.
168// <li> Assertion in debug mode if operator(Vector<>) with empty Vector
169// </thrown>
170
171// <todo asof="2001/08/19">
172// <li> Gaussians that know about their DFT's could be required eventually.
173// </todo>
174
175template <class T>
176class Gaussian2D : public Gaussian2DParam<T> {
177 public:
178 // # Enumerations
179
180 // # Constructors
181 // Constructs the two dimensional Gaussians. Defaults:
182 // height=1, center=0, width(FWHM)=1, PA=0. The center and width vectors
183 // must have two elements
184 // <note role=warning> Could not use default arguments
185 // that worked both with gcc and IRIX </note>
186 // <group>
188 Gaussian2D(const T &height, const Vector<T> &center, const Vector<T> &width, const T &pa)
190 Gaussian2D(const T &height, const T &xCenter, const T &yCenter, const T &majorAxis,
191 const T &axialRatio, const T &pa)
193 // </group>
194
195 // Copy constructor (deep copy)
196 // <group>
197 Gaussian2D(const Gaussian2D<T> &other) : Gaussian2DParam<T>(other) {}
198 template <class W>
199 Gaussian2D(const Gaussian2D<W> &other) : Gaussian2DParam<T>(other) {}
200 // </group>
201
202 // Copy assignment (deep copy)
205 return *this;
206 }
207
208 // Destructor
209 virtual ~Gaussian2D() {}
210
211 // # Operators
212 // Evaluate the Gaussian at <src>x</src>.
213 // <group>
214 virtual T eval(typename Function<T>::FunctionArg x) const;
215 // </group>
216
217 // # Member functions
218 // Return a copy of this object from the heap. The caller is responsible
219 // for deleting this pointer.
220 // <group>
221 virtual Function<T> *clone() const { return new Gaussian2D<T>(*this); }
228 // </group>
229
230 // # Make members of parent classes known.
231 protected:
233 using Gaussian2DParam<T>::thePA;
237
238 public:
243 using Gaussian2DParam<T>::RATIO;
246};
247
248#define Gaussian2D_PS Gaussian2D
249
250// <summary> Partial specialization of Gaussian2D for <src>AutoDiff</src>
251// </summary>
252
253// <synopsis>
254// <note role=warning> The name <src>Gaussian2D_PS</src> is only for cxx2html
255// documentation problems. Use <src>Gaussian2D</src> in your code.</note>
256// </synopsis>
257
258template <class T>
259class Gaussian2D_PS<AutoDiff<T>> : public Gaussian2DParam<AutoDiff<T>> {
260 public:
261 // # Constructors
262 // Constructs two dimensional Gaussians.
263 // <group>
265 Gaussian2D_PS(const AutoDiff<T> &height, const Vector<AutoDiff<T>> &center,
266 const Vector<AutoDiff<T>> &width, const AutoDiff<T> &pa)
268 Gaussian2D_PS(const AutoDiff<T> &height, const AutoDiff<T> &xCenter, const AutoDiff<T> &yCenter,
269 const AutoDiff<T> &majorAxis, const AutoDiff<T> &axialRatio, const AutoDiff<T> &pa)
270 : Gaussian2DParam<AutoDiff<T>>(height, xCenter, yCenter, majorAxis, axialRatio, pa) {}
271 // </group>
272
273 // Copy constructor (deep copy)
274 // <group>
275 Gaussian2D_PS(const Gaussian2D_PS &other) : Gaussian2DParam<AutoDiff<T>>(other) {}
276 template <class W>
277 Gaussian2D_PS(const Gaussian2D_PS<W> &other) : Gaussian2DParam<AutoDiff<T>>(other) {}
278 // </group>
279
280 // Copy assignment (deep copy)
282 Gaussian2DParam<AutoDiff<T>>::operator=(other);
283 return *this;
284 }
285
286 // Destructor
287 virtual ~Gaussian2D_PS() {}
288
289 // # Operators
290 // Evaluate the Gaussian and its derivatives at <src>x</src>.
291 // <group>
292 virtual AutoDiff<T> eval(typename Function<AutoDiff<T>>::FunctionArg x) const;
293 // </group>
294
295 // # Member functions
296 // Return a copy of this object from the heap. The caller is responsible
297 // for deleting this pointer.
298 // <group>
299 virtual Function<AutoDiff<T>> *clone() const { return new Gaussian2D<AutoDiff<T>>(*this); }
300 virtual Function<typename FunctionTraits<AutoDiff<T>>::DiffType> *cloneAD() const {
301 return new Gaussian2D<typename FunctionTraits<AutoDiff<T>>::DiffType>(*this);
303 virtual Function<typename FunctionTraits<AutoDiff<T>>::BaseType> *cloneNonAD() const {
304 return new Gaussian2D<typename FunctionTraits<AutoDiff<T>>::BaseType>(*this);
305 }
306 // </group>
307
308 // # Make members of parent classes known.
309 protected:
310 using Gaussian2DParam<AutoDiff<T>>::param_p;
311 using Gaussian2DParam<AutoDiff<T>>::thePA;
312 using Gaussian2DParam<AutoDiff<T>>::theCpa;
313 using Gaussian2DParam<AutoDiff<T>>::theSpa;
314 using Gaussian2DParam<AutoDiff<T>>::theXwidth;
315
316 public:
317 using Gaussian2DParam<AutoDiff<T>>::HEIGHT;
318 using Gaussian2DParam<AutoDiff<T>>::XCENTER;
319 using Gaussian2DParam<AutoDiff<T>>::YCENTER;
320 using Gaussian2DParam<AutoDiff<T>>::YWIDTH;
321 using Gaussian2DParam<AutoDiff<T>>::RATIO;
322 using Gaussian2DParam<AutoDiff<T>>::PANGLE;
323 using Gaussian2DParam<AutoDiff<T>>::fwhm2int;
324};
325
326#undef Gaussian2D_PS
327
328} // namespace casacore
329
330#ifndef CASACORE_NO_AUTO_TEMPLATES
331#include <casacore/scimath/Functionals/Gaussian2D.tcc>
332#include <casacore/scimath/Functionals/Gaussian2D2.tcc>
333#endif // # CASACORE_NO_AUTO_TEMPLATES
334#endif
#define Gaussian2D_PS
Definition Gaussian2D.h:248
FunctionParam< T > param_p
The parameters and masks.
Definition Function.h:337
const ArgType * FunctionArg
Definition Function.h:204
T theXwidth
cached vale of the Xwidth = ratio*theYwidth;
T height() const
Get or set the peak height of the Gaussian.
T thePA
cached vale of the PA
Vector< T > center() const
Get or set the center ordinate of the Gaussian.
Vector< T > width() const
Set or get the FWHM of the Gaussian.
T fwhm2int
Constant to scale halfwidth at 1/e to FWHM.
Gaussian2DParam()
Constructs the two dimensional Gaussians.
T theSpa
cached values of the cos and sine of thePA
Gaussian2DParam< T > & operator=(const Gaussian2DParam< T > &other)
Copy assignment (deep copy).
virtual Function< typename FunctionTraits< AutoDiff< T > >::BaseType > * cloneNonAD() const
Definition Gaussian2D.h:302
Gaussian2D_PS()
Constructs two dimensional Gaussians.
Definition Gaussian2D.h:263
Gaussian2D_PS< AutoDiff< T > > & operator=(const Gaussian2D_PS< AutoDiff< T > > &other)
Copy assignment (deep copy).
Definition Gaussian2D.h:280
Gaussian2D_PS(const AutoDiff< T > &height, const Vector< AutoDiff< T > > &center, const Vector< AutoDiff< T > > &width, const AutoDiff< T > &pa)
Definition Gaussian2D.h:264
Gaussian2D_PS(const AutoDiff< T > &height, const AutoDiff< T > &xCenter, const AutoDiff< T > &yCenter, const AutoDiff< T > &majorAxis, const AutoDiff< T > &axialRatio, const AutoDiff< T > &pa)
Definition Gaussian2D.h:267
Gaussian2D_PS(const Gaussian2D_PS &other)
Copy constructor (deep copy).
Definition Gaussian2D.h:274
Gaussian2D_PS(const Gaussian2D_PS< W > &other)
Definition Gaussian2D.h:276
virtual Function< typename FunctionTraits< AutoDiff< T > >::DiffType > * cloneAD() const
Definition Gaussian2D.h:299
virtual Function< AutoDiff< T > > * clone() const
Return a copy of this object from the heap.
Definition Gaussian2D.h:298
virtual AutoDiff< T > eval(typename Function< AutoDiff< T > >::FunctionArg x) const
Evaluate the Gaussian and its derivatives at x.
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
Definition Gaussian2D.h:222
virtual ~Gaussian2D()
Destructor.
Definition Gaussian2D.h:209
Gaussian2D(const T &height, const T &xCenter, const T &yCenter, const T &majorAxis, const T &axialRatio, const T &pa)
Definition Gaussian2D.h:190
Gaussian2D()
Constructs the two dimensional Gaussians.
Definition Gaussian2D.h:187
Gaussian2D< T > & operator=(const Gaussian2D< T > &other)
Copy assignment (deep copy).
Definition Gaussian2D.h:203
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
Definition Gaussian2D.h:225
Gaussian2D(const Gaussian2D< W > &other)
Definition Gaussian2D.h:199
virtual Function< T > * clone() const
Return a copy of this object from the heap.
Definition Gaussian2D.h:221
Gaussian2D(const T &height, const Vector< T > &center, const Vector< T > &width, const T &pa)
Definition Gaussian2D.h:188
Gaussian2D(const Gaussian2D< T > &other)
Copy constructor (deep copy).
Definition Gaussian2D.h:197
virtual T eval(typename Function< T >::FunctionArg x) const
Evaluate the Gaussian at x.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
LatticeExprNode pa(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds 180/pi*atan2(left,right)/2.
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
Definition Polynomial.h:126
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
Definition Polynomial.h:129