Commit 90914b4a authored by Ludovic Courtès's avatar Ludovic Courtès

core: data: Devirtualize the 'size' method.

parent d2884238
......@@ -34,10 +34,11 @@ class data
{
public: // methods
data(const parameters &p): _parameters(p) {}
data(const parameters &p, int size)
: _parameters(p), _size(size) {}
data(const parameters& p, const vec& min, const vec& max)
: _parameters(p), _min(min), _max(max)
data(const parameters& p, int size, const vec& min, const vec& max)
: _parameters(p), _size(size), _min(min), _max(max)
{
assert(min.size() == p.dimX());
assert(max.size() == p.dimX());
......@@ -76,7 +77,7 @@ class data
// Get data size, e.g. the number of samples to fit
virtual int size() const = 0 ;
int size() const { return _size; };
//! \brief Return true if this object is equal to DATA ±ε.
virtual bool equals(const data& data,
......@@ -104,6 +105,7 @@ class data
protected: // data
parameters _parameters;
int _size;
vec _min, _max;
} ;
......@@ -134,12 +136,13 @@ class data_params : public data
//! \brief contructor requires the definition of a base class that
//! has a parametrization, and a new parametrization.
data_params(const ptr<data> d, params::input new_param,
data_params(const ptr<data> d, int size, params::input new_param,
data_params::clustering method = data_params::NONE) :
data(parameters(params::dimension(new_param),
d->parametrization().dimY(),
new_param,
d->parametrization().output_parametrization())),
d->parametrization().output_parametrization()),
size),
_clustering_method(method)
{
std::cout << "<<INFO>> Reparametrization of the data" << std::endl;
......@@ -166,12 +169,6 @@ class data_params : public data
this->set(i, x);
}
// Get data size, e.g. the number of samples to fit
virtual int size() const
{
return _data.size();
}
protected: // data
data_params::clustering _clustering_method;
......
......@@ -575,7 +575,8 @@ void plugins_manager::check_compatibility( ptr<data>& d,
{
std::cout << "<<INFO>> has to change the parametrization of the input data " << params::get_name(d->parametrization().input_parametrization()) << std::endl;
std::cout << "<<INFO>> to " << params::get_name(f->parametrization().input_parametrization()) << std::endl;
ptr<data_params> dd = ptr<data_params>(new data_params(d, f->parametrization().input_parametrization()));
ptr<data_params> dd = ptr<data_params>(new data_params(d, d->size(),
f->parametrization().input_parametrization()));
d = dynamic_pointer_cast<data>(dd) ;
}
else
......
......@@ -68,7 +68,7 @@ static vec data_max(unsigned int size, const std::vector<vec>& data)
vertical_segment::vertical_segment(const parameters& params,
std::vector<vec>&& input_data)
: data(params,
: data(params, input_data.size(),
data_min(params.dimX(), input_data),
data_max(params.dimX(), input_data)),
_data(input_data), _is_absolute(true), _dt(0.1)
......@@ -76,7 +76,7 @@ vertical_segment::vertical_segment(const parameters& params,
}
vertical_segment::vertical_segment(const parameters& params, unsigned int size):
data(params), _is_absolute(true), _dt(0.1)
data(params, size), _is_absolute(true), _dt(0.1)
{
initializeToZero(size);
}
......@@ -149,11 +149,6 @@ void vertical_segment::set(int i, const vec& x)
}
}
int vertical_segment::size() const
{
return _data.size() ;
}
vec vertical_segment::vs(const vec& x) const {
vec y(_parameters.dimX() + 3*_parameters.dimY());
......
......@@ -107,9 +107,6 @@ class vertical_segment : public data
//! ordinate segment.
virtual void get(int i, vec& yl, vec& yu) const ;
// Get data size
virtual int size() const ;
private: // method
protected: // method
......
......@@ -59,7 +59,7 @@ class MatlabInterpolant : public data
public: // methods
MatlabInterpolant()
: _data( ptr<data>( new vertical_segment() ) )
: _data( ptr<data>( new vertical_segment() ) ) // FIXME: size?
{
// Create matlab engine
#ifdef WIN32
......@@ -209,12 +209,6 @@ class MatlabInterpolant : public data
return res;
}
// Get data size, e.g. the number of samples to fit
virtual int size() const
{
return _data->size();
}
};
ALTA_DLL_EXPORT data* provide_data(size_t, const parameters&, const arguments&)
......
......@@ -74,7 +74,8 @@ class rbf_interpolant : public data
public:
rbf_interpolant(ptr<data> proxied_data)
: data(proxied_data->parametrization()),
: data(proxied_data->parametrization(),
proxied_data->size()),
_data(proxied_data),
_knn(3)
{
......@@ -211,13 +212,6 @@ class rbf_interpolant : public data
return res;
}
// Get data size, e.g. the number of samples to fit
virtual int size() const
{
assert(_data);
return _data->size();
}
};
ALTA_DLL_EXPORT data* load_data(std::istream& input, const arguments& args)
......
......@@ -73,6 +73,10 @@ using namespace alta;
ALTA_DLL_EXPORT data* load_data(std::istream& input, const arguments& args);
#define MERL_SIZE \
(BRDF_SAMPLING_RES_THETA_H * BRDF_SAMPLING_RES_THETA_D \
* BRDF_SAMPLING_RES_PHI_D / 2)
class MERL : public data
{
private: // data
......@@ -86,8 +90,7 @@ private: // data
public: // methods
MERL(const parameters& params) :
data(params),
_nSlice(BRDF_SAMPLING_RES_THETA_H*BRDF_SAMPLING_RES_THETA_D*BRDF_SAMPLING_RES_PHI_D/2) {
data(params, MERL_SIZE), _nSlice(MERL_SIZE) {
brdf = new double[3*_nSlice];
std::fill(brdf, brdf + 3*_nSlice, 0.0);
......@@ -185,13 +188,6 @@ public: // methods
}
// Get data size, e.g. the number of samples to fit
int size() const {
return BRDF_SAMPLING_RES_THETA_H *
BRDF_SAMPLING_RES_THETA_D *
BRDF_SAMPLING_RES_PHI_D / 2 ;
}
private: //methods
// cross product of two vectors
......
......@@ -82,7 +82,8 @@ class BrdfSlice : public data {
BrdfSlice(const arguments& args,
int width, int height, int slice,
double* content)
: data(brdf_slice_parameters(args)),
: data(brdf_slice_parameters(args),
width * height * slice),
_width(width), _height(height), _slice(slice),
_data(content)
{
......@@ -197,12 +198,6 @@ class BrdfSlice : public data {
private:
// Get data size, e.g. the number of samples to fit
int size() const
{
return _width*_height*_slice;
}
// Get min and max input space values
vec min() const
{
......
......@@ -32,6 +32,15 @@ using namespace alta;
ALTA_DLL_EXPORT data* load_data(std::istream& input, const arguments& args);
#define STEP_T 15.
#define STEP_P 7.5
#define NTI 6
#define NTV 6
#define NPI ((int)(360.f/STEP_P))
#define NPV ((int)(360.f/STEP_P))
#define N_PER_PLANE (NTI * NPI * NTV * NPV)
/*! \ingroup datas
* \class data_utia
* \brief Data interface for the [UTIA][utia] file format.
......@@ -63,16 +72,16 @@ private:
public:
UTIA(const parameters& params)
: data(params)
: data(params, N_PER_PLANE)
{
this->step_t = 15;
this->step_p = 7.5;
this->nti = 6;
this->ntv = 6;
this->npi = (int)(360.f/step_p);
this->npv = (int)(360.f/step_p);
this->step_t = STEP_T;
this->step_p = STEP_P;
this->nti = NTI;
this->ntv = NTV;
this->npi = NPI;
this->npv = NPV;
this->planes = 3;
this->nPerPlane = nti*npi*ntv*npv;
this->nPerPlane = N_PER_PLANE;
this->Bd = new double[planes*nti*npi*ntv*npv];
_min[0] = 0.0;
......@@ -271,11 +280,6 @@ public:
}
}
// Get data size, e.g. the number of samples to fit
virtual int size() const {
return nPerPlane;
}
friend data* load_data(std::istream&, const arguments&);
};
......
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