47#include "../include/Config.h"
48#include "../include/JsonParser.h"
58 bool g_verbose =
false;
62 float const defaultPrecision = 1.f;
63 ColorSpace
const defaultColorSpace = ColorSpace::RGB;
65 float g_rescale = defaultPrecision;
66 ColorSpace g_color_space = defaultColorSpace;
69 bool g_with_opengl =
true;
76 std::string path = filename;
78 path = dir +
'/' + filename;
80 std::ifstream stream(path);
83 std::ostringstream what;
84 what <<
"Failed to open configuration file \"" << dir +
'/' + filename <<
"\" for reading: \n" << strerror(errno);
85 throw std::runtime_error(what.str());
87 auto root = json::Node::readFrom(stream);
93 config.setVersionFrom(root);
94 config.setInputCameraNamesFrom(root);
95 config.setVirtualCameraNamesFrom(root);
96 config.setInputCameraParameters(root);
97 config.setVirtualCameraParameters(root);
98 config.setInputFilepaths(root,
"ViewImageNames", config.
texture_names);
99 config.setInputFilepaths(root,
"DepthMapNames", config.
depth_names);
100 config.setOutputFilepaths(root,
"OutputFiles", config.
outfilenames);
105 config.setValidityThreshold(root);
106 config.setSynthesisMethod(root);
107 config.setBlendingMethod(root);
108 config.setBlendingFactor(root);
109 config.setBlendingLowFreqFactor(root);
110 config.setBlendingHighFreqFactor(root);
111 config.setStartFrame(root);
112 config.setNumberOfFrames(root);
117 auto node = root.optional(
"VirtualPoseTraceName");
119 auto filepath = node.asString();
121 std::cout <<
"VirtualPoseTraceName: " << filepath <<
'\n';
125 config.setOverrideVirtualViewSetting(root);
130 void Config::setOverrideVirtualViewSetting(
json::Node root)
132 auto node = root.
optional(
"OverrideVirtualSetting");
133 if (node.type() == json::Node::Type::boolean) {
138 std::vector<Parameters> Config::loadCamerasParametersFromFile(std::string
const& file, std::vector<std::string> names,
json::Node overrides)
140 std::string
const& filepath = this->
directory +
'/'+ file;
142 std::ifstream stream(filepath);
143 if (!stream.good()) {
144 std::ostringstream what;
145 what <<
"Failed to open camera parameters file \"" << filepath <<
"\" for reading \n" << strerror(errno) ;
146 throw std::runtime_error(what.str());
150 if (version_.substr(0, 2) !=
"2." &&
151 version_.substr(0, 2) !=
"3.") {
152 throw std::runtime_error(
"Version of the camera parameters file is not compatible with this version of RVS");
156 std::map<std::string, Parameters> index;
157 auto cameras = root.
require(
"cameras");
158 for (
auto i = 0u; i != cameras.size(); ++i) {
159 auto node = cameras.
at(i);
161 if (index.count(name)) {
162 std::ostringstream what;
163 what <<
"Camera parameters file has duplicate camera '" << name <<
"'";
164 throw std::runtime_error(what.str());
167 node.setOverrides(overrides);
173 std::vector<Parameters> parameters;
174 for (
auto name : names) {
178 std::cout <<
" * " << name <<
": ";
179 index.at(name).printTo(std::cout);
182 parameters.push_back(index.at(name));
184 catch (std::out_of_range&) {
185 std::ostringstream what;
186 what <<
"Camera parameters file does not have camera '" << name <<
"'";
187 throw std::runtime_error(what.str());
209 if (
version.substr(0, 2) !=
"2." &&
210 version.substr(0, 2) !=
"3.") {
211 throw std::runtime_error(
"Configuration file does not match the RVS version");
214 std::cout <<
"Version: " <<
version <<
'\n';
217 void Config::setInputCameraNamesFrom(
json::Node root)
219 auto node = root.
require(
"InputCameraNames");
220 for (
auto i = 0u; i != node.size(); ++i) {
225 std::cout <<
"InputCameraNames:";
227 std::cout <<
' ' << x;
233 void Config::setVirtualCameraNamesFrom(
json::Node root)
235 auto node = root.
require(
"VirtualCameraNames");
236 for (
auto i = 0u; i != node.size(); ++i) {
241 std::cout <<
"VirtualCameraNames:";
243 std::cout <<
' ' << x;
249 void Config::setInputCameraParameters(
json::Node root)
253 std::cout <<
"InputCameraParameterFile: " << filepath <<
'\n';
254 auto overrides = root.
optional(
"InputOverrides");
257 std::cout <<
"InputOverrides: " << overrides.
size() <<
" keys\n";
262 void Config::setVirtualCameraParameters(
json::Node root)
266 std::cout <<
"VirtualCameraParameterFile: " << filepath <<
'\n';
267 auto overrides = root.
optional(
"VirtualOverrides");
270 std::cout <<
"VirtualOverrides: " << overrides.
size() <<
" keys\n";
275 void Config::setInputFilepaths(
json::Node root,
char const *name, std::vector<std::string>& filepaths)
277 auto node = root.
require(name);
279 std::ostringstream what;
280 what <<
"Length of " << name <<
" should match with InputCameraNames";
281 throw std::runtime_error(what.str());
283 for (
auto i = 0u; i != node.size(); ++i) {
284 filepaths.push_back(node.at(i).asString());
288 std::cout << name <<
':';
289 for (
auto x : filepaths) {
290 std::cout <<
"\n * " << x;
296 void Config::setOutputFilepaths(
json::Node root,
char const *name, std::vector<std::string>& filepaths)
301 std::ostringstream what;
302 what <<
"Length of " << name <<
" should match with VirtualCameraNames";
303 throw std::runtime_error(what.str());
305 for (
auto i = 0u; i != node.size(); ++i) {
306 filepaths.push_back(node.at(i).asString());
310 std::cout << name <<
':';
311 for (
auto x : filepaths) {
312 std::cout <<
"\n * " << x;
319 void Config::setValidityThreshold(
json::Node root)
321 auto node = root.
optional(
"ValidityThreshold");
329 void Config::setSynthesisMethod(
json::Node root)
331 auto node = root.
optional(
"ViewSynthesisMethod");
337 void Config::setBlendingMethod(
json::Node root)
339 auto node = root.
optional(
"BlendingMethod");
347 void Config::setBlendingFactor(
json::Node root)
349 auto node = root.
optional(
"BlendingFactor");
357 void Config::setBlendingLowFreqFactor(
json::Node root)
366 void Config::setBlendingHighFreqFactor(
json::Node root)
377 auto node = root.
optional(
"StartFrame");
381 std::cout <<
"StartFrame: " <<
start_frame <<
'\n';
385 void Config::setNumberOfFrames(
json::Node root)
387 auto node = root.
optional(
"NumberOfFrames");
397 auto node = root.
optional(
"Precision");
399 detail::g_rescale =
static_cast<float>(node.asDouble());
401 std::cout <<
"Precision: " << detail::g_rescale <<
'\n';
404 detail::g_rescale = detail::defaultPrecision;
410 auto node = root.
optional(
"ColorSpace");
412 if (node.asString() ==
"YUV") {
413 detail::g_color_space = detail::ColorSpace::YUV;
415 std::cout <<
"ColorSpace: YUV\n";
417 else if (node.asString() ==
"RGB") {
418 detail::g_color_space = detail::ColorSpace::RGB;
420 std::cout <<
"ColorSpace: RGB\n";
423 throw std::runtime_error(
"Unknown color space");
427 detail::g_color_space = detail::defaultColorSpace;
Node optional(std::string const &key) const
std::string const & asString() const
Node require(std::string const &key) const
Node at(std::size_t index) const
static Node readFrom(std::istream &)
Configuration parameters.
float blending_low_freq_factor
std::vector< std::string > outdepthfilenames
static Config loadFromFile(std::string const &filename, std::string const &dir)
std::vector< Parameters > params_real
std::vector< std::string > outfilenames
float blending_high_freq_factor
std::vector< std::string > outmaskedfilenames
std::vector< std::string > outmaskdepthfilenames
std::vector< std::string > outmaskfilenames
bool overrideVirtualViewSetting
std::vector< std::string > VirtualCameraNames
std::vector< std::string > InputCameraNames
std::vector< std::string > depth_names
std::vector< std::string > texture_names
std::vector< Parameters > params_virtual
std::string blending_method
static Parameters readFrom(json::Node parameters)