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