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
139
140
141template<class T> class Gaussian3D : public Gaussian3DParam<T>
142{
143public:
144 // A functional for a rotated, 3D Gaussian. Similar to Gaussian2D, but
145 // the xWidth, yWidth, and zWidth parameters are not adjusted for FWHM;
146 // they are identical to the parameters used in the function.
147
148 // Constructs the three-dimensional Gaussians. Defaults:
149 // height = 1, center = {0,0,0}, width = {1,1,1}, theta = phi = 0.
150 // The center and width vectors must have three elements.
151 // <group>
154 const Vector<T>& width, T theta, T phi);
156 T &xWidth, T &yWidth, T &zWidth, T &theta, T &phi);
157 // </group>
158
159 // Copy constructor
160 // <group>
162 template <class W>
163 Gaussian3D(const Gaussian3D<W> &other) : Gaussian3DParam<T>(other) {}
164 // </group>
165
166 // Destructor
167 virtual ~Gaussian3D();
168
169 // Assignment operator
171
172 // Evaluate the Gaussian at <src>x</src>.
173 virtual T eval(typename Function<T>::FunctionArg x) const;
174
175 // Return a copy of this object from the heap. The caller is responsible
176 // for deleting this pointer.
177 // <group>
178 virtual Function<T> *clone() const;
183 // </group>
184
185private:
186 // AutoDiff does not have a square() function, so one is provided here.
187 T sq(T v) const;
188
189 //# Make members of parent classes known.
190protected:
202public:
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
217// AUTODIFF SPECIALIZATION
218
219#define Gaussian3D_PS Gaussian3D
220
221// <summary> Partial specialization of Gaussian3D for <src>AutoDiff</src>
222// </summary>
223
224// <synopsis>
225// <note role=warning> The name <src>Gaussian3D_PS</src> is only for cxx2html
226// documentation problems. Use <src>Gaussian3D</src> in your code.</note>
227// </synopsis>
228
230template <class T> class Gaussian3D_PS<AutoDiff<T> > : public Gaussian3DParam<AutoDiff<T> >
231{
232public:
234 Gaussian3D_PS(const AutoDiff<T> &height,
235 const Vector<AutoDiff<T> >& center,
236 const Vector<AutoDiff<T> >& width,
237 const AutoDiff<T>& theta,
238 const AutoDiff<T>& phi);
239 Gaussian3D_PS(AutoDiff<T>& height, AutoDiff<T>& xCenter,
240 AutoDiff<T>& yCenter, AutoDiff<T>& zCenter,
241 AutoDiff<T>& xWidth, AutoDiff<T>& yWidth,
242 AutoDiff<T>& zWidth, AutoDiff<T>& theta,
245 template <class W>
246 Gaussian3D_PS(const Gaussian3D_PS<W> &other) :
248 virtual ~Gaussian3D_PS();
250 Gaussian3D_PS<AutoDiff<T> > &operator=(const Gaussian3D_PS<AutoDiff<T> > &other);
252 virtual AutoDiff<T> eval(typename Function<AutoDiff<T> >::FunctionArg x) const;
253 virtual Function<AutoDiff<T> > *clone() const;
255 *cloneAD() const {
257 (*this); }
259 *cloneNonAD() const {
261 (*this); }
262
263private:
264 T sq(T v) const;
265
266 //# Make members of parent classes known.
267protected:
268 using Gaussian3DParam<AutoDiff<T> >::param_p;
269 using Gaussian3DParam<AutoDiff<T> >::stoT_p;
270 using Gaussian3DParam<AutoDiff<T> >::stoP_p;
271 using Gaussian3DParam<AutoDiff<T> >::cosT_p;
272 using Gaussian3DParam<AutoDiff<T> >::cosP_p;
273 using Gaussian3DParam<AutoDiff<T> >::sinT_p;
274 using Gaussian3DParam<AutoDiff<T> >::sinP_p;
275 using Gaussian3DParam<AutoDiff<T> >::cosTcosP_p;
276 using Gaussian3DParam<AutoDiff<T> >::cosTsinP_p;
277 using Gaussian3DParam<AutoDiff<T> >::sinTcosP_p;
278 using Gaussian3DParam<AutoDiff<T> >::sinTsinP_p;
279public:
280 using Gaussian3DParam<AutoDiff<T> >::H;
281 using Gaussian3DParam<AutoDiff<T> >::CX;
282 using Gaussian3DParam<AutoDiff<T> >::CY;
283 using Gaussian3DParam<AutoDiff<T> >::CZ;
284 using Gaussian3DParam<AutoDiff<T> >::AX;
285 using Gaussian3DParam<AutoDiff<T> >::AY;
286 using Gaussian3DParam<AutoDiff<T> >::AZ;
287 using Gaussian3DParam<AutoDiff<T> >::THETA;
288 using Gaussian3DParam<AutoDiff<T> >::PHI;
289 using Gaussian3DParam<AutoDiff<T> >::fwhm2int;
290 using Gaussian3DParam<AutoDiff<T> >::settrigvals;
291};
292
293#undef Gaussian3D_PS
294
295
296} //# NAMESPACE CASACORE - END
297
298#ifndef CASACORE_NO_AUTO_TEMPLATES
299#include <casacore/scimath/Functionals/Gaussian3D.tcc>
300#include <casacore/scimath/Functionals/Gaussian3D2.tcc>
301#endif //# CASACORE_NO_AUTO_TEMPLATES
302#endif
303
304
305
306
307
#define Gaussian3D_PS
AUTODIFF SPECIALIZATION.
Definition Gaussian3D.h:219
FunctionParam< T > param_p
The parameters and masks.
Definition Function.h:330
Vector< T > center() const
Get or cet the center coordinates of the Gaussian.
Vector< T > width() const
Get or set the sigma-width of the Gaussian.
T height() const
Get or set the peak height of the Gaussian.
T theta() const
Get or set the rotation angles of the Gaussian.
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:245
Gaussian3D_PS< AutoDiff< T > > & operator=(const Gaussian3D_PS< AutoDiff< T > > &other)
virtual Function< typename FunctionTraits< AutoDiff< T > >::BaseType > * cloneNonAD() const
Definition Gaussian3D.h:258
virtual Function< typename FunctionTraits< AutoDiff< T > >::DiffType > * cloneAD() const
Definition Gaussian3D.h:254
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:179
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:163
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:181
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.
this file contains all the compiler specific defines
Definition mainpage.dox:28
PtrHolder< T > & operator=(const PtrHolder< T > &other)