casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: 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 //# $Id$
27 
28 #ifndef SCIMATH_GAUSSIAN3D_H
29 #define SCIMATH_GAUSSIAN3D_H
30 
31 #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> A three dimensional Gaussian class.</summary>
43 
44 // <use visibility=export>
45 
46 // <reviewed reviewer="" date="" tests="tGaussian3D"
47 // demos="">
48 // </reviewed>
49 
50 // <prerequisite>
51 // <li> <linkto class="Gaussian3DParam">Gaussian3DParam</linkto>
52 // <li> <linkto class="Function">Function</linkto>
53 // </prerequisite>
54 
55 // <etymology>
56 // A Gaussian3D functional is designed exclusively for calculating a
57 // Gaussian (or Normal) distribution in three dimensions. Other classes exist
58 // for calculating these functions in one
59 // (<linkto class=Gaussian1D>Gaussian1D</linkto>), two
60 // (<linkto class=Gaussian2D>Gaussian2D</linkto>), and N
61 // (<linkto class=GaussianND>GaussianND</linkto>) dimensions.
62 // </etymology>
63 
64 // <synopsis>
65 // A <src>Gaussian3D</src> is described by a height, center, and width,
66 // and position angles. Its fundamental operation is evaluating itself
67 // at some <src>(x,y,z)</src>
68 // coordinate. Its parameters (height, center and width, position angles) may
69 // be changed at run time.
70 
71 // The width of the Gaussian is now specified in terms of the full width
72 // at half maximum (FWHM), like the 2D and 1D Gaussian functional classes.
73 
74 // The three axis values refer to the x, y, and z axes, and unlike with the
75 // 2D Gaussian any of the three axes may be the longest; instead, the position
76 // angles are restricted. The first position angle, theta, is the longitudinal
77 // angle, referring to the rotation (counterclockwise) around the z-axis. The
78 // second, phi, is the latidudinal angle, referring to the rotation around
79 // the theta-rotated y axis. The domain of both angles is -pi/4 < A < pi/4,
80 // although the angles are not constrained when fitting and can be set outside
81 // the domain by setting the parameters directly using Functional operator[].
82 // (Note that the use of theta and phi corresponds to the mathematics
83 // convention for these angles, not the physics convention.)
84 
85 // The parameter interface (see
86 // <linkto class="Gaussian3DParam">Gaussian3DParam</linkto> class),
87 // is used to provide an interface to the
88 // <linkto module="Fitting">Fitting</linkto> classes.
89 //
90 // There are 9 parameters that are used to describe the Gaussian:
91 // <ol>
92 // <li> The height of the Gaussian. This is identical to the value
93 // returned using the <src> height </src> member function.
94 // <li> The center of the Gaussian in the x direction. This is identical to
95 // the value returned using the <src> xCenter </src> member function.
96 // <li> The center of the Gaussian in the y direction. This is identical to
97 // the value returned using the <src> yCenter </src> member function.
98 // <li> The center of the Gaussian in the z direction. This is identical to
99 // the value returned using the <src> zCenter </src> member function.
100 // <li> The width of the Gaussian along the x-axis.
101 // <li> The width of the Gaussian along the y-axis.
102 // <li> The width of the Gaussian along the z-axis.
103 // <li> The longitudinal position angle, theta (in radians)
104 // <li> The latitudinal position angle, phi (also in radians).
105 // </ol>
106 
107 // An enumeration for the parameter index is provided, enabling the setting
108 // and reading of parameters with the <src>[]</src> operator. The
109 // <src>mask()</src> methods can be used to check and set the parameter masks.
110 //
111 // </synopsis>
112 
113 // <example>
114 // <srcblock>
115 // Gaussian3D<Double> g(9.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0);
116 // Vector<Double> x(3);
117 // x(0) = 1.0; x(1) = 0.5; x(2) = 0.0
118 // cout << "g(" << x(0) << "," << x(1) << "," << x(2) << ")=" << g(x) << endl;
119 // </srcblock>
120 // </example>
121 
122 // <motivation>
123 // The GaussianND class does not contain explicit derivatives
124 // and was insufficient for fitting 3D Gaussians to data.
125 // </motivation>
126 
127 // <templating arg=T>
128 // <li> T should have standard numerical operators and exp() function. Current
129 // implementation only tested for real types.
130 // <li> To obtain derivatives, the derivatives should be defined.
131 // </templating>
132 
133 // <thrown>
134 // <li> Assertion in debug mode if attempt is made to set a negative width
135 // <li> AipsError if incorrect parameter number specified.
136 // <li> Assertion in debug mode if operator(Vector<>) with empty Vector
137 // </thrown>
138 
139 // <todo asof="2002/07/22">
140 // <li> Optimize derivative calculations for faster fitting?
141 // </todo>
142 
143 
144 
145 template<class T> class Gaussian3D : public Gaussian3DParam<T>
146 {
147 public:
148  // A functional for a rotated, 3D Gaussian. Similar to Gaussian2D, but
149  // the xWidth, yWidth, and zWidth parameters are not adjusted for FWHM;
150  // they are identical to the parameters used in the function.
151 
152  // Constructs the three-dimensional Gaussians. Defaults:
153  // height = 1, center = {0,0,0}, width = {1,1,1}, theta = phi = 0.
154  // The center and width vectors must have three elements.
155  // <group>
156  Gaussian3D();
157  Gaussian3D(T height, const Vector<T>& center,
158  const Vector<T>& width, T theta, T phi);
159  Gaussian3D(T &height, T &xCenter, T &yCenter, T &zCenter,
160  T &xWidth, T &yWidth, T &zWidth, T &theta, T &phi);
161  // </group>
162 
163  // Copy constructor
164  // <group>
165  Gaussian3D(const Gaussian3D<T> &other);
166  template <class W>
167  Gaussian3D(const Gaussian3D<W> &other) : Gaussian3DParam<T>(other) {}
168  // </group>
169 
170  // Destructor
171  virtual ~Gaussian3D();
172 
173  // Assignment operator
174  Gaussian3D<T> &operator=(const Gaussian3D<T> &other);
175 
176  // Evaluate the Gaussian at <src>x</src>.
177  virtual T eval(typename Function<T>::FunctionArg x) const;
178 
179  // Return a copy of this object from the heap. The caller is responsible
180  // for deleting this pointer.
181  // <group>
182  virtual Function<T> *clone() const;
187  // </group>
188 
189 private:
190  // AutoDiff does not have a square() function, so one is provided here.
191  T sq(T v) const;
192 
193  //# Make members of parent classes known.
194 protected:
206 public:
207  using Gaussian3DParam<T>::H;
218 };
219 
220 
221 // AUTODIFF SPECIALIZATION
222 
223 #define Gaussian3D_PS Gaussian3D
224 
225 // <summary> Partial specialization of Gaussian3D for <src>AutoDiff</src>
226 // </summary>
227 
228 // <synopsis>
229 // <note role=warning> The name <src>Gaussian3D_PS</src> is only for cxx2html
230 // documentation problems. Use <src>Gaussian3D</src> in your code.</note>
231 // </synopsis>
232 
234 template <class T> class Gaussian3D_PS<AutoDiff<T> > : public Gaussian3DParam<AutoDiff<T> >
235 {
236 public:
237  Gaussian3D_PS();
238  Gaussian3D_PS(const AutoDiff<T> &height,
239  const Vector<AutoDiff<T> >& center,
240  const Vector<AutoDiff<T> >& width,
241  const AutoDiff<T>& theta,
242  const AutoDiff<T>& phi);
243  Gaussian3D_PS(AutoDiff<T>& height, AutoDiff<T>& xCenter,
244  AutoDiff<T>& yCenter, AutoDiff<T>& zCenter,
245  AutoDiff<T>& xWidth, AutoDiff<T>& yWidth,
246  AutoDiff<T>& zWidth, AutoDiff<T>& theta,
247  AutoDiff<T>& phi);
248  Gaussian3D_PS(const Gaussian3D_PS<AutoDiff<T> > &other);
249  template <class W>
250  Gaussian3D_PS(const Gaussian3D_PS<W> &other) :
251  Gaussian3DParam<AutoDiff<T> >(other) {}
252  virtual ~Gaussian3D_PS();
253 //
254  Gaussian3D_PS<AutoDiff<T> > &operator=(const Gaussian3D_PS<AutoDiff<T> > &other);
255 //
256  virtual AutoDiff<T> eval(typename Function<AutoDiff<T> >::FunctionArg x) const;
257  virtual Function<AutoDiff<T> > *clone() const;
259  *cloneAD() const {
260  return new Gaussian3D<typename FunctionTraits<AutoDiff<T> >::DiffType>
261  (*this); }
263  *cloneNonAD() const {
264  return new Gaussian3D<typename FunctionTraits<AutoDiff<T> >::BaseType>
265  (*this); }
266 
267 private:
268  T sq(T v) const;
269 
270  //# Make members of parent classes known.
271 protected:
272  using Gaussian3DParam<AutoDiff<T> >::param_p;
273  using Gaussian3DParam<AutoDiff<T> >::stoT_p;
274  using Gaussian3DParam<AutoDiff<T> >::stoP_p;
275  using Gaussian3DParam<AutoDiff<T> >::cosT_p;
276  using Gaussian3DParam<AutoDiff<T> >::cosP_p;
277  using Gaussian3DParam<AutoDiff<T> >::sinT_p;
278  using Gaussian3DParam<AutoDiff<T> >::sinP_p;
279  using Gaussian3DParam<AutoDiff<T> >::cosTcosP_p;
280  using Gaussian3DParam<AutoDiff<T> >::cosTsinP_p;
281  using Gaussian3DParam<AutoDiff<T> >::sinTcosP_p;
282  using Gaussian3DParam<AutoDiff<T> >::sinTsinP_p;
283 public:
284  using Gaussian3DParam<AutoDiff<T> >::H;
285  using Gaussian3DParam<AutoDiff<T> >::CX;
286  using Gaussian3DParam<AutoDiff<T> >::CY;
287  using Gaussian3DParam<AutoDiff<T> >::CZ;
288  using Gaussian3DParam<AutoDiff<T> >::AX;
289  using Gaussian3DParam<AutoDiff<T> >::AY;
290  using Gaussian3DParam<AutoDiff<T> >::AZ;
291  using Gaussian3DParam<AutoDiff<T> >::THETA;
292  using Gaussian3DParam<AutoDiff<T> >::PHI;
293  using Gaussian3DParam<AutoDiff<T> >::fwhm2int;
294  using Gaussian3DParam<AutoDiff<T> >::settrigvals;
295 };
296 
297 #undef Gaussian3D_PS
298 
299 
300 } //# NAMESPACE CASACORE - END
301 
302 #ifndef CASACORE_NO_AUTO_TEMPLATES
303 #include <casacore/scimath/Functionals/Gaussian3D.tcc>
304 #include <casacore/scimath/Functionals/Gaussian3D2.tcc>
305 #endif //# CASACORE_NO_AUTO_TEMPLATES
306 #endif
307 
308 
309 
310 
311 
T height() const
Get or set the peak height of the Gaussian.
A 1-D Specialization of the Array class.
std::vector< double > Vector
Definition: ds9context.h:24
virtual T eval(typename Function< T >::FunctionArg x) const
Evaluate the Gaussian at x.
T theta() const
Get or set the rotation angles of the Gaussian.
virtual Function< T > * clone() const
Return a copy of this object from the heap.
PtrHolder< T > & operator=(const PtrHolder< T > &other)
Gaussian3D(const Gaussian3D< W > &other)
Definition: Gaussian3D.h:167
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
Definition: Gaussian3D.h:183
Vector< T > center() const
Get or cet the center coordinates of the Gaussian.
Parameter handling for 3 dimensional Gaussian class.
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
Definition: Gaussian3D.h:185
Gaussian3D()
A functional for a rotated, 3D Gaussian.
Numerical functional interface class.
Vector< T > width() const
Get or set the sigma-width of the Gaussian.
virtual ~Gaussian3D()
Destructor.
Class that computes partial derivatives by automatic differentiation.
Definition: AutoDiff.h:257
casacore::Bool clone(const casacore::String &imageName, const casacore::String &newImageName)
A three dimensional Gaussian class.
Definition: Gaussian3D.h:145
Gaussian3D< T > & operator=(const Gaussian3D< T > &other)
Assignment operator.
T sq(T v) const
AutoDiff does not have a square() function, so one is provided here.
#define Gaussian3D_PS
AUTODIFF SPECIALIZATION.
Definition: Gaussian3D.h:223
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42