ENH: additional methods/operators for boundBox (related to #196)

- Constructor for bounding box of a single point.

- add(boundBox), add(point) ...
  -> Extend box to enclose the second box or point(s).

  Eg,
      bb.add(pt);
  vs.
      bb.min() = Foam::min(bb.min(), pt);
      bb.max() = Foam::max(bb.max(), pt);

Also works with other bounding boxes.
  Eg,
      bb.add(bb2);
      // OR
      bb += bb2;
  vs.
      bb.min() = Foam::min(bb.min(), bb2.min());
      bb.max() = Foam::max(bb.max(), bb2.max());

'+=' operator allows the reduction to be used in parallel
gather/scatter operations.

A global '+' operator is not currently needed.

Note: may be useful in the future to have a 'clear()' method
that resets to a zero-sized (inverted) box.

STYLE: make many bounding box constructors explicit
This commit is contained in:
Mark Olesen
2017-01-25 19:26:50 +01:00
parent 17d76e6261
commit 722d23f59c
31 changed files with 443 additions and 420 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -198,10 +198,10 @@ void Foam::AABBTree<Type>::createBoxes
// Assign the objects to min or max bin
DynamicList<label> minBinObjectIDs(objectIDs.size());
treeBoundBox minBb(point::max, point::min);
treeBoundBox minBb(boundBox::invertedBox);
DynamicList<label> maxBinObjectIDs(objectIDs.size());
treeBoundBox maxBb(point::max, point::min);
treeBoundBox maxBb(boundBox::invertedBox);
forAll(objectIDs, i)
{
@ -229,16 +229,12 @@ void Foam::AABBTree<Type>::createBoxes
if (intoMin)
{
minBinObjectIDs.append(objI);
const boundBox objBb(points, obj, false);
minBb.min() = min(minBb.min(), objBb.min());
minBb.max() = max(minBb.max(), objBb.max());
minBb.add(points, obj);
}
if (intoMax)
{
maxBinObjectIDs.append(objI);
const boundBox objBb(points, obj, false);
maxBb.min() = min(maxBb.min(), objBb.min());
maxBb.max() = max(maxBb.max(), objBb.max());
maxBb.add(points, obj);
}
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -41,20 +41,7 @@ namespace Foam
Foam::treeBoundBox Foam::treeDataFace::calcBb(const label facei) const
{
const pointField& points = mesh_.points();
const face& f = mesh_.faces()[facei];
treeBoundBox bb(points[f[0]], points[f[0]]);
for (label fp = 1; fp < f.size(); fp++)
{
const point& p = points[f[fp]];
bb.min() = min(bb.min(), p);
bb.max() = max(bb.max(), p);
}
return bb;
return treeBoundBox(mesh_.points(), mesh_.faces()[facei]);
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -31,26 +31,6 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class PatchType>
Foam::treeBoundBox Foam::treeDataPrimitivePatch<PatchType>::calcBb
(
const pointField& points,
const face& f
)
{
treeBoundBox bb(points[f[0]], points[f[0]]);
for (label fp = 1; fp < f.size(); fp++)
{
const point& p = points[f[fp]];
bb.min() = min(bb.min(), p);
bb.max() = max(bb.max(), p);
}
return bb;
}
template<class PatchType>
void Foam::treeDataPrimitivePatch<PatchType>::update()
{
@ -60,7 +40,7 @@ void Foam::treeDataPrimitivePatch<PatchType>::update()
forAll(patch_, i)
{
bbs_[i] = calcBb(patch_.points(), patch_[i]);
bbs_[i] = treeBoundBox(patch_.points(), patch_[i]);
}
}
}
@ -386,19 +366,14 @@ bool Foam::treeDataPrimitivePatch<PatchType>::overlaps
) const
{
// 1. Quick rejection: bb does not intersect face bb at all
if (cacheBb_)
if
(
cacheBb_
? !cubeBb.overlaps(bbs_[index])
: !cubeBb.overlaps(treeBoundBox(patch_.points(), patch_[index]))
)
{
if (!cubeBb.overlaps(bbs_[index]))
{
return false;
}
}
else
{
if (!cubeBb.overlaps(calcBb(patch_.points(), patch_[index])))
{
return false;
}
return false;
}
@ -459,19 +434,14 @@ bool Foam::treeDataPrimitivePatch<PatchType>::overlaps
) const
{
// 1. Quick rejection: sphere does not intersect face bb at all
if (cacheBb_)
if
(
cacheBb_
? !bbs_[index].overlaps(centre, radiusSqr)
: !treeBoundBox(patch_.points(),patch_[index]).overlaps(centre, radiusSqr)
)
{
if (!bbs_[index].overlaps(centre, radiusSqr))
{
return false;
}
}
else
{
if (!calcBb(patch_.points(), patch_[index]).overlaps(centre, radiusSqr))
{
return false;
}
return false;
}
const pointField& points = patch_.points();

View File

@ -80,9 +80,6 @@ class treeDataPrimitivePatch
// Private Member Functions
//- Calculate face bounding box
static treeBoundBox calcBb(const pointField&, const face&);
//- Initialise all member data
void update();

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -244,8 +244,8 @@ Foam::searchableSurfaceCollection::searchableSurfaceCollection
subGeom_.setSize(surfI);
indexOffset_.setSize(surfI+1);
// Bounds is the overall bounds
bounds() = boundBox(point::max, point::min);
// Bounds is the overall bounds - prepare for min/max ops
bounds() = boundBox::invertedBox;
forAll(subGeom_, surfI)
{

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -659,18 +659,14 @@ Foam::boundBox Foam::searchableSurfacesQueries::bounds
const labelList& surfacesToTest
)
{
pointField bbPoints(2*surfacesToTest.size());
boundBox bb(boundBox::invertedBox);
forAll(surfacesToTest, testI)
forAll(surfacesToTest, testi)
{
const searchableSurface& surface(allSurfaces[surfacesToTest[testI]]);
bbPoints[2*testI] = surface.bounds().min();
bbPoints[2*testI + 1] = surface.bounds().max();
bb.add(allSurfaces[surfacesToTest[testi]].bounds());
}
return boundBox(bbPoints);
return bb;
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -55,13 +55,9 @@ Foam::treeBoundBox Foam::tetOverlapVolume::pyrBb
const point& fc
)
{
treeBoundBox bb(fc, fc);
forAll(f, fp)
{
const point& pt = points[f[fp]];
bb.min() = min(bb.min(), pt);
bb.max() = max(bb.max(), pt);
}
treeBoundBox bb(fc);
bb.add(points, f);
return bb;
}