40 #ifndef octreelocalizert_h 41 #define octreelocalizert_h 65 #define TEMPLATED_OCTREE_MAX_NODES_LIMIT 800 67 #define TEMPLATED_OCTREE_MAX_DEPTH 8 100 for (
int i = 1; i <= coords.
giveSize(); i++ ) {
101 origin.
at(i) = coords.
at(i);
108 void setMask(
int i,
int mask) { spatialMask.
at(i) = mask; }
128 this->spatialMask = mask;
132 for (
int i = 1; i <= coords.
giveSize(); i++ ) {
133 if ( spatialMask.
at(i) ) {
134 if ( coords.
at(i) < this->origin.
at(i) ) {
138 if ( coords.
at(i) > ( this->origin.
at(i) + this->
size ) ) {
167 CellPtrType child [ 2 ] [ 2 ] [ 2 ];
181 this->localizer = loc;
182 this->parent = parent;
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++ ) {
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);
270 if ( this->containsPoint(coords) ) {
271 if ( this->isTerminalOctant() ) {
276 for (
int i = 1; i <= coords.
giveSize(); i++ ) {
284 * child = this->child [ ind.
at(1) ] [ ind.
at(2) ] [ ind.
at(3) ];
295 if ( this->child [ 0 ] [ 0 ] [ 0 ] ) {
309 int i, j, k, result = 1;
311 if ( this->isTerminalOctant() ) {
316 for ( i = 0; i <= octantMask.
at(1); i++ ) {
317 for ( j = 0; j <= octantMask.
at(2); j++ ) {
318 for ( k = 0; k <= octantMask.
at(3); k++ ) {
319 childOrigin.
at(1) = this->origin.
at(1) + i * ( this->size / 2. );
320 childOrigin.
at(2) = this->origin.
at(2) + j * ( this->size / 2. );
321 childOrigin.
at(3) = this->origin.
at(3) + k * ( this->size / 2. );
323 this->child [ i ] [ j ] [ k ] =
new OctantRecT(localizer,
this, childOrigin, this->size / 2.0);
329 int newLevel = level - 1;
330 if ( newLevel > 0 ) {
332 for ( i = 0; i <= octantMask.
at(1); i++ ) {
333 for ( j = 0; j <= octantMask.
at(2); j++ ) {
334 for ( k = 0; k <= octantMask.
at(3); k++ ) {
335 if ( this->child [ i ] [ j ] [ k ] ) {
336 result &= this->child [ i ] [ j ] [ k ]->
divideLocally(newLevel, octantMask);
354 double BBXSize = testedBBX.
giveSize();
357 int BBXOriginInside = this->containsPoint(BBXOrigin);
358 if ( BBXOriginInside ) {
359 for ( i = 1; i <= 3; i++ ) {
361 if ( this->size > ( BBXSize + ( BBXOrigin.
at(i) - this->origin.
at(i) ) ) ) {
373 for ( i = 1; i <= 3; i++ ) {
375 if ( BBXOrigin.
at(i) > ( this->size + this->origin.
at(i) ) ) {
378 if ( BBXOrigin.
at(i) + BBXSize > this->origin.
at(i) ) {
398 int i, test = 1, nsd, size = coords.
giveSize();
404 double cellRadius = sqrt( nsd * ( this->size / 2.0 ) * ( this->size / 2. ) );
405 for ( i = 1; i < 4; i++ ) {
406 cellCenter.
at(i) += this->size / 2.0;
409 for ( i = 1, dist = 0.0; i <=
size; i++ ) {
411 dist += ( cellCenter.
at(i) - coords.
at(i) ) * ( cellCenter.
at(i) - coords.
at(i) );
416 if ( dist > ( cellRadius + radius ) ) {
420 int centerInside = this->containsPoint(coords);
421 if ( centerInside ) {
422 for ( i = 1; i <=
size; i++ ) {
424 if ( ( this->origin.
at(i) > ( coords.
at(i) - radius ) ) || ( ( this->origin.
at(i) + this->
size ) < ( coords.
at(i) + radius ) ) ) {
438 for ( i = 1; i <=
size; i++ ) {
439 if ( localizer->
giveOctreeMaskValue(i) && ( fabs( cellCenter.
at(i) - coords.
at(i) ) > ( this->size / 2. + radius ) ) ) {
455 if ( dataList == NULL ) {
456 dataList =
new std :: list< T >;
473 this->giveDataList()->push_front(member);
474 return this->giveDataList()->begin();
521 virtual std :: list< LocalInsertionData< T > > *giveInsertionList(T &member) = 0;
552 for (
int i = 1; i <= 3; i++ ) {
601 centerCoords.
at(3) = 0.0;
628 virtual bool evaluate(T &obj) = 0;
630 virtual void giveStartingPosition(
FloatArray &answer) = 0;
632 virtual void giveResult(std :: list< T > &answer) = 0;
636 virtual bool isBBXStage1Defined(
BoundingBox &BBXStage1) = 0;
641 virtual bool isBBXStage2Defined(
BoundingBox &BBXStage2) = 0;
669 startingPosition = pos;
681 position = * startingPosition;
695 if ( ( distance - distanceToClosestNode ) <= distance * 0.001 ) {
696 if ( ( distance - distanceToClosestNode ) >= -0.001 * distance ) {
697 closestNodeIndices.push_back(nodeNr);
699 closestNodeIndices.clear();
700 closestNodeIndices.push_back(nodeNr);
701 distanceToClosestNode = distance;
705 closestNodeIndices.push_back(nodeNr);
718 answer = closestNodeIndices;
730 BBXStage2.
setSize(distanceToClosestNode);
759 startingPosition = pos;
775 centerCoords.
at(3) = 0.0;
777 if ( ( startingPosition->
distance(centerCoords) ) < radius ) {
778 result.push_back(DTptr);
791 answer = * startingPosition;
840 if (rootCell)
delete rootCell;
851 if ( initialDivision ) {
852 this->rootCell->
divideLocally(initialDivision, this->octreeMask);
866 if ( functor.
evaluate(memberID, rootCell) ) {
867 this->insertMemberIntoCell(memberID, functor, rootCell);
877 this->removeMemberFromCell(memberID, functor, rootCell);
884 typename std :: list< T > *cellDataList;
886 listIteratorType pos;
888 typename std :: list< CellPtrType > *cellListPostSearch = NULL;
889 typename std :: list< CellPtrType > :: iterator cellListPos;
894 CellPtrType terminal;
897 terminal = this->findTerminalContaining(rootCell, startPos);
900 for ( pos = cellDataList->begin(); pos != cellDataList->end(); ++pos ) {
907 giveListOfTerminalCellsInBoundingBox(* cellListPostSearch, BBS2, rootCell);
908 for ( cellListPos = cellListPostSearch->begin(); cellListPos != cellListPostSearch->end(); ++cellListPos ) {
909 if ( * cellListPos != terminal ) {
910 cellDataList = ( * cellListPos )->giveDataList();
911 for ( pos = cellDataList->begin(); pos != cellDataList->end(); ++pos ) {
926 typename std :: list< T > *cellDataList;
927 listIteratorType pos, positionInDataList;
929 std :: list< LocalInsertionData< T > > *insertionDataList;
930 typedef typename std :: list< LocalInsertionData< T > > :: iterator LIDiterator;
934 CellPtrType terminal, cell;
937 terminal = this->findTerminalContaining(rootCell, startingPosition);
940 for ( pos = cellDataList->begin(); pos != cellDataList->end(); ) {
945 if ( insertionDataList ) {
946 for ( LIDiterator insDataIT = insertionDataList->begin(); insDataIT != insertionDataList->end(); insDataIT++ ) {
947 cell = ( * insDataIT ).containedInCell;
948 positionInDataList = ( * insDataIT ).posInCellDataList;
953 removeMemberFromCell(_obj, insertor, terminal);
957 pos = cellDataList->begin();
976 this->giveMaxTreeDepthFrom(rootCell, treeDepth);
985 CellPtrType currCell = startCell;
990 if ( result == -2 ) {
1011 int nCellItems, cellDepth;
1012 dataContainerType *cellDataList;
1013 listIteratorType pos;
1014 listIteratorType insertedPosition;
1016 std :: list< LocalInsertionData< T > > *insData;
1017 typedef typename std :: list< LocalInsertionData< T > > :: iterator LIDiterator;
1019 if ( cell == NULL ) {
1025 nCellItems = cellDataList->size();
1026 cellDepth = this->giveCellDepth(cell);
1027 if ( cellDepth > maxDepthReached ) {
1028 maxDepthReached = cellDepth;
1029 #ifdef TEMPLATED_OCTREE_DEBUG 1030 printf(
"Reached cell depth: %i \n", maxDepthReached);
1038 #if 1 // more memory efficient implementation 1039 while (!cellDataList->empty())
1041 this->insertMemberIntoCell(cellDataList->back(), functor, cell);
1044 for ( LIDiterator insDataIT = insData->begin(); insDataIT != insData->end(); ) {
1045 if ( ( * insDataIT ).containedInCell == cell ) {
1046 insDataIT = insData->erase(insDataIT);
1052 cellDataList->pop_back();
1055 for ( pos = cellDataList->begin(); pos != cellDataList->end(); ++pos ) {
1056 this->insertMemberIntoCell(* pos, functor, cell);
1059 for ( LIDiterator insDataIT = insData->begin(); insDataIT != insData->end(); ) {
1060 if ( ( * insDataIT ).containedInCell == cell ) {
1061 insDataIT = insData->erase(insDataIT);
1071 this->insertMemberIntoCell(memberID, functor, cell);
1073 insertedPosition = cell->
addMember(memberID);
1082 for ( i = 0; i <= 1; i++ ) {
1083 for ( j = 0; j <= 1; j++ ) {
1084 for ( k = 0; k <= 1; k++ ) {
1088 this->insertMemberIntoCell( memberID, functor, cell->
giveChild(i, j, k) );
1103 listIteratorType pos;
1107 if ( functor.
evaluate(memberID, cell) ) {
1114 for ( i = 0; i <= 1; i++ ) {
1115 for ( j = 0; j <= 1; j++ ) {
1116 for ( k = 0; k <= 1; k++ ) {
1117 this->removeMemberFromCell( memberID, functor, cell->
giveChild(i, j, k) );
1130 int i, j, k, depth = this->giveCellDepth(root);
1131 maxDepth =
max(maxDepth, depth);
1133 for ( i = 0; i <= octreeMask.
at(1); i++ ) {
1134 for ( j = 0; j <= octreeMask.
at(2); j++ ) {
1135 for ( k = 0; k <= octreeMask.
at(3); k++ ) {
1137 this->giveMaxTreeDepthFrom(root->
giveChild(i, j, k), maxDepth);
1151 cellList.push_back(currentCell);
1153 for ( i = 0; i <= octreeMask.
at(1); i++ ) {
1154 for ( j = 0; j <= octreeMask.
at(2); j++ ) {
1155 for ( k = 0; k <= octreeMask.
at(3); k++ ) {
1156 if ( currentCell->
giveChild(i, j, k) ) {
1157 this->giveListOfTerminalCellsInBoundingBox( cellList, BBX, currentCell->
giveChild(i, j, k) );
1169 #endif // octreelocalizer_h Templated octree cell containing data of T type.
OctantRecT< T > * CellPtrType
Squared bounding box for templated octree localizer.
void giveResult(std::list< DelaunayTriangle * > &answer)
Gives the triangles containing the node.
virtual void giveStartingPosition(FloatArray &answer)=0
Gives the starting position of the search.
void giveMaxTreeDepthFrom(CellPtrType root, int &maxDepth)
Gives the maximal tree depth from given cell.
InsertTriangleBasedOnCircumcircle(Domain *d)
Constructor.
int giveOctreeMaskValue(int indx)
bool evaluate(DelaunayTriangle *&DTptr)
Evaluates a triangle upon its circumscribed cricle.
void registerInsertion(DelaunayTriangle *&TEptr, LocalInsertionData< DelaunayTriangle * >LIdata)
Stores LocalInsertionData on the member.
~ElementCircumCirclesContainingNode()
void giveStartingPosition(FloatArray &answer)
Gives the starting position of the search.
void setMask(int i, int mask)
Sets the spatial mask.
int removeMemberFromCell(T &memberID, SL_Insertion_Functor< T > &functor, CellPtrType cell)
Removes member from cell using insertion functor to ensure member is contained in.
bool isBBXStage1Defined(BoundingBox &BBXStage1)
Stage1 means, we are looking for objects in a distance given by some boundingBox (e.g.
~BoundingBox()
Destructor.
OctantRecT< T > * containedInCell
Octant cell containing object.
void zero()
Sets all component to zero.
double & at(int i)
Coefficient access function.
int max(int i, int j)
Returns bigger value form two given decimals.
int removeMemberFromOctree(T &memberID, SL_Insertion_Functor< T > &functor)
Removes member from octree using insertion functor - NOT IN USE.
void giveOctreeMask(IntArray &answer)
std::list< DelaunayTriangle * > result
void removeMember(T &member)
Removes member from data list.
LocalizerPtrType localizer
Octree localizer whose part of is the cell.
FloatArray origin
Origin of the cell.
bool evaluate(int &nodeNr)
Evaluates a node.
virtual bool isBBXStage1Defined(BoundingBox &BBXStage1)=0
Stage1 means, we are looking for objects in a distance given by some boundingBox (e.g.
void giveOrigin(FloatArray &answer)
Gives the cell origin.
int insertMemberIntoCell(T &memberID, SL_Insertion_Functor< T > &functor, CellPtrType cell)
Inserts member into the cell by evaluating the insertion functor Method is called recursivelly until ...
double giveCircumRadius() const
Gives the radius of the circumscribed circle.
virtual void giveResult(std::list< T > &answer)=0
Gives a container with found objects.
std::list< LocalInsertionData< DelaunayTriangle * > > * giveInsertionList(DelaunayTriangle *&DTptr)
Returns list of LocalInsertionData stored on the member.
CellPtrType giveRootCell()
void init(FloatArray &origin, double size, IntArray &mask)
Sets all BBOx parameters in ince.
BoundingBox()
Constructor.
virtual bool evaluate(T &obj)=0
Evaluates wether the search condition is accomplished or not.
virtual void registerInsertion(T &member, LocalInsertionData< T >LIdata)=0
Stores LocalInsertionData on the member.
virtual double giveCoordinate(int i)
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.
void deleteDataList()
Removes the data list.
Class implementing an array of integers.
int & at(int i)
Coefficient access function.
Delaunay triangle for the triangulation of a set of nodes.
std::list< LocalInsertionData< DelaunayTriangle * > > * giveListOfCellsAndPosition()
Returns a list of octree cells and with iterator position in their member lists.
listIteratorType addMember(T &member)
Adds the object in to the data list returning iterator position to the object in the list...
std::list< T >::iterator listIteratorType
virtual bool isBBXStage2Defined(BoundingBox &BBXStage2)=0
Stage2BBX is given by results of a prior search.
FloatArray * startingPosition
double distance(const FloatArray &x) const
Computes the distance between position represented by receiver and position given as parameter...
OctantRecT< T > * CellPtrType
std::list< T > dataContainerType
std::list< T >::iterator listIteratorType
void giveListOfTerminalCellsInBoundingBox(std::list< CellPtrType > &cellList, BoundingBox &BBX, CellPtrType currentCell)
Gives a list of terminal cells in a bounding box.
#define TEMPLATED_OCTREE_MAX_NODES_LIMIT
Functor for finding triangles whose circumscribed circles contains given node.
std::list< int > closestNodeIndices
#define OOFEM_LOG_INFO(...)
double giveYCenterCoordinate() const
Gives the y coordinate of the center of the circumscribed circle.
listIteratorType posInCellDataList
Iterator position in the list of cell objects.
int giveCellDepth(CellPtrType cell)
Returns the depth of the cell.
OctantRecT(LocalizerPtrType loc, CellPtrType parent, FloatArray &origin, double size)
Constructor.
bool isBBXStage2Defined(BoundingBox &BBXStage2)
Stage2BBX is given by results of a prior search.
CellPtrType giveChild(int xi, int yi, int zi)
Gives the Child at given local indices.
IntArray spatialMask
Spatial dimension mask.
LocalInsertionData()
Constructor.
const char * giveClassName() const
Help class for storing pointer to octant cell and position of the member in the data list...
void giveMask(IntArray &answer)
Gives the spatial mask of the bounding box.
double giveSize()
Gives the size of the cell.
virtual std::list< LocalInsertionData< T > > * giveInsertionList(T &member)=0
Returns list of LocalInsertionData stored on the member.
void setSize(double s)
Sets the size of the bounding box (all sides are equal)
boundingSphereStatus testBoundingSphere(const FloatArray &coords, double radius)
Tests the position of a bounding spere in relation to the octant cell.
int giveChildContainingPoint(CellPtrType *child, const FloatArray &coords)
Returns the child containing given point.
void giveStartingPosition(FloatArray &position)
Gives the starting position of the search.
~InsertTriangleBasedOnCircumcircle()
Destructor.
double distanceToClosestNode
std::list< T >::const_iterator listConstIteratorType
double giveXCenterCoordinate() const
Gives the x coordinate of the center of the circumscribed circle.
OctreeSpatialLocalizerT()
Constructor.
int divideLocally(int level, const IntArray &octantMask)
Divide receiver further, creating corresponding children.
Class representing vector of real numbers.
Functor for storing triangles in the octree according to theirs circumscribed circles.
double size
Size of the cell.
Functor base class responsible for insertion of members into the octree cell.
bool contains(const FloatArray &coords) const
bool evaluate(DelaunayTriangle *&DTptr, OctantRecT< DelaunayTriangle * > *cell)
Evaluates the position of a triangle.
OctantRec::BoundingBoxStatus testBoundingBox(BoundingBox &testedBBX)
Tests the position of a bounding box in relation to the octant cell.
OctantRecT< T > * CellPtrType
int containsPoint(const FloatArray &coords)
Gives 1 if a given point is contained in the cell, 0 otherwise.
FloatArray origin
Starting point.
std::list< T > * giveDataList()
Return reference to member List.
virtual bool evaluate(T &member, OctantRecT< T > *cell)=0
Evaluates wether the member should be stored in the octant cell.
bool isBBXStage2Defined(BoundingBox &BBXStage2)
Stage2BBX is given by results of a prior search.
Class implementing single timer, providing wall clock and user time capabilities. ...
CellPtrType findTerminalContaining(CellPtrType startCell, const FloatArray &coords)
Returns terminal octant cell containing node with coords.
int insertMemberIntoOctree(T &memberID, SL_Insertion_Functor< T > &functor)
Inserts member into the octree using functor for the evaluation.
std::list< T >::iterator listIteratorType
CellPtrType parent
Parent octree cell.
double size
Bounding box size length.
Templated octree spatial localizer.
OctreeSpatialLocalizerT< T > * LocalizerPtrType
Functor base class for evaluating search tasks on the octree according given condition.
virtual FloatArray * giveCoordinates()
void proceedDataOnFilterAndRemoveFromOctree(std::list< T > &answer, SL_Evaluation_Functor< T > &filter, SL_Insertion_Functor< T > &insertor, Timer &searchingTimer)
Applies the evaluation functor, fills the answer list with results and removes found object from octr...
void giveOrigin(FloatArray &answer)
Returns the bounding box origin.
int init(BoundingBox &BBX, int initialDivision=0)
Initilizes the octree structure.
bool isBBXStage1Defined(BoundingBox &BBXStage1)
Stage1 means, we are looking for objects in a distance given by some boundingBox (e.g.
bool evaluate(int &nodeNr, OctantRecT< int > *cell)
Evaluates the position of a node.
InsertNode(Domain *d)
Constuctor.
int giveSize() const
Returns the size of receiver.
Node * giveNode(int n)
Service for accessing particular domain node.
the oofem namespace is to define a context or scope in which all oofem names are defined.
std::list< T > * dataList
Octant cell member list.
~ClosestNode()
Destructor.
void registerInsertion(int &nodeNr, LocalInsertionData< int >LIdata)
Stores LocalInsertionData on the member.
FloatArray * startingPosition
Functor for storing nodes in the octree.
double giveSize()
Gives the size of the bounding box.
#define TEMPLATED_OCTREE_MAX_DEPTH
ClosestNode(FloatArray *pos, Domain *d)
Constructor.
std::list< LocalInsertionData< int > > * giveInsertionList(int &nodeNr)
Returns list of LocalInsertionData stored on the member.
ElementCircumCirclesContainingNode(FloatArray *pos, Domain *d)
Constructor.
~OctreeSpatialLocalizerT()
Destructor.
void giveResult(std::list< int > &answer)
Gives the closest nodes.
void resize(int s)
Resizes receiver towards requested size.
std::list< T >::iterator listIteratorType
void setOrigin(FloatArray &coords)
Sets the origin of the bounding box.
Functor for closest node search.