Changeset 12213
- Timestamp:
- 05/04/12 16:53:41 (13 years ago)
- Location:
- issm/trunk-jpl/src/c
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/Container/Observations.cpp
r12210 r12213 28 28 /*FUNCTION Observations::Observations(){{{*/ 29 29 Observations::Observations(){ 30 this->quadtree = NULL; 30 31 return; 31 32 } … … 34 35 Observations::Observations(double* observations_list,double* x,double* y,int n){ 35 36 37 const int MaxICoor = 1073741823; // 2^30-1 =111...111 (29 times) 38 39 /*Intermediaries*/ 40 int i; 41 int xi,yi; 42 double offset; 43 Observation *observation = NULL; 44 45 /*Initialize Quadtree*/ 46 this->quadtree = new Quadtree(); 47 48 /*Get extrema*/ 49 this->xmin=x[0]; this->ymin=y[0]; 50 this->xmax=x[0]; this->ymax=y[0]; 51 for(i=1;i<n;i++){ 52 xmin=min(xmin,x[i]); ymin=min(ymin,y[i]); 53 xmax=max(xmax,x[i]); ymax=max(ymax,y[i]); 54 } 55 offset=0.05*(xmax-xmin); xmin-=offset; xmax+=offset; 56 offset=0.05*(ymax-ymin); ymin-=offset; ymax+=offset; 57 58 /*coeffIcoor is the coefficient used for integer coordinates: 59 * (x-xmin) 60 * xi = (2^30 -1) ------------ 61 * D 62 * coefficient = (2^30 -1)/D 63 */ 64 this->coefficient = double(MaxICoor)/max(xmax-xmin,ymax-ymin); _assert_(coefficient>=0); 65 36 66 /*Add observations one by one*/ 37 for(int i=0;i<n;i++){ 38 this->AddObject(new Observation(x[i],y[i],0,0,observations_list[i])); 67 for(i=0;i<n;i++){ 68 xi=int(coefficient*(x[i]-xmin)); 69 yi=int(coefficient*(y[i]-ymin)); 70 observation = new Observation(x[i],y[i],xi,yi,observations_list[i]); 71 this->quadtree->Add(observation); 72 this->AddObject(observation); 39 73 } 40 41 74 } 42 75 /*}}}*/ 43 76 /*FUNCTION Observations::~Observations(){{{*/ 44 77 Observations::~Observations(){ 78 delete quadtree; 45 79 return; 46 80 } … … 49 83 /*Methods*/ 50 84 /*FUNCTION Observations::ObservationList{{{*/ 51 void Observations::ObservationList(double **px,double **py,double **pobs,int* pnobs,double x_interp,double y_interp){ /*{{{*/85 void Observations::ObservationList(double **px,double **py,double **pobs,int* pnobs,double x_interp,double y_interp){ 52 86 53 87 /*Output and Intermediaries*/ … … 78 112 *pnobs=nobs; 79 113 }/*}}}*/ 114 /*FUNCTION Observations::QuadtreeColoring{{{*/ 115 void Observations::QuadtreeColoring(double* A,double *x,double *y,int n){ 116 117 /*Convert to integer coordinates*/ 118 int *xi = (int*)xmalloc(n*sizeof(int)); 119 int *yi = (int*)xmalloc(n*sizeof(int)); 120 for(int i=0;i<n;i++){ 121 xi[i]=int(coefficient*(x[i]-xmin)); 122 yi[i]=int(coefficient*(y[i]-ymin)); 123 } 124 125 /*Call quadtree method*/ 126 this->quadtree->QuadtreeColoring(A,xi,yi,n); 127 128 /*clean-up*/ 129 xfree((void**)&xi); 130 xfree((void**)&yi); 131 132 }/*}}}*/ -
issm/trunk-jpl/src/c/Container/Observations.h
r12210 r12213 7 7 8 8 class Obsevration; 9 class Quadtree; 9 10 10 11 class Observations: public DataSet{ 12 13 private: 14 Quadtree* quadtree; 15 double coefficient; //For integer coordinate conversion 16 double xmin; 17 double ymin; 18 double xmax; 19 double ymax; 11 20 12 21 public: … … 19 28 /*Methods*/ 20 29 void ObservationList(double **px,double **py,double **pobs,int* pnobs,double x_interp,double y_interp); 30 void QuadtreeColoring(double* A,double *x,double *y,int n); 21 31 22 32 }; -
issm/trunk-jpl/src/c/Container/Vertices.h
r10522 r12213 32 32 }; 33 33 34 35 36 34 #endif //ifndef _VERTICES_H_ 37 -
issm/trunk-jpl/src/c/modules/Krigingx/Krigingx.cpp
r12210 r12213 44 44 /*Allocation output*/ 45 45 predictions =(double*)xmalloc(n_interp*sizeof(double)); 46 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; 46 51 47 52 /*Loop over all interpolations*/ … … 101 106 delete observations; 102 107 *ppredictions=predictions; 108 return 1; 103 109 } 104 110 -
issm/trunk-jpl/src/c/objects/Kriging/Observation.cpp
r12207 r12213 3 3 */ 4 4 5 #include <stdlib.h> 5 6 #include "../objects.h" 6 7 … … 31 32 /*FUNCTION Observation::Echo {{{1*/ 32 33 void Observation::Echo(void){ 34 35 int bit; 36 33 37 printf("Observation\n"); 34 38 printf(" x : %g\n",this->x); 35 39 printf(" y : %g\n",this->y); 36 printf(" xi : %i\n",this->xi);37 printf(" yi : %i\n",this->yi);40 printf(" xi : "); printbinary(this->xi); printf("\n"); 41 printf(" yi : "); printbinary(this->yi); printf("\n"); 38 42 printf(" value : %g\n",this->value); 39 43 } -
issm/trunk-jpl/src/c/objects/Kriging/Quadtree.cpp
r12210 r12213 110 110 /*Intermediaries*/ 111 111 const int MaxDeep = 30; 112 int k,ij; 113 long i,j,level; 112 int xi,yi,ij,level; 114 113 QuadtreeBox **pb = NULL; 115 114 QuadtreeBox *b = NULL; 115 QuadtreeBox *bb = NULL; 116 Observation *obs[4]; 116 117 117 118 /*Get integer coodinates*/ 118 i = observation->xi;119 j= observation->yi;119 xi = observation->xi; 120 yi = observation->yi; 120 121 121 122 /*Initialize level*/ … … 128 129 while((b=*pb) && (b->nbitems<0)){ 129 130 130 /*shift b->nbitems by -1 as a counter*/131 b->nbitems--;132 133 131 /*Go down one level = 00100 -> 00010*/ 134 132 level>>=1; 135 133 136 134 /*Get next subbox according to the bit value (level)*/ 137 pb = &b->box[IJ( i,j,level)];135 pb = &b->box[IJ(xi,yi,level)]; 138 136 } 139 137 _assert_(level>0); … … 143 141 144 142 /*Copy the 4 observation in the current Quadtreebox*/ 145 Observation* obs[4];146 143 obs[0] = b->obs[0]; 147 144 obs[1] = b->obs[1]; … … 162 159 163 160 /*Put the four observations in the new boxes*/ 164 for ( k=0;k<4;k++){161 for (int k=0;k<4;k++){ 165 162 166 163 /*Get box for observation number k*/ 167 ij =IJ(obs[k]->xi,obs[k]->yi,level);168 QuadtreeBox *bb = b->box[ij];164 ij = IJ(obs[k]->xi,obs[k]->yi,level); 165 bb = b->box[ij]; 169 166 if(!bb){ 170 167 b->box[ij]=NewQuadtreeBox(); 171 168 bb=b->box[ij]; 172 169 } 173 174 /*Copy current observations*/175 170 bb->obs[bb->nbitems++] = obs[k]; 176 171 } 177 172 178 173 /*Get the subbox where the current observation is located*/ 179 ij=IJ( i,j,level);174 ij=IJ(xi,yi,level); 180 175 pb=&b->box[ij]; 181 176 } … … 183 178 /*alloc the QuadtreeBox if necessary and add current observation*/ 184 179 b=*pb; 185 if(!b) b=NewQuadtreeBox(); 180 if(!b){ 181 b=*pb=NewQuadtreeBox(); 182 } 186 183 b->obs[b->nbitems++]=observation; 187 184 NbObs++; 188 185 189 186 }/*}}}*/ 190 /*FUNCTION Quadtree::NewQuadtreeBox {{{1*/ 191 Quadtree::QuadtreeBox* Quadtree::NewQuadtreeBox(void){ 192 193 /*Output*/ 194 QuadtreeBox* newbox=NULL; 195 196 /*Create and initialize a new box*/ 197 newbox=new QuadtreeBox(); 198 newbox->nbitems=0; 199 newbox->box[0]=NULL; 200 newbox->box[1]=NULL; 201 newbox->box[2]=NULL; 202 newbox->box[3]=NULL; 203 204 /*Add root to the container*/ 205 boxcontainer->AddObject(newbox); 206 207 /*Increase counter*/ 208 NbQuadtreeBox++; 209 210 /*currentbox now points toward next quadtree box*/ 211 return newbox; 212 }/*}}}*/ 187 /*FUNCTION Quadtree::Echo{{{1*/ 188 void Quadtree::Echo(void){ 189 190 printf("Quadtree:\n"); 191 printf(" NbQuadtreeBox = %i\n",NbQuadtreeBox); 192 printf(" NbObs = %i\n",NbObs); 193 printf(" root = %p\n",root); 194 195 }/*}}}*/ 196 /*FUNCTION Quadtree::NewQuadtreeBox {{{1*/ 197 Quadtree::QuadtreeBox* Quadtree::NewQuadtreeBox(void){ 198 199 /*Output*/ 200 QuadtreeBox* newbox=NULL; 201 202 /*Create and initialize a new box*/ 203 newbox=new QuadtreeBox(); 204 newbox->nbitems=0; 205 newbox->box[0]=NULL; 206 newbox->box[1]=NULL; 207 newbox->box[2]=NULL; 208 newbox->box[3]=NULL; 209 210 /*Add to container*/ 211 this->boxcontainer->AddObject(newbox); 212 NbQuadtreeBox++; 213 214 /*currentbox now points toward next quadtree box*/ 215 return newbox; 216 }/*}}}*/ 217 /*FUNCTION Quadtree::QuadtreeColoring{{{1*/ 218 void Quadtree::QuadtreeColoring(double* A,int *xi,int *yi,int n){ 219 220 const int MaxDeep = 30; 221 QuadtreeBox **pb = NULL; 222 QuadtreeBox *b = NULL; 223 int level; 224 225 for(int i=0;i<n;i++){ 226 227 /*Initialize level*/ 228 level=(1L<<MaxDeep);// = 2^30 229 230 /*Get inital box (the largest)*/ 231 pb=&root; 232 233 /*Find the smallest box where the observation is located*/ 234 while((b=*pb) && (b->nbitems<0)){ 235 236 /*Color matrix onces more*/ 237 A[i]+=1; 238 239 /*Go to one box deeper*/ 240 level>>=1; 241 pb = &b->box[IJ(xi[i],yi[i],level)]; 242 } 243 } 244 }/*}}}*/ -
issm/trunk-jpl/src/c/objects/Kriging/Quadtree.h
r12210 r12213 41 41 Quadtree(); 42 42 ~Quadtree(); 43 void Add(Observation* observation); 44 QuadtreeBox* NewQuadtreeBox(void); 43 void Echo(void); 44 void Add(Observation *observation); 45 void QuadtreeColoring(double *A,int *xi,int *yi,int n); 46 QuadtreeBox *NewQuadtreeBox(void); 45 47 }; 46 48 #endif //_QUADTREEK_H -
issm/trunk-jpl/src/c/shared/Elements/elements.h
r11656 r12213 47 47 printf("\n"); 48 48 } 49 inline void printbinary(int n) { 50 unsigned int i; 51 i=1<<(sizeof(n)*8-1); 52 53 while (i>0) { 54 if (n&i) 55 printf("1"); 56 else 57 printf("0"); 58 i>>=1; 59 } 60 } 49 61 50 62 #endif //ifndef _SHARED_ELEMENTS_H_
Note:
See TracChangeset
for help on using the changeset viewer.