casacore
Loading...
Searching...
No Matches
Sinusoid1D.h
Go to the documentation of this file.
1//# Sinusoid1D.h: A one dimensional Sinusoid class
2//# Copyright (C) 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_SINUSOID1D_H
27#define SCIMATH_SINUSOID1D_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/scimath/Functionals/Sinusoid1DParam.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 Sinusoid class.
41// </summary>
42
43// <use visibility=export>
44
45// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tSinusoid1D"
46// demos="">
47// </reviewed>
48
49// <prerequisite>
50// <li> <linkto class="Sinusoid1DParam">Sinusoid1DParam</linkto>
51// <li> <linkto class="Function">Function</linkto>
52// </prerequisite>
53
54// <etymology>
55// A Sinusoid1D functional is designed for calculating a
56// Sinusoid in one dimension.
57// </etymology>
58
59// <synopsis>
60// A <src>Sinusoid1D</src> is described by an amplitude, a period,
61// and a location of a peak. Its fundamental operation is evaluating itself
62// at some <src>x</src>. The
63// parameters (amplitude, period, and x0) may be changed at run time.
64//
65// The functional form is <src> A*cos(2*pi(x-x0)/P) </src>
66//
67// The parameter interface (see
68// <linkto class="Sinusoid1DParam">Sinusoid1DParam</linkto> class),
69// is used to provide an interface to the
70// <linkto module="Fitting"> Fitting </linkto> classes.
71//
72// There are 3 parameters that are used to describe the Sinusoid:
73// <ol>
74// <li> The amplitude of the Sinusoid. This is the value
75// returned using the <src> amplitude </src> member function.
76// <li> The period of the Sinusoid in the x direction. This is
77// the value returned using the <src> period </src> member function.
78// The period is expressed in full cycles.
79// <li> The location of a peak of the Sinusoid (i.e. where
80// <src>x=pi+k.2pi</src>)
81// </ol>
82//
83// An enumeration for the <src>AMPLITUDE</src>, <src>PERIOD</src> and
84// <src>X0</src> parameter index is provided, enabling the setting
85// and reading of parameters with the <src>[]</src> operator. The
86// <src>mask()</src> methods can be used to check and set the parameter masks.
87//
88// </synopsis>
89
90// <example>
91// <srcblock>
92// Sinusoid1D<Double> sf(5.0, 25.0, 7);
93// sf(25); // = -0.9369
94// sf.setAmplitude(1.0);
95// sf[PERIOD] = 2.0;
96// sf.setX0(0.0);
97// sf(0.5); // = 0.0
98// </srcblock>
99// </example>
100
101// <templating arg=T>
102// <li> T should have standard numerical operators and cos() function. Current
103// implementation only tested for real types.
104// <li> To obtain derivatives, the derivatives should be defined.
105// </templating>
106
107// <thrown>
108// <li> AipsError if incorrect parameter number specified.
109// <li> Assertion in debug mode if operator(Vector<>) with empty Vector
110// </thrown>
111
112template<class T> class Sinusoid1D : public Sinusoid1DParam<T>
113{
114public:
115 //# Enumerations
116
117 //# Constructors
118 // Constructs the Sinusoids, Defaults:
119 // amplitude=1, period==1, x0=0. I.e. a cosinusoid with <src>cos(x)</src>.
120 // <note role=warning> Could not use default arguments
121 // that worked both with gcc and IRIX </note>
122 // <group>
124 explicit Sinusoid1D(const T &amplitude) :
126 Sinusoid1D(const T &amplitude, const T &period) :
128 Sinusoid1D(const T &amplitude, const T &period, const T &x0) :
130 // </group>
131
132 // Copy constructor (deep copy)
133 // <group>
134 Sinusoid1D(const Sinusoid1D &other) : Sinusoid1DParam<T>(other) {}
135 template <class W>
136 Sinusoid1D(const Sinusoid1D<W> &other) : Sinusoid1DParam<T>(other) {}
137 // </group>
138
139 // Copy assignment (deep copy)
141 Sinusoid1DParam<T>::operator=(other); return *this; }
142
143 // Destructor
144 virtual ~Sinusoid1D() {}
145
146 //# Operators
147 // Evaluate the Sinusoid at <src>x</src>.
148 // If a vector is used as the argument only its first element is used.
149 // <group>
150 virtual T eval(typename Function1D<T>::FunctionArg x) const;
151 // </group>
152
153 //# Member functions
154 // Return a copy of this object from the heap. The caller is responsible
155 // for deleting this pointer.
156 // <group>
157 virtual Function<T> *clone() const { return new Sinusoid1D<T>(*this); }
162 // </group>
163
164 //# Make members of parent classes known.
165protected:
167public:
171 using Sinusoid1DParam<T>::X0;
172};
173
174
175#define Sinusoid1D_PS Sinusoid1D
176// <summary> Partial specialization of Sinusoid1D for <src>AutoDiff</src>
177// </summary>
178
179// <synopsis>
180// <note role=warning> The name <src>Sinusoid1D_PS</src> is only for cxx2html
181// documentation problems. Use <src>Sinusoid1D</src> in your code.</note>
182// </synopsis>
184template <class T> class Sinusoid1D_PS<AutoDiff<T> > :
185public Sinusoid1DParam<AutoDiff<T> >
186{
187public:
188 //# Constructors
189 // Constructs one dimensional Sinusoids.
190 // <group>
192 explicit Sinusoid1D_PS(const AutoDiff<T> &amplitude) :
194 Sinusoid1D_PS(const AutoDiff<T> &amplitude, const AutoDiff<T> &period) :
196 Sinusoid1D_PS(const AutoDiff<T> &amplitude, const AutoDiff<T> &period,
197 const AutoDiff<T> &x0) :
198 Sinusoid1DParam<AutoDiff<T> >(amplitude, period, x0) {}
199 // </group>
200
201 // Copy constructor (deep copy)
202 // <group>
203 Sinusoid1D_PS(const Sinusoid1D_PS &other) :
204 Sinusoid1DParam<AutoDiff<T> >(other) {}
205 template <class W>
206 Sinusoid1D_PS(const Sinusoid1D_PS<W> &other) :
207 Sinusoid1DParam<AutoDiff<T> >(other) {}
208 // </group>
209
210 // Copy assignment (deep copy)
211 Sinusoid1D_PS<AutoDiff<T> > &
212 operator=(const Sinusoid1D_PS<AutoDiff<T> > &other) {
213 Sinusoid1DParam<AutoDiff<T> >::operator=(other); return *this; }
214
215 // Destructor
216 virtual ~Sinusoid1D_PS() {}
217
218 //# Operators
219 // Evaluate the Sinusoid at <src>x</src>.
220 // <group>
222 eval(typename Function<AutoDiff<T> >::FunctionArg x) const;
223 // </group>
224
225 //# Member functions
226 // Return a copy of this object from the heap. The caller is responsible
227 // for deleting this pointer.
228 // <group>
229 virtual Function<AutoDiff<T> > *clone() const {
230 return new Sinusoid1D<AutoDiff<T> >(*this); }
232 *cloneAD() const {
234 (*this); }
236 *cloneNonAD() const {
238 (*this); }
239 // </group>
240
241protected:
242 //# Make members of parent classes known.
243 using Sinusoid1DParam<AutoDiff<T> >::param_p;
244 using Sinusoid1DParam<AutoDiff<T> >::nparameters;
245 using Sinusoid1DParam<AutoDiff<T> >::AMPLITUDE;
246 using Sinusoid1DParam<AutoDiff<T> >::PERIOD;
247 using Sinusoid1DParam<AutoDiff<T> >::X0;
248};
249
250#undef Sinusoid1D_PS
251
252} //# NAMESPACE CASACORE - END
253
254#ifndef CASACORE_NO_AUTO_TEMPLATES
255#include <casacore/scimath/Functionals/Sinusoid1D.tcc>
256#include <casacore/scimath/Functionals/Sinusoid1D2.tcc>
257#endif //# CASACORE_NO_AUTO_TEMPLATES
258#endif
#define Sinusoid1D_PS
Definition Sinusoid1D.h:175
const T * FunctionArg
Definition Function1D.h:76
FunctionParam< T > param_p
The parameters and masks.
Definition Function.h:330
uInt nparameters() const
Returns the number of parameters.
Definition Function.h:228
T x0() const
Get or set the x0 of the Sinusoid, the location of a peak.
T amplitude() const
Get or set the amplitude of the Sinusoid.
T period() const
Get or set the period of the Sinusoid in full cycles.
Sinusoid1DParam< T > & operator=(const Sinusoid1DParam< T > &other)
Copy assignment (deep copy)
Sinusoid1D_PS(const Sinusoid1D_PS &other)
Copy constructor (deep copy)
Definition Sinusoid1D.h:202
Sinusoid1D_PS(const AutoDiff< T > &amplitude, const AutoDiff< T > &period)
Definition Sinusoid1D.h:193
virtual Function< typename FunctionTraits< AutoDiff< T > >::BaseType > * cloneNonAD() const
Definition Sinusoid1D.h:235
Sinusoid1D_PS(const AutoDiff< T > &amplitude, const AutoDiff< T > &period, const AutoDiff< T > &x0)
Definition Sinusoid1D.h:195
virtual Function< typename FunctionTraits< AutoDiff< T > >::DiffType > * cloneAD() const
Definition Sinusoid1D.h:231
Sinusoid1D_PS()
Constructs one dimensional Sinusoids.
Definition Sinusoid1D.h:190
Sinusoid1D_PS< AutoDiff< T > > & operator=(const Sinusoid1D_PS< AutoDiff< T > > &other)
Copy assignment (deep copy)
Definition Sinusoid1D.h:211
Sinusoid1D_PS(const AutoDiff< T > &amplitude)
Definition Sinusoid1D.h:191
virtual AutoDiff< T > eval(typename Function< AutoDiff< T > >::FunctionArg x) const
Evaluate the Sinusoid at x.
Sinusoid1D_PS(const Sinusoid1D_PS< W > &other)
Definition Sinusoid1D.h:205
virtual Function< AutoDiff< T > > * clone() const
Return a copy of this object from the heap.
Definition Sinusoid1D.h:228
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
Definition Sinusoid1D.h:160
Sinusoid1D(const T &amplitude, const T &period)
Definition Sinusoid1D.h:126
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
Definition Sinusoid1D.h:158
virtual ~Sinusoid1D()
Destructor.
Definition Sinusoid1D.h:144
virtual Function< T > * clone() const
Return a copy of this object from the heap.
Definition Sinusoid1D.h:157
Sinusoid1D()
Constructs the Sinusoids, Defaults: amplitude=1, period==1, x0=0.
Definition Sinusoid1D.h:123
Sinusoid1D(const T &amplitude, const T &period, const T &x0)
Definition Sinusoid1D.h:128
virtual T eval(typename Function1D< T >::FunctionArg x) const
Evaluate the Sinusoid at x.
Sinusoid1D(const Sinusoid1D &other)
Copy constructor (deep copy)
Definition Sinusoid1D.h:134
Sinusoid1D(const T &amplitude)
Definition Sinusoid1D.h:124
Sinusoid1D< T > & operator=(const Sinusoid1D< T > &other)
Copy assignment (deep copy)
Definition Sinusoid1D.h:140
Sinusoid1D(const Sinusoid1D< W > &other)
Definition Sinusoid1D.h:136
this file contains all the compiler specific defines
Definition mainpage.dox:28
TableExprNode amplitude(const TableExprNode &node)
The amplitude (i.e.
Definition ExprNode.h:1444
PtrHolder< T > & operator=(const PtrHolder< T > &other)