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