diff --git a/sources/core/args.h b/sources/core/args.h index cf593241da5e4867dbe7d99f6c0c35de89f30717..88444d5d62cb12627eead2c9a8fe4cc3d6406f79 100644 --- a/sources/core/args.h +++ b/sources/core/args.h @@ -130,6 +130,11 @@ class arguments //std::cerr << "Underfined request to key : \"" << key << "\"" << std::endl ; return std::string() ; } + } + //! \brief update the value \a val stored under key \a key + bool update(const std::string& key, const std::string& val) + { + _map[key] = val; } //! \brief acces to the string value associated with the parameter //! \a key. diff --git a/sources/core/function.cpp b/sources/core/function.cpp index 2215f5092949885dff1816086ac2442e3fa60aa9..e343ba7ea1dec3a2b9de5e79a7eb17adb9083fec 100644 --- a/sources/core/function.cpp +++ b/sources/core/function.cpp @@ -85,7 +85,10 @@ void function::save_header(std::ostream& out, const arguments& args) const out << "#CMD " << args.get_cmd() << std::endl; out << "#DIM " << _nX << " " << _nY << std::endl; out << "#PARAM_IN " << params::get_name(input_parametrization()) << std::endl; - //out << "#PARAM_OUT " << params::get_name(output_parametrization()) << std::endl; + //out << "#PARAM_OUT " << params::get_name(output_parametrization()) << std::endl;* + if(args.is_defined("export-append")) { + out << args["export-append"] << std::endl; + } out << "#ALTA HEADER END" << std::endl; out << std::endl; } diff --git a/sources/softs/data2brdf/main.cpp b/sources/softs/data2brdf/main.cpp index e6427f535d02f77dec6d8bd4398c8791d78707d1..5e14bd10b7a7762e083d3bc140fcdfe1a393748a 100644 --- a/sources/softs/data2brdf/main.cpp +++ b/sources/softs/data2brdf/main.cpp @@ -20,167 +20,95 @@ int main(int argc, char** argv) { QCoreApplication app(argc, argv); - arguments args(argc, argv) ; - - plugins_manager manager(args) ; - fitter* fit = manager.get_fitter(args["fitter"]) ; - if(fit == NULL) - { - fit = manager.get_fitter() ; - } - - if(args.is_defined("available_params")) - { - params::print_input_params(); - return 0; - } - - if(! args.is_defined("input")) { - std::cerr << "<> the input filename is not defined" << std::endl ; - return 1 ; - } - if(! args.is_defined("output")) { - std::cerr << "<> the output filename is not defined" << std::endl ; - return 1 ; - } - - // if(fitters.size() > 0 && datas.size() > 0 && functions.size() > 0) - if(fit != NULL) - { - fit->set_parameters(args) ; - - function* f = plugins_manager::get_function(args); - data* d = plugins_manager::get_data(args["data"]); - d->load(args["input"], args); - - if(f == NULL || d == NULL) - { - std::cerr << "<> no function or data object correctly defined" << std::endl; - return 1; - } - - // Check the compatibility between the data and the function - plugins_manager::check_compatibility(d, f, args); - - - // Start a timer - QTime time ; - time.start() ; - - // Fit the data - bool is_fitted = fit->fit_data(d, f, args) ; - - // Get the fitting duration - int msec = time.elapsed() ; - int sec = (msec / 1000) % 60 ; - int min = (msec / 60000) % 60 ; - int hour = (msec / 3600000) ; - - - // Display the result - if(is_fitted) - { - std::cout << "<> total time: " << hour << "h " << min << "m " << sec << "s" << std::endl ; - /* - vec min, max ; - min.assign(2, args.get_float("min", 0.0f)) ; - max.assign(2, args.get_float("max", 1.5f)) ; - - int nb_samples = args.get_int("nb_samples", 100) ; - double dt = (max[0]-min[0]) / nb_samples ; - - std::ofstream file(args["output"].c_str(), std::ios_base::trunc); - for(double x=min[0]; x<=max[0]; x+=dt) - { - vec vx ; for(int i=0;i<2; ++i) { vx.push_back(x) ; } - file << x << "\t" << f->value(vx)[0] << std::endl ; - std::cout << x << "\t" << f->value(vx)[0] << std::endl ; - } - /*/ - double L2 = f->L2_distance(d); - double Linf = f->Linf_distance(d); - std::cout << "<> L2 distance to data = " << L2 << std::endl; - std::cout << "<> Linf distance to data = " << Linf << std::endl; - - f->save(args["output"], args) ; -#ifdef OLD // use brdf2gnuplot - size_t n = args["output"].find('.') ; - std::string gnuplot_filename = args["output"].substr(0,n); - gnuplot_filename.append(".gnuplot") ; - /* - f->save_gnuplot(gnuplot_filename, d, args); - /*/ - std::ofstream file(gnuplot_filename.c_str(), std::ios_base::trunc); - for(int i=0; isize(); ++i) - { - vec v = d->get(i) ; - // vec y1(d->dimY()) ; - // for(int k=0; kdimY(); ++k) { y1[k] = v[d->dimX() + k] ; } - - vec y2 = f->value(v) ; - for(int u=0; udimX(); ++u) - file << v[u] << "\t" ; - - for(int u=0; udimY(); ++u) - file << y2[u] << "\t" ; - - file << std::endl ; - } - file.close(); - //*/ - std::string error_filename = args["output"].substr(0,n); - error_filename.append(".errorplot") ; - file.open(error_filename.c_str(), std::ios_base::trunc); - for(int i=0; isize(); ++i) - { - vec v = d->get(i) ; - vec y1(d->dimY()) ; - for(int k=0; kdimY(); ++k) { y1[k] = v[d->dimX() + k] ; } - - vec y2 = f->value(v) ; - for(int u=0; udimX(); ++u) - file << v[u] << "\t" ; - - for(int u=0; udimY(); ++u) - file << y2[u]-y1[u] << "\t" ; - - file << std::endl ; - } - file.close(); - - std::string linerror_filename = args["output"].substr(0,n); - linerror_filename.append(".linearerrorplot") ; - file.open(linerror_filename.c_str(), std::ios_base::trunc); - for(int i=0; isize(); ++i) - { - vec v = d->get(i) ; - - vec y1(d->dimY()) ; - for(int k=0; kdimY(); ++k) { y1[k] = 0.5*(v[d->dimX() + k] +v[d->dimX()+d->dimY() + k]); } - vec y2 = f->value(v) ; - - file << i << "\t" ; - for(int u=0; udimY(); ++u) - file << y2[u]-y1[u] << "\t" ; - - file << std::endl ; - } - file.close(); - //*/ -#endif - return 0; - } - else - { - std::cout << "<> unable to fit the data" << std::endl ; - return 1; - } - - } - else - { - std::cout << "<> no fitter loaded, please check your command line arguments" << std::endl ; - } - - return 0 ; + arguments args(argc, argv) ; + + plugins_manager manager(args) ; + fitter* fit = manager.get_fitter(args["fitter"]) ; + if(fit == NULL) + { + fit = manager.get_fitter() ; + } + + if(args.is_defined("available_params")) + { + params::print_input_params(); + return 0; + } + + if(! args.is_defined("input")) { + std::cerr << "<> the input filename is not defined" << std::endl ; + return 1 ; + } + if(! args.is_defined("output")) { + std::cerr << "<> the output filename is not defined" << std::endl ; + return 1 ; + } + + // if(fitters.size() > 0 && datas.size() > 0 && functions.size() > 0) + if(fit != NULL) + { + fit->set_parameters(args) ; + + function* f = plugins_manager::get_function(args); + data* d = plugins_manager::get_data(args["data"]); + d->load(args["input"], args); + + if(f == NULL || d == NULL) + { + std::cerr << "<> no function or data object correctly defined" << std::endl; + return 1; + } + + // Check the compatibility between the data and the function + plugins_manager::check_compatibility(d, f, args); + + + // Start a timer + QTime time ; + time.start() ; + + // Fit the data + bool is_fitted = fit->fit_data(d, f, args) ; + + // Get the fitting duration + int msec = time.elapsed() ; + int sec = (msec / 1000) % 60 ; + int min = (msec / 60000) % 60 ; + int hour = (msec / 3600000) ; + + + // Display the result + if(is_fitted) + { + std::cout << "<> total time: " << hour << "h " << min << "m " << sec << "s" << std::endl ; + + double L2 = f->L2_distance(d); + double Linf = f->Linf_distance(d); + std::cout << "<> L2 distance to data = " << L2 << std::endl; + std::cout << "<> Linf distance to data = " << Linf << std::endl; + + std::stringstream append; // Append informations to the export + if(args.is_defined("export-append")) { + append << args["export-append"]; + } + append << "#L2 " << L2 << std::endl; + append << "#LINF " << Linf ; + args.update("export-append", append.str()); + + f->save(args["output"], args) ; + return 0; + } + else + { + std::cout << "<> unable to fit the data" << std::endl ; + return 1; + } + + } + else + { + std::cout << "<> no fitter loaded, please check your command line arguments" << std::endl ; + } + + return 0 ; }