25 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
52 void split(
CellHandle _ch,
const bool bGarbageCollectionOnTheFly=
false );
120 inline int size()
const;
133 Scalar & _x, Scalar & _y, Scalar & _z, Scalar & _size )
const;
135 Scalar & _x, Scalar & _y, Scalar & _z )
const;
137 Scalar & _x, Scalar & _y, Scalar & _z, Scalar & _size )
const;
149 Scalar & _x, Scalar & _y, Scalar & _z )
const;
151 Scalar & _x, Scalar & _y, Scalar & _z, Scalar & _size )
const;
155 LocCode binary_cell_size = 1 << locinfo.
level();
156 return binary_cell_size;
180 inline void reserve(
unsigned int _size );
181 inline void resize (
unsigned int _size );
187 if ( _max_octree_level > MAX_ROOT_LEVEL )
189 fprintf( stderr,
"Error: octree::initialize(): invalid root level\n" );
190 exit( EXIT_FAILURE );
205 for (
size_t i=0; i<7; ++i)
m_OctreeCell.push_back( dummy );
223 inline int cell(
int _i )
const 265 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
273 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
281 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
289 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
297 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
305 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
313 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
321 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
324 return _ch.
idx() == 7;
329 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
336 _size = (
Scalar ) binary_cell_size;
344 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
359 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
365 _s = (
Scalar ) binary_cell_size;
374 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
381 _size = (
Scalar ) binary_cell_size;
389 case 1 : _x += _size;
break;
390 case 2 : _y += _size;
break;
391 case 3 : _x += _size; _y += _size;
break;
392 case 4 : _z += _size;
break;
393 case 5 : _x += _size; _z += _size;
break;
394 case 6 : _y += _size; _z += _size;
break;
395 case 7 : _x += _size; _y += _size; _z += _size;
break;
401 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
416 case 1 : _x +=
size;
break;
417 case 2 : _y +=
size;
break;
418 case 3 : _x +=
size; _y +=
size;
break;
419 case 4 : _z +=
size;
break;
420 case 5 : _x +=
size; _z +=
size;
break;
421 case 6 : _y +=
size; _z +=
size;
break;
428 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
439 LocCode child_branch_bit = 1 << next_level;
440 unsigned int child_index =
441 ( ( _loc_x & child_branch_bit ) >> ( next_level ) ) +
442 2 * ( ( _loc_y & child_branch_bit ) >> ( next_level ) ) +
443 4 * ( ( _loc_z & child_branch_bit ) >> ( next_level ) );
445 _ch =
child( _ch, child_index );
453 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
463 LocCode n = next_level - _level + 1;
467 LocCode child_branch_bit = 1 << next_level;
468 unsigned int child_index =
469 1 * ( ( _loc_x & child_branch_bit ) >> ( next_level ) ) +
470 2 * ( ( _loc_y & child_branch_bit ) >> ( next_level ) ) +
471 4 * ( ( _loc_z & child_branch_bit ) >> ( next_level ) );
473 _ch =
child( _ch, child_index );
483 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
491 const LocCode binary_cell_size = ((int)1) << locinfo.
level();
502 new_loc_x = loc_x + binary_cell_size;
503 diff = loc_x ^ new_loc_x;
508 new_loc_y = loc_y + binary_cell_size;
509 diff = loc_y ^ new_loc_y;
514 new_loc_z = loc_z + binary_cell_size;
515 diff = loc_z ^ new_loc_z;
520 new_loc_z = loc_z - 1;
521 diff = loc_z ^ new_loc_z;
526 new_loc_y = loc_y - 1;
527 diff = loc_y ^ new_loc_y;
532 new_loc_x = loc_x - 1;
533 diff = loc_x ^ new_loc_x;
544 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
549 while ( _binary_diff & ( 1 << cell_level ) )
560 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
568 while ( _binary_diff0 & _binary_diff1 & ( 1 << cell_level ) )
574 if ( _binary_diff0 & ( 1 << cell_level ) )
575 while ( _binary_diff0 & ( 1 << cell_level ) )
581 while ( _binary_diff1 & ( 1 << cell_level ) )
592 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
604 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
627 new_loc_y = loc_y - 1;
628 new_loc_z = loc_z - 1;
635 new_loc_x = loc_x - 1;
636 new_loc_z = loc_z - 1;
643 new_loc_x = loc_x - 1;
644 new_loc_y = loc_y - 1;
649 if ( loc_x + binary_cell_size >= extent )
return CellHandle();
651 new_loc_x = loc_x + binary_cell_size;
652 new_loc_z = loc_z - 1;
658 if ( loc_y + binary_cell_size >= extent )
return CellHandle();
659 new_loc_x = loc_x - 1;
660 new_loc_y = loc_y + binary_cell_size;
666 if ( loc_z + binary_cell_size >= extent )
return CellHandle();
667 new_loc_y = loc_y - 1;
668 new_loc_z = loc_z + binary_cell_size;
673 if ( loc_y + binary_cell_size >= extent )
return CellHandle();
675 new_loc_y = loc_y + binary_cell_size;
676 new_loc_z = loc_z - 1;
681 if ( loc_x + binary_cell_size >= extent )
return CellHandle();
683 new_loc_x = loc_x + binary_cell_size;
684 new_loc_y = loc_y - 1;
690 if ( loc_z + binary_cell_size >= extent )
return CellHandle();
691 new_loc_x = loc_x - 1;
692 new_loc_z = loc_z + binary_cell_size;
697 if ( loc_x + binary_cell_size >= extent )
return CellHandle();
698 if ( loc_y + binary_cell_size >= extent )
return CellHandle();
699 new_loc_x = loc_x + binary_cell_size;
700 new_loc_y = loc_y + binary_cell_size;
705 if ( loc_x + binary_cell_size >= extent )
return CellHandle();
706 if ( loc_z + binary_cell_size >= extent )
return CellHandle();
707 new_loc_x = loc_x + binary_cell_size;
708 new_loc_z = loc_z + binary_cell_size;
713 if ( loc_y + binary_cell_size >= extent )
return CellHandle();
714 if ( loc_z + binary_cell_size >= extent )
return CellHandle();
715 new_loc_y = loc_y + binary_cell_size;
716 new_loc_z = loc_z + binary_cell_size;
729 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
732 std::vector<CellHandle> cellHandles;
733 std::vector<uint> markers;
734 std::vector<Location*> locations;
746 LocCode loc_Y = loc_y + binary_cell_size * octreeVertexTable[_idx][1];
747 LocCode loc_Z = loc_z + binary_cell_size * octreeVertexTable[_idx][2];
750 for(
unsigned char i = 0; i < 8; i++)
756 int new_loc_x = loc_X;
757 int new_loc_y = loc_Y;
758 int new_loc_z = loc_Z;
761 if ( new_loc_x >= extent || new_loc_x < 0 )
767 new_loc_y = loc_Y + octreeCornerNeighborTable[i][1];
768 if ( new_loc_y >= extent || new_loc_y < 0 )
774 new_loc_z = loc_Z + octreeCornerNeighborTable[i][2];
775 if ( new_loc_z >= extent || new_loc_z < 0 )
781 locations.push_back(
new Location(new_loc_x, new_loc_y, new_loc_z, locinfo.
level() + 1, locinfo.
parent()));
782 markers.push_back(marker);
791 std::vector<Location*>().
swap(locations);
793 return make_pair(cellHandles, markers);
798 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
822 new_loc_x = loc_x - 1;
823 new_loc_y = loc_y - 1;
824 new_loc_z = loc_z - 1;
829 if ( loc_x + binary_cell_size >= extent )
return CellHandle();
832 new_loc_x = loc_x + binary_cell_size;
833 new_loc_y = loc_y - 1;
834 new_loc_z = loc_z - 1;
840 if ( loc_y + binary_cell_size >= extent )
return CellHandle();
842 new_loc_x = loc_x - 1;
843 new_loc_y = loc_y + binary_cell_size;
844 new_loc_z = loc_z - 1;
849 if ( loc_x + binary_cell_size >= extent )
return CellHandle();
850 if ( loc_y + binary_cell_size >= extent )
return CellHandle();
852 new_loc_x = loc_x + binary_cell_size;
853 new_loc_y = loc_y + binary_cell_size;
854 new_loc_z = loc_z - 1;
861 if ( loc_z + binary_cell_size >= extent )
return CellHandle();
862 new_loc_x = loc_x - 1;
863 new_loc_y = loc_y - 1;
864 new_loc_z = loc_z + binary_cell_size;
869 if ( loc_x + binary_cell_size >= extent )
return CellHandle();
871 if ( loc_z + binary_cell_size >= extent )
return CellHandle();
872 new_loc_x = loc_x + binary_cell_size;
873 new_loc_y = loc_y - 1;
874 new_loc_z = loc_z + binary_cell_size;
880 if ( loc_y + binary_cell_size >= extent )
return CellHandle();
881 if ( loc_z + binary_cell_size >= extent )
return CellHandle();
882 new_loc_x = loc_x - 1;
883 new_loc_y = loc_y + binary_cell_size;
884 new_loc_z = loc_z + binary_cell_size;
889 if ( loc_x + binary_cell_size >= extent )
return CellHandle();
890 if ( loc_y + binary_cell_size >= extent )
return CellHandle();
891 if ( loc_z + binary_cell_size >= extent )
return CellHandle();
892 new_loc_x = loc_x + binary_cell_size;
893 new_loc_y = loc_y + binary_cell_size;
894 new_loc_z = loc_z + binary_cell_size;
906 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
914 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
922 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
930 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
939 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
952 return ( loc_x == 0 ||
955 loc_x + binary_cell_size == tree_size ||
956 loc_y + binary_cell_size == tree_size ||
957 loc_z + binary_cell_size == tree_size );
962 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
982 unsigned int cidx = ( _x < cx ? 0 : 1 )
983 + ( _y < cy ? 0 : 2 )
984 + ( _z < cz ? 0 : 4 );
985 ch =
child( ch, cidx );
993 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
1001 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
1009 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
1017 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
1033 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
1036 bool left = (_direction == 0);
1037 bool right = (_direction == 1);
1038 bool up = (_direction == 2);
1039 bool down = (_direction == 3);
1041 BaseVecT xAxis(_mvm[0], _mvm[4], _mvm[8]);
1042 BaseVecT yAxis(_mvm[1], _mvm[5], _mvm[9]);
1047 if (fabs(xAxis[0])>fabs(xAxis[1]))
1049 if (fabs(xAxis[0])>fabs(xAxis[2]))
1052 else if (fabs(xAxis[1])>fabs(xAxis[2]))
1056 if (fabs(yAxis[0])>fabs(yAxis[1]))
1058 if (fabs(yAxis[0])>fabs(yAxis[2]))
1061 else if (fabs(yAxis[1])>fabs(yAxis[2]))
1069 if (xAxis[xIndex]<0)
1086 if (xAxis[xIndex]<0)
1103 if (xAxis[xIndex]<0)
1123 if (yAxis[yIndex]<0)
1140 if (yAxis[yIndex]<0)
1157 if (yAxis[yIndex]<0)
1197 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
1200 return (((*point)[0]) > center[0] ) | ((((*point)[1]) > center[1] ) << 1) | ((((*point)[2]) > center[2] ) << 2);
1203 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
1206 return ((point[0]) > center[0] ) | (((point[1]) > center[1] ) << 1) | (((point[2]) > center[2] ) << 2);
1221 template <
typename BaseVecT,
typename BoxT,
typename T_CellData>
1240 LocCode cell_bit_mask = ( 1 << cell_level );
1251 dummy.location =
Location( par_loc_x, par_loc_y, par_loc_z, cell_level, _parent );
1254 dummy.location =
Location( par_loc_x | cell_bit_mask, par_loc_y, par_loc_z, cell_level, _parent );
1257 dummy.location =
Location( par_loc_x, par_loc_y | cell_bit_mask, par_loc_z, cell_level, _parent );
1260 dummy.location =
Location( par_loc_x | cell_bit_mask, par_loc_y | cell_bit_mask, par_loc_z, cell_level, _parent );
1263 dummy.location =
Location( par_loc_x, par_loc_y, par_loc_z | cell_bit_mask, cell_level, _parent );
1266 dummy.location =
Location( par_loc_x | cell_bit_mask, par_loc_y, par_loc_z | cell_bit_mask, cell_level, _parent );
1269 dummy.location =
Location( par_loc_x, par_loc_y | cell_bit_mask, par_loc_z | cell_bit_mask, cell_level, _parent );
1272 dummy.location =
Location( par_loc_x | cell_bit_mask, par_loc_y | cell_bit_mask, par_loc_z | cell_bit_mask, cell_level, _parent );
1281 Location( par_loc_x, par_loc_y, par_loc_z, cell_level, _parent );
1283 Location( par_loc_x | cell_bit_mask, par_loc_y, par_loc_z, cell_level, _parent );
1285 Location( par_loc_x, par_loc_y | cell_bit_mask, par_loc_z, cell_level, _parent );
1287 Location( par_loc_x | cell_bit_mask, par_loc_y | cell_bit_mask, par_loc_z, cell_level, _parent );
1289 Location( par_loc_x, par_loc_y, par_loc_z | cell_bit_mask, cell_level, _parent );
1291 Location( par_loc_x | cell_bit_mask, par_loc_y, par_loc_z | cell_bit_mask, cell_level, _parent );
1293 Location( par_loc_x, par_loc_y | cell_bit_mask, par_loc_z | cell_bit_mask, cell_level, _parent );
1295 Location( par_loc_x | cell_bit_mask, par_loc_y | cell_bit_mask, par_loc_z | cell_bit_mask, cell_level, _parent );
Location & location(CellHandle _h)
bool PickChildCell(int _idx)
Pick the child cell of the currently picked cell.
bool is_inner_boundary(CellHandle _ch) const
static const int MAX_ROOT_LEVEL
Maximal root level defined by size of data type of the cell coordinates (leafs have side length 1) ...
void MovePickedCellUp(double *_mvm)
int level(CellHandle _ch) const
CellHandle m_PickedCell
The handle of the picked octree cell.
void MovePickedCellDown(double *_mvm)
std::pair< std::vector< CellHandle >, std::vector< uint > > all_corner_neighbors(CellHandle _ch, int _idx) const
std::vector< T_CellData > m_OctreeCell
Vector containing the cells.
CellHandle parent(CellHandle _ch) const
Scalar cell_size(CellHandle _ch) const
LocCode GetExtractionLevel() const
Get the level to be treated as leaf level.
bool is_leaf(CellHandle _ch) const
int getChildIndex(BaseVecT center, coord< float > *point)
CellHandle GetPickedCell() const
Get the handle of the picked cell.
int m_NumberOfGeneratedCells
Number of octree cells generated; this counter is adjusted in the split routine only.
void MovePickedCellRight(double *_mvm)
CellHandle face_neighbor(CellHandle _ch, int _idx) const
void MovePickedCell(int _key, double *_mvm)
Moving the picked cell, i.e. picking one of the neighbouring cells (if possible)
LocCode m_rootLevel
Root level.
void ResetNumberOfGeneratedCells()
Reset the number of generated cells.
CellHandle traverse(CellHandle _ch, LocCode _loc_x, LocCode _loc_y, LocCode _loc_z) const
unsigned short LocCode
This datatype determines the maximal depth of the octree.
void resize(unsigned int _size)
CellHandle parent() const
bool PickParentCell()
Pick the parent cell of the currently picked cell.
CellHandle traverse_to_level(CellHandle _ch, LocCode _loc_x, LocCode _loc_y, LocCode _loc_z, LocCode _level) const
void ResetPickedCell()
Reset the cell handle of the picked cell.
void split(CellHandle _ch, const bool bGarbageCollectionOnTheFly=false)
Split the cell, i.e. create eight children.
void SetPickedCell(CellHandle _ch)
Set the cell handle of the picked cell.
bool is_root(CellHandle _ch) const
size_t m_nextFreeBlock
Pointer to the next free block (garbage collection)
CellHandle get_common_ancestor(CellHandle _ch, LocCode _diff) const
void set_cell(int _i, int _cell)
CellHandle cell(Scalar _x, Scalar _y, Scalar _z) const
CellHandle child(CellHandle _ch, int _idx) const
void initialize(int _max_octree_level)
Initializing the octree with maximal level = root level (leafs have level 0)
BaseVecT cell_corner(CellHandle _ch, int _idx) const
void MovePickedCellLeft(double *_mvm)
Location::LocCode LocCode
static const int octreeVertexTable[8][3]
BaseVecT cell_center(CellHandle _ch) const
int GetNumberOfGeneratedCells() const
Get number of generated cells.
void swap(T *&arr, size_t i1, size_t i2, size_t n)
int depth(CellHandle _ch) const
static const int octreeCornerNeighborTable[64][3]
CellHandle corner_neighbor(CellHandle _ch, int _idx) const
void reserve(unsigned int _size)
LocCode m_ExtractionLevel
Level of the cells to be treated as leafs during surface extraction.
LocCode SetExtractionLevel(LocCode _level)
Set the level to be treated as leaf level.
const Location & location(CellHandle _h) const
bool is_extraction_leaf(CellHandle _ch) const
CellHandle edge_neighbor(CellHandle _ch, int _idx) const