Commit 10076200 authored by Laurent Belcour's avatar Laurent Belcour

Updating the interface of data to incorporate an index based set function.

parent ec2f94ea
......@@ -281,7 +281,7 @@ throw
// Mathematical definition not provided on the Window plateform
#ifdef _WIN32
#define M_PI 3.14159265
#define M_PI 3.1415926535897932384626433832795
template<typename T> bool isnan(T x)
{
......
......@@ -58,25 +58,19 @@ class data : public parametrized
// Acces to data
virtual vec get(int i) const = 0 ;
virtual vec operator[](int i) const = 0 ;
/*
//! \brief Provide an evaluation in a BRDF way of the data.
//!
//! \details
//! The input vector in (can have texture coordinate) and the output
//! 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.
//! \brief Provide an evaluation of the data using interpolation. If
//! the data object does not provide an interpolation mechanism, it
//! should throw an exception.
//!
//! \details
//! The input vector must have the parametrization of the data.
virtual vec value(vec in) const = 0;
//! The input vector must have the parametrization of the data, and
//! match the total dimension: dimX + dimY.
virtual vec value(const vec& in) const = 0;
//! \brief Put the sample inside the data
virtual void set(vec x) = 0;
virtual void set(const vec& x) = 0;
virtual void set(int i, const vec& x) = 0;
// Get data size, e.g. the number of samples to fit
......@@ -130,11 +124,7 @@ class data_params : public data
save(std::string("cluster.gnuplot"));
}
virtual vec value(vec, vec) const
{
NOT_IMPLEMENTED();
}
virtual vec value(vec) const
virtual vec value(const vec&) const
{
NOT_IMPLEMENTED();
}
......@@ -163,11 +153,16 @@ class data_params : public data
}
//! \todo This should crash at execution.
virtual void set(vec x)
virtual void set(const vec& x)
{
this->set(x);
}
virtual void set(int i, const vec& x)
{
this->set(i, x);
}
// Get data size, e.g. the number of samples to fit
virtual int size() const
{
......
......@@ -369,6 +369,12 @@ class params
class parametrized
{
public:
parametrized(params::input in_param, params::output out_param) {
_in_param = in_param;
_out_param = out_param;
_nX = params::dimension(_in_param);
_nY = params::dimension(_out_param);
}
parametrized() : _in_param(params::UNKNOWN_INPUT),
_out_param(params::UNKNOWN_OUTPUT) { }
......
......@@ -286,12 +286,18 @@ vec vertical_segment::get(int i) const
//! \todo Check the vertical segment size and if the data
//! is not already present.
void vertical_segment::set(vec x)
void vertical_segment::set(const vec& x)
{
// assert(x.size() == dimX() + dimY() || x.size() == dimX() + 3*dimY());
_data.push_back(x);
}
void vertical_segment::set(int i, const vec& x)
{
// assert(x.size() == dimX() + dimY() || x.size() == dimX() + 3*dimY());
_data[i] = x;
}
int vertical_segment::size() const
{
return _data.size() ;
......
......@@ -90,18 +90,16 @@ class vertical_segment : public data
// Acces to data
virtual vec get(int i) const ;
virtual vec operator[](int i) const ;
virtual vec value(vec, vec) const
{
NOT_IMPLEMENTED();
}
virtual vec value(vec) const
virtual vec operator[](int i) const;
virtual vec value(const vec&) const
{
NOT_IMPLEMENTED();
}
//! \brief Put the sample inside the data
virtual void set(vec x);
virtual void set(const vec& x);
virtual void set(int i, const vec& x);
//! \brief Specific accessor to a vertical segment, this gives the
//! complete vector, plus the ordinate segment
......
......@@ -2,6 +2,7 @@
SConscript('data_merl/SConscript')
SConscript('data_brdf_slice/SConscript')
SConscript('data_interpolant/SConscript')
#SConscript('data_io/SConscript')
# # Building nonlinear fitters
SConscript('nonlinear_fitter_ceres/SConscript')
......@@ -31,6 +32,7 @@ SConscript('rational_fitter_leastsquare/SConscript')
SConscript('rational_fitter_quadprog/SConscript')
SConscript('rational_fitter_parallel/SConscript')
SConscript('rational_fitter_matlab/SConscript')
SConscript('rational_fitters/SConscript')
# # Building rational functions
......
......@@ -66,7 +66,7 @@ void data_astm::load(const std::string& filename, const arguments& args)
}
// Acces to data
vec data_astm::get(int i) const
vec& data_astm::get(int i)
{
return _data[i];
}
......
......@@ -28,7 +28,7 @@ class data_astm : public QObject, public data
// Acces to data
virtual vec get(int i) const ;
virtual vec operator[](int i) const ;
virtual vec& operator[](int i) ;
virtual vec value(vec in, vec out) const ;
// Get data size, e.g. the number of samples to fit
......
......@@ -10,6 +10,10 @@
#ifndef EXR_IO_H_
#define EXR_IO_H_
/*
* Author: Cyril Soler
*/
#include <stdexcept>
......
......@@ -78,7 +78,7 @@ vec data_brdf_slice::operator[](int i) const
}
//! \todo Test this function
void data_brdf_slice::set(vec x)
void data_brdf_slice::set(const vec& x)
{
assert(x.size() == 6);
assert(x[0] <= 0.5*M_PI && x[0] >= 0.0);
......@@ -93,13 +93,16 @@ void data_brdf_slice::set(vec x)
_data[3*id + 1] = x[4];
_data[3*id + 2] = x[5];
}
vec data_brdf_slice::value(vec, vec) const
void data_brdf_slice::set(int id, const vec& x)
{
vec res(3);
return res;
assert(x.size() == 3);
_data[3*id + 0] = x[0];
_data[3*id + 1] = x[1];
_data[3*id + 2] = x[2];
}
vec data_brdf_slice::value(vec x) const
vec data_brdf_slice::value(const vec& x) const
{
assert(x[0] <= 0.5*M_PI && x[0] >= 0.0);
assert(x[1] <= 0.5*M_PI && x[1] >= 0.0);
......
......@@ -31,11 +31,11 @@ class data_brdf_slice : public 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 x) const;
virtual vec value(const vec& x) const;
// Set data
virtual void set(vec x);
virtual void set(int i, const vec& x);
virtual void set(const vec& x);
// Get data size, e.g. the number of samples to fit
virtual int size() const ;
......
......@@ -342,13 +342,13 @@ vec data_merl::get(int i) const
res[5] = brdf[i + BRDF_SAMPLING_RES_THETA_H*BRDF_SAMPLING_RES_THETA_D*BRDF_SAMPLING_RES_PHI_D] * BLUE_SCALE;
return res ;
}
vec data_merl::operator[](int i) const
vec data_merl::operator[](int i) const
{
return get(i) ;
}
//! \todo Test this function
void data_merl::set(vec x)
void data_merl::set(const vec& x)
{
assert(x.size() == 6);
const int phid_ind = phi_diff_index(x[2]);
......@@ -366,7 +366,15 @@ void data_merl::set(vec x)
brdf[i + BRDF_SAMPLING_RES_THETA_H*BRDF_SAMPLING_RES_THETA_D*BRDF_SAMPLING_RES_PHI_D] = x[5] / BLUE_SCALE;
}
vec data_merl::value(vec in) const
void data_merl::set(int i, const vec& x)
{
assert(x.size() == 3);
brdf[i] = x[0] / RED_SCALE;
brdf[i + BRDF_SAMPLING_RES_THETA_H*BRDF_SAMPLING_RES_THETA_D*BRDF_SAMPLING_RES_PHI_D/2] = x[1] / GREEN_SCALE;
brdf[i + BRDF_SAMPLING_RES_THETA_H*BRDF_SAMPLING_RES_THETA_D*BRDF_SAMPLING_RES_PHI_D] = x[2] / BLUE_SCALE;
}
vec data_merl::value(const vec& in) const
{
double r, g, b;
lookup_brdf_val(brdf, in[0], in[1], in[2], r, g, b) ;
......
......@@ -27,13 +27,14 @@ class data_merl : public data
virtual void save(const std::string& filename) const ;
// Acces to data
virtual vec get(int i) const ;
virtual vec operator[](int i) const ;
virtual vec get(int i) const;
virtual vec operator[](int i) const;
virtual vec value(vec in) const;
virtual vec value(const vec& in) const;
// Set data
virtual void set(vec x);
virtual void set(int i, const vec& x);
virtual void set(const vec& x);
// Get data size, e.g. the number of samples to fit
virtual int size() const ;
......
......@@ -155,7 +155,7 @@ BOOST_PYTHON_MODULE(alta)
bp::class_<data, ptr<data>, boost::noncopyable>("data", bp::no_init)
.def("size", &data::size)
.def("get", &data::get)
.def("set", &data::set)
//.def("set", &data::set)
.def("load", static_cast< void(data::*)(const std::string&)>(&data::load))
.def("save", &data::save);
bp::def("get_data", plugins_manager::get_data);
......
......@@ -4,4 +4,6 @@ SConscript('data2moments/SConscript')
SConscript('brdf2brdf/SConscript')
SConscript('brdf2data/SConscript')
SConscript('brdf2gnuplot/SConscript')
\ No newline at end of file
SConscript('brdf2gnuplot/SConscript')
#SConscript('tests/SConscript')
......@@ -95,6 +95,11 @@ int main(int argc, char** argv)
if(d && f != NULL)
{
// Is the output data file already allocated and has the same size
// than the training data ?
const bool out_filled = d->size() == d_out->size();
const bool output_dif = args.is_defined("export-diff");
vec temp(f->dimX());
for(int i=0; i<d->size(); ++i)
{
......@@ -111,12 +116,17 @@ int main(int argc, char** argv)
}
vec y = f->value(temp);
for(int j=0; j<d->dimY(); ++j)
{
x[d->dimX() + j] = y[j];
for(int j=0; j<d->dimY(); ++j) {
x[d->dimX() + j] = (output_dif) ? x[d->dimX() + j] - y[j] : y[j];
}
d_out->set(x);
// If the output data is already allocated and has the same size
// than the training data, we do simple copy of the index elements.
if(out_filled) {
d_out->set(i, y);
} else {
d_out->set(x);
}
}
d_out->save(args["output"]);
......
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions
Copyright (C) 2013 Inria
......@@ -8,6 +9,29 @@
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <core/param.h>
int main(int argc, char** argv) {
spherical sphericalParam;
isotropic_tl_tv isotropicParam;
vec in(4);
in[0] = 0.0;
in[1] = 0.0;
in[2] = 0.0;
in[3] = 0.0;
vec out(2);
sphericalParam.convert_to(in, isotropicParam, out);
return 0;
}
#ifdef OLD
#include <core/args.h>
#include <core/data.h>
#include <core/function.h>
......@@ -208,3 +232,5 @@ int parametrization_tests()
*/
return nb_tests_failed;
}
#endif
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