#include "searchgrid.h" #define MAXSHORT 32767 // ************************************************************* // * create empty grid from packed structure * // ************************************************************* searchgrid::searchgrid(float *geom) { printf("other constructor\n"); rmax=geom[0]; rmax2=rmax*rmax; zmax=geom[1]; npoint=mpoint=nsparse=0; printf("done\n"); } // ************************************************************* // * find distance^2 between two points p1 and p2 * // ************************************************************* inline double searchgrid::dis2(double &dx,double &dy,double &dz,int p1,int p2) { dx=points[3*p1]-points[3*p2]; // difference in x coordinate dy=points[3*p1+1]-points[3*p2+1]; // difference in y coordinate dz=points[3*p1+2]-points[3*p2+2]; // difference in z coordinate return(dx*dx+dy*dy+dz*dz); } // ************************************************************* // * find the first point in interval (p2min,p2max) to which * // * point p1 is closer than sqrt(d2max) * // ************************************************************* inline int searchgrid::close_to(double &dx,double &dy,double &dz, int p1,int p2min,int p2max,double d2max) { // loop through point p2 from p2min to p2max for(; p2minmpoint) expand_size(npoint+np-mpoint); rfac=rmax/MAXSHORT; zfac=zmax/MAXSHORT; for(np=0; npoint=mpoint) expand_size(stop-start); dmin*=dmin; // square minimum distance // copy first point points[3*npoint]=points[3*start]; points[3*npoint+1]=points[3*start+1]; points[3*npoint+2]=points[3*start+2]; mult[npoint++]=1; // loop through all other points for(point=start+1; point=mpoint) expand_size(stop-point); points[3*npoint]=points[3*point]; points[3*npoint+1]=points[3*point+1]; points[3*npoint+2]=points[3*point+2]; mult[npoint++]=1; } else { // yes, then add the point to the one found mult[sec]+=mult[point]; multfac=double(mult[point])/double(mult[sec]); points[3*sec]+=dx*multfac; points[3*sec+1]+=dy*multfac; points[3*sec+2]+=dz*multfac; } } } // ************************************************************* // * pack a set of grid points into a buffer, if size of buffer* // * is large enough * // ************************************************************* void searchgrid::packset(void *buffer,short int max_size,short int set) { short int *ibuffer=(short int *) buffer,np=size(set),start,i; float *fbuffer=(float *) buffer,val; if (max_size<10) return; ibuffer[4]=-1; if (np<=0) return; if (10+6*np>max_size) return; fbuffer[0]=rmax; fbuffer[1]=zmax; ibuffer+=4; *ibuffer++=np; if (set==0) start=0; // first set; else // last set if ((set<0) || (set==nsparse)) start=3*set_starts[nsparse-1]; else start=3*set_starts[set-1]; // any other set for(i=0; i