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> class Gaussian2D : public Gaussian2DParam<T>
176{
177public:
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>
189 const Vector<T> &width, const T &pa) :
191 Gaussian2D(const T &height, const T &xCenter, const T &yCenter,
192 const T &majorAxis, const T &axialRatio, const T &pa) :
194 axialRatio, pa) {}
195 // </group>
196
197 // Copy constructor (deep copy)
198 // <group>
199 Gaussian2D(const Gaussian2D<T> &other) : Gaussian2DParam<T>(other) {}
200 template <class W>
201 Gaussian2D(const Gaussian2D<W> &other) : Gaussian2DParam<T>(other) {}
202 // </group>
203
204 // Copy assignment (deep copy)
206 Gaussian2DParam<T>::operator=(other); return *this; }
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); }
226 // </group>
227
228 //# Make members of parent classes known.
229protected:
231 using Gaussian2DParam<T>::thePA;
235public:
240 using Gaussian2DParam<T>::RATIO;
243};
244
245#define Gaussian2D_PS Gaussian2D
246
247// <summary> Partial specialization of Gaussian2D for <src>AutoDiff</src>
248// </summary>
249
250// <synopsis>
251// <note role=warning> The name <src>Gaussian2D_PS</src> is only for cxx2html
252// documentation problems. Use <src>Gaussian2D</src> in your code.</note>
253// </synopsis>
255template <class T> class Gaussian2D_PS<AutoDiff<T> > :
256public Gaussian2DParam<AutoDiff<T> >
257{
258public:
259 //# Constructors
260 // Constructs two dimensional Gaussians.
261 // <group>
263 Gaussian2D_PS(const AutoDiff<T> &height,
264 const Vector<AutoDiff<T> > &center,
265 const Vector<AutoDiff<T> > &width,
266 const AutoDiff<T> &pa) :
267 Gaussian2DParam<AutoDiff<T> >(height, center, width, pa) {}
268 Gaussian2D_PS(const AutoDiff<T> &height, const AutoDiff<T> &xCenter,
269 const AutoDiff<T> &yCenter, const AutoDiff<T> &majorAxis,
270 const AutoDiff<T> &axialRatio, const AutoDiff<T> &pa) :
271 Gaussian2DParam<AutoDiff<T> >(height, xCenter, yCenter, majorAxis,
272 axialRatio, pa) {}
273 // </group>
274
275 // Copy constructor (deep copy)
276 // <group>
277 Gaussian2D_PS(const Gaussian2D_PS &other) :
278 Gaussian2DParam<AutoDiff<T> >(other) {}
279 template <class W>
280 Gaussian2D_PS(const Gaussian2D_PS<W> &other) :
281 Gaussian2DParam<AutoDiff<T> >(other) {}
282 // </group>
283
284 // Copy assignment (deep copy)
285 Gaussian2D_PS<AutoDiff<T> > &
286 operator=(const Gaussian2D_PS<AutoDiff<T> > &other) {
287 Gaussian2DParam<AutoDiff<T> >::operator=(other); return *this; }
288
289 // Destructor
290 virtual ~Gaussian2D_PS() {}
291
292 //# Operators
293 // Evaluate the Gaussian and its derivatives at <src>x</src>.
294 // <group>
295 virtual AutoDiff<T> eval(typename Function<AutoDiff<T> >::FunctionArg x) const;
296 // </group>
297
298 //# Member functions
299 // Return a copy of this object from the heap. The caller is responsible
300 // for deleting this pointer.
301 // <group>
302 virtual Function<AutoDiff<T> > *clone() const {
303 return new Gaussian2D<AutoDiff<T> >(*this); }
305 *cloneAD() const {
307 (*this); }
309 *cloneNonAD() const {
311 (*this); }
312 // </group>
313
314 //# Make members of parent classes known.
315protected:
316 using Gaussian2DParam<AutoDiff<T> >::param_p;
317 using Gaussian2DParam<AutoDiff<T> >::thePA;
318 using Gaussian2DParam<AutoDiff<T> >::theCpa;
319 using Gaussian2DParam<AutoDiff<T> >::theSpa;
320 using Gaussian2DParam<AutoDiff<T> >::theXwidth;
321public:
322 using Gaussian2DParam<AutoDiff<T> >::HEIGHT;
323 using Gaussian2DParam<AutoDiff<T> >::XCENTER;
324 using Gaussian2DParam<AutoDiff<T> >::YCENTER;
325 using Gaussian2DParam<AutoDiff<T> >::YWIDTH;
326 using Gaussian2DParam<AutoDiff<T> >::RATIO;
327 using Gaussian2DParam<AutoDiff<T> >::PANGLE;
328 using Gaussian2DParam<AutoDiff<T> >::fwhm2int;
329};
330
331#undef Gaussian2D_PS
332
333
334} //# NAMESPACE CASACORE - END
335
336#ifndef CASACORE_NO_AUTO_TEMPLATES
337#include <casacore/scimath/Functionals/Gaussian2D.tcc>
338#include <casacore/scimath/Functionals/Gaussian2D2.tcc>
339#endif //# CASACORE_NO_AUTO_TEMPLATES
340#endif
#define Gaussian2D_PS
Definition Gaussian2D.h:245
FunctionParam< T > param_p
The parameters and masks.
Definition Function.h:330
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.
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:308
Gaussian2D_PS()
Constructs two dimensional Gaussians.
Definition Gaussian2D.h:261
Gaussian2D_PS< AutoDiff< T > > & operator=(const Gaussian2D_PS< AutoDiff< T > > &other)
Copy assignment (deep copy)
Definition Gaussian2D.h:285
Gaussian2D_PS(const AutoDiff< T > &height, const Vector< AutoDiff< T > > &center, const Vector< AutoDiff< T > > &width, const AutoDiff< T > &pa)
Definition Gaussian2D.h:262
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:276
Gaussian2D_PS(const Gaussian2D_PS< W > &other)
Definition Gaussian2D.h:279
virtual Function< typename FunctionTraits< AutoDiff< T > >::DiffType > * cloneAD() const
Definition Gaussian2D.h:304
virtual Function< AutoDiff< T > > * clone() const
Return a copy of this object from the heap.
Definition Gaussian2D.h:301
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:191
Gaussian2D()
Constructs the two dimensional Gaussians.
Definition Gaussian2D.h:187
Gaussian2D< T > & operator=(const Gaussian2D< T > &other)
Copy assignment (deep copy)
Definition Gaussian2D.h:205
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
Definition Gaussian2D.h:224
Gaussian2D(const Gaussian2D< W > &other)
Definition Gaussian2D.h:201
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:199
virtual T eval(typename Function< T >::FunctionArg x) const
Evaluate the Gaussian at x.
this file contains all the compiler specific defines
Definition mainpage.dox:28
LatticeExprNode pa(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds 180/pi*atan2(left,right)/2.
PtrHolder< T > & operator=(const PtrHolder< T > &other)