]> git.mxchange.org Git - flightgear.git/blob - src/WeatherCM/sphrintp.h
Update from JSBSim
[flightgear.git] / src / WeatherCM / sphrintp.h
1 /*
2   WARNING - Do not remove this header.
3
4   This code is a templated version of the 'magic-software' spherical
5   interpolation code by Dave Eberly. The original (un-hacked) code can be
6   obtained from here: http://www.magic-software.com/gr_appr.htm
7   This code is derived from linintp2.h/cpp and sphrintp.h/cpp.
8
9   Dave Eberly says that the conditions for use are:
10
11   * You may distribute the original source code to others at no charge.
12
13   * You may modify the original source code and distribute it to others at
14     no charge. The modified code must be documented to indicate that it is
15     not part of the original package.
16
17   * You may use this code for non-commercial purposes. You may also
18     incorporate this code into commercial packages. However, you may not
19     sell any of your source code which contains my original and/or modified
20     source code. In such a case, you need to factor out my code and freely
21     distribute it.
22
23   * The original code comes with absolutely no warranty and no guarantee is
24     made that the code is bug-free.
25
26   This does not seem incompatible with GPL - so this modified version
27   is hereby placed under GPL along with the rest of FlightGear.
28
29                               Christian Mayer
30 */
31
32 #ifndef SPHRINTP_H
33 #define SPHRINTP_H
34
35 #include "linintp2.h"
36 #include <plib/sg.h>
37
38 template<class T>
39 class SphereInterpolate
40 {
41 public:
42     SphereInterpolate (int n, const double* x, const double* y,
43         const double* z, const T* f);
44     SphereInterpolate (int n, const sgVec2* p, const T* f);
45    
46     ~SphereInterpolate ();
47     
48     void GetSphericalCoords (const double x, const double y, const double z,
49         double& thetaAngle, double& phiAngle) const;
50     
51     int Evaluate (const double x, const double y, const double z, T& f) const;
52     int Evaluate (const double thetaAngle, const double phiAngle, T& f) const;
53
54 #ifndef macintosh
55     // CodeWarrior doesn't know the differece between sgVec2 and
56     // sgVec3, so I commented this out for Mac builds. This change is
57     // related to a similar change in FGLocalWeatherDatabase module.
58      
59     T Evaluate(const sgVec2& p) const
60     {
61         T retval;
62         Evaluate(p[1], p[0], retval);
63         return retval;
64     }
65 #endif
66
67  
68     T Evaluate(const sgVec3& p) const
69     {
70         T retval;
71         Evaluate(p[1], p[0], retval);
72         return retval;
73     }
74
75 protected:
76     int numPoints;
77     double* theta;
78     double* phi;
79     T* func;
80     mgcLinInterp2D<T>* pInterp;
81 };
82
83 #include "sphrintp.inl"
84
85 #endif