Changeset 12210 for issm/trunk-jpl/src/c/objects/Kriging/Quadtree.cpp
- Timestamp:
- 05/04/12 12:26:38 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/objects/Kriging/Quadtree.cpp
r12207 r12210 47 47 * we just need to look at the bits from the left to the right (See ::Add) 48 48 }}}1*/ 49 /*MACROS {{{1*/ 50 /* 51 * 52 * J j 53 * ^ ^ 54 * | | +--------+--------+ 55 * | | | | | 56 * 1X | | | 2 | 3 | 57 * | | | | | 58 * | | +--------+--------+ 59 * | | | | | 60 * 0X | | | 0 | 1 | 61 * | | | | | 62 * | | +--------+--------+ 63 * | +-----------------------> i 64 * | 65 * |----------------------------> I 66 * X0 X1 67 * 68 * box 0 -> I=0 J=0 IJ=00 = 0 69 * box 1 -> I=1 J=0 IJ=01 = 1 70 * box 2 -> I=0 J=1 IJ=10 = 2 71 * box 3 -> I=1 J=1 IJ=11 = 3 72 */ 73 //IJ(i,j,l) returns the box number of i and j with respect to l 74 //if !j&l and !i&l -> 0 (box zero: lower left ) 75 //if !j&l and i&l -> 1 (box one: lower right) 76 //if j&l and !i&l -> 2 (box two: upper left ) 77 //if j&l and i&l -> 3 (box three:upper right) 78 #define IJ(i,j,l) ((j&l) ? ((i&l) ? 3:2 ) :((i&l) ? 1:0 )) 79 /*}}}*/ 49 80 50 81 /*Constructors/Destructors*/ … … 54 85 /*Number of boxes and vertices*/ 55 86 NbQuadtreeBox=0; 56 Nb Points=0;87 NbObs=0; 57 88 58 89 /*Create container*/ … … 74 105 75 106 /*Methods*/ 107 /*FUNCTION Quadtree::Add{{{1*/ 108 void Quadtree::Add(Observation* observation){ 109 110 /*Intermediaries*/ 111 const int MaxDeep = 30; 112 int k,ij; 113 long i,j,level; 114 QuadtreeBox **pb = NULL; 115 QuadtreeBox *b = NULL; 116 117 /*Get integer coodinates*/ 118 i = observation->xi; 119 j = observation->yi; 120 121 /*Initialize level*/ 122 level=(1L<<MaxDeep);// = 2^30 123 124 /*Get inital box (the largest)*/ 125 pb=&root; 126 127 /*Find the smallest box where the observation is located*/ 128 while((b=*pb) && (b->nbitems<0)){ 129 130 /*shift b->nbitems by -1 as a counter*/ 131 b->nbitems--; 132 133 /*Go down one level = 00100 -> 00010*/ 134 level>>=1; 135 136 /*Get next subbox according to the bit value (level)*/ 137 pb = &b->box[IJ(i,j,level)]; 138 } 139 _assert_(level>0); 140 141 /*Now, try to add the vertex, if the box is full (nbitems=4), we have to divide it in 4 new boxes*/ 142 while((b=*pb) && (b->nbitems==4)){ 143 144 /*Copy the 4 observation in the current Quadtreebox*/ 145 Observation* obs[4]; 146 obs[0] = b->obs[0]; 147 obs[1] = b->obs[1]; 148 obs[2] = b->obs[2]; 149 obs[3] = b->obs[3]; 150 151 /*set nbitems as negative (now holding boxes instead of observations)*/ 152 b->nbitems = -b->nbitems; 153 154 /*Initialize the 4 pointers toward the 4 subboxes*/ 155 b->box[0]=NULL; 156 b->box[1]=NULL; 157 b->box[2]=NULL; 158 b->box[3]=NULL; 159 160 /*level = 00100 -> 00010*/ 161 level>>=1; 162 163 /*Put the four observations in the new boxes*/ 164 for (k=0;k<4;k++){ 165 166 /*Get box for observation number k*/ 167 ij=IJ(obs[k]->xi,obs[k]->yi,level); 168 QuadtreeBox *bb = b->box[ij]; 169 if(!bb){ 170 b->box[ij]=NewQuadtreeBox(); 171 bb=b->box[ij]; 172 } 173 174 /*Copy current observations*/ 175 bb->obs[bb->nbitems++] = obs[k]; 176 } 177 178 /*Get the subbox where the current observation is located*/ 179 ij=IJ(i,j,level); 180 pb=&b->box[ij]; 181 } 182 183 /*alloc the QuadtreeBox if necessary and add current observation*/ 184 b=*pb; 185 if(!b) b=NewQuadtreeBox(); 186 b->obs[b->nbitems++]=observation; 187 NbObs++; 188 189 }/*}}}*/ 76 190 /*FUNCTION Quadtree::NewQuadtreeBox {{{1*/ 77 191 Quadtree::QuadtreeBox* Quadtree::NewQuadtreeBox(void){
Note:
See TracChangeset
for help on using the changeset viewer.