Commit 3c8186c0 authored by Laurent Belcour's avatar Laurent Belcour

Loading/Saving Fresnel function

parent f029428e
......@@ -233,6 +233,8 @@ vec normalize(const vec& a);
double dot(const vec& a, const vec& b);
vec product(const vec& a, const vec& b);
//! \brief locate the first index of value v in vector vec. Complexity in
//! O(n) is the worst case.
template<typename T> int is_in(std::vector<T> ve, T v)
......
......@@ -469,7 +469,9 @@ class fresnel : public nonlinear_function
virtual vec value(const vec& x) const
{
vec fres = fresnelValue(x);
return fres * f->value(x);
vec func = f->value(x);
return product(fres, func);
}
//! Load function specific files
......@@ -492,12 +494,6 @@ class fresnel : public nonlinear_function
f->bootstrap(d, args);
}
//! Save the Fresnel part along with the function
virtual void save(const std::string& filename, const arguments& args) const
{
f->save(filename, args);
}
//! Set the dimension of the input space of the function
virtual void setDimX(int nX)
{
......@@ -545,9 +541,9 @@ class fresnel : public nonlinear_function
}
vec fres_params = getFresnelParameters();
for(int i=nb_func_params; i<nb_params; ++i)
for(int i=0; i<nb_fres_params; ++i)
{
params[i] = fres_params[i-nb_func_params];
params[i+nb_func_params] = fres_params[i];
}
return params;
......@@ -600,7 +596,7 @@ class fresnel : public nonlinear_function
for(int i=0; i<nb_fres_params; ++i)
{
jac[y + _nY*(i+nb_func_params)] = fres_jacobian[y + _nY*i] * fres_value[y];
jac[y + _nY*(i+nb_func_params)] = fres_jacobian[y + _nY*i] * func_value[y];
}
}
......
......@@ -17,6 +17,8 @@ ALTA_DLL_EXPORT function* provide_function()
//! Load function specific files
void schlick::load(std::istream& in)
{
fresnel::load(in);
// Parse line until the next comment
while(in.peek() != '#')
{
......@@ -27,7 +29,7 @@ void schlick::load(std::istream& in)
// Checking for the comment line #FUNC nonlinear_fresnel_schlick
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 != "#FUNC") { std::cerr << "<<ERROR>> parsing the stream. The #FUNC is not the next line defined." << std::endl; }
in >> token;
if(token != "nonlinear_fresnel_schlick") { std::cerr << "<<ERROR>> parsing the stream. function name is not the next token." << std::endl; }
......@@ -35,6 +37,15 @@ void schlick::load(std::istream& in)
// R [double]
in >> token >> R;
}
void schlick::save_call(std::ostream& out, const arguments& args) const
{
f->save_call(out, args);
out << "#FUNC nonlinear_fresnel_schlick" << std::endl ;
out << "R " << R << std::endl;
out << std::endl;
}
vec schlick::fresnelValue(const vec& x) const
{
......
......@@ -18,8 +18,9 @@ class schlick : public fresnel
public: // methods
//! \brief Load function specific files
virtual void load(std::istream& in) ;
virtual void load(std::istream& in) ;
virtual void save_call(std::ostream& out, const arguments& args) const;
protected: // methods
......
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