89 fMin =
new double[fDim];
90 fMax =
new double[fDim];
91 size_t size = fDim *
sizeof(double);
92 memcpy(fMin, min, size);
93 memcpy(fMax, max, size);
106 fMin =
new double[fDim];
107 fMax =
new double[fDim];
108 size_t size = fDim *
sizeof(double);
109 memcpy(fMin, rect.
fMin, size);
110 memcpy(fMax, rect.
fMax, size);
117 for (i=0; i < fDim; i++)
119 if (pos[i] < fMin[i])
123 if (pos[i] > fMax[i])
134 for (
int i=0; i < fDim; i++)
136 if (pos[i] < fMin[i])
138 result +=
sqr(fMin[i] - pos[i]);
140 else if (pos[i] > fMax[i])
142 result +=
sqr(fMax[i] - pos[i]);
145 if(result >= *bestmatch)
return false ;
163 if(
this == &rhs)
return *
this;
190 if(fKDMap)
delete fKDMap;
243 int Nnodes = fKDMap->
GetSize();
252 for(
int n = 0 ;
n < Nnodes ;
n =
n+fDim)
254 for(
int dim = 0 ; dim < fDim ; dim ++)
309 int ret(-1), added_res(0);
311 if(node->
GetData() && node != source_node)
313 bool do_break = false ;
315 for(
int i=0; i<fDim; i++)
318 if(dist_sq > range_sq)
324 if(!do_break && dist_sq <= range_sq)
326 list.
Insert(dist_sq, node);
333 ret =
__NearestInRange(dx <= 0.0 ? node->GetLeft() : node->
GetRight(), pos, range_sq, range, list, ordered, source_node);
334 if(ret >= 0 && fabs(dx) <= range)
337 ret =
__NearestInRange(dx <= 0.0 ? node->GetRight() : node->
GetLeft(), pos, range_sq, range, list, ordered, source_node);
355 double dummy(0.), dist_sq(-1.);
356 G4KDNode *nearer_subtree(0), *farther_subtree (0);
357 double *nearer_hyperrect_coord(0),*farther_hyperrect_coord(0);
363 nearer_subtree = node->
GetLeft();
366 nearer_hyperrect_coord = rect->
GetMax() + dir;
367 farther_hyperrect_coord = rect->
GetMin() + dir;
372 farther_subtree = node->
GetLeft();
373 nearer_hyperrect_coord = rect->
GetMin() + dir;
374 farther_hyperrect_coord = rect->
GetMax() + dir;
380 dummy = *nearer_hyperrect_coord;
381 *nearer_hyperrect_coord = node->
GetPosition()[dir];
385 *nearer_hyperrect_coord = dummy;
393 bool do_break = false ;
394 for(i=0; i < fDim; i++)
397 if(dist_sq > *result_dist_sq)
403 if (!do_break && dist_sq < *result_dist_sq)
406 *result_dist_sq = dist_sq;
413 dummy = *farther_hyperrect_coord;
414 *farther_hyperrect_coord = node->
GetPosition()[dir];
424 *farther_hyperrect_coord = dummy;
432 if (!fRect)
return 0;
451 rset->Insert(dist_sq, result);
463 const double *pos, std::vector<G4KDNode*>& result,
double *result_dist_sq,
467 double dummy, dist_sq;
468 G4KDNode *nearer_subtree (0), *farther_subtree (0);
469 double *nearer_hyperrect_coord (0), *farther_hyperrect_coord (0);
475 nearer_subtree = node->
GetLeft();
477 nearer_hyperrect_coord = rect->
GetMax() + dir;
478 farther_hyperrect_coord = rect->
GetMin() + dir;
483 farther_subtree = node->
GetLeft();
484 nearer_hyperrect_coord = rect->
GetMin() + dir;
485 farther_hyperrect_coord = rect->
GetMax() + dir;
491 dummy = *nearer_hyperrect_coord;
492 *nearer_hyperrect_coord = node->
GetPosition()[dir];
494 __NearestToNode(source_node, nearer_subtree, pos, result, result_dist_sq, rect, nbresult);
496 *nearer_hyperrect_coord = dummy;
501 if(node->
GetData() && node != source_node)
504 bool do_break =
false;
505 for(
int i=0; i < fDim; i++)
508 if(dist_sq > *result_dist_sq)
516 if (dist_sq < *result_dist_sq)
520 result.push_back(node);
521 *result_dist_sq = dist_sq;
523 else if(dist_sq == *result_dist_sq)
525 result.push_back(node);
534 dummy = *farther_hyperrect_coord;
535 *farther_hyperrect_coord = node->
GetPosition()[dir];
543 __NearestToNode(source_node, farther_subtree, pos, result, result_dist_sq, rect, nbresult);
546 *farther_hyperrect_coord = dummy;
560 std::vector<G4KDNode*> result;
581 rset->Insert(dist_sq, result[j]);
607 const double range_sq =
sqr(range) ;
639 const double range_sq =
sqr(range) ;
void __Clear_Rec(G4KDNode *node)
G4KDNode * PopOutMiddle(int dimension)
HyperRect(const HyperRect &rect)
HyperRect(int dim, const double *min, const double *max)
void Extend(const double *pos)
G4KDNode * Insert(const double *p, void *data)
int __NearestInRange(G4KDNode *node, const double *pos, const double &range_sq, const double &range, G4KDTreeResult &list, int ordered, G4KDNode *source_node=0)
G4GLOB_DLL std::ostream G4cout
G4KDTreeResultHandle Nearest(const double *pos)
void Insert(double, G4KDNode *)
void __NearestToNode(G4KDNode *source_node, G4KDNode *node, const double *pos, std::vector< G4KDNode * > &result, double *result_dist_sq, struct HyperRect *fRect, int &nbresult)
G4KDNode * InsertMap(const double &x, const double &y, const double &z, void *data)
T max(const T t1, const T t2)
brief Return the largest of the two arguments
const double * GetPosition()
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
void __NearestToPosition(G4KDNode *node, const double *pos, G4KDNode *&result, double *result_dist_sq, struct HyperRect *fRect)
G4KDTreeResultHandle NearestInRange(const double *pos, const double &range)
void * GetData(G4KDNode *)
G4KDNode * Insert(const double *pos, void *data)
const XML_Char const XML_Char * data
void Insert(G4KDNode *pos)
bool CompareDistSqr(const double *pos, const double *bestmatch)