Commit 997ff3ef authored by Ludovic Courtès's avatar Ludovic Courtès

core: plugins_manager: 'get_data' takes the size and parameters.

parent ddb878bc
......@@ -442,14 +442,16 @@ ptr<function> plugins_manager::get_function(const std::string& n,
}
ptr<data> plugins_manager::get_data(const std::string& n, const arguments& args)
ptr<data> plugins_manager::get_data(const std::string& n, size_t size,
const parameters& params,
const arguments& args)
{
if(n.empty() || n == "vertical_segment")
{
#ifdef DEBUG
std::cout << "<<DEBUG>> no data plugin specified, returning a vertical_segment loader" << std::endl;
#endif
return ptr<data>(new vertical_segment());
return ptr<data>(new vertical_segment(params, size));
}
DataPrototype myData = open_library<DataPrototype>(n, "provide_data");
......@@ -458,7 +460,7 @@ ptr<data> plugins_manager::get_data(const std::string& n, const arguments& args)
#ifdef DEBUG
std::cout << "<<DEBUG>> using data provider in file \"" << n << "\"" << std::endl;
#endif
return ptr<data>(myData(args));
return ptr<data>(myData(size, params, args));
}
else
{
......
......@@ -55,7 +55,10 @@ class plugins_manager
//! \brief get an instance of the data that is defined in the plugin with
//! filename n. Return null if no one exist.
static ptr<data> get_data(const std::string& n, const arguments& args = arguments());
static ptr<data> get_data(const std::string& n,
size_t size,
const parameters& params,
const arguments& args = arguments());
//! \brief Load from INPUT an instance of TYPE and return it.
static ptr<data> load_data(const std::string& type, std::istream& input,
......@@ -89,7 +92,8 @@ class plugins_manager
// Object provider prototypes
typedef function* (*FunctionPrototype)(const parameters&);
typedef fitter* (*FitterPrototype)();
typedef data* (*DataPrototype)(const arguments&);
typedef data* (*DataPrototype)(size_t size, const parameters& params,
const arguments&);
typedef data* (*LoadDataPrototype)(std::istream& input,
const arguments&);
};
......
......@@ -152,10 +152,8 @@ class BrdfGrid : public vertical_segment {
std::vector<int> _size;
BrdfGrid(const arguments& args)
: vertical_segment(alta::parameters(2, 3, params::STARK_2D,
params::RGB_COLOR),
0) // XXX: size
BrdfGrid(size_t size, const parameters& params, const arguments& args)
: vertical_segment(params, size)
{
initialize(args);
}
......@@ -365,9 +363,11 @@ class BrdfGrid : public vertical_segment {
}
};
ALTA_DLL_EXPORT data* provide_data(const arguments& args)
ALTA_DLL_EXPORT data* provide_data(size_t size,
const parameters& params,
const arguments& args)
{
return new BrdfGrid(args);
return new BrdfGrid(size, params, args);
}
ALTA_DLL_EXPORT data* load_data(std::istream& input,
......@@ -375,11 +375,6 @@ ALTA_DLL_EXPORT data* load_data(std::istream& input,
{
arguments header = arguments::parse_header(input);
BrdfGrid* result = new BrdfGrid(args);
// XXX: Should be done in constructor.
result->initialize(header, false);
#ifdef __GNUC__
# warning FIXME we are not returning a "BrdfGrid"
#endif
......@@ -387,5 +382,12 @@ ALTA_DLL_EXPORT data* load_data(std::istream& input,
// to 'data'.
abort();
#if 0
BrdfGrid* result = new BrdfGrid(args);
// XXX: Should be done in constructor.
result->initialize(header, false);
#endif
return load_data_from_text(input, header);
}
......@@ -221,7 +221,7 @@ class MatlabInterpolant : public data
}
};
ALTA_DLL_EXPORT data* provide_data(const arguments&)
ALTA_DLL_EXPORT data* provide_data(size_t, const parameters&, const arguments&)
{
return new MatlabInterpolant();
}
......@@ -55,7 +55,9 @@ public: //methods
: vertical_segment(params, std::move(input_data))
{ }
ASTM(): vertical_segment() { }
ASTM(const parameters& params, size_t size)
: vertical_segment(params, size)
{ }
};
// Parse ASTM header.
......@@ -129,9 +131,10 @@ compute_parameters(const std::vector<std::string>& vars)
}
ALTA_DLL_EXPORT data* provide_data(const arguments&)
ALTA_DLL_EXPORT data* provide_data(size_t size, const parameters& params,
const arguments&)
{
return new ASTM();
return new ASTM(params, size);
}
ALTA_DLL_EXPORT data* load_data(std::istream& input, const arguments& args)
......
......@@ -79,10 +79,14 @@ private: // data
double *brdf ;
const int _nSlice;
MERL()
: MERL(parameters(3, 3, params::RUSIN_TH_TD_PD, params::RGB_COLOR))
{ }
public: // methods
MERL() :
data(parameters(3, 3, params::RUSIN_TH_TD_PD, params::RGB_COLOR)),
MERL(const parameters& params) :
data(params),
_nSlice(BRDF_SAMPLING_RES_THETA_H*BRDF_SAMPLING_RES_THETA_D*BRDF_SAMPLING_RES_PHI_D/2) {
brdf = new double[3*_nSlice];
std::fill(brdf, brdf + 3*_nSlice, 0.0);
......@@ -97,6 +101,7 @@ public: // methods
_max[1] = 0.5*M_PI;
_max[2] = 2.0*M_PI;
}
~MERL() {
delete[] brdf;
}
......@@ -460,9 +465,10 @@ static bool read_brdf(std::istream& input, double* &brdf)
}
ALTA_DLL_EXPORT data* provide_data(const arguments&)
ALTA_DLL_EXPORT data* provide_data(size_t size, const parameters& params,
const arguments& args)
{
return new MERL();
return new MERL(params);
}
ALTA_DLL_EXPORT data* load_data(std::istream& input, const arguments& args)
......
......@@ -290,7 +290,8 @@ class BrdfSlice : public data {
friend data* load_data(std::istream&, const arguments&);
};
ALTA_DLL_EXPORT data* provide_data(const arguments& args)
ALTA_DLL_EXPORT data* provide_data(size_t size, const parameters& params,
const arguments& args)
{
return new BrdfSlice(args);
}
......
......@@ -62,10 +62,8 @@ private:
double* Bd;
public:
UTIA()
: data(alta::parameters(4, 3,
params::SPHERICAL_TL_PL_TV_PV,
params::RGB_COLOR))
UTIA(const parameters& params)
: data(params)
{
this->step_t = 15;
this->step_p = 7.5;
......@@ -299,9 +297,10 @@ public:
friend data* load_data(std::istream&, const arguments&);
};
ALTA_DLL_EXPORT data* provide_data(const arguments&)
ALTA_DLL_EXPORT data* provide_data(size_t size, const parameters& params,
const arguments&)
{
return new UTIA();
return new UTIA(params);
}
ALTA_DLL_EXPORT data* load_data(std::istream& input, const arguments& args)
......@@ -333,7 +332,9 @@ ALTA_DLL_EXPORT data* load_data(std::istream& input, const arguments& args)
} else
#endif
UTIA* result = new UTIA();
UTIA* result = new UTIA(alta::parameters(0, 0,
params::UNKNOWN_INPUT,
params::UNKNOWN_OUTPUT));
int count = 0;
for(int isp=0; isp < result->planes; isp++) {
......
......@@ -66,11 +66,15 @@ static ptr<data> load_data(const std::string& plugin_name, const std::string& fi
ptr<data> d = plugins_manager::load_data(filename, plugin_name);
return d;
}
static ptr<data> get_data_with_args(const std::string& plugin_name, const python_arguments& args) {
return plugins_manager::get_data(plugin_name, args);
static ptr<data> get_data_with_args(const std::string& plugin_name,
size_t size,
const parameters& params,
const python_arguments& args) {
return plugins_manager::get_data(plugin_name, size, params, args);
}
static ptr<data> get_data(const std::string& plugin_name) {
return plugins_manager::get_data(plugin_name);
static ptr<data> get_data(const std::string& plugin_name, size_t size,
const parameters& params) {
return plugins_manager::get_data(plugin_name, size, params);
}
/* Creating functions for the plugins_manager calls
......
......@@ -78,18 +78,6 @@ int main(int argc, char** argv)
}
CATCH_FILE_IO_ERROR(args["data-file"]);
// Get the output object. In the case where it is not a VS file, we use
// the load object.
ptr<data> d_out = plugins_manager::get_data(args["data"], args);
if(dynamic_pointer_cast<vertical_segment>(d) != NULL)
{
parameters p(d->parametrization().dimX(),
d->parametrization().dimY(),
d->parametrization().input_parametrization(),
d->parametrization().output_parametrization());
d_out->setParametrization(p);
}
// Get the function file
function* f = NULL;
f = plugins_manager::load_function(args["input"]);
......@@ -99,11 +87,17 @@ int main(int argc, char** argv)
return 1;
}
// Get the output object. In the case where it is not a VS file, we use the
// load object.
ptr<data> d_out = plugins_manager::get_data(args["data"],
d->size(),
dynamic_pointer_cast<vertical_segment>(d)
? d->parametrization()
: f->parametrization(),
args);
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->parametrization().dimX());
......@@ -125,17 +119,27 @@ int main(int argc, char** argv)
}
vec y = f->value(temp);
for(int j=0; j<d->parametrization().dimY(); ++j) {
x[d->parametrization().dimX() + j] =
(output_dif) ? x[d->parametrization().dimX() + j] - y[j] : y[j];
if (dynamic_pointer_cast<vertical_segment>(d_out))
{
// Vertical segment has a "scatter" representation, so we need to
// pass both X and Y.
vec z(d_out->parametrization().dimX()
+ d_out->parametrization().dimY());
for(int j=0; j<d->parametrization().dimX(); ++j) {
z[j] = x[j];
}
for(int j=0; j<d->parametrization().dimY(); ++j) {
z[d->parametrization().dimX() + j] =
output_dif ? x[d->parametrization().dimX() + j] - y[j] : y[j];
}
d_out->set(i, z);
}
// 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) {
else
{
// Grid representation: only Y is stored.
d_out->set(i, y);
} else {
d_out->set(x);
}
}
......
......@@ -59,6 +59,28 @@
using namespace alta;
static parameters compute_parameters(const data& d_in,
const arguments& args)
{
params::input param = params::parse_input(args["param"]);
if(param == params::UNKNOWN_INPUT
&& d_in.parametrization().input_parametrization() != params::UNKNOWN_INPUT)
{
std::cout << "<<DEBUG>> using the input parametrization of the input file for the output file as well." << std::endl;
param = d_in.parametrization().input_parametrization();
}
else if(param == params::UNKNOWN_INPUT)
{
std::cerr << "<<ERROR>> no parametrization defined for input and output files." << std::endl;
exit(EXIT_FAILURE);
}
return alta::parameters(params::dimension(param),
d_in.parametrization().dimY(),
param, params::UNKNOWN_OUTPUT);
}
int main(int argc, char** argv)
{
arguments args(argc, argv) ;
......@@ -125,7 +147,10 @@ int main(int argc, char** argv)
std::cout << "<<INFO>> input data will be treated as ALTA format" << std::endl;
}
ptr<data> d_out = plugins_manager::get_data(args["out-data"], args) ;
ptr<data> d_out = plugins_manager::get_data(args["out-data"],
d_in->size(),
compute_parameters(*d_in, args),
args) ;
if(!d_out)
{
std::cout << "<<INFO>> data will be outputed to ALTA format" << std::endl;
......@@ -140,34 +165,8 @@ int main(int argc, char** argv)
std::cout << "<<INFO>> conversion from " << params::get_name(d_in->parametrization().input_parametrization())
<< " to " << params::get_name(d_out->parametrization().input_parametrization()) << std::endl;
bool is_vs = dynamic_pointer_cast<vertical_segment>(d_out) &&
d_out->size() == 0;
if(is_vs || args.is_defined("splat"))
if(dynamic_pointer_cast<vertical_segment>(d_out) || args.is_defined("splat"))
{
if(dynamic_pointer_cast<vertical_segment>(d_out))
{
params::input param = params::parse_input(args["param"]);
if(param == params::UNKNOWN_INPUT
&& d_in->parametrization().input_parametrization() != params::UNKNOWN_INPUT)
{
std::cout << "<<DEBUG>> using the input parametrization of the input file for the output file as well." << std::endl;
param = d_in->parametrization().input_parametrization();
}
else if(param == params::UNKNOWN_INPUT)
{
std::cerr << "<<ERROR>> no parametrization defined for input and output files." << std::endl;
return -1;
}
{
parameters p(params::dimension(param),
d_in->parametrization().dimY(),
param, params::UNKNOWN_OUTPUT);
d_out->setParametrization(p);
}
}
std::cout << "<<INFO>> output DIM = " << d_out->parametrization().dimX() << ", " << d_out->parametrization().dimY() << std::endl;
vec temp(d_out->parametrization().dimX() + d_out->parametrization().dimY());
......@@ -185,7 +184,7 @@ int main(int argc, char** argv)
d_out->parametrization().output_parametrization(),
d_out->parametrization().dimY(),
&temp[d_out->parametrization().dimX()]);
d_out->set(temp);
d_out->set(i, temp);
}
}
else
......
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