TuttleOFX
1
|
00001 #include "LutReader.hpp" 00002 00003 #include <boost/filesystem/path.hpp> 00004 #include <boost/tokenizer.hpp> 00005 #include <boost/spirit/include/classic_core.hpp> 00006 #include <boost/spirit/include/classic.hpp> 00007 #include <boost/spirit/include/classic_assign_actor.hpp> 00008 #include <boost/spirit/include/classic_core.hpp> 00009 #include <boost/filesystem/fstream.hpp> 00010 00011 #include <algorithm> 00012 #include <sstream> 00013 #include <iostream> 00014 00015 namespace tuttle { 00016 00017 using namespace boost; 00018 using namespace boost::spirit::classic; 00019 namespace fs = boost::filesystem; 00020 00021 bool LutReader::read( const fs::path& filename ) 00022 { 00023 std::stringstream ss; 00024 fs::ifstream file; 00025 00026 _data.clear(); 00027 _steps.clear(); 00028 00029 file.open( filename, std::ios::in ); 00030 ss << file.rdbuf(); 00031 gram_3dl g( *this ); 00032 parse_info<> info = parse( ss.str().c_str(), g >> eps_p ); 00033 00034 // Normalize values 00035 if( _data.size() > 0 ) 00036 { 00037 double max = *( max_element( _data.begin(), _data.end() ) ); 00038 double norm = 1.0 / std::pow( 2.0, std::ceil( std::log( max ) / std::log( 2.0 ) ) ); 00039 for( VectorDouble::iterator it = _data.begin(); it != _data.end(); ++it ) 00040 { 00041 ( *it ) *= norm; 00042 } 00043 } 00044 return _bReadOk = info.full; 00045 } 00046 00047 } // namespace tuttle