Changeset 12226
- Timestamp:
- 05/08/12 13:35:24 (13 years ago)
- Location:
- issm/trunk-jpl/src/c
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/Container/Observations.cpp
r12225 r12226 32 32 } 33 33 /*}}}*/ 34 /*FUNCTION Observations::Observations(double* observations_list,double* x,double* y,int n ){{{*/35 Observations::Observations(double* observations_list,double* x,double* y,int n ){34 /*FUNCTION Observations::Observations(double* observations_list,double* x,double* y,int n,Options* options){{{*/ 35 Observations::Observations(double* observations_list,double* x,double* y,int n,Options* options){ 36 36 37 37 /*Intermediaries*/ 38 int i ;38 int i,maxdepth; 39 39 int xi,yi; 40 40 double xmin,xmax,ymin,ymax; 41 double offset ;41 double offset,minlength; 42 42 Observation *observation = NULL; 43 43 … … 52 52 offset=0.05*(ymax-ymin); ymin-=offset; ymax+=offset; 53 53 54 /*Get Minimum box size*/ 55 if(options->GetOption("boxlength")){ 56 options->Get(&minlength,"boxlength"); 57 if(minlength<=0)_error_("boxlength should be a positive number"); 58 maxdepth=int(log(max(xmax-xmin,ymax-ymin)/minlength +1)/log(2)); 59 } 60 else{ 61 maxdepth = 30; 62 minlength=max(xmax-xmin,ymax-ymin)/double((1L<<maxdepth)-1); 63 } 64 65 54 66 /*Initialize Quadtree*/ 55 this->quadtree = new Quadtree(xmin,xmax,ymin,ymax,30); 67 printf("Generating quadtree with a maximum box size %g (depth=%i)...",minlength,maxdepth); 68 this->quadtree = new Quadtree(xmin,xmax,ymin,ymax,maxdepth); 56 69 57 70 /*Add observations one by one*/ 71 int level; 58 72 for(i=0;i<n;i++){ 59 73 this->quadtree->IntergerCoordinates(&xi,&yi,x[i],y[i]); 60 observation = new Observation(x[i],y[i],xi,yi,observations_list[i]); 61 this->quadtree->Add(observation); 62 this->AddObject(observation); 74 this->quadtree->QuadtreeDepth2(&level,xi,yi); 75 if((int)level >= maxdepth){ 76 } 77 else{ 78 observation = new Observation(x[i],y[i],xi,yi,observations_list[i]); 79 this->quadtree->Add(observation); 80 this->AddObject(observation); 81 } 63 82 } 83 printf("done\n"); 64 84 } 65 85 /*}}}*/ … … 105 125 void Observations::QuadtreeColoring(double* A,double *x,double *y,int n){ 106 126 107 int xi,yi ;127 int xi,yi,level; 108 128 109 129 for(int i=0;i<n;i++){ 110 130 this->quadtree->IntergerCoordinates(&xi,&yi,x[i],y[i]); 111 this->quadtree->QuadtreeColoring(&A[i],xi,yi); 131 this->quadtree->QuadtreeDepth(&level,xi,yi); 132 A[i]=(double)level; 112 133 } 113 134 -
issm/trunk-jpl/src/c/Container/Observations.h
r12225 r12226 8 8 class Obsevration; 9 9 class Quadtree; 10 class Options; 10 11 11 12 class Observations: public DataSet{ … … 18 19 /*constructors, destructors*/ 19 20 Observations(); 20 Observations(double* observations_list,double* x,double* y,int n );21 Observations(double* observations_list,double* x,double* y,int n,Options* options); 21 22 ~Observations(); 22 23 -
issm/trunk-jpl/src/c/modules/Krigingx/Krigingx.cpp
r12213 r12226 40 40 41 41 /*Process observation dataset*/ 42 observations=new Observations(obs_list,obs_x,obs_y,obs_length );42 observations=new Observations(obs_list,obs_x,obs_y,obs_length,options); 43 43 44 44 /*Allocation output*/ -
issm/trunk-jpl/src/c/objects/Kriging/Quadtree.cpp
r12225 r12226 312 312 return newbox; 313 313 }/*}}}*/ 314 /*FUNCTION Quadtree::Quadtree Coloring{{{1*/315 void Quadtree::Quadtree Coloring(double* A,int xi,int yi){314 /*FUNCTION Quadtree::QuadtreeDepth{{{1*/ 315 void Quadtree::QuadtreeDepth(int* A,int xi,int yi){ 316 316 317 317 QuadtreeBox **pbox = NULL; … … 336 336 /*This box is not empty, add one level*/ 337 337 level+=1; 338 } 339 340 *A=level; 341 }/*}}}*/ 342 /*FUNCTION Quadtree::QuadtreeDepth2{{{1*/ 343 void Quadtree::QuadtreeDepth2(int* A,int xi,int yi){ 344 345 QuadtreeBox **pbox = NULL; 346 QuadtreeBox *box = NULL; 347 int level,levelbin; 348 349 /*Initialize levels*/ 350 level = 0; 351 levelbin = (1L<<this->MaxDepth);// = 2^30 352 353 /*Get inital box (the largest)*/ 354 pbox=&root; 355 356 /*Find the smallest box where this point is located*/ 357 while((box=*pbox) && (box->nbitems<0)){ 358 359 levelbin>>=1; level+=1; 360 361 pbox = &box->box[IJ(xi,yi,levelbin)]; 362 } 363 if(box && box->nbitems>0){ 364 /*This box is not empty, add one level*/ 365 level+=1; 366 } 367 368 /*If we were to add the vertex, get level*/ 369 if(box && box->nbitems==4){ 370 int ij; 371 bool flag=true; 372 while(flag){ 373 374 levelbin>>=1; level+=1; 375 if(level>this->MaxDepth){ 376 level+=1; 377 break; 378 } 379 380 /*loop over the four observations*/ 381 ij=IJ(box->obs[0]->xi,box->obs[0]->yi,levelbin); 382 for (int k=1;k<4;k++){ 383 if(IJ(box->obs[k]->xi,box->obs[k]->yi,levelbin) != ij){ 384 flag = false; 385 } 386 } 387 if(IJ(xi,yi,levelbin)!=ij){ 388 flag = false; 389 } 390 } 338 391 } 339 392 -
issm/trunk-jpl/src/c/objects/Kriging/Quadtree.h
r12225 r12226 53 53 QuadtreeBox *NewQuadtreeBox(double xcenter,double ycenter,double length); 54 54 QuadtreeBox *NewQuadtreeBox(QuadtreeBox* master,int index); 55 void QuadtreeColoring(double *A,int xi,int yi); 55 void QuadtreeDepth(int *A,int xi,int yi); 56 void QuadtreeDepth2(int *A,int xi,int yi); 56 57 }; 57 58 #endif //_QUADTREEK_H
Note:
See TracChangeset
for help on using the changeset viewer.