Skip to content

Commit b36f004

Browse files
committed
replace boost::json with nlohmann_json
Signed-off-by: Anton Dukhovnikov <[email protected]>
1 parent 29a7f59 commit b36f004

File tree

9 files changed

+67
-54
lines changed

9 files changed

+67
-54
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
shell: bash
5656
run: |
5757
build_scripts/install_aces_container.bash
58-
sudo yum install --setopt=tsflags=nodocs -y eigen3-devel ceres-solver-devel LibRaw-devel
58+
sudo yum install --setopt=tsflags=nodocs -y eigen3-devel ceres-solver-devel LibRaw-devel json-devel
5959
6060
- name: Configure CMake
6161
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.

build_scripts/install_deps.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ time sudo apt-get -q -f install -y \
1111
libopenimageio-dev \
1212
libboost-dev libboost-thread-dev libboost-filesystem-dev \
1313
libboost-test-dev \
14-
libraw-dev libceres-dev
14+
libraw-dev libceres-dev nlohmann-json-dev

build_scripts/install_deps_linux.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ time sudo apt-get -q -f install -y \
1212
libraw-dev libceres-dev \
1313
libopencv-dev \
1414
openimageio-tools \
15-
libopenimageio-dev
15+
libopenimageio-dev \
16+
nlohmann-json3-dev

build_scripts/install_deps_mac.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
set -ex
44

5-
brew install ceres-solver imath openexr libraw boost openimageio
5+
brew install ceres-solver imath openexr libraw boost openimageio nlohmann-json

build_scripts/install_deps_windows.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ vcpkg install \
1111
boost-foreach:x64-windows \
1212
boost-filesystem:x64-windows \
1313
boost-test:x64-windows \
14-
boost-property-tree:x64-windows
14+
boost-property-tree:x64-windows \
15+
nlohmann-json:x64-windows

configure.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ find_package ( OpenImageIO CONFIG REQUIRED )
77
find_package ( AcesContainer CONFIG REQUIRED )
88
find_package ( Eigen3 CONFIG REQUIRED )
99
find_package ( Imath CONFIG REQUIRED )
10+
find_package ( nlohmann_json CONFIG REQUIRED )
1011
find_package ( Ceres REQUIRED )
1112
find_package ( Boost REQUIRED
1213
COMPONENTS

include/rawtoaces/define.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,13 @@ inline vector<string> openDir( string path = "." )
359359
{
360360
vector<string> paths;
361361

362-
for ( auto &i: filesystem::directory_iterator( path ) )
362+
if ( filesystem::exists( path ) )
363363
{
364-
if ( i.status().type() != filesystem::file_type::directory )
365-
paths.push_back( i.path().string() );
364+
for ( auto &i: filesystem::directory_iterator( path ) )
365+
{
366+
if ( i.status().type() != filesystem::file_type::directory )
367+
paths.push_back( i.path().string() );
368+
}
366369
}
367370

368371
return paths;

src/rawtoaces_idt/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ target_link_libraries(
2121
PRIVATE
2222
Boost::boost
2323
Boost::system
24-
Imath::Imath
25-
Imath::ImathConfig
24+
nlohmann_json::nlohmann_json
2625
)
2726

2827
# Ceres is also used in rawtoaces_util and rawtoaces_util2, so setting it public here

src/rawtoaces_idt/rta.cpp

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,14 @@
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;
6361
using namespace ceres;
6462

6563
namespace rta
6664
{
65+
6766
Illum::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,31 @@ 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() ||
605+
strcasecmp( camera_make.c_str(), maker ) != 0 )
607606
return 0;
608-
setBrand( cmaker.c_str() );
609607

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 )
612613
return 0;
613-
setModel( cmodel.c_str() );
614+
615+
setModel( camera_model.c_str() );
614616

615617
vector<int> wavs;
616618
int inc;
617619

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() )
620622
{
621-
wavs.push_back( atoi( ( row.first ).c_str() ) );
623+
std::string row = index;
624+
wavs.push_back( stoi( row ) );
622625

623626
if ( wavs.size() == 2 )
624627
inc = wavs[1] - wavs[0];
@@ -640,8 +643,8 @@ int Spst::loadSpst( const string &path, const char *maker, const char *model )
640643
break;
641644

642645
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 );
645648

646649
// ensure there are three components
647650
assert( data.size() == 3 );
@@ -980,19 +983,22 @@ void Idt::loadTrainingData( const string &path )
980983

981984
try
982985
{
983-
ptree pt;
984-
read_json( path, pt );
986+
std::ifstream stream( path );
987+
nlohmann::json data = nlohmann::json::parse( stream );
985988

986989
int i = 0;
987990

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() )
990993
{
991-
_trainingSpec[i]._wl = atoi( ( row.first ).c_str() );
994+
std::string row = index;
995+
_trainingSpec[i]._wl = stoi( row );
992996

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+
}
9961002

9971003
assert( _trainingSpec[i]._data.size() == 190 );
9981004

@@ -1021,14 +1027,16 @@ void Idt::loadCMF( const string &path )
10211027

10221028
try
10231029
{
1024-
ptree pt;
1025-
read_json( path, pt );
1030+
std::ifstream stream( path );
1031+
nlohmann::json data = nlohmann::json::parse( stream );
10261032

10271033
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() )
10301037
{
1031-
int wl = atoi( ( row.first ).c_str() );
1038+
std::string row = index;
1039+
int wl = stoi( row );
10321040

10331041
if ( wl < 380 || wl % 5 )
10341042
continue;
@@ -1038,8 +1046,8 @@ void Idt::loadCMF( const string &path )
10381046
_cmf[i]._wl = wl;
10391047

10401048
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 );
10431051

10441052
assert( data.size() == 3 );
10451053
_cmf[i]._xbar = data[0];

0 commit comments

Comments
 (0)