Skip to content
Snippets Groups Projects
Commit 8d920be8 authored by Jesper Andersson's avatar Jesper Andersson
Browse files

First version pretty much finished and tested

parent 1ddffee6
No related branches found
No related tags found
No related merge requests found
......@@ -56,12 +56,14 @@ public:
std::vector<ExtrapolationType> ett(dim.size(),et);
common_construction(data,dim,order,prec,ett,copy_low_order);
}
// Copy construction. May be removed in future
Splinterpolator(const Splinterpolator<T>& src) : _valid(false), _own_coef(false), _coef(0), _cptr(0), _ndim(0) { assign(src); }
// Destructor
virtual ~Splinterpolator() { if(_own_coef) delete [] _coef; }
~Splinterpolator() { if(_own_coef) delete [] _coef; }
// Assignment. May be removed in future
Splinterpolator& operator=(const Splinterpolator& s);
Splinterpolator& operator=(const Splinterpolator& src) { if(_own_coef) delete [] _coef; assign(src); return(*this); }
// Set new data in Splinterpolator.
void Set(const T *data, const std::vector<unsigned int>& dim, const std::vector<ExtrapolationType>& et, unsigned int order=3, bool copy_low_order=true, double prec=1e-8)
......@@ -69,7 +71,7 @@ public:
if (_own_coef) delete [] _coef;
common_construction(data,dim,order,prec,et,copy_low_order);
}
virtual void Set(const T *data, const std::vector<unsigned int>& dim, ExtrapolationType et, unsigned int order=3, bool copy_low_order=true, double prec=1e-8)
void Set(const T *data, const std::vector<unsigned int>& dim, ExtrapolationType et, unsigned int order=3, bool copy_low_order=true, double prec=1e-8)
{
std::vector<ExtrapolationType> vet(dim.size(),Zeros);
Set(data,dim,vet,order,copy_low_order,prec);
......@@ -105,6 +107,7 @@ public:
// Remaining functions are mainly for debugging/diagnostics.
//
unsigned int NDim() const { return(_ndim); }
unsigned int Order() const { return(_order); }
const std::vector<unsigned int>& Size() const { return(_dim); }
unsigned int Size(unsigned int dim) const { if (dim > 4) return(0); else return(_dim[dim]);}
T Coef(unsigned int x, unsigned int y=0, unsigned int z=0) const
......@@ -177,6 +180,7 @@ private:
// Private helper-functions
//
void common_construction(const T *data, const std::vector<unsigned int>& dim, unsigned int order, double prec, const std::vector<ExtrapolationType>& et, bool copy);
void assign(const Splinterpolator<T>& src);
bool calc_coef(const T *data, bool copy);
void deconv_along(unsigned int dim);
T coef(int *indx) const;
......@@ -203,7 +207,7 @@ private:
//
// Disallowed member functions
//
Splinterpolator(const Splinterpolator& s); // Don't allow copy-construction
// Splinterpolator(const Splinterpolator& s); // Don't allow copy-construction
// Splinterpolator& operator=(const Splinterpolator& s); // Don't allow assignment
};
......@@ -213,29 +217,6 @@ private:
//
/////////////////////////////////////////////////////////////////////
template<class T>
Splinterpolator<T>& Splinterpolator<T>::operator=(const Splinterpolator<T>& src)
{
if (_own_coef) delete [] _coef;
_valid = src._valid;
_own_coef = src._own_coef;
_cptr = src._cptr;
_order = src._order;
_ndim = src._ndim;
_prec = src._prec;
_dim = src._dim;
_et = src._et;
if (_own_coef) { // If we need to do a deep copy
unsigned int ts = 1;
for (unsigned int i=0; i<_ndim; i++) ts *= _dim[i];
_coef = new T[ts];
memcpy(_coef,src._coef,ts*sizeof(T));
}
return(*this);
}
/////////////////////////////////////////////////////////////////////
//
// Returns interpolated value at location coord.
......@@ -1000,6 +981,33 @@ void Splinterpolator<T>::common_construction(const T *data, const std::vector<un
_valid = true;
}
/////////////////////////////////////////////////////////////////////
//
// Takes care of the "common" tasks when copy-constructing
// and when assigning.
//
/////////////////////////////////////////////////////////////////////
template<class T>
void Splinterpolator<T>::assign(const Splinterpolator<T>& src)
{
_valid = src._valid;
_own_coef = src._own_coef;
_cptr = src._cptr;
_order = src._order;
_ndim = src._ndim;
_prec = src._prec;
_dim = src._dim;
_et = src._et;
if (_own_coef) { // If we need to do a deep copy
unsigned int ts = 1;
for (unsigned int i=0; i<_ndim; i++) ts *= _dim[i];
_coef = new T[ts];
memcpy(_coef,src._coef,ts*sizeof(T));
}
}
/////////////////////////////////////////////////////////////////////
//
// Performs deconvolution, converting signal to spline coefficients.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment