29 #ifndef DOXY_IGNORE_THIS
50 template<
class NodeData,
class Real>
56 Allocator.set(blockSize);
60 template<
class NodeData,
class Real>
63 template <
class NodeData,
class Real>
66 d=off[0]=off[1]=off[2]=0;
69 template <
class NodeData,
class Real>
71 if(!UseAlloc){
if(children){
delete[] children;}}
74 template <
class NodeData,
class Real>
78 if( !children ) initChildren();
79 for(
int i=0 ; i<8 ; i++ ) children[i].setFullDepth( maxDepth-1 );
83 template <
class NodeData,
class Real>
86 if( UseAlloc ) children=Allocator.newElements(8);
89 if( children )
delete[] children;
91 children =
new OctNode[Cube::CORNERS];
95 fprintf(stderr,
"Failed to initialize children in OctNode::initChildren\n");
100 depthAndOffset( d , off );
101 for(
int i=0 ; i<2 ; i++ )
for(
int j=0 ; j<2 ; j++ )
for(
int k=0 ; k<2 ; k++ )
103 int idx=Cube::CornerIndex(i,j,k);
104 children[idx].parent =
this;
105 children[idx].children = NULL;
107 off2[0] = (off[0]<<1)+i;
108 off2[1] = (off[1]<<1)+j;
109 off2[2] = (off[2]<<1)+k;
110 Index( d+1 , off2 , children[idx].d , children[idx].off );
114 template <
class NodeData,
class Real>
117 off[0]=short((1<<depth)+offset[0]-1);
118 off[1]=short((1<<depth)+offset[1]-1);
119 off[2]=short((1<<depth)+offset[2]-1);
122 template<
class NodeData,
class Real>
125 offset[0]=(int(off[0])+1)&(~(1<<depth));
126 offset[1]=(int(off[1])+1)&(~(1<<depth));
127 offset[2]=(int(off[2])+1)&(~(1<<depth));
129 template<
class NodeData,
class Real>
131 template<
class NodeData,
class Real>
133 depth=int(index&DepthMask);
134 offset[0]=(int((index>>OffsetShift1)&OffsetMask)+1)&(~(1<<depth));
135 offset[1]=(int((index>>OffsetShift2)&OffsetMask)+1)&(~(1<<depth));
136 offset[2]=(int((index>>OffsetShift3)&OffsetMask)+1)&(~(1<<depth));
138 template<
class NodeData,
class Real>
140 template <
class NodeData,
class Real>
144 offset[0]=(int(off[0])+1)&(~(1<<depth));
145 offset[1]=(int(off[1])+1)&(~(1<<depth));
146 offset[2]=(int(off[2])+1)&(~(1<<depth));
147 width=Real(1.0/(1<<depth));
148 for(
int dim=0;dim<DIMENSION;dim++){center.coords[dim]=Real(0.5+offset[dim])*width;}
150 template<
class NodeData ,
class Real >
155 centerAndWidth( c , w );
157 return (c[0]-w)<p[0] && p[0]<=(c[0]+w) && (c[1]-w)<p[1] && p[1]<=(c[1]+w) && (c[2]-w)<p[2] && p[2]<=(c[2]+w);
159 template <
class NodeData,
class Real>
162 depth=index&DepthMask;
163 offset[0]=(int((index>>OffsetShift1)&OffsetMask)+1)&(~(1<<depth));
164 offset[1]=(int((index>>OffsetShift2)&OffsetMask)+1)&(~(1<<depth));
165 offset[2]=(int((index>>OffsetShift3)&OffsetMask)+1)&(~(1<<depth));
166 width=Real(1.0/(1<<depth));
167 for(
int dim=0;dim<DIMENSION;dim++){center.coords[dim]=Real(0.5+offset[dim])*width;}
170 template <
class NodeData,
class Real>
172 if(!children){
return 0;}
176 for(
unsigned int i=0;i<Cube::CORNERS;i++){
177 d=children[i].maxDepth();
183 template <
class NodeData,
class Real>
185 if(!children){
return 1;}
188 for(
unsigned int i=0;i<Cube::CORNERS;i++){c+=children[i].nodes();}
192 template <
class NodeData,
class Real>
194 if(!children){
return 1;}
197 for(
unsigned int i=0;i<Cube::CORNERS;i++){c+=children[i].leaves();}
201 template<
class NodeData,
class Real>
203 if(depth()>maxDepth){
return 0;}
204 if(!children){
return 1;}
207 for(
unsigned int i=0;i<Cube::CORNERS;i++){c+=children[i].maxDepthLeaves(maxDepth);}
211 template <
class NodeData,
class Real>
214 while(temp->parent){temp=temp->parent;}
219 template <
class NodeData,
class Real>
222 if( !current->parent || current==
this )
return NULL;
223 if(current-current->parent->children==Cube::CORNERS-1)
return nextBranch( current->parent );
224 else return current+1;
226 template <
class NodeData,
class Real>
228 if(!current->parent || current==
this){
return NULL;}
229 if(current-current->parent->children==Cube::CORNERS-1){
return nextBranch(current->parent);}
230 else{
return current+1;}
232 template<
class NodeData ,
class Real >
235 if( !current->parent || current==
this )
return NULL;
236 if( current-current->parent->children==0 )
return prevBranch( current->parent );
237 else return current-1;
239 template<
class NodeData ,
class Real >
242 if( !current->parent || current==
this )
return NULL;
243 if( current-current->parent->children==0 )
return prevBranch( current->parent );
244 else return current-1;
246 template <
class NodeData,
class Real>
250 while(temp->children){temp=&temp->children[0];}
253 if(current->children){
return current->nextLeaf();}
254 const OctNode* temp=nextBranch(current);
255 if(!temp){
return NULL;}
256 else{
return temp->nextLeaf();}
258 template <
class NodeData,
class Real>
262 while(temp->children){temp=&temp->children[0];}
265 if(current->children){
return current->nextLeaf();}
266 OctNode* temp=nextBranch(current);
267 if(!temp){
return NULL;}
268 else{
return temp->nextLeaf();}
271 template <
class NodeData,
class Real>
274 if( !current )
return this;
275 else if( current->children )
return ¤t->children[0];
276 else return nextBranch(current);
278 template <
class NodeData,
class Real>
281 if( !current )
return this;
282 else if( current->children )
return ¤t->children[0];
283 else return nextBranch( current );
286 template <
class NodeData,
class Real>
290 centerAndWidth(center,width);
291 for(
int dim=0;dim<DIMENSION;dim++){
292 printf(
"[%f,%f]",center.coords[dim]-width/2,center.coords[dim]+width/2);
293 if(dim<DIMENSION-1){printf(
"x");}
298 template <
class NodeData,
class Real>
301 template <
class NodeData,
class Real>
302 template<
class NodeAdjacencyFunction>
304 if(processCurrent){F->Function(
this,node);}
305 if(children){__processNodeNodes(node,F);}
307 template <
class NodeData,
class Real>
308 template<
class NodeAdjacencyFunction>
310 if(processCurrent){F->Function(
this,node);}
313 Cube::FaceCorners(fIndex,c1,c2,c3,c4);
314 __processNodeFaces(node,F,c1,c2,c3,c4);
317 template <
class NodeData,
class Real>
318 template<
class NodeAdjacencyFunction>
320 if(processCurrent){F->Function(
this,node);}
323 Cube::EdgeCorners(eIndex,c1,c2);
324 __processNodeEdges(node,F,c1,c2);
327 template <
class NodeData,
class Real>
328 template<
class NodeAdjacencyFunction>
330 if(processCurrent){F->Function(
this,node);}
332 while(temp->children){
333 temp=&temp->children[cIndex];
334 F->Function(temp,node);
337 template <
class NodeData,
class Real>
338 template<
class NodeAdjacencyFunction>
340 F->Function(&children[0],node);
341 F->Function(&children[1],node);
342 F->Function(&children[2],node);
343 F->Function(&children[3],node);
344 F->Function(&children[4],node);
345 F->Function(&children[5],node);
346 F->Function(&children[6],node);
347 F->Function(&children[7],node);
348 if(children[0].children){children[0].__processNodeNodes(node,F);}
349 if(children[1].children){children[1].__processNodeNodes(node,F);}
350 if(children[2].children){children[2].__processNodeNodes(node,F);}
351 if(children[3].children){children[3].__processNodeNodes(node,F);}
352 if(children[4].children){children[4].__processNodeNodes(node,F);}
353 if(children[5].children){children[5].__processNodeNodes(node,F);}
354 if(children[6].children){children[6].__processNodeNodes(node,F);}
355 if(children[7].children){children[7].__processNodeNodes(node,F);}
357 template <
class NodeData,
class Real>
358 template<
class NodeAdjacencyFunction>
360 F->Function(&children[cIndex1],node);
361 F->Function(&children[cIndex2],node);
362 if(children[cIndex1].children){children[cIndex1].__processNodeEdges(node,F,cIndex1,cIndex2);}
363 if(children[cIndex2].children){children[cIndex2].__processNodeEdges(node,F,cIndex1,cIndex2);}
365 template <
class NodeData,
class Real>
366 template<
class NodeAdjacencyFunction>
368 F->Function(&children[cIndex1],node);
369 F->Function(&children[cIndex2],node);
370 F->Function(&children[cIndex3],node);
371 F->Function(&children[cIndex4],node);
372 if(children[cIndex1].children){children[cIndex1].__processNodeFaces(node,F,cIndex1,cIndex2,cIndex3,cIndex4);}
373 if(children[cIndex2].children){children[cIndex2].__processNodeFaces(node,F,cIndex1,cIndex2,cIndex3,cIndex4);}
374 if(children[cIndex3].children){children[cIndex3].__processNodeFaces(node,F,cIndex1,cIndex2,cIndex3,cIndex4);}
375 if(children[cIndex4].children){children[cIndex4].__processNodeFaces(node,F,cIndex1,cIndex2,cIndex3,cIndex4);}
377 template<
class NodeData,
class Real>
378 template<
class NodeAdjacencyFunction>
380 int c1[3],c2[3],w1,w2;
381 node1->centerIndex(maxDepth+1,c1);
382 node2->centerIndex(maxDepth+1,c2);
383 w1=node1->width(maxDepth+1);
384 w2=node2->width(maxDepth+1);
386 ProcessNodeAdjacentNodes(c1[0]-c2[0],c1[1]-c2[1],c1[2]-c2[2],node1,(width1*w1)>>1,node2,(width2*w2)>>1,w2,F,processCurrent);
388 template<
class NodeData,
class Real>
389 template<
class NodeAdjacencyFunction>
393 NodeAdjacencyFunction* F,
int processCurrent){
394 if(!Overlap(dx,dy,dz,radius1+radius2)){
return;}
395 if(processCurrent){F->Function(node2,node1);}
396 if(!node2->children){
return;}
397 __ProcessNodeAdjacentNodes(-dx,-dy,-dz,node1,radius1,node2,radius2,width2/2,F);
399 template<
class NodeData,
class Real>
400 template<
class TerminatingNodeAdjacencyFunction>
402 int c1[3],c2[3],w1,w2;
403 node1->centerIndex(maxDepth+1,c1);
404 node2->centerIndex(maxDepth+1,c2);
405 w1=node1->width(maxDepth+1);
406 w2=node2->width(maxDepth+1);
408 ProcessTerminatingNodeAdjacentNodes(c1[0]-c2[0],c1[1]-c2[1],c1[2]-c2[2],node1,(width1*w1)>>1,node2,(width2*w2)>>1,w2,F,processCurrent);
410 template<
class NodeData,
class Real>
411 template<
class TerminatingNodeAdjacencyFunction>
415 TerminatingNodeAdjacencyFunction* F,
int processCurrent)
417 if(!Overlap(dx,dy,dz,radius1+radius2)){
return;}
418 if(processCurrent){F->Function(node2,node1);}
419 if(!node2->children){
return;}
420 __ProcessTerminatingNodeAdjacentNodes(-dx,-dy,-dz,node1,radius1,node2,radius2,width2/2,F);
422 template<
class NodeData,
class Real>
423 template<
class Po
intAdjacencyFunction>
427 node2->centerIndex( maxDepth+1 , c2 );
428 w2 = node2->width( maxDepth+1 );
429 ProcessPointAdjacentNodes( c1[0]-c2[0] , c1[1]-c2[1] , c1[2]-c2[2] , node2 , (width2*w2)>>1 , w2 , F , processCurrent );
431 template<
class NodeData,
class Real>
432 template<
class Po
intAdjacencyFunction>
435 PointAdjacencyFunction* F,
int processCurrent)
437 if( !Overlap(dx,dy,dz,radius2) )
return;
438 if( processCurrent ) F->Function(node2);
439 if( !node2->children )
return;
440 __ProcessPointAdjacentNodes( -dx , -dy , -dz , node2 , radius2 , width2>>1 , F );
442 template<
class NodeData,
class Real>
443 template<
class NodeAdjacencyFunction>
447 int depth,NodeAdjacencyFunction* F,
int processCurrent)
449 int c1[3],c2[3],w1,w2;
450 node1->centerIndex(maxDepth+1,c1);
451 node2->centerIndex(maxDepth+1,c2);
452 w1=node1->width(maxDepth+1);
453 w2=node2->width(maxDepth+1);
455 ProcessFixedDepthNodeAdjacentNodes(c1[0]-c2[0],c1[1]-c2[1],c1[2]-c2[2],node1,(width1*w1)>>1,node2,(width2*w2)>>1,w2,depth,F,processCurrent);
457 template<
class NodeData,
class Real>
458 template<
class NodeAdjacencyFunction>
462 int depth,NodeAdjacencyFunction* F,
int processCurrent)
464 int d=node2->depth();
466 if(!Overlap(dx,dy,dz,radius1+radius2)){
return;}
467 if(d==depth){
if(processCurrent){F->Function(node2,node1);}}
469 if(!node2->children){
return;}
470 __ProcessFixedDepthNodeAdjacentNodes(-dx,-dy,-dz,node1,radius1,node2,radius2,width2/2,depth-1,F);
473 template<
class NodeData,
class Real>
474 template<
class NodeAdjacencyFunction>
478 int depth,NodeAdjacencyFunction* F,
int processCurrent)
480 int c1[3],c2[3],w1,w2;
481 node1->centerIndex(maxDepth+1,c1);
482 node2->centerIndex(maxDepth+1,c2);
483 w1=node1->width(maxDepth+1);
484 w2=node2->width(maxDepth+1);
485 ProcessMaxDepthNodeAdjacentNodes(c1[0]-c2[0],c1[1]-c2[1],c1[2]-c2[2],node1,(width1*w1)>>1,node2,(width2*w2)>>1,w2,depth,F,processCurrent);
487 template<
class NodeData,
class Real>
488 template<
class NodeAdjacencyFunction>
492 int depth,NodeAdjacencyFunction* F,
int processCurrent)
494 int d=node2->depth();
496 if(!Overlap(dx,dy,dz,radius1+radius2)){
return;}
497 if(processCurrent){F->Function(node2,node1);}
498 if(d<depth && node2->children){__ProcessMaxDepthNodeAdjacentNodes(-dx,-dy,-dz,node1,radius1,node2,radius2,width2>>1,depth-1,F);}
500 template <
class NodeData,
class Real>
501 template<
class NodeAdjacencyFunction>
504 OctNode* node2,
int radius2,
int cWidth2,
505 NodeAdjacencyFunction* F)
507 int cWidth=cWidth2>>1;
508 int radius=radius2>>1;
509 int o=ChildOverlap(dx,dy,dz,radius1+radius,cWidth);
517 if(o& 1){F->Function(&node2->children[0],node1);
if(node2->children[0].children){__ProcessNodeAdjacentNodes(dx1,dy1,dz1,node1,radius1,&node2->children[0],radius,cWidth,F);}}
518 if(o& 2){F->Function(&node2->children[1],node1);
if(node2->children[1].children){__ProcessNodeAdjacentNodes(dx2,dy1,dz1,node1,radius1,&node2->children[1],radius,cWidth,F);}}
519 if(o& 4){F->Function(&node2->children[2],node1);
if(node2->children[2].children){__ProcessNodeAdjacentNodes(dx1,dy2,dz1,node1,radius1,&node2->children[2],radius,cWidth,F);}}
520 if(o& 8){F->Function(&node2->children[3],node1);
if(node2->children[3].children){__ProcessNodeAdjacentNodes(dx2,dy2,dz1,node1,radius1,&node2->children[3],radius,cWidth,F);}}
521 if(o& 16){F->Function(&node2->children[4],node1);
if(node2->children[4].children){__ProcessNodeAdjacentNodes(dx1,dy1,dz2,node1,radius1,&node2->children[4],radius,cWidth,F);}}
522 if(o& 32){F->Function(&node2->children[5],node1);
if(node2->children[5].children){__ProcessNodeAdjacentNodes(dx2,dy1,dz2,node1,radius1,&node2->children[5],radius,cWidth,F);}}
523 if(o& 64){F->Function(&node2->children[6],node1);
if(node2->children[6].children){__ProcessNodeAdjacentNodes(dx1,dy2,dz2,node1,radius1,&node2->children[6],radius,cWidth,F);}}
524 if(o&128){F->Function(&node2->children[7],node1);
if(node2->children[7].children){__ProcessNodeAdjacentNodes(dx2,dy2,dz2,node1,radius1,&node2->children[7],radius,cWidth,F);}}
527 template <
class NodeData,
class Real>
528 template<
class TerminatingNodeAdjacencyFunction>
531 OctNode* node2,
int radius2,
int cWidth2,
532 TerminatingNodeAdjacencyFunction* F)
534 int cWidth=cWidth2>>1;
535 int radius=radius2>>1;
536 int o=ChildOverlap(dx,dy,dz,radius1+radius,cWidth);
544 if(o& 1){
if(F->Function(&node2->children[0],node1) && node2->children[0].children){__ProcessTerminatingNodeAdjacentNodes(dx1,dy1,dz1,node1,radius1,&node2->children[0],radius,cWidth,F);}}
545 if(o& 2){
if(F->Function(&node2->children[1],node1) && node2->children[1].children){__ProcessTerminatingNodeAdjacentNodes(dx2,dy1,dz1,node1,radius1,&node2->children[1],radius,cWidth,F);}}
546 if(o& 4){
if(F->Function(&node2->children[2],node1) && node2->children[2].children){__ProcessTerminatingNodeAdjacentNodes(dx1,dy2,dz1,node1,radius1,&node2->children[2],radius,cWidth,F);}}
547 if(o& 8){
if(F->Function(&node2->children[3],node1) && node2->children[3].children){__ProcessTerminatingNodeAdjacentNodes(dx2,dy2,dz1,node1,radius1,&node2->children[3],radius,cWidth,F);}}
548 if(o& 16){
if(F->Function(&node2->children[4],node1) && node2->children[4].children){__ProcessTerminatingNodeAdjacentNodes(dx1,dy1,dz2,node1,radius1,&node2->children[4],radius,cWidth,F);}}
549 if(o& 32){
if(F->Function(&node2->children[5],node1) && node2->children[5].children){__ProcessTerminatingNodeAdjacentNodes(dx2,dy1,dz2,node1,radius1,&node2->children[5],radius,cWidth,F);}}
550 if(o& 64){
if(F->Function(&node2->children[6],node1) && node2->children[6].children){__ProcessTerminatingNodeAdjacentNodes(dx1,dy2,dz2,node1,radius1,&node2->children[6],radius,cWidth,F);}}
551 if(o&128){
if(F->Function(&node2->children[7],node1) && node2->children[7].children){__ProcessTerminatingNodeAdjacentNodes(dx2,dy2,dz2,node1,radius1,&node2->children[7],radius,cWidth,F);}}
554 template <
class NodeData,
class Real>
555 template<
class Po
intAdjacencyFunction>
557 OctNode* node2,
int radius2,
int cWidth2,
558 PointAdjacencyFunction* F)
560 int cWidth=cWidth2>>1;
561 int radius=radius2>>1;
562 int o=ChildOverlap(dx,dy,dz,radius,cWidth);
571 if(o& 1){F->Function(&node2->children[0]);
if(node2->children[0].children){__ProcessPointAdjacentNodes(dx1,dy1,dz1,&node2->children[0],radius,cWidth,F);}}
572 if(o& 2){F->Function(&node2->children[1]);
if(node2->children[1].children){__ProcessPointAdjacentNodes(dx2,dy1,dz1,&node2->children[1],radius,cWidth,F);}}
573 if(o& 4){F->Function(&node2->children[2]);
if(node2->children[2].children){__ProcessPointAdjacentNodes(dx1,dy2,dz1,&node2->children[2],radius,cWidth,F);}}
574 if(o& 8){F->Function(&node2->children[3]);
if(node2->children[3].children){__ProcessPointAdjacentNodes(dx2,dy2,dz1,&node2->children[3],radius,cWidth,F);}}
575 if(o& 16){F->Function(&node2->children[4]);
if(node2->children[4].children){__ProcessPointAdjacentNodes(dx1,dy1,dz2,&node2->children[4],radius,cWidth,F);}}
576 if(o& 32){F->Function(&node2->children[5]);
if(node2->children[5].children){__ProcessPointAdjacentNodes(dx2,dy1,dz2,&node2->children[5],radius,cWidth,F);}}
577 if(o& 64){F->Function(&node2->children[6]);
if(node2->children[6].children){__ProcessPointAdjacentNodes(dx1,dy2,dz2,&node2->children[6],radius,cWidth,F);}}
578 if(o&128){F->Function(&node2->children[7]);
if(node2->children[7].children){__ProcessPointAdjacentNodes(dx2,dy2,dz2,&node2->children[7],radius,cWidth,F);}}
581 template <
class NodeData,
class Real>
582 template<
class NodeAdjacencyFunction>
585 OctNode* node2,
int radius2,
int cWidth2,
586 int depth,NodeAdjacencyFunction* F)
588 int cWidth=cWidth2>>1;
589 int radius=radius2>>1;
590 int o=ChildOverlap(dx,dy,dz,radius1+radius,cWidth);
598 if(node2->depth()==depth){
599 if(o& 1){F->Function(&node2->children[0],node1);}
600 if(o& 2){F->Function(&node2->children[1],node1);}
601 if(o& 4){F->Function(&node2->children[2],node1);}
602 if(o& 8){F->Function(&node2->children[3],node1);}
603 if(o& 16){F->Function(&node2->children[4],node1);}
604 if(o& 32){F->Function(&node2->children[5],node1);}
605 if(o& 64){F->Function(&node2->children[6],node1);}
606 if(o&128){F->Function(&node2->children[7],node1);}
609 if(o& 1){
if(node2->children[0].children){__ProcessFixedDepthNodeAdjacentNodes(dx1,dy1,dz1,node1,radius1,&node2->children[0],radius,cWidth,depth,F);}}
610 if(o& 2){
if(node2->children[1].children){__ProcessFixedDepthNodeAdjacentNodes(dx2,dy1,dz1,node1,radius1,&node2->children[1],radius,cWidth,depth,F);}}
611 if(o& 4){
if(node2->children[2].children){__ProcessFixedDepthNodeAdjacentNodes(dx1,dy2,dz1,node1,radius1,&node2->children[2],radius,cWidth,depth,F);}}
612 if(o& 8){
if(node2->children[3].children){__ProcessFixedDepthNodeAdjacentNodes(dx2,dy2,dz1,node1,radius1,&node2->children[3],radius,cWidth,depth,F);}}
613 if(o& 16){
if(node2->children[4].children){__ProcessFixedDepthNodeAdjacentNodes(dx1,dy1,dz2,node1,radius1,&node2->children[4],radius,cWidth,depth,F);}}
614 if(o& 32){
if(node2->children[5].children){__ProcessFixedDepthNodeAdjacentNodes(dx2,dy1,dz2,node1,radius1,&node2->children[5],radius,cWidth,depth,F);}}
615 if(o& 64){
if(node2->children[6].children){__ProcessFixedDepthNodeAdjacentNodes(dx1,dy2,dz2,node1,radius1,&node2->children[6],radius,cWidth,depth,F);}}
616 if(o&128){
if(node2->children[7].children){__ProcessFixedDepthNodeAdjacentNodes(dx2,dy2,dz2,node1,radius1,&node2->children[7],radius,cWidth,depth,F);}}
620 template <
class NodeData,
class Real>
621 template<
class NodeAdjacencyFunction>
624 OctNode* node2,
int radius2,
int cWidth2,
625 int depth,NodeAdjacencyFunction* F)
627 int cWidth=cWidth2>>1;
628 int radius=radius2>>1;
629 int o=ChildOverlap(dx,dy,dz,radius1+radius,cWidth);
637 if(node2->depth()<=depth){
638 if(o& 1){F->Function(&node2->children[0],node1);}
639 if(o& 2){F->Function(&node2->children[1],node1);}
640 if(o& 4){F->Function(&node2->children[2],node1);}
641 if(o& 8){F->Function(&node2->children[3],node1);}
642 if(o& 16){F->Function(&node2->children[4],node1);}
643 if(o& 32){F->Function(&node2->children[5],node1);}
644 if(o& 64){F->Function(&node2->children[6],node1);}
645 if(o&128){F->Function(&node2->children[7],node1);}
647 if(node2->depth()<depth){
648 if(o& 1){
if(node2->children[0].children){__ProcessMaxDepthNodeAdjacentNodes(dx1,dy1,dz1,node1,radius1,&node2->children[0],radius,cWidth,depth,F);}}
649 if(o& 2){
if(node2->children[1].children){__ProcessMaxDepthNodeAdjacentNodes(dx2,dy1,dz1,node1,radius1,&node2->children[1],radius,cWidth,depth,F);}}
650 if(o& 4){
if(node2->children[2].children){__ProcessMaxDepthNodeAdjacentNodes(dx1,dy2,dz1,node1,radius1,&node2->children[2],radius,cWidth,depth,F);}}
651 if(o& 8){
if(node2->children[3].children){__ProcessMaxDepthNodeAdjacentNodes(dx2,dy2,dz1,node1,radius1,&node2->children[3],radius,cWidth,depth,F);}}
652 if(o& 16){
if(node2->children[4].children){__ProcessMaxDepthNodeAdjacentNodes(dx1,dy1,dz2,node1,radius1,&node2->children[4],radius,cWidth,depth,F);}}
653 if(o& 32){
if(node2->children[5].children){__ProcessMaxDepthNodeAdjacentNodes(dx2,dy1,dz2,node1,radius1,&node2->children[5],radius,cWidth,depth,F);}}
654 if(o& 64){
if(node2->children[6].children){__ProcessMaxDepthNodeAdjacentNodes(dx1,dy2,dz2,node1,radius1,&node2->children[6],radius,cWidth,depth,F);}}
655 if(o&128){
if(node2->children[7].children){__ProcessMaxDepthNodeAdjacentNodes(dx2,dy2,dz2,node1,radius1,&node2->children[7],radius,cWidth,depth,F);}}
659 template <
class NodeData,
class Real>
667 if(dx<w2 && dx>-w1){test =1;}
668 if(dx<w1 && dx>-w2){test|=2;}
671 if(dz<w2 && dz>-w1){test1 =test;}
672 if(dz<w1 && dz>-w2){test1|=test<<4;}
674 if(!test1){
return 0;}
675 if(dy<w2 && dy>-w1){overlap =test1;}
676 if(dy<w1 && dy>-w2){overlap|=test1<<2;}
680 template <
class NodeData,
class Real>
686 if(!children){
return this;}
687 centerAndWidth(center,width);
689 while(temp->children){
690 cIndex=CornerIndex(center,p);
691 temp=&temp->children[cIndex];
693 if(cIndex&1){center.coords[0]+=width/2;}
694 else {center.coords[0]-=width/2;}
695 if(cIndex&2){center.coords[1]+=width/2;}
696 else {center.coords[1]-=width/2;}
697 if(cIndex&4){center.coords[2]+=width/2;}
698 else {center.coords[2]-=width/2;}
702 template <
class NodeData,
class Real>
706 if(!children){
return this;}
707 for(
unsigned int i=0;i<Cube::CORNERS;i++){
708 temp=SquareDistance(children[i].center,p);
709 if(!i || temp<dist2){
714 return children[nearest].getNearestLeaf(p);
717 template <
class NodeData,
class Real>
719 int o1,o2,i1,i2,j1,j2;
721 Cube::FactorEdgeIndex(eIndex1,o1,i1,j1);
722 Cube::FactorEdgeIndex(eIndex2,o2,i2,j2);
723 if(o1!=o2){
return 0;}
729 case 0: dir[0]=1; dir[1]=2;
break;
730 case 1: dir[0]=0; dir[1]=2;
break;
731 case 2: dir[0]=0; dir[1]=1;
break;
733 int d1,d2,off1[3],off2[3];
734 node1->depthAndOffset(d1,off1);
735 node2->depthAndOffset(d2,off2);
736 idx1[0]=off1[dir[0]]+(1<<d1)+i1;
737 idx1[1]=off1[dir[1]]+(1<<d1)+j1;
738 idx2[0]=off2[dir[0]]+(1<<d2)+i2;
739 idx2[1]=off2[dir[1]]+(1<<d2)+j2;
748 if(idx1[0]==idx2[0] && idx1[1]==idx2[1]){
return 1;}
751 template<
class NodeData,
class Real>
754 if(p.coords[0]>center.coords[0]){cIndex|=1;}
755 if(p.coords[1]>center.coords[1]){cIndex|=2;}
756 if(p.coords[2]>center.coords[2]){cIndex|=4;}
759 template <
class NodeData,
class Real>
760 template<
class NodeData2>
763 if(children){
delete[] children;}
766 this->depth=node.depth;
767 for(
unsigned int i=0;i<DIMENSION;i++){this->offset[i] = node.offset[i];}
770 for(
unsigned int i=0;i<Cube::CORNERS;i++){children[i] = node.children[i];}
774 template <
class NodeData,
class Real>
778 template<
class NodeData ,
class Real >
783 if( n1->d!=n2->d )
return int(n1->d)-int(n2->d);
784 else if( n1->off[0]!=n2->off[0] )
return int(n1->off[0]) - int(n2->off[0]);
785 else if( n1->off[1]!=n2->off[1] )
return int(n1->off[1]) - int(n2->off[1]);
786 else if( n1->off[2]!=n2->off[2] )
return int(n1->off[2]) - int(n2->off[2]);
790 long long _InterleaveBits(
int p[3] )
793 for(
int i=0 ; i<32 ; i++ ) key |= ( ( p[0] & (1<<i) )<<(2*i) ) | ( ( p[1] & (1<<i) )<<(2*i+1) ) | ( ( p[2] & (1<<i) )<<(2*i+2) );
796 template <
class NodeData,
class Real>
801 int d1 , off1[3] , d2 , off2[3];
802 n1->depthAndOffset( d1 , off1 ) , n2->depthAndOffset( d2 , off2 );
803 if ( d1>d2 )
return 1;
804 else if( d1<d2 )
return -1;
805 long long k1 = _InterleaveBits( off1 ) , k2 = _InterleaveBits( off2 );
806 if ( k1>k2 )
return 1;
807 else if( k1<k2 )
return -1;
811 template <
class NodeData,
class Real>
816 if(n1->d!=n2->d){
return int(n1->d)-int(n2->d);}
817 while( n1->parent!=n2->parent )
822 if(n1->off[0]!=n2->off[0]){
return int(n1->off[0])-int(n2->off[0]);}
823 if(n1->off[1]!=n2->off[1]){
return int(n1->off[1])-int(n2->off[1]);}
824 return int(n1->off[2])-int(n2->off[2]);
827 template <
class NodeData,
class Real>
831 template <
class NodeData,
class Real>
835 template <
class NodeData,
class Real>
836 inline int OctNode<NodeData,Real>::Overlap2(
const int &depth1,
const int offSet1[DIMENSION],
const Real& multiplier1,
const int &depth2,
const int offSet2[DIMENSION],
const Real& multiplier2){
838 Real w=multiplier2+multiplier1*(1<<d);
839 Real w2=Real((1<<(d-1))-0.5);
841 fabs(Real(offSet2[0]-(offSet1[0]<<d))-w2)>=w ||
842 fabs(Real(offSet2[1]-(offSet1[1]<<d))-w2)>=w ||
843 fabs(Real(offSet2[2]-(offSet1[2]<<d))-w2)>=w
847 template <
class NodeData,
class Real>
849 if(c1>=dWidth || c1<=-dWidth || c2>=dWidth || c2<=-dWidth || c3>=dWidth || c3<=-dWidth){
return 0;}
852 template <
class NodeData,
class Real>
854 template <
class NodeData,
class Real>
856 template <
class NodeData,
class Real>
858 if(!parent){
return NULL;}
859 ptrdiff_t pIndex= ptrdiff_t(-(this->parent->children -
this));
861 if((pIndex & (1<<dir))==(off<<dir)){
return &parent->children[pIndex];}
863 OctNode* temp=parent->__faceNeighbor(dir,off,forceChildren);
864 if(!temp){
return NULL;}
866 if(forceChildren){temp->initChildren();}
869 return &temp->children[pIndex];
872 template <
class NodeData,
class Real>
874 if(!parent){
return NULL;}
875 ptrdiff_t pIndex= ptrdiff_t(-(this->parent->children -
this));
877 if((pIndex & (1<<dir))==(off<<dir)){
return &parent->children[pIndex];}
879 const OctNode* temp=parent->__faceNeighbor(dir,off);
880 if(!temp || !temp->children){
return temp;}
881 else{
return &temp->children[pIndex];}
885 template <
class NodeData,
class Real>
888 Cube::FactorEdgeIndex(edgeIndex,o,i[0],i[1]);
890 case 0: idx[0]=1; idx[1]=2;
break;
891 case 1: idx[0]=0; idx[1]=2;
break;
892 case 2: idx[0]=0; idx[1]=1;
break;
894 return __edgeNeighbor(o,i,idx,forceChildren);
896 template <
class NodeData,
class Real>
899 Cube::FactorEdgeIndex(edgeIndex,o,i[0],i[1]);
901 case 0: idx[0]=1; idx[1]=2;
break;
902 case 1: idx[0]=0; idx[1]=2;
break;
903 case 2: idx[0]=0; idx[1]=1;
break;
905 return __edgeNeighbor(o,i,idx);
907 template <
class NodeData,
class Real>
909 if(!parent){
return NULL;}
910 ptrdiff_t pIndex= ptrdiff_t(-(this->parent->children -
this));
911 int aIndex,x[DIMENSION];
913 Cube::FactorCornerIndex(pIndex,x[0],x[1],x[2]);
914 aIndex=(~((i[0] ^ x[idx[0]]) | ((i[1] ^ x[idx[1]])<<1))) & 3;
915 pIndex^=(7 ^ (1<<o));
917 const OctNode* temp=parent->__faceNeighbor(idx[0],i[0]);
918 if(!temp || !temp->children){
return NULL;}
919 else{
return &temp->children[pIndex];}
922 const OctNode* temp=parent->__faceNeighbor(idx[1],i[1]);
923 if(!temp || !temp->children){
return NULL;}
924 else{
return &temp->children[pIndex];}
927 return &parent->children[pIndex];
930 const OctNode* temp=parent->__edgeNeighbor(o,i,idx);
931 if(!temp || !temp->children){
return temp;}
932 else{
return &temp->children[pIndex];}
936 template <
class NodeData,
class Real>
938 if(!parent){
return NULL;}
939 ptrdiff_t pIndex= ptrdiff_t(-(this->parent->children -
this));
940 int aIndex,x[DIMENSION];
942 Cube::FactorCornerIndex(pIndex,x[0],x[1],x[2]);
943 aIndex=(~((i[0] ^ x[idx[0]]) | ((i[1] ^ x[idx[1]])<<1))) & 3;
944 pIndex^=(7 ^ (1<<o));
946 OctNode* temp=parent->__faceNeighbor(idx[0],i[0],0);
947 if(!temp || !temp->children){
return NULL;}
948 else{
return &temp->children[pIndex];}
951 OctNode* temp=parent->__faceNeighbor(idx[1],i[1],0);
952 if(!temp || !temp->children){
return NULL;}
953 else{
return &temp->children[pIndex];}
956 return &parent->children[pIndex];
959 OctNode* temp=parent->__edgeNeighbor(o,i,idx,forceChildren);
960 if(!temp){
return NULL;}
962 if(forceChildren){temp->initChildren();}
965 return &temp->children[pIndex];
970 template <
class NodeData,
class Real>
973 if(!parent){
return NULL;}
975 ptrdiff_t pIndex= ptrdiff_t(-(this->parent->children -
this));
976 aIndex=(cornerIndex ^ pIndex);
979 return &parent->children[pIndex];
982 const OctNode* temp=
static_cast<const OctNode*
>(parent)->cornerNeighbor(cornerIndex);
983 if(!temp || !temp->children){
return temp;}
984 else{
return &temp->children[pIndex];}
987 const OctNode* temp=
static_cast<const OctNode*
>(parent)->__faceNeighbor(0,cornerIndex & 1);
988 if(!temp || !temp->children){
return NULL;}
989 else{
return & temp->children[pIndex];}
992 const OctNode* temp=
static_cast<const OctNode*
>(parent)->__faceNeighbor(1,(cornerIndex & 2)>>1);
993 if(!temp || !temp->children){
return NULL;}
994 else{
return & temp->children[pIndex];}
997 const OctNode* temp=
static_cast<const OctNode*
>(parent)->__faceNeighbor(2,(cornerIndex & 4)>>2);
998 if(!temp || !temp->children){
return NULL;}
999 else{
return & temp->children[pIndex];}
1002 const OctNode* temp=
static_cast<const OctNode*
>(parent)->edgeNeighbor(8 | (cornerIndex & 1) | (cornerIndex & 2) );
1003 if(!temp || !temp->children){
return NULL;}
1004 else{
return & temp->children[pIndex];}
1007 const OctNode* temp=
static_cast<const OctNode*
>(parent)->edgeNeighbor(4 | (cornerIndex & 1) | ((cornerIndex & 4)>>1) );
1008 if(!temp || !temp->children){
return NULL;}
1009 else{
return & temp->children[pIndex];}
1012 const OctNode* temp=
static_cast<const OctNode*
>(parent)->edgeNeighbor(((cornerIndex & 2) | (cornerIndex & 4))>>1 );
1013 if(!temp || !temp->children){
return NULL;}
1014 else{
return & temp->children[pIndex];}
1018 template <
class NodeData,
class Real>
1021 if(!parent){
return NULL;}
1023 ptrdiff_t pIndex= ptrdiff_t(-(this->parent->children -
this));
1024 aIndex=(cornerIndex ^ pIndex);
1027 return &parent->children[pIndex];
1030 OctNode* temp=
static_cast<OctNode*
>(parent)->cornerNeighbor(cornerIndex,forceChildren);
1031 if(!temp){
return NULL;}
1032 if(!temp->children){
1033 if(forceChildren){temp->initChildren();}
1036 return &temp->children[pIndex];
1039 OctNode* temp=
static_cast<OctNode*
>(parent)->__faceNeighbor(0,cornerIndex & 1,0);
1040 if(!temp || !temp->children){
return NULL;}
1041 else{
return & temp->children[pIndex];}
1044 OctNode* temp=
static_cast<OctNode*
>(parent)->__faceNeighbor(1,(cornerIndex & 2)>>1,0);
1045 if(!temp || !temp->children){
return NULL;}
1046 else{
return & temp->children[pIndex];}
1049 OctNode* temp=
static_cast<OctNode*
>(parent)->__faceNeighbor(2,(cornerIndex & 4)>>2,0);
1050 if(!temp || !temp->children){
return NULL;}
1051 else{
return & temp->children[pIndex];}
1054 OctNode* temp=
static_cast<OctNode*
>(parent)->edgeNeighbor(8 | (cornerIndex & 1) | (cornerIndex & 2) );
1055 if(!temp || !temp->children){
return NULL;}
1056 else{
return & temp->children[pIndex];}
1059 OctNode* temp=
static_cast<OctNode*
>(parent)->edgeNeighbor(4 | (cornerIndex & 1) | ((cornerIndex & 4)>>1) );
1060 if(!temp || !temp->children){
return NULL;}
1061 else{
return & temp->children[pIndex];}
1064 OctNode* temp=
static_cast<OctNode*
>(parent)->edgeNeighbor(((cornerIndex & 2) | (cornerIndex & 4))>>1 );
1065 if(!temp || !temp->children){
return NULL;}
1066 else{
return & temp->children[pIndex];}
1073 template<
class NodeData,
class Real>
1075 template<
class NodeData,
class Real>
1077 for(
int i=0;i<3;i++){
for(
int j=0;j<3;j++){
for(
int k=0;k<3;k++){neighbors[i][j][k]=NULL;}}}
1079 template<
class NodeData,
class Real>
1081 template<
class NodeData,
class Real>
1084 if( neighbors )
delete[] neighbors;
1088 template<
class NodeData,
class Real>
1091 if( neighbors )
delete[] neighbors;
1094 neighbors =
new Neighbors3[d+1];
1096 template<
class NodeData ,
class Real >
1099 if( !neighbors[d].neighbors[1][1][1] || !neighbors[d].neighbors[1][1][1]->isInside( p ) )
1101 neighbors[d].clear();
1103 if( !d ) neighbors[d].neighbors[1][1][1] = root;
1106 Neighbors3& temp = setNeighbors( root , p , d-1 );
1108 int i , j , k , x1 , y1 , z1 , x2 , y2 , z2;
1111 temp.neighbors[1][1][1]->centerAndWidth( c , w );
1112 int idx = CornerIndex( c , p );
1113 Cube::FactorCornerIndex( idx , x1 , y1 , z1 );
1114 Cube::FactorCornerIndex( (~idx)&7 , x2 , y2 , z2 );
1116 if( !temp.neighbors[1][1][1]->children ) temp.neighbors[1][1][1]->initChildren();
1117 for( i=0 ; i<2 ; i++ )
for( j=0 ; j<2 ; j++ )
for( k=0 ; k<2 ; k++ )
1118 neighbors[d].neighbors[x2+i][y2+j][z2+k] = &temp.neighbors[1][1][1]->children[Cube::CornerIndex(i,j,k)];
1123 if( temp.neighbors[i][1][1] )
1125 if( !temp.neighbors[i][1][1]->children ) temp.neighbors[i][1][1]->initChildren();
1126 for( j=0 ; j<2 ; j++ )
for( k=0 ; k<2 ; k++ ) neighbors[d].neighbors[i][y2+j][z2+k] = &temp.neighbors[i][1][1]->children[Cube::CornerIndex(x2,j,k)];
1129 if( temp.neighbors[1][j][1] )
1131 if( !temp.neighbors[1][j][1]->children ) temp.neighbors[1][j][1]->initChildren();
1132 for( i=0 ; i<2 ; i++ )
for( k=0 ; k<2 ; k++ ) neighbors[d].neighbors[x2+i][j][z2+k] = &temp.neighbors[1][j][1]->children[Cube::CornerIndex(i,y2,k)];
1135 if( temp.neighbors[1][1][k] )
1137 if( !temp.neighbors[1][1][k]->children ) temp.neighbors[1][1][k]->initChildren();
1138 for( i=0 ; i<2 ; i++ )
for( j=0 ; j<2 ; j++ ) neighbors[d].neighbors[x2+i][y2+j][k] = &temp.neighbors[1][1][k]->children[Cube::CornerIndex(i,j,z2)];
1143 if( temp.neighbors[i][j][1] )
1145 if( !temp.neighbors[i][j][1]->children ) temp.neighbors[i][j][1]->initChildren();
1146 for( k=0 ; k<2 ; k++ ) neighbors[d].neighbors[i][j][z2+k] = &temp.neighbors[i][j][1]->children[Cube::CornerIndex(x2,y2,k)];
1149 if( temp.neighbors[i][1][k] )
1151 if( !temp.neighbors[i][1][k]->children ) temp.neighbors[i][1][k]->initChildren();
1152 for( j=0 ; j<2 ; j++ ) neighbors[d].neighbors[i][y2+j][k] = &temp.neighbors[i][1][k]->children[Cube::CornerIndex(x2,j,z2)];
1155 if( temp.neighbors[1][j][k] )
1157 if( !temp.neighbors[1][j][k]->children ) temp.neighbors[1][j][k]->initChildren();
1158 for( i=0 ; i<2 ; i++ ) neighbors[d].neighbors[x2+i][j][k] = &temp.neighbors[1][j][k]->children[Cube::CornerIndex(i,y2,z2)];
1162 i=x1<<1 , j=y1<<1 , k=z1<<1;
1163 if( temp.neighbors[i][j][k] )
1165 if( !temp.neighbors[i][j][k]->children ) temp.neighbors[i][j][k]->initChildren();
1166 neighbors[d].neighbors[i][j][k] = &temp.neighbors[i][j][k]->children[Cube::CornerIndex(x2,y2,z2)];
1170 return neighbors[d];
1172 template<
class NodeData ,
class Real >
1175 if( !neighbors[d].neighbors[1][1][1] || !neighbors[d].neighbors[1][1][1]->isInside( p ) )
1177 neighbors[d].clear();
1179 if( !d ) neighbors[d].neighbors[1][1][1] = root;
1182 Neighbors3& temp = getNeighbors( root , p , d-1 );
1184 int i , j , k , x1 , y1 , z1 , x2 , y2 , z2;
1187 temp.neighbors[1][1][1]->centerAndWidth( c , w );
1188 int idx = CornerIndex( c , p );
1189 Cube::FactorCornerIndex( idx , x1 , y1 , z1 );
1190 Cube::FactorCornerIndex( (~idx)&7 , x2 , y2 , z2 );
1192 if( !temp.neighbors[1][1][1] || !temp.neighbors[1][1][1]->children )
1194 fprintf( stderr ,
"[ERROR] Couldn't find node at appropriate depth\n" );
1197 for( i=0 ; i<2 ; i++ )
for( j=0 ; j<2 ; j++ )
for( k=0 ; k<2 ; k++ )
1198 neighbors[d].neighbors[x2+i][y2+j][z2+k] = &temp.neighbors[1][1][1]->children[Cube::CornerIndex(i,j,k)];
1203 if( temp.neighbors[i][1][1] )
1204 for( j=0 ; j<2 ; j++ )
for( k=0 ; k<2 ; k++ ) neighbors[d].neighbors[i][y2+j][z2+k] = &temp.neighbors[i][1][1]->children[Cube::CornerIndex(x2,j,k)];
1206 if( temp.neighbors[1][j][1] )
1207 for( i=0 ; i<2 ; i++ )
for( k=0 ; k<2 ; k++ ) neighbors[d].neighbors[x2+i][j][z2+k] = &temp.neighbors[1][j][1]->children[Cube::CornerIndex(i,y2,k)];
1209 if( temp.neighbors[1][1][k] )
1210 for( i=0 ; i<2 ; i++ )
for( j=0 ; j<2 ; j++ ) neighbors[d].neighbors[x2+i][y2+j][k] = &temp.neighbors[1][1][k]->children[Cube::CornerIndex(i,j,z2)];
1214 if( temp.neighbors[i][j][1] )
1215 for( k=0 ; k<2 ; k++ ) neighbors[d].neighbors[i][j][z2+k] = &temp.neighbors[i][j][1]->children[Cube::CornerIndex(x2,y2,k)];
1217 if( temp.neighbors[i][1][k] )
1218 for( j=0 ; j<2 ; j++ ) neighbors[d].neighbors[i][y2+j][k] = &temp.neighbors[i][1][k]->children[Cube::CornerIndex(x2,j,z2)];
1220 if( temp.neighbors[1][j][k] )
1221 for( i=0 ; i<2 ; i++ ) neighbors[d].neighbors[x2+i][j][k] = &temp.neighbors[1][j][k]->children[Cube::CornerIndex(i,y2,z2)];
1224 i=x1<<1 , j=y1<<1 , k=z1<<1;
1225 if( temp.neighbors[i][j][k] )
1226 neighbors[d].neighbors[i][j][k] = &temp.neighbors[i][j][k]->children[Cube::CornerIndex(x2,y2,z2)];
1229 return neighbors[d];
1232 template<
class NodeData ,
class Real >
1235 int d = node->depth();
1236 if( node==neighbors[d].neighbors[1][1][1] )
1239 for(
int i=0 ; i<3 ; i++ )
for(
int j=0 ; j<3 ; j++ )
for(
int k=0 ; k<3 ; k++ )
if( !neighbors[d].neighbors[i][j][k] ) reset =
true;
1240 if( reset ) neighbors[d].neighbors[1][1][1] = NULL;
1242 if( node!=neighbors[d].neighbors[1][1][1] )
1244 neighbors[d].clear();
1246 if( !node->parent ) neighbors[d].neighbors[1][1][1] = node;
1249 int i,j,k,x1,y1,z1,x2,y2,z2;
1250 int idx=int(node-node->parent->children);
1251 Cube::FactorCornerIndex( idx ,x1,y1,z1);
1252 Cube::FactorCornerIndex((~idx)&7,x2,y2,z2);
1256 neighbors[d].neighbors[x2+i][y2+j][z2+k]=&node->parent->children[Cube::CornerIndex(i,j,k)];
1260 Neighbors3& temp=setNeighbors(node->parent);
1264 if(temp.neighbors[i][1][1]){
1265 if(!temp.neighbors[i][1][1]->children) temp.neighbors[i][1][1]->initChildren();
1266 for(j=0;j<2;j++)
for(k=0;k<2;k++) neighbors[d].neighbors[i][y2+j][z2+k]=&temp.neighbors[i][1][1]->children[Cube::CornerIndex(x2,j,k)];
1269 if(temp.neighbors[1][j][1]){
1270 if(!temp.neighbors[1][j][1]->children){temp.neighbors[1][j][1]->initChildren();}
1271 for(i=0;i<2;i++){
for(k=0;k<2;k++){neighbors[d].neighbors[x2+i][j][z2+k]=&temp.neighbors[1][j][1]->children[Cube::CornerIndex(i,y2,k)];}}
1274 if(temp.neighbors[1][1][k]){
1275 if(!temp.neighbors[1][1][k]->children){temp.neighbors[1][1][k]->initChildren();}
1276 for(i=0;i<2;i++){
for(j=0;j<2;j++){neighbors[d].neighbors[x2+i][y2+j][k]=&temp.neighbors[1][1][k]->children[Cube::CornerIndex(i,j,z2)];}}
1281 if(temp.neighbors[i][j][1]){
1282 if(!temp.neighbors[i][j][1]->children){temp.neighbors[i][j][1]->initChildren();}
1283 for(k=0;k<2;k++){neighbors[d].neighbors[i][j][z2+k]=&temp.neighbors[i][j][1]->children[Cube::CornerIndex(x2,y2,k)];}
1286 if(temp.neighbors[i][1][k]){
1287 if(!temp.neighbors[i][1][k]->children){temp.neighbors[i][1][k]->initChildren();}
1288 for(j=0;j<2;j++){neighbors[d].neighbors[i][y2+j][k]=&temp.neighbors[i][1][k]->children[Cube::CornerIndex(x2,j,z2)];}
1291 if(temp.neighbors[1][j][k]){
1292 if(!temp.neighbors[1][j][k]->children){temp.neighbors[1][j][k]->initChildren();}
1293 for(i=0;i<2;i++){neighbors[d].neighbors[x2+i][j][k]=&temp.neighbors[1][j][k]->children[Cube::CornerIndex(i,y2,z2)];}
1297 i=x1<<1; j=y1<<1; k=z1<<1;
1298 if(temp.neighbors[i][j][k]){
1299 if(!temp.neighbors[i][j][k]->children){temp.neighbors[i][j][k]->initChildren();}
1300 neighbors[d].neighbors[i][j][k]=&temp.neighbors[i][j][k]->children[Cube::CornerIndex(x2,y2,z2)];
1304 return neighbors[d];
1308 template<
class NodeData ,
class Real >
1311 int d = node->depth();
1312 if( node==neighbors[d].neighbors[1][1][1] )
1315 for(
int i=0 ; i<3 ; i++ )
for(
int j=0 ; j<3 ; j++ )
for(
int k=0 ; k<3 ; k++ )
if( flags[i][j][k] && !neighbors[d].neighbors[i][j][k] ) reset =
true;
1316 if( reset ) neighbors[d].neighbors[1][1][1] = NULL;
1318 if( node!=neighbors[d].neighbors[1][1][1] )
1320 neighbors[d].clear();
1322 if( !node->parent ) neighbors[d].neighbors[1][1][1] = node;
1325 int x1,y1,z1,x2,y2,z2;
1326 int idx=int(node-node->parent->children);
1327 Cube::FactorCornerIndex( idx ,x1,y1,z1);
1328 Cube::FactorCornerIndex((~idx)&7,x2,y2,z2);
1329 for(
int i=0 ; i<2 ; i++ )
1330 for(
int j=0 ; j<2 ; j++ )
1331 for(
int k=0 ; k<2 ; k++ )
1332 neighbors[d].neighbors[x2+i][y2+j][z2+k]=&node->parent->children[Cube::CornerIndex(i,j,k)];
1334 Neighbors3& temp=setNeighbors( node->parent , flags );
1339 if( temp.neighbors[i][1][1] )
1341 if( flags[i][1][1] && !temp.neighbors[i][1][1]->children ) temp.neighbors[i][1][1]->initChildren();
1342 if( temp.neighbors[i][1][1]->children )
for(
int j=0 ; j<2 ; j++ )
for(
int k=0 ; k<2 ; k++ ) neighbors[d].neighbors[i][y2+j][z2+k] = &temp.neighbors[i][1][1]->children[Cube::CornerIndex(x2,j,k)];
1347 if( temp.neighbors[1][j][1] )
1349 if( flags[1][j][1] && !temp.neighbors[1][j][1]->children ) temp.neighbors[1][j][1]->initChildren();
1350 if( temp.neighbors[1][j][1]->children )
for(
int i=0 ; i<2 ; i++ )
for(
int k=0 ; k<2 ; k++ ) neighbors[d].neighbors[x2+i][j][z2+k] = &temp.neighbors[1][j][1]->children[Cube::CornerIndex(i,y2,k)];
1355 if( temp.neighbors[1][1][k] )
1357 if( flags[1][1][k] && !temp.neighbors[1][1][k]->children ) temp.neighbors[1][1][k]->initChildren();
1358 if( temp.neighbors[1][1][k]->children )
for(
int i=0 ; i<2 ; i++ )
for(
int j=0 ; j<2 ; j++ ) neighbors[d].neighbors[x2+i][y2+j][k] = &temp.neighbors[1][1][k]->children[Cube::CornerIndex(i,j,z2)];
1364 int i=x1<<1 , j=y1<<1;
1365 if( temp.neighbors[i][j][1] )
1367 if( flags[i][j][1] && !temp.neighbors[i][j][1]->children ) temp.neighbors[i][j][1]->initChildren();
1368 if( temp.neighbors[i][j][1]->children )
for(
int k=0 ; k<2 ; k++ ) neighbors[d].neighbors[i][j][z2+k] = &temp.neighbors[i][j][1]->children[Cube::CornerIndex(x2,y2,k)];
1372 int i=x1<<1 , k=z1<<1;
1373 if( temp.neighbors[i][1][k] )
1375 if( flags[i][1][k] && !temp.neighbors[i][1][k]->children ) temp.neighbors[i][1][k]->initChildren();
1376 if( temp.neighbors[i][1][k]->children )
for(
int j=0 ; j<2 ; j++ ) neighbors[d].neighbors[i][y2+j][k] = &temp.neighbors[i][1][k]->children[Cube::CornerIndex(x2,j,z2)];
1380 int j=y1<<1 , k=z1<<1;
1381 if( temp.neighbors[1][j][k] )
1383 if( flags[1][j][k] && !temp.neighbors[1][j][k]->children ) temp.neighbors[1][j][k]->initChildren();
1384 if( temp.neighbors[1][j][k]->children )
for(
int i=0 ; i<2 ; i++ ) neighbors[d].neighbors[x2+i][j][k] = &temp.neighbors[1][j][k]->children[Cube::CornerIndex(i,y2,z2)];
1390 int i=x1<<1 , j=y1<<1 , k=z1<<1;
1391 if( temp.neighbors[i][j][k] )
1393 if( flags[i][j][k] && !temp.neighbors[i][j][k]->children ) temp.neighbors[i][j][k]->initChildren();
1394 if( temp.neighbors[i][j][k]->children ) neighbors[d].neighbors[i][j][k] = &temp.neighbors[i][j][k]->children[Cube::CornerIndex(x2,y2,z2)];
1399 return neighbors[d];
1402 template<
class NodeData,
class Real>
1404 int d=node->depth();
1405 if(node!=neighbors[d].neighbors[1][1][1]){
1406 neighbors[d].clear();
1408 if(!node->parent){neighbors[d].neighbors[1][1][1]=node;}
1410 int i,j,k,x1,y1,z1,x2,y2,z2;
1411 int idx=int(node-node->parent->children);
1412 Cube::FactorCornerIndex( idx ,x1,y1,z1);
1413 Cube::FactorCornerIndex((~idx)&7,x2,y2,z2);
1417 neighbors[d].neighbors[x2+i][y2+j][z2+k]=&node->parent->children[Cube::CornerIndex(i,j,k)];
1421 Neighbors3& temp=getNeighbors(node->parent);
1425 if(temp.neighbors[i][1][1] && temp.neighbors[i][1][1]->children){
1426 for(j=0;j<2;j++){
for(k=0;k<2;k++){neighbors[d].neighbors[i][y2+j][z2+k]=&temp.neighbors[i][1][1]->children[Cube::CornerIndex(x2,j,k)];}}
1429 if(temp.neighbors[1][j][1] && temp.neighbors[1][j][1]->children){
1430 for(i=0;i<2;i++){
for(k=0;k<2;k++){neighbors[d].neighbors[x2+i][j][z2+k]=&temp.neighbors[1][j][1]->children[Cube::CornerIndex(i,y2,k)];}}
1433 if(temp.neighbors[1][1][k] && temp.neighbors[1][1][k]->children){
1434 for(i=0;i<2;i++){
for(j=0;j<2;j++){neighbors[d].neighbors[x2+i][y2+j][k]=&temp.neighbors[1][1][k]->children[Cube::CornerIndex(i,j,z2)];}}
1439 if(temp.neighbors[i][j][1] && temp.neighbors[i][j][1]->children){
1440 for(k=0;k<2;k++){neighbors[d].neighbors[i][j][z2+k]=&temp.neighbors[i][j][1]->children[Cube::CornerIndex(x2,y2,k)];}
1443 if(temp.neighbors[i][1][k] && temp.neighbors[i][1][k]->children){
1444 for(j=0;j<2;j++){neighbors[d].neighbors[i][y2+j][k]=&temp.neighbors[i][1][k]->children[Cube::CornerIndex(x2,j,z2)];}
1447 if(temp.neighbors[1][j][k] && temp.neighbors[1][j][k]->children){
1448 for(i=0;i<2;i++){neighbors[d].neighbors[x2+i][j][k]=&temp.neighbors[1][j][k]->children[Cube::CornerIndex(i,y2,z2)];}
1452 i=x1<<1; j=y1<<1; k=z1<<1;
1453 if(temp.neighbors[i][j][k] && temp.neighbors[i][j][k]->children){
1454 neighbors[d].neighbors[i][j][k]=&temp.neighbors[i][j][k]->children[Cube::CornerIndex(x2,y2,z2)];
1458 return neighbors[node->depth()];
1464 template<
class NodeData,
class Real>
1466 template<
class NodeData,
class Real>
1468 for(
int i=0;i<3;i++){
for(
int j=0;j<3;j++){
for(
int k=0;k<3;k++){neighbors[i][j][k]=NULL;}}}
1470 template<
class NodeData,
class Real>
1472 template<
class NodeData,
class Real>
1474 if(neighbors){
delete[] neighbors;}
1478 template<
class NodeData,
class Real>
1480 if(neighbors){
delete[] neighbors;}
1483 neighbors=
new ConstNeighbors3[d+1];
1485 template<
class NodeData,
class Real>
1487 int d=node->depth();
1488 if(node!=neighbors[d].neighbors[1][1][1]){
1489 neighbors[d].clear();
1491 if(!node->parent){neighbors[d].neighbors[1][1][1]=node;}
1493 int i,j,k,x1,y1,z1,x2,y2,z2;
1494 int idx=int(node-node->parent->children);
1495 Cube::FactorCornerIndex( idx ,x1,y1,z1);
1496 Cube::FactorCornerIndex((~idx)&7,x2,y2,z2);
1500 neighbors[d].neighbors[x2+i][y2+j][z2+k]=&node->parent->children[Cube::CornerIndex(i,j,k)];
1504 ConstNeighbors3& temp=getNeighbors(node->parent);
1508 if(temp.neighbors[i][1][1] && temp.neighbors[i][1][1]->children){
1509 for(j=0;j<2;j++){
for(k=0;k<2;k++){neighbors[d].neighbors[i][y2+j][z2+k]=&temp.neighbors[i][1][1]->children[Cube::CornerIndex(x2,j,k)];}}
1512 if(temp.neighbors[1][j][1] && temp.neighbors[1][j][1]->children){
1513 for(i=0;i<2;i++){
for(k=0;k<2;k++){neighbors[d].neighbors[x2+i][j][z2+k]=&temp.neighbors[1][j][1]->children[Cube::CornerIndex(i,y2,k)];}}
1516 if(temp.neighbors[1][1][k] && temp.neighbors[1][1][k]->children){
1517 for(i=0;i<2;i++){
for(j=0;j<2;j++){neighbors[d].neighbors[x2+i][y2+j][k]=&temp.neighbors[1][1][k]->children[Cube::CornerIndex(i,j,z2)];}}
1522 if(temp.neighbors[i][j][1] && temp.neighbors[i][j][1]->children){
1523 for(k=0;k<2;k++){neighbors[d].neighbors[i][j][z2+k]=&temp.neighbors[i][j][1]->children[Cube::CornerIndex(x2,y2,k)];}
1526 if(temp.neighbors[i][1][k] && temp.neighbors[i][1][k]->children){
1527 for(j=0;j<2;j++){neighbors[d].neighbors[i][y2+j][k]=&temp.neighbors[i][1][k]->children[Cube::CornerIndex(x2,j,z2)];}
1530 if(temp.neighbors[1][j][k] && temp.neighbors[1][j][k]->children){
1531 for(i=0;i<2;i++){neighbors[d].neighbors[x2+i][j][k]=&temp.neighbors[1][j][k]->children[Cube::CornerIndex(i,y2,z2)];}
1535 i=x1<<1; j=y1<<1; k=z1<<1;
1536 if(temp.neighbors[i][j][k] && temp.neighbors[i][j][k]->children){
1537 neighbors[d].neighbors[i][j][k]=&temp.neighbors[i][j][k]->children[Cube::CornerIndex(x2,y2,z2)];
1541 return neighbors[node->depth()];
1543 template<
class NodeData,
class Real>
1546 int d=node->depth();
1547 if( d<minDepth ) fprintf( stderr ,
"[ERROR] Node depth lower than min-depth: %d < %d\n" , d , minDepth ) , exit( 0 );
1548 if( node!=neighbors[d].neighbors[1][1][1] )
1550 neighbors[d].clear();
1552 if( d==minDepth ) neighbors[d].neighbors[1][1][1]=node;
1555 int i,j,k,x1,y1,z1,x2,y2,z2;
1556 int idx = int(node-node->parent->children);
1557 Cube::FactorCornerIndex( idx ,x1,y1,z1);
1558 Cube::FactorCornerIndex((~idx)&7,x2,y2,z2);
1560 ConstNeighbors3& temp=getNeighbors( node->parent , minDepth );
1563 for( i=0 ; i<2 ; i++ )
for( j=0 ; j<2 ; j++ )
for( k=0 ; k<2 ; k++ )
1564 neighbors[d].neighbors[x2+i][y2+j][z2+k] = &node->parent->children[ Cube::CornerIndex(i,j,k) ];
1568 if( temp.neighbors[i][1][1] && temp.neighbors[i][1][1]->children )
1569 for( j=0 ; j<2 ; j++ )
for( k=0 ; k<2 ; k++ ) neighbors[d].neighbors[i][y2+j][z2+k] = &temp.neighbors[i][1][1]->children[Cube::CornerIndex(x2,j,k)];
1572 if( temp.neighbors[1][j][1] && temp.neighbors[1][j][1]->children )
1573 for( i=0 ; i<2 ; i++ )
for( k=0 ; k<2 ; k++ ) neighbors[d].neighbors[x2+i][j][z2+k] = &temp.neighbors[1][j][1]->children[Cube::CornerIndex(i,y2,k)];
1576 if( temp.neighbors[1][1][k] && temp.neighbors[1][1][k]->children )
1577 for( i=0 ; i<2 ; i++ )
for( j=0 ; j<2 ; j++ ) neighbors[d].neighbors[x2+i][y2+j][k] = &temp.neighbors[1][1][k]->children[Cube::CornerIndex(i,j,z2)];
1581 if( temp.neighbors[i][j][1] && temp.neighbors[i][j][1]->children )
1582 for( k=0 ; k<2 ; k++ ) neighbors[d].neighbors[i][j][z2+k] = &temp.neighbors[i][j][1]->children[Cube::CornerIndex(x2,y2,k)];
1585 if( temp.neighbors[i][1][k] && temp.neighbors[i][1][k]->children )
1586 for( j=0 ; j<2 ; j++ ) neighbors[d].neighbors[i][y2+j][k] = &temp.neighbors[i][1][k]->children[Cube::CornerIndex(x2,j,z2)];
1589 if( temp.neighbors[1][j][k] && temp.neighbors[1][j][k]->children )
1590 for( i=0 ; i<2 ; i++ ) neighbors[d].neighbors[x2+i][j][k] = &temp.neighbors[1][j][k]->children[Cube::CornerIndex(i,y2,z2)];
1593 i=x1<<1 , j=y1<<1 , k=z1<<1;
1594 if( temp.neighbors[i][j][k] && temp.neighbors[i][j][k]->children )
1595 neighbors[d].neighbors[i][j][k] = &temp.neighbors[i][j][k]->children[Cube::CornerIndex(x2,y2,z2)];
1598 return neighbors[node->depth()];
1603 template<
class NodeData ,
class Real >
1606 for(
int i=0 ; i<5 ; i++ )
for(
int j=0 ; j<5 ; j++ )
for(
int k=0 ; k<5 ; k++ ) neighbors[i][j][k] = NULL;
1608 template<
class NodeData ,
class Real >
1611 for(
int i=0 ; i<5 ; i++ )
for(
int j=0 ; j<5 ; j++ )
for(
int k=0 ; k<5 ; k++ ) neighbors[i][j][k] = NULL;
1613 template<
class NodeData ,
class Real >
1619 template<
class NodeData ,
class Real >
1625 template<
class NodeData ,
class Real >
1628 if( neighbors )
delete[] neighbors;
1631 template<
class NodeData ,
class Real >
1634 if( neighbors )
delete[] neighbors;
1637 template<
class NodeData ,
class Real >
1640 if( neighbors )
delete[] neighbors;
1644 neighbors=
new Neighbors5[d+1];
1646 template<
class NodeData ,
class Real >
1649 if( neighbors )
delete[] neighbors;
1653 neighbors=
new ConstNeighbors5[d+1];
1655 template<
class NodeData ,
class Real >
1658 int d=node->depth();
1659 if( node!=neighbors[d].neighbors[2][2][2] )
1661 neighbors[d].clear();
1663 if( !node->parent ) neighbors[d].neighbors[2][2][2]=node;
1666 getNeighbors( node->parent );
1667 Neighbors5& temp = neighbors[d-1];
1668 int x1 , y1 , z1 , x2 , y2 , z2;
1669 int idx = int( node - node->parent->children );
1670 Cube::FactorCornerIndex( idx , x1 , y1 , z1 );
1672 Neighbors5& n = neighbors[d];
1673 Cube::FactorCornerIndex( (~idx)&7 , x2 , y2 , z2 );
1675 int fx0 = x2+1 , fy0 = y2+1 , fz0 = z2+1;
1676 int cx1 = x1*2+1 , cy1 = y1*2+1 , cz1 = z1*2+1;
1677 int cx2 = x2*2+1 , cy2 = y2*2+1 , cz2 = z2*2+1;
1678 int fx1 = x1*3 , fy1 = y1*3 , fz1 = z1*3;
1679 int fx2 = x2*4 , fy2 = y2*4 , fz2 = z2*4;
1682 for( i=0 ; i<2 ; i++ )
for( j=0 ; j<2 ; j++ )
for( k=0 ; k<2 ; k++ )
1683 n.neighbors[fx0+i][fy0+j][fz0+k] = node->parent->children + Cube::CornerIndex( i , j , k );
1686 if( temp.neighbors[cx1][2][2] && temp.neighbors[cx1][2][2]->children )
1687 for( i=0 ; i<2 ; i++ )
for( j=0 ; j<2 ; j++ )
for( k=0 ; k<2 ; k++ )
1688 n.neighbors[fx1+i][fy0+j][fz0+k] = temp.neighbors[cx1][2][2]->children + Cube::CornerIndex( i , j , k );
1689 if( temp.neighbors[2][cy1][2] && temp.neighbors[2][cy1][2]->children )
1690 for( i=0 ; i<2 ; i++ )
for( j=0 ; j<2 ; j++ )
for( k=0 ; k<2 ; k++ )
1691 n.neighbors[fx0+i][fy1+j][fz0+k] = temp.neighbors[2][cy1][2]->children + Cube::CornerIndex( i , j , k );
1692 if( temp.neighbors[2][2][cz1] && temp.neighbors[2][2][cz1]->children )
1693 for( i=0 ; i<2 ; i++ )
for( j=0 ; j<2 ; j++ )
for( k=0 ; k<2 ; k++ )
1694 n.neighbors[fx0+i][fy0+j][fz1+k] = temp.neighbors[2][2][cz1]->children + Cube::CornerIndex( i , j , k );
1695 if( temp.neighbors[cx2][2][2] && temp.neighbors[cx2][2][2]->children )
1696 for( j=0 ; j<2 ; j++ )
for( k=0 ; k<2 ; k++ )
1697 n.neighbors[fx2 ][fy0+j][fz0+k] = temp.neighbors[cx2][2][2]->children + Cube::CornerIndex( x1 , j , k );
1698 if( temp.neighbors[2][cy2][2] && temp.neighbors[2][cy2][2]->children )
1699 for( i=0 ; i<2 ; i++ )
for( k=0 ; k<2 ; k++ )
1700 n.neighbors[fx0+i][fy2 ][fz0+k] = temp.neighbors[2][cy2][2]->children + Cube::CornerIndex( i , y1 , k );
1701 if( temp.neighbors[2][2][cz2] && temp.neighbors[2][2][cz2]->children )
1702 for( i=0 ; i<2 ; i++ )
for( j=0 ; j<2 ; j++ )
1703 n.neighbors[fx0+i][fy0+j][fz2 ] = temp.neighbors[2][2][cz2]->children + Cube::CornerIndex( i , j , z1 );
1706 if( temp.neighbors[cx1][cy1][2] && temp.neighbors[cx1][cy1][2]->children )
1707 for( i=0 ; i<2 ; i++ )
for( j=0 ; j<2 ; j++ )
for( k=0 ; k<2 ; k++ )
1708 n.neighbors[fx1+i][fy1+j][fz0+k] = temp.neighbors[cx1][cy1][2]->children + Cube::CornerIndex( i , j , k );
1709 if( temp.neighbors[cx1][2][cz1] && temp.neighbors[cx1][2][cz1]->children )
1710 for( i=0 ; i<2 ; i++ )
for( j=0 ; j<2 ; j++ )
for( k=0 ; k<2 ; k++ )
1711 n.neighbors[fx1+i][fy0+j][fz1+k] = temp.neighbors[cx1][2][cz1]->children + Cube::CornerIndex( i , j , k );
1712 if( temp.neighbors[2][cy1][cz1] && temp.neighbors[2][cy1][cz1]->children )
1713 for( i=0 ; i<2 ; i++ )
for( j=0 ; j<2 ; j++ )
for( k=0 ; k<2 ; k++ )
1714 n.neighbors[fx0+i][fy1+j][fz1+k] = temp.neighbors[2][cy1][cz1]->children + Cube::CornerIndex( i , j , k );
1715 if( temp.neighbors[cx1][cy2][2] && temp.neighbors[cx1][cy2][2]->children )
1716 for( i=0 ; i<2 ; i++ )
for( k=0 ; k<2 ; k++ )
1717 n.neighbors[fx1+i][fy2 ][fz0+k] = temp.neighbors[cx1][cy2][2]->children + Cube::CornerIndex( i , y1 , k );
1718 if( temp.neighbors[cx1][2][cz2] && temp.neighbors[cx1][2][cz2]->children )
1719 for( i=0 ; i<2 ; i++ )
for( j=0 ; j<2 ; j++ )
1720 n.neighbors[fx1+i][fy0+j][fz2 ] = temp.neighbors[cx1][2][cz2]->children + Cube::CornerIndex( i , j , z1 );
1721 if( temp.neighbors[cx2][cy1][2] && temp.neighbors[cx2][cy1][2]->children )
1722 for( j=0 ; j<2 ; j++ )
for( k=0 ; k<2 ; k++ )
1723 n.neighbors[fx2 ][fy1+j][fz0+k] = temp.neighbors[cx2][cy1][2]->children + Cube::CornerIndex( x1 , j , k );
1724 if( temp.neighbors[2][cy1][cz2] && temp.neighbors[2][cy1][cz2]->children )
1725 for( i=0 ; i<2 ; i++ )
for( j=0 ; j<2 ; j++ )
1726 n.neighbors[fx0+i][fy1+j][fz2 ] = temp.neighbors[2][cy1][cz2]->children + Cube::CornerIndex( i , j , z1 );
1727 if( temp.neighbors[cx2][2][cz1] && temp.neighbors[cx2][2][cz1]->children )
1728 for( j=0 ; j<2 ; j++ )
for( k=0 ; k<2 ; k++ )
1729 n.neighbors[fx2 ][fy0+j][fz1+k] = temp.neighbors[cx2][2][cz1]->children + Cube::CornerIndex( x1 , j , k );
1730 if( temp.neighbors[2][cy2][cz1] && temp.neighbors[2][cy2][cz1]->children )
1731 for( i=0 ; i<2 ; i++ )
for( k=0 ; k<2 ; k++ )
1732 n.neighbors[fx0+i][fy2 ][fz1+k] = temp.neighbors[2][cy2][cz1]->children + Cube::CornerIndex( i , y1 , k );
1733 if( temp.neighbors[cx2][cy2][2] && temp.neighbors[cx2][cy2][2]->children )
1734 for( k=0 ; k<2 ; k++ )
1735 n.neighbors[fx2 ][fy2 ][fz0+k] = temp.neighbors[cx2][cy2][2]->children + Cube::CornerIndex( x1 , y1 , k );
1736 if( temp.neighbors[cx2][2][cz2] && temp.neighbors[cx2][2][cz2]->children )
1737 for( j=0 ; j<2 ; j++ )
1738 n.neighbors[fx2 ][fy0+j][fz2 ] = temp.neighbors[cx2][2][cz2]->children + Cube::CornerIndex( x1 , j , z1 );
1739 if( temp.neighbors[2][cy2][cz2] && temp.neighbors[2][cy2][cz2]->children )
1740 for( i=0 ; i<2 ; i++ )
1741 n.neighbors[fx0+i][fy2 ][fz2 ] = temp.neighbors[2][cy2][cz2]->children + Cube::CornerIndex( i , y1 , z1 );
1744 if( temp.neighbors[cx1][cy1][cz1] && temp.neighbors[cx1][cy1][cz1]->children )
1745 for( i=0 ; i<2 ; i++ )
for( j=0 ; j<2 ; j++ )
for( k=0 ; k<2 ; k++ )
1746 n.neighbors[fx1+i][fy1+j][fz1+k] = temp.neighbors[cx1][cy1][cz1]->children + Cube::CornerIndex( i , j , k );
1747 if( temp.neighbors[cx1][cy1][cz2] && temp.neighbors[cx1][cy1][cz2]->children )
1748 for( i=0 ; i<2 ; i++ )
for( j=0 ; j<2 ; j++ )
1749 n.neighbors[fx1+i][fy1+j][fz2 ] = temp.neighbors[cx1][cy1][cz2]->children + Cube::CornerIndex( i , j , z1 );
1750 if( temp.neighbors[cx1][cy2][cz1] && temp.neighbors[cx1][cy2][cz1]->children )
1751 for( i=0 ; i<2 ; i++ )
for( k=0 ; k<2 ; k++ )
1752 n.neighbors[fx1+i][fy2 ][fz1+k] = temp.neighbors[cx1][cy2][cz1]->children + Cube::CornerIndex( i , y1 , k );
1753 if( temp.neighbors[cx2][cy1][cz1] && temp.neighbors[cx2][cy1][cz1]->children )
1754 for( j=0 ; j<2 ; j++ )
for( k=0 ; k<2 ; k++ )
1755 n.neighbors[fx2 ][fy1+j][fz1+k] = temp.neighbors[cx2][cy1][cz1]->children + Cube::CornerIndex( x1 , j , k );
1756 if( temp.neighbors[cx1][cy2][cz2] && temp.neighbors[cx1][cy2][cz2]->children )
1757 for( i=0 ; i<2 ; i++ )
1758 n.neighbors[fx1+i][fy2 ][fz2 ] = temp.neighbors[cx1][cy2][cz2]->children + Cube::CornerIndex( i , y1 , z1 );
1759 if( temp.neighbors[cx2][cy1][cz2] && temp.neighbors[cx2][cy1][cz2]->children )
1760 for( j=0 ; j<2 ; j++ )
1761 n.neighbors[fx2 ][fy1+j][fz2 ] = temp.neighbors[cx2][cy1][cz2]->children + Cube::CornerIndex( x1 , j , z1 );
1762 if( temp.neighbors[cx2][cy2][cz1] && temp.neighbors[cx2][cy2][cz1]->children )
1763 for( k=0 ; k<2 ; k++ )
1764 n.neighbors[fx2 ][fy2 ][fz1+k] = temp.neighbors[cx2][cy2][cz1]->children + Cube::CornerIndex( x1 , y1 , k );
1765 if( temp.neighbors[cx2][cy2][cz2] && temp.neighbors[cx2][cy2][cz2]->children )
1766 n.neighbors[fx2 ][fy2 ][fz2 ] = temp.neighbors[cx2][cy2][cz2]->children + Cube::CornerIndex( x1 , y1 , z1 );
1769 return neighbors[d];
1771 template<
class NodeData ,
class Real >
1774 int d=node->depth();
1775 if( node!=neighbors[d].neighbors[2][2][2] )
1777 neighbors[d].clear();
1779 if( !node->parent ) neighbors[d].neighbors[2][2][2]=node;
1782 setNeighbors( node->parent , xStart , xEnd , yStart , yEnd , zStart , zEnd );
1783 Neighbors5& temp = neighbors[d-1];
1784 int x1 , y1 , z1 , x2 , y2 , z2 , ii , jj , kk;
1785 int idx = int( node-node->parent->children );
1786 Cube::FactorCornerIndex( idx , x1 , y1 , z1 );
1788 for(
int i=xStart ; i<xEnd ; i++ )
1793 for(
int j=yStart ; j<yEnd ; j++ )
1798 for(
int k=zStart ; k<zEnd ; k++ )
1803 if(temp.neighbors[x2][y2][z2] )
1805 if( !temp.neighbors[x2][y2][z2]->children ) temp.neighbors[x2][y2][z2]->initChildren();
1806 neighbors[d].neighbors[i][j][k] = temp.neighbors[x2][y2][z2]->children + Cube::CornerIndex(ii,jj,kk);
1813 return neighbors[d];
1815 template<
class NodeData ,
class Real >
1818 int d=node->depth();
1819 if( node!=neighbors[d].neighbors[2][2][2] )
1821 neighbors[d].clear();
1823 if(!node->parent) neighbors[d].neighbors[2][2][2]=node;
1826 getNeighbors( node->parent );
1827 ConstNeighbors5& temp = neighbors[d-1];
1828 int x1,y1,z1,x2,y2,z2,ii,jj,kk;
1829 int idx=int(node-node->parent->children);
1830 Cube::FactorCornerIndex(idx,x1,y1,z1);
1832 for(
int i=0;i<5;i++)
1837 for(
int j=0;j<5;j++)
1842 for(
int k=0;k<5;k++)
1847 if(temp.neighbors[x2][y2][z2] && temp.neighbors[x2][y2][z2]->children)
1848 neighbors[d].neighbors[i][j][k] = temp.neighbors[x2][y2][z2]->children + Cube::CornerIndex(ii,jj,kk);
1854 return neighbors[d];
1858 template <
class NodeData,
class Real>
1860 FILE* fp=fopen(fileName,
"wb");
1866 template <
class NodeData,
class Real>
1869 if(children){
for(
unsigned int i=0;i<Cube::CORNERS;i++){children[i].write(fp);}}
1872 template <
class NodeData,
class Real>
1874 FILE* fp=fopen(fileName,
"rb");
1880 template <
class NodeData,
class Real>
1887 for(
unsigned int i=0;i<Cube::CORNERS;i++){
1888 children[i].read(fp);
1889 children[i].parent=
this;
1894 template<
class NodeData,
class Real>
1897 return 1<<(maxDepth-d);
1899 template<
class NodeData,
class Real>
1902 depthAndOffset(d,o);