Commit deb03d7f authored by Ludovic Courtès's avatar Ludovic Courtès

core: Remove 'setDimX' and 'setDimY' from 'function' and sub-classes.

parent 693a66cf
......@@ -276,21 +276,6 @@ double function::Linf_distance(const ptr<data>& d) const
return linf_dist;
}
void function::setDimX(int x)
{
_parameters = parameters(x, _parameters.dimY(),
_parameters.input_parametrization(),
_parameters.output_parametrization());
_min.resize(x); _max.resize(x);
}
void function::setDimY(int y)
{
_parameters = parameters(_parameters.dimX(), y,
_parameters.input_parametrization(),
_parameters.output_parametrization());
}
/*--- Non-linear functions implementation ----*/
......@@ -657,31 +642,6 @@ void compound_function::bootstrap(const ::ptr<data> d, const arguments& args)
}
}
void compound_function::setDimX(int nX)
{
if(parametrization().input_parametrization() == params::UNKNOWN_INPUT)
{
function::setDimX(nX);
}
for(unsigned int i=0; i<fs.size(); ++i)
{
if(fs[i]->parametrization().input_parametrization() == params::UNKNOWN_INPUT)
{
fs[i]->setDimX(nX);
}
}
}
void compound_function::setDimY(int nY)
{
function::setDimY(nY);
for(unsigned int i=0; i<fs.size(); ++i)
{
fs[i]->setDimY(nY);
}
}
void compound_function::setMin(const vec& min)
{
function::setMin(min);
......@@ -1049,22 +1009,6 @@ void product_function::bootstrap(const ptr<data> d, const arguments& args)
f2->bootstrap(d, args);
}
}
void product_function::setDimX(int nX)
{
f1->setDimX(nX);
f2->setDimX(nX);
function::setDimX(f1->parametrization().dimX());
}
void product_function::setDimY(int nY)
{
f1->setDimY(nY);
f2->setDimY(nY);
function::setDimY(f1->parametrization().dimY());
}
void product_function::setMin(const vec& min)
{
......
......@@ -125,10 +125,6 @@ class function
_parameters = p;
}
// TODO: Deprecate, then remove these two methods.
virtual void setDimX(int x) ALTA_DEPRECATED;
virtual void setDimY(int y) ALTA_DEPRECATED;
protected:
// Input and output parametrization
parameters _parameters;
......@@ -257,12 +253,6 @@ class compound_function: public nonlinear_function
//! Local bootstrap can not overload the global bootstrap.
virtual void bootstrap(const ptr<data> d, const arguments& args);
//! Set the dimension of the input space of the function
virtual void setDimX(int nX);
//! Set the dimension of the output space of the function
virtual void setDimY(int nY);
// Acces to the domain of definition of the function
virtual void setMin(const vec& min);
virtual void setMax(const vec& max);
......@@ -372,10 +362,6 @@ class product_function : public nonlinear_function
//! \brief Provide a first rough fit of the function.
virtual void bootstrap(const ptr<data> d, const arguments& args);
// Set the dimension of the input/output space of the function
virtual void setDimX(int nX);
virtual void setDimY(int nY);
// Acces to the domain of definition of the function
virtual void setMin(const vec& min);
virtual void setMax(const vec& max);
......
......@@ -220,11 +220,6 @@ function* plugins_manager::load_function(const std::string& filename)
// Create the function from the command line
function* f = get_function(args, params);
// FIXME: Since the above is not quite the same as calling 'setDimY' (which
// is virtual), also call it from here. TODO: Remove it ASAP.
f->setDimY(params.dimY());
f->setDimX(params.dimX());
// Load the function part from the file object
if( f->load(file) )
{
......@@ -536,7 +531,9 @@ void plugins_manager::check_compatibility( ptr<data>& d,
if(f->parametrization().dimY() != d->parametrization().dimY())
{
f->setDimY(d->parametrization().dimY());
abort();
// FIXME: Used to be this:
// f->setDimY(d->parametrization().dimY());
}
/*
......
......@@ -20,6 +20,7 @@
#include <limits>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <core/common.h>
......@@ -322,10 +323,8 @@ nonlinear_fitter_eigen::~nonlinear_fitter_eigen()
bool nonlinear_fitter_eigen::fit_data(const ptr<data>& d, ptr<function>& fit, const arguments &args)
{
// I need to set the dimension of the resulting function to be equal
// to the dimension of my fitting problem
fit->setDimX(d->parametrization().dimX()) ;
fit->setDimY(d->parametrization().dimY()) ;
// XXX: FIT and D may have different values of dimX() and dimY(), but
// this is fine: we convert values as needed in operator().
fit->setMin(d->min());
fit->setMax(d->max());
......
......@@ -18,6 +18,7 @@
#include <limits>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <core/common.h>
......@@ -145,10 +146,8 @@ nonlinear_fitter_nlopt::~nonlinear_fitter_nlopt()
bool nonlinear_fitter_nlopt::fit_data(const ptr<data>& d, ptr<function>& fit, const arguments &args)
{
// I need to set the dimension of the resulting function to be equal
// to the dimension of my fitting problem
fit->setDimX(d->parametrization().dimX());
fit->setDimY(d->parametrization().dimY());
// XXX: FIT and D may have different values of dimX() and dimY(), but
// this is fine: we convert values as needed in operator().
fit->setMin(d->min());
fit->setMax(d->max());
......
......@@ -64,13 +64,6 @@ class schlick : public nonlinear_function
//! \brief Boostrap the function by defining the diffuse term
virtual void bootstrap(const ptr<data> d, const arguments& args);
//! \brief resize the parameter vector
virtual void setDimY(int nY)
{
nonlinear_function::setDimY(nY);
R.resize(nY);
}
private: // data
//! Unidimensional Fresnel reflectance at theta = 0
......
......@@ -29,6 +29,7 @@ ALTA_DLL_EXPORT function* provide_function(const parameters& params)
retro_schlick::retro_schlick(const alta::parameters& params):
nonlinear_function(params.set_input(6, params::CARTESIAN))
{
R.resize(params.dimY());
}
vec retro_schlick::value(const vec& x) const
......
......@@ -63,13 +63,6 @@ class retro_schlick : public nonlinear_function
//! \brief Boostrap the function by defining the diffuse term
virtual void bootstrap(const ptr<data> d, const arguments& args);
//! \brief resize the parameter vector
virtual void setDimY(int nY)
{
function::setDimY(nY);
R.resize(nY);
}
private: // data
//! Unidimensional Fresnel reflectance at theta = 0
......
......@@ -29,6 +29,7 @@ ALTA_DLL_EXPORT function* provide_function(const parameters& params)
schlick_fresnel::schlick_fresnel(const alta::parameters& params)
: nonlinear_function(params)
{
R.resize(params.dimY());
}
//! Load function specific files
......
......@@ -68,13 +68,6 @@ class schlick_fresnel : public nonlinear_function
//! \brief Boostrap the function by defining the diffuse term
virtual void bootstrap(const ptr<data> d, const arguments& args);
//! \brief resize the parameter vector
virtual void setDimY(int nY)
{
function::setDimY(nY);
R.resize(nY);
}
private: // data
//! Fresnel reflectance at theta = 0
......
......@@ -53,20 +53,6 @@ vec abc_function::value(const vec& x) const
return res;
}
// Reset the output dimension
void abc_function::setDimY(int nY)
{
alta::parameters new_params(_parameters.dimX(), nY,
_parameters.input_parametrization(),
_parameters.output_parametrization());
_parameters = new_params;
// Update the length of the vectors
_a.resize(parametrization().dimY()) ;
_b.resize(parametrization().dimY()) ;
_c.resize(parametrization().dimY()) ;
}
//! Number of parameters to this non-linear function
int abc_function::nbParameters() const
{
......
......@@ -50,7 +50,12 @@ class abc_function : public nonlinear_function
abc_function(const alta::parameters& params)
: nonlinear_function(params)
{}
{
// Update the length of the vectors
_a.resize(params.dimY());
_b.resize(params.dimY());
_c.resize(params.dimY());
}
// Overload the function operator
virtual vec operator()(const vec& x) const ;
......@@ -84,9 +89,6 @@ class abc_function : public nonlinear_function
//! parameters.
virtual vec parametersJacobian(const vec& x) const ;
//! \brief Set the number of output dimensions
void setDimY(int nY);
private: // data
vec _a, _b, _c; // Lobes data
......
......@@ -30,6 +30,9 @@ ALTA_DLL_EXPORT function* provide_function(const parameters& params)
beckmann_function::beckmann_function(const alta::parameters& params)
: nonlinear_function(params.set_input(6, params::CARTESIAN))
{
// Update the length of the vectors
_a.resize(parametrization().dimY()) ;
_ks.resize(parametrization().dimY()) ;
}
......@@ -91,18 +94,6 @@ vec beckmann_function::value(const vec& x) const
return res;
}
// Reset the output dimension
void beckmann_function::setDimY(int nY)
{
_parameters = alta::parameters(_parameters.dimX(), nY,
_parameters.input_parametrization(),
_parameters.output_parametrization());
// Update the length of the vectors
_a.resize(parametrization().dimY()) ;
_ks.resize(parametrization().dimY()) ;
}
//! Number of parameters to this non-linear function
int beckmann_function::nbParameters() const
{
......
......@@ -75,9 +75,6 @@ class beckmann_function : public nonlinear_function
//! parameters.
virtual vec parametersJacobian(const vec& x) const ;
//! \brief Set the number of output dimensions
void setDimY(int nY);
private: // data
vec _ks; //Specular coefficients. One per color/wavelength
......
......@@ -28,7 +28,11 @@ ALTA_DLL_EXPORT function* provide_function(const alta::parameters& params)
blinn_function::blinn_function(const alta::parameters& params)
: nonlinear_function(params.set_input(1, params::COS_TH))
{}
{
// Update the length of the vectors
_ks.resize(_parameters.dimY()) ;
_N.resize(_parameters.dimY()) ;
}
// Overload the function operator
......
......@@ -76,17 +76,6 @@ class blinn_function : public nonlinear_function
//! parameters.
virtual vec parametersJacobian(const vec& x) const ;
void setDimY(int nY)
{
//CODE CONSISTENCY WITH THE OTHER PLUGIN
//_nY = nY ;
function::setDimY(nY);
// Update the length of the vectors
_ks.resize(_parameters.dimY()) ;
_N.resize(_parameters.dimY()) ;
}
void save_call(std::ostream& out, const arguments& args) const;
void save_body(std::ostream& out, const arguments& args) const;
......
......@@ -66,17 +66,9 @@ class diffuse_function : public nonlinear_function
virtual void setParameters(const vec& p) ;
//! \brief Obtain the derivatives of the function with respect to the
//! parameters.
//! parameters.
virtual vec parametersJacobian(const vec& x) const ;
virtual void setDimY(int nY)
{
_parameters = alta::parameters(_parameters.dimX(), nY,
_parameters.input_parametrization(),
_parameters.output_parametrization());
_kd.resize(nY);
}
private: // data
vec _kd;
......
......@@ -29,7 +29,17 @@ ALTA_DLL_EXPORT function* provide_function(const alta::parameters& params)
isotropic_lafortune_function::isotropic_lafortune_function(const alta::parameters& params):
nonlinear_function(params.set_input(6, params::CARTESIAN)),
_n(1)
{}
{
// Update the length of the vectors
_C.resize(_n*_parameters.dimY()*2) ;
_N.resize(_n*_parameters.dimY()) ;
#ifdef USE_DIFFUSE
_kd.resize(_parameters.dimY());
for(int i=0; i<nY; ++i)
_kd[i] = 0.0;
#endif
}
// Overload the function operator
vec isotropic_lafortune_function::operator()(const vec& x) const
......@@ -133,24 +143,6 @@ void isotropic_lafortune_function::setNbLobes(int N)
_N.resize(_n*_parameters.dimY()) ;
}
// Reset the output dimension
void isotropic_lafortune_function::setDimY(int nY)
{
_parameters = alta::parameters(_parameters.dimX(), nY,
_parameters.input_parametrization(),
_parameters.output_parametrization());
// Update the length of the vectors
_C.resize(_n*_parameters.dimY()*2) ;
_N.resize(_n*_parameters.dimY()) ;
#ifdef USE_DIFFUSE
_kd.resize(_parameters.dimY());
for(int i=0; i<nY; ++i)
_kd[i] = 0.0;
#endif
}
//! Number of parameters to this non-linear function
int isotropic_lafortune_function::nbParameters() const
{
......
......@@ -96,9 +96,6 @@ class isotropic_lafortune_function : public nonlinear_function
//! parameters.
virtual vec parametersJacobian(const vec& x) const ;
//! \brief Set the number of output dimensions
void setDimY(int nY);
//! \brief Set the number of lobes to be used in the fit
void setNbLobes(int N);
......
......@@ -27,6 +27,22 @@ ALTA_DLL_EXPORT function* provide_function(const parameters& params)
return new lafortune_function(params);
}
lafortune_function::lafortune_function(const parameters& params)
{
auto nY = params.dimY();
// Update the length of the vectors
if(_isotropic)
_C.resize(_n*nY*2) ;
else
_C.resize(_n*nY*3) ;
_N.resize(_n*nY) ;
_kd.resize(nY);
for(int i=0; i<nY; ++i)
_kd[i] = 0.0;
}
// Overload the function operator
vec lafortune_function::operator()(const vec& x) const
{
......@@ -133,23 +149,6 @@ void lafortune_function::setNbLobes(int N)
_N.resize(_n*_nY) ;
}
// Reset the output dimension
void lafortune_function::setDimY(int nY)
{
_nY = nY ;
// Update the length of the vectors
if(_isotropic)
_C.resize(_n*_nY*2) ;
else
_C.resize(_n*_nY*3) ;
_N.resize(_n*_nY) ;
_kd.resize(_nY);
for(int i=0; i<nY; ++i)
_kd[i] = 0.0;
}
//! Number of parameters to this non-linear function
int lafortune_function::nbParameters() const
{
......
......@@ -44,11 +44,7 @@ class lafortune_function : public nonlinear_function
public: // methods
lafortune_function() : _n(1), _isotropic(false)
{
nonlinear_function::setParametrization(params::CARTESIAN);
nonlinear_function::setDimX(6);
}
lafortune_function(const parameters& params);
// Overload the function operator
virtual vec operator()(const vec& x) const ;
......@@ -98,9 +94,6 @@ class lafortune_function : public nonlinear_function
#endif
}
//! \brief Set the number of output dimensions
void setDimY(int nY);
//! \brief Set the number of lobes to be used in the fit
void setNbLobes(int N);
......@@ -135,5 +128,11 @@ class lafortune_function : public nonlinear_function
//!\brief Flags to get an isotropic lobe
bool _isotropic;
lafortune_function()
: nonlinear_function(6, 0,
params::CARTESIAN, params::UNKNOWN_OUTPUT)
{
};
} ;
......@@ -31,6 +31,9 @@ beckmann_function::beckmann_function(const alta::parameters& params)
: nonlinear_function(params.set_input(6, params::CARTESIAN)),
_use_back_param(true)
{
// Update the length of the vectors
_a.resize(_parameters.dimY()) ;
_ks.resize(_parameters.dimY()) ;
}
......@@ -74,18 +77,6 @@ vec beckmann_function::value(const vec& x) const
return res;
}
// Reset the output dimension
void beckmann_function::setDimY(int nY)
{
_parameters = alta::parameters(_parameters.dimX(), nY,
_parameters.input_parametrization(),
_parameters.output_parametrization());
// Update the length of the vectors
_a.resize(_parameters.dimY()) ;
_ks.resize(_parameters.dimY()) ;
}
//! Number of parameters to this non-linear function
int beckmann_function::nbParameters() const
{
......
......@@ -75,9 +75,6 @@ class beckmann_function : public nonlinear_function
//! parameters.
virtual vec parametersJacobian(const vec& x) const ;
//! \brief Set the number of output dimensions
void setDimY(int nY);
private: // data
vec _ks, _a; // Lobes data
......
......@@ -29,6 +29,9 @@ ALTA_DLL_EXPORT function* provide_function(const alta::parameters& params)
retroblinn_function::retroblinn_function(const alta::parameters &params)
: nonlinear_function(params)
{
// Update the length of the vectors
_ks.resize(_parameters.dimY()) ;
_N.resize(_parameters.dimY()) ;
}
// Overload the function operator
......
......@@ -70,17 +70,6 @@ class retroblinn_function : public nonlinear_function
//! parameters.
virtual vec parametersJacobian(const vec& x) const ;
void setDimY(int nY)
{
_parameters = alta::parameters(_parameters.dimX(), nY,
_parameters.input_parametrization(),
_parameters.output_parametrization());
// Update the length of the vectors
_ks.resize(_parameters.dimY()) ;
_N.resize(_parameters.dimY()) ;
}
//! \brief Export function
virtual void save_call(std::ostream& out,
const arguments& args) const;
......
......@@ -30,6 +30,9 @@ ALTA_DLL_EXPORT function* provide_function(const alta::parameters& params)
yoo_function::yoo_function(const alta::parameters& params)
: nonlinear_function(params.set_input(6, params::CARTESIAN))
{
// Update the length of the vectors
_lt.resize(_parameters.dimY()) ;
_kr.resize(_parameters.dimY()) ;
}
......@@ -51,18 +54,6 @@ vec yoo_function::value(const vec& x) const
return res;
}
// Reset the output dimension
void yoo_function::setDimY(int nY)
{
_parameters = alta::parameters(_parameters.dimX(), nY,
_parameters.input_parametrization(),
_parameters.output_parametrization());
// Update the length of the vectors
_lt.resize(_parameters.dimY()) ;
_kr.resize(_parameters.dimY()) ;
}
//! Number of parameters to this non-linear function
int yoo_function::nbParameters() const
{
......
......@@ -78,9 +78,6 @@ class yoo_function : public nonlinear_function
//! parameters.
virtual vec parametersJacobian(const vec& x) const ;
//! \brief Set the number of output dimensions
void setDimY(int nY);
private: // data
vec _kr, _lt; // Lobes data
......
......@@ -28,7 +28,24 @@ ALTA_DLL_EXPORT function* provide_function(const alta::parameters& params)
shifted_gamma_function::shifted_gamma_function(const alta::parameters& params)
: nonlinear_function(params.set_input(6, params::CARTESIAN))
{}
{
auto nY = params.dimY();
// Update the length of the vectors
sh_c = vec::Zero(nY);
sh_theta0 = vec::Zero(nY);
sh_k = vec::Zero(nY);
sh_lambda = vec::Zero(nY);
p = vec::Zero(nY);
F_0 = vec::Zero(nY);
F_1 = vec::Zero(nY);
K_ap = vec::Zero(nY);
rho_d = vec::Zero(nY);
rho_s = vec::Zero(nY);
alpha = vec::Zero(nY);
alpha.fill(1.0);
}
// Overload the function operator
......
......@@ -58,26 +58,6 @@ class shifted_gamma_function : public nonlinear_function
//! parameters.
virtual vec parametersJacobian(const vec& x) const ;
//! Update the parameter vectors
void setDimY(int nY) {
nonlinear_function::setDimY(nY);
// Update the length of the vectors
sh_c = vec::Zero(nY);
sh_theta0 = vec::Zero(nY);
sh_k = vec::Zero(nY);
sh_lambda = vec::Zero(nY);
p = vec::Zero(nY);
F_0 = vec::Zero(nY);
F_1 = vec::Zero(nY);
K_ap = vec::Zero(nY);
rho_d = vec::Zero(nY);
rho_s = vec::Zero(nY);
alpha = vec::Zero(nY);
alpha.fill(1.0);
}
//! Load BRDF parameters from .brdf file
virtual bool load(std::istream& in);
......
......@@ -27,6 +27,15 @@ ALTA_DLL_EXPORT function* provide_function(const parameters& params)
return new spherical_gaussian_function(params);
}
spherical_gaussian_function::spherical_gaussian_function(const parameters& params)
: nonlinear_function(params.set_input(6, params::CARTESIAN)),
_non_a(1), _type(Mirror)
{