Commit 0378ebb1 authored by Laurent Belcour's avatar Laurent Belcour

Fixing the retro-Schlick and the Parametrization order for CARTESIAN coordiantes.

parent b8d5db00
......@@ -158,6 +158,7 @@ double function::L2_distance(const data* d) const
//! \brief Linf norm to data.
double function::Linf_distance(const data* d) const
{
vec mean(dimY()), var(dimY());
double linf_dist = 0.0;
for(int i=0; i<d->size(); ++i)
......@@ -168,7 +169,26 @@ double function::Linf_distance(const data* d) const
for(int j=0; j<d->dimY(); ++j) { y[j] = dat[d->dimX()+j]; }
linf_dist = std::max<double>(linf_dist, std::abs(norm(y-value(x))));
mean += (y-value(x)) / double(d->size());
}
for(int i=0; i<d->size(); ++i)
{
vec dat = d->get(i);
vec x(dimX()), y(d->dimY()), val(dimY());
params::convert(&dat[0], d->input_parametrization(), input_parametrization(), &x[0]);
val = value(x);
for(int j=0; j<d->dimY(); ++j)
{
y[j] = dat[d->dimX()+j];
var[j] += pow(mean[j] - (val[j]-y[j]), 2) / double(d->size());
}
}
std::cout << "<<INFO>> Mean = " << mean << ", Var = " << var << std::endl;
return linf_dist;
}
......
......@@ -140,18 +140,18 @@ void params::to_cartesian(const double* invec, params::input intype,
const double theta = sqrt(invec[1]*invec[1] + invec[2]*invec[2]);
if(theta > 0.0)
{
outvec[3] = (invec[1]/theta)*sin(theta);
outvec[4] = (invec[2]/theta)*sin(theta);
outvec[0] = (invec[1]/theta)*sin(theta);
outvec[1] = (invec[2]/theta)*sin(theta);
}
else
{
outvec[3] = 0.0;
outvec[4] = 0.0;
outvec[0] = 0.0;
outvec[1] = 0.0;
}
outvec[5] = cos(theta);
outvec[0] = sin(invec[0]);
outvec[1] = 0.0;
outvec[2] = cos(invec[0]);
outvec[2] = cos(theta);
outvec[3] = sin(invec[0]);
outvec[4] = 0.0;
outvec[5] = cos(invec[0]);
}
break;
......@@ -161,12 +161,12 @@ void params::to_cartesian(const double* invec, params::input intype,
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]);
outvec[0] = cos(invec[3])*sin(invec[2]);
outvec[1] = sin(invec[3])*sin(invec[2]);
outvec[2] = cos(invec[2]);
outvec[3] = cos(invec[1])*sin(invec[0]);
outvec[4] = sin(invec[1])*sin(invec[0]);
outvec[5] = cos(invec[0]);
break;
case params::STEREOGRAPHIC:
......@@ -274,7 +274,7 @@ void params::from_cartesian(const double* invec, params::input outtype,
case params::ISOTROPIC_TV_TL_DPHI:
outvec[0] = acos(invec[2]);
outvec[1] = acos(invec[5]);
outvec[2] = atan2(invec[1], invec[0]) - atan2(invec[4], invec[3]);
outvec[2] = atan2(invec[4], invec[3]) - atan2(invec[1], invec[0]);
break;
case params::RUSIN_VH:
outvec[0] = half[0];
......@@ -283,9 +283,9 @@ void params::from_cartesian(const double* invec, params::input outtype,
break;
case params::SCHLICK_VK:
{
const double Kx = invec[0]-invec[3];
const double Ky = invec[1]-invec[4];
const double Kz = invec[2]-invec[5];
const double Kx = invec[3]-invec[0];
const double Ky = invec[4]-invec[1];
const double Kz = invec[5]+invec[2];
const double norm = sqrt(Kx*Kx + Ky*Ky + Kz*Kz);
if(norm > 1.0E-10)
......@@ -304,9 +304,9 @@ void params::from_cartesian(const double* invec, params::input outtype,
break;
case ISOTROPIC_TL_TV_PROJ_DPHI:
{
const double theta_l = acos(invec[2]);
const double theta_v = acos(invec[5]);
const double dphi = atan2(invec[1], invec[0]) - atan2(invec[4], invec[3]);
const double theta_l = acos(invec[5]);
const double theta_v = acos(invec[2]);
const double dphi = atan2(invec[4], invec[3]) - atan2(invec[1], invec[0]);
outvec[0] = theta_l;
outvec[1] = theta_v * cos(dphi);
outvec[2] = theta_v * sin(dphi);
......@@ -330,10 +330,10 @@ void params::from_cartesian(const double* invec, params::input outtype,
break;
case params::SPHERICAL_TL_PL_TV_PV:
outvec[0] = acos(invec[2]);
outvec[1] = atan2(invec[1], invec[0]);
outvec[2] = acos(invec[5]);
outvec[3] = atan2(invec[4], invec[3]);
outvec[0] = acos(invec[5]);
outvec[1] = atan2(invec[4], invec[3]);
outvec[2] = acos(invec[2]);
outvec[3] = atan2(invec[1], invec[0]);
#ifdef DEBUG
std::cout << invec[2] << " - acos -> " << outvec[0] << std::endl;
#endif
......
......@@ -57,6 +57,7 @@ class params
STEREOGRAPHIC, /*!< Stereographic projection of the Light and View vectors */
SPHERICAL_TL_PL_TV_PV, /*!< Light and View vectors represented in spherical coordinates */
ISOTROPIC_TV_TL, /*!< Light and View vectors represented in spherical coordinates, */
ISOTROPIC_TV_TL_DPHI, /*!< Light and View vectors represented in spherical coordinates,
with the difference of azimutal coordinates in the last component */
ISOTROPIC_TV_PROJ_DPHI,/*!< 2D Parametrization where the phi component is projected.
......@@ -67,7 +68,9 @@ class params
\theta_v \sin(\Delta\phi).\f$]*/
ISOTROPIC_TD_PD, /*!< Difference between two directions such as R and H */
CARTESIAN, /*!< Light and View vectors represented in cartesian coordinates */
CARTESIAN, /*!< View and Light vectors represented in cartesian coordinates.
We always pack the view vector first: \f$\vec{c} = [v.x, v.y,
v.z, l.x, l.y, l.z] \f$*/
UNKNOWN_INPUT /*!< Default behaviour. Only use this is you do not fit BRDF data */
};
......
......@@ -26,12 +26,12 @@ vec retro_schlick::value(const vec& x) const
params::convert(&x[0], input_parametrization(), params::SCHLICK_VK, xp);
params::convert(&x[0], input_parametrization(), params::CARTESIAN, cart);
const double dotRK = xp[0]*cart[0] + xp[1]*cart[1] + xp[2]*cart[2];
const double dotRK = xp[2]*cart[2] - (xp[0]*cart[0] + xp[1]*cart[1]) ;
vec res(_nY);
for(int i=0; i<_nY; ++i)
{
res[i] = R[i] + (1.0 - R[i]) * pow(1.0 - clamp(dotRK, 0.0, 1.0), 5.0);
res[i] = R[i] + (1.0 - R[i]) * (pow(1.0 - dotRK, 5.0));
}
return res;
......@@ -66,7 +66,7 @@ vec retro_schlick::parametersJacobian(const vec& x) const
params::convert(&x[0], input_parametrization(), params::SCHLICK_VK, xp);
params::convert(&x[0], input_parametrization(), params::CARTESIAN, cart);
const double dotRK = xp[0]*cart[0] + xp[1]*cart[1] + xp[2]*cart[2];
const double dotRK = xp[2]*cart[2] - (xp[0]*cart[0] + xp[1]*cart[1]) ;
vec jac(nbParameters()*nY);
for(int i=0; i<nY; ++i)
......@@ -74,7 +74,7 @@ vec retro_schlick::parametersJacobian(const vec& x) const
{
if(i == j)
{
jac[i*nY + j] = 1.0 - pow(1.0 - clamp(dotRK, 0.0, 1.0), 5.0);
jac[i*nY + j] = 1.0 - (pow(1.0 - dotRK, 5.0));
}
else
{
......
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