55
55
#include < rawtoaces/rta.h>
56
56
#include < rawtoaces/mathOps.h>
57
57
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>
61
60
62
- using namespace boost ::property_tree;
63
61
using namespace ceres ;
64
62
65
63
namespace rta
66
64
{
65
+
67
66
Illum::Illum ()
68
67
{
69
68
_inc = 5 ;
@@ -146,23 +145,22 @@ int Illum::readSPD( const string &path, const string &type )
146
145
147
146
try
148
147
{
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" )
155
152
return 0 ;
156
153
157
154
_type = stype;
158
155
159
156
vector<int > wavs;
160
157
int dis;
161
158
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 ( ) )
164
161
{
165
- wavs.push_back ( atoi ( ( row.first ).c_str () ) );
162
+ std::string row = index ;
163
+ wavs.push_back ( stoi ( row ) );
166
164
167
165
if ( wavs.size () == 2 )
168
166
dis = wavs[1 ] - wavs[0 ];
@@ -183,11 +181,11 @@ int Illum::readSPD( const string &path, const string &type )
183
181
else if ( wavs[wavs.size () - 1 ] > 780 )
184
182
break ;
185
183
186
- BOOST_FOREACH ( ptree::value_type &cell, row. second )
184
+ for ( auto j: values )
187
185
{
188
- _data.push_back ( cell. second . get_value < double >() );
186
+ _data.push_back ( ( double )j );
189
187
if ( wavs[wavs.size () - 1 ] == 550 )
190
- _index = cell. second . get_value < double >() ;
188
+ _index = ( double )j ;
191
189
}
192
190
193
191
// printf ( "\"%i\": [ %18.13f ], \n",
@@ -599,26 +597,31 @@ int Spst::loadSpst( const string &path, const char *maker, const char *model )
599
597
600
598
try
601
599
{
602
- ptree pt ;
603
- read_json ( path, pt );
600
+ std::ifstream i ( path ) ;
601
+ nlohmann::json data = nlohmann::json::parse ( i );
604
602
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 () ||
605
+ strcasecmp ( camera_make.c_str (), maker ) != 0 )
607
606
return 0 ;
608
- setBrand ( cmaker.c_str () );
609
607
610
- string cmodel = pt.get <string>( " header.model" );
611
- if ( model != nullptr && cmp_str ( model, cmodel.c_str () ) )
608
+ setBrand ( camera_make.c_str () );
609
+
610
+ const string camera_model = data[" header" ][" model" ];
611
+ if ( camera_model.empty () ||
612
+ strcasecmp ( camera_model.c_str (), model ) != 0 )
612
613
return 0 ;
613
- setModel ( cmodel.c_str () );
614
+
615
+ setModel ( camera_model.c_str () );
614
616
615
617
vector<int > wavs;
616
618
int inc;
617
619
618
- BOOST_FOREACH (
619
- ptree::value_type &row, pt. get_child ( " spectral_data.data.main " ) )
620
+ nlohmann::json main_data = data[ " spectral_data " ][ " data " ][ " main " ];
621
+ for ( auto &[ index , values]: main_data. items ( ) )
620
622
{
621
- wavs.push_back ( atoi ( ( row.first ).c_str () ) );
623
+ std::string row = index ;
624
+ wavs.push_back ( stoi ( row ) );
622
625
623
626
if ( wavs.size () == 2 )
624
627
inc = wavs[1 ] - wavs[0 ];
@@ -640,8 +643,8 @@ int Spst::loadSpst( const string &path, const char *maker, const char *model )
640
643
break ;
641
644
642
645
vector<double > data;
643
- BOOST_FOREACH ( ptree::value_type &cell, row. second )
644
- data.push_back ( cell. second . get_value < double >() );
646
+ for ( auto j: values )
647
+ data.push_back ( ( double )j );
645
648
646
649
// ensure there are three components
647
650
assert ( data.size () == 3 );
@@ -980,19 +983,22 @@ void Idt::loadTrainingData( const string &path )
980
983
981
984
try
982
985
{
983
- ptree pt ;
984
- read_json ( path, pt );
986
+ std::ifstream stream ( path ) ;
987
+ nlohmann::json data = nlohmann::json::parse ( stream );
985
988
986
989
int i = 0 ;
987
990
988
- BOOST_FOREACH (
989
- ptree::value_type &row, pt. get_child ( " spectral_data.data.main " ) )
991
+ nlohmann::json main_data = data[ " spectral_data " ][ " data " ][ " main " ];
992
+ for ( auto &[ index , values]: main_data. items ( ) )
990
993
{
991
- _trainingSpec[i]._wl = atoi ( ( row.first ).c_str () );
994
+ std::string row = index ;
995
+ _trainingSpec[i]._wl = stoi ( row );
992
996
993
- BOOST_FOREACH ( ptree::value_type &cell, row.second )
994
- _trainingSpec[i]._data .push_back (
995
- cell.second .get_value <double >() );
997
+ for ( auto j: values )
998
+ {
999
+ double d = j;
1000
+ _trainingSpec[i]._data .push_back ( d );
1001
+ }
996
1002
997
1003
assert ( _trainingSpec[i]._data .size () == 190 );
998
1004
@@ -1021,14 +1027,16 @@ void Idt::loadCMF( const string &path )
1021
1027
1022
1028
try
1023
1029
{
1024
- ptree pt ;
1025
- read_json ( path, pt );
1030
+ std::ifstream stream ( path ) ;
1031
+ nlohmann::json data = nlohmann::json::parse ( stream );
1026
1032
1027
1033
int i = 0 ;
1028
- BOOST_FOREACH (
1029
- ptree::value_type &row, pt.get_child ( " spectral_data.data.main" ) )
1034
+
1035
+ nlohmann::json main_data = data[" spectral_data" ][" data" ][" main" ];
1036
+ for ( auto &[index , values]: main_data.items () )
1030
1037
{
1031
- int wl = atoi ( ( row.first ).c_str () );
1038
+ std::string row = index ;
1039
+ int wl = stoi ( row );
1032
1040
1033
1041
if ( wl < 380 || wl % 5 )
1034
1042
continue ;
@@ -1038,8 +1046,8 @@ void Idt::loadCMF( const string &path )
1038
1046
_cmf[i]._wl = wl;
1039
1047
1040
1048
vector<double > data;
1041
- BOOST_FOREACH ( ptree::value_type &cell, row. second )
1042
- data.push_back ( cell. second . get_value < double >() );
1049
+ for ( auto j: values )
1050
+ data.push_back ( ( double )j );
1043
1051
1044
1052
assert ( data.size () == 3 );
1045
1053
_cmf[i]._xbar = data[0 ];
0 commit comments