Commit d9fd53a0 by Laurent Belcour

### Adding some plugins and a correction in the parametrization.

parent c6ea14e4
 ... ... @@ -201,29 +201,29 @@ void params::from_cartesian(const double* invec, params::input outtype, break; case params::RUSIN_TH_TD: outvec[0] = acos(half[2]); outvec[2] = acos(half[0]*invec[0] + half[1]*invec[1] + half[2]*invec[2]); outvec[1] = acos(half[0]*invec[0] + half[1]*invec[1] + half[2]*invec[2]); break; // 3D Parametrization case params::RUSIN_TH_PH_TD: outvec[0] = acos(half[2]); outvec[1] = atan2(half[1], half[0]); outvec[1] = atan2(half[1], half[0]); outvec[2] = acos(half[0]*invec[0] + half[1]*invec[1] + half[2]*invec[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, -atan2(half[1], half[0])); rotate_binormal(diff, -outvec[0]); outvec[1] = acos(diff[2]); outvec[2] = atan2(diff[1], diff[0]); 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, -atan2(half[1], half[0])); rotate_binormal(diff, -outvec[0]); outvec[1] = acos(diff[2]); outvec[2] = atan2(diff[1], diff[0]); break; case params::ISOTROPIC_TV_TL_DPHI: outvec[0] = acos(invec[2]); outvec[1] = acos(invec[5]); ... ...
 #include "data.h" #include #include #include #include #include #include #include // Load data from a file void data_astm::load(const std::string& filename) { std::ifstream file(filename.c_str()); std::string line; // Parse the header for(int i=0; i<22; ++i) { std::getline(file, line); } while(file.good()) { std::getline(file, line); size_t s = 0; // start size_t t; // end bool sample_wrong = false; vec x(7); for(int i=0; i<7; ++i) { t = line.find_first_of(',', s); if(t == s || t == std::string::npos) { sample_wrong = true; } x[i] = atof(line.substr(s, t-s).c_str()); s = t+1; } if(!sample_wrong) { _data.push_back(x); } } file.close(); } void data_astm::load(const std::string& filename, const arguments& args) { this->load(filename); } // Acces to data vec data_astm::get(int i) const { return _data[i]; } vec data_astm::operator[](int i) const { return _data[i]; } vec data_astm::value(vec in, vec out) const { std::cout << "<> not implemented" << std::endl; vec res(4); return res; } // Get data size, e.g. the number of samples to fit int data_astm::size() const { return _data.size() ; } // Get min and max input space values vec data_astm::min() const { vec res(4); res[0] = 0.0 ; res[1] = 0.0 ; res[2] = 0.0 ; res[3] = 0.0 ; return res ; } vec data_astm::max() const { vec res(4); res[0] = M_PI / 2 ; res[1] = 0.0 ; res[2] = M_PI / 2 ; res[3] = M_PI ; return res ; } data* provide_data() { return new data_astm(); } Q_EXPORT_PLUGIN2(data_astm, data_astm)
 #pragma once #include #include #include #include class data_astm : public QObject, public data { // Q_OBJECT Q_INTERFACES(data) public: // methods // Load data from a file virtual void load(const std::string& filename) ; virtual void load(const std::string& filename, const arguments& args) ; // Acces to data virtual vec get(int i) const ; virtual vec operator[](int i) const ; virtual vec value(vec in, vec out) const ; // Get data size, e.g. the number of samples to fit virtual int size() const ; // Get min and max input space values virtual vec min() const ; virtual vec max() const ; virtual int dimX() const { return 4; } virtual int dimY() const { return 3; } virtual params::input parametrization() const { return params::SPHERICAL_TL_PL_TV_PV; } private: // data std::vector _data; } ;
 TEMPLATE = lib CONFIG *= qt \ plugin DESTDIR = ../../build INCLUDEPATH += ../.. HEADERS = data.h SOURCES = data.cpp LIBS += -L../../build \ -lcore
 #include "data.h" #include #include #include data_brdf_slice::data_brdf_slice() { // Allocate data _data = new fipImage(); //_data->setSize(FIT_FLOAT, 512, 512, 16); // Set the input and output parametrization _in_param = params::RUSIN_TH_TD; _out_param = params::RGB_COLOR; _nX = 2; _nY = 3; } data_brdf_slice::~data_brdf_slice() { delete _data; } // Load data from a file void data_brdf_slice::load(const std::string& filename) { _data->load(filename.c_str()); _data->convertTo32Bits(); width = _data->getWidth(); height = _data->getHeight(); } void data_brdf_slice::load(const std::string& filename, const arguments&) { load(filename); } void data_brdf_slice::save(const std::string& filename) const { if(!_data->save(filename.c_str())) { std::cerr << "<> unable to save image file" << std::endl; } } // Acces to data vec data_brdf_slice::get(int id) const { vec res(3) ; int i = id % width; int j = id / width; RGBQUAD pixel; _data->getPixelColor(i, j, &pixel); res[0] = pixel.rgbRed / 255.0; res[1] = pixel.rgbGreen / 255.0; res[2] = pixel.rgbBlue / 255.0; return res ; } vec data_brdf_slice::operator[](int i) const { return get(i) ; } //! \todo Test this function void data_brdf_slice::set(vec x) { assert(x.size() == 5); int i = floor(x[0] * width / (0.5*M_PI)); int j = floor(x[1] * height / (0.5*M_PI)); RGBQUAD* pixel; _data->getPixelColor(i, j, pixel); pixel->rgbRed = x[2]; pixel->rgbGreen = x[3]; pixel->rgbBlue = x[4]; } vec data_brdf_slice::value(vec, vec) const { vec res(3); return res; } vec data_brdf_slice::value(vec x) const { int i = floor(x[0] * width / (0.5*M_PI)); int j = floor(x[1] * height / (0.5*M_PI)); if(i < 0 || i >= width) { std::cerr << "<> out of bounds: " << x << std::endl; } if(j < 0 || j >= height) { std::cerr << "<> out of bounds: " << x << std::endl; } return get(i + j*width); } // Get data size, e.g. the number of samples to fit int data_brdf_slice::size() const { return width*height; } // Get min and max input space values vec data_brdf_slice::min() const { vec res(2); res[0] = 0.0 ; res[1] = 0.0 ; return res ; } vec data_brdf_slice::max() const { vec res(2); res[0] = M_PI / 2 ; res[1] = M_PI / 2 ; return res ; } int data_brdf_slice::dimX() const { return 2 ; } int data_brdf_slice::dimY() const { return 3; } ALTA_DLL_EXPORT data* provide_data() { return new data_brdf_slice(); }
 #pragma once #include #include #include #include class data_brdf_slice : public data { public: // methods data_brdf_slice(); ~data_brdf_slice(); // Load data from a file virtual void load(const std::string& filename) ; virtual void load(const std::string& filename, const arguments& args) ; 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 value(vec in, vec out) const; virtual vec value(vec x) const; // Set data virtual void set(vec x); // Get data size, e.g. the number of samples to fit virtual int size() const ; // Get min and max input space values virtual vec min() const ; virtual vec max() const ; virtual int dimX() const ; virtual int dimY() const ; private: // data fipImage* _data; int width, height; } ;
 TEMPLATE = lib CONFIG *= plugin \ eigen DESTDIR = ../../build INCLUDEPATH += ../.. HEADERS = data.h SOURCES = data.cpp LIBS += -L../../build \ -lcore \ -lfreeimageplus
 ... ... @@ -25,5 +25,6 @@ SUBDIRS = \ nonlinear_function_lafortune \ nonlinear_function_isotropic_lafortune \ data_merl \ data_brdf_slice \ # data_astm
 ... ... @@ -46,7 +46,7 @@ int main(int argc, char** argv) d = plugins_manager::get_data(args["data"]) ; function* f = NULL; f = plugins_manager::get_function(args["input"]); f = plugins_manager::get_function(args); // Modify function or data to provide coherent // interfaces ... ...
 CONFIG += console \ eigen INCLUDEPATH += ../../ DESTDIR = ../../build SOURCES += main.cpp LIBS += -L../../build -lcore unix{ PRE_TARGETDEPS += ../../build/libcore.a LIBS += -ldl }
 #include #include #include #include #include #include #include #include #include #include #include #include #include int main(int argc, char** argv) { arguments args(argc, argv) ; if(args.is_defined("help")) { std::cout << "<> data2data --input data.file --output data.file --out-data exporter.so --in-data importer.so" << std::endl ; std::cout << " - input, output, func, data are mandatory parameters" << std::endl ; return 0 ; } if(! args.is_defined("input")) { std::cerr << "<> the input filename is not defined" << std::endl ; return 1 ; } if(! args.is_defined("output")) { std::cerr << "<> the output filename is not defined" << std::endl ; return 1 ; } if(! args.is_defined("in-data")) { std::cerr << "<> the data importer is not defined" << std::endl ; return 1 ; } if(! args.is_defined("out-data")) { std::cerr << "<> the data exporter is not defined" << std::endl ; return 1 ; } // Import data data* d_in = NULL ; d_in = plugins_manager::get_data(args["in-data"]) ; d_in->load(args["input"]); data* d_out = NULL; d_out = plugins_manager::get_data(args["out-data"]) ; if(d_out->dimY() != d_in->dimY()) { std::cerr << "<> data types have incompatible output dimensions" << std::endl; } if(d_in != NULL && d_out != NULL) { vec temp(d_in->dimX()); for(int i=0; isize(); ++i) { // Copy the input vector vec x = d_out->get(i); //params::convert(&x[0], d_out->parametrization(), d_in->parametrization(), &temp[0]); temp[0] = x[0]; temp[1] = x[1]; vec y = d_in->value(temp); for(int j=0; jdimY(); ++j) { x[d_out->dimX() + j] = y[j]; } d_out->set(x); } d_out->save(args["output"]); return 0 ; } else { std::cerr << "<> cannot import or export data" << std::endl ; return 1; } }
 TEMPLATE = subdirs SUBDIRS = generate_data \ data2brdf \ data2data \ brdf2data \ brdf2brdf \ brdf2gnuplot \ ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!