5555#include < rawtoaces/rta.h>
5656#include < rawtoaces/mathOps.h>
5757
58- #include < boost/property_tree/ptree.hpp>
59- #include < boost/property_tree/json_parser.hpp>
60- #include < boost/foreach.hpp>
58+ #include < fstream>
59+ #include < nlohmann/json.hpp>
6160
62- using namespace boost ::property_tree;
6361using namespace ceres ;
6462
6563namespace rta
6664{
65+
6766Illum::Illum ()
6867{
6968 _inc = 5 ;
@@ -146,23 +145,22 @@ int Illum::readSPD( const string &path, const string &type )
146145
147146 try
148147 {
149- // using libraries from boost::property_tree
150- ptree pt;
151- read_json ( path, pt );
152-
153- const string stype = pt.get <string>( " header.illuminant" );
154- if ( type.compare ( stype ) != 0 && type.compare ( " na" ) != 0 )
148+ std::ifstream i ( path );
149+ nlohmann::json data = nlohmann::json::parse ( i );
150+ const string stype = data[" header" ][" illuminant" ];
151+ if ( type != stype && type != " na" )
155152 return 0 ;
156153
157154 _type = stype;
158155
159156 vector<int > wavs;
160157 int dis;
161158
162- BOOST_FOREACH (
163- ptree::value_type &row, pt. get_child ( " spectral_data.data.main " ) )
159+ nlohmann::json main_data = data[ " spectral_data " ][ " data " ][ " main " ];
160+ for ( auto &[index, values]: main_data. items ( ) )
164161 {
165- wavs.push_back ( atoi ( ( row.first ).c_str () ) );
162+ std::string row = index;
163+ wavs.push_back ( stoi ( row ) );
166164
167165 if ( wavs.size () == 2 )
168166 dis = wavs[1 ] - wavs[0 ];
@@ -183,11 +181,11 @@ int Illum::readSPD( const string &path, const string &type )
183181 else if ( wavs[wavs.size () - 1 ] > 780 )
184182 break ;
185183
186- BOOST_FOREACH ( ptree::value_type &cell, row. second )
184+ for ( auto j: values )
187185 {
188- _data.push_back ( cell. second . get_value < double >() );
186+ _data.push_back ( ( double )j );
189187 if ( wavs[wavs.size () - 1 ] == 550 )
190- _index = cell. second . get_value < double >() ;
188+ _index = ( double )j ;
191189 }
192190
193191 // printf ( "\"%i\": [ %18.13f ], \n",
@@ -599,26 +597,30 @@ int Spst::loadSpst( const string &path, const char *maker, const char *model )
599597
600598 try
601599 {
602- ptree pt ;
603- read_json ( path, pt );
600+ std::ifstream i ( path ) ;
601+ nlohmann::json data = nlohmann::json::parse ( i );
604602
605- string cmaker = pt. get <string>( " header. manufacturer" ) ;
606- if ( maker != nullptr && cmp_str ( maker, cmaker .c_str () ) )
603+ const string camera_make = data[ " header" ][ " manufacturer" ] ;
604+ if ( camera_make. empty () || cmp_str ( camera_make .c_str (), maker ) != 0 )
607605 return 0 ;
608- setBrand ( cmaker.c_str () );
609606
610- string cmodel = pt.get <string>( " header.model" );
611- if ( model != nullptr && cmp_str ( model, cmodel.c_str () ) )
607+ setBrand ( camera_make.c_str () );
608+
609+ const string camera_model = data[" header" ][" model" ];
610+ if ( camera_model.empty () ||
611+ cmp_str ( camera_model.c_str (), model ) != 0 )
612612 return 0 ;
613- setModel ( cmodel.c_str () );
613+
614+ setModel ( camera_model.c_str () );
614615
615616 vector<int > wavs;
616617 int inc;
617618
618- BOOST_FOREACH (
619- ptree::value_type &row, pt. get_child ( " spectral_data.data.main " ) )
619+ nlohmann::json main_data = data[ " spectral_data " ][ " data " ][ " main " ];
620+ for ( auto &[index, values]: main_data. items ( ) )
620621 {
621- wavs.push_back ( atoi ( ( row.first ).c_str () ) );
622+ std::string row = index;
623+ wavs.push_back ( stoi ( row ) );
622624
623625 if ( wavs.size () == 2 )
624626 inc = wavs[1 ] - wavs[0 ];
@@ -640,8 +642,8 @@ int Spst::loadSpst( const string &path, const char *maker, const char *model )
640642 break ;
641643
642644 vector<double > data;
643- BOOST_FOREACH ( ptree::value_type &cell, row. second )
644- data.push_back ( cell. second . get_value < double >() );
645+ for ( auto j: values )
646+ data.push_back ( ( double )j );
645647
646648 // ensure there are three components
647649 assert ( data.size () == 3 );
@@ -980,19 +982,22 @@ void Idt::loadTrainingData( const string &path )
980982
981983 try
982984 {
983- ptree pt ;
984- read_json ( path, pt );
985+ std::ifstream stream ( path ) ;
986+ nlohmann::json data = nlohmann::json::parse ( stream );
985987
986988 int i = 0 ;
987989
988- BOOST_FOREACH (
989- ptree::value_type &row, pt. get_child ( " spectral_data.data.main " ) )
990+ nlohmann::json main_data = data[ " spectral_data " ][ " data " ][ " main " ];
991+ for ( auto &[index, values]: main_data. items ( ) )
990992 {
991- _trainingSpec[i]._wl = atoi ( ( row.first ).c_str () );
993+ std::string row = index;
994+ _trainingSpec[i]._wl = stoi ( row );
992995
993- BOOST_FOREACH ( ptree::value_type &cell, row.second )
994- _trainingSpec[i]._data .push_back (
995- cell.second .get_value <double >() );
996+ for ( auto j: values )
997+ {
998+ double d = j;
999+ _trainingSpec[i]._data .push_back ( d );
1000+ }
9961001
9971002 assert ( _trainingSpec[i]._data .size () == 190 );
9981003
@@ -1021,14 +1026,16 @@ void Idt::loadCMF( const string &path )
10211026
10221027 try
10231028 {
1024- ptree pt ;
1025- read_json ( path, pt );
1029+ std::ifstream stream ( path ) ;
1030+ nlohmann::json data = nlohmann::json::parse ( stream );
10261031
10271032 int i = 0 ;
1028- BOOST_FOREACH (
1029- ptree::value_type &row, pt.get_child ( " spectral_data.data.main" ) )
1033+
1034+ nlohmann::json main_data = data[" spectral_data" ][" data" ][" main" ];
1035+ for ( auto &[index, values]: main_data.items () )
10301036 {
1031- int wl = atoi ( ( row.first ).c_str () );
1037+ std::string row = index;
1038+ int wl = stoi ( row );
10321039
10331040 if ( wl < 380 || wl % 5 )
10341041 continue ;
@@ -1038,8 +1045,8 @@ void Idt::loadCMF( const string &path )
10381045 _cmf[i]._wl = wl;
10391046
10401047 vector<double > data;
1041- BOOST_FOREACH ( ptree::value_type &cell, row. second )
1042- data.push_back ( cell. second . get_value < double >() );
1048+ for ( auto j: values )
1049+ data.push_back ( ( double )j );
10431050
10441051 assert ( data.size () == 3 );
10451052 _cmf[i]._xbar = data[0 ];
0 commit comments