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+
66+ bool case_insensitive_compare ( const string & str1, const char * str2 )
67+ {
68+ if ( str1.length () != strlen ( str2 ) )
69+ return false ;
70+ for ( size_t i = 0 ; i < str1.length (); i++ )
71+ if ( std::tolower ( str1[i] ) != std::tolower ( str2[i] ) )
72+ return false ;
73+ return true ;
74+ }
75+
6776Illum::Illum ()
6877{
6978 _inc = 5 ;
@@ -146,23 +155,22 @@ int Illum::readSPD( const string &path, const string &type )
146155
147156 try
148157 {
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 )
158+ std::ifstream i ( path );
159+ nlohmann::json data = nlohmann::json::parse ( i );
160+ const string stype = data[" header" ][" illuminant" ];
161+ if ( type != stype && type != " na" )
155162 return 0 ;
156163
157164 _type = stype;
158165
159166 vector<int > wavs;
160167 int dis;
161168
162- BOOST_FOREACH (
163- ptree::value_type &row, pt. get_child ( " spectral_data.data.main " ) )
169+ nlohmann::json main_data = data[ " spectral_data " ][ " data " ][ " main " ];
170+ for ( auto &[index, values]: main_data. items ( ) )
164171 {
165- wavs.push_back ( atoi ( ( row.first ).c_str () ) );
172+ std::string row = index;
173+ wavs.push_back ( stoi ( row ) );
166174
167175 if ( wavs.size () == 2 )
168176 dis = wavs[1 ] - wavs[0 ];
@@ -183,11 +191,11 @@ int Illum::readSPD( const string &path, const string &type )
183191 else if ( wavs[wavs.size () - 1 ] > 780 )
184192 break ;
185193
186- BOOST_FOREACH ( ptree::value_type &cell, row. second )
194+ for ( auto j: values )
187195 {
188- _data.push_back ( cell. second . get_value < double >() );
196+ _data.push_back ( ( double )j );
189197 if ( wavs[wavs.size () - 1 ] == 550 )
190- _index = cell. second . get_value < double >() ;
198+ _index = ( double )j ;
191199 }
192200
193201 // printf ( "\"%i\": [ %18.13f ], \n",
@@ -599,26 +607,33 @@ int Spst::loadSpst( const string &path, const char *maker, const char *model )
599607
600608 try
601609 {
602- ptree pt ;
603- read_json ( path, pt );
610+ std::ifstream i ( path ) ;
611+ nlohmann::json data = nlohmann::json::parse ( i );
604612
605- string cmaker = pt.get <string>( " header.manufacturer" );
606- if ( maker != nullptr && cmp_str ( maker, cmaker.c_str () ) )
613+ const string camera_make = data[" header" ][" manufacturer" ];
614+ if ( camera_make.empty () )
615+ return 0 ;
616+ if ( !case_insensitive_compare ( camera_make, maker ) )
607617 return 0 ;
608- setBrand ( cmaker.c_str () );
609618
610- string cmodel = pt.get <string>( " header.model" );
611- if ( model != nullptr && cmp_str ( model, cmodel.c_str () ) )
619+ setBrand ( camera_make.c_str () );
620+
621+ const string camera_model = data[" header" ][" model" ];
622+ if ( camera_model.empty () )
623+ return 0 ;
624+ if ( !case_insensitive_compare ( camera_model, model ) )
612625 return 0 ;
613- setModel ( cmodel.c_str () );
626+
627+ setModel ( camera_model.c_str () );
614628
615629 vector<int > wavs;
616630 int inc;
617631
618- BOOST_FOREACH (
619- ptree::value_type &row, pt. get_child ( " spectral_data.data.main " ) )
632+ nlohmann::json main_data = data[ " spectral_data " ][ " data " ][ " main " ];
633+ for ( auto &[index, values]: main_data. items ( ) )
620634 {
621- wavs.push_back ( atoi ( ( row.first ).c_str () ) );
635+ std::string row = index;
636+ wavs.push_back ( stoi ( row ) );
622637
623638 if ( wavs.size () == 2 )
624639 inc = wavs[1 ] - wavs[0 ];
@@ -640,8 +655,8 @@ int Spst::loadSpst( const string &path, const char *maker, const char *model )
640655 break ;
641656
642657 vector<double > data;
643- BOOST_FOREACH ( ptree::value_type &cell, row. second )
644- data.push_back ( cell. second . get_value < double >() );
658+ for ( auto j: values )
659+ data.push_back ( ( double )j );
645660
646661 // ensure there are three components
647662 assert ( data.size () == 3 );
@@ -980,19 +995,22 @@ void Idt::loadTrainingData( const string &path )
980995
981996 try
982997 {
983- ptree pt ;
984- read_json ( path, pt );
998+ std::ifstream stream ( path ) ;
999+ nlohmann::json data = nlohmann::json::parse ( stream );
9851000
9861001 int i = 0 ;
9871002
988- BOOST_FOREACH (
989- ptree::value_type &row, pt. get_child ( " spectral_data.data.main " ) )
1003+ nlohmann::json main_data = data[ " spectral_data " ][ " data " ][ " main " ];
1004+ for ( auto &[index, values]: main_data. items ( ) )
9901005 {
991- _trainingSpec[i]._wl = atoi ( ( row.first ).c_str () );
1006+ std::string row = index;
1007+ _trainingSpec[i]._wl = stoi ( row );
9921008
993- BOOST_FOREACH ( ptree::value_type &cell, row.second )
994- _trainingSpec[i]._data .push_back (
995- cell.second .get_value <double >() );
1009+ for ( auto j: values )
1010+ {
1011+ double d = j;
1012+ _trainingSpec[i]._data .push_back ( d );
1013+ }
9961014
9971015 assert ( _trainingSpec[i]._data .size () == 190 );
9981016
@@ -1021,14 +1039,16 @@ void Idt::loadCMF( const string &path )
10211039
10221040 try
10231041 {
1024- ptree pt ;
1025- read_json ( path, pt );
1042+ std::ifstream stream ( path ) ;
1043+ nlohmann::json data = nlohmann::json::parse ( stream );
10261044
10271045 int i = 0 ;
1028- BOOST_FOREACH (
1029- ptree::value_type &row, pt.get_child ( " spectral_data.data.main" ) )
1046+
1047+ nlohmann::json main_data = data[" spectral_data" ][" data" ][" main" ];
1048+ for ( auto &[index, values]: main_data.items () )
10301049 {
1031- int wl = atoi ( ( row.first ).c_str () );
1050+ std::string row = index;
1051+ int wl = stoi ( row );
10321052
10331053 if ( wl < 380 || wl % 5 )
10341054 continue ;
@@ -1038,8 +1058,8 @@ void Idt::loadCMF( const string &path )
10381058 _cmf[i]._wl = wl;
10391059
10401060 vector<double > data;
1041- BOOST_FOREACH ( ptree::value_type &cell, row. second )
1042- data.push_back ( cell. second . get_value < double >() );
1061+ for ( auto j: values )
1062+ data.push_back ( ( double )j );
10431063
10441064 assert ( data.size () == 3 );
10451065 _cmf[i]._xbar = data[0 ];
0 commit comments