Commit 32814cc4 authored by Laurent Belcour's avatar Laurent Belcour

Completing the implementation of the parametrization class

parent 44340579
......@@ -28,7 +28,15 @@ class vec : public std::vector<double>
}
virtual ~vec()
{
}
}
//! \brief get a subpart of the vector
vec subvector(int start, int n) const
{
vec res(n);
memcpy(&res[0], &this->at(start), n*sizeof(double));
return res;
}
//! \brief copy operator. It resize the left operand to the size of the
//! right operand.
......
......@@ -60,21 +60,36 @@ Q_DECLARE_INTERFACE(data, "Fitter.Data")
class data_params : public data
{
public:
//! \brief contructor requires the definition of a base class that
//! has a parametrization, and a new parametrization.
data_params(const data* d, params::type param) : _d(d), _param(param)
{
_nX = d->dimX(); //! \todo the parametrization can change the size
//! of the input domain.
_nY = d->dimY();
}
// Load data from a file
virtual void load(const std::string& filename)
{
_d->load(filename);
std::cerr << "<<ERROR>> this data type cannot load data" << std::endl;
throw;
}
virtual void load(const std::string& filename, const arguments& args)
{
_d->load(filename, args);
std::cerr << "<<ERROR>> this data type cannot load data" << std::endl;
throw;
}
// Acces to data
virtual vec get(int i) const
{
return _d->get(i);
vec res(_nX + _nY);
params::convert(&_d->get(i)[0], _d->parametrization(), _param, &res[0]);
return res;
}
virtual vec operator[](int i) const
{
......@@ -99,5 +114,6 @@ public:
protected:
// data object to interface
data* _d;
const data* _d;
params::type _param;
};
......@@ -30,12 +30,173 @@ class params
public: // methods
//! \brief static function for input type convertion.
//! \todo implement the convertion method using a case on the
//! out type. It should work if the input vector is converted
//! to a 6D vector (in, out).
static vec convert(const vec& invec, params::type intype, params::type outtype)
//! \brief static function for input type convertion. This
//! function allocate the resulting vector.
static double* convert(const double* invec, params::type intype,
params::type outtype)
{
return invec;
int dim = dimension(outtype); // Get the size of the output vector
if(dim > 0)
{
double* outvec = new double[dim];
double temvec[6]; // Temp CARTESIAN vectors
to_cartesian(invec, intype, temvec);
from_cartesian(temvec, outtype, outvec);
return outvec;
}
else
{
return NULL;
}
}
//! \brief static function for input type convertion. The \param
//! outvec resulting vector should be allocated with the correct
//! output size.
static void convert(const double* invec, params::type intype,
params::type outtype, double* outvec)
{
double temvec[6]; // Temp CARTESIAN vectors
to_cartesian(invec, intype, temvec);
from_cartesian(temvec, outtype, outvec);
}
//! \brief convert a input vector in a given parametrization to an
//! output vector in a cartesian parametrization, that is two 3d
//! vectors concatenated.
static void to_cartesian(const double* invec, params::type intype,
double* outvec)
{
double half[3];
switch(intype)
{
// 3D Parametrization
case params::RUSIN_TH_PH_TD:
half[0] = sin(invec[0])*cos(invec[1]);
half[1] = sin(invec[0])*sin(invec[1]);
half[2] = cos(invec[0]);
break;
// 4D Parametrization
case params::RUSIN_TH_PH_TD_PD:
break;
// 6D Parametrization
case params::CARTESIAN:
memcpy(outvec, invec, 6*sizeof(double));
break;
default:
throw("Transformation not implemented, params::to_cartesian");
break;
}
}
//! \brief convert a input CARTESIAN vector, that is two 3d vectors
//! concatenated to an output vector in a given parametrization.
static void from_cartesian(const double* invec, params::type outtype,
double* outvec)
{
// Compute the half vector
double half[3] ;
half[0] = invec[0] + invec[3];
half[1] = invec[1] + invec[4];
half[2] = invec[2] + invec[5];
double half_norm = sqrt(half[0]*half[0] + half[1]*half[1] + half[2]*half[2]);
half[0] /= half_norm;
half[1] /= half_norm;
half[2] /= half_norm;
switch(outtype)
{
// 2D Parametrizations
case params::COS_TH_TD:
outvec[0] = half[2];
outvec[1] = half[0]*outvec[0] + half[1]*outvec[1] + half[2]*outvec[2];
break;
// 3D Parametrization
case params::RUSIN_TH_PH_TD:
outvec[0] = acos(half[2]);
outvec[1] = atan2(half[0], half[1]);
outvec[2] = acos(half[0]*outvec[0] + half[1]*outvec[1] + half[2]*outvec[2]);
break;
// 6D Parametrization
case params::CARTESIAN:
memcpy(outvec, invec, 6*sizeof(double));
break;
default:
throw("Transformation not implemented, params::from_cartesian");
break;
}
}
//! \brief provide a dimension associated with a parametrization
static int dimension(params::type t)
{
switch(t)
{
// 2D Parametrizations
case params::ISOTROPIC_TD_PD:
case params::ROMEIRO_TH_TD:
case params::COS_TH_TD:
return 2;
break;
// 3D Parametrization
case params::RUSIN_TH_PH_TD:
case params::RUSIN_TH_TD_PD:
case params::ISOTROPIC_TV_TL_DPHI:
return 3;
break;
// 4D Parametrization
case params::RUSIN_TH_PH_TD_PD:
case params::SPHERICAL_TL_PL_TV_PV:
return 4;
break;
// 6D Parametrization
case params::CARTESIAN:
return 6;
break;
default:
return -1;
break;
}
}
//! \brief rotate a cartesian vector with respec to another of
//! \param theta degrees.
static void rotate(double* vec, double* ref, double theta)
{
const double cost = cos(theta);
const double sint = sin(theta);
/*
vec[0] = ;
vec[1] = ;
vec[2] = ;
*/
}
//! \brief rotate a cartesian vector with respect to the normal of
//! \param theta degrees.
static void rotate(double* vec, double theta)
{
const double cost = cos(theta);
const double sint = sin(theta);
vec[0] = cost * vec[0] - sint * vec[1];
vec[1] = sint * vec[0] + cost * vec[1];
}
};
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