Changeset 12273
- Timestamp:
- 05/22/12 10:54:55 (13 years ago)
- Location:
- issm/trunk-jpl/src/c
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/Container/Observations.cpp
r12231 r12273 78 78 } 79 79 else{ 80 //We need to average with the current observations (not done yet) 80 /*We need to average with the current observations*/ 81 this->quadtree->AddAndAverage(x[i],y[i],observations_list[i]); 81 82 } 82 83 } -
issm/trunk-jpl/src/c/objects/Kriging/Observation.cpp
r12229 r12273 15 15 Observation::Observation(double x_in,double y_in,int xi_in,int yi_in,int index_in,double value_in){ 16 16 17 this->x = x_in; 18 this->y = y_in; 19 this->xi = xi_in; 20 this->yi = yi_in; 21 this->index = index_in; 22 this->value = value_in; 17 this->x = x_in; 18 this->y = y_in; 19 this->xi = xi_in; 20 this->yi = yi_in; 21 this->index = index_in; 22 this->value = value_in; 23 this->weight = 1.; 23 24 24 25 } … … 42 43 printf(" xi : "); printbinary(this->xi); printf("\n"); 43 44 printf(" yi : "); printbinary(this->yi); printf("\n"); 45 printf(" weight: %g\n",this->weight); 44 46 printf(" value : %g\n",this->value); 45 47 } -
issm/trunk-jpl/src/c/objects/Kriging/Observation.h
r12229 r12273 14 14 int xi,yi; 15 15 int index; 16 double weight; 16 17 double value; 17 18 -
issm/trunk-jpl/src/c/objects/Kriging/Quadtree.cpp
r12230 r12273 198 198 199 199 }/*}}}*/ 200 /*FUNCTION Quadtree::AddAndAverage{{{1*/ 201 void Quadtree::AddAndAverage(double x,double y,double value){ 202 203 QuadtreeBox **pbox = NULL; 204 QuadtreeBox *box = NULL; 205 int xi,yi; 206 int level,levelbin; 207 int index; 208 double length,length2; 209 210 /*Get integer coodinates*/ 211 this->IntergerCoordinates(&xi,&yi,x,y); 212 213 /*Initialize levels*/ 214 level = 0; 215 levelbin = (1L<<this->MaxDepth);// = 2^30 216 217 /*Get inital box (the largest)*/ 218 pbox=&root; 219 220 /*Find the smallest box where this point is located*/ 221 while((box=*pbox) && (box->nbitems<0)){ 222 223 levelbin>>=1; level+=1; 224 225 pbox = &box->box[IJ(xi,yi,levelbin)]; 226 } 227 228 /*Add obervation in this box (should be full)*/ 229 if(box && box->nbitems==4){ 230 index = 0; 231 length = pow(box->obs[0]->x - x,2.) + pow(box->obs[0]->y - y,2.); 232 for(int i=1;i<4;i++){ 233 length2 = pow(box->obs[i]->x - x,2.) + pow(box->obs[i]->y - y,2.); 234 if(length2<length){ 235 index = i; 236 length = length2; 237 } 238 } 239 240 /*We found the closest observation, now average observation (do not change xi and yi to avoid round off errors*/ 241 box->obs[index]->x = (box->obs[index]->weight*box->obs[index]->x + x)/(box->obs[index]->weight+1); 242 box->obs[index]->y = (box->obs[index]->weight*box->obs[index]->y + y)/(box->obs[index]->weight+1); 243 box->obs[index]->xi= int((box->obs[index]->weight*double(box->obs[index]->xi) + double(xi))/(box->obs[index]->weight+1)); 244 box->obs[index]->yi= int((box->obs[index]->weight*double(box->obs[index]->yi) + double(yi))/(box->obs[index]->weight+1)); 245 box->obs[index]->value = (box->obs[index]->weight*box->obs[index]->value + value)/(box->obs[index]->weight+1); 246 box->obs[index]->weight += 1; 247 } 248 else{ 249 _error_("Box is not full"); 250 } 251 }/*}}}*/ 200 252 /*FUNCTION Quadtree::Echo{{{1*/ 201 253 void Quadtree::Echo(void){ -
issm/trunk-jpl/src/c/objects/Kriging/Quadtree.h
r12229 r12273 53 53 ~Quadtree(); 54 54 void Add(Observation *observation); 55 void AddAndAverage(double x,double y,double value); 55 56 void DeepEcho(void); 56 57 void Echo(void);
Note:
See TracChangeset
for help on using the changeset viewer.