Commit 757f9b85 authored by Laurent Belcour's avatar Laurent Belcour

Updating params. There was a bug.

The Lafortune loader is not working !
parent 4b89bdbf
......@@ -156,28 +156,29 @@ class params
{
// Calculate the half vector
double half[3];
half[0] = sin(theta_h)*cos(phi_h);
half[1] = sin(theta_h)*sin(phi_h);
half[0] = sin(theta_h)*sin(phi_h);
half[1] = sin(theta_h)*cos(phi_h);
half[2] = cos(theta_h);
// Compute the light vector using the rotation formula.
out[0] = sin(theta_d)*cos(phi_d);
out[1] = sin(theta_d)*sin(phi_d);
out[0] = sin(theta_d)*sin(phi_d);
out[1] = sin(theta_d)*cos(phi_d);
out[2] = cos(theta_d);
//! \todo investigate here, the rotation along N should be
//1 of phi_h not theta_h !
// Rotate the diff vector to get the output vector
rotate_binormal(out, theta_h);
rotate_normal(out, phi_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] + (dot+1.0) * half[0];
out[4] = -out[1] + (dot+1.0) * half[1];
out[5] = -out[2] + (dot+1.0) * 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];
assert(out[5] >= 0.0);
#ifdef DEBUG
assert(out[2] >= 0.0 && out[5] >= 0.0);
#endif
}
//! \brief from the 4D definition of a classical vector parametrization,
......@@ -200,8 +201,10 @@ class params
const double cost = cos(theta);
const double sint = sin(theta);
vec[0] = cost * vec[0] - sint * vec[1];
vec[1] = sint * vec[0] + cost * vec[1];
const double temp = cost * vec[0] + sint * vec[1];
vec[1] = cost * vec[1] - sint * vec[0];
vec[0] = temp;
}
//! \brief rotate a cartesian vector with respect to the bi-normal of
......@@ -211,8 +214,10 @@ class params
const double cost = cos(theta);
const double sint = sin(theta);
vec[1] = cost * vec[1] - sint * vec[2];
vec[2] = sint * vec[1] + cost * vec[2];
const double temp = cost * vec[1] + sint * vec[2];
vec[2] = cost * vec[2] - sint * vec[1];
vec[1] = temp;
}
static void print_input_params();
......
......@@ -361,17 +361,48 @@ void lafortune_function::load(const std::string& filename)
}
}
_kd = vec(_nY);
setNbLobes(_n);
// Parse the diffuse
for(int i=0; i<_nY; ++i)
{
file >> _kd[i];
}
// Parse the lobe
for(int n=0; n<_n; ++n)
{
std::cout << (char)file.peek() << std::endl;
// TODO find a way to discard those lines
while(file.peek() == '#')
{
std::string line ;
std::getline(file, line) ;
}
// std::cout << (char)file.peek() << std::endl;
for(int i=0; i<_nY; ++i)
{
file >> _C[(n*_nY + i)*3 + 0] >> _C[(n*_nY + i)*3 + 1] >> _C[(n*_nY + i)*3 + 2];
}
// TODO find a way to discard those lines
while(file.peek() == '#')
{
std::string line ;
std::getline(file, line) ;
}
for(int i=0; i<_nY; ++i)
{
file >> _N[i];
}
}
std::cout << "<<INFO>> Kd = " << _kd << std::endl;
std::cout << "<<INFO>> Cd = " << _C << std::endl;
std::cout << "<<INFO>> N = " << _N << std::endl;
}
void lafortune_function::save(const std::string& filename) const
......@@ -379,6 +410,12 @@ void lafortune_function::save(const std::string& filename) const
std::ofstream file(filename.c_str(), std::ios_base::trunc);
file << "#DIM " << _nX << " " << _nY << std::endl ;
file << "#NB_LOBES " << _n << std::endl ;
for(int i=0; i<_nY; ++i)
{
file << _kd[i] << std::endl;
}
file << std::endl;
for(int n=0; n<_n; ++n)
{
......
......@@ -16,8 +16,8 @@ test_kirby=1
test_alta=1
#fitter="matlab"
fitter="quadprog"
#fitter="cgal"
#fitter="quadprog"
fitter="cgal"
#fitter="parallel"
fitter_args="--min-np 1 --np 100 --min-nq 1 --nq 100"
......
......@@ -21,7 +21,7 @@ do
if [ $? -eq 0 ]; then
echo "Test number $i passed"
#./build/brdf2gnuplot --input tests/output_lafortune_$i.lafortune $function --data tests/input_$i.gnuplot --output tests/output_lafortune_$i.gnuplot > /dev/null
./build/brdf2gnuplot --input tests/output_lafortune_$i.lafortune $function --data tests/input_$i.gnuplot --output tests/output_lafortune_$i.gnuplot #> /dev/null
else
echo "Test number $i failed"
fi
......
......@@ -19,9 +19,6 @@
int main(int argc, char** argv)
{
// QCoreApplication::addLibraryPath() ;
// QCoreApplication::addLibraryPath(QString("/home/belcour/Projects/alta/sources/tests/plugin_loader/")) ;
QCoreApplication app(argc, argv, false);
arguments args(argc, argv) ;
......@@ -47,7 +44,7 @@ int main(int argc, char** argv)
return 1 ;
}
// if(fitters.size() > 0 && datas.size() > 0 && functions.size() > 0)
// if(fitters.size() > 0 && datas.size() > 0 && functions.size() > 0)
{
fit->set_parameters(args) ;
function* f = plugins_manager::get_function(args["func"]);
......@@ -76,92 +73,92 @@ int main(int argc, char** argv)
if(is_fitted)
{
std::cout << "<<INFO>> total time: " << hour << "h " << min << "m " << sec << "s" << std::endl ;
/*
vec min, max ;
min.assign(2, args.get_float("min", 0.0f)) ;
max.assign(2, args.get_float("max", 1.5f)) ;
/*
vec min, max ;
min.assign(2, args.get_float("min", 0.0f)) ;
max.assign(2, args.get_float("max", 1.5f)) ;
int nb_samples = args.get_int("nb_samples", 100) ;
double dt = (max[0]-min[0]) / nb_samples ;
int nb_samples = args.get_int("nb_samples", 100) ;
double dt = (max[0]-min[0]) / nb_samples ;
std::ofstream file(args["output"].c_str(), std::ios_base::trunc);
for(double x=min[0]; x<=max[0]; x+=dt)
{
std::ofstream file(args["output"].c_str(), std::ios_base::trunc);
for(double x=min[0]; x<=max[0]; x+=dt)
{
vec vx ; for(int i=0;i<2; ++i) { vx.push_back(x) ; }
file << x << "\t" << f->value(vx)[0] << std::endl ;
std::cout << x << "\t" << f->value(vx)[0] << std::endl ;
}
/*/
double L2 = f->L2_distance(d);
double Linf = f->Linf_distance(d);
std::cout << "<<INFO>> L2 distance to data = " << L2 << std::endl;
std::cout << "<<INFO>> Linf distance to data = " << Linf << std::endl;
f->save(args["output"], args) ;
#ifdef OLD // use brdf2gnuplot
size_t n = args["output"].find('.') ;
std::string gnuplot_filename = args["output"].substr(0,n);
gnuplot_filename.append(".gnuplot") ;
/*
f->save_gnuplot(gnuplot_filename, d, args);
/*/
std::ofstream file(gnuplot_filename.c_str(), std::ios_base::trunc);
for(int i=0; i<d->size(); ++i)
{
vec v = d->get(i) ;
// vec y1(d->dimY()) ;
// for(int k=0; k<d->dimY(); ++k) { y1[k] = v[d->dimX() + k] ; }
vec y2 = f->value(v) ;
for(int u=0; u<d->dimX(); ++u)
file << v[u] << "\t" ;
for(int u=0; u<d->dimY(); ++u)
file << y2[u] << "\t" ;
file << std::endl ;
}
/*/
double L2 = f->L2_distance(d);
double Linf = f->Linf_distance(d);
std::cout << "<<INFO>> L2 distance to data = " << L2 << std::endl;
std::cout << "<<INFO>> Linf distance to data = " << Linf << std::endl;
f->save(args["output"], args) ;
#ifndef OLD // use brdf2gnuplot
size_t n = args["output"].find('.') ;
std::string gnuplot_filename = args["output"].substr(0,n);
gnuplot_filename.append(".gnuplot") ;
/*
f->save_gnuplot(gnuplot_filename, d, args);
/*/
std::ofstream file(gnuplot_filename.c_str(), std::ios_base::trunc);
file.close();
//*/
std::string error_filename = args["output"].substr(0,n);
error_filename.append(".errorplot") ;
file.open(error_filename.c_str(), std::ios_base::trunc);
for(int i=0; i<d->size(); ++i)
{
vec v = d->get(i) ;
// vec y1(d->dimY()) ;
// for(int k=0; k<d->dimY(); ++k) { y1[k] = v[d->dimX() + k] ; }
vec y1(d->dimY()) ;
for(int k=0; k<d->dimY(); ++k) { y1[k] = v[d->dimX() + k] ; }
vec y2 = f->value(v) ;
for(int u=0; u<d->dimX(); ++u)
file << v[u] << "\t" ;
for(int u=0; u<d->dimY(); ++u)
file << y2[u] << "\t" ;
file << y2[u]-y1[u] << "\t" ;
file << std::endl ;
}
file.close();
//*/
std::string error_filename = args["output"].substr(0,n);
error_filename.append(".errorplot") ;
file.open(error_filename.c_str(), std::ios_base::trunc);
}
file.close();
std::string linerror_filename = args["output"].substr(0,n);
linerror_filename.append(".linearerrorplot") ;
file.open(linerror_filename.c_str(), std::ios_base::trunc);
for(int i=0; i<d->size(); ++i)
{
vec v = d->get(i) ;
vec y1(d->dimY()) ;
for(int k=0; k<d->dimY(); ++k) { y1[k] = v[d->dimX() + k] ; }
vec y1(d->dimY()) ;
for(int k=0; k<d->dimY(); ++k) { y1[k] = 0.5*(v[d->dimX() + k] +v[d->dimX()+d->dimY() + k]); }
vec y2 = f->value(v) ;
for(int u=0; u<d->dimX(); ++u)
file << v[u] << "\t" ;
file << i << "\t" ;
for(int u=0; u<d->dimY(); ++u)
file << y2[u]-y1[u] << "\t" ;
file << std::endl ;
file << y2[u]-y1[u] << "\t" ;
file << std::endl ;
}
file.close();
std::string linerror_filename = args["output"].substr(0,n);
linerror_filename.append(".linearerrorplot") ;
file.open(linerror_filename.c_str(), std::ios_base::trunc);
for(int i=0; i<d->size(); ++i)
{
vec v = d->get(i) ;
vec y1(d->dimY()) ;
for(int k=0; k<d->dimY(); ++k) { y1[k] = 0.5*(v[d->dimX() + k] +v[d->dimX()+d->dimY() + k]); }
vec y2 = f->value(v) ;
file << i << "\t" ;
for(int u=0; u<d->dimY(); ++u)
file << y2[u]-y1[u] << "\t" ;
file << std::endl ;
}
file.close();
//*/
file.close();
//*/
#endif
return 0;
}
......@@ -172,11 +169,11 @@ int main(int argc, char** argv)
}
}
/* else
{
/* else
{
std::cout << "<<ERROR>> not enough plugin defined" << std::endl ;
}
*/
}
*/
return 0 ;
}
......@@ -46,7 +46,7 @@ int main(int argc, char** argv)
if(d != NULL)
{
std::cout << "<<INFO>> will export " << d->size() << " elements" << std::endl ;
double theta_in = (double)args.get_float("theta", 0.0f);
double phi_in = (double)args.get_float("phi", 0.0f);
vec in(3), out(3) ;
......@@ -67,10 +67,10 @@ int main(int argc, char** argv)
file << phi << "\t" << theta << "\t" ;
for(int u=0; u<d->dimY(); ++u)
{
{
file << v[u] << "\t" ;
}
}
file << std::endl ;
}
}
......
......@@ -17,7 +17,14 @@
#include <limits>
#include <cstdlib>
#define EPSILON 1.0E-10
#define EPSILON 1.0E-5
bool is_close(double x, double y)
{
return std::abs(x - y) < EPSILON;
}
int parametrization_tests();
int main(int argc, char** argv)
{
......@@ -30,7 +37,7 @@ int main(int argc, char** argv)
// Parametrization tests
//
nb_tests_failed += parametrization_tests();
// Evaluation tests
//
......@@ -39,5 +46,35 @@ int main(int argc, char** argv)
std::cout << "<<INFO>> " << nb_tests_failed << " tests failed" << std::endl;
return nb_tests_failed;
}
int parametrization_tests()
{
// Params
int nb_tests_failed = 0;
// Test Rusinkevich parametrization
vec cart(6);
vec rusi(3);
// Equal directions test, when the PHI_D is ZERO
rusi[0] = 0.25*M_PI; rusi[1] = 0.0; rusi[2] = 0.0;
params::convert(&rusi[0], params::RUSIN_TH_TD_PD, params::CARTESIAN, &cart[0]);
const double dot = cart[0]*cart[3] + cart[1]*cart[4] + cart[2]*cart[5];
if(!is_close(cart[0], cart[3]) || !is_close(cart[1], cart[4]) ||
!is_close(cart[2], cart[5]) || !is_close(dot, 1.0))
{
std::cout << "<<DEBUG>> rusin 3d: " << rusi << std::endl;
std::cout << "<<DEBUG>> cartesian: " << cart << std::endl;
std::cout << "<<DEBUG>> dot: " << dot << std::endl;
std::cout << std::endl;
nb_tests_failed++;
}
return nb_tests_failed;
}
......@@ -9,4 +9,6 @@ LIBS += -L../../build -lcore
unix{
PRE_TARGETDEPS += ../../build/libcore.a
CONFIG += debug
}
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