Changeset 12229
- Timestamp:
- 05/10/12 10:41:54 (13 years ago)
- Location:
- issm/trunk-jpl/src/c
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified issm/trunk-jpl/src/c/Container/Observations.cpp ¶
r12228 r12229 36 36 37 37 /*Intermediaries*/ 38 int i,maxdepth ;38 int i,maxdepth,level,counter; 39 39 int xi,yi; 40 40 double xmin,xmax,ymin,ymax; … … 63 63 } 64 64 65 66 65 /*Initialize Quadtree*/ 67 printf("Generating quadtree with a maximum box size %g (depth=%i)... ",minlength,maxdepth);66 printf("Generating quadtree with a maximum box size %g (depth=%i)... ",minlength,maxdepth); 68 67 this->quadtree = new Quadtree(xmin,xmax,ymin,ymax,maxdepth); 69 68 70 69 /*Add observations one by one*/ 71 int level;70 counter = 0; 72 71 for(i=0;i<n;i++){ 73 72 this->quadtree->IntergerCoordinates(&xi,&yi,x[i],y[i]); 74 73 this->quadtree->QuadtreeDepth2(&level,xi,yi); 75 if((int)level >= maxdepth){ 74 if((int)level <= maxdepth){ 75 observation = new Observation(x[i],y[i],xi,yi,counter++,observations_list[i]); 76 this->quadtree->Add(observation); 77 this->AddObject(observation); 76 78 } 77 79 else{ 78 observation = new Observation(x[i],y[i],xi,yi,observations_list[i]); 79 this->quadtree->Add(observation); 80 this->AddObject(observation); 80 //We need to average with the current observations (not done yet) 81 81 } 82 82 } … … 93 93 /*Methods*/ 94 94 /*FUNCTION Observations::ObservationList{{{*/ 95 void Observations::ObservationList(double **px,double **py,double **pobs,int* pnobs,double x_interp,double y_interp ){95 void Observations::ObservationList(double **px,double **py,double **pobs,int* pnobs,double x_interp,double y_interp,double range){ 96 96 97 97 /*Output and Intermediaries*/ 98 int nobs,i; 99 double *x = NULL; 100 double *y = NULL; 101 double *obs = NULL; 102 Observation *observation = NULL; 98 int nobs,i,index; 99 double *x = NULL; 100 double *y = NULL; 101 double *obs = NULL; 102 Observation *observation = NULL; 103 int *indices = NULL; 103 104 104 /*Get number of observations*/ 105 nobs = this->Size(); 105 /*Treat range*/ 106 if(range==0){ 107 range=this->quadtree->root->length; 108 } 106 109 107 /*Allocate vectors*/ 108 x = (double*)xmalloc(nobs*sizeof(double)); 109 y = (double*)xmalloc(nobs*sizeof(double)); 110 obs = (double*)xmalloc(nobs*sizeof(double)); 110 /*Find all observations that are in range*/ 111 this->quadtree->RangeSearch(&indices,&nobs,x_interp,y_interp,range); 111 112 112 /*Loop over all observations and fill in x, y and obs*/ 113 for (i=0;i<nobs;i++){ 114 observation=(Observation*)this->GetObjectByOffset(i); 115 observation->WriteXYObs(&x[i],&y[i],&obs[i]); 113 if(nobs==0){ 114 /*No observation found, double range*/ 115 printf("No observation found within range, doubling range\n"); 116 xfree((void**)&indices); 117 this->ObservationList(&x,&y,&obs,&nobs,x_interp,y_interp,range*2); 118 } 119 else{ 120 if(nobs>1000) printf("Taking more than 1000 observations\n"); 121 /*Allocate vectors*/ 122 x = (double*)xmalloc(nobs*sizeof(double)); 123 y = (double*)xmalloc(nobs*sizeof(double)); 124 obs = (double*)xmalloc(nobs*sizeof(double)); 125 126 /*Loop over all observations and fill in x, y and obs*/ 127 for (i=0;i<nobs;i++){ 128 observation=(Observation*)this->GetObjectByOffset(indices[i]); 129 observation->WriteXYObs(&x[i],&y[i],&obs[i]); 130 } 116 131 } 117 132 118 133 /*Assign output pointer*/ 134 xfree((void**)&indices); 119 135 *px=x; 120 136 *py=y; -
TabularUnified issm/trunk-jpl/src/c/Container/Observations.h ¶
r12226 r12229 23 23 24 24 /*Methods*/ 25 void ObservationList(double **px,double **py,double **pobs,int* pnobs,double x_interp,double y_interp );25 void ObservationList(double **px,double **py,double **pobs,int* pnobs,double x_interp,double y_interp,double range); 26 26 void QuadtreeColoring(double* A,double *x,double *y,int n); 27 27 -
TabularUnified issm/trunk-jpl/src/c/modules/Krigingx/Krigingx.cpp ¶
r12226 r12229 23 23 /*Intermediaries*/ 24 24 int i,j,n_obs; 25 double range; 25 26 double numerator,denominator,ratio; 26 27 double *x = NULL; … … 33 34 double *gamma0 = NULL; 34 35 double *ones = NULL; 36 char *output = NULL; 35 37 Variogram *variogram = NULL; 36 38 Observations *observations = NULL; … … 38 40 /*Get Variogram from Options*/ 39 41 ProcessVariogram(&variogram,options); 42 options->Get(&range,"searchrange",0.); 40 43 41 44 /*Process observation dataset*/ … … 44 47 /*Allocation output*/ 45 48 predictions =(double*)xmalloc(n_interp*sizeof(double)); 49 for(i=0;i<n_interp;i++) predictions[i]=0; 46 50 47 for(i=0;i<n_interp;i++) predictions[i]=0; 48 observations->QuadtreeColoring(predictions,x_interp,y_interp,n_interp); 49 *ppredictions=predictions; 50 return 1; 51 /*Get output*/ 52 options->Get(&output,"output","quadtree"); 53 54 if(strcmp(output,"quadtree")==0){ 55 observations->QuadtreeColoring(predictions,x_interp,y_interp,n_interp); 56 *ppredictions=predictions; 57 return 1; 58 } 51 59 52 60 /*Loop over all interpolations*/ … … 56 64 57 65 /*Get list of observations for current point*/ 58 observations->ObservationList(&x,&y,&obs,&n_obs,x_interp[idx],y_interp[idx] );66 observations->ObservationList(&x,&y,&obs,&n_obs,x_interp[idx],y_interp[idx],range); 59 67 60 68 /*Allocate intermediary matrix and vectors*/ … … 105 113 delete variogram; 106 114 delete observations; 115 xfree((void**)&output); 107 116 *ppredictions=predictions; 108 117 return 1; -
TabularUnified issm/trunk-jpl/src/c/objects/Bamg/BamgQuadtree.h ¶
r12218 r12229 1 1 /*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, BamgQuadtree.h)*/ 2 #ifndef _ QUADTREE_H3 #define _ QUADTREE_H2 #ifndef _BAMGQUADTREE_H 3 #define _BAMGQUADTREE_H 4 4 5 5 #include "./include.h" -
TabularUnified issm/trunk-jpl/src/c/objects/Kriging/Observation.cpp ¶
r12213 r12229 12 12 } 13 13 /*}}}*/ 14 /*FUNCTION Observation::Observation(double x,double y,int xi,int yi, double value){{{1*/15 Observation::Observation(double x_in,double y_in,int xi_in,int yi_in, double value_in){14 /*FUNCTION Observation::Observation(double x,double y,int xi,int yi,int index,double value){{{1*/ 15 Observation::Observation(double x_in,double y_in,int xi_in,int yi_in,int index_in,double value_in){ 16 16 17 17 this->x = x_in; … … 19 19 this->xi = xi_in; 20 20 this->yi = yi_in; 21 this->index = index_in; 21 22 this->value = value_in; 22 23 … … 36 37 37 38 printf("Observation\n"); 39 printf(" index : %i\n",this->index); 38 40 printf(" x : %g\n",this->x); 39 41 printf(" y : %g\n",this->y); -
TabularUnified issm/trunk-jpl/src/c/objects/Kriging/Observation.h ¶
r12207 r12229 13 13 double x,y; 14 14 int xi,yi; 15 int index; 15 16 double value; 16 17 17 18 /*Observation constructors, destructors*/ 18 19 Observation(); 19 Observation(double x_in,double y_in,int xi_in,int yi_in, double value_in);20 Observation(double x_in,double y_in,int xi_in,int yi_in,int index_in,double value_in); 20 21 ~Observation(); 21 22 … … 31 32 void WriteXYObs(double* px,double* py,double* pobs); 32 33 }; 33 #endif /* _ EXPONENTIALVARIOGRAM_H*/34 #endif /* _OBSERVATION_*/ -
TabularUnified issm/trunk-jpl/src/c/objects/Kriging/Quadtree.cpp ¶
r12226 r12229 393 393 *A=level; 394 394 }/*}}}*/ 395 /*FUNCTION Quadtree::RangeSearch{{{1*/ 396 void Quadtree::RangeSearch(int **pindices,int *pnobs,double x,double y,double range){ 397 398 /*Intermediaries*/ 399 int nobs; 400 int *indices = NULL; 401 402 /*Allocate indices (maximum by default*/ 403 indices = (int*)xmalloc(this->NbObs*sizeof(int)); 404 nobs = 0; 405 406 this->root->RangeSearch(indices,&nobs,x,y,range); 407 408 /*Clean-up and return*/ 409 *pnobs=nobs; 410 *pindices=indices; 411 412 }/*}}}*/ 395 413 396 414 /*QuadtreeBox methos*/ … … 405 423 406 424 }/*}}}*/ 425 /*FUNCTION QuadtreeBox::IsWithinRange{{{1*/ 426 int Quadtree::QuadtreeBox::IsWithinRange(double x,double y,double range){ 427 428 /*Return 0 if the 2 boxes do not overlap*/ 429 if(this->xcenter+this->length/2 < x-range) return 0; 430 if(this->xcenter-this->length/2 > x+range) return 0; 431 if(this->ycenter+this->length/2 < y-range) return 0; 432 if(this->ycenter-this->length/2 > y+range) return 0; 433 434 /*Return 2 if the this box is included in the range*/ 435 if( 436 this->xcenter+this->length/2 <= x+range && 437 this->ycenter+this->length/2 <= y+range && 438 this->xcenter-this->length/2 >= x-range && 439 this->ycenter-this->length/2 >= y-range 440 ) return 2; 441 442 /*This is a simple overlap*/ 443 return 1; 444 445 }/*}}}*/ 446 /*FUNCTION QuadtreeBox::RangeSearch{{{1*/ 447 void Quadtree::QuadtreeBox::RangeSearch(int* indices,int *pnobs,double x,double y,double range){ 448 449 /*Intermediaries*/ 450 int i,nobs; 451 452 /*Recover current number of observations*/ 453 nobs = *pnobs; 454 455 switch(this->IsWithinRange(x,y,range)){ 456 case 0: 457 /*If this box is not within range, return*/ 458 break; 459 case 2: 460 /*This box is included in range*/ 461 this->WriteObservations(indices,&nobs); 462 break; 463 case 1: 464 /*This box is partly included*/ 465 if(this->nbitems>0){ 466 /*If this box has only observations, add indices that are within range*/ 467 for(i=0;i<this->nbitems;i++){ 468 if(fabs(this->obs[i]->x-x) <= range && fabs(this->obs[i]->y-y) <= range){ 469 indices[nobs++]=this->obs[i]->index; 470 } 471 } 472 } 473 else{ 474 /*This box points toward boxes*/ 475 if(this->box[0]) this->box[0]->RangeSearch(indices,&nobs,x,y,range); 476 if(this->box[1]) this->box[1]->RangeSearch(indices,&nobs,x,y,range); 477 if(this->box[2]) this->box[2]->RangeSearch(indices,&nobs,x,y,range); 478 if(this->box[3]) this->box[3]->RangeSearch(indices,&nobs,x,y,range); 479 } 480 break; 481 default: 482 _error_("Case %i not supported",this->IsWithinRange(x,y,range)); 483 } 484 485 /*Assign output pointers: */ 486 *pnobs=nobs; 487 }/*}}}*/ 488 /*FUNCTION QuadtreeBox::WriteObservations{{{1*/ 489 void Quadtree::QuadtreeBox::WriteObservations(int* indices,int *pnobs){ 490 491 /*Intermediaries*/ 492 int i,nobs; 493 494 /*Recover current number of observations*/ 495 nobs = *pnobs; 496 497 if(this->nbitems>0){ 498 /*If this box has only observations, add all indices*/ 499 for(i=0;i<this->nbitems;i++){ 500 indices[nobs++]=this->obs[i]->index; 501 } 502 } 503 else{ 504 /*This box points toward boxes, */ 505 if(this->box[0]) this->box[0]->WriteObservations(indices,&nobs); 506 if(this->box[1]) this->box[1]->WriteObservations(indices,&nobs); 507 if(this->box[2]) this->box[2]->WriteObservations(indices,&nobs); 508 if(this->box[3]) this->box[3]->WriteObservations(indices,&nobs); 509 } 510 511 /*Assign output pointers: */ 512 *pnobs=nobs; 513 }/*}}}*/ -
TabularUnified issm/trunk-jpl/src/c/objects/Kriging/Quadtree.h ¶
r12226 r12229 1 1 2 #ifndef _QUADTREE K_H3 #define _QUADTREE K_H2 #ifndef _QUADTREE_H 3 #define _QUADTREE_H 4 4 5 5 class Observation; … … 32 32 int ObjectEnum(){_error_("not implemented yet"); }; 33 33 Object *copy() {_error_("not implemented yet"); }; 34 35 /*Methods*/ 36 int IsWithinRange(double x,double y,double range); 37 void RangeSearch(int* indices,int *pnobs,double x,double y,double range); 38 void WriteObservations(int* indices,int *pnobs); 39 34 40 }; 35 41 … … 39 45 public: 40 46 int MaxDepth; // maximum number of subdivision 41 double coordconversion; // Coefficient to convert coordinates to integer42 47 QuadtreeBox *root; // main box 43 48 long NbQuadtreeBox; // total number of boxes … … 55 60 void QuadtreeDepth(int *A,int xi,int yi); 56 61 void QuadtreeDepth2(int *A,int xi,int yi); 62 void RangeSearch(int **pindices,int *pnobs,double x,double y,double range); 57 63 }; 58 #endif //_QUADTREE K_H64 #endif //_QUADTREE_H
Note:
See TracChangeset
for help on using the changeset viewer.