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