]> git.mxchange.org Git - simgear.git/blob - simgear/math/interpolater.hxx
Merge branch 'next' of git.mxchange.org:/var/cache/git/repos/simgear into next
[simgear.git] / simgear / math / interpolater.hxx
1 /**
2  * \file interpolater.hxx
3  * Routines to handle linear interpolation from a table of x,y The
4  * table must be sorted by "x" in ascending order
5  */
6
7 // Written by Curtis Olson, started April 1998.
8 //
9 // Copyright (C) 1998  Curtis L. Olson  - http://www.flightgear.org/~curt
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Library General Public
13 // License as published by the Free Software Foundation; either
14 // version 2 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 // Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24 //
25 // $Id$
26
27
28 #ifndef _INTERPOLATER_H
29 #define _INTERPOLATER_H
30
31
32 #ifndef __cplusplus
33 # error This library requires C++
34 #endif
35
36 #include <simgear/compiler.h>
37
38 #include <simgear/structure/SGReferenced.hxx>
39
40 #include <map>
41 #include <string>
42
43 class SGPropertyNode;
44 class SGPath;
45
46 /**
47  * A class that provids a simple linear 2d interpolation lookup table.
48  * The actual table is expected to be loaded from a file.  The
49  * independant variable must be strictly ascending.  The dependent
50  * variable can be anything.
51  */
52 class SGInterpTable : public SGReferenced {
53 public:
54
55     /**
56      * Constructor. Creates a new, empty table.
57      */
58     SGInterpTable();
59
60     /**
61      * Constructor. Loads the interpolation table from an interpolation
62      * property node.
63      * @param interpolation property node having entry children
64      */
65     SGInterpTable(const SGPropertyNode* interpolation);
66
67     /**
68      * Constructor. Loads the interpolation table from the specified file.
69      * @param file name of interpolation file
70      */
71     SGInterpTable( const std::string& file );
72
73     /**
74      * Constructor. Loads the interpolation table from the specified file.
75      * @param file name of interpolation file
76      */
77     SGInterpTable( const SGPath& path );
78     
79     /**
80      * Add an entry to the table, extending the table's length.
81      *
82      * @param ind The independent variable.
83      * @param dep The dependent variable.
84      */
85     void addEntry (double ind, double dep);
86     
87
88     /**
89      * Given an x value, linearly interpolate the y value from the table.
90      * @param x independent variable
91      * @return interpolated dependent variable
92      */
93     double interpolate(double x) const;
94
95     /** Destructor */
96     ~SGInterpTable();
97
98 private:
99     typedef std::map<double, double> Table;
100     Table _table;
101 };
102
103
104 #endif // _INTERPOLATER_H
105
106