Commit 244b1dd2 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: minor consistency improvements for bounding box

- a valid() method (same as !empty() call) for consistency with other
  containers and data types

- a centre() method (same as midpoint() method) for consistency with
  other OpenFOAM geometric entities
parent ff6641be
......@@ -67,7 +67,7 @@ int main(int argc, char *argv[])
pointField newPoints(mesh.points());
const point half = meshBb.midpoint();
const point half = meshBb.centre();
forAll(newPoints, pointi)
{
......
......@@ -177,7 +177,7 @@ void Foam::backgroundMeshDecomposition::initialRefinement()
{
volumeStatus[celli] = volumeType::MIXED;
}
else if (geometry.inside(cellBb.midpoint()))
else if (geometry.inside(cellBb.centre()))
{
volumeStatus[celli] = volumeType::INSIDE;
}
......@@ -296,7 +296,7 @@ void Foam::backgroundMeshDecomposition::initialRefinement()
{
volumeStatus[celli] = volumeType::MIXED;
}
else if (geometry.inside(cellBb.midpoint()))
else if (geometry.inside(cellBb.centre()))
{
volumeStatus[celli] = volumeType::INSIDE;
}
......@@ -578,7 +578,7 @@ bool Foam::backgroundMeshDecomposition::refineCell
// hitInfo[i].hitPoint()
// );
//
// // Info<< "cellBb.midpoint() " << cellBb.midpoint() << nl
// // Info<< "cellBb.centre() " << cellBb.centre() << nl
// // << samplePoints[i] << nl
// // << hitInfo[i] << nl
// // << "cellBb.span() " << cellBb.span() << nl
......@@ -603,10 +603,9 @@ bool Foam::backgroundMeshDecomposition::refineCell
else if (volType == volumeType::INSIDE)
{
// scalar s =
// foamyHexMesh_.cellShapeControl_.cellSize(cellBb.midpoint());
// foamyHexMesh_.cellShapeControl_.cellSize(cellBb.centre());
// Estimate the number of points in the cell by the size at the cell
// midpoint
// Estimate number of points in cell by the size at the cell centre
// weightEstimate = cellBb.volume()/pow3(s);
return false;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -41,6 +41,7 @@ addToRunTimeSelectionTable
dictionary
);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::autoDensity::writeOBJ
......@@ -242,7 +243,7 @@ Foam::label Foam::autoDensity::recurseAndFill
}
}
}
else if (combinedInside(subBB.midpoint()))
else if (combinedInside(subBB.centre()))
{
if (debug)
{
......@@ -322,14 +323,14 @@ bool Foam::autoDensity::fillBox
// Check the nearest point on the surface to the box, if it is far
// enough away, then the surface sampling of the box can be skipped.
// Checking if the nearest piece of surface is at least 1.5*bb.span away
// from the bb.midpoint.
// from the bb.centre()
pointIndexHit surfHit;
label hitSurface;
geometry.findSurfaceNearest
(
bb.midpoint(),
bb.centre(),
2.25*magSqr(span),
surfHit,
hitSurface
......
......@@ -199,7 +199,7 @@ public:
////- Surface intersects bb (but not using intersection test)
//scalar ccDist = signedDistance(bb.midpoint());
//scalar ccDist = signedDistance(bb.centre());
//scalar ccVal = ccDist - _iso_val;
//if (mag(ccVal) < SMALL)
//{
......
......@@ -357,7 +357,7 @@ Foam::volumeType Foam::dynamicIndexedOctree<Type>::calcVolumeType
subType = volumeType
(
shapes_.getVolumeType(*this, subBb.midpoint())
shapes_.getVolumeType(*this, subBb.centre())
);
}
......
......@@ -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) 2016-2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -376,7 +376,7 @@ Foam::volumeType Foam::indexedOctree<Type>::calcVolumeType
// of its bounding box.
const treeBoundBox subBb = nod.bb_.subBbox(octant);
subType = shapes_.getVolumeType(*this, subBb.midpoint());
subType = shapes_.getVolumeType(*this, subBb.centre());
}
// Store octant type
......
......@@ -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) 2016-2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -146,7 +146,7 @@ Foam::tmp<Foam::pointField> Foam::boundBox::faceCentres() const
Foam::point Foam::boundBox::faceCentre(const direction facei) const
{
point pt = boundBox::midpoint();
point pt = boundBox::centre();
if (facei > 5)
{
......@@ -190,7 +190,7 @@ bool Foam::boundBox::intersect(const boundBox& bb)
min_ = ::Foam::max(min_, bb.min_);
max_ = ::Foam::min(max_, bb.max_);
return !empty();
return valid();
}
......
......@@ -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) 2016-2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -25,7 +25,7 @@ Class
Foam::boundBox
Description
A bounding box defined in terms of the points at its extremities.
A bounding box defined in terms of min/max extrema points.
Note
When a bounding box is created without any points, it creates an inverted
......@@ -133,8 +133,8 @@ 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();
//- Bounding box is non-inverted.
inline bool valid() const;
//- Minimum describing the bounding box
inline const point& min() const;
......@@ -148,7 +148,10 @@ public:
//- Maximum describing the bounding box, non-const access
inline point& max();
//- The midpoint of the bounding box
//- The centre (midpoint) of the bounding box
inline point centre() const;
//- The midpoint (centre) of the bounding box. Identical to centre()
inline point midpoint() const;
//- The bounding box span (from minimum to maximum)
......@@ -189,6 +192,9 @@ public:
// Manipulate
//- Clear bounding box and make it an inverted box
inline void clear();
//- Extend to include the second box.
inline void add(const boundBox& bb);
......@@ -231,6 +237,7 @@ public:
//- Parallel reduction of min/max values
void reduce();
// Query
//- Intersection (union) with the second box.
......
......@@ -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) 2016-2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -70,10 +70,18 @@ inline bool Foam::boundBox::empty() const
}
inline void Foam::boundBox::clear()
inline bool Foam::boundBox::valid() const
{
min_ = invertedBox.min();
max_ = invertedBox.max();
// Check each component for max < min
for (direction dir = 0; dir < vector::nComponents; ++dir)
{
if (max_[dir] < min_[dir])
{
return false;
}
}
return true;
}
......@@ -101,9 +109,15 @@ inline Foam::point& Foam::boundBox::max()
}
inline Foam::point Foam::boundBox::centre() const
{
return 0.5 * (min_ + max_);
}
inline Foam::point Foam::boundBox::midpoint() const
{
return 0.5 * (max_ + min_);
return this->centre();
}
......@@ -164,6 +178,13 @@ Foam::label Foam::boundBox::nDim() const
}
inline void Foam::boundBox::clear()
{
min_ = invertedBox.min();
max_ = invertedBox.max();
}
inline void Foam::boundBox::add(const boundBox& bb)
{
min_ = ::Foam::min(min_, bb.min_);
......@@ -248,9 +269,9 @@ inline bool Foam::boundBox::contains(const point& pt) const
{
return
(
pt.x() >= min_.x() && pt.x() <= max_.x()
&& pt.y() >= min_.y() && pt.y() <= max_.y()
&& pt.z() >= min_.z() && pt.z() <= max_.z()
min_.x() <= pt.x() && pt.x() <= max_.x()
&& min_.y() <= pt.y() && pt.y() <= max_.y()
&& min_.z() <= pt.z() && pt.z() <= max_.z()
);
}
......@@ -265,9 +286,9 @@ inline bool Foam::boundBox::containsInside(const point& pt) const
{
return
(
pt.x() > min_.x() && pt.x() < max_.x()
&& pt.y() > min_.y() && pt.y() < max_.y()
&& pt.z() > min_.z() && pt.z() < max_.z()
min_.x() < pt.x() && pt.x() < max_.x()
&& min_.y() < pt.y() && pt.y() < max_.y()
&& min_.z() < pt.z() && pt.z() < max_.z()
);
}
......
......@@ -72,14 +72,16 @@ void Foam::boundBox::add
const label len = points.size();
// Skip if points is empty
if (len)
if (!len)
{
return;
}
for (const label pointi : indices)
{
for (const label pointi : indices)
if (pointi >= 0 && pointi < len)
{
if (pointi >= 0 && pointi < len)
{
add(points[pointi]);
}
add(points[pointi]);
}
}
}
......@@ -95,14 +97,16 @@ void Foam::boundBox::add
const label len = points.size();
// Skip if points is empty
if (len)
if (!len)
{
return;
}
for (const label pointi : indices)
{
for (const label pointi : indices)
if (pointi >= 0 && pointi < len)
{
if (pointi >= 0 && pointi < len)
{
add(points[pointi]);
}
add(points[pointi]);
}
}
}
......
......@@ -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) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -63,10 +63,7 @@ Foam::treeBoundBox::treeBoundBox(const UList<point>& points)
if (points.empty())
{
WarningInFunction
<< "cannot find bounding box for zero-sized pointField, "
<< "returning zero" << endl;
return;
<< "No bounding box for zero-sized pointField" << nl;
}
}
......@@ -82,10 +79,7 @@ Foam::treeBoundBox::treeBoundBox
if (points.empty() || indices.empty())
{
WarningInFunction
<< "cannot find bounding box for zero-sized pointField, "
<< "returning zero" << endl;
return;
<< "No bounding box for zero-sized pointField" << nl;
}
}
......@@ -108,7 +102,7 @@ Foam::tmp<Foam::pointField> Foam::treeBoundBox::points() const
Foam::treeBoundBox Foam::treeBoundBox::subBbox(const direction octant) const
{
return subBbox(midpoint(), octant);
return subBbox(centre(), octant);
}
......
......@@ -25,7 +25,7 @@ Class
Foam::treeBoundBox
Description
Standard boundBox + extra functionality for use in octree.
Standard boundBox with extra functionality for use in octree.
Numbering of corner points is according to octant numbering.
......@@ -153,7 +153,7 @@ public:
// Constructors
//- Construct null setting points to zero
//- Construct without any points - an inverted bounding box
inline treeBoundBox();
//- Construct from a boundBox
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -80,7 +80,7 @@ inline Foam::point Foam::treeBoundBox::corner(const direction octant) const
// Returns octant in which point resides. Reverse of subBbox.
inline Foam::direction Foam::treeBoundBox::subOctant(const point& pt) const
{
return subOctant(midpoint(), pt);
return subOctant(centre(), pt);
}
......@@ -121,7 +121,7 @@ inline Foam::direction Foam::treeBoundBox::subOctant
bool& onEdge
) const
{
return subOctant(midpoint(), pt, onEdge);
return subOctant(centre(), pt, onEdge);
}
......@@ -234,7 +234,7 @@ inline void Foam::treeBoundBox::searchOrder
FixedList<direction,8>& octantOrder
) const
{
vector dist = midpoint() - pt;
vector dist = centre() - pt;
direction octant = 0;
......
......@@ -41,10 +41,7 @@ Foam::treeBoundBox::treeBoundBox
if (points.empty())
{
WarningInFunction
<< "cannot find bounding box for zero-sized pointField, "
<< "returning zero" << endl;
return;
<< "No bounding box for zero-sized pointField" << nl;
}
}
......
......@@ -351,7 +351,7 @@ void Foam::lumpedPointMovement::setBoundBox
if (autoCentre_)
{
centre_ = boundBox_.midpoint();
centre_ = boundBox_.centre();
centre_ -= (centre_ & axis_) * axis_;
if (lumpedPointIOMovement::debug)
{
......
......@@ -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) 2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -183,11 +183,12 @@ Foam::searchableBox::searchableBox
searchableSurface(io),
treeBoundBox(bb)
{
if (!contains(midpoint()))
if (!treeBoundBox::valid())
{
FatalErrorInFunction
<< "Illegal bounding box specification : "
<< static_cast<const treeBoundBox>(*this) << exit(FatalError);
<< static_cast<const treeBoundBox>(*this) << nl
<< exit(FatalError);
}
bounds() = static_cast<boundBox>(*this);
......@@ -203,11 +204,12 @@ Foam::searchableBox::searchableBox
searchableSurface(io),
treeBoundBox(dict.get<point>("min"), dict.get<point>("max"))
{
if (!contains(midpoint()))
if (!treeBoundBox::valid())
{
FatalErrorInFunction
<< "Illegal bounding box specification : "
<< static_cast<const treeBoundBox>(*this) << exit(FatalError);
<< static_cast<const treeBoundBox>(*this) << nl
<< exit(FatalError);
}
bounds() = static_cast<boundBox>(*this);
......@@ -291,7 +293,7 @@ Foam::pointIndexHit Foam::searchableBox::findNearest
const scalar nearestDistSqr
) const
{
return findNearest(midpoint(), sample, nearestDistSqr);
return findNearest(centre(), sample, nearestDistSqr);
}
......@@ -301,7 +303,7 @@ Foam::pointIndexHit Foam::searchableBox::findNearestOnEdge
const scalar nearestDistSqr
) const
{
const point bbMid(midpoint());
const point bbMid(centre());
// Outside point projected onto cube. Assume faces 0..5.
pointIndexHit info(true, sample, -1);
......@@ -459,7 +461,7 @@ void Foam::searchableBox::findNearest
{
info.setSize(samples.size());
const point bbMid(midpoint());
const point bbMid(centre());
forAll(samples, i)
{
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -87,7 +87,7 @@ Foam::searchableExtrudedCircle::searchableExtrudedCircle
bounds() = boundBox(points, false);
vector halfSpan(0.5*bounds().span());
point ctr(bounds().midpoint());
point ctr(bounds().centre());
bounds().min() = ctr - mag(halfSpan) * vector::one;
bounds().max() = ctr + mag(halfSpan) * vector::one;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -195,7 +195,7 @@ void Foam::pointToPointPlanarInterpolation::calcWeights
auto& localVertices = tlocalVertices.ref();
const boundBox bb(localVertices, true);
const point bbMid(bb.midpoint());
const point bbMid(bb.centre());
if (debug)
{
......
......@@ -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-2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -1985,7 +1985,7 @@ Foam::triSurface Foam::distributedTriSurfaceMesh::overlappingSurface
const scalar eps = 1.0e-4;
forAll(bbs, i)
{
const point mid = bbs[i].midpoint();
const point mid = bbs[i].centre();
const vector halfSpan = (1.0+eps)*(bbs[i].max() - mid);
bbsX[i].min() = mid - halfSpan;
......
......@@ -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) 2016-2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -53,7 +53,7 @@ void Foam::sampledCuttingPlane::checkBoundsIntersection
) const
{
// Verify specified bounding box
if (!bounds_.empty())
if (bounds_.valid())
{
// Bounding box does not overlap with (global) mesh!