diff --git a/sources/core/args.h b/sources/core/args.h index bc88c60dc8cc031c374a6ae41beb887f204c3505..ac29a7092951b0f4572d46faa4e141e65bd80ed5 100644 --- a/sources/core/args.h +++ b/sources/core/args.h @@ -233,9 +233,13 @@ class arguments std::map::const_iterator it = _map.begin(); for(;it != _map.end(); it++) { - cmd.append(it->first); - cmd.append(" "); - cmd.append(it->second); + if(!it->first.empty()) + { + cmd.append(" --"); + cmd.append(it->first); + cmd.append(" "); + cmd.append(it->second); + } } return cmd; diff --git a/sources/core/function.cpp b/sources/core/function.cpp index 691d749b4595f97d99a1b07864c563d20561e812..cedb8be8892bb88e03990d29bd17b240f10f3d19 100644 --- a/sources/core/function.cpp +++ b/sources/core/function.cpp @@ -28,12 +28,12 @@ void function::save_header(std::ostream& out, const arguments& args) const { if(!args.is_defined("export")) { - out << "ALTA FUNC HEADER" << std::endl; + out << "#ALTA FUNC HEADER" << std::endl; 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 << "ALTA HEADER END" << std::endl; + out << "#ALTA HEADER END" << std::endl; out << std::endl; } } diff --git a/sources/core/function.h b/sources/core/function.h index cc9d0524500621c0ce3f3ab2d1df91673ed0e61c..1f2f35f67d1df925b2f47d06492e6d675fbfa025 100644 --- a/sources/core/function.h +++ b/sources/core/function.h @@ -101,6 +101,7 @@ class function : public parametrized //! \brief Linf norm to data. double Linf_distance(const data* d) const ; + protected: // data // Dimension of the function & domain of definition. @@ -157,13 +158,19 @@ class nonlinear_function: public function // Checking for the comment line #FUNC nonlinear_function_phong std::string token; in >> token; - if(token != "FUNC") { std::cerr << "<> parsing the stream. The #FUNC is not the next line defined." << std::endl; } + if(token.compare("#FUNC") != 0) + { + std::cerr << "<> parsing the stream. The #FUNC is not the next line defined." << std::endl; +#ifdef DEBUG + std::cout << "<> got: \"" << token << "\"" << std::endl; +#endif + } in >> token; - if(token != "nonlinear_function") + if(token.compare("nonlinear_function") != 0) { std::cerr << "<> parsing the stream. A function name is defined." << std::endl; - std::cerr << "<> did you forget to specify the plugin used to expor?" << std::endl; + std::cerr << "<> did you forget to specify the plugin used to export?" << std::endl; } int nb_params = nbParameters(); @@ -178,7 +185,7 @@ class nonlinear_function: public function //! \brief default non_linear export. It will dump the parameters in order //! but won't assign names for the function nor parameters. - virtual void save_call(std::ostream& out, arguments& args) const + virtual void save_call(std::ostream& out, const arguments& args) const { if(!args.is_defined("export")) { @@ -401,7 +408,7 @@ class compound_function: public nonlinear_function, public std::vector> token; - if(token != "FUNC") { std::cerr << "<> parsing the stream. The #FUNC is not the next line defined." << std::endl; } + if(token.compare("#FUNC") != 0) + { + std::cerr << "<> parsing the stream. The #FUNC is not the next line defined." << std::endl; + } in >> token; - if(token != "nonlinear_function_lafortune") { std::cerr << "<> parsing the stream. function name is not the next token." << std::endl; } + if(token.compare("nonlinear_function_lafortune") != 0) + { + std::cerr << "<> parsing the stream. function name is not the next token." << std::endl; + } // Shoudl have the #NB_LOBES [int] int nb_lobes; @@ -346,103 +351,21 @@ void isotropic_lafortune_function::load(std::istream& in) } -void isotropic_lafortune_function::save(const std::string& filename) const + +void isotropic_lafortune_function::save_call(std::ostream& out, const arguments& args) const { - std::ofstream file(filename.c_str(), std::ios_base::trunc); - file << "#DIM " << _nX << " " << _nY << std::endl ; - file << "#NB_LOBES " << _n << std::endl ; - - for(int i=0; i<_nY; ++i) - { - file << _kd[i] << std::endl; - } - file << std::endl; + out << "#FUNC nonlinear_function_lafortune" << std::endl ; + out << "#NB_LOBES " << _n << std::endl ; for(int n=0; n<_n; ++n) { - file << "#Lobe number " << n << std::endl; - file << "#Cxy Cz" << std::endl; for(int i=0; i<_nY; ++i) { - file << _C[(n*_nY + i)*2 + 0] << " " << _C[(n*_nY + i)*2 + 1] << std::endl; + out << "Cxy " << _C[(n*_nY + i)*2 + 0] << std::endl; + out << "Cz " << _C[(n*_nY + i)*2 + 1] << std::endl; + out << "N " << _N[n*_nY + i] << std::endl; } - file << std::endl; - - file << "#N" << std::endl; - for(int i=0; i<_nY; ++i) - { - file << _N[n*_nY + i] << std::endl; - } - file << std::endl; } + out << std::endl; } - -//! \brief Output the function using a BRDF Explorer formating. -//! \todo Finish -void isotropic_lafortune_function::save_brdfexplorer(const std::string& filename, - const arguments& args) const -{ - std::ofstream file(filename.c_str(), std::ios_base::trunc); - file << "analytic" << std::endl; - - file << std::endl; -// file << "::begin parameters" << std::endl; -// file << "::end parameters" << std::endl; -// file << std::endl; - file << std::endl; - file << "::begin shader" << std::endl; - - type_definition(file, _nY) << " n;" << std::endl; - type_definition(file, _nY) << " Cx;" << std::endl; - type_definition(file, _nY) << " Cy;" << std::endl; - type_definition(file, _nY) << " Cz;" << std::endl; - type_definition(file, _nY) << " "; - type_affectation(file, std::string("kd"), _kd, _nY); - - file << std::endl; - file << std::endl; - file << "vec3 BRDF( vec3 L, vec3 V, vec3 N, vec3 X, vec3 Y )" << std::endl; - file << "{" << std::endl; - if(_nY == 1) - { - file << " "; - type_definition(file, _nY) << " D = kd;" << std::endl << std::endl; - - for(int n=0; n<_n; ++n) - { - file << " // Lobe number " << n+1 << std::endl; - file << " n = " << _N[n] << "; " << std::endl; - file << " Cx = " << _C[2*n + 0] << "; " << std::endl; - file << " Cy = " << _C[2*n + 0] << "; " << std::endl; - file << " Cz = " << _C[2*n + 1] << "; " << std::endl; - file << " D += pow(max(Cx * L.x * V.x + Cy * L.y * V.y + Cz * L.z * V.z, "; - type_definition(file, _nY) << "(0.0)), n);" << std::endl; - file << std::endl; - } - } - else - { - file << " "; - type_definition(file, _nY) << " D = kd;" << std::endl << std::endl; - - for(int n=0; n<_n; ++n) - { - file << " // Lobe number " << n+1 << std::endl; - file << " "; type_affectation(file, std::string("n"), _N, _nY, n); - file << " "; type_affectation(file, std::string("Cx"), _C, _nY, n, 0, 2); - file << " "; type_affectation(file, std::string("Cy"), _C, _nY, n, 0, 2); - file << " "; type_affectation(file, std::string("Cz"), _C, _nY, n, 1, 2); - file << " D += pow(max(Cx * L.x * V.x + Cy * L.y * V.y + Cz * L.z * V.z, "; - type_definition(file, _nY) << "(0.0)), n);" << std::endl; - file << std::endl; - } - } - file << " return vec3(D);" << std::endl; -// file << " if (normalized)" << std::endl; -// file << " D *= (2+n) / (2*PI);" << std::endl; - file << "}" << std::endl; - file << std::endl; - file << "::end shader" << std::endl; - file.close(); -} diff --git a/sources/plugins/nonlinear_function_isotropic_lafortune/function.h b/sources/plugins/nonlinear_function_isotropic_lafortune/function.h index 96bb2857bcc079ad5b75e2d612129ca5ac6a9492..f68b2777fcd212659688ed6a8b48d8f1465c2d2a 100644 --- a/sources/plugins/nonlinear_function_isotropic_lafortune/function.h +++ b/sources/plugins/nonlinear_function_isotropic_lafortune/function.h @@ -46,6 +46,9 @@ class isotropic_lafortune_function : public nonlinear_function //! \brief Load function specific files virtual void load(std::istream& in) ; + //! \brief Export function + virtual void save_call(std::ostream& out, const arguments& args) const; + //! \brief Boostrap the function by defining the diffuse term //! //! \details @@ -76,15 +79,6 @@ class isotropic_lafortune_function : public nonlinear_function //! \brief Set the number of lobes to be used in the fit void setNbLobes(int N); - protected: // methods - - virtual void save(const std::string& filename) const; - - - //! \brief Output the function using a BRDF Explorer formating. - virtual void save_brdfexplorer(const std::string& filename, - const arguments& args) const; - private: // methods //! \brief Provide the coefficient of the monochromatic lobe number