Commit 6bc5dcf9 authored by Laurent Belcour's avatar Laurent Belcour

Moments export working for the mean

parent abddc9f7
......@@ -5,7 +5,7 @@ CONFIG *= static \
DESTDIR = ../build
QMAKE_CXXFLAGS += -std=c++0x
QMAKE_CXXFLAGS += -std=c++0x -m64
HEADERS = args.h \
common.h \
......
......@@ -49,10 +49,16 @@ class data : public parametrized
//!
//! \details
//! The input vector in (can have texture coordinate) and the output
//! vector out are taken to grad a value and return it. The two vectors
//! vector out are taken to grab a value and return it. The two vectors
//! should be compliant with the size and parametrization of the data.
virtual vec value(vec in, vec out) const = 0;
//! \brief Provide an evaluation in a BRDF way of the data.
//!
//! \details
//! The input vector must have the parametrization of the data.
virtual vec value(vec in) const = 0;
//! \brief Put the sample inside the data
virtual void set(vec x) = 0;
......@@ -123,6 +129,10 @@ class data_params : public data
{
NOT_IMPLEMENTED();
}
virtual vec value(vec in) const
{
NOT_IMPLEMENTED();
}
// Load data from a file
virtual void load(const std::string& filename)
......
......@@ -161,6 +161,19 @@ void params::from_cartesian(const double* invec, params::input outtype,
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::RUSIN_TH_TD_PD:
outvec[0] = acos(half[2]);
// 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[1] = acos(diff[2]);
outvec[2] = atan2(diff[0], diff[1]);
break;
case params::ISOTROPIC_TV_TL_DPHI:
outvec[0] = acos(invec[2]);
outvec[1] = 0.0;
......@@ -197,6 +210,7 @@ void params::from_cartesian(const double* invec, params::input outtype,
break;
default:
std::cout << "<<ERROR>> not defined input param: " << get_name(outtype) << std::endl;
assert(false);
break;
}
......
......@@ -234,7 +234,6 @@ class parametrized
parametrized() : _in_param(params::UNKNOWN_INPUT),
_out_param(params::UNKNOWN_OUTPUT) { }
//! \brief provide the input parametrization of the object.
virtual params::input parametrization() const
{
......
......@@ -37,6 +37,10 @@ class vertical_segment : public data
{
NOT_IMPLEMENTED();
}
virtual vec value(vec in) const
{
NOT_IMPLEMENTED();
}
//! \brief Put the sample inside the data
virtual void set(vec x);
......
......@@ -39,6 +39,12 @@ data_merl::data_merl()
{
const int n = BRDF_SAMPLING_RES_PHI_D/2 * BRDF_SAMPLING_RES_THETA_D * BRDF_SAMPLING_RES_THETA_H;
brdf = (double*) malloc (sizeof(double)*3*n);
// Set the input and output parametrization
_in_param = params::RUSIN_TH_TD_PD;
_out_param = params::RGB_COLOR;
_nX = 3;
_nY = 3;
}
// cross product of two vectors
......@@ -202,6 +208,10 @@ void lookup_brdf_val(double* brdf, double theta_in, double fi_in,
std_coords_to_half_diff_coords(theta_in, fi_in, theta_out, fi_out,
theta_half, fi_half, theta_diff, fi_diff);
// Testing the input domain
assert(theta_half >= 0.0); assert(theta_half <= 0.5*M_PI);
assert(theta_diff >= 0.0); assert(theta_diff <= 0.5*M_PI);
assert(fi_diff >= 0.0); assert(fi_diff <= 2.0*M_PI);
// Find index.
// Note that phi_half is ignored, since isotropic BRDFs are assumed
......@@ -216,7 +226,7 @@ void lookup_brdf_val(double* brdf, double theta_in, double fi_in,
if (red_val < 0.0 || green_val < 0.0 || blue_val < 0.0)
fprintf(stderr, "Below horizon.\n");
fprintf(stderr, "Negative value [%f, %f, %f].\n", theta_half, theta_diff, fi_diff);
}
......@@ -335,6 +345,20 @@ vec data_merl::value(vec in, vec out) const
res[2] = b;
return res;
}
vec data_merl::value(vec in) const
{
double r, g, b;
double t_in[4];
params::convert(&in[0], params::RUSIN_TH_TD_PD, params::SPHERICAL_TL_PL_TV_PV, t_in);
lookup_brdf_val(brdf, t_in[0], t_in[1], t_in[2], t_in[3], r, g, b) ;
vec res(3);
res[0] = r;
res[1] = g;
res[2] = b;
return res;
}
// Get data size, e.g. the number of samples to fit
int data_merl::size() const
......
......@@ -13,7 +13,7 @@ class data_merl : public QObject, public data
public: // methods
data_merl();
data_merl();
// Load data from a file
virtual void load(const std::string& filename) ;
......@@ -24,18 +24,15 @@ class data_merl : public QObject, public data
// Acces to data
virtual vec get(int i) const ;
virtual vec operator[](int i) const ;
virtual vec value(vec in, vec out) const ;
virtual vec value(vec in) const;
// Set data
virtual void set(vec x);
// Get data size, e.g. the number of samples to fit
virtual int size() const ;
virtual params::input parametrization() const
{
return params::RUSIN_TH_TD_PD;
}
// Get min and max input space values
virtual vec min() const ;
......
......@@ -276,7 +276,7 @@ bool rational_fitter_quadprog::fit_data(const vertical_segment* dat, int np, int
#endif
return false ;
}
else if(delta == 0.0)
else if(delta <= 0.0)
{
delta = 1.0 ;
}
......@@ -288,8 +288,8 @@ bool rational_fitter_quadprog::fit_data(const vertical_segment* dat, int np, int
for(int i=0; i<2*d->size(); ++i)
{
ci[i] = ci[i] * delta ;
#ifdef DEBUG
std::cout << ci[i] << "\t" ;
#ifndef DEBUG
std::cout << i << "\t" << -ci[i] << std::endl ;
#endif
}
#ifdef DEBUG
......
......@@ -16,17 +16,12 @@ test_kirby=1
test_alta=1
test_merl=0
#fitter="matlab"
#fitter="quadprog"
#fitter="cgal"
#fitter="parallel"
fitter="eigen"
fitters="matlab quadprog parallel eigen cgal"
#fitter_args="--min-np 1 --np 100 --min-nq 1 --nq 100"
fitter_args="--np 10 --nq 10"
fitter_args="--np 2 --nq 2"
#Use the DCA optimizer afterwards
use_dca=1
use_dca=0
mkdir tests
......@@ -38,21 +33,27 @@ 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${function_append}_${i}.rational $function --fitter /build/librational_fitter_${fitter}.so ${fitter_args} --dt 0.1 $relative > tests/output${function_append}_${i}.out
for fitter in ${fitters};
do
echo "Using fitter ${fitter} with generated data";
echo "------------------------------------------";
./build/data2brdf --input tests/input_${i}.gnuplot --output tests/output${function_append}_${i}_${fitter}.rational $function --fitter /build/librational_fitter_${fitter}.so ${fitter_args} --dt 0.1 $relative > tests/output${function_append}_${i}_${fitter}.out
if [ $? -eq 0 ]; then
echo "Test number ${i} passed"
./build/brdf2gnuplot --input tests/output${function_append}_${i}.rational $function --data tests/input_${i}.gnuplot --output tests/output_${i}.gnuplot > /dev/null
./build/brdf2gnuplot --input tests/output${function_append}_${i}_${fitter}.rational $function --data tests/input_${i}.gnuplot --output tests/output_${i}_${fitter}.gnuplot > /dev/null
#DCA Optimization
if [ $use_dca -eq 1 ]; then
./build/data2brdf --input tests/input_${i}.gnuplot --output tests/output${function_append}_${i}_dca.rational $function --fitter /build/librational_fitter_dca.so --bootstrap tests/output${function_append}_${i}.rational > tests/output${function_append}_${i}_dca.out
./build/data2brdf --input tests/input_${i}.gnuplot --output tests/output${function_append}_${i}_${fitter}_dca.rational $function --fitter /build/librational_fitter_dca.so --bootstrap tests/output${function_append}_${i}_${fitter}.rational > tests/output${function_append}_${i}_${fitter}_dca.out
if [ $? -eq 0 ]; then
echo "Optimized using DCA"
./build/brdf2gnuplot --input tests/output${function_append}_${i}_dca.rational $function --data tests/input_${i}.gnuplot --output tests/output_${i}_dca.gnuplot > /dev/null
./build/brdf2gnuplot --input tests/output${function_append}_${i}_${fitter}_dca.rational $function --data tests/input_${i}.gnuplot --output tests/output_${i}_${fitter}_dca.gnuplot > /dev/null
fi
fi
......@@ -61,6 +62,10 @@ do
else
echo "Test number $i failed"
fi
echo "\n\n";
done
done
fi
......
......@@ -23,7 +23,7 @@ int main(int argc, char** argv)
plugins_manager manager(args) ;
if(args.is_defined("help")) {
std::cout << "<<HELP>> data2moments --input data.file --output gnuplot.file --data loader.so --param RUSIN_TH_PH_TD_PD --partial 0" << std::endl ;
std::cout << "<<HELP>> data2moments --input data.file --output gnuplot.file --data loader.so" << std::endl ;
std::cout << " - input, output and data are mandatory parameters" << std::endl ;
return 0 ;
}
......@@ -40,10 +40,6 @@ int main(int argc, char** argv)
std::cerr << "<<ERROR>> the data loader is not defined" << std::endl ;
return 1 ;
}
if(! args.is_defined("param")) {
std::cerr << "<<ERROR>> the parametrization is not defined" << std::endl ;
return 1 ;
}
// Import data
data* d = NULL ;
......@@ -55,17 +51,50 @@ int main(int argc, char** argv)
if(d != NULL)
{
//vec L(3), V(3), tempParam(params::dimension(p_in)), tempCart(6);
for(int i=0; i<d->size(); ++i)
// Data parametrization
params::input data_param = d->parametrization();
int d_size = params::dimension(data_param);
double in_angle[4] = {0.0, 0.0, 0.0, 0.0} ;
// Sample every degree
double dtheta = 0.5*M_PI / 90.0;
// Moments
vec mean(d->dimY());
for(int theta_in=0; theta_in<90; theta_in++)
{
// Copy the input vector
vec x = d->get(i);
vec out_x = x;
in_angle[0] = theta_in * 0.5*M_PI / 90.0;
// Integrate over the light hemisphere
for(int theta_out=0; theta_out<90; theta_out++)
{
in_angle[2] = theta_out * 0.5*M_PI / 90.0;
for(int phi_out=0; phi_out<180; phi_out++)
{
in_angle[3] = theta_out * 0.5*M_PI / 180.0;
vec in(d_size);
params::convert(in_angle, params::SPHERICAL_TL_PL_TV_PV, data_param, &in[0]);
// Copy the input vector
vec x = d->value(in);
for(int i=0; i<mean.size(); ++i)
mean[i] += x[i];
}
}
for(int i=0; i<mean.size(); ++i)
mean[i] /= 180.0*90.0;
// Convert input to required param
//params::convert(&x[0], d->parametrization(), p_in, &tempParam[0]);
// Output the value into the file
file << in_angle[0] << "\t";
for(int i=0; i<mean.size(); ++i)
file << mean[i] << "\t";
file << std::endl;
// TODO Integrate
}
file.close();
......
......@@ -12,7 +12,7 @@ int main(int argc, char** argv)
std::cout.precision(10);
int nbx = 100;
int nbx = 10000;
int nby = 100;
int nbz = 100;
if(args.is_defined("nbx"))
......@@ -30,9 +30,9 @@ int main(int argc, char** argv)
{
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 = (1.0) / (1.0E-10 + 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)
......
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