]> git.mxchange.org Git - flightgear.git/blob - src/WeatherCM/sphrintp.h
Hack in an /accelerations/pilot-g property, for testing a new panel
[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 <simgear/compiler.h>
36 #include STL_IOSTREAM
37
38 #include "linintp2.h"
39 #include <plib/sg.h>
40
41 #ifndef SG_HAVE_NATIVE_SGI_COMPILERS
42 SG_USING_NAMESPACE(std);
43 SG_USING_STD(cout);
44 #endif
45
46
47 class SphereInterpolate
48 {
49 public:
50     SphereInterpolate (int n, const double* x, const double* y,
51         const double* z, const unsigned int* f);
52     SphereInterpolate (int n, const sgVec2* p, const unsigned int* f);
53    
54     ~SphereInterpolate ();
55     
56     void GetSphericalCoords (const double x, const double y, const double z,
57         double& thetaAngle, double& phiAngle) const;
58     
59     int Evaluate (const double x, const double y, const double z, EvaluateData& f) const;
60     int Evaluate (const double thetaAngle, const double phiAngle, EvaluateData& f) const;
61
62 #ifndef macintosh
63     // CodeWarrior doesn't know the differece between sgVec2 and
64     // sgVec3, so I commented this out for Mac builds. This change is
65     // related to a similar change in FGLocalWeatherDatabase module.
66      
67     EvaluateData Evaluate(const sgVec2& p) const
68     {
69         EvaluateData retval;
70         Evaluate(p[1], p[0], retval);
71         return retval;
72     }
73 #endif
74
75  
76     EvaluateData Evaluate(const sgVec3& p) const
77     {
78         EvaluateData retval;
79         if (!Evaluate(p[1], p[0], retval))
80         {
81           cout << "Error during spherical interpolation. Point (" 
82                << p[0] << "/" << p[1] << "/" << p[2] << ") was in no triangle\n";
83           retval.index[0] = 0;  //fake something
84           retval.index[1] = 0;
85           retval.index[2] = 0;
86           retval.percentage[0] = 1.0;
87           retval.percentage[1] = 0.0;
88           retval.percentage[2] = 0.0;
89         }
90         return retval;
91     }
92
93 protected:
94     int numPoints;
95     double* theta;
96     double* phi;
97     unsigned int* func;
98     mgcLinInterp2D* pInterp;
99 };
100
101 #endif