mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -720,7 +720,7 @@ void Foam::backgroundMeshDecomposition::buildPatchAndTree()
|
||||
Pstream::scatterList(allBackgroundMeshBounds_);
|
||||
|
||||
// find global bounding box
|
||||
globalBackgroundBounds_ = treeBoundBox::invertedBox;
|
||||
globalBackgroundBounds_ = treeBoundBox(boundBox::invertedBox);
|
||||
forAll(allBackgroundMeshBounds_, proci)
|
||||
{
|
||||
globalBackgroundBounds_.add(allBackgroundMeshBounds_[proci]);
|
||||
|
||||
@ -29,11 +29,17 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
// (min,max) = (-VGREAT,+VGREAT)
|
||||
const Foam::boundBox Foam::boundBox::greatBox(point::min, point::max);
|
||||
const Foam::boundBox Foam::boundBox::greatBox
|
||||
(
|
||||
point::uniform(-ROOTVGREAT),
|
||||
point::uniform(ROOTVGREAT)
|
||||
);
|
||||
|
||||
// (min,max) = (+VGREAT,-VGREAT)
|
||||
const Foam::boundBox Foam::boundBox::invertedBox(point::max, point::min);
|
||||
const Foam::boundBox Foam::boundBox::invertedBox
|
||||
(
|
||||
point::uniform(ROOTVGREAT),
|
||||
point::uniform(-ROOTVGREAT)
|
||||
);
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
:
|
||||
min_(Zero),
|
||||
max_(Zero)
|
||||
min_(invertedBox.min()),
|
||||
max_(invertedBox.max())
|
||||
{
|
||||
calculate(tpoints(), doReduce);
|
||||
tpoints.clear();
|
||||
add(tpoints);
|
||||
|
||||
if (doReduce)
|
||||
{
|
||||
reduce();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -101,24 +90,11 @@ Foam::boundBox::boundBox
|
||||
bool doReduce
|
||||
)
|
||||
:
|
||||
min_(Zero),
|
||||
max_(Zero)
|
||||
min_(invertedBox.min()),
|
||||
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)
|
||||
{
|
||||
reduce();
|
||||
|
||||
@ -27,6 +27,11 @@ Class
|
||||
Description
|
||||
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
|
||||
@ -63,20 +68,14 @@ class boundBox
|
||||
//- Minimum and maximum points describing the bounding box
|
||||
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:
|
||||
|
||||
// Static data members
|
||||
|
||||
//- A very large boundBox: min/max == -/+ VGREAT
|
||||
//- A large boundBox: min/max == -/+ ROOTVGREAT
|
||||
static const boundBox greatBox;
|
||||
|
||||
//- A very large inverted boundBox: min/max == +/- VGREAT
|
||||
//- A large inverted boundBox: min/max == +/- ROOTVGREAT
|
||||
static const boundBox invertedBox;
|
||||
|
||||
//- Faces to point addressing, as per a 'hex' cell
|
||||
@ -85,7 +84,7 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null, setting points to zero
|
||||
//- Construct without any points - an inverted bounding box
|
||||
inline boundBox();
|
||||
|
||||
//- Construct a bounding box containing a single initial point
|
||||
@ -134,6 +133,9 @@ public:
|
||||
//- Bounding box is inverted, contains no points.
|
||||
inline bool empty() const;
|
||||
|
||||
//- Clear bounding box of all points - make it an inverted box
|
||||
inline void clear();
|
||||
|
||||
//- Minimum describing the bounding box
|
||||
inline const point& min() const;
|
||||
|
||||
|
||||
@ -30,8 +30,8 @@ License
|
||||
|
||||
inline Foam::boundBox::boundBox()
|
||||
:
|
||||
min_(Zero),
|
||||
max_(Zero)
|
||||
min_(invertedBox.min()),
|
||||
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
|
||||
{
|
||||
return min_;
|
||||
|
||||
@ -36,25 +36,11 @@ Foam::boundBox::boundBox
|
||||
bool doReduce
|
||||
)
|
||||
:
|
||||
min_(Zero),
|
||||
max_(Zero)
|
||||
min_(invertedBox.min()),
|
||||
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)
|
||||
{
|
||||
reduce();
|
||||
|
||||
@ -27,18 +27,6 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * 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
|
||||
({
|
||||
face{0, 4, 6, 2}, // left
|
||||
|
||||
@ -46,6 +46,11 @@ Description
|
||||
|
||||
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
|
||||
treeBoundBoxI.H
|
||||
treeBoundBox.C
|
||||
@ -93,12 +98,6 @@ public:
|
||||
|
||||
// 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.
|
||||
// Every octant/corner point is the combination of three faces.
|
||||
enum octantBit
|
||||
|
||||
@ -891,11 +891,11 @@ Foam::distributedTriSurfaceMesh::independentlyDistributedBbs
|
||||
|
||||
// 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());
|
||||
forAll(bbs, procI)
|
||||
{
|
||||
bbs[procI].setSize(1, treeBoundBox::invertedBox);
|
||||
bbs[procI].setSize(1, treeBoundBox(boundBox::invertedBox));
|
||||
}
|
||||
|
||||
forAll(s, triI)
|
||||
|
||||
@ -69,7 +69,7 @@ void Foam::patchProbes::findElements(const fvMesh& mesh)
|
||||
{
|
||||
// Collect mesh faces and bounding box
|
||||
labelList bndFaces(nFaces);
|
||||
treeBoundBox overallBb(treeBoundBox::invertedBox);
|
||||
treeBoundBox overallBb(boundBox::invertedBox);
|
||||
|
||||
nFaces = 0;
|
||||
forAll(patchIDs, i)
|
||||
|
||||
@ -74,7 +74,7 @@ void Foam::patchCloudSet::calcSamples
|
||||
|
||||
labelList patchFaces(sz);
|
||||
sz = 0;
|
||||
treeBoundBox bb(treeBoundBox::invertedBox);
|
||||
treeBoundBox bb(boundBox::invertedBox);
|
||||
forAllConstIter(labelHashSet, patchSet_, iter)
|
||||
{
|
||||
const polyPatch& pp = mesh().boundaryMesh()[iter.key()];
|
||||
|
||||
Reference in New Issue
Block a user