Commit 09321c27 authored by Laurent Belcour's avatar Laurent Belcour

Adding type of parametrization check in the plugin manager.

parent bf4a76e7
......@@ -4,6 +4,7 @@
#include <iostream>
#include <cassert>
#include <cmath>
#include <cstring>
/*! \brief A core implementation of a vector of double.
* \ingroup core
......
......@@ -43,12 +43,13 @@ class data
return params::UNKNOWN_INPUT;
}
protected:
// Dimension of the function
protected: // data
// Dimensions of the data
int _nX, _nY ;
} ;
Q_DECLARE_INTERFACE(data, "Fitter.Data")
Q_DECLARE_INTERFACE(data, "Fitter.Data")
/*! \brief Change the parametrization of data to fit the parametrization of the
* function to be fitted.
......@@ -68,9 +69,9 @@ public: // structures
//! dimension is reduced, the program will halt.
enum clustrering
{
mean,
median,
none
MEAN,
MEDIAN,
NONE
};
public: // methods
......@@ -78,13 +79,13 @@ public: // methods
//! \brief contructor requires the definition of a base class that
//! has a parametrization, and a new parametrization.
data_params(const data* d, params::input param,
data_params::clustrering method = data_params::none) :
data_params::clustrering method = data_params::NONE) :
_d(d), _param_in(param), _clustering_method(method)
{
_nX = params::dimension(param);
_nY = d->dimY();
if(_nX < _d->dimX() && method == data_params::none)
if(_nX < _d->dimX() && method == data_params::NONE)
{
throw("No cluster method provided");
}
......@@ -135,9 +136,11 @@ public: // methods
return _d->max();
}
protected:
// data object to interface
protected: // data
const data* _d;
params::input _param_in;
data_params::clustrering _clustering_method;
//! \todo Add a cluster object that will duplicate data or store indices.
};
......@@ -26,6 +26,10 @@ class function
{
public: // methods
// Constructor
function() : _in_param(params::UNKNOWN_INPUT),
_out_param(params::UNKNOWN_OUTPUT) { }
// Overload the function operator
virtual vec operator()(const vec& x) const = 0 ;
virtual vec value(const vec& x) const = 0 ;
......@@ -70,7 +74,18 @@ class function
//! to the data.
virtual params::input parametrization() const
{
return params::UNKNOWN_INPUT;
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: //data
......@@ -78,6 +93,10 @@ class function
// Dimension of the function & domain of definition.
int _nX, _nY ;
vec _min, _max ;
// Input and output parametrization
params::input _in_param ;
params::output _out_param ;
};
/*! \brief Non-linear function interface
......
......@@ -33,7 +33,31 @@ class plugins_manager
//! based on the name. Return null if no one exist.
static function* get_function(const std::string& n) ;
static data* get_data(const std::string& n) ;
fitter* get_fitter(const std::string& n) const ;
fitter* get_fitter(const std::string& n) const ;
//! \brief check if a data object and a function object are compatibles.
//! this has to be done before fitting to ensure that the
//! parametrizations spaces are the same.
//! \todo specify an output parametrization for the function ?
static void check_compatibility(data*& d, function*& f,
const arguments& args)
{
if(f->parametrization() == params::UNKNOWN_INPUT)
{
std::cout << "<<DEBUG>> function will take the parametrization of the data" << std::endl;
f->setParametrization(d->parametrization());
}
else if(d->parametrization() != f->parametrization())
{
std::cout << "<<INFO>> has to change the parametrization of the input data" << std::endl;
data_params* dd = new data_params(d, f->parametrization());
d = dd ;
}
else
{
std::cout << "<<DEBUG>> no change was made to the parametrization" << std::endl;
}
}
//! \brief Provide a measure of how much memory there is on the system.
//! \details It permits to know is one can allocate more memory for a fitting
......
......@@ -19,24 +19,10 @@ vec phong_function::operator()(const vec& x) const
}
vec phong_function::value(const vec& x) const
{
/*
// shading
vec lv(3); lv[0] = x[0]; lv[1] = x[1]; lv[2] = x[2];
vec n(3); n[0] = 0.0; n[1] = 0.0; n[2] = 1.0;
vec ev(3); ev[0] = x[3]; ev[1] = x[4]; ev = x[5];
vec halfVector = normalize(lv + ev);
vec res(dimY());
res = _kd + _ks * pow(x[0], _N);
double v_h = dot(ev, halfVector);
double n_h = dot(n, halfVector);
double n_l = dot(n, lv);
double inLight = 1.0;
if (n_l < 0.0) inLight = 0.0;
double n_v = dot(n, ev);
return one_pi * inLight * (n_l * rho_d + rho_s *
D(alpha, p, n_h, K_ap) * G1(n_l) * G1 (n_v) *
Fresnel(F_0, F_1, v_h));
*/
return res;
}
//! Load function specific files
......
......@@ -18,7 +18,7 @@
* fitting algorithms.
*
* \details
* A phong lobe is defined as \f$k_d + k_s |R.H|^N\f$
* A phong lobe is defined as \f$k_d + k_s |N.H|^a\f$
* \todo Finish implementation
*/
class phong_function : public nonlinear_function, public QObject
......@@ -55,14 +55,14 @@ class phong_function : public nonlinear_function, public QObject
//! \brief Provide the dimension of the input space of the function
virtual int dimX() const
{
return 2 ;
return 1 ;
}
//! \brief Provide the parametrization of the input space of the function.
//! For this one, we fix that the parametrization is in THETAD_PHID
virtual params::type parametrization() const
virtual params::input parametrization() const
{
return params::ISOTROPIC_TD_PD ;
return params::COS_TH ;
}
......
......@@ -48,6 +48,9 @@ int main(int argc, char** argv)
data* d = plugins_manager::get_data(args["data"]);
d->load(args["input"], args);
// Check the compatibility between the data and the function
plugins_manager::check_compatibility(d, f, args);
QTime time ;
time.start() ;
bool is_fitted = fit->fit_data(d, f, args) ;
......
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