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