Commit 8b622db3 authored by Laurent Belcour's avatar Laurent Belcour

Import and export working for simple functions

parent abc950b7
......@@ -233,9 +233,13 @@ class arguments
std::map<std::string, std::string>::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;
......
......@@ -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;
}
}
......
......@@ -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 << "<<ERROR>> parsing the stream. The #FUNC is not the next line defined." << std::endl; }
if(token.compare("#FUNC") != 0)
{
std::cerr << "<<ERROR>> parsing the stream. The #FUNC is not the next line defined." << std::endl;
#ifdef DEBUG
std::cout << "<<DEBUG>> got: \"" << token << "\"" << std::endl;
#endif
}
in >> token;
if(token != "nonlinear_function")
if(token.compare("nonlinear_function") != 0)
{
std::cerr << "<<ERROR>> parsing the stream. A function name is defined." << std::endl;
std::cerr << "<<ERROR>> did you forget to specify the plugin used to expor?" << std::endl;
std::cerr << "<<ERROR>> 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<nonlinear
//! \brief save object specific information. For an ALTA export the
//! coefficients will be exported. For a C++ or matlab export, the call
//! to the associated function will be done.
virtual void save_call(std::ostream& out, arguments& args) const
virtual void save_call(std::ostream& out, const arguments& args) const
{
bool is_cpp = args["export"] == "C++";
bool is_shader = args["export"] == "shader";
......
......@@ -304,7 +304,6 @@ std::ofstream& type_affectation(std::ofstream& out, const std::string& name, con
return out;
}
//! Load function specific files
void isotropic_lafortune_function::load(std::istream& in)
{
......@@ -318,10 +317,16 @@ void isotropic_lafortune_function::load(std::istream& in)
// Checking for the comment line #FUNC nonlinear_function_lafortune
std::string token;
in >> token;
if(token != "FUNC") { std::cerr << "<<ERROR>> parsing the stream. The #FUNC is not the next line defined." << std::endl; }
if(token.compare("#FUNC") != 0)
{
std::cerr << "<<ERROR>> parsing the stream. The #FUNC is not the next line defined." << std::endl;
}
in >> token;
if(token != "nonlinear_function_lafortune") { std::cerr << "<<ERROR>> parsing the stream. function name is not the next token." << std::endl; }
if(token.compare("nonlinear_function_lafortune") != 0)
{
std::cerr << "<<ERROR>> 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();
}
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment