1 #include "../classes.h"
79 #define IJ(i,j,l) ((j&l) ? ((i&l) ? 3:2 ) :((i&l) ? 1:0 ))
84 _error_(
"Constructor not supported");
102 length=
max(xmax-xmin,ymax-ymin);
118 int xi,yi,ij,level,levelbin;
126 xi = observation->
xi;
127 yi = observation->
yi;
138 while((box=*pbox) && (box->
nbitems<0)){
145 pbox = &box->
box[
IJ(xi,yi,levelbin)];
150 while((box=*pbox) && (box->
nbitems==4)){
153 obs[0] = box->
obs[0];
154 obs[1] = box->
obs[1];
155 obs[2] = box->
obs[2];
156 obs[3] = box->
obs[3];
169 for (
int k=0;k<4;k++){
172 ij =
IJ(obs[k]->xi,obs[k]->yi,levelbin);
173 slave = box->
box[ij];
176 slave = box->
box[ij];
182 ij =
IJ(xi,yi,levelbin);
184 pbox = &box->
box[ij];
190 ij =
IJ(xi,yi,levelbin);
204 double length,length2;
216 while((box=*pbox) && (box->
nbitems<0)){
218 pbox = &box->
box[
IJ(xi,yi,levelbin)];
224 length = pow(box->
obs[0]->
x - x,2) + pow(box->
obs[0]->
y - y,2);
225 for(
int i=1;i<4;i++){
226 length2 = pow(box->
obs[i]->
x - x,2) + pow(box->
obs[i]->
y - y,2);
252 double length,length2;
264 while((box=*pbox) && (box->
nbitems<0)){
266 pbox = &box->
box[
IJ(xi,yi,levelbin)];
272 length = pow(box->
obs[0]->
x - x,2) + pow(box->
obs[0]->
y - y,2);
273 for(
int i=1;i<box->
nbitems;i++){
274 length2 = pow(box->
obs[i]->
x - x,2) + pow(box->
obs[i]->
y - y,2);
323 *xi=int(coefficient*(x - xmin));
324 *yi=int(coefficient*(y - ymin));
382 _error_(
"Case " << index <<
" not supported");
400 if(this->
NbObs) indices = xNew<int>(this->
NbObs);
424 while((box=*pbox) && (box->
nbitems<0)){
428 pbox = &box->
box[
IJ(xi,yi,levelbin)];
451 while((box=*pbox) && (box->
nbitems<0)){
453 levelbin>>=1; level+=1;
455 pbox = &box->
box[
IJ(xi,yi,levelbin)];
468 levelbin>>=1; level+=1;
476 for (
int k=1;k<4;k++){
481 if(
IJ(xi,yi,levelbin)!=ij){
495 for (
int i=0; i<4; ++i){
497 else qtreebox->
box[i] = NULL;
499 for (
int i=0; i<4; ++i){
501 else qtreebox->
obs[i] = NULL;
504 return (
Object*) qtreebox;
510 _printf_(
" nbitems = " << this->nbitems <<
"\n");
511 _printf_(
" xcenter = " << this->xcenter <<
"\n");
512 _printf_(
" ycenter = " << this->ycenter <<
"\n");
513 _printf_(
" length = " << this->length <<
"\n");
519 if(this->xcenter+this->length/2 < x-range)
return 0;
520 if(this->xcenter-this->length/2 > x+range)
return 0;
521 if(this->ycenter+this->length/2 < y-range)
return 0;
522 if(this->ycenter-this->length/2 > y+range)
return 0;
525 if(this->xcenter+this->length/2 <= x+range &&
526 this->ycenter+this->length/2 <= y+range &&
527 this->xcenter-this->length/2 >= x-range &&
528 this->ycenter-this->length/2 >= y-range)
return 2;
542 switch(this->IsWithinRange(x,y,range)){
548 this->WriteObservations(indices,&nobs);
554 for(i=0;i<this->nbitems;i++){
555 if(fabs(this->obs[i]->x-x) <= range && fabs(this->obs[i]->y-y) <= range){
556 indices[nobs++]=this->obs[i]->index;
562 if(this->box[0]) this->box[0]->RangeSearch(indices,&nobs,x,y,range);
563 if(this->box[1]) this->box[1]->RangeSearch(indices,&nobs,x,y,range);
564 if(this->box[2]) this->box[2]->RangeSearch(indices,&nobs,x,y,range);
565 if(this->box[3]) this->box[3]->RangeSearch(indices,&nobs,x,y,range);
569 _error_(
"Case " << this->IsWithinRange(x,y,range) <<
" not supported");
585 for(i=0;i<this->nbitems;i++){
586 indices[nobs++]=this->obs[i]->index;
591 if(this->box[0]) this->box[0]->WriteObservations(indices,&nobs);
592 if(this->box[1]) this->box[1]->WriteObservations(indices,&nobs);
593 if(this->box[2]) this->box[2]->WriteObservations(indices,&nobs);
594 if(this->box[3]) this->box[3]->WriteObservations(indices,&nobs);