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