Commit 8bec7b5b authored by Laurent Belcour's avatar Laurent Belcour

Adding more consistant fitting

parent 23138862
......@@ -136,6 +136,7 @@ template<class T> void clustering(const T* in_data, int _nY, params::input in_pa
params::convert(&p[0], in_param, out_param, &e[0]);
// Search for duplicates
/*
bool already_exist = false;
for(unsigned int j=0; j<out_data.size(); ++j)
{
......@@ -153,6 +154,7 @@ template<class T> void clustering(const T* in_data, int _nY, params::input in_pa
}
if(!already_exist)
*/
{
// Fill the output part of the vector
for(int j=0; j<_nY; ++j)
......
......@@ -123,7 +123,16 @@ class params
{
// 1D Parametrizations
case params::COS_TH:
half_to_cartesian(acos(invec[0]), 0.0, 0.0, 0.0, outvec);
#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
......@@ -286,15 +295,20 @@ class params
out[0] = sin(theta_d)*cos(phi_d);
out[1] = sin(theta_d)*sin(phi_d);
out[2] = cos(theta_d);
rotate_binormal(out, phi_h);
rotate_normal(out, theta_h);
//! \todo investigate here, the rotation along N should be
//1 of phi_h not theta_h !
rotate_normal(out, phi_h);
rotate_binormal(out, theta_h);
// Compute the out vector from the in vector and the half
// vector.
const double dot = out[0]*half[0] + out[1]*half[1] + out[2]*half[2];
out[3] = -out[0] + 2.0*dot * half[0];
out[4] = -out[1] + 2.0*dot * half[1];
out[5] = -out[2] + 2.0*dot * half[2];
out[3] = -out[0] + (dot+1.0) * half[0];
out[4] = -out[1] + (dot+1.0) * half[1];
out[5] = -out[2] + (dot+1.0) * half[2];
assert(out[5] >= 0.0);
}
//! \brief rotate a cartesian vector with respect to the normal of
......
......@@ -136,9 +136,10 @@ bool nonlinear_fitter_eigen::fit_data(const data* d, function* fit, const argume
/* the following starting values provide a rough fit. */
int info;
Eigen::VectorXd x(6);
Eigen::VectorXd x(nf->nbParameters());
x.setConstant(nf->nbParameters(), 1.);
EigenFunctor functor(nf, d);
Eigen::LevenbergMarquardt<EigenFunctor> lm(functor);
......
......@@ -12,5 +12,6 @@ SUBDIRS = \
rational_fitter_dca \
nonlinear_levenberg_eigen \
nonlinear_function_phong \
nonlinear_function_lafortune \
data_merl
......@@ -68,16 +68,21 @@ int main(int argc, char** argv)
}
else if(k == 5)
{
f << "#DIM 1 3" << std::endl ;
f << "#DIM 1 1" << std::endl ;
f << "#PARAM_IN COS_TH" << std::endl;
for(int i=0; i<nbx; ++i)
{
const float x = i / (float)nbx ;
const float z1 = 0.1 + 0.5 * std::pow(x, 1.5) ;
const float z2 = 0.0 - 0.1 * std::pow(x, 4.0) ;
const float z3 = 0.5 + 0.7 * std::pow(x, 1.0) ;
const float x = i / (float)nbx ;
// const float d[3] = {0.1, 0.0, 0.5};
const float d[3] = {0.0, 0.0, 0.0};
const float z1 = d[0] + 0.2 * std::pow(x, 1.5) ;
// const float z2 = d[1] - 0.1 * std::pow(x, 4.0) ;
// const float z3 = d[2] + 0.7 * std::pow(x, 1.0) ;
f << x << "\t" << z1 << "\t" << z2 << "\t" << z3 << std::endl ;
f << x << "\t" << z1 ;
// f << "\t" << z2 ;
// f << "\t" << z3 ;
f << std::endl ;
}
}
else if(k == 6)
......
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