Commit 4b89bdbf authored by Laurent Belcour's avatar Laurent Belcour

Adding test suite for Lafortune

parent 7bef7190
......@@ -82,7 +82,7 @@ void params::to_cartesian(const double* invec, params::input intype,
break;
case params::RUSIN_TH_TD:
half_to_cartesian(invec[0], 0.0, invec[1], 0.5*M_PI, outvec);
half_to_cartesian(invec[0], 0.0, invec[1], 0.0, outvec);
break;
// 3D Parametrization
......
......@@ -167,8 +167,8 @@ class params
//! \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);
rotate_normal(out, phi_h);
// Compute the out vector from the in vector and the half
// vector.
......@@ -211,8 +211,8 @@ class params
const double cost = cos(theta);
const double sint = sin(theta);
vec[0] = cost * vec[0] - sint * vec[2];
vec[2] = sint * vec[0] + cost * vec[2];
vec[1] = cost * vec[1] - sint * vec[2];
vec[2] = sint * vec[1] + cost * vec[2];
}
static void print_input_params();
......
......@@ -55,8 +55,6 @@ vec lafortune_function::value(const vec& x) const
const double d = Cx*dx + Cy*dy + Cz*dz;
if(d > 0.0)
res[i] += pow(d, N);
else
res[i] += 0.0;
}
}
......@@ -102,8 +100,6 @@ vec lafortune_function::value(const vec& x, const vec& p) const
const double d = Cx*dx + Cy*dy + Cz*dz;
if(d > 0.0)
res[i] += pow(d, N);
else
res[i] += 0.0;
}
}
......
#! /bin/sh
## Params
function="--func ./build/libnonlinear_function_lafortune.so"
fitter="--fitter ./build/libnonlinear_levenberg_eigen.so"
test_generated=1
test_alta=0
mkdir tests
## Test with generated data
##
if [ $test_generated -eq 1 ]; then
min_test=7; max_test=8
for i in `seq $min_test $max_test`
do
./build/generate_data --f $i
mv input.gnuplot tests/input_$i.gnuplot
./build/data2brdf --input tests/input_$i.gnuplot --output tests/output_lafortune_$i.lafortune ${function} ${fitter} ${fitter_args} > tests/output_lafortune_$i.out
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
else
echo "Test number $i failed"
fi
done
fi
## Test with ALTA internal data
##
if [ $test_alta -eq 1 ]; then
./build/data2brdf --input ../data/2d/matusik_merl/beige-fabric-double-cc-cos-th-td-90deg.dat --output tests/beige.lafortune ${function} ${fitter} ${fitter_args} > tests/beige_lafortune.out
if [ $? -eq 0 ]; then
echo "Test beige matusik passed"
./build/brdf2gnuplot --input tests/beige.lafortune $function --data ../data/2d/matusik_merl/beige-fabric-double-cc-cos-th-td-90deg.dat --output tests/beige_lafortune.gnuplot > /dev/null
else
echo "Test beige matusik failed"
fi
fi
......@@ -79,29 +79,29 @@ int main(int argc, char** argv)
vec v = d->get(i) ;
vec y2 = f->value(v) ;
if(!linear_plot)
{
for(int u=0; u<d->dimX(); ++u)
file << v[u] << "\t" ;
}
else
{
file << i << "\t" ;
}
if(!linear_plot)
{
for(int u=0; u<d->dimX(); ++u)
file << v[u] << "\t" ;
}
else
{
file << i << "\t" ;
}
for(int u=0; u<d->dimY(); ++u)
{
if(plot_error)
{
file << (v[d->dimX() + u] - y2[u])/v[d->dimX()+u] << "\t" ;
}
else if(linear_plot)
{
file << (v[d->dimX() + u] - y2[u])/v[d->dimX()+u] << "\t" ;
}
else
{
file << y2[u] << "\t" ;
if(plot_error)
{
file << (v[d->dimX() + u] - y2[u])/v[d->dimX()+u] << "\t" ;
}
else if(linear_plot)
{
file << (v[d->dimX() + u] - y2[u])/v[d->dimX()+u] << "\t" ;
}
else
{
file << y2[u] << "\t" ;
}
}
......
......@@ -5,7 +5,7 @@
#include <core/fitter.h>
#include <core/plugins_manager.h>
#include <QApplication>
#include <QCoreApplication>
#include <iostream>
#include <vector>
......@@ -17,7 +17,7 @@
int main(int argc, char** argv)
{
QApplication app(argc, argv, false);
QCoreApplication app(argc, argv, false);
arguments args(argc, argv) ;
plugins_manager manager(args) ;
......
......@@ -10,7 +10,7 @@ int main(int argc, char** argv)
std::ofstream f("input.gnuplot") ;
arguments args(argc, argv);
std::cout.precision(10);
std::cout.precision(10);
int nbx = 100;
int nby = 100;
......@@ -24,30 +24,30 @@ int main(int argc, char** argv)
if(k == 1)
{
f << "#DIM 1 1" << std::endl ;
f << "#PARAM_IN UNKNOWN" << std::endl;
//f << "#VS 2" << std::endl;
f << "#PARAM_IN UNKNOWN" << std::endl;
//f << "#VS 2" << std::endl;
for(int i=0; i<nbx; ++i)
{
const float x = i / (float)nbx ;
//const float y = 100.0f * exp(-10.0 * x*x) * x*x - 0.01 *x*x*x + 0.1 ;
const float y = (1.0) / (1.0E-10 + x*x*x);
//const float y = 100.0f * exp(-10.0 * x*x) * x*x - 0.01 *x*x*x + 0.1 ;
const float y = (1.0) / (1.0E-10 + x*x*x);
f << x << "\t" << y << "\t" << y*0.9f << "\t" << y*1.1f << std::endl ;
f << x << "\t" << y << "\t" << y*0.9f << "\t" << y*1.1f << std::endl ;
}
}
else if(k == 2)
{
f << "#DIM 1 1" << std::endl ;
f << "#PARAM_IN UNKNOWN" << std::endl;
for(int i=0; i<nbx; ++i)
{
const float x = i / (float)nbx ;
const float y = (1.0 + 7.0*x - 10.5*x*x) / (1.0 + 7.0 * x) ;
f << x << "\t" << y << "\t" << 0.1f << std::endl ;
}
}
else if(k == 3)
else if(k == 2)
{
f << "#DIM 1 1" << std::endl ;
f << "#PARAM_IN UNKNOWN" << std::endl;
for(int i=0; i<nbx; ++i)
{
const float x = i / (float)nbx ;
const float y = (1.0 + 7.0*x - 10.5*x*x) / (1.0 + 7.0 * x) ;
f << x << "\t" << y << "\t" << 0.1f << std::endl ;
}
}
else if(k == 3)
{
f << "#DIM 2 1" << std::endl ;
for(int i=0; i<nbx; ++i)
......@@ -55,123 +55,126 @@ int main(int argc, char** argv)
{
const float x = i / (float)nbx ;
const float y = j / (float)nby ;
const float z = 10 * x + 1.0;
f << x << "\t" << y << "\t" << z << "\t" << z-0.1f << "\t" << z << std::endl ;
const float z = 10 * x + 1.0;
f << x << "\t" << y << "\t" << z << "\t" << z-0.1f << "\t" << z << std::endl ;
}
}
else if(k == 4)
else if(k == 4)
{
f << "#DIM 2 1" << std::endl ;
f << "#PARAM_IN UNKNOWN" << std::endl;
f << "#PARAM_IN UNKNOWN" << std::endl;
for(int i=0; i<nbx; ++i)
for(int j=0; j<nby; ++j)
{
const float x = i / (float)nbx ;
const float y = j / (float)nby ;
const float z = x*y / (1.0E-3 + x*x*x) + 10.;
const float z = x*y / (1.0E-3 + x*x*x) + 10.;
f << x << "\t" << y << "\t" << z << std::endl ;
f << x << "\t" << y << "\t" << z << std::endl ;
}
}
else if(k == 5)
else if(k == 5)
{
f << "#DIM 1 1" << std::endl ;
f << "#PARAM_IN COS_TH" << std::endl;
for(int i=0; i<nbx; ++i)
{
const double 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 ;
// f << "\t" << z2 ;
// f << "\t" << z3 ;
f << std::endl ;
const double 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 ;
// f << "\t" << z2 ;
// f << "\t" << z3 ;
f << std::endl ;
}
}
else if(k == 6)
else if(k == 6)
{
f << "#DIM 1 1" << std::endl ;
f << "#PARAM_IN COS_TH" << std::endl;
for(int i=0; i<nbx; ++i)
{
const double x = i / (float)nbx ;
const double z = 0.1 + 0.5 * std::pow(x, 1.5) ;
f << x << "\t" << z << std::endl ;
const double x = i / (float)nbx ;
const double z = 0.1 + 0.5 * std::pow(x, 1.5) ;
f << x << "\t" << z << std::endl ;
}
}
// Lafortune fitting
// Single lobe (0.86, 0.77, 18.6)
else if(k == 7)
{
f << "#DIM 2 1" << std::endl ;
f << "#PARAM_IN RUSIN_TH_TD" << std::endl;
for(int i=0; i<nbx; ++i)
{
for(int j=0; j<nby; ++j)
{
double in_r[2], in_c[6];
in_r[0] = M_PI * 0.5 * i / (float)nbx ;
in_r[1] = M_PI * 0.5 * j / (float)nby ;
params::convert(in_r, params::RUSIN_TH_TD, params::CARTESIAN, in_c);
const double Cx =0.86;
const double Cz =0.77;
const double n = 18.6;
const double cos = Cx * (in_c[0]*in_c[3] + in_c[1]*in_c[4]) + Cz*in_c[2]*in_c[5];
if(cos > 0.0)
{
const double z = std::pow(cos, n) ;
f << in_r[0] << "\t" << in_r[1] << "\t" << z << std::endl ;
}
else
{
f << in_r[0] << "\t" << in_r[1] << "\t" << 0.0 << std::endl ;
}
}
}
}
// Lafortune fitting
// Triple lobe (0.86, 0.77, 18.6), (-0.41, 0.018, 2.58), (-1.03, 0.7, 63.8)
else if(k == 8)
{
f << "#DIM 2 1" << std::endl ;
f << "#PARAM_IN RUSIN_TH_TD" << std::endl;
for(int i=0; i<=90; ++i)
{
for(int j=0; j<=90; ++j)
{
double in_r[2], in_c[6];
in_r[0] = M_PI * 0.5 * i / (double)90 ;
in_r[1] = M_PI * 0.5 * j / (double)90 ;
params::convert(in_r, params::RUSIN_TH_TD, params::CARTESIAN, in_c);
const double Cx[3] = {0.86, -0.410, -1.03};
const double Cz[3] = {0.77, 0.018, 0.70};
const double n[3] = {18.6, 2.580, 63.8};
double z = 0.0;
for(int k=0; k<3; ++k)
{
const double cos = Cx[k] * (in_c[0]*in_c[3] + in_c[1]*in_c[4]) + Cz[k]*in_c[2]*in_c[5];
if(cos > 0.0)
{
z += std::pow(cos, n[k]) ;
}
}
f << in_r[0] << "\t" << in_r[1] << "\t" << z << std::endl ;
}
}
}
// Lafortune fitting
// Single lobe (0.86, 0.77, 18.6)
else if(k == 7)
{
f << "#DIM 2 1" << std::endl ;
f << "#PARAM_IN RUSIN_TH_TD" << std::endl;
for(int i=0; i<nbx; ++i)
{
for(int j=0; j<nby; ++j)
{
double in_r[2], in_c[6];
in_r[0] = M_PI * 0.5 * i / (float)nbx ;
in_r[1] = M_PI * 0.5 * j / (float)nby ;
params::convert(in_r, params::RUSIN_TH_TD, params::CARTESIAN, in_c);
const double Cx =0.86;
const double Cz =0.77;
const double n = 18.6;
const double cos = Cx * (in_c[0]*in_c[3] + in_c[1]*in_c[4]) + Cz*in_c[2]*in_c[5];
if(cos > 0.0)
{
const double z = std::pow(cos, n) ;
f << in_r[0] << "\t" << in_r[1] << "\t" << z << std::endl ;
}
}
}
}
// Lafortune fitting
// Triple lobe (0.86, 0.77, 18.6), (-0.41, 0.018, 2.58), (-1.03, 0.7, 63.8)
else if(k == 8)
{
f << "#DIM 2 1" << std::endl ;
f << "#PARAM_IN RUSIN_TH_TD" << std::endl;
for(int i=0; i<nbx; ++i)
{
for(int j=0; j<nby; ++j)
{
double in_r[2], in_c[6];
in_r[0] = M_PI * 0.5 * i / (float)nbx ;
in_r[1] = M_PI * 0.5 * j / (float)nby ;
params::convert(in_r, params::RUSIN_TH_TD, params::CARTESIAN, in_c);
const double Cx[3] = {0.86, -0.410, -1.03};
const double Cz[3] = {0.77, 0.018, 0.70};
const double n[3] = {18.6, 2.580, 63.8};
double z = 0.0;
for(int k=0; k<3; ++k)
{
const double cos = Cx[k] * (in_c[0]*in_c[3] + in_c[1]*in_c[4]) + Cz[k]*in_c[2]*in_c[5];
if(cos > 0.0)
{
z += std::pow(cos, n[k]) ;
}
}
f << in_r[0] << "\t" << in_r[1] << "\t" << z << std::endl ;
}
}
}
return 0 ;
}
......@@ -6,4 +6,5 @@ SUBDIRS = generate_data \
data2gnuplot \
data2diff \
data2moments \
tests \
# fourieranalysis
#include <core/args.h>
#include <core/data.h>
#include <core/function.h>
#include <core/fitter.h>
#include <core/plugins_manager.h>
#include <QPluginLoader>
#include <QtPlugin>
#include <QCoreApplication>
#include <QDir>
#include <QTime>
#include <iostream>
#include <vector>
#include <iostream>
#include <fstream>
#include <limits>
#include <cstdlib>
#define EPSILON 1.0E-10
int main(int argc, char** argv)
{
QCoreApplication app(argc, argv, false);
arguments args(argc, argv) ;
plugins_manager manager(args) ;
int nb_tests_failed = 0;
// Parametrization tests
//
// Evaluation tests
//
std::cout << "<<INFO>> " << nb_tests_failed << " tests failed" << std::endl;
return nb_tests_failed;
}
CONFIG += qt \
console
DESTDIR = ../../build
INCLUDEPATH += ../../ ../../libs/rational_1d \
SOURCES += main.cpp
LIBS += -L../../build -lcore
unix{
PRE_TARGETDEPS += ../../build/libcore.a
}
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