]> git.mxchange.org Git - flightgear.git/blob - src/WeatherCM/linintp2.h
Update from JSBSim
[flightgear.git] / src / WeatherCM / linintp2.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 LININTP2_H
33 #define LININTP2_H
34
35 template<class T>
36 class mgcLinInterp2D
37 {
38 public:
39     mgcLinInterp2D (int _numPoints, double* x, double* y, T* _f);
40
41     ~mgcLinInterp2D ();
42
43     double XMin () { return xmin; }
44     double XMax () { return xmax; }
45     double XRange () { return xmax-xmin; }
46     double YMin () { return ymin; }
47     double YMax () { return ymax; }
48     double YRange () { return ymax-ymin; }
49
50     int PointCount () { return numPoints; }
51     void GetPoint (int i, double& x, double& y);
52
53     int EdgeCount () { return numEdges; }
54     void GetEdge (int i, double& x0, double& y0, double& x1, double& y1);
55
56     int TriangleCount () { return numTriangles; }
57     void GetTriangle (int i, double& x0, double& y0, double& x1, double& y1,
58         double& x2, double& y2);
59
60     int Evaluate (double x, double y, T& F);
61     
62 private:
63     typedef struct
64     {
65         double x, y;
66     }
67     Vertex;
68
69     typedef struct
70     {
71         int vertex[3];  // listed in counterclockwise order
72
73         int adj[3];
74             // adj[0] points to triangle sharing edge (vertex[0],vertex[1])
75             // adj[1] points to triangle sharing edge (vertex[1],vertex[2])
76             // adj[2] points to triangle sharing edge (vertex[2],vertex[0])
77     }
78     Triangle;
79
80     typedef struct 
81     {
82         int vertex[2];
83         int triangle[2];
84         int index[2];
85     } 
86     Edge;
87
88     int numPoints;
89     double** point;
90     double** tmppoint;
91     T* f;
92
93     double xmin, xmax, ymin, ymax;
94
95
96     int numEdges;
97     Edge* edge;
98
99     int numTriangles;
100     Triangle* triangle;
101
102     int Delaunay2D ();
103     void ComputeBarycenter (Vertex& v0, Vertex& v1, Vertex& v2, Vertex& ver, 
104                             double c[3]);
105     int InTriangle (Vertex& v0, Vertex& v1, Vertex& v2, Vertex& test);
106 };
107
108 #include "linintp2.inl"
109
110 #endif