casacore
Loading...
Searching...
No Matches
Gaussian3D.h
Go to the documentation of this file.
1// # Gaussian3D.h: A three-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_GAUSSIAN3D_H
27#define SCIMATH_GAUSSIAN3D_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Arrays/ArrayFwd.h>
31#include <casacore/scimath/Functionals/Gaussian3DParam.h>
32#include <casacore/scimath/Functionals/Function.h>
33#include <casacore/scimath/Mathematics/AutoDiff.h>
34#include <casacore/scimath/Mathematics/AutoDiffMath.h>
35
36namespace casacore { // # NAMESPACE CASACORE - BEGIN
37
38// <summary> A three dimensional Gaussian class.</summary>
39
40// <use visibility=export>
41
42// <reviewed reviewer="" date="" tests="tGaussian3D"
43// demos="">
44// </reviewed>
45
46// <prerequisite>
47// <li> <linkto class="Gaussian3DParam">Gaussian3DParam</linkto>
48// <li> <linkto class="Function">Function</linkto>
49// </prerequisite>
50
51// <etymology>
52// A Gaussian3D functional is designed exclusively for calculating a
53// Gaussian (or Normal) distribution in three dimensions. Other classes exist
54// for calculating these functions in one
55// (<linkto class=Gaussian1D>Gaussian1D</linkto>), two
56// (<linkto class=Gaussian2D>Gaussian2D</linkto>), and N
57// (<linkto class=GaussianND>GaussianND</linkto>) dimensions.
58// </etymology>
59
60// <synopsis>
61// A <src>Gaussian3D</src> is described by a height, center, and width,
62// and position angles. Its fundamental operation is evaluating itself
63// at some <src>(x,y,z)</src>
64// coordinate. Its parameters (height, center and width, position angles) may
65// be changed at run time.
66
67// The width of the Gaussian is now specified in terms of the full width
68// at half maximum (FWHM), like the 2D and 1D Gaussian functional classes.
69
70// The three axis values refer to the x, y, and z axes, and unlike with the
71// 2D Gaussian any of the three axes may be the longest; instead, the position
72// angles are restricted. The first position angle, theta, is the longitudinal
73// angle, referring to the rotation (counterclockwise) around the z-axis. The
74// second, phi, is the latidudinal angle, referring to the rotation around
75// the theta-rotated y axis. The domain of both angles is -pi/4 < A < pi/4,
76// although the angles are not constrained when fitting and can be set outside
77// the domain by setting the parameters directly using Functional operator[].
78// (Note that the use of theta and phi corresponds to the mathematics
79// convention for these angles, not the physics convention.)
80
81// The parameter interface (see
82// <linkto class="Gaussian3DParam">Gaussian3DParam</linkto> class),
83// is used to provide an interface to the
84// <linkto module="Fitting">Fitting</linkto> classes.
85//
86// There are 9 parameters that are used to describe the Gaussian:
87// <ol>
88// <li> The height of the Gaussian. This is identical to the value
89// returned using the <src> height </src> member function.
90// <li> The center of the Gaussian in the x direction. This is identical to
91// the value returned using the <src> xCenter </src> member function.
92// <li> The center of the Gaussian in the y direction. This is identical to
93// the value returned using the <src> yCenter </src> member function.
94// <li> The center of the Gaussian in the z direction. This is identical to
95// the value returned using the <src> zCenter </src> member function.
96// <li> The width of the Gaussian along the x-axis.
97// <li> The width of the Gaussian along the y-axis.
98// <li> The width of the Gaussian along the z-axis.
99// <li> The longitudinal position angle, theta (in radians)
100// <li> The latitudinal position angle, phi (also in radians).
101// </ol>
102
103// An enumeration for the parameter index is provided, enabling the setting
104// and reading of parameters with the <src>[]</src> operator. The
105// <src>mask()</src> methods can be used to check and set the parameter masks.
106//
107// </synopsis>
108
109// <example>
110// <srcblock>
111// Gaussian3D<Double> g(9.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0);
112// Vector<Double> x(3);
113// x(0) = 1.0; x(1) = 0.5; x(2) = 0.0
114// cout << "g(" << x(0) << "," << x(1) << "," << x(2) << ")=" << g(x) << endl;
115// </srcblock>
116// </example>
117
118// <motivation>
119// The GaussianND class does not contain explicit derivatives
120// and was insufficient for fitting 3D Gaussians to data.
121// </motivation>
122
123// <templating arg=T>
124// <li> T should have standard numerical operators and exp() function. Current
125// implementation only tested for real types.
126// <li> To obtain derivatives, the derivatives should be defined.
127// </templating>
128
129// <thrown>
130// <li> Assertion in debug mode if attempt is made to set a negative width
131// <li> AipsError if incorrect parameter number specified.
132// <li> Assertion in debug mode if operator(Vector<>) with empty Vector
133// </thrown>
134
135// <todo asof="2002/07/22">
136// <li> Optimize derivative calculations for faster fitting?
137// </todo>
138
139template <class T>
140class Gaussian3D : public Gaussian3DParam<T> {
141 public:
142 // A functional for a rotated, 3D Gaussian. Similar to Gaussian2D, but
143 // the xWidth, yWidth, and zWidth parameters are not adjusted for FWHM;
144 // they are identical to the parameters used in the function.
145
146 // Constructs the three-dimensional Gaussians. Defaults:
147 // height = 1, center = {0,0,0}, width = {1,1,1}, theta = phi = 0.
148 // The center and width vectors must have three elements.
149 // <group>
153 T &theta, T &phi);
154 // </group>
155
156 // Copy constructor
157 // <group>
159 template <class W>
160 Gaussian3D(const Gaussian3D<W> &other) : Gaussian3DParam<T>(other) {}
161 // </group>
162
163 // Destructor
164 virtual ~Gaussian3D();
165
166 // Assignment operator
168
169 // Evaluate the Gaussian at <src>x</src>.
170 virtual T eval(typename Function<T>::FunctionArg x) const;
171
172 // Return a copy of this object from the heap. The caller is responsible
173 // for deleting this pointer.
174 // <group>
175 virtual Function<T> *clone() const;
182 // </group>
183
184 private:
185 // AutoDiff does not have a square() function, so one is provided here.
186 T sq(T v) const;
187
188 // # Make members of parent classes known.
189 protected:
201
202 public:
203 using Gaussian3DParam<T>::H;
204 using Gaussian3DParam<T>::CX;
205 using Gaussian3DParam<T>::CY;
206 using Gaussian3DParam<T>::CZ;
207 using Gaussian3DParam<T>::AX;
208 using Gaussian3DParam<T>::AY;
209 using Gaussian3DParam<T>::AZ;
210 using Gaussian3DParam<T>::THETA;
211 using Gaussian3DParam<T>::PHI;
214};
215
216// AUTODIFF SPECIALIZATION
217
218#define Gaussian3D_PS Gaussian3D
219
220// <summary> Partial specialization of Gaussian3D for <src>AutoDiff</src>
221// </summary>
222
223// <synopsis>
224// <note role=warning> The name <src>Gaussian3D_PS</src> is only for cxx2html
225// documentation problems. Use <src>Gaussian3D</src> in your code.</note>
226// </synopsis>
227
228template <class T>
229class Gaussian3D_PS<AutoDiff<T>> : public Gaussian3DParam<AutoDiff<T>> {
230 public:
238 template <class W>
240 virtual ~Gaussian3D_PS();
241 //
243 //
245 virtual Function<AutoDiff<T>> *clone() const;
246 virtual Function<typename FunctionTraits<AutoDiff<T>>::DiffType> *cloneAD() const {
247 return new Gaussian3D<typename FunctionTraits<AutoDiff<T>>::DiffType>(*this);
249 virtual Function<typename FunctionTraits<AutoDiff<T>>::BaseType> *cloneNonAD() const {
250 return new Gaussian3D<typename FunctionTraits<AutoDiff<T>>::BaseType>(*this);
251 }
252
253 private:
254 T sq(T v) const;
255
256 // # Make members of parent classes known.
257 protected:
269
270 public:
282};
283
284#undef Gaussian3D_PS
285
286} // namespace casacore
287
288#ifndef CASACORE_NO_AUTO_TEMPLATES
289#include <casacore/scimath/Functionals/Gaussian3D.tcc>
290#include <casacore/scimath/Functionals/Gaussian3D2.tcc>
291#endif // # CASACORE_NO_AUTO_TEMPLATES
292#endif
#define Gaussian3D_PS
AUTODIFF SPECIALIZATION.
Definition Gaussian3D.h:218
FunctionParam< T > param_p
The parameters and masks.
Definition Function.h:337
const ArgType * FunctionArg
Definition Function.h:204
Vector< T > center() const
Vector< T > width() const
Gaussian3D_PS(const AutoDiff< T > &height, const Vector< AutoDiff< T > > &center, const Vector< AutoDiff< T > > &width, const AutoDiff< T > &theta, const AutoDiff< T > &phi)
Gaussian3D_PS(AutoDiff< T > &height, AutoDiff< T > &xCenter, AutoDiff< T > &yCenter, AutoDiff< T > &zCenter, AutoDiff< T > &xWidth, AutoDiff< T > &yWidth, AutoDiff< T > &zWidth, AutoDiff< T > &theta, AutoDiff< T > &phi)
Gaussian3D_PS(const Gaussian3D_PS< W > &other)
Definition Gaussian3D.h:238
Gaussian3D_PS< AutoDiff< T > > & operator=(const Gaussian3D_PS< AutoDiff< T > > &other)
virtual Function< typename FunctionTraits< AutoDiff< T > >::BaseType > * cloneNonAD() const
Definition Gaussian3D.h:248
virtual Function< typename FunctionTraits< AutoDiff< T > >::DiffType > * cloneAD() const
Definition Gaussian3D.h:245
virtual AutoDiff< T > eval(typename Function< AutoDiff< T > >::FunctionArg x) const
virtual Function< AutoDiff< T > > * clone() const
Return a copy of this object from the heap.
Gaussian3D_PS(const Gaussian3D_PS< AutoDiff< T > > &other)
Gaussian3D< T > & operator=(const Gaussian3D< T > &other)
Assignment operator.
virtual ~Gaussian3D()
Destructor.
Gaussian3D(const Gaussian3D< T > &other)
Copy constructor.
virtual Function< T > * clone() const
Return a copy of this object from the heap.
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
Definition Gaussian3D.h:176
Gaussian3D(T &height, T &xCenter, T &yCenter, T &zCenter, T &xWidth, T &yWidth, T &zWidth, T &theta, T &phi)
Gaussian3D(const Gaussian3D< W > &other)
Definition Gaussian3D.h:160
Gaussian3D(T height, const Vector< T > &center, const Vector< T > &width, T theta, T phi)
Gaussian3D()
A functional for a rotated, 3D Gaussian.
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
Definition Gaussian3D.h:179
virtual T eval(typename Function< T >::FunctionArg x) const
Evaluate the Gaussian at x.
T sq(T v) const
AutoDiff does not have a square() function, so one is provided here.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
Definition Polynomial.h:129