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