28 for(
unsigned int ui=0;ui<3;ui++)
31 valid[ui][0] = valid[ui][1] =
true;
33 bounds[ui][0] =std::min(p1[ui],p2[ui]);
34 bounds[ui][1] =std::max(p1[ui],p2[ui]);
40 for(
unsigned int ui=0; ui<3; ui++)
42 if(bounds[ui][0]!=other.bounds[ui][0] ||
43 bounds[ui][1]!=other.bounds[ui][1])
50 float xMax,
float yMax,
float zMax)
52 bounds[0][0]=xMin; bounds[1][0]=yMin; bounds[2][0]=zMin;
53 bounds[0][1]=xMax; bounds[1][1]=yMax; bounds[2][1]=zMax;
55 valid[0][0]=
true; valid[1][0]=
true; valid[2][0]=
true;
56 valid[0][1]=
true; valid[1][1]=
true; valid[2][1]=
true;
62 for(
unsigned int ui=0;ui<3;ui++)
64 bounds[ui][0] = b.bounds[ui][0];
65 bounds[ui][1] = b.bounds[ui][1];
67 valid[ui][0] = b.valid[ui][0];
68 valid[ui][1] = b.valid[ui][1];
78 ASSERT(bound <3 && minMax < 2);
79 bounds[bound][minMax]=value;
81 valid[bound][minMax]=
true;
88 ASSERT(bound <3 && minMax < 2);
89 ASSERT(valid[bound][minMax]==
true);
90 return bounds[bound][minMax];
96 bounds[0][0] = std::numeric_limits<float>::max();
97 bounds[1][0] = std::numeric_limits<float>::max();
98 bounds[2][0] = std::numeric_limits<float>::max();
100 bounds[0][1] = -std::numeric_limits<float>::max();
101 bounds[1][1] = -std::numeric_limits<float>::max();
102 bounds[2][1] = -std::numeric_limits<float>::max();
117 bounds[0][0] = -std::numeric_limits<float>::max();
118 bounds[1][0] = -std::numeric_limits<float>::max();
119 bounds[2][0] = -std::numeric_limits<float>::max();
121 bounds[0][1] = std::numeric_limits<float>::max();
122 bounds[1][1] = std::numeric_limits<float>::max();
123 bounds[2][1] = std::numeric_limits<float>::max();
139 for(
unsigned int ui=0;ui<3; ui++)
141 if(fabs(bounds[ui][0] - bounds[ui][1]) < std::numeric_limits<float>::epsilon())
161 for(
unsigned int ui=0; ui<3; ui++)
163 if(b.bounds[ui][0] < bounds[ui][0])
165 bounds[ui][0] = b.bounds[ui][0];
171 if(b.bounds[ui][1] > bounds[ui][1])
173 bounds[ui][1] = b.bounds[ui][1];
185 for(
unsigned int ui=0; ui<3; ui++)
188 if(bounds[ui][0] > p[ui])
189 bounds[ui][0] = p[ui];
192 if(bounds[ui][1] < p[ui])
193 bounds[ui][1] = p[ui];
200 for(
unsigned int ui=0; ui<3; ui++)
212 bounds[0][0] = std::numeric_limits<float>::max();
213 bounds[1][0] = std::numeric_limits<float>::max();
214 bounds[2][0] = std::numeric_limits<float>::max();
216 bounds[0][1] = -std::numeric_limits<float>::max();
217 bounds[1][1] = -std::numeric_limits<float>::max();
218 bounds[2][1] = -std::numeric_limits<float>::max();
220 for(
unsigned int ui=0;ui<n; ui++)
222 for(
unsigned int uj=0;uj<3;uj++)
224 if(bounds[uj][0] > p[ui][uj])
226 bounds[uj][0] = p[ui][uj];
233 if(bounds[uj][1] < p[ui][uj])
235 bounds[uj][1] = p[ui][uj];
246 for(
unsigned int ui=0; ui<3; ui++)
248 bounds[ui][0]=std::min(p1[ui],p2[ui]);
249 bounds[ui][1]=std::max(p1[ui],p2[ui]);
261 for(
unsigned int ui=0;ui<3;ui++)
263 bounds[ui][0]=p1[ui]-radius;
264 bounds[ui][1]=p1[ui]+radius;
282 #pragma omp parallel for 283 for(
size_t ui=0;ui<ptArray.size();ui++)
285 for(
unsigned int uj=0;uj<3;uj++)
287 bounds[uj][0]=std::min(bounds[uj][0],ptArray[ui].getPosRef()[uj]);
288 bounds[uj][1]=std::max(bounds[uj][1],ptArray[ui].getPosRef()[uj]);
293 for(
unsigned int ui=0;ui<3;ui++)
295 if(bounds[ui][0] < bounds[ui][1])
296 valid[ui][0]=valid[ui][1]=
true;
304 for(
unsigned int ui=0; ui<3; ui++)
306 ASSERT(valid[ui][0] && valid[ui][1]);
315 for(
unsigned int ui=0; ui<3; ui++)
327 for(
unsigned int ui=0; ui<3; ui++)
347 for(
unsigned int ui=0;ui<3; ui++)
349 ASSERT(valid[0][1] && valid [0][0]);
352 return fabs(bounds[dim][1] - bounds[dim][0]);
369 for(
unsigned int ui=0; ui<3; ui++)
371 ASSERT(valid[ui][0] && valid[ui][1]);
372 if( p[ui] < bounds[ui][0] || p[ui] > bounds[ui][1])
381 float sqrRad= radius*radius;
383 for(
size_t ui=0;ui<8;ui++)
386 p[0] = bounds[0][ui&1];
387 p[1] = bounds[1][(ui&2) >> 1];
388 p[2] = bounds[2][(ui&4)>> 2];
390 if(p.sqrDist(origin) >=sqrRad)
402 for(
unsigned int dim=0;dim<3;dim++)
406 a=bounds[dim][0]; b=bC.bounds[dim][0];
409 a=bounds[dim][1]; b=bC.bounds[dim][1];
419 for(
unsigned int dim=0;dim<3;dim++)
423 a=bounds[dim][0]; b=bC.bounds[dim][0];
426 a=bounds[dim][1]; b=bC.bounds[dim][1];
443 if(*val <= bounds[ui][0])
450 if(*val >=bounds[ui][1])
462 return (nearPt.
sqrDist(pt) < sqrRad);
489 for(
unsigned int ui=0;ui<3; ui++)
491 ASSERT(valid[ui][1] && valid [ui][0]);
494 return Point3D(bounds[0][1] + bounds[0][0],
495 bounds[1][1] + bounds[1][0],
496 bounds[2][1] + bounds[2][0])/2.0f;
502 for(
unsigned int ui=0;ui<3; ui++)
504 ASSERT(valid[ui][1] && valid [ui][0]);
508 float maxDistSqr=0.0f;
515 p[0] =
Point3D(bounds[0][0],bounds[1][0],bounds[2][0]);
516 p[1] =
Point3D(bounds[0][1],bounds[1][1],bounds[2][1]);
519 for(
unsigned int ui=0;ui<8; ui++)
521 maxDistSqr=std::max(maxDistSqr,
522 queryPt.
sqrDist(
Point3D(p[ui&1][0],p[(ui&2) >> 1][1],p[(ui&4) >> 2][2])));
525 return sqrtf(maxDistSqr);
535 if( slice < bounds[dim][0])
539 if( slice >=bounds[dim][1])
548 for(
unsigned int ui=0;ui<3; ui++)
550 for(
unsigned int uj=0;uj<2; uj++)
553 valid[ui][uj] = b.valid[ui][uj];
555 bounds[ui][uj] = b.bounds[ui][uj];
565 stream <<
"Bounds :Low (";
566 stream << b.bounds[0][0] <<
",";
567 stream << b.bounds[1][0] <<
",";
568 stream << b.bounds[2][0] <<
") , High (";
570 stream << b.bounds[0][1] <<
",";
571 stream << b.bounds[1][1] <<
",";
572 stream << b.bounds[2][1] <<
")" << std::endl;
576 stream <<
"Bounds Valid: Low (";
577 stream << b.valid[0][0] <<
",";
578 stream << b.valid[1][0] <<
",";
579 stream << b.valid[2][0] <<
") , High (";
581 stream << b.valid[0][1] <<
",";
582 stream << b.valid[1][1] <<
",";
583 stream << b.valid[2][1] <<
")" << std::endl;
589 bool BoundCube::isValid()
const 591 for(
unsigned int ui=0;ui<3; ui++)
593 if(!valid[ui][0] || !valid[ui][1])
600 bool BoundCube::isValid(
unsigned int dim)
const 602 return (valid[dim][0] && valid[dim][1]);
605 void BoundCube::setInvalid()
607 valid[0][0]=
false; valid[1][0]=
false; valid[2][0]=
false;
608 valid[0][1]=
false; valid[1][1]=
false; valid[2][1]=
false;
float sqrDist(const Point3D &pt) const
Returns the square of distance to another Point3D.
bool containsPt(const Point3D &pt) const
Check to see if the point is contained in, or part of the walls of the cube.
void setInverseLimits()
Set the cube to be "inside out" at the limits of numeric results;.
const float * getValueArr() const
Obtain a pointer to internal array (3 floats)
void setLimits()
Set min-max bounds to fp min/max.
bool intersects(const Point3D &pt, float sqrRad) const
Checks if a point intersects a sphere of centre Pt, radius^2 sqrRad.
void getBounds(Point3D &low, Point3D &high) const
Get the bounds of the cube as two points, the lower left (minimum bound) and upper right corner (max ...
float getMaxDistanceToBox(const Point3D &pt) const
Returns maximum distance to box corners (which is an upper bound on max box distance).
float getSize(unsigned int dim) const
Return the size of the side parallel to the given dimension.
float getVolume() const
Obtain the volume of the cube.
friend std::ostream & operator<<(std::ostream &stream, const BoundCube &b)
A 3D point data class storage.
unsigned int segmentTriple(unsigned int dim, float slice) const
Return a triplet to indicate a spatial partition value lies in.
BoundCube makeUnion(const BoundCube &b) const
Create the box containing a union of two bounding cubes.
float getLargestDim() const
Get the largest dimension of the bound cube.
void setBound(unsigned int bound, unsigned int minMax, float value)
Set an individual bound.
float getBound(unsigned int bound, unsigned int minMax) const
Return the bound on the given dimension.
void setValue(unsigned int ui, float val)
Set value val of the ui-th dimension, ui in (0,1,2)
BoundCube makeIntersection(const BoundCube &b) const
Create the box which is the intersection of two bounding cubes this is either null, or a box.
bool operator==(const BoundCube &other) const
Helper class to define a bounding cube.
bool containedInSphere(const Point3D &origin, float radius) const
Returns true if this box is contained by the sphere, represented by the origin+radius.
bool isFlat() const
Returns true if any bound is of null thickness.
Point3D getCentroid() const
Return the centroid.
BoundCube operator=(const BoundCube &)
bool contains(const BoundCube &b) const
Does this bounding box entirely contain another.
void setBounds(float xMin, float yMin, float zMin, float xMax, float yMax, float zMax)
Set the bounds by passing in minima and maxima of each dimension.
void expand(const BoundCube &b)
Expand (as needed) volume such that the argument bounding cube is enclosed by this one...