diff --git a/sources/core/common.h b/sources/core/common.h index 12c9c6bbb2c1406c0329a429bca2f3819398c691..e6273eabe06c8b3b20f1830116049333c4fd175e 100644 --- a/sources/core/common.h +++ b/sources/core/common.h @@ -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 bool isnan(T x) { diff --git a/sources/core/data.h b/sources/core/data.h index 5c7dae270860cc66a414e1ee8c79b409eb62804d..17ad348c50a5c96f0ec84fe057f00b729fe24502 100644 --- a/sources/core/data.h +++ b/sources/core/data.h @@ -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 { diff --git a/sources/core/params.h b/sources/core/params.h index 0f28c89f99fbcfe97d0089e55e150811b88bb47f..e33fcd89d12dd299c3e93b791c7878bb6e853cf4 100644 --- a/sources/core/params.h +++ b/sources/core/params.h @@ -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) { } diff --git a/sources/core/vertical_segment.cpp b/sources/core/vertical_segment.cpp index 605a2857973caafd8f79663fdd7df9caa3debcea..227e88e4553c1e338417b2ff809aea5d56157bcc 100644 --- a/sources/core/vertical_segment.cpp +++ b/sources/core/vertical_segment.cpp @@ -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() ; diff --git a/sources/core/vertical_segment.h b/sources/core/vertical_segment.h index dc989f2cbf673c283d3827eaea1e992503639f4a..a524e92b912fac0fd045fc39842178c8d22ee648 100644 --- a/sources/core/vertical_segment.h +++ b/sources/core/vertical_segment.h @@ -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 diff --git a/sources/plugins/SConscript b/sources/plugins/SConscript index ddffdb2c2442f9293e4b24453fdbffd4d33f969c..46f148390961a8620a1be779e3db5db3588baf7f 100644 --- a/sources/plugins/SConscript +++ b/sources/plugins/SConscript @@ -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 diff --git a/sources/plugins/data_astm/data.cpp b/sources/plugins/data_astm/data.cpp index 2bc20914f828fbaa252ba06fb1dc75163a57b7d4..8608490f012d0c008ad6d5b0ef8072d264bce49f 100644 --- a/sources/plugins/data_astm/data.cpp +++ b/sources/plugins/data_astm/data.cpp @@ -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]; } diff --git a/sources/plugins/data_astm/data.h b/sources/plugins/data_astm/data.h index 799beaac117cd2e5aa0d458fe0ffece23c1705d0..621623c488bf606ece81a2b7e52f5ecbf553574a 100644 --- a/sources/plugins/data_astm/data.h +++ b/sources/plugins/data_astm/data.h @@ -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 diff --git a/sources/plugins/data_brdf_slice/EXR_IO.h b/sources/plugins/data_brdf_slice/EXR_IO.h index a7bd2b281bbb706ed9c934fb3a5ea622143cedab..941c09bfd8a16c48600aab2f762988d081acc048 100644 --- a/sources/plugins/data_brdf_slice/EXR_IO.h +++ b/sources/plugins/data_brdf_slice/EXR_IO.h @@ -10,6 +10,10 @@ #ifndef EXR_IO_H_ #define EXR_IO_H_ +/* + * Author: Cyril Soler + */ + #include diff --git a/sources/plugins/data_brdf_slice/data.cpp b/sources/plugins/data_brdf_slice/data.cpp index 87bb1dc58ad1027470046737e09294b48f8cabe5..c66ef88e16c851ee5698c9ca7d3d5709a50b0929 100644 --- a/sources/plugins/data_brdf_slice/data.cpp +++ b/sources/plugins/data_brdf_slice/data.cpp @@ -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); diff --git a/sources/plugins/data_brdf_slice/data.h b/sources/plugins/data_brdf_slice/data.h index 0e04abfdf0499035d6a22f63c745b9fbeb84926b..d89a6fd419e633ca2e7bfacb9e6c479598239732 100644 --- a/sources/plugins/data_brdf_slice/data.h +++ b/sources/plugins/data_brdf_slice/data.h @@ -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 ; diff --git a/sources/plugins/data_merl/data.cpp b/sources/plugins/data_merl/data.cpp index c0fa283c6b26d89d1c929b3c9c130337e135324e..e77d931cfedb377ef6519c9375feb3238b54979c 100644 --- a/sources/plugins/data_merl/data.cpp +++ b/sources/plugins/data_merl/data.cpp @@ -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) ; diff --git a/sources/plugins/data_merl/data.h b/sources/plugins/data_merl/data.h index 4d96a49cb61dc88bac91f347ad759a043b62c243..0c0d81d7ca3d4d98a6f7b66f0593e4cf177ab1d0 100644 --- a/sources/plugins/data_merl/data.h +++ b/sources/plugins/data_merl/data.h @@ -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 ; diff --git a/sources/python/alta.cpp b/sources/python/alta.cpp index 6d81eeb260612140eeed2d1c103092257858d5e9..c788de7525972de3162af54bf745441817577ffc 100644 --- a/sources/python/alta.cpp +++ b/sources/python/alta.cpp @@ -155,7 +155,7 @@ BOOST_PYTHON_MODULE(alta) bp::class_, 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); diff --git a/sources/softs/SConscript b/sources/softs/SConscript index 13d68410f781c24e330e75ac07a0ed42cd4a0869..71aff6523ac797d597943e994923a93e7dba0cfa 100644 --- a/sources/softs/SConscript +++ b/sources/softs/SConscript @@ -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') diff --git a/sources/softs/brdf2data/main.cpp b/sources/softs/brdf2data/main.cpp index 1c849402228483f7979895308edfd58b1da7ae77..a7dabe625670c27519ef7a711394c5728665f8fa 100644 --- a/sources/softs/brdf2data/main.cpp +++ b/sources/softs/brdf2data/main.cpp @@ -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; isize(); ++i) { @@ -111,12 +116,17 @@ int main(int argc, char** argv) } vec y = f->value(temp); - for(int j=0; jdimY(); ++j) - { - x[d->dimX() + j] = y[j]; + for(int j=0; jdimY(); ++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"]); diff --git a/sources/softs/tests/main.cpp b/sources/softs/tests/main.cpp index 028683f21947b0c760cb0872dbd367132fe03b18..301c6dc9a456816e0966a97b72530b1bcfd705d4 100644 --- a/sources/softs/tests/main.cpp +++ b/sources/softs/tests/main.cpp @@ -1,3 +1,4 @@ + /* 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 + +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 #include #include @@ -208,3 +232,5 @@ int parametrization_tests() */ return nb_tests_failed; } + +#endif