casacore
Loading...
Searching...
No Matches
MathFunc.h
Go to the documentation of this file.
1// # MathFunc.h: Templated letter/envelope classes for single dependent variable functions
2// # Copyright (C) 1993,1994,1995,1996,1999,2000,2001,2003
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_MATHFUNC_H
27#define SCIMATH_MATHFUNC_H
28
29// # MathFunc: A templated letter/envelope set of classes for packaging
30// # of specific single dependent variable functions.
31
32#include <casacore/casa/aips.h>
33#include <casacore/casa/BasicMath/Math.h>
34#include <casacore/casa/BasicSL/Constants.h>
35#include <casacore/casa/Exceptions/Error.h>
36#include <casacore/casa/Arrays/Vector.h>
37#include <casacore/casa/BasicSL/String.h>
38
39namespace casacore { // # NAMESPACE CASACORE - BEGIN
40
41// <summary>
42// Error class for <linkto class=MathFunc>MathFunc</linkto> class
43// </summary>
44
45// <synopsis>
46// Error class for <linkto class=MathFunc>MathFunc</linkto> class
47// </synopsis>
48
49class MathFuncError : public AipsError {
50 public:
51 MathFuncError() : AipsError("MathFuncError") {}
52 MathFuncError(const Char *m) : AipsError(m) {}
53 MathFuncError(const String &m) : AipsError(m) {}
54
55 virtual ~MathFuncError() noexcept {}
56};
57
58// <summary>
59// Fred Schwab function to calculate spheriodal functions
60// </summary>
61
62// <synopsis>
63// Fred Schwab function to calculate spheriodal functions.
64// </synopsis>
65
66// <group name="spheriodal functions">
68// Fred Schwab function to calculate spheriodal functions, in C.
69extern "C" {
70Int sphfn(Int *, Int *, Int *, float *, float *, Int *);
71}
72
73// C++ wrapper to Fred Schwab function to calculate spheriodal functions.
74float sphfn(Int ialf, Int im, float eta);
75
76// </group>
77
78// <summary>
79// Enum used to identify function type for
80// MathFunc class
81// </summary>
82
83// <synopsis>
84// Enum used to identify function type for
85// <linkto class=MathFunc>MathFunc</linkto> class
86// </synopsis>
87
88// ############################################################################
89// # NOTE: Delete the following listing of the enumerations when enumerations
90// # are handled properly by the documentation extractor.
91// ############################################################################
92
93// <note role=caution>
94// The following enum documentation is currently
95// extracted by hand, and thus
96// could be out of date if this documentation was not updated when the
97// enum was modified.
98// </note>
99
100// The FUNCTYPE enum is:
101// <srcblock>
102//
103// enum FUNCTYPE { UNARY, GAUSSIAN, KB, MOD_KB, SINC, SPHEROIDAL, EXP_SINC };
104//
105// </srcblock>
106
107// <group name="FUNCTYPE enum">
110
111// </group>
112
113// <summary>
114// Function ID, for use by <linkto class=MathFunc>MathFunc</linkto> class
115// </summary>
116
117// <synopsis>
118// Function ID, for use by <linkto class=MathFunc>MathFunc</linkto> class.
119// </synopsis>
120
125
126// <summary> A class to generate values of mathematical functions </summary>
127//
128// <synopsis>
129//
130// This class is the abstract base class for 1-dimensional math functions.
131//
132// Actual math functions are then an inherited class from the base
133// class. This approach allows one to define actual function values
134// for each derived class. Then, one can pass a generic MathFunc
135// pointer to other objects, but the other objects will still get
136// function values from the actual inherited function.
137//
138// By defining each math function as an object, we can place
139// parameters which will not change from one call to the function value
140// to another in the class definition and they only have to be
141// initialized once.
142//
143// </synopsis>
144
145//
146// MathFunc is the base class for 1-dimensional math functions
147//
148template <class T>
149class MathFunc {
150 public:
151 //
152 // constructors
153 //
154 MathFunc(FUNCTYPE);
155 // accept up to 4 arguments, the first being the support radius
156 MathFunc(FUNCTYPE, T cutoff, T arg1 = 1.0e+30, T arg2 = 1.0e+30, T arg3 = 1.0e+30);
158 MathFunc(const MathFunc<T> &); // Copy constructor
160
161 //
162 // Destructor
163 //
164 virtual ~MathFunc();
165
166 //
167 // Assignment operator - Note: this function works only for envelops.
168 // Polymorphism flaws will let you pass a letter as an argument but an
169 // exception will be thrown at run time.
170 //
172
173 //
174 // return value of support width
175 //
176 virtual T sup_value() const;
177
178 //
179 // compute and return a value of the math function
180 //
181 virtual T value(const T &a) const;
182
183 //
184 // create a new math function
185 //
187
188 //
189 // return a FuncId structure for Table storage/retrieval.
190 //
191 virtual FuncId id() const;
192
193 //
194 // These functions return the static constants used as default
195 // parameters for the various derived functions
196 //
197
198 // The default support radius
199 static T defcutoff() { return defcutoff_p; }
200 // The default width for Gaussian_Conv
201 static T defwidth() { return defwidth_p; }
202 // The default width for KB_Conv and Mod_KB_Conv
203 static T defKBwidth() { return defKBwidth_p; }
204 // A default parameter for KB_Conv and Mod_KB_Conv
205 static T defKBparm() { return defKBparm_p; }
206 // A default parameter for Mod_KB_Conv
207 static T defmodKBparm() { return defmodKBparm_p; }
208 // The default support radius for Sinc_Conv and Sph_Conv
209 static T defSphcutoff() { return defSphcutoff_p; }
210 // The default Sinc parameter for Sinc_Conv and Exp_Sinc_Conv
211 static T defSincparm() { return defSincparm_p; }
212 // The default parameter for Sph_Conv
213 static T defSphparm() { return defSphparm_p; }
214 // The default exponential power for Exp_Sinc_Conv
215 static T defExpPower() { return defExpPower_p; }
216 // The default exponential scale length for Exp_Sinc_Conv
217 static T defExpScale() { return defExpScale_p; }
218
219 protected:
220 //
221 // for every derived class, return new of that class with its own parameters
222 //
223 virtual MathFunc<T> *clone() const;
224
225 //
226 // Default constructor (Null)
227 //
229
230 //
231 // pointer to letter class
232 //
234
235 private:
236 static T defcutoff_p;
237 static T defwidth_p;
238 static T defKBparm_p;
239 static T defKBwidth_p;
242 static T defSphparm_p;
246};
247
248// # ========================================================
249// # Now we define actual math classes as inherited classes of
250// # the base class MathFunc
251// # =========================================================
252
253//
254// <summary>Unary</summary>
255//
256// <synopsis>
257// A Unary function (always returns the value 1.0)
258// </synopsis>
259//
260template <class T>
261class Unary : public MathFunc<T> {
262 public:
263 //
264 // default constructor
265 //
267
268 //
269 // copy constructor
270 //
271 Unary(const Unary<T> &);
272
274
275 T sup_value() const { return sup_width; }
276
277 T value(const T &) const;
278
279 //
280 // return a FuncId structure for Table storage/retrieval.
281 //
282 FuncId id() const;
283
284 private:
286
288};
289
290//
291// <category lib=aips sect="Math">
292// <summary>Gaussian</summary>
293//
294// <synopsis>
295// A Gaussian
296// </synopsis>
297//
298template <class T>
299class GaussianConv : public MathFunc<T> {
300 public:
301 //
302 // default constructor
303 //
305
306 //
307 // copy constructor
308 //
310
312
313 T sup_value() const { return sup_width; }
314
315 T value(const T &) const;
316
317 //
318 // return a FuncId structure for Table storage/retrieval.
319 //
320 FuncId id() const;
321
322 private:
324
326 const T ln16;
327};
328
329//
330// <category lib=aips sect="Math">
331// <summary>A Kaiser-Bessel function</summary>
332//
333// <synopsis>
334// A Kaiser-Bessel function
335// </synopsis>
336//
337template <class T>
338class KB_Conv : public MathFunc<T> {
339 public:
340 // default constructor
343
344 // copy constructor
346
348
349 T sup_value() const { return sup_width; }
350
351 T value(const T &) const;
352
353 //
354 // return a FuncId structure for Table storage/retrieval.
355 //
356 FuncId id() const;
357
358 private:
360
362};
363
364//
365// <category lib=aips sect="Math">
366// <summary>A Kaiser-Bessel function multiplied by a Gaussian</summary>
367//
368// <synopsis>
369// A Kaiser-Bessel function multiplied by a Gaussian
370// </synopsis>
371//
372
373template <class T>
374class Mod_KB_Conv : public MathFunc<T> {
375 public:
376 // default constructor
379
380 // copy constructor
382
384
385 T sup_value() const { return sup_width; }
386
387 T value(const T &) const;
388
389 //
390 // return a FuncId structure for Table storage/retrieval.
391 //
392 FuncId id() const;
393
394 private:
396
398 const T ln16;
399};
400
401// <category lib=aips sect="Math">
402// <summary>Sine x / x function</summary>
403//
404//
405// <synopsis>
406// Sine x / x function
407// </synopsis>
408//
409template <class T>
410class Sinc_Conv : public MathFunc<T> {
411 public:
412 // default constructor
414 // copy constructor
416
418
419 T sup_value() const { return sup_width; }
420
421 T value(const T &) const;
422
423 //
424 // return a FuncId structure for Table storage/retrieval.
425 //
426 FuncId id() const;
427
428 private:
430
432};
433
434//
435// <category lib=aips sect="Math">
436// <summary>Spheroidal function</summary>
437//
438// <synopsis>
439// Spheroidal function - calls Fred Schwab function converted by f2c
440// </synopsis>
441//
442template <class T>
443class Sph_Conv : public MathFunc<T>
444//
445// Spheroidal function - calls Fred Schwab function converted by f2c
446//
447{
448 public:
449 // default constructor
451 // copy constructor
453
455
456 T sup_value() const { return sup_width; }
457
458 float value(const float &) const;
459
460 //
461 // return a FuncId structure for Table storage/retrieval.
462 //
463 FuncId id() const;
464
465 private:
467
469};
470
471// <category lib=aips sect="Math">
472// <summary>Exponential times a Sinc</summary>
473//
474// <synopsis>
475// An Exponential times a Sinc
476//
477// The <src> value(T &x) </src> is given by
478// <src> Exp(-(abs(x) / expscale) ** exppow) * Sinc( pi * x / sincparm) </src>
479//
480// where the 3 paramaters correspond to those in the default constructor
481// Note that the default case of <src> exppow = 2 </src> is
482// a Gaussian times a Sinc.
483// Since this is often a useful case, that parameter appears last in the
484// constructor.
485// </synopsis>
486//
487template <class T>
488class ExpSincConv : public MathFunc<T> {
489 public:
490 //
491 // default constructor
492 //
494 T exppow = MathFunc<T>::defExpPower(), T expscale = MathFunc<T>::defExpScale());
495 // copy constructor
497
498 // assignment operator
500
501 // get access to the support width
502 T sup_value() const { return sup_width; }
503
504 // and get the value of the function
505 T value(const T &) const;
506
507 //
508 // return FuncID structure for Table storage/retrieval.
509 //
510 FuncId id() const;
511
512 private:
514
516};
517
518} // namespace casacore
519
520#ifndef CASACORE_NO_AUTO_TEMPLATES
521#include <casacore/scimath/Mathematics/MathFunc.tcc>
522#endif // # CASACORE_NO_AUTO_TEMPLATES
523#endif // AIPS_MATHFUNC_H
AipsError(const Char *str, Category c=GENERAL)
Creates an AipsError and initializes the error message from the parameter.
FuncId id() const
return FuncID structure for Table storage/retrieval.
ExpSincConv< T > & operator=(const ExpSincConv< T > &)
assignment operator
T value(const T &) const
and get the value of the function
MathFunc< T > * clone() const
for every derived class, return new of that class with its own parameters
ExpSincConv(const ExpSincConv< T > &)
copy constructor
ExpSincConv(T cut=MathFunc< T >::defcutoff(), T sincparm=MathFunc< T >::defSincparm(), T exppow=MathFunc< T >::defExpPower(), T expscale=MathFunc< T >::defExpScale())
default constructor
T sup_value() const
get access to the support width
Definition MathFunc.h:502
MathFunc< T > * clone() const
for every derived class, return new of that class with its own parameters
T sup_value() const
return value of support width
Definition MathFunc.h:313
GaussianConv< T > & operator=(const GaussianConv< T > &)
FuncId id() const
return a FuncId structure for Table storage/retrieval.
GaussianConv(const GaussianConv< T > &)
copy constructor
T value(const T &) const
compute and return a value of the math function
GaussianConv(T cut=MathFunc< T >::defcutoff(), T wparm=MathFunc< T >::defwidth())
default constructor
KB_Conv(const KB_Conv< T > &)
copy constructor
T sup_value() const
return value of support width
Definition MathFunc.h:349
MathFunc< T > * clone() const
for every derived class, return new of that class with its own parameters
KB_Conv< T > & operator=(const KB_Conv< T > &)
T value(const T &) const
compute and return a value of the math function
KB_Conv(T cut=MathFunc< T >::defcutoff(), T wparm=MathFunc< T >::defKBwidth(), T kbparm=MathFunc< T >::defKBparm())
default constructor
FuncId id() const
return a FuncId structure for Table storage/retrieval.
virtual ~MathFuncError() noexcept
Definition MathFunc.h:55
MathFuncError(const Char *m)
Definition MathFunc.h:52
MathFuncError(const String &m)
Definition MathFunc.h:53
static T defSphparm_p
Definition MathFunc.h:242
static T defSphparm()
The default parameter for Sph_Conv.
Definition MathFunc.h:213
static T defExpPower_p
Definition MathFunc.h:244
static MathFunc< T > * newMathFunc(const MathFunc< T > &)
create a new math function
static T defwidth_p
Definition MathFunc.h:237
static T defSphcutoff_p
Definition MathFunc.h:241
static T defKBparm_p
Definition MathFunc.h:238
virtual ~MathFunc()
Destructor.
static T defcutoff()
These functions return the static constants used as default parameters for the various derived functi...
Definition MathFunc.h:199
static T defcutoff_p
Definition MathFunc.h:236
virtual MathFunc< T > * clone() const
for every derived class, return new of that class with its own parameters
MathFunc(MathFunc< T > *)
static T defExpPower()
The default exponential power for Exp_Sinc_Conv.
Definition MathFunc.h:215
MathFunc< T > & operator=(const MathFunc< T > &)
Assignment operator - Note: this function works only for envelops.
static T defKBwidth()
The default width for KB_Conv and Mod_KB_Conv.
Definition MathFunc.h:203
MathFunc(FUNCTYPE, T cutoff, T arg1=1.0e+30, T arg2=1.0e+30, T arg3=1.0e+30)
accept up to 4 arguments, the first being the support radius
MathFunc(const MathFunc< T > &)
static T defSphcutoff()
The default support radius for Sinc_Conv and Sph_Conv.
Definition MathFunc.h:209
MathFunc(String &, Vector< double > &)
virtual FuncId id() const
return a FuncId structure for Table storage/retrieval.
MathFunc< T > * object
pointer to letter class
Definition MathFunc.h:233
static T defmodKBparm_p
Definition MathFunc.h:240
static T defExpScale()
The default exponential scale length for Exp_Sinc_Conv.
Definition MathFunc.h:217
virtual T sup_value() const
return value of support width
static T defSincparm_p
Definition MathFunc.h:243
virtual T value(const T &a) const
compute and return a value of the math function
static T defmodKBparm()
A default parameter for Mod_KB_Conv.
Definition MathFunc.h:207
static T defSincparm()
The default Sinc parameter for Sinc_Conv and Exp_Sinc_Conv.
Definition MathFunc.h:211
MathFunc()
Default constructor (Null).
static T defKBwidth_p
Definition MathFunc.h:239
static T defKBparm()
A default parameter for KB_Conv and Mod_KB_Conv.
Definition MathFunc.h:205
static T defExpScale_p
Definition MathFunc.h:245
static T defwidth()
The default width for Gaussian_Conv.
Definition MathFunc.h:201
MathFunc(FUNCTYPE)
constructors
MathFunc< T > * clone() const
for every derived class, return new of that class with its own parameters
Mod_KB_Conv(const Mod_KB_Conv< T > &)
copy constructor
Mod_KB_Conv< T > & operator=(const Mod_KB_Conv< T > &)
T value(const T &) const
compute and return a value of the math function
FuncId id() const
return a FuncId structure for Table storage/retrieval.
Mod_KB_Conv(T cut=MathFunc< T >::defcutoff(), T wparm=MathFunc< T >::defKBwidth(), T kbparm=MathFunc< T >::defKBparm(), T gwparm=MathFunc< T >::defmodKBparm())
default constructor
T sup_value() const
return value of support width
Definition MathFunc.h:385
FuncId id() const
return a FuncId structure for Table storage/retrieval.
T value(const T &) const
compute and return a value of the math function
Sinc_Conv< T > & operator=(const Sinc_Conv< T > &)
Sinc_Conv(T cut=MathFunc< T >::defSphcutoff(), T sincparm=MathFunc< T >::defSincparm())
default constructor
T sup_value() const
return value of support width
Definition MathFunc.h:419
Sinc_Conv(const Sinc_Conv< T > &)
copy constructor
MathFunc< T > * clone() const
for every derived class, return new of that class with its own parameters
T sup_value() const
return value of support width
Definition MathFunc.h:456
FuncId id() const
return a FuncId structure for Table storage/retrieval.
MathFunc< T > * clone() const
for every derived class, return new of that class with its own parameters
Sph_Conv< T > & operator=(const Sph_Conv< T > &)
Sph_Conv(const Sph_Conv< T > &)
copy constructor
float value(const float &) const
Sph_Conv(T cut=MathFunc< T >::defSphcutoff(), T Sphparm=MathFunc< T >::defSphparm())
default constructor
String: the storage and methods of handling collections of characters.
Definition String.h:355
Unary< T > & operator=(const Unary< T > &)
Unary(const Unary< T > &)
copy constructor
FuncId id() const
return a FuncId structure for Table storage/retrieval.
T value(const T &) const
compute and return a value of the math function
T sup_value() const
return value of support width
Definition MathFunc.h:275
Unary(T cut=MathFunc< T >::defcutoff())
default constructor
MathFunc< T > * clone() const
for every derived class, return new of that class with its own parameters
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
int Int
Definition aipstype.h:48
char Char
Definition aipstype.h:44
Function ID, for use by MathFunc class.
Definition MathFunc.h:121
Vector< double > args
Definition MathFunc.h:123
Enum used to identify function type for MathFunc class.
Definition MathFunc.h:108
Fred Schwab function to calculate spheriodal functions.
Definition MathFunc.h:67
float sphfn(Int ialf, Int im, float eta)
C++ wrapper to Fred Schwab function to calculate spheriodal functions.
Int sphfn(Int *, Int *, Int *, float *, float *, Int *)
Fred Schwab function to calculate spheriodal functions, in C.