Changeset 2910
- Timestamp:
- 01/26/10 09:24:07 (15 years ago)
- Location:
- issm/trunk/src/c/Bamgx
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/Bamgx/QuadTree.h
r2885 r2910 7 7 const int MaxDeep = 30; 8 8 typedef long IntQuad; 9 const IntQuad MaxISize = ( 1L << MaxDeep); 9 const IntQuad MaxISize = ( 1L << MaxDeep); //long int 1, bitwise operation: 8L = 00001000 << 2L -> 00100000 shifted left by 2 10 10 class Triangles; 11 11 class Vertex; -
issm/trunk/src/c/Bamgx/objects/Geometry.cpp
r2909 r2910 504 504 for (i=0;i<nbv;i++) vertices[i].link = vertices+i; 505 505 506 //build quadtree for this geometry (error if we have duplicates (k>0))506 //build quadtree for this geometry 507 507 for (i=0;i<nbv;i++){ 508 508 … … 515 515 vertices[i].i=toI2(vertices[i].r); 516 516 517 // Build the quadtree:517 //find nearest vertex already present in the quadtree (NULL if empty) 518 518 Vertex* v=quadtree.NearestVertex(vertices[i].i.x,vertices[i].i.y); 519 520 //if there is a vertex found that is to close to vertices[i] -> error 519 521 if( v && Norme1(v->r - vertices[i]) < eps ){ 520 522 // mama's old trick to get j … … 528 530 k++; 529 531 } 530 else quadtree.Add(vertices[i]); //Add vertices[i] to the quadtree 531 } 532 533 //The nearest vertex was non existent or far enough from vertices[i] 534 //Add vertices[i] to the quadtree 535 else quadtree.Add(vertices[i]); 536 } 537 538 //if k>0, there are some duplicate vertices -> error 532 539 if (k) { 533 540 printf("number of distinct vertices= %i, over %i\n",nbv - k,nbv); -
issm/trunk/src/c/Bamgx/objects/QuadTree.cpp
r2885 r2910 15 15 namespace bamg { 16 16 17 //INTER_SEG(a,b,x,y) returns 1 if [x y] is included in [a b] 17 18 #define INTER_SEG(a,b,x,y) (((y) > (a)) && ((x) <(b))) 19 //ABS(i) retruns |i| 18 20 #define ABS(i) ((i)<0 ?-(i) :(i)) 21 //MAX1(i,j) returns max(i,j) 19 22 #define MAX1(i,j) ((i)>(j) ?(i) :(j)) 23 //NORM(i1,j1,i2,j2) returns max(|i1-j1|,|i2-j2|) 20 24 #define NORM(i1,j1,i2,j2) MAX1(ABS((i1)-(j1)),ABS((i2)-(j2))) 21 25 //IJ(i,j,l) returns 3 if (1,1,1), 2 if (0,1,1), 1 if (1,0,1), else 0 22 26 #define IJ(i,j,l) ( ( j & l) ? (( i & l) ? 3 : 2 ) :( ( i & l)? 1 : 0 )) 27 //I_IJ(k,l) retruns l if first bit of k is 1, else 0 23 28 #define I_IJ(k,l) (( k&1) ? l : 0) 29 //J_IJ(k,l) retruns l if second bit of k is 1, else 0 24 30 #define J_IJ(k,l) (( k&2) ? l : 0) 25 31 … … 46 52 /*FUNCTION QuadTree::QuadTree(){{{1*/ 47 53 QuadTree::QuadTree() : 48 lenStorageQuadTreeBox(100), 49 th(0), 50 NbQuadTreeBox(0), 51 NbVertices(0), 52 NbQuadTreeBoxSearch(0), 53 NbVerticesSearch(0){ 54 sb =new StorageQuadTreeBox(lenStorageQuadTreeBox); 54 lenStorageQuadTreeBox(100), // by default 100 vertices by box 55 th(0), // initial mesh = NULL 56 NbQuadTreeBox(0), // initial number of quadtree boxes = 0 57 NbVertices(0), // initial number of vertices = 0 58 NbQuadTreeBoxSearch(0), // initial ?? = 0 59 NbVerticesSearch(0){ // initial ?? = 0 60 //create lenStorageQuadTreeBox (100) StorageQuadTreeBox elements 61 sb =new StorageQuadTreeBox(lenStorageQuadTreeBox); 62 //root=QuadTreeBox* pointer roward ?? 55 63 root=NewQuadTreeBox(); 56 64 } … … 71 79 pb = &root; 72 80 while((b=*pb) && (b->n<0)){ 73 b->n--; 74 l >>= 1; 75 pb = &b->b[IJ(i,j,l)]; 81 b->n--; //n=n-1 in b->n 82 l >>= 1; //shifted righ by one bit: l=00000010 -> 00000001 83 pb = &b->b[IJ(i,j,l)]; //pointer toward b 76 84 } 77 85 if (b) { … … 81 89 if (b->n > 0 && b->v[0] == &w) return; 82 90 } 91 92 //check that l is still non zero 83 93 if (l==0){ 84 throw ErrorException(__FUNCT__,exprintf("l==0 "));94 throw ErrorException(__FUNCT__,exprintf("l==0 cannot be true as it has been initialized as MaxISize = %i",MaxISize)); 85 95 } 86 96 while ((b= *pb) && (b->n == 4)){ // the QuadTreeBox is full … … 121 131 IntQuad hb=MaxISize; 122 132 Icoor1 i0=0,j0=0; 133 //iplus= i projected in [0,MaxISize-1] (example: if i<0, i=0) 123 134 Icoor1 iplus( i<MaxISize?(i<0?0:i):MaxISize-1); 135 //jplus= j projected in [0,MaxISize-1] (example: if j>=MaxISize, j=MaxISize-1) 124 136 Icoor1 jplus( j<MaxISize?(j<0?0:j):MaxISize-1); 125 126 Vertex *vn=0;137 //initial nearest vertex pointer 138 Vertex* vn=NULL; 127 139 128 140 //initialization for optimization … … 130 142 register Int4 n0; 131 143 132 if (!root->n) return vn; // empty tree 133 144 //if the tree is empty, return NULL pointer 145 if (!root->n) return vn; 146 147 //else: find the index n of the non empty 148 //QuadTreeBox containing the point (i,j) 134 149 while( (n0 = b->n) < 0){ 135 // search the non empty136 // QuadTreeBox containing the point (i,j)137 150 register Icoor1 hb2 = hb >> 1 ; 138 register int k = IJ(iplus,jplus,hb2);// QuadTreeBox number of size hb2 cont ening i;j139 register QuadTreeBox 140 if ( ( b0 == 0) || (b0->n == 0) ) break;// null box or empty => break151 register int k = IJ(iplus,jplus,hb2);// QuadTreeBox number of size hb2 containing i;j (Macro) 152 register QuadTreeBox* b0= b->b[k]; 153 if (( b0 == 0) || (b0->n == 0)) break;// null box or empty => break 141 154 NbQuadTreeBoxSearch++; 142 155 b=b0; 143 i0 += I_IJ(k,hb2); // i orign of QuadTreeBox 156 i0 += I_IJ(k,hb2); // i orign of QuadTreeBox (macro) 144 157 j0 += J_IJ(k,hb2); // j orign of QuadTreeBox 145 158 hb = hb2; 146 159 } 147 160 161 // if n0>0 ??? 148 162 if ( n0 > 0){ 149 163 for(register int k=0;k<n0;k++){ … … 169 183 register int k = pi[l]; 170 184 171 if (b->n>0){ // Vertex QuadTreeBox no neempty185 if (b->n>0){ // Vertex QuadTreeBox not empty 172 186 NbVerticesSearch++; 173 187 I2 i2 = b->v[k]->i; … … 179 193 } 180 194 } 181 else{ // Pointer QuadTreeBox 195 else{ // Pointer QuadTreeBox 182 196 register QuadTreeBox *b0=b; 183 197 NbQuadTreeBoxSearch++;
Note:
See TracChangeset
for help on using the changeset viewer.