From 8cfe5a2e088116f8fcd8b7e33aee21cbdb182fc6 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 23 Jun 2016 15:21:26 +0100 Subject: [PATCH] Native SGPath API on SGInterpTable - string-based version will be removed in the future. --- simgear/math/interpolater.cxx | 22 ++++++++++++++++++++++ simgear/math/interpolater.hxx | 8 +++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/simgear/math/interpolater.cxx b/simgear/math/interpolater.cxx index b9526ea9..cbbb31cf 100644 --- a/simgear/math/interpolater.cxx +++ b/simgear/math/interpolater.cxx @@ -64,6 +64,28 @@ SGInterpTable::SGInterpTable( const std::string& file ) return; } + in >> skipcomment; + while ( in ) { + double ind, dep; + in >> ind >> dep; + in >> std::skipws; + _table[ind] = dep; + } +} + + +// Constructor -- loads the interpolation table from the specified +// file +SGInterpTable::SGInterpTable( const SGPath& file ) +{ + SG_LOG( SG_MATH, SG_INFO, "Initializing Interpolator for " << file ); + + sg_gzifstream in( file ); + if ( !in.is_open() ) { + SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << file ); + return; + } + in >> skipcomment; while ( in ) { double ind, dep; diff --git a/simgear/math/interpolater.hxx b/simgear/math/interpolater.hxx index 34dff626..5f928502 100644 --- a/simgear/math/interpolater.hxx +++ b/simgear/math/interpolater.hxx @@ -41,6 +41,7 @@ #include class SGPropertyNode; +class SGPath; /** * A class that provids a simple linear 2d interpolation lookup table. @@ -69,7 +70,12 @@ public: */ SGInterpTable( const std::string& file ); - + /** + * Constructor. Loads the interpolation table from the specified file. + * @param file name of interpolation file + */ + SGInterpTable( const SGPath& path ); + /** * Add an entry to the table, extending the table's length. *