casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Gaussian2D.h
Go to the documentation of this file.
1 //# Gaussian2D.h: A two-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_GAUSSIAN2D_H
29 #define SCIMATH_GAUSSIAN2D_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
37 
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40 //# Forward declarations
41 template<class T> class Vector;
42 
43 // <summary> A two dimensional Gaussian class.</summary>
44 
45 // <use visibility=export>
46 
47 // <reviewed reviewer="tcornwel" date="1996/02/22" tests="tGaussian2D"
48 // demos="">
49 // </reviewed>
50 
51 // <prerequisite>
52 // <li> <linkto class="Gaussian2DParam">Gaussian2DParam</linkto>
53 // <li> <linkto class="Function">Function</linkto>
54 // </prerequisite>
55 
56 // <etymology>
57 // A Gaussian2D functional is designed exclusively for calculating a
58 // Gaussian (or Normal) distribution in two dimensions. Other classes exist
59 // for calculating these functions in two
60 // (<linkto class=Gaussian1D>Gaussian1D</linkto>) and N
61 // (<linkto class=GaussianND>GaussianND</linkto>) dimensions.
62 // </etymology>
63 
64 // <synopsis>
65 // A <src>Gaussian2D</src> is described by a height, center, and width,
66 // and position angle. Its fundamental operation is evaluating itself
67 // at some <src>(x,y)</src>
68 // coordinate. Its parameters (height, center and width, position angle) may
69 // be changed at run time.
70 //
71 // The width of the Gaussian (for the constructors or the <src> setWidth
72 // </src> function) is always specified in terms of the full width at half
73 // maximum (FWHM). The major axis is parallel with the y axis when the
74 // position angle is zero. The major axis will always have a larger width
75 // than the minor axis.
76 //
77 // It is not possible to set the width of the major axis (using the <src>
78 // setMajorAxis </src> function) smaller than the width of the current minor
79 // axis. Similarly it is not possible to set the width of the minor axis
80 // (using the <src> setMinorAxis </src> function) to be larger than the
81 // current major axis. Exceptions are thrown if these rules are violated or
82 // if the either the major or minor axis is set to a non-positive width. To
83 // set both axis in one hit use the <src> setWidth </src> function. All
84 // these restrictions can be overcome when the parameters interface is used
85 // (see below).
86 //
87 // The position angle is the angle between the y axis and the major axis and
88 // is measured counterclockwise, so a position angle of 45 degrees rotates
89 // the major axis to the line where y=-x. The position angle is always
90 // specified and returned in radians. When using the <src> setPA </src>
91 // function its value must be between -2pi and + 2pi, and the returned value
92 // from the <src> pa </src> function will always be a value between 0 and
93 // pi.
94 //
95 // The axial ratio can be used as an alternative to specifying the width of
96 // the minor axis. It is the ratio between the minor and major axis
97 // widths. The axial ratio is constrained to be between zero and one, and
98 // specifying something different (using setAxialRatio) will throw an
99 // exception.
100 //
101 // The peak height of the Gaussian can be specified at construction time or
102 // by using the <src> setHeight </src> function. Alternatively the <src>
103 // setFlux </src> function can be used to implicitly set the peak height by
104 // specifying the integrated area under the Gaussian. The height (or flux)
105 // can be positive, negative or zero, as this class makes no assumptions on
106 // what quantity the height represents.
107 //
108 // <note role=tip> Changing the width of the Gaussian will not affect
109 // its peak height but will change its flux. So you should always set the
110 // width before setting the flux. </note>
111 //
112 // The parameter interface (see
113 // <linkto class="Gaussian2DParam">Gaussian2DParam</linkto> class),
114 // is used to provide an interface to the
115 // <linkto module="Fitting">Fitting</linkto> classes.
116 //
117 // There are 6 parameters that are used to describe the Gaussian:
118 // <ol>
119 // <li> The height of the Gaussian. This is identical to the value
120 // returned using the <src> height </src> member function.
121 // <li> The center of the Gaussian in the x direction. This is identical to
122 // the value returned using the <src> xCenter </src> member function.
123 // <li> The center of the Gaussian in the y direction. This is identical to
124 // the value returned using the <src> yCenter </src> member function.
125 // <li> The width (FWHM) of the Gaussian on one axis. Initially this will be
126 // the major axis, but if the parameters are adjusted by a Fitting
127 // class, it may become the axis with the smaller width. To aid
128 // convergence of the non-linear fitting routines this parameter is
129 // allowed to be negative. This does not affect the shape of the
130 // Gaussian as the squares of the widths are used when evaluating the
131 // function.
132 // <li> A modified axial ratio. This parameter is the ratio of the width on
133 // the 'other' axis (which initially is the minor axis) and axis given
134 // by parameter YWIDTH. Because these internal widths are allowed to be
135 // negative and because there is no constraints on which axis is the
136 // larger one the modified axial ratio is not constrained to be between
137 // zero and one.
138 // <li> The position angle. This represents the angle (in radians) between
139 // the axis used by parameter 4, and the y axis, measured
140 // counterclockwise. If parameter 4 represents the major axis width
141 // then this parameter will be identical to the position angle,
142 // otherwise it will be different by 90 degrees. The tight constraints
143 // on the value of the rotation angle enforced by the setPA() function
144 // are relaxed so that any value between -6000 and 6000 is allowed. It
145 // is still interpreted in radians.
146 // </ol>
147 //
148 // An enumeration for the parameter index is provided, enabling the setting
149 // and reading of parameters with the <src>[]</src> operator. The
150 // <src>mask()</src> methods can be used to check and set the parameter masks.
151 //
152 // </synopsis>
153 
154 // <example>
155 // <srcblock>
156 // Gaussian2D<Double> g(10.0, 0.0, 0.0, 2.0, 1.0, 0.0);
157 // Vector<Double> x(2);
158 // x(0) = 1.0; x(1) = 0.5;
159 // cout << "g(" << x(0) << "," << x(1) << ") = " << g(x) << endl;
160 // </srcblock>
161 // </example>
162 
163 // <templating arg=T>
164 // <li> T should have standard numerical operators and exp() function. Current
165 // implementation only tested for real types.
166 // <li> To obtain derivatives, the derivatives should be defined.
167 // </templating>
168 
169 // <thrown>
170 // <li> Assertion in debug mode if attempt is made to set a negative width
171 // <li> AipsError if incorrect parameter number specified.
172 // <li> Assertion in debug mode if operator(Vector<>) with empty Vector
173 // </thrown>
174 
175 // <todo asof="2001/08/19">
176 // <li> Gaussians that know about their DFT's could be required eventually.
177 // </todo>
178 
179 template<class T> class Gaussian2D : public Gaussian2DParam<T>
180 {
181 public:
182  //# Enumerations
183 
184  //# Constructors
185  // Constructs the two dimensional Gaussians. Defaults:
186  // height=1, center=0, width(FWHM)=1, PA=0. The center and width vectors
187  // must have two elements
188  // <note role=warning> Could not use default arguments
189  // that worked both with gcc and IRIX </note>
190  // <group>
192  Gaussian2D(const T &height, const Vector<T> &center,
193  const Vector<T> &width, const T &pa) :
194  Gaussian2DParam<T>(height, center, width, pa) {}
195  Gaussian2D(const T &height, const T &xCenter, const T &yCenter,
196  const T &majorAxis, const T &axialRatio, const T &pa) :
197  Gaussian2DParam<T>(height, xCenter, yCenter, majorAxis,
198  axialRatio, pa) {}
199  // </group>
200 
201  // Copy constructor (deep copy)
202  // <group>
203  Gaussian2D(const Gaussian2D<T> &other) : Gaussian2DParam<T>(other) {}
204  template <class W>
205  Gaussian2D(const Gaussian2D<W> &other) : Gaussian2DParam<T>(other) {}
206  // </group>
207 
208  // Copy assignment (deep copy)
210  Gaussian2DParam<T>::operator=(other); return *this; }
211 
212  // Destructor
213  virtual ~Gaussian2D() {}
214 
215  //# Operators
216  // Evaluate the Gaussian at <src>x</src>.
217  // <group>
218  virtual T eval(typename Function<T>::FunctionArg x) const;
219  // </group>
220 
221  //# Member functions
222  // Return a copy of this object from the heap. The caller is responsible
223  // for deleting this pointer.
224  // <group>
225  virtual Function<T> *clone() const { return new Gaussian2D<T>(*this); }
230  // </group>
231 
232  //# Make members of parent classes known.
233 protected:
239 public:
247 };
248 
249 #define Gaussian2D_PS Gaussian2D
250 
251 // <summary> Partial specialization of Gaussian2D for <src>AutoDiff</src>
252 // </summary>
253 
254 // <synopsis>
255 // <note role=warning> The name <src>Gaussian2D_PS</src> is only for cxx2html
256 // documentation problems. Use <src>Gaussian2D</src> in your code.</note>
257 // </synopsis>
259 template <class T> class Gaussian2D_PS<AutoDiff<T> > :
260 public Gaussian2DParam<AutoDiff<T> >
261 {
262 public:
263  //# Constructors
264  // Constructs two dimensional Gaussians.
265  // <group>
267  Gaussian2D_PS(const AutoDiff<T> &height,
268  const Vector<AutoDiff<T> > &center,
269  const Vector<AutoDiff<T> > &width,
270  const AutoDiff<T> &pa) :
271  Gaussian2DParam<AutoDiff<T> >(height, center, width, pa) {}
272  Gaussian2D_PS(const AutoDiff<T> &height, const AutoDiff<T> &xCenter,
273  const AutoDiff<T> &yCenter, const AutoDiff<T> &majorAxis,
274  const AutoDiff<T> &axialRatio, const AutoDiff<T> &pa) :
275  Gaussian2DParam<AutoDiff<T> >(height, xCenter, yCenter, majorAxis,
276  axialRatio, pa) {}
277  // </group>
278 
279  // Copy constructor (deep copy)
280  // <group>
281  Gaussian2D_PS(const Gaussian2D_PS &other) :
282  Gaussian2DParam<AutoDiff<T> >(other) {}
283  template <class W>
284  Gaussian2D_PS(const Gaussian2D_PS<W> &other) :
285  Gaussian2DParam<AutoDiff<T> >(other) {}
286  // </group>
287 
288  // Copy assignment (deep copy)
289  Gaussian2D_PS<AutoDiff<T> > &
290  operator=(const Gaussian2D_PS<AutoDiff<T> > &other) {
291  Gaussian2DParam<AutoDiff<T> >::operator=(other); return *this; }
292 
293  // Destructor
294  virtual ~Gaussian2D_PS() {}
295 
296  //# Operators
297  // Evaluate the Gaussian and its derivatives at <src>x</src>.
298  // <group>
299  virtual AutoDiff<T> eval(typename Function<AutoDiff<T> >::FunctionArg x) const;
300  // </group>
301 
302  //# Member functions
303  // Return a copy of this object from the heap. The caller is responsible
304  // for deleting this pointer.
305  // <group>
306  virtual Function<AutoDiff<T> > *clone() const {
307  return new Gaussian2D<AutoDiff<T> >(*this); }
309  *cloneAD() const {
310  return new Gaussian2D<typename FunctionTraits<AutoDiff<T> >::DiffType>
311  (*this); }
313  *cloneNonAD() const {
314  return new Gaussian2D<typename FunctionTraits<AutoDiff<T> >::BaseType>
315  (*this); }
316  // </group>
317 
318  //# Make members of parent classes known.
319 protected:
320  using Gaussian2DParam<AutoDiff<T> >::param_p;
321  using Gaussian2DParam<AutoDiff<T> >::thePA;
322  using Gaussian2DParam<AutoDiff<T> >::theCpa;
323  using Gaussian2DParam<AutoDiff<T> >::theSpa;
324  using Gaussian2DParam<AutoDiff<T> >::theXwidth;
325 public:
326  using Gaussian2DParam<AutoDiff<T> >::HEIGHT;
327  using Gaussian2DParam<AutoDiff<T> >::XCENTER;
328  using Gaussian2DParam<AutoDiff<T> >::YCENTER;
329  using Gaussian2DParam<AutoDiff<T> >::YWIDTH;
330  using Gaussian2DParam<AutoDiff<T> >::RATIO;
331  using Gaussian2DParam<AutoDiff<T> >::PANGLE;
332  using Gaussian2DParam<AutoDiff<T> >::fwhm2int;
333 };
334 
335 #undef Gaussian2D_PS
336 
337 
338 } //# NAMESPACE CASACORE - END
339 
340 #ifndef CASACORE_NO_AUTO_TEMPLATES
341 #include <casacore/scimath/Functionals/Gaussian2D.tcc>
342 #include <casacore/scimath/Functionals/Gaussian2D2.tcc>
343 #endif //# CASACORE_NO_AUTO_TEMPLATES
344 #endif
A 1-D Specialization of the Array class.
std::vector< double > Vector
Definition: ds9context.h:24
T height() const
Get or set the peak height of the Gaussian.
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
Definition: Gaussian2D.h:228
A two dimensional Gaussian class.
Definition: Gaussian2D.h:179
Parameter handling for 2 dimensional Gaussian class.
#define Gaussian2D_PS
Definition: Gaussian2D.h:249
PtrHolder< T > & operator=(const PtrHolder< T > &other)
Gaussian2D(const Gaussian2D< T > &other)
Copy constructor (deep copy)
Definition: Gaussian2D.h:203
Vector< T > width() const
Set or get the FWHM of the Gaussian.
Gaussian2D< T > & operator=(const Gaussian2D< T > &other)
Copy assignment (deep copy)
Definition: Gaussian2D.h:209
Gaussian2DParam< T > & operator=(const Gaussian2DParam< T > &other)
Copy assignment (deep copy)
Gaussian2D()
Constructs the two dimensional Gaussians.
Definition: Gaussian2D.h:191
LatticeExprNode pa(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds 180/pi*atan2(left,right)/2.
Numerical functional interface class.
Gaussian2D(const T &height, const T &xCenter, const T &yCenter, const T &majorAxis, const T &axialRatio, const T &pa)
Definition: Gaussian2D.h:195
Class that computes partial derivatives by automatic differentiation.
Definition: AutoDiff.h:257
virtual ~Gaussian2D()
Destructor.
Definition: Gaussian2D.h:213
casacore::Bool clone(const casacore::String &imageName, const casacore::String &newImageName)
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
Definition: Gaussian2D.h:226
virtual T eval(typename Function< T >::FunctionArg x) const
Evaluate the Gaussian at x.
Gaussian2D(const Gaussian2D< W > &other)
Definition: Gaussian2D.h:205
Gaussian2D(const T &height, const Vector< T > &center, const Vector< T > &width, const T &pa)
Definition: Gaussian2D.h:192
Vector< T > center() const
Get or set the center ordinate of the Gaussian.
virtual Function< T > * clone() const
Return a copy of this object from the heap.
Definition: Gaussian2D.h:225
Gaussian2D_PS(const AutoDiff< T > &height, const Vector< AutoDiff< T > > &center, const Vector< AutoDiff< T > > &width, const AutoDiff< T > &pa)
Definition: Gaussian2D.h:266
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42