41#ifndef octreelocalizert_h
42#define octreelocalizert_h
65#define TEMPLATED_OCTREE_MAX_NODES_LIMIT 500
67#define TEMPLATED_OCTREE_MAX_DEPTH 8
100 for (
int i = 1; i <= coords.
giveSize(); i++ ) {
126 this->origin = _origin;
128 this->spatialMask = mask;
132 for (
int i = 1; i <= coords.
giveSize(); i++ ) {
134 if ( coords.
at(i) < this->origin.at(i) ) {
138 if ( coords.
at(i) > ( this->origin.at(i) + this->size ) ) {
181 this->localizer = loc;
185 this->dataList = NULL;
188 for (
int i = 0; i <= 1; i++ ) {
189 for (
int j = 0; j <= 1; j++ ) {
190 for (
int k = 0; k <= 1; k++ ) {
191 this->child [ i ] [ j ] [ k ] = NULL;
199 for (
int i = 0; i <= 1; i++ ) {
200 for (
int j = 0; j <= 1; j++ ) {
201 for (
int k = 0; k <= 1; k++ ) {
202 if ( this->child [ i ] [ j ] [ k ] ) {
203 delete this->child [ i ] [ j ] [ k ];
228 for (
int i = 1; i <= coords.
giveSize(); i++ ) {
229 if (
localizer->giveOctreeMaskValue(i) ) {
230 if ( coords.
at(i) < this->origin.at(i) ) {
234 if ( coords.
at(i) > ( this->origin.at(i) + this->size ) ) {
250 if ( ( xi >= 0 ) && ( xi < 2 ) && ( yi >= 0 ) && ( yi < 2 ) && ( zi >= 0 ) && ( zi < 2 ) ) {
251 return this->child [ xi ] [ yi ] [ zi ];
253 OOFEM_ERROR(
"OctantRecT::giveChild invalid child index (%d,%d,%d)", xi, yi, zi);
275 for (
int i = 1; i <= coords.
giveSize(); i++ ) {
276 if (
localizer->giveOctreeMaskValue(i) && ( coords.
at(i) > ( this->origin.at(i) + this->size / 2. ) ) ) {
283 *
child = this->child [ ind.
at(1) ] [ ind.
at(2) ] [ ind.
at(3) ];
294 if ( this->child [ 0 ] [ 0 ] [ 0 ] ) {
308 int i, j, k, result = 1;
314 for ( i = 0; i <= octantMask.
at(1); i++ ) {
315 for ( j = 0; j <= octantMask.
at(2); j++ ) {
316 for ( k = 0; k <= octantMask.
at(3); k++ ) {
317 childOrigin.
at(1) = this->origin.
at(1) + i * ( this->size / 2. );
318 childOrigin.
at(2) = this->origin.
at(2) + j * ( this->size / 2. );
319 childOrigin.
at(3) = this->origin.
at(3) + k * ( this->size / 2. );
321 this->child [ i ] [ j ] [ k ] =
new OctantRecT(
localizer,
this, childOrigin, this->size / 2.0);
327 int newLevel = level - 1;
328 if ( newLevel > 0 ) {
330 for ( i = 0; i <= octantMask.
at(1); i++ ) {
331 for ( j = 0; j <= octantMask.
at(2); j++ ) {
332 for ( k = 0; k <= octantMask.
at(3); k++ ) {
333 if ( this->child [ i ] [ j ] [ k ] ) {
334 result &= this->child [ i ] [ j ] [ k ]->
divideLocally(newLevel, octantMask);
359 if (sAInside && eAInside) {
360 return OctantRec :: BBS_InsideCell;
361 }
else if (sAInside || eAInside) {
362 return OctantRec :: BBS_ContainsCell;
364 return OctantRec :: BBS_OutsideCell;
382 double cellRadius = sqrt( nsd * ( this->size / 2.0 ) * ( this->size / 2. ) );
383 for ( i = 1; i < 4; i++ ) {
384 cellCenter.
at(i) += this->size / 2.0;
387 for ( i = 1, dist = 0.0; i <=
size; i++ ) {
388 if (
localizer->giveOctreeMaskValue(i) ) {
389 dist += ( cellCenter.
at(i) - coords.
at(i) ) * ( cellCenter.
at(i) - coords.
at(i) );
394 if ( dist > ( cellRadius + radius ) ) {
399 if ( centerInside ) {
400 for ( i = 1; i <=
size; i++ ) {
401 if (
localizer->giveOctreeMaskValue(i) ) {
402 if ( ( this->origin.
at(i) > ( coords.
at(i) - radius ) ) || ( ( this->origin.at(i) + this->size ) < ( coords.
at(i) + radius ) ) ) {
416 for ( i = 1; i <=
size; i++ ) {
417 if (
localizer->giveOctreeMaskValue(i) && ( fabs( cellCenter.
at(i) - coords.
at(i) ) > ( this->size / 2. + radius ) ) ) {
572 if ( initialDivision ) {
573 this->rootCell->
divideLocally(initialDivision, this->octreeMask);
605 typename std :: list< T > *cellDataList;
609 typename std :: list< CellPtrType > *cellListPostSearch = NULL;
610 typename std :: list< CellPtrType > :: iterator cellListPos;
621 for ( pos = cellDataList->begin(); pos != cellDataList->end(); ++pos ) {
626 OctantRec :: BoundingBoxStatus BBStatus = terminal->
testBoundingBox(BBS2);
627 if ( BBStatus == OctantRec :: BBS_ContainsCell ) {
629 for ( cellListPos = cellListPostSearch->begin(); cellListPos != cellListPostSearch->end(); ++cellListPos ) {
630 if ( * cellListPos != terminal ) {
631 cellDataList = ( * cellListPos )->giveDataList();
632 for ( pos = cellDataList->begin(); pos != cellDataList->end(); ++pos ) {
647 typename std :: list< T > *cellDataList;
650 std :: list< LocalInsertionData< T > > *insertionDataList;
651 typedef typename std :: list< LocalInsertionData< T > > :: iterator LIDiterator;
661 for ( pos = cellDataList->begin(); pos != cellDataList->end(); ) {
666 if ( insertionDataList ) {
667 for ( LIDiterator insDataIT = insertionDataList->begin(); insDataIT != insertionDataList->end(); insDataIT++ ) {
668 cell = ( * insDataIT ).containedInCell;
669 positionInDataList = ( * insDataIT ).posInCellDataList;
678 pos = cellDataList->begin();
711 if ( result == -2 ) {
732 int nCellItems, cellDepth;
737 std :: list< LocalInsertionData< T > > *insData;
738 typedef typename std :: list< LocalInsertionData< T > > :: iterator LIDiterator;
740 if ( cell == NULL ) {
746 nCellItems = cellDataList->size();
750#ifdef TEMPLATED_OCTREE_DEBUG
760 while (!cellDataList->empty())
765 for ( LIDiterator insDataIT = insData->begin(); insDataIT != insData->end(); ) {
766 if ( ( * insDataIT ).containedInCell == cell ) {
767 insDataIT = insData->erase(insDataIT);
773 cellDataList->pop_back();
776 for ( pos = cellDataList->begin(); pos != cellDataList->end(); ++pos ) {
780 for ( LIDiterator insDataIT = insData->begin(); insDataIT != insData->end(); ) {
781 if ( ( * insDataIT ).containedInCell == cell ) {
782 insDataIT = insData->erase(insDataIT);
794 insertedPosition = cell->
addMember(memberID);
803 for ( i = 0; i <= 1; i++ ) {
804 for ( j = 0; j <= 1; j++ ) {
805 for ( k = 0; k <= 1; k++ ) {
828 if ( functor.
evaluate(memberID, cell) ) {
835 for ( i = 0; i <= 1; i++ ) {
836 for ( j = 0; j <= 1; j++ ) {
837 for ( k = 0; k <= 1; k++ ) {
852 maxDepth =
max(maxDepth, depth);
869 OctantRec :: BoundingBoxStatus BBStatus = currentCell->
testBoundingBox(BBX);
870 if ( ( BBStatus == OctantRec :: BBS_InsideCell ) || ( BBStatus == OctantRec :: BBS_ContainsCell ) ) {
872 cellList.push_back(currentCell);
double size
Bounding box size length.
BoundingBox()
Constructor.
void init(FloatArray &_origin, double _size, IntArray &mask)
void setMask(int i, int mask)
Sets the spatial mask.
bool contains(const FloatArray &coords) const
FloatArray origin
Starting point.
void giveOrigin(FloatArray &answer)
void setOrigin(FloatArray &coords)
Sets the origin of the bounding box.
void setSize(double s)
Sets the size of the bounding box (all sides are equal).
IntArray spatialMask
Spatial dimension mask.
void giveMask(IntArray &answer)
~BoundingBox()
Destructor.
double giveSize()
Gives the size of the bounding box.
Index giveSize() const
Returns the size of receiver.
void add(const FloatArray &src)
LocalInsertionData()
Constructor.
OctantRecT< T > * CellPtrType
std::list< T >::iterator listIteratorType
listIteratorType posInCellDataList
Iterator position in the list of cell objects.
OctantRecT< T > * containedInCell
Octant cell containing object.
OctantRecT< T > * CellPtrType
std::list< T >::iterator listIteratorType
double giveSize()
Gives the size of the cell.
void giveOrigin(FloatArray &answer)
OctreeSpatialLocalizerT< T > * LocalizerPtrType
friend class OctreeSpatialLocalizerT< T >
int giveChildContainingPoint(CellPtrType *child, const FloatArray &coords)
OctantRecT(LocalizerPtrType loc, CellPtrType parent, FloatArray &origin, double size)
Constructor.
std ::list< T > * dataList
LocalizerPtrType localizer
int divideLocally(int level, const IntArray &octantMask)
CellPtrType giveChild(int xi, int yi, int zi)
CellPtrType child[2][2][2]
OctantRec::BoundingBoxStatus testBoundingBox(BoundingBox &A)
void deleteDataList()
Removes the data list.
int containsPoint(const FloatArray &coords)
std ::list< T > * giveDataList()
Return reference to member List.
boundingSphereStatus testBoundingSphere(const FloatArray &coords, double radius)
listIteratorType addMember(T &member)
Adds the object in to the data list returning iterator position to the object in the list.
void removeMember(T &member)
Removes member from data list.
void giveDataOnFilter(std ::list< T > &answer, SL_Evaluation_Functor< T > &filter)
Evalutes the search accoring used functor a fills the list with results - NOT IN USE.
int giveOctreeMaskValue(int indx)
OctreeSpatialLocalizerT()
Constructor.
int insertMemberIntoOctree(T &memberID, SL_Insertion_Functor< T > &functor)
Inserts member into the octree using functor for the evaluation.
std ::list< T > dataContainerType
void giveOctreeMask(IntArray &answer)
const char * giveClassName() const
CellPtrType findTerminalContaining(CellPtrType startCell, const FloatArray &coords)
Returns terminal octant cell containing node with coords.
int removeMemberFromOctree(T &memberID, SL_Insertion_Functor< T > &functor)
Removes member from octree using insertion functor - NOT IN USE.
int insertMemberIntoCell(T &memberID, SL_Insertion_Functor< T > &functor, CellPtrType cell)
OctantRecT< T > * CellPtrType
std::list< T >::iterator listIteratorType
int giveCellDepth(CellPtrType cell)
Returns the depth of the cell.
void proceedDataOnFilterAndRemoveFromOctree(std ::list< T > &answer, SL_Evaluation_Functor< T > &filter, SL_Insertion_Functor< T > &insertor, Timer &searchingTimer)
void giveMaxTreeDepthFrom(CellPtrType root, int &maxDepth)
Gives the maximal tree depth from given cell.
void giveListOfTerminalCellsInBoundingBox(std ::list< CellPtrType > &cellList, BoundingBox &BBX, CellPtrType currentCell)
Gives a list of terminal cells in a bounding box.
int removeMemberFromCell(T &memberID, SL_Insertion_Functor< T > &functor, CellPtrType cell)
Removes member from cell using insertion functor to ensure member is contained in.
CellPtrType giveRootCell()
~OctreeSpatialLocalizerT()
Destructor.
friend class OctantRecT< T >
std::list< T >::const_iterator listConstIteratorType
int init(BoundingBox &BBX, int initialDivision=0)
Initilizes the octree structure.
virtual bool evaluate(T &obj)=0
Evaluates wether the search condition is accomplished or not.
virtual void giveResult(std ::list< T > &answer)=0
Gives a container with found objects.
virtual bool isBBXStage1Defined(BoundingBox &BBXStage1)=0
virtual void giveStartingPosition(FloatArray &answer)=0
Gives the starting position of the search.
virtual bool isBBXStage2Defined(BoundingBox &BBXStage2)=0
virtual std ::list< LocalInsertionData< T > > * giveInsertionList(T &member)=0
Returns list of LocalInsertionData stored on the member.
std::list< T >::iterator listIteratorType
virtual void registerInsertion(T &member, LocalInsertionData< T >LIdata)=0
Stores LocalInsertionData on the member.
virtual bool evaluate(T &member, OctantRecT< T > *cell)=0
Evaluates wether the member should be stored in the octant cell.
#define OOFEM_LOG_INFO(...)
FloatArrayF< N > max(const FloatArrayF< N > &a, const FloatArrayF< N > &b)
#define TEMPLATED_OCTREE_MAX_NODES_LIMIT
#define TEMPLATED_OCTREE_MAX_DEPTH