46 for(
unsigned int ui=0;ui<
NUM_IONS;ui++)
50 xyzm[0] =
SCALE*((float)rand()/RAND_MAX-0.5);
51 xyzm[1] =
SCALE*((float)rand()/RAND_MAX-0.5);
52 xyzm[2] =
SCALE*((float)rand()/RAND_MAX-0.5);
53 xyzm[3] =
SCALE*((float)rand()/RAND_MAX-0.5);
54 ions[ui].setHit(xyzm);
68 for(
unsigned int ui=1;ui<kdExact.
size();ui++)
72 vector<size_t> resultA, resultB;
76 std::sort(resultA.begin(),resultA.end());
77 std::sort(resultB.begin(),resultB.end());
80 if(resultA.size() != resultB.size() ||
81 !(std::equal(resultA.begin(),resultA.end(),resultB.begin())))
83 cerr <<
"FAIL! Mismatched" << resultA.size () <<
" vs " << resultB.size() <<
"pts, sourcept : " << ui << endl;
86 for(
unsigned int uj=0;uj<resultA.size();uj++)
87 cerr <<
"\t" << kdExact.
getPtRef(resultA[uj]) << endl;
89 for(
unsigned int uj=0;uj<resultB.size();uj++)
90 cerr <<
"\t" << kdExact.
getPtRef(resultB[uj]) << endl;
104 pts.push_back(
Point3D(0,0.5,0.5));
105 pts.push_back(
Point3D(100,0,0));
118 cerr <<
"K3DTreeApprox findNearest check failed" << endl;
129 gettimeofday(&timeNow,NULL);
133 cerr <<
"TEST FAILED" << endl;
138 cerr <<
"Comparing two NN search methods to ensure they give the same answers, over many queries" << endl;
140 unsigned int randSeed=timeNow.tv_usec;
142 cerr <<
"Random seed :" << randSeed << endl;
143 cerr <<
"SCALE :" <<
SCALE <<
" Num Ions per Build : " <<
NUM_IONS << endl;
144 cerr <<
"Search radius :" <<
SEARCH_RAD << endl;
146 const unsigned int ITERATIONS=100;
147 cerr <<
"Attempting " << ITERATIONS <<
" random trees, finding ions in < search radius, using every ion as centre." << endl;
148 cerr <<
"Will repeat for :" << ITERATIONS <<
" passes" << endl;
149 for(
unsigned int ui=1;ui<ITERATIONS; ui++)
154 cerr <<
" Pass" << ui<< endl;
158 gettimeofday(&timeEnd,NULL);
160 timeDelta = (timeEnd.tv_sec - timeNow.tv_sec)*1e3 + (timeEnd.tv_usec - timeNow.tv_usec)/1000;
161 cerr <<
"Complete (" << timeDelta <<
" msec), all searches gave the same results" << endl;
float sqrDist(const Point3D &pt) const
Returns the square of distance to another Point3D.
void getBoundCube(BoundCube &b)
obtain the bounding rectangular prism volume for all elements in the KD tree
const unsigned int NUM_IONS
void setProgressPointer(unsigned int *p)
void findUntaggedInRadius(const Point3D &queryPt, const BoundCube &b, float radius, std::vector< size_t > &result)
Find untagged points within a given radius.
A 3D point data class storage.
void setCallback(bool(*cb)(void))
const Point3D * findNearest(const Point3D &, const BoundCube &, float deadDistSqr) const
Find the nearest point to a given P that lies outsid some dead zone.
Helper class to define a bounding cube.
void resetPts(std::vector< Point3D > &pts, bool clear=true)
Supply points to KD tree. Ouput vector will be erased if clear=true.
bool build()
Build the KD tree using the previously supplied points.
const Point3D & getPtRef(size_t index) const
void ptsInSphere(const Point3D &origin, float radius, std::vector< size_t > &pts) const
void build(const std::vector< Point3D > &pts)
Builds a balanced KD tree from a list of points.