casacore
Loading...
Searching...
No Matches
Gaussian3DParam.h
Go to the documentation of this file.
1//# Gaussian3DParam.h: Parameter handling for 3 dimensional Gaussian class
2//# Copyright (C) 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_GAUSSIAN3DPARAM_H
27#define SCIMATH_GAUSSIAN3DPARAM_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Arrays/ArrayFwd.h>
31#include <casacore/casa/BasicSL/String.h>
32#include <casacore/scimath/Functionals/Function.h>
33#include <casacore/scimath/Mathematics/AutoDiff.h>
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37// <summary> Parameter handling for 3 dimensional Gaussian class
38// </summary>
39
40// <use visibility=local>
41
42// <reviewed reviewer="" date="" tests="tGaussian3DParam">
43// </reviewed>
44
45// <prerequisite>
46// <li> <linkto class="FunctionParam">FunctionParam</linkto> class
47// <li> <linkto class="Function">Function</linkto> class
48// </prerequisite>
49
50// <etymology>
51// A 3-dimensional Gaussian's parameters.
52// </etymology>
53
54// <synopsis>
55
56// A <src>Gaussian3D</src> is described by a height, center, width,
57// and two position angles.
58
59// The width of the Gaussian is now specified in terms of the full width
60// at half maximum (FWHM), as with the 1D and 2D Gaussian functional classes.
61
62// The three axis values refer to the x, y, and z axes, and unlike with the
63// 2D Gaussian any of the three axes may be the longest. Instead, the position
64// angles are restricted: The first position angle, theta, is the longitudinal
65// angle, referring to the rotation (counterclockwise) around the z-axis. The
66// second, phi, is the latidudinal angle, referring to the rotation around
67// the theta-rotated y axis. The domain of both angles is -pi/4 < A < pi/4.
68// (Note that the use of theta and phi corresponds to the mathematical
69// convention for these angles, not the physics convention.)
70
71// The parameter interface (see
72// <linkto class="FunctionParam">FunctionParam</linkto> class),
73// is used to provide an interface to the
74// <linkto module="Fitting"> Fitting </linkto> classes.
75//
76// There are 9 parameters that are used to describe the Gaussian:
77// <ol>
78// <li> The height of the Gaussian. This is identical to the value
79// returned using the <src> height </src> member function.
80// <li> The center of the Gaussian in the x direction. This is identical to
81// the value returned using the <src> xCenter </src> member function.
82// <li> The center of the Gaussian in the y direction. This is identical to
83// the value returned using the <src> yCenter </src> member function.
84// <li> The center of the Gaussian in the z direction. This is identical to
85// the value returned using the <src> zCenter </src> member function.
86// <li> The width of the Gaussian along the x-axis.
87// <li> The width of the Gaussian along the y-axis.
88// <li> The width of the Gaussian along the z-axis.
89// <li> The longitudinal position angle, theta (in radians)
90// <li> The latitudinal position angle, phi (also in radians).
91// </ol>
92
93
94// An enumeration for the <src>H</src>, <src>CX</src>,
95// <src>CY</src>,<src>CZ</src>, <src>AX</src>, <src>AY</src>,
96// <src>AZ</src>, <src>THETA</src>, <src>PHI</src>
97// parameter index is provided, enabling the setting
98// and reading of parameters with the <src>[]</src> operator. The
99// <src>mask()</src> methods can be used to check and set the parameter masks.
100//
101// This class is in general used implicitly by the <src>Gaussian3D</src>
102// class only.
103//
104// <note role=tip>
105// Other points to bear in mind when fitting this class to measured data
106// are:
107// <ul>
108// <li> If you need to fit a circular Gaussian to data you should mask one or
109// both position angles. This avoids rank deficiency in the fitting
110// routines as the position angle is meaningless when the axes are
111// equal.
112// </ul>
113// </note>
114//
115// </synopsis>
116
117// <example>
118// <srcblock>
119// Gaussian3D<Double> g(9.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0);
120// Vector<Double> x(3);
121// x(0) = 1.0; x(1) = 0.5; x(2) = 0.0
122// cout << "g(" << x(0) << "," << x(1) << "," << x(2) << ")=" << g(x) << endl;
123// </srcblock>
124// </example>
125
126
127// <templating arg=T>
128// <li> T should have standard numerical operators and exp() function. Current
129// implementation only tested for real types (and AutoDiff of them).
130// </templating>
131
132// <thrown>
133// <li> Assertion in debug mode if attempt is made to set a negative width
134// <li> AipsError if incorrect parameter number specified.
135// <li> others?
136// </thrown>
137
138// <todo asof="2002/07/19">
139// <li> Gaussians that know about their DFT's could be required eventually.
140// </todo>
141
142
143
144template<class Type> class Gaussian3DParam : public Function<Type>
145{
146 // Parameter handling for the functional for 3D Gaussian Class.
147 // Similar to Gaussian2DParam, but width parameters are not adjusted
148 // for FWHM; they are identical to the parameters used in the function.
149
150 // Position angle parameters are restricted to -PI/4 < angle < PI/4.
151
152public:
153
154 //#Enumerations
155 enum
156 {
157 H=0, // value of Gaussian at the center
158 CX, // X center value
159 CY, // Y center value
160 CZ, // Z center value
161 AX, // width along X axis when T = P = 0
162 AY, // width along Y axis when T = P = 0
163 AZ, // width along Z axis when T = P = 0
164 THETA, // rotation about Z axis.
165 PHI, // rotation around X and Y axes (which depends on T).
166 NPAR // number of total parameters (9)
167 };
168
169 // Constructs the three dimensional Gaussians. Defaults:
170 // height = 1, center = {0,0,0}, width = {1,1,1}, theta = phi = 0
171 // <group>
174 const Vector<Type>& width, Type theta, Type phi);
175 Gaussian3DParam(Type &height, Type &xCenter, Type &yCenter, Type &zCenter,
176 Type &xWidth, Type &yWidth, Type &zWidth,
177 Type &theta, Type &phi);
178 // </group>
179
180 // Copy construcor
181 // <group>
183 template <class W>
185 Function<Type>(other),
186 fwhm2int(Type(1.0)/sqrt(log(Type(16.0)))) { settrigvals(); }
187 // </group>
188
189 // Copy assignment
191
192 // Destructor
194
195 //# Member functions
196 // Give name of function
197 virtual const String &name() const { static String x("gaussian3d");
198 return x; }
199
200 // Return dimensionality
201 virtual uInt ndim() const {return 3;}
202
203 // Get or set the peak height of the Gaussian
204 // <group>
205 Type height() const;
206 void setHeight(const Type & height);
207 // </group>
208
209 // Get or set the total flux of the Gaussian. (Note: Since this changes
210 // the height of the Gaussian but not its width, always set the width
211 // before setting the flux.)
212 // <group>
213 Type flux() const;
214 void setFlux(const Type & flux);
215 // </group>
216
217 // Get or cet the center coordinates of the Gaussian
218 // <group>
221 Type xCenter() const;
222 void setXcenter(const Type & xcenter);
223 Type yCenter() const;
224 void setYcenter(const Type & ycenter);
225 Type zCenter() const;
226 void setZcenter(const Type & zcenter);
227 // </group>
228
229 // Get or set the sigma-width of the Gaussian
230 // <group>
233 void setXwidth(const Type & xwidth);
234 Type xWidth() const;
235 void setYwidth(const Type & ywidth);
236 Type yWidth() const;
237 void setZwidth(const Type & zwidth);
238 Type zWidth() const;
239 // </group>
240
241 // Get or set the rotation angles of the Gaussian.
242 // Theta=logitude, phi=latitude
243 // <group>
244 Type theta() const;
245 void settheta(const Type & sT);
246 Type phi() const;
247 void setphi(const Type & sP);
248 // </group>
249
250protected:
251
252 void settrigvals() const;
253
254 Type fwhm2int; // const to scale halfwidth at 1/e to FWHM
255
256 mutable Type stoT_p; // used to check if cached values below are updated
257 mutable Type stoP_p; //
258 mutable Type cosT_p,sinT_p; // cached values of the cos and sine of THETA
259 mutable Type cosP_p,sinP_p; // PHI
260 mutable Type cosTcosP_p; //cached values of products of cos/sine of angles
261 mutable Type cosTsinP_p;
262 mutable Type sinTcosP_p;
263 mutable Type sinTsinP_p;
264
265 //# Make members of parent classes known.
266protected:
267 using Function<Type>::param_p;
268public:
269 using Function<Type>::nparameters;
270};
271
272
273} //# NAMESPACE CASACORE - END
274
275#ifndef CASACORE_NO_AUTO_TEMPLATES
276#include <casacore/scimath/Functionals/Gaussian3DParam.tcc>
277#endif //# CASACORE_NO_AUTO_TEMPLATES
278#endif
279
280
281
282
FunctionParam< Type > param_p
The parameters and masks.
Definition Function.h:330
uInt nparameters() const
Returns the number of parameters.
Definition Function.h:228
Vector< Type > center() const
Get or cet the center coordinates of the Gaussian.
void setYwidth(const Type &ywidth)
Vector< Type > width() const
Get or set the sigma-width of the Gaussian.
void setCenter(const Vector< Type > &center)
void setYcenter(const Type &ycenter)
void setZcenter(const Type &zcenter)
void settheta(const Type &sT)
void setWidth(const Vector< Type > &width)
Gaussian3DParam(const Gaussian3DParam< Type > &other)
Copy construcor.
Gaussian3DParam(Type height, const Vector< Type > &center, const Vector< Type > &width, Type theta, Type phi)
Type flux() const
Get or set the total flux of the Gaussian.
Type height() const
Get or set the peak height of the Gaussian.
virtual const String & name() const
Give name of function.
void setZwidth(const Type &zwidth)
Gaussian3DParam< Type > & operator=(const Gaussian3DParam< Type > &other)
Copy assignment.
void setHeight(const Type &height)
virtual ~Gaussian3DParam()
Destructor.
Gaussian3DParam(Type &height, Type &xCenter, Type &yCenter, Type &zCenter, Type &xWidth, Type &yWidth, Type &zWidth, Type &theta, Type &phi)
void setphi(const Type &sP)
void setXcenter(const Type &xcenter)
Gaussian3DParam()
Constructs the three dimensional Gaussians.
void setXwidth(const Type &xwidth)
virtual uInt ndim() const
Return dimensionality.
Gaussian3DParam(const Gaussian3DParam< W > &other)
void setFlux(const Type &flux)
Type theta() const
Get or set the rotation angles of the Gaussian.
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
LatticeExprNode sqrt(const LatticeExprNode &expr)
LatticeExprNode log(const LatticeExprNode &expr)