Commit 88f080da authored by Laurent Belcour's avatar Laurent Belcour

Updating parametrization issues

parent 9c55c5a6
......@@ -114,6 +114,14 @@ class function
{
return _in_param;
}
//! \brief provide the output parametrization of the function.
//! \note some function type can modify the parametrization to adapt
//! to the data.
virtual params::output out_parametrization() const
{
return _out_param;
}
//! \brief can set the input parametrization of a non-parametrized
//! function. Throw an exception if it tries to erase a previously
......@@ -125,6 +133,17 @@ class function
_in_param = new_param;
}
//! \brief can set the output parametrization of a non-parametrized
//! function. Throw an exception if it tries to erase a previously
//! defined one.
virtual void setParametrization(params::output new_param)
{
if(_out_param != params::UNKNOWN_OUTPUT)
throw("A parametrization is already defined");
_out_param = new_param;
}
protected: // function
......
......@@ -12,14 +12,168 @@ struct param_info
// Assing the input params map
static const std::map<params::input, const param_info> input_map = {
/* 1D Params */
{params::COS_TH, {"COS_TH", 1, "Cosine of the Half angle"}},
/* 2D Params */
{params::RUSIN_TH_TD, {"RUSIN_TH_TD", 2, "Radialy symmetric Half angle parametrization"}},
/* 3D Params */
{params::RUSIN_TH_TD_PD, {"RUSIN_TH_TD_PD", 3, "Isotropic Half angle parametrization"}},
{params::ISOTROPIC_TV_TL_DPHI, {"ISOTROPIC_TV_TL_DPHI", 3, "Isotropic Light/View angle parametrization"}},
/* 4D Params */
{params::RUSIN_TH_PH_TD_PD, {"RUSIN_TH_PH_TD_PD", 4, "Complete Half angle parametrization"}},
{params::SPHERICAL_TL_PL_TV_PV, {"SPHERICAL_TL_PL_TV_PV", 4, "Complete classical parametrization"}},
/* 6D Params */
{params::CARTESIAN, {"CARTESIAN", 6, "Complete vector parametrization"}}
};
void params::to_cartesian(const double* invec, params::input intype,
double* outvec)
{
switch(intype)
{
// 1D Parametrizations
case params::COS_TH:
#ifndef USE_HALF
half_to_cartesian(acos(invec[0]), 0.0, 0.0, 0.0, outvec);
#else
outvec[0] = sqrt(1.0 - invec[0]*invec[0]);
outvec[1] = 0;
outvec[2] = invec[0];
outvec[3] = sqrt(1.0 - invec[0]*invec[0]);
outvec[4] = 0;
outvec[5] = invec[0];
#endif
break;
// 2D Parametrizations
case params::COS_TH_TD:
half_to_cartesian(acos(invec[0]), 0.0, acos(invec[1]), 0.0, outvec);
break;
case params::RUSIN_TH_TD:
half_to_cartesian(invec[0], 0.0, invec[1], 0.0, outvec);
break;
// 3D Parametrization
case params::RUSIN_TH_PH_TD:
half_to_cartesian(invec[0], invec[1], invec[2], 0.0, outvec);
break;
case params::RUSIN_TH_TD_PD:
half_to_cartesian(invec[0], 0.0, invec[1], invec[2], outvec);
break;
case params::ISOTROPIC_TV_TL_DPHI:
classical_to_cartesian(invec[0], 0.0, invec[1], invec[2], outvec);
break;
// 4D Parametrization
case params::RUSIN_TH_PH_TD_PD:
half_to_cartesian(invec[0], invec[1], invec[2], invec[3], outvec);
break;
case params::SPHERICAL_TL_PL_TV_PV:
outvec[0] = cos(invec[1])*sin(invec[0]);
outvec[1] = sin(invec[1])*sin(invec[0]);
outvec[2] = cos(invec[0]);
outvec[3] = cos(invec[3])*sin(invec[2]);
outvec[4] = sin(invec[3])*sin(invec[2]);
outvec[5] = cos(invec[2]);
break;
// 6D Parametrization
case params::CARTESIAN:
memcpy(outvec, invec, 6*sizeof(double));
break;
default:
throw("Transformation not implemented, params::to_cartesian");
break;
}
}
void params::from_cartesian(const double* invec, params::input outtype,
double* outvec)
{
// Compute the half vector
double half[3] ;
half[0] = invec[0] + invec[3];
half[1] = invec[1] + invec[4];
half[2] = invec[2] + invec[5];
double half_norm = sqrt(half[0]*half[0] + half[1]*half[1] + half[2]*half[2]);
half[0] /= half_norm;
half[1] /= half_norm;
half[2] /= half_norm;
// Difference vector
double diff[3];
switch(outtype)
{
// 1D Parametrizations
case params::COS_TH:
outvec[0] = half[2];
break;
// 2D Parametrizations
case params::COS_TH_TD:
outvec[0] = half[2];
outvec[1] = half[0]*outvec[0] + half[1]*outvec[1] + half[2]*outvec[2];
break;
case params::RUSIN_TH_TD:
outvec[0] = acos(half[2]);
outvec[2] = acos(half[0]*outvec[0] + half[1]*outvec[1] + half[2]*outvec[2]);
break;
// 3D Parametrization
case params::RUSIN_TH_PH_TD:
outvec[0] = acos(half[2]);
outvec[1] = atan2(half[0], half[1]);
outvec[2] = acos(half[0]*outvec[0] + half[1]*outvec[1] + half[2]*outvec[2]);
break;
case params::ISOTROPIC_TV_TL_DPHI:
outvec[0] = acos(invec[2]);
outvec[1] = 0.0;
outvec[2] = acos(invec[5]);
outvec[3] = atan2(invec[1], invec[0]) - atan2(invec[4], invec[3]);
break;
// 4D Parametrization
case params::RUSIN_TH_PH_TD_PD:
outvec[0] = acos(half[2]);
outvec[1] = atan2(half[0], half[1]);
// Compute the diff vector
diff[0] = invec[0];
diff[1] = invec[1];
diff[2] = invec[2];
rotate_normal(diff, -outvec[1]);
rotate_binormal(diff, -outvec[0]);
outvec[2] = acos(diff[2]);
outvec[3] = atan2(diff[0], diff[1]);
break;
case params::SPHERICAL_TL_PL_TV_PV:
outvec[0] = acos(invec[2]);
outvec[1] = atan2(invec[0], invec[1]);
outvec[2] = acos(invec[5]);
outvec[3] = atan2(invec[3], invec[4]);
break;
// 6D Parametrization
case params::CARTESIAN:
memcpy(outvec, invec, 6*sizeof(double));
break;
default:
assert(false);
break;
}
}
params::input params::parse_input(const std::string& txt)
{
for(std::map<params::input, const param_info>::const_iterator it=input_map.begin(); it != input_map.end(); ++it)
......@@ -31,25 +185,6 @@ params::input params::parse_input(const std::string& txt)
}
return params::UNKNOWN_INPUT;
/*
if(txt == std::string("COS_TH"))
{
return params::COS_TH;
}
else if(txt == std::string("RUSIN_TH_TD"))
{
return params::RUSIN_TH_TD;
}
else if(txt == std::string("RUSIN_TH_PH_TD_PD"))
{
return params::RUSIN_TH_PH_TD_PD;
}
else
{
return params::UNKNOWN_INPUT;
}
*/
}
std::string params::get_name(const params::input param)
......@@ -74,46 +209,6 @@ int params::dimension(params::input t)
{
return -1;
}
/*
switch(t)
{
// 1D Parametrizations
case params::COS_TH:
return 1;
break;
// 2D Parametrizations
case params::ISOTROPIC_TD_PD:
case params::RUSIN_TH_TD:
case params::ROMEIRO_TH_TD:
case params::COS_TH_TD:
return 2;
break;
// 3D Parametrization
case params::RUSIN_TH_PH_TD:
case params::RUSIN_TH_TD_PD:
case params::ISOTROPIC_TV_TL_DPHI:
return 3;
break;
// 4D Parametrization
case params::RUSIN_TH_PH_TD_PD:
case params::SPHERICAL_TL_PL_TV_PV:
return 4;
break;
// 6D Parametrization
case params::CARTESIAN:
return 6;
break;
default:
assert(false);
return -1;
break;
}
*/
}
void params::print_input_params()
......
......@@ -115,142 +115,12 @@ class params
//! output vector in a cartesian parametrization, that is two 3d
//! vectors concatenated.
static void to_cartesian(const double* invec, params::input intype,
double* outvec)
{
switch(intype)
{
// 1D Parametrizations
case params::COS_TH:
#ifndef USE_HALF
half_to_cartesian(acos(invec[0]), 0.0, 0.0, 0.0, outvec);
#else
outvec[0] = sqrt(1.0 - invec[0]*invec[0]);
outvec[1] = 0;
outvec[2] = invec[0];
outvec[3] = sqrt(1.0 - invec[0]*invec[0]);
outvec[4] = 0;
outvec[5] = invec[0];
#endif
break;
// 2D Parametrizations
case params::COS_TH_TD:
half_to_cartesian(acos(invec[0]), 0.0, acos(invec[1]), 0.0, outvec);
break;
case params::RUSIN_TH_TD:
half_to_cartesian(invec[0], 0.0, invec[1], 0.0, outvec);
break;
// 3D Parametrization
case params::RUSIN_TH_PH_TD:
half_to_cartesian(invec[0], invec[1], invec[2], 0.0, outvec);
break;
case params::RUSIN_TH_TD_PD:
half_to_cartesian(invec[0], 0.0, invec[1], invec[2], outvec);
break;
// 4D Parametrization
case params::RUSIN_TH_PH_TD_PD:
half_to_cartesian(invec[0], invec[1], invec[2], invec[3], outvec);
break;
case params::SPHERICAL_TL_PL_TV_PV:
outvec[0] = cos(invec[1])*sin(invec[0]);
outvec[1] = sin(invec[1])*sin(invec[0]);
outvec[2] = cos(invec[0]);
outvec[3] = cos(invec[3])*sin(invec[2]);
outvec[4] = sin(invec[3])*sin(invec[2]);
outvec[5] = cos(invec[2]);
break;
// 6D Parametrization
case params::CARTESIAN:
memcpy(outvec, invec, 6*sizeof(double));
break;
default:
throw("Transformation not implemented, params::to_cartesian");
break;
}
}
double* outvec);
//! \brief convert a input CARTESIAN vector, that is two 3d vectors
//! concatenated to an output vector in a given parametrization.
static void from_cartesian(const double* invec, params::input outtype,
double* outvec)
{
// Compute the half vector
double half[3] ;
half[0] = invec[0] + invec[3];
half[1] = invec[1] + invec[4];
half[2] = invec[2] + invec[5];
double half_norm = sqrt(half[0]*half[0] + half[1]*half[1] + half[2]*half[2]);
half[0] /= half_norm;
half[1] /= half_norm;
half[2] /= half_norm;
// Difference vector
double diff[3];
switch(outtype)
{
// 1D Parametrizations
case params::COS_TH:
outvec[0] = half[2];
break;
// 2D Parametrizations
case params::COS_TH_TD:
outvec[0] = half[2];
outvec[1] = half[0]*outvec[0] + half[1]*outvec[1] + half[2]*outvec[2];
break;
case params::RUSIN_TH_TD:
outvec[0] = acos(half[2]);
outvec[2] = acos(half[0]*outvec[0] + half[1]*outvec[1] + half[2]*outvec[2]);
break;
// 3D Parametrization
case params::RUSIN_TH_PH_TD:
outvec[0] = acos(half[2]);
outvec[1] = atan2(half[0], half[1]);
outvec[2] = acos(half[0]*outvec[0] + half[1]*outvec[1] + half[2]*outvec[2]);
break;
// 4D Parametrization
case params::RUSIN_TH_PH_TD_PD:
outvec[0] = acos(half[2]);
outvec[1] = atan2(half[0], half[1]);
// Compute the diff vector
diff[0] = invec[0];
diff[1] = invec[1];
diff[2] = invec[2];
rotate_normal(diff, -outvec[1]);
rotate_binormal(diff, -outvec[0]);
outvec[2] = acos(diff[2]);
outvec[3] = atan2(diff[0], diff[1]);
break;
case params::SPHERICAL_TL_PL_TV_PV:
outvec[0] = acos(invec[2]);
outvec[1] = atan2(invec[0], invec[1]);
outvec[2] = acos(invec[5]);
outvec[3] = atan2(invec[3], invec[4]);
break;
// 6D Parametrization
case params::CARTESIAN:
memcpy(outvec, invec, 6*sizeof(double));
break;
default:
assert(false);
break;
}
}
double* outvec);
//! \brief provide a dimension associated with a parametrization
static int dimension(params::input t);
......@@ -309,6 +179,19 @@ class params
assert(out[5] >= 0.0);
}
//! \brief from the 4D definition of a classical vector parametrization,
//! export the cartesian coordinates.
static void classical_to_cartesian(double theta_l, double phi_l,
double theta_v, double phi_v, double* out)
{
out[0] = cos(phi_l)*sin(theta_l);
out[1] = sin(phi_l)*sin(theta_l);
out[2] = cos(theta_l);
out[3] = cos(phi_v)*sin(theta_v);
out[4] = sin(phi_v)*sin(theta_v);
out[5] = cos(theta_v);
}
//! \brief rotate a cartesian vector with respect to the normal of
//! theta degrees.
......
......@@ -63,6 +63,11 @@ class plugins_manager
static void check_compatibility(data*& d, function*& f,
const arguments& args)
{
if(d->parametrization() == params::UNKNOWN_INPUT)
{
std::cout << "<<WARNING>> unknown parametrization for data" << std::endl;
}
if(f->parametrization() == params::UNKNOWN_INPUT)
{
std::cout << "<<DEBUG>> function will take the parametrization of the data" << std::endl;
......@@ -78,12 +83,12 @@ class plugins_manager
{
std::cout << "<<DEBUG>> no change was made to the parametrization" << std::endl;
}
/*
if(f->dimY() != d->dimY())
{
std::cout << "<<ERROR>> the data and the function have different Y dimensions" << std::endl;
std::cout << "<<WARNING>> the data and the function have different Y dimensions" << std::endl;
}
*/
/*
// Check is the data has to be clusterized
if(args.is_defined("cluster-dim"))
......
......@@ -50,16 +50,22 @@ int main(int argc, char** argv)
// if(fitters.size() > 0 && datas.size() > 0 && functions.size() > 0)
{
fit->set_parameters(args) ;
function* f = plugins_manager::get_function(args["func"]);
data* d = plugins_manager::get_data(args["data"]);
function* f = plugins_manager::get_function(args["func"]);
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);
// Check the compatibility between the data and the function
plugins_manager::check_compatibility(d, f, args);
// Start a timer
QTime time ;
time.start() ;
bool is_fitted = fit->fit_data(d, f, args) ;
// Fit the data
bool is_fitted = fit->fit_data(d, f, args) ;
// Get the fitting duration
int msec = time.elapsed() ;
int sec = (msec / 1000) % 60 ;
int min = (msec / 60000) % 60 ;
......
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