ENH: creating a bounding box without points yields an inverted box

- The code create a box with a (0,0,0) point.
  The new definition is more logical and makes it very easy to grow
  the bounding box to include new points. It also simplifies much of
  the logic in the constructors.

- Use ROOTVGREAT instead of VGREAT for sizing greatBox and invertedBox.
  Avoids some overflow issues reported by Mattijs (thus GREAT has been
  used in treeBoundBox), but might still need further revision.
This commit is contained in:
Mark Olesen
2017-02-01 12:15:00 +00:00
parent af4429f94c
commit 0ffae6461a
10 changed files with 60 additions and 102 deletions

View File

@ -720,7 +720,7 @@ void Foam::backgroundMeshDecomposition::buildPatchAndTree()
Pstream::scatterList(allBackgroundMeshBounds_); Pstream::scatterList(allBackgroundMeshBounds_);
// find global bounding box // find global bounding box
globalBackgroundBounds_ = treeBoundBox::invertedBox; globalBackgroundBounds_ = treeBoundBox(boundBox::invertedBox);
forAll(allBackgroundMeshBounds_, proci) forAll(allBackgroundMeshBounds_, proci)
{ {
globalBackgroundBounds_.add(allBackgroundMeshBounds_[proci]); globalBackgroundBounds_.add(allBackgroundMeshBounds_[proci]);

View File

@ -29,11 +29,17 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// (min,max) = (-VGREAT,+VGREAT) const Foam::boundBox Foam::boundBox::greatBox
const Foam::boundBox Foam::boundBox::greatBox(point::min, point::max); (
point::uniform(-ROOTVGREAT),
point::uniform(ROOTVGREAT)
);
// (min,max) = (+VGREAT,-VGREAT) const Foam::boundBox Foam::boundBox::invertedBox
const Foam::boundBox Foam::boundBox::invertedBox(point::max, point::min); (
point::uniform(ROOTVGREAT),
point::uniform(-ROOTVGREAT)
);
const Foam::faceList Foam::boundBox::faces const Foam::faceList Foam::boundBox::faces
({ ({
@ -47,25 +53,15 @@ const Foam::faceList Foam::boundBox::faces
}); });
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
void Foam::boundBox::calculate(const UList<point>& points, bool doReduce) Foam::boundBox::boundBox(const UList<point>& points, bool doReduce)
:
min_(invertedBox.min()),
max_(invertedBox.max())
{ {
if (points.empty())
{
if (doReduce && Pstream::parRun())
{
// Values that get overwritten by subsequent reduce operation
operator=(invertedBox);
}
}
else
{
operator=(invertedBox);
add(points); add(points);
}
// Parallel reduction
if (doReduce) if (doReduce)
{ {
reduce(); reduce();
@ -73,24 +69,17 @@ void Foam::boundBox::calculate(const UList<point>& points, bool doReduce)
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::boundBox::boundBox(const UList<point>& points, bool doReduce)
:
min_(Zero),
max_(Zero)
{
calculate(points, doReduce);
}
Foam::boundBox::boundBox(const tmp<pointField>& tpoints, bool doReduce) Foam::boundBox::boundBox(const tmp<pointField>& tpoints, bool doReduce)
: :
min_(Zero), min_(invertedBox.min()),
max_(Zero) max_(invertedBox.max())
{ {
calculate(tpoints(), doReduce); add(tpoints);
tpoints.clear();
if (doReduce)
{
reduce();
}
} }
@ -101,24 +90,11 @@ Foam::boundBox::boundBox
bool doReduce bool doReduce
) )
: :
min_(Zero), min_(invertedBox.min()),
max_(Zero) max_(invertedBox.max())
{ {
if (points.empty() || indices.empty())
{
if (doReduce && Pstream::parRun())
{
// Values that get overwritten by subsequent reduce operation
operator=(invertedBox);
}
}
else
{
operator=(invertedBox);
add(points, indices); add(points, indices);
}
// Parallel reduction
if (doReduce) if (doReduce)
{ {
reduce(); reduce();

View File

@ -27,6 +27,11 @@ Class
Description Description
A bounding box defined in terms of the points at its extremities. A bounding box defined in terms of the points at its extremities.
Note
When a bounding box is created without any points, it creates an inverted
bounding box. Points can be added later and the bounding box will grow to
include them.
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef boundBox_H #ifndef boundBox_H
@ -63,20 +68,14 @@ class boundBox
//- Minimum and maximum points describing the bounding box //- Minimum and maximum points describing the bounding box
point min_, max_; point min_, max_;
// Private Member Functions
//- Calculate the bounding box from the given points.
// Does parallel communication (doReduce = true)
void calculate(const UList<point>& points, bool doReduce = true);
public: public:
// Static data members // Static data members
//- A very large boundBox: min/max == -/+ VGREAT //- A large boundBox: min/max == -/+ ROOTVGREAT
static const boundBox greatBox; static const boundBox greatBox;
//- A very large inverted boundBox: min/max == +/- VGREAT //- A large inverted boundBox: min/max == +/- ROOTVGREAT
static const boundBox invertedBox; static const boundBox invertedBox;
//- Faces to point addressing, as per a 'hex' cell //- Faces to point addressing, as per a 'hex' cell
@ -85,7 +84,7 @@ public:
// Constructors // Constructors
//- Construct null, setting points to zero //- Construct without any points - an inverted bounding box
inline boundBox(); inline boundBox();
//- Construct a bounding box containing a single initial point //- Construct a bounding box containing a single initial point
@ -134,6 +133,9 @@ public:
//- Bounding box is inverted, contains no points. //- Bounding box is inverted, contains no points.
inline bool empty() const; inline bool empty() const;
//- Clear bounding box of all points - make it an inverted box
inline void clear();
//- Minimum describing the bounding box //- Minimum describing the bounding box
inline const point& min() const; inline const point& min() const;

View File

@ -30,8 +30,8 @@ License
inline Foam::boundBox::boundBox() inline Foam::boundBox::boundBox()
: :
min_(Zero), min_(invertedBox.min()),
max_(Zero) max_(invertedBox.max())
{} {}
@ -63,6 +63,13 @@ inline bool Foam::boundBox::empty() const
} }
inline void Foam::boundBox::clear()
{
min_ = invertedBox.min();
max_ = invertedBox.max();
}
inline const Foam::point& Foam::boundBox::min() const inline const Foam::point& Foam::boundBox::min() const
{ {
return min_; return min_;

View File

@ -36,25 +36,11 @@ Foam::boundBox::boundBox
bool doReduce bool doReduce
) )
: :
min_(Zero), min_(invertedBox.min()),
max_(Zero) max_(invertedBox.max())
{ {
// a FixedList is never empty
if (points.empty())
{
if (doReduce && Pstream::parRun())
{
// Values that get overwritten by subsequent reduce operation
operator=(invertedBox);
}
}
else
{
operator=(invertedBox);
add(points, indices); add(points, indices);
}
// Parallel reduction
if (doReduce) if (doReduce)
{ {
reduce(); reduce();

View File

@ -27,18 +27,6 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::treeBoundBox Foam::treeBoundBox::greatBox
(
point::uniform(-GREAT),
point::uniform(GREAT)
);
const Foam::treeBoundBox Foam::treeBoundBox::invertedBox
(
point::uniform(GREAT),
point::uniform(-GREAT)
);
const Foam::faceList Foam::treeBoundBox::faces const Foam::faceList Foam::treeBoundBox::faces
({ ({
face{0, 4, 6, 2}, // left face{0, 4, 6, 2}, // left

View File

@ -46,6 +46,11 @@ Description
For the front plane add 4 to the point labels. For the front plane add 4 to the point labels.
Note
When a bounding box is created without any points, it creates an inverted
bounding box. Points can be added later and the bounding box will grow to
include them.
SourceFiles SourceFiles
treeBoundBoxI.H treeBoundBoxI.H
treeBoundBox.C treeBoundBox.C
@ -93,12 +98,6 @@ public:
// Static data members // Static data members
//- As per boundBox::greatBox, but with GREAT instead of VGREAT
static const treeBoundBox greatBox;
//- As per boundBox::invertedBox, but with GREAT instead of VGREAT
static const treeBoundBox invertedBox;
//- Bits used for octant/point coding. //- Bits used for octant/point coding.
// Every octant/corner point is the combination of three faces. // Every octant/corner point is the combination of three faces.
enum octantBit enum octantBit

View File

@ -891,11 +891,11 @@ Foam::distributedTriSurfaceMesh::independentlyDistributedBbs
// Find bounding box for all triangles on new distribution. // Find bounding box for all triangles on new distribution.
// Initialise to inverted box (GREAT, -GREAT) // Initialise to inverted box
List<List<treeBoundBox>> bbs(Pstream::nProcs()); List<List<treeBoundBox>> bbs(Pstream::nProcs());
forAll(bbs, procI) forAll(bbs, procI)
{ {
bbs[procI].setSize(1, treeBoundBox::invertedBox); bbs[procI].setSize(1, treeBoundBox(boundBox::invertedBox));
} }
forAll(s, triI) forAll(s, triI)

View File

@ -69,7 +69,7 @@ void Foam::patchProbes::findElements(const fvMesh& mesh)
{ {
// Collect mesh faces and bounding box // Collect mesh faces and bounding box
labelList bndFaces(nFaces); labelList bndFaces(nFaces);
treeBoundBox overallBb(treeBoundBox::invertedBox); treeBoundBox overallBb(boundBox::invertedBox);
nFaces = 0; nFaces = 0;
forAll(patchIDs, i) forAll(patchIDs, i)

View File

@ -74,7 +74,7 @@ void Foam::patchCloudSet::calcSamples
labelList patchFaces(sz); labelList patchFaces(sz);
sz = 0; sz = 0;
treeBoundBox bb(treeBoundBox::invertedBox); treeBoundBox bb(boundBox::invertedBox);
forAllConstIter(labelHashSet, patchSet_, iter) forAllConstIter(labelHashSet, patchSet_, iter)
{ {
const polyPatch& pp = mesh().boundaryMesh()[iter.key()]; const polyPatch& pp = mesh().boundaryMesh()[iter.key()];