casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Gaussian1D.h
Go to the documentation of this file.
1 //# Gaussian1D.h: A one-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_GAUSSIAN1D_H
29 #define SCIMATH_GAUSSIAN1D_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
37 
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40 //# Forward declarations
41 
42 // <summary> A one dimensional Gaussian class.</summary>
43 
44 // <use visibility=export>
45 
46 // <reviewed reviewer="tcornwel" date="1996/02/22" tests="tGaussian1D"
47 // demos="">
48 // </reviewed>
49 
50 // <prerequisite>
51 // <li> <linkto class="Gaussian1DParam">Gaussian1DParam</linkto>
52 // <li> <linkto class="Function">Function</linkto>
53 // </prerequisite>
54 
55 // <etymology>
56 // A Gaussian1D functional is designed exclusively for calculating a
57 // Gaussian (or Normal) distribution in one dimension. Other classes exist
58 // for calculating these functions in two
59 // (<linkto class=Gaussian2D>Gaussian2D</linkto>) and N
60 // (<linkto class=GaussianND>GaussianND</linkto>) dimensions.
61 // </etymology>
62 
63 // <synopsis>
64 // A <src>Gaussian1D</src> is described by a height, center, and width. Its
65 // fundamental operation is evaluating itself at some <src>x</src>.
66 // The parameters (height, center and width) may be changed at run time.
67 //
68 // The width of the Gaussian (for the constructors or the <src>setWidth
69 // </src> function) is always specified in terms of the full width at half
70 // maximum (FWHM). It is always positive and attempts to set a non-positive
71 // width will throw an assertion when in debug mode.
72 //
73 // The peak height of the Gaussian can be specified at construction time or
74 // by using the <src> setHeight </src> function. Alternatively the <src>
75 // setFlux </src> function can be used to implicitly set the peak height by
76 // specifying the integrated area under the Gaussian. The height (or flux)
77 // can be positive, negative or zero, as this class makes no assumptions on
78 // what quantity the height represents.
79 //
80 // <note role=tip> Changing the width of the Gaussian will not affect
81 // its peak height but will change its flux. So you should always set the
82 // width before setting the flux. </note>
83 //
84 // The parameter interface (see
85 // <linkto class="Gaussian1DParam">Gaussian1DParam</linkto> class),
86 // is used to provide an interface to the
87 // <linkto module="Fitting">Fitting</linkto> classes.
88 //
89 // There are 3 parameters that are used to describe the Gaussian:
90 // <ol>
91 // <li> The height of the Gaussian. This is identical to the value
92 // returned using the <src>height()</src> member function.
93 // <li> The center of the Gaussian in the x direction. This is identical to
94 // the value returned using the <src>center()</src> member function.
95 // <li> The width (FWHM) of the Gaussian. To aid convergence of
96 // the non-linear fitting routines this parameter is allowed to be
97 // negative. This does not affect the shape of the Gaussian as the
98 // square of the width is used when evaluating the function.
99 // </ol>
100 //
101 // An enumeration for the <src>HEIGHT</src>, <src>WIDTH</src> and
102 // <src>CENTER</src> 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 // </synopsis>
107 
108 // <example>
109 // <srcblock>
110 // Gaussian<Double> gf(5.0, 25.0, 7);
111 // gf(25); // = 5.0
112 // gf[HEIGHT](1.0);
113 // gf.setWidth(2.0);
114 // gf[CENTER](0.0);
115 // gf(1); // = 0.5*height = 0.5
116 // </srcblock>
117 // </example>
118 
119 // <templating arg=T>
120 // <li> T should have standard numerical operators and exp() function. Current
121 // implementation only tested for real types.
122 // <li> To obtain derivatives, the derivatives should be defined.
123 // </templating>
124 
125 // <thrown>
126 // <li> Assertion in debug mode if attempt is made to set a negative width
127 // <li> AipsError if incorrect parameter number specified.
128 // <li> Assertion in debug mode if operator(Vector<>) with empty Vector
129 // </thrown>
130 
131 // <todo asof="2001/08/19">
132 // <li> Gaussians that know about their DFT's could be required eventually.
133 // </todo>
134 
135 template<class T> class Gaussian1D : public Gaussian1DParam<T> {
136 public:
137  //# Enumerations
138 
139  //# Constructors
140  // Constructs the one dimensional Gaussians. Defaults:
141  // height=1, center=0, width(FWHM)=1.
142  // <note role=warning> Could not use default arguments
143  // that worked both with gcc and IRIX </note>
144  // <group>
146  explicit Gaussian1D(const T &height) : Gaussian1DParam<T>(height) {}
147  Gaussian1D(const T &height, const T &center) :
148  Gaussian1DParam<T>(height, center) {}
149  Gaussian1D(const T &height, const T &center, const T &width) :
150  Gaussian1DParam<T>(height, center, width) {}
151  // </group>
152 
153  // Copy constructor (deep copy)
154  // <group>
155  Gaussian1D(const Gaussian1D<T> &other) : Gaussian1DParam<T>(other) {}
156  template <class W>
157  Gaussian1D(const Gaussian1D<W> &other) : Gaussian1DParam<T>(other) {}
158  // </group>
159 
160  // Copy assignment (deep copy)
162  Gaussian1DParam<T>::operator=(other); return *this; }
163 
164  // Destructor
165  virtual ~Gaussian1D() {}
166 
167  //# Operators
168  // Evaluate the Gaussian at <src>x</src>.
169  // <group>
170  virtual T eval(typename Function1D<T>::FunctionArg x) const;
171  // </group>
172 
173  //# Member functions
174  // Return a copy of this object from the heap. The caller is responsible
175  // for deleting this pointer.
176  // <group>
177  virtual Function<T> *clone() const { return new Gaussian1D<T>(*this); }
182  // </group>
183 
184  //# Make members of parent classes known.
185 protected:
187 public:
192 };
193 
194 
195 #define Gaussian1D_PS Gaussian1D
196 
197 // <summary> Partial specialization of Gaussian1D for <src>AutoDiff</src>
198 // </summary>
199 
200 // <synopsis>
201 // <note role=warning> The name <src>Gaussian1D_PS</src> is only for cxx2html
202 // documentation problems. Use <src>Gaussian1D</src> in your code.</note>
203 // </synopsis>
205 template <class T> class Gaussian1D_PS<AutoDiff<T> > :
206 public Gaussian1DParam<AutoDiff<T> >
207 {
208 public:
209  //# Constructors
210  // Constructs one dimensional Gaussians.
211  // <group>
213  explicit Gaussian1D_PS(const AutoDiff<T> &height) :
214  Gaussian1DParam<AutoDiff<T> >(height) {}
215  Gaussian1D_PS(const AutoDiff<T> &height, const AutoDiff<T> &center) :
216  Gaussian1DParam<AutoDiff<T> >(height, center) {}
217  Gaussian1D_PS(const AutoDiff<T> &height, const AutoDiff<T> &center,
218  const AutoDiff<T> &width) :
219  Gaussian1DParam<AutoDiff<T> >(height, center, width) {}
220  // </group>
221 
222  // Copy constructor (deep copy)
223  // <group>
224  Gaussian1D_PS(const Gaussian1D_PS &other) :
225  Gaussian1DParam<AutoDiff<T> >(other) {}
226  template <class W>
227  Gaussian1D_PS(const Gaussian1D_PS<W> &other) :
228  Gaussian1DParam<AutoDiff<T> >(other) {}
229  // </group>
230 
231  // Copy assignment (deep copy)
232  Gaussian1D_PS<AutoDiff<T> > &
233  operator=(const Gaussian1D_PS<AutoDiff<T> > &other) {
234  Gaussian1DParam<AutoDiff<T> >::operator=(other); return *this; }
235 
236  // Destructor
237  virtual ~Gaussian1D_PS() {}
238 
239  //# Operators
240  // Evaluate the Gaussian and its derivatives at <src>x</src>.
241  // <group>
242  virtual AutoDiff<T> eval(typename Function<AutoDiff<T> >::FunctionArg x) const;
243  // </group>
244 
245  //# Member functions
246  // Return a copy of this object from the heap. The caller is responsible
247  // for deleting this pointer.
248  // <group>
249  virtual Function<AutoDiff<T> > *clone() const {
250  return new Gaussian1D<AutoDiff<T> >(*this); }
252  *cloneAD() const {
253  return new Gaussian1D<typename FunctionTraits<AutoDiff<T> >::DiffType>
254  (*this); }
256  *cloneNonAD() const {
257  return new Gaussian1D<typename FunctionTraits<AutoDiff<T> >::BaseType>
258  (*this); }
259  // </group>
260 
261  //# Make members of parent classes known.
262 protected:
263  using Gaussian1DParam<AutoDiff<T> >::param_p;
264 public:
265  using Gaussian1DParam<AutoDiff<T> >::HEIGHT;
267  using Gaussian1DParam<AutoDiff<T> >::WIDTH;
268  using Gaussian1DParam<AutoDiff<T> >::fwhm2int;
269 };
270 
271 #undef Gaussian1D_PS
272 
273 
274 } //# NAMESPACE CASACORE - END
275 
276 #ifndef CASACORE_NO_AUTO_TEMPLATES
277 #include <casacore/scimath/Functionals/Gaussian1D.tcc>
278 #include <casacore/scimath/Functionals/Gaussian1D2.tcc>
279 #endif //# CASACORE_NO_AUTO_TEMPLATES
280 #endif
Gaussian1D(const Gaussian1D< T > &other)
Copy constructor (deep copy)
Definition: Gaussian1D.h:155
Gaussian1D< T > & operator=(const Gaussian1D< T > &other)
Copy assignment (deep copy)
Definition: Gaussian1D.h:161
virtual Function< T > * clone() const
Return a copy of this object from the heap.
Definition: Gaussian1D.h:177
Gaussian1D()
Constructs the one dimensional Gaussians.
Definition: Gaussian1D.h:145
T center() const
Get or set the center ordinate of the Gaussian.
T width() const
Get or set the FWHM of the Gaussian.
T height() const
Get or set the peak height of the Gaussian.
Gaussian1D(const Gaussian1D< W > &other)
Definition: Gaussian1D.h:157
PtrHolder< T > & operator=(const PtrHolder< T > &other)
virtual T eval(typename Function1D< T >::FunctionArg x) const
Evaluate the Gaussian at x.
Gaussian1D(const T &height, const T &center, const T &width)
Definition: Gaussian1D.h:149
Gaussian1D(const T &height, const T &center)
Definition: Gaussian1D.h:147
A one dimensional Gaussian class.
Definition: Gaussian1D.h:135
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
Definition: Gaussian1D.h:178
Class that computes partial derivatives by automatic differentiation.
Definition: AutoDiff.h:257
casacore::Bool clone(const casacore::String &imageName, const casacore::String &newImageName)
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
Definition: Gaussian1D.h:180
Numerical functional interface class for 1 dimension.
Definition: Function1D.h:75
Gaussian1D(const T &height)
Definition: Gaussian1D.h:146
Gaussian1D_PS(const AutoDiff< T > &height)
Definition: Gaussian1D.h:212
virtual ~Gaussian1D()
Destructor.
Definition: Gaussian1D.h:165
Gaussian1DParam< T > & operator=(const Gaussian1DParam< T > &other)
Copy assignment (deep copy)
#define Gaussian1D_PS
Definition: Gaussian1D.h:195
Parameter handling for one dimensional Gaussian class.
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42