Mise à jour terminée. Pour connaître les apports de la version 13.8.4 par rapport à notre ancienne version vous pouvez lire les "Release Notes" suivantes :
https://about.gitlab.com/releases/2021/02/11/security-release-gitlab-13-8-4-released/
https://about.gitlab.com/releases/2021/02/05/gitlab-13-8-3-released/

Commit efd1b303 authored by Laurent Belcour's avatar Laurent Belcour

Adding a boostrap function to set non fitted parameters such

as diffuse lobe for example.
parent 8bec7b5b
......@@ -12,10 +12,10 @@ HEADERS = args.h \
plugins_manager.h \
vertical_segment.h \
rational_function.h \
params.h \
clustering.h
params.h \
clustering.h
SOURCES = plugins_manager.cpp \
vertical_segment.cpp \
SOURCES = plugins_manager.cpp \
vertical_segment.cpp \
rational_function.cpp \
#clustering.cpp
#clustering.cpp
......@@ -26,9 +26,9 @@ class function
{
public: // methods
// Constructor
function() : _in_param(params::UNKNOWN_INPUT),
_out_param(params::UNKNOWN_OUTPUT) { }
// Constructor
function() : _in_param(params::UNKNOWN_INPUT),
_out_param(params::UNKNOWN_OUTPUT) { }
// Overload the function operator
virtual vec operator()(const vec& x) const = 0 ;
......@@ -37,13 +37,20 @@ class function
//! Load function specific files
virtual void load(const std::string& filename) = 0 ;
//! \brief Provide a first rough fit of the function.
//!
//! \details
//! Can be used to set the diffuse component of the function for
//! example.
virtual void boostrap(const data* d, const arguments& args) {}
//! \brief Save the current function to a specific file type, args can
//! be used to differenciate the type of export.
//!
//! \see rational_function.cpp for an example
virtual void save(const std::string& filename, const arguments& args) const
{
std::cout << "<<DEBUG>> Exporting the function" << std::endl;
std::cout << "<<DEBUG>> Exporting the function" << std::endl;
if(args.is_defined("export"))
{
if(args["export"].compare("c++") == 0)
......@@ -56,11 +63,11 @@ class function
std::cout << "<<INFO>> will export in matlab format" << std::endl;
save_matlab(filename, args);
}
else if(args["export"].compare("explorer") == 0)
{
std::cout << "<<INFO>> will export in BRDF explorer format" << std::endl;
save_brdfexplorer(filename, args);
}
else if(args["export"].compare("explorer") == 0)
{
std::cout << "<<INFO>> will export in BRDF explorer format" << std::endl;
save_brdfexplorer(filename, args);
}
else
{
std::cerr << "<<ERROR>> the export format is unknown" << std::endl ;
......@@ -77,7 +84,9 @@ class function
//! Provide the dimension of the output space of the function
virtual int dimY() const { return _nY ; }
//! Set the dimension of the input space of the function
virtual void setDimX(int nX) { _nX = nX ; }
//! Set the dimension of the output space of the function
virtual void setDimY(int nY) { _nY = nY ; }
// Acces to the domain of definition of the function
......@@ -86,7 +95,7 @@ class function
#ifdef DEBUG
assert(min.size() == _nX) ;
#endif
_min = min ;
_min = min ;
}
virtual void setMax(const vec& max)
{
......@@ -98,25 +107,25 @@ class function
virtual vec getMin() const { return _min ; }
virtual vec getMax() const { return _max ; }
//! \brief provide the parametrization of the function.
//! \note some function type can modify the parametrization to adapt
//! to the data.
virtual params::input parametrization() const
{
return _in_param;
}
//! \brief can set the input parametrization of a non-parametrized
//! function. Throw an exception if it tries to erase a previously
//! defined one.
virtual void setParametrization(params::input new_param)
{
if(_in_param != params::UNKNOWN_INPUT)
throw("A parametrization is already defined");
_in_param = new_param;
}
//! \brief provide the parametrization of the function.
//! \note some function type can modify the parametrization to adapt
//! to the data.
virtual params::input parametrization() const
{
return _in_param;
}
//! \brief can set the input parametrization of a non-parametrized
//! function. Throw an exception if it tries to erase a previously
//! defined one.
virtual void setParametrization(params::input new_param)
{
if(_in_param != params::UNKNOWN_INPUT)
throw("A parametrization is already defined");
_in_param = new_param;
}
protected: // function
//! \brief Standard saving function.
......@@ -125,52 +134,52 @@ class function
NOT_IMPLEMENTED();
}
//! \brief Output the function as a gnuplot file. It requires
//! \brief Output the function as a gnuplot file. It requires
//! the data object to output the function at the input location only.
virtual void save_gnuplot(const std::string& filename, const data* d,
const arguments& args) const
{
const arguments& args) const
{
#ifndef OLD
std::ofstream file(filename.c_str(), std::ios_base::trunc);
for(int i=0; i<d->size(); ++i)
{
vec v = d->get(i) ;
// vec y1 ; y1.assign(d->dimY(), 0.0) ;
// for(int k=0; k<d->dimY(); ++k) { y1[k] = v[d->dimX() + k] ; }
vec y2 = value(v) ;
for(int u=0; u<d->dimX(); ++u)
file << v[u] << "\t" ;
for(int u=0; u<d->dimY(); ++u)
file << y2[u] << "\t" ;
file << std::endl ;
}
file.close();
std::ofstream file(filename.c_str(), std::ios_base::trunc);
for(int i=0; i<d->size(); ++i)
{
vec v = d->get(i) ;
// vec y1 ; y1.assign(d->dimY(), 0.0) ;
// for(int k=0; k<d->dimY(); ++k) { y1[k] = v[d->dimX() + k] ; }
vec y2 = value(v) ;
for(int u=0; u<d->dimX(); ++u)
file << v[u] << "\t" ;
for(int u=0; u<d->dimY(); ++u)
file << y2[u] << "\t" ;
file << std::endl ;
}
file.close();
#else
NOT_IMPLEMENTED();
NOT_IMPLEMENTED();
#endif
}
//! \brief Output the function using a C++ function formating.
}
//! \brief Output the function using a C++ function formating.
virtual void save_cpp(const std::string& filename, const arguments& args) const
{
NOT_IMPLEMENTED();
}
//! \brief Output the function using a C++ function formating.
//! \brief Output the function using a C++ function formating.
virtual void save_matlab(const std::string& filename, const arguments& args) const
{
NOT_IMPLEMENTED();
}
//! \brief Output the function using a BRDF Explorer formating.
virtual void save_brdfexplorer(const std::string& filename, const arguments& args) const
{
NOT_IMPLEMENTED();
}
//! \brief Output the function using a BRDF Explorer formating.
virtual void save_brdfexplorer(const std::string& filename, const arguments& args) const
{
NOT_IMPLEMENTED();
}
protected: // data
......@@ -179,9 +188,9 @@ class function
int _nX, _nY ;
vec _min, _max ;
// Input and output parametrization
params::input _in_param ;
params::output _out_param ;
// Input and output parametrization
params::input _in_param ;
params::output _out_param ;
};
/*! \brief Non-linear function interface
......@@ -222,3 +231,4 @@ class nonlinear_function: public function
};
Q_DECLARE_INTERFACE(function, "Fitter.Function")
......@@ -38,12 +38,17 @@ void phong_function::load(const std::string& filename)
//! Number of parameters to this non-linear function
int phong_function::nbParameters() const
{
#ifdef FIT_DIFFUSE
return 3*dimY();
#else
return 2*dimY();
#endif
}
//! Get the vector of parameters for the function
vec phong_function::parameters() const
{
#ifdef FIT_DIFFUSE
vec res(3*dimY());
for(int i=0; i<dimY(); ++i)
{
......@@ -51,6 +56,14 @@ vec phong_function::parameters() const
res[i*3 + 1] = _ks[i];
res[i*3 + 2] = _N[i];
}
#else
vec res(2*dimY());
for(int i=0; i<dimY(); ++i)
{
res[i*2 + 0] = _ks[i];
res[i*2 + 1] = _N[i];
}
#endif
return res;
}
......@@ -60,9 +73,14 @@ void phong_function::setParameters(const vec& p)
{
for(int i=0; i<dimY(); ++i)
{
#ifdef FIT_DIFFUSE
_kd[i] = p[i*3 + 0];
_ks[i] = p[i*3 + 1];
_N[i] = p[i*3 + 2];
#else
_ks[i] = p[i*2 + 0];
_N[i] = p[i*2 + 1];
#endif
}
}
......@@ -76,6 +94,7 @@ vec phong_function::parametersJacobian(const vec& x) const
{
if(i == j)
{
#ifdef FIT_DIFFUSE
// df / dk_d
jac[i*nbParameters() + j*3+0] = 1.0;
......@@ -87,18 +106,50 @@ vec phong_function::parametersJacobian(const vec& x) const
jac[i*nbParameters() + j*3+2] = 0.0;
else
jac[i*nbParameters() + j*3+2] = _ks[j] * std::log(x[0]) * std::pow(x[0], _N[j]);
}
#else
// df / dk_s
jac[i*nbParameters() + j*2+0] = std::pow(x[0], _N[j]);
// df / dN
if(x[0] == 0.0)
jac[i*nbParameters() + j*2+1] = 0.0;
else
jac[i*nbParameters() + j*2+1] = _ks[j] * std::log(x[0]) * std::pow(x[0], _N[j]);
#endif
}
else
{
#ifdef FIT_DIFFUSE
jac[i*nbParameters() + j*3+0] = 0.0;
jac[i*nbParameters() + j*3+1] = 0.0;
jac[i*nbParameters() + j*3+2] = 0.0;
#else
jac[i*nbParameters() + j*2+0] = 0.0;
jac[i*nbParameters() + j*2+1] = 0.0;
#endif
}
}
return jac;
}
void phong_function::boostrap(const data* d, const arguments& args)
{
vec x0 = d->get(0);
for(int i=0; i<d->dimY(); ++i)
_kd[i] = x0[d->dimX() + i];
for(int i=1; i<d->size(); ++i)
{
vec xi = d->get(i);
for(int j=0; j<d->dimY(); ++j)
_kd[j] = std::min(xi[d->dimX() + j], _kd[j]);
}
}
std::ofstream& type_affectation(std::ofstream& out,
const std::string& name,
const vec& x, int nY)
......
......@@ -49,6 +49,10 @@ class phong_function : public nonlinear_function, public QObject
return res;
}
//! \brief Boostrap the function by defining the diffuse term
virtual void boostrap(const data* d, const arguments& args);
//! \brief Load function specific files
virtual void load(const std::string& filename) ;
......
......@@ -123,12 +123,14 @@ bool nonlinear_fitter_eigen::fit_data(const data* d, function* fit, const argume
fit->setMin(d->min()) ;
fit->setMax(d->max()) ;
// Convert the function and boostrap it with the data
if(dynamic_cast<nonlinear_function*>(fit) == NULL)
{
std::cerr << "<<ERROR>> the function is not a non-linear function" << std::endl;
return false;
}
nonlinear_function* nf = dynamic_cast<nonlinear_function*>(fit);
nf->boostrap(d, args);
#ifndef DEBUG
std::cout << "<<DEBUG>> number of parameters: " << nf->nbParameters() << std::endl;
......
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