85 HyperRect(
int dim,
const double *min,
const double *max)
90 size_t size =
fDim *
sizeof(double);
91 memcpy(
fMin, min, size);
92 memcpy(
fMax, max, size);
107 size_t size =
fDim *
sizeof(double);
116 for (i=0; i <
fDim; i++)
118 if (pos[i] <
fMin[i])
122 if (pos[i] >
fMax[i])
133 for (
int i=0; i <
fDim; i++)
135 if (pos[i] <
fMin[i])
137 result +=
sqr(
fMin[i] - pos[i]);
139 else if (pos[i] >
fMax[i])
141 result +=
sqr(
fMax[i] - pos[i]);
144 if(result >= *bestmatch)
return false ;
162 if(
this == &rhs)
return *
this;
267 int ret(-1), added_res(0);
269 if(node->
GetData() && node != source_node)
271 bool do_break = false ;
273 for(
int i=0; i<fDim; i++)
276 if(dist_sq > range_sq)
282 if(!do_break && dist_sq <= range_sq)
284 list.
Insert(dist_sq, node);
291 ret =
__NearestInRange(dx <= 0.0 ? node->GetLeft() : node->
GetRight(), pos, range_sq, range, list, ordered, source_node);
292 if(ret >= 0 && fabs(dx) <= range)
295 ret =
__NearestInRange(dx <= 0.0 ? node->GetRight() : node->
GetLeft(), pos, range_sq, range, list, ordered, source_node);
313 double dummy(0.), dist_sq(-1.);
314 G4KDNode *nearer_subtree(0), *farther_subtree (0);
315 double *nearer_hyperrect_coord(0),*farther_hyperrect_coord(0);
321 nearer_subtree = node->
GetLeft();
324 nearer_hyperrect_coord = rect->
GetMax() + dir;
325 farther_hyperrect_coord = rect->
GetMin() + dir;
330 farther_subtree = node->
GetLeft();
331 nearer_hyperrect_coord = rect->
GetMin() + dir;
332 farther_hyperrect_coord = rect->
GetMax() + dir;
338 dummy = *nearer_hyperrect_coord;
339 *nearer_hyperrect_coord = node->
GetPosition()[dir];
343 *nearer_hyperrect_coord = dummy;
351 bool do_break = false ;
352 for(i=0; i < fDim; i++)
355 if(dist_sq > *result_dist_sq)
361 if (!do_break && dist_sq < *result_dist_sq)
364 *result_dist_sq = dist_sq;
371 dummy = *farther_hyperrect_coord;
372 *farther_hyperrect_coord = node->
GetPosition()[dir];
382 *farther_hyperrect_coord = dummy;
390 if (!fRect)
return 0;
409 rset->Insert(dist_sq, result);
421 const double *pos, std::vector<G4KDNode*>& result,
double *result_dist_sq,
425 double dummy, dist_sq;
426 G4KDNode *nearer_subtree (0), *farther_subtree (0);
427 double *nearer_hyperrect_coord (0), *farther_hyperrect_coord (0);
433 nearer_subtree = node->
GetLeft();
435 nearer_hyperrect_coord = rect->
GetMax() + dir;
436 farther_hyperrect_coord = rect->
GetMin() + dir;
441 farther_subtree = node->
GetLeft();
442 nearer_hyperrect_coord = rect->
GetMin() + dir;
443 farther_hyperrect_coord = rect->
GetMax() + dir;
449 dummy = *nearer_hyperrect_coord;
450 *nearer_hyperrect_coord = node->
GetPosition()[dir];
452 __NearestToNode(source_node, nearer_subtree, pos, result, result_dist_sq, rect, nbresult);
454 *nearer_hyperrect_coord = dummy;
459 if(node->
GetData() && node != source_node)
462 bool do_break =
false;
463 for(
int i=0; i < fDim; i++)
466 if(dist_sq > *result_dist_sq)
474 if (dist_sq < *result_dist_sq)
478 result.push_back(node);
479 *result_dist_sq = dist_sq;
481 else if(dist_sq == *result_dist_sq)
483 result.push_back(node);
492 dummy = *farther_hyperrect_coord;
493 *farther_hyperrect_coord = node->
GetPosition()[dir];
501 __NearestToNode(source_node, farther_subtree, pos, result, result_dist_sq, rect, nbresult);
504 *farther_hyperrect_coord = dummy;
518 std::vector<G4KDNode*> result;
539 rset->Insert(dist_sq, result[j]);
565 const double range_sq =
sqr(range) ;
597 const double range_sq =
sqr(range) ;
void * GetData(G4KDNode *)
G4DLLIMPORT std::ostream G4cout
const double * GetPosition()
G4KDNode * Insert(const double *p, void *data)
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)
int __NearestInRange(G4KDNode *node, const double *pos, const double &range_sq, const double &range, G4KDTreeResult &list, int ordered, G4KDNode *source_node=0)
void __NearestToPosition(G4KDNode *node, const double *pos, G4KDNode *&result, double *result_dist_sq, struct HyperRect *fRect)
G4KDTreeResultHandle NearestInRange(const double *pos, const double &range)
G4KDNode * Insert(const double *pos, void *data)
G4KDTreeResultHandle Nearest(const double *pos)
void __Clear_Rec(G4KDNode *node)
HyperRect(const HyperRect &rect)
bool CompareDistSqr(const double *pos, const double *bestmatch)
void Extend(const double *pos)
HyperRect(int dim, const double *min, const double *max)