18 inline double max (
double x,
double y)
23 inline double min (
double x,
double y)
33 memset(_child, 0,
sizeof(_child));
57 const unsigned int count,
58 const unsigned int threshold,
59 const unsigned int maximumDepth,
61 const unsigned int currentDepth
69 _currentDepth=currentDepth;
80 if (count <= threshold || currentDepth >= maximumDepth)
84 _points =
new Point [count];
85 memcpy(_points, points,
sizeof (
Point)* count);
100 unsigned int childPointCounts[8]={0};
105 for (
unsigned int i = 0; i < count; i++)
109 Point &p = points[i];
129 childPointCounts[p.
code]++;
134 for (
int i = 0; i < 8; i++)
139 if (!childPointCounts[i])
continue;
148 Point *newList =
new Point [childPointCounts[i]];
153 Point *ptr = newList;
155 for (
unsigned int j = 0; j < count; j++)
157 if (points[j].code == i)
168 int newCount=childPointCounts[i];
180 static VectorT3 boundsOffsetTable[8];
182 boundsOffsetTable[0][0]=-0.5;
183 boundsOffsetTable[0][1]=-0.5;
184 boundsOffsetTable[0][2]=-0.5;
186 boundsOffsetTable[1][0]=+0.5;
187 boundsOffsetTable[1][1]=-0.5;
188 boundsOffsetTable[1][2]=-0.5;
190 boundsOffsetTable[2][0]=-0.5;
191 boundsOffsetTable[2][1]=+0.5;
192 boundsOffsetTable[2][2]=-0.5;
194 boundsOffsetTable[3][0]=+0.5;
195 boundsOffsetTable[3][1]=+0.5;
196 boundsOffsetTable[3][2]=-0.5;
198 boundsOffsetTable[4][0]=-0.5;
199 boundsOffsetTable[4][1]=-0.5;
200 boundsOffsetTable[4][2]=+0.5;
202 boundsOffsetTable[5][0]=+0.5;
203 boundsOffsetTable[5][1]=-0.5;
204 boundsOffsetTable[5][2]=+0.5;
206 boundsOffsetTable[6][0]=-0.5;
207 boundsOffsetTable[6][1]=+0.5;
208 boundsOffsetTable[6][2]=+0.5;
210 boundsOffsetTable[7][0]=+0.5;
211 boundsOffsetTable[7][1]=+0.5;
212 boundsOffsetTable[7][2]=+0.5;
240 _child[i]->build(newList, newCount, threshold, maximumDepth,
241 newBounds, currentDepth+1);
256 const unsigned int count)
267 for (
unsigned int i = 0; i < count; i++)
270 if (p[0] < min[0]) min[0] = p[0];
271 if (p[1] < min[1]) min[1] = p[1];
272 if (p[2] < min[2]) min[2] = p[2];
273 if (p[0] > max[0]) max[0] = p[0];
274 if (p[1] > max[1]) max[1] = p[1];
275 if (p[2] > max[2]) max[2] = p[2];
314 fprintf(fp,
"currentDepth is %i\n", _currentDepth);
315 fprintf(fp,
"node center is %f\t%f\t%f\n", _center[0],_center[1],_center[2]);
316 fprintf(fp,
"node radius is %f\n", _radius);
317 fprintf(fp,
"data in this node is ");
318 for(
unsigned int i=0; i<_pointCount; i++){
319 fprintf(fp,
"%i\t", _points[i].cellIndex);
321 fprintf(fp,
"\n end of node\n");
325 for(
int i=0; i<8;i++){
327 if(!_child[i])
continue;
329 _child[i]->report(fp);
343 double x=coordinate[0];
344 double y=coordinate[1];
345 double z=coordinate[2];
350 double leftBound=_center[0]-_radius;
351 double rightBound=_center[0]+_radius;
352 double frontBound=_center[1]-_radius;
353 double backBound=_center[1]+_radius;
354 double bottomBound=_center[2]-_radius;
355 double topBound=_center[2]+_radius;
357 if(leftBound <= x && x <= rightBound)
360 ewdistance =
min(
fabs(x-rightBound),
fabs(x-leftBound));
362 if(frontBound <= y && y <= backBound)
365 fbdistance =
min(
fabs(y-backBound),
fabs(y-frontBound));
367 if(bottomBound <= z && z <= topBound)
370 nsdistance =
min(
fabs(z-topBound),
fabs(z-bottomBound));
372 return (nsdistance * nsdistance +
373 ewdistance * ewdistance +
374 fbdistance * fbdistance);
395 for (
unsigned int i=0; i<_pointCount; i++){
396 dR=_points[i].coordinate-coordinate;
399 if(distance < shortestDistance*shortestDistance){
400 shortestDistance=
sqrt(distance);
401 node=_points[i].cellIndex;
407 else if(_nodeType==0){
412 for (
int i=0; i<8;i++){
414 if(!_child[i])
continue;
416 double childDistance=_child[i]->borderDistance(coordinate);
417 if (childDistance < shortestDistance*shortestDistance){
419 test=_child[i]->getNode(coordinate, shortestDistance);
445 double LargeNumber=1.0e20;
456 double LargeNumber=1.0e20;
474 for (
unsigned int i=0; i<_pointCount; i++){
475 dR=_points[i].coordinate-coordinate;
477 if(distance <= radius*radius){
478 cellList.push_back(_points[i].cellIndex);
483 else if(_nodeType==0){
488 for (
int i=0; i<8;i++){
490 if(!_child[i])
continue;
492 double childDistance=_child[i]->borderDistance(coordinate);
493 if (childDistance <= radius*radius){
494 _child[i]->getNodes(coordinate, radius, cellList);
502 const double radius, vector<int>& cellList)
520 double shortestDistance=100000;
521 double shortestDistanceSqr=shortestDistance*shortestDistance;
525 for (
int i=0; i<count; i++){
527 double distanceSqr=
mag2(dR);
528 if(distanceSqr < shortestDistanceSqr){
529 shortestDistance=
sqrt(distanceSqr);
530 shortestDistanceSqr=shortestDistance*shortestDistance;
543 vector<int> cellIndexList;
545 double radiusSqr=radius*radius;
546 for (
int i=0; i<count; i++){
548 double distanceSqr=
mag2(dR);
549 if(distanceSqr < radiusSqr){
550 cellIndexList.push_back(points[i].cellIndex);
553 return(cellIndexList);
562 const int nCells = cells.
getCount();
566 for(
int i=0; i<nCells; i++){
574 const int threshold=1;
575 const int maxDepth=20;
576 const int count=nCells;
588 Octree::build(points, count, threshold, maxDepth, bounds, currentDepth);
601 if (fg.
id == faceGroupID)
604 const int nFaces = faces.
getCount();
609 for(
int i=0; i<nFaces; i++){
617 const int threshold=1;
618 const int maxDepth=20;
619 const int count=nFaces;
627 Octree::build(points, count, threshold, maxDepth, bounds, currentDepth);
void Impl(const Mesh &mesh, const GeomFields &geomFields)
void Create(const Mesh &mesh, const GeomFields &geomFields, const int faceGroupID)
const FaceGroupList & getBoundaryFaceGroups() const
shared_ptr< FaceGroup > FaceGroupPtr
const vector< int > Naive_getNodes(const VectorT3 coordinate, const int count, const Point *points, const double radius)
const double borderDistance(const VectorT3 coordinate)
A utility method to figure out the closest distance of a border to a point. If the point is inside th...
double max(double x, double y)
Tangent sqrt(const Tangent &a)
void getNodes(const VectorT3 coordinate, const double radius, vector< int > &cellList)
Get all objects closest to a x/y/z within a radius. search mechanism similar to getNode(coordinate) ...
const int Naive_getNode(const VectorT3 coordinate, const int count, const Point *points)
Get all objects closest to a x/y/z within a radius. by simply looping over all the points ...
const StorageSite & getCells() const
Octree::VectorT3Array VectorT3Array
Tangent fabs(const Tangent &a)
const Bounds calcCubicBounds(const Point *points, const unsigned int count)
const int getNode(const double x, const double y, const double z)
double min(double x, double y)
virtual bool build(Point *points, const unsigned int count, const unsigned int threshold, const unsigned int maximumDepth, const Bounds &bounds, const unsigned int currentDepth=0)
Octree::VectorT3 VectorT3
T mag2(const Vector< T, 3 > &a)