#include "scalefunctions.h" template void myNormalizeP(T *x, T *y) { //cout <<"Pointer version of myNormalize called\n"; T length; length = *x * *x + *y * *y; length = (T)sqrt(length); *x /= length; *y /= length; } template void myNormalize(T &x, T &y) { //cout <<"Reference version of myNormalize called\n"; T length; length = x * x + y * y; length = (T)sqrt(length); x /= length; y /= length; } template void myNormalizeP(T *x, T *y, T *z) { //cout <<"Pointer version of myNormalize called\n"; T length; length = *x * *x + *y * *y + *z * *z; length = (T)sqrt(length); *x /= length; *y /= length; *z /= length; } template void myNormalize(T &x, T &y, T &z) { cout <<"Reference version of myNormalize called \n"; T length; length = x * x + y * y + z * z; length = (T)sqrt(length); x /= length; y /= length; z /= length; } // template void myNormalize(T x, T y, T z) // { // cout <<"Common version of myNormalize called\n"; // } template void scaleArray(T *vector, const int length, const T min, const T max) { T oldmin, oldmax;//, scale; double scale = 1.0; minmax(vector, length, oldmin, oldmax); //oldrange = oldmax - oldmin; //newrange = max - min; //scale = newrange/oldrange; if(oldmax==oldmin) { // there is only one value in the array cout <<"WARNING:In scalefunctions.h scaleArray(): oldmin==oldmax=="<0.01) || (vector[i]>max && (max-vector[i])>0.01)){ // out of range values, 1% of tolerance cout <<"Values in scaleArray are out of range, even with 0.01 tolerance\n"; //printf("\tPosition %d has value %f whereas min is %f and max is %f\n", i, vector[i], min, max); //printf("\toldmin is %f, oldmax is %f, scale is %f\n", oldmin, oldmax, scale); } //assert(vector[i]>=min); //assert(vector[i]<=max); } } template void fitVectorToVolume(T *vector, const int length, const T xmin, const T xmax, const T ymin, const T ymax, const T zmin = 0, const T zmax = 0) { cout <<"ERROR:\tFunction fitVectorToVolume NOT YET FINISHED\n"; // function is not working properly! int Dimension = 3; if(zmin == zmax && zmin == 0){ Dimension = 2; } T _xmin, _xmax, _ymin, _ymax, _zmin, _zmax; getObjectBoundaries(vector, length, _xmin, _xmax, _ymin, _ymax, _zmin, _zmax); T _Xmove = 0.0; T _Ymove = 0.0; T _Zmove = 0.0; T _Xscale = 1.0; T _Yscale = 1.0; T _Zscale = 1.0; _Xscale = (xmax - xmin)/(_xmax - _xmin); _Yscale = (ymax - ymin)/(_ymax - _ymin); _Zscale = (zmax - zmin)/(_zmax - _zmin); _Xmove = _Xscale*(_xmax - _xmin)/2.0; _Ymove = _Yscale*(_ymax - _ymin)/2.0; _Zmove = _Zscale*(_zmax - _zmin)/2.0; cout <<"Some values: "< void fitVectorToArea(const T xmin, const T xmax, const T ymin, const T ymax, T *vector, const int length) { } template void centerAndScaleObject(T *vector, const int length, const T range, const int Dimension=3) { T _xmin, _xmax, _ymin, _ymax, _zmin, _zmax; getObjectBoundaries(vector, length, _xmin, _xmax, _ymin, _ymax, _zmin, _zmax, Dimension); centerObject(vector, length, _xmin, _xmax, _ymin, _ymax, _zmin, _zmax, Dimension); T _scale = scaleObject(vector, length, range, _xmin, _xmax, _ymin, _ymax, _zmin, _zmax, Dimension); for(int i=0; i T scaleObject(T *vector, const int length, const T range, const T xmin, const T xmax, const T ymin, const T ymax, const T zmin, const T zmax, const int Dimension=3) { T _small = xmax - xmin; T _medium = ymax - ymin; T _big = zmax - zmin; sort(_small, _medium, _big); return range/_big; } template void centerObject(T *vector, const int length, const int Dimension=3) { T _xmin, _xmax, _ymin, _ymax, _zmin, _zmax; getObjectBoundaries(vector, length, _xmin, _xmax, _ymin, _ymax, _zmin, _zmax, Dimension); centerObject(vector, length, _xmin, _xmax, _ymin, _ymax, _zmin, _zmax, Dimension); } template void centerObject(T *vector, const int length, const T xmin, const T xmax, const T ymin, const T ymax, const T zmin, const T zmax, const int Dimension=3) { T _xmove = xmax - (xmax-xmin)/T(2.0); T _ymove = ymax - (ymax-ymin)/T(2.0); T _zmove = zmax - (zmax-zmin)/T(2.0); for(int i=0; i xmax) xmax = vector[Dimension*i]; if(vector[Dimension*i+1] > ymax) ymax = vector[Dimension*i+1]; if(Dimension == 3 && vector[Dimension*i+2] > zmax) zmax = vector[Dimension*i+2]; } #ifdef INFO if(Dimension == 3){ cout <<"INFO:\tMinimum values found: ("<