Skip to content
Snippets Groups Projects
Commit ce6c4673 authored by Mark Jenkinson's avatar Mark Jenkinson
Browse files

Removed all calls by copy (!! - yes COPY!) and replaced by calls by reference

parent b2bab736
No related branches found
No related tags found
No related merge requests found
...@@ -30,14 +30,12 @@ namespace MISCMATHS { ...@@ -30,14 +30,12 @@ namespace MISCMATHS {
return kernel(n)*(1.0-dn) + kernel(n+1)*dn; return kernel(n)*(1.0-dn) + kernel(n+1)*dn;
} }
inline bool in_bounds(ColumnVector data, int index) inline bool in_bounds(const ColumnVector& data, int index)
{ return ( (index>=1) && (index<=data.Nrows())); } { return ( (index>=1) && (index<=data.Nrows())); }
inline bool in_bounds(ColumnVector data, float index) inline bool in_bounds(const ColumnVector& data, float index)
{ return ( ((int)floor(index)>=1) && ((int)ceil(index)<=data.Nrows())); } { return ( ((int)floor(index)>=1) && ((int)ceil(index)<=data.Nrows())); }
// Support Functions
float sincfn(float x) float sincfn(float x)
{ {
if (fabs(x)<1e-7) { return 1.0-fabs(x); } if (fabs(x)<1e-7) { return 1.0-fabs(x); }
...@@ -125,7 +123,7 @@ namespace MISCMATHS { ...@@ -125,7 +123,7 @@ namespace MISCMATHS {
} }
// dummy fn for now // dummy fn for now
float extrapolate_1d(const ColumnVector data, const int index) float extrapolate_1d(const ColumnVector& data, const int index)
{ {
float extrapval; float extrapval;
...@@ -142,7 +140,7 @@ namespace MISCMATHS { ...@@ -142,7 +140,7 @@ namespace MISCMATHS {
} }
// basic trilinear call // basic trilinear call
float interpolate_1d(ColumnVector data, const float index) float interpolate_1d(const ColumnVector& data, const float index)
{ {
float interpval; float interpval;
int low_bound = (int)floor(index); int low_bound = (int)floor(index);
...@@ -159,7 +157,7 @@ namespace MISCMATHS { ...@@ -159,7 +157,7 @@ namespace MISCMATHS {
//////// Spline Support ///////// //////// Spline Support /////////
float hermiteinterpolation_1d(ColumnVector data, int p1, int p4, float t) float hermiteinterpolation_1d(const ColumnVector& data, int p1, int p4, float t)
{ {
// Q(t) = (2t^3 - 3t^2 + 1)P_1 + (-2t^3 + 3t^2)P_4 + (t^3 - 2t^2 + t)R_1 + (t^3 - t^2)R_4 // Q(t) = (2t^3 - 3t^2 + 1)P_1 + (-2t^3 + 3t^2)P_4 + (t^3 - 2t^2 + t)R_1 + (t^3 - t^2)R_4
// inputs: points P_1, P_4; tangents R_1, R_4; interpolation index t; // inputs: points P_1, P_4; tangents R_1, R_4; interpolation index t;
...@@ -193,24 +191,26 @@ namespace MISCMATHS { ...@@ -193,24 +191,26 @@ namespace MISCMATHS {
//////// Kernel Interpolation Call ///////// //////// Kernel Interpolation Call /////////
float kernelinterpolation_1d(ColumnVector data, float index, ColumnVector userkernel, int width) float kernelinterpolation_1d(const ColumnVector& data, float index, const ColumnVector& userkernel, int width)
{ {
int widthx = (width - 1)/2; int widthx = (width - 1)/2;
// kernel half-width (i.e. range is +/- w) // kernel half-width (i.e. range is +/- w)
int wx= widthx;
ColumnVector kernelx = userkernel;
float *storex = new float[2*wx+1];
int ix0; int ix0;
ix0 = (int) floor(index); ix0 = (int) floor(index);
static int wx=0;
static float *storex = 0;
if ( (wx!=widthx) || (storex==0) ) {
wx=widthx;
storex = new float[2*wx+1];
for (int d=-wx; d<=wx; d++) {
storex[d+wx] = kernelval((index-ix0+d),wx,userkernel);
}
}
float convsum=0.0, interpval=0.0, kersum=0.0; float convsum=0.0, interpval=0.0, kersum=0.0;
for (int d=-wx; d<=wx; d++) {
storex[d+wx] = kernelval((index-ix0+d),wx,kernelx);
}
int xj; int xj;
for (int x1=ix0-wx; x1<=ix0+wx; x1++) { for (int x1=ix0-wx; x1<=ix0+wx; x1++) {
if (in_bounds(data, x1)) { if (in_bounds(data, x1)) {
...@@ -223,8 +223,6 @@ namespace MISCMATHS { ...@@ -223,8 +223,6 @@ namespace MISCMATHS {
} }
} }
delete(storex);
if ( (fabs(kersum)>1e-9) ) { if ( (fabs(kersum)>1e-9) ) {
interpval = convsum / kersum; interpval = convsum / kersum;
} else { } else {
...@@ -238,7 +236,7 @@ namespace MISCMATHS { ...@@ -238,7 +236,7 @@ namespace MISCMATHS {
////// Kernel wrappers ////// ////// Kernel wrappers //////
float kernelinterpolation_1d(ColumnVector data, float index) float kernelinterpolation_1d(const ColumnVector& data, float index)
{ {
ColumnVector userkernel = sinckernel1D("hanning", 7, 1201); ColumnVector userkernel = sinckernel1D("hanning", 7, 1201);
return kernelinterpolation_1d(data, index, userkernel, 7); return kernelinterpolation_1d(data, index, userkernel, 7);
...@@ -251,14 +249,3 @@ namespace MISCMATHS { ...@@ -251,14 +249,3 @@ namespace MISCMATHS {
} }
} }
...@@ -167,12 +167,12 @@ namespace MISCMATHS { ...@@ -167,12 +167,12 @@ namespace MISCMATHS {
kernel sinckernel(const string& sincwindowtype, int w, int nstore); kernel sinckernel(const string& sincwindowtype, int w, int nstore);
kernel sinckernel(const string& sincwindowtype, kernel sinckernel(const string& sincwindowtype,
int wx, int wy, int wz, int nstore); int wx, int wy, int wz, int nstore);
float extrapolate_1d(const ColumnVector data, const int index); float extrapolate_1d(const ColumnVector& data, const int index);
float interpolate_1d(ColumnVector data, const float index); float interpolate_1d(const ColumnVector& data, const float index);
float kernelinterpolation_1d(ColumnVector data, float index, ColumnVector userkernel, int width); float kernelinterpolation_1d(const ColumnVector& data, float index, const ColumnVector& userkernel, int width);
float kernelinterpolation_1d(ColumnVector data, float index); float kernelinterpolation_1d(const ColumnVector& data, float index);
float kernelinterpolation_1d(RowVector data, float index); float kernelinterpolation_1d(RowVector data, float index);
float hermiteinterpolation_1d(ColumnVector data, int p1, int p4, float t); float hermiteinterpolation_1d(const ColumnVector& data, int p1, int p4, float t);
} }
#endif #endif
......
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