added static data boundBox::greatBox and boundBox::invertedBox

- boundBox::invertedBox is useful for initializing our own calculations
- NOTE treeBoundBox::greatBox is still in place, since it uses GREAT
  instead of VGREAT. If this is only historical, we can drop it.
This commit is contained in:
Mark Olesen
2008-11-22 11:15:20 +01:00
parent 99eea2d52e
commit d6b247a3b1
11 changed files with 95 additions and 101 deletions

View File

@ -214,7 +214,7 @@ Foam::label Foam::checkTopology
const pointField& pts = pp.points(); const pointField& pts = pp.points();
const labelList& mp = pp.meshPoints(); const labelList& mp = pp.meshPoints();
boundBox bb(vector::zero, vector::zero); boundBox bb; // zero-sized
if (returnReduce(mp.size(), sumOp<label>()) > 0) if (returnReduce(mp.size(), sumOp<label>()) > 0)
{ {
bb.min() = pts[mp[0]]; bb.min() = pts[mp[0]];

View File

@ -418,11 +418,7 @@ int main(int argc, char *argv[])
// Read point on individual processors to determine merge tolerance // Read point on individual processors to determine merge tolerance
// (otherwise single cell domains might give problems) // (otherwise single cell domains might give problems)
boundBox bb boundBox bb = boundBox::invertedBox;
(
point(GREAT, GREAT, GREAT),
point(-GREAT, -GREAT, -GREAT)
);
for (label procI = 0; procI < nProcs; procI++) for (label procI = 0; procI < nProcs; procI++)
{ {

View File

@ -27,24 +27,40 @@ License
#include "boundBox.H" #include "boundBox.H"
#include "PstreamReduceOps.H" #include "PstreamReduceOps.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::boundBox Foam::boundBox::greatBox
(
point(-VGREAT, -VGREAT, -VGREAT),
point(VGREAT, VGREAT, VGREAT)
);
const Foam::boundBox Foam::boundBox::invertedBox
(
point(VGREAT, VGREAT, VGREAT),
point(-VGREAT, -VGREAT, -VGREAT)
);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::boundBox::boundBox(const pointField& points, const bool doReduce) Foam::boundBox::boundBox(const pointField& points, const bool doReduce)
: :
min_(vector::zero), min_(point::zero),
max_(vector::zero) max_(point::zero)
{ {
if (points.size() == 0) if (points.size() == 0)
{ {
if (Pstream::parRun() && doReduce) if (Pstream::parRun() && doReduce)
{ {
// Use values which get overwritten by reduce minOp,maxOp below // Use values that get overwritten by reduce minOp, maxOp below
min_ = point(VGREAT, VGREAT, VGREAT); min_ = point(VGREAT, VGREAT, VGREAT);
max_ = point(-VGREAT, -VGREAT, -VGREAT); max_ = point(-VGREAT, -VGREAT, -VGREAT);
} }
else else
{ {
WarningIn("boundBox::boundBox(const pointField& points)") WarningIn("boundBox::boundBox(const pointField&)")
<< "Cannot find bounding box for zero sized pointField, " << "Cannot find bounding box for zero sized pointField, "
"returning zero" "returning zero"
<< endl; << endl;
@ -98,7 +114,6 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const boundBox& bb)
// Check state of Ostream // Check state of Ostream
os.check("Ostream& operator<<(Ostream&, const boundBox&)"); os.check("Ostream& operator<<(Ostream&, const boundBox&)");
return os; return os;
} }
@ -120,7 +135,6 @@ Foam::Istream& Foam::operator>>(Istream& is, boundBox& bb)
// Check state of Istream // Check state of Istream
is.check("Istream& operator>>(Istream&, boundBox&)"); is.check("Istream& operator>>(Istream&, boundBox&)");
return is; return is;
} }

View File

@ -48,7 +48,7 @@ Ostream& operator<<(Ostream& os, const boundBox& b);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class boundBox Declaration Class boundBox Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class boundBox class boundBox
@ -61,13 +61,22 @@ class boundBox
public: public:
// Static data members
//- A very large boundBox: min/max == -/+ VGREAT
static const boundBox greatBox;
//- A very large inverted boundBox: min/max == +/- VGREAT
static const boundBox invertedBox;
// Constructors // Constructors
//- Construct null setting points to zero //- Construct null, setting points to zero
boundBox() boundBox()
: :
min_(vector::zero), min_(point::zero),
max_(vector::zero) max_(point::zero)
{} {}
//- Construct from components //- Construct from components
@ -77,8 +86,8 @@ public:
max_(max) max_(max)
{} {}
//- Construct as the bounding box of the given pointField. Does //- Construct as the bounding box of the given pointField.
// parallel communication (doReduce = true) // Does parallel communication (doReduce = true)
boundBox(const pointField& points, const bool doReduce = true); boundBox(const pointField& points, const bool doReduce = true);
//- Construct from Istream //- Construct from Istream
@ -117,39 +126,26 @@ public:
// Query // Query
//- Intersects other boundingbox? //- Intersects other boundingBox?
bool overlaps(const boundBox& bb) const bool overlaps(const boundBox& bb) const
{ {
if return
( (
(min_.x() <= bb.max().x()) && min_.x() <= bb.max().x() && max_.x() >= bb.min().x()
(min_.y() <= bb.max().y()) && && min_.y() <= bb.max().y() && max_.y() >= bb.min().y()
(min_.z() <= bb.max().z()) && && min_.z() <= bb.max().z() && max_.z() >= bb.min().z()
);
(max_.x() >= bb.min().x()) &&
(max_.y() >= bb.min().y()) &&
(max_.z() >= bb.min().z())
)
{
return true;
}
else
{
return false;
}
} }
//- Contains a point? //- Contains a point?
bool contains(const point& pt) const bool contains(const point& pt) const
{ {
return return
pt.x() >= min().x() (
&& pt.y() >= min().y() pt.x() >= min().x() && pt.x() <= max().x()
&& pt.z() >= min().z() && pt.y() >= min().y() && pt.y() <= max().y()
&& pt.x() <= max().x() && pt.z() >= min().z() && pt.z() <= max().z()
&& pt.y() <= max().y() );
&& pt.z() <= max().z();
} }
@ -173,7 +169,7 @@ public:
}; };
//- Specify data associated with boundBox type is contiguous //- Specify data associated with boundBox type are contiguous
template<> template<>
inline bool contiguous<boundBox>() {return contiguous<point>();} inline bool contiguous<boundBox>() {return contiguous<point>();}

View File

@ -96,11 +96,7 @@ Foam::scalar Foam::autoHexMeshDriver::getMergeDistance(const scalar mergeTol)
//) //)
//{ //{
// // Determine outside point. // // Determine outside point.
// boundBox overallBb // boundBox overallBb = boundBox::invertedBox;
// (
// point(GREAT, GREAT, GREAT),
// point(-GREAT, -GREAT, -GREAT)
// );
// //
// bool hasSurface = false; // bool hasSurface = false;
// //

View File

@ -158,11 +158,7 @@ void Foam::shellSurfaces::setAndCheckLevels
void Foam::shellSurfaces::orient() void Foam::shellSurfaces::orient()
{ {
// Determine outside point. // Determine outside point.
boundBox overallBb boundBox overallBb = boundBox::invertedBox;
(
point(GREAT, GREAT, GREAT),
point(-GREAT, -GREAT, -GREAT)
);
bool hasSurface = false; bool hasSurface = false;

View File

@ -110,8 +110,10 @@ Foam::treeBoundBox::treeBoundBox(const UList<point>& points)
{ {
if (points.size() == 0) if (points.size() == 0)
{ {
WarningIn("treeBoundBox::treeBoundBox(const UList<point>&)") WarningIn
<< "cannot find bounding box for zero sized pointField" (
"treeBoundBox::treeBoundBox(const UList<point>&)"
) << "cannot find bounding box for zero-sized pointField"
<< "returning zero" << endl; << "returning zero" << endl;
return; return;
@ -132,17 +134,18 @@ Foam::treeBoundBox::treeBoundBox(const UList<point>& points)
Foam::treeBoundBox::treeBoundBox Foam::treeBoundBox::treeBoundBox
( (
const UList<point>& points, const UList<point>& points,
const labelList& meshPoints const UList<label>& meshPoints
) )
: :
boundBox() boundBox()
{ {
if (meshPoints.size() == 0) if (points.size() == 0 || meshPoints.size() == 0)
{ {
WarningIn WarningIn
( (
"treeBoundBox::treeBoundBox(const UList<point>&, const labelList)" "treeBoundBox::treeBoundBox"
) << "cannot find bounding box for zero sized pointField" "(const UList<point>&, const UList<label>&)"
) << "cannot find bounding box for zero-sized pointField"
<< "returning zero" << endl; << "returning zero" << endl;
return; return;

View File

@ -87,6 +87,7 @@ public:
// Static data members // Static data members
//- As per boundBox::greatBox, but with GREAT instead of VGREAT
static const treeBoundBox greatBox; static const treeBoundBox greatBox;
//- Bits used for octant/point coding. Every octant/corner point //- Bits used for octant/point coding. Every octant/corner point
@ -171,7 +172,7 @@ public:
treeBoundBox(const UList<point>& points); treeBoundBox(const UList<point>& points);
//- Construct as subset of points //- Construct as subset of points
treeBoundBox(const UList<point>&, const labelList& meshPoints); treeBoundBox(const UList<point>&, const UList<label>& meshPoints);
//- Construct from Istream //- Construct from Istream
treeBoundBox(Istream&); treeBoundBox(Istream&);

View File

@ -27,29 +27,21 @@ License
#include "treeBoundBox.H" #include "treeBoundBox.H"
#include "Random.H" #include "Random.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct null setting points to zero inline Foam::treeBoundBox::treeBoundBox()
inline treeBoundBox::treeBoundBox()
: :
boundBox() boundBox()
{} {}
// Construct from components inline Foam::treeBoundBox::treeBoundBox(const point& min, const point& max)
inline treeBoundBox::treeBoundBox(const point& min, const point& max)
: :
boundBox(min, max) boundBox(min, max)
{} {}
// Construct from components inline Foam::treeBoundBox::treeBoundBox(const boundBox& bb)
inline treeBoundBox::treeBoundBox(const boundBox& bb)
: :
boundBox(bb) boundBox(bb)
{} {}
@ -57,7 +49,7 @@ inline treeBoundBox::treeBoundBox(const boundBox& bb)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline scalar treeBoundBox::minDim() const inline Foam::scalar Foam::treeBoundBox::minDim() const
{ {
return ::Foam::min return ::Foam::min
( (
@ -71,7 +63,7 @@ inline scalar treeBoundBox::minDim() const
} }
inline scalar treeBoundBox::maxDim() const inline Foam::scalar Foam::treeBoundBox::maxDim() const
{ {
return ::Foam::max return ::Foam::max
( (
@ -85,7 +77,7 @@ inline scalar treeBoundBox::maxDim() const
} }
inline scalar treeBoundBox::avgDim() const inline Foam::scalar Foam::treeBoundBox::avgDim() const
{ {
return return
( (
@ -96,19 +88,19 @@ inline scalar treeBoundBox::avgDim() const
} }
inline scalar treeBoundBox::typDim() const inline Foam::scalar Foam::treeBoundBox::typDim() const
{ {
return avgDim(); return avgDim();
} }
inline point treeBoundBox::mid() const inline Foam::point Foam::treeBoundBox::mid() const
{ {
return 0.5*(min() + max()); return 0.5*(min() + max());
} }
inline point treeBoundBox::corner(const direction octant) const inline Foam::point Foam::treeBoundBox::corner(const direction octant) const
{ {
return point return point
( (
@ -119,7 +111,7 @@ inline point treeBoundBox::corner(const direction octant) const
} }
// Returns octant in which sample resides. Reverse of subBbox. // Returns octant in which sample resides. Reverse of subBbox.
inline direction treeBoundBox::subOctant(const point& sample) const inline Foam::direction Foam::treeBoundBox::subOctant(const point& sample) const
{ {
point mid = 0.5*(max() + min()); point mid = 0.5*(max() + min());
@ -146,7 +138,7 @@ inline direction treeBoundBox::subOctant(const point& sample) const
// Returns octant in which sample resides. Reverse of subBbox. Precalculated // Returns octant in which sample resides. Reverse of subBbox. Precalculated
// midpoint // midpoint
inline direction treeBoundBox::subOctant inline Foam::direction Foam::treeBoundBox::subOctant
( (
const point& mid, const point& mid,
const point& sample const point& sample
@ -175,8 +167,11 @@ inline direction treeBoundBox::subOctant
// Returns octant in which sample resides. Reverse of subBbox. Flags sample // Returns octant in which sample resides. Reverse of subBbox. Flags sample
// exactly on edge. // exactly on edge.
inline direction treeBoundBox::subOctant(const point& sample, bool& onEdge) inline Foam::direction Foam::treeBoundBox::subOctant
const (
const point& sample,
bool& onEdge
) const
{ {
point mid = 0.5*(max() + min()); point mid = 0.5*(max() + min());
@ -216,7 +211,7 @@ inline direction treeBoundBox::subOctant(const point& sample, bool& onEdge)
// Returns octant in which sample resides. Reverse of subBbox. Precalculated // Returns octant in which sample resides. Reverse of subBbox. Precalculated
// midpoint // midpoint
inline direction treeBoundBox::subOctant inline Foam::direction Foam::treeBoundBox::subOctant
( (
const point& mid, const point& mid,
const point& sample, const point& sample,
@ -261,7 +256,7 @@ inline direction treeBoundBox::subOctant
// Precalculated midpoint. If the sample is on the dividing line between // Precalculated midpoint. If the sample is on the dividing line between
// the octants the direction vector determines which octant to use // the octants the direction vector determines which octant to use
// (i.e. in which octant the sample would be if it were moved along dir) // (i.e. in which octant the sample would be if it were moved along dir)
inline direction treeBoundBox::subOctant inline Foam::direction Foam::treeBoundBox::subOctant
( (
const point& mid, const point& mid,
const vector& dir, const vector& dir,
@ -321,7 +316,7 @@ inline direction treeBoundBox::subOctant
// Returns reference to octantOrder which defines the // Returns reference to octantOrder which defines the
// order to do the search. // order to do the search.
inline void treeBoundBox::searchOrder inline void Foam::treeBoundBox::searchOrder
( (
const point& sample, const point& sample,
FixedList<direction,8>& octantOrder FixedList<direction,8>& octantOrder
@ -412,13 +407,13 @@ inline void treeBoundBox::searchOrder
// true if bb's intersect or overlap. // true if bb's intersect or overlap.
// Note: <= to make sure we catch all. // Note: <= to make sure we catch all.
inline bool treeBoundBox::overlaps(const treeBoundBox& bb) const inline bool Foam::treeBoundBox::overlaps(const treeBoundBox& bb) const
{ {
return boundBox::overlaps(bb); return boundBox::overlaps(bb);
} }
inline bool treeBoundBox::contains(const point& sample) const inline bool Foam::treeBoundBox::contains(const point& sample) const
{ {
return return
( (
@ -433,7 +428,11 @@ inline bool treeBoundBox::contains(const point& sample) const
//- Return slightly wider bounding box //- Return slightly wider bounding box
inline treeBoundBox treeBoundBox::extend(Random& rndGen, const scalar s) const inline Foam::treeBoundBox Foam::treeBoundBox::extend
(
Random& rndGen,
const scalar s
) const
{ {
treeBoundBox bb(*this); treeBoundBox bb(*this);
@ -456,6 +455,4 @@ inline treeBoundBox treeBoundBox::extend(Random& rndGen, const scalar s) const
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -776,8 +776,7 @@ void Foam::distributedTriSurfaceMesh::calcBounds
pointIsUsed = 0U; pointIsUsed = 0U;
nPoints = 0; nPoints = 0;
bb.min() = point(VGREAT, VGREAT, VGREAT); bb = boundBox::invertedBox;
bb.max() = point(-VGREAT, -VGREAT, -VGREAT);
const triSurface& s = static_cast<const triSurface&>(*this); const triSurface& s = static_cast<const triSurface&>(*this);

View File

@ -1213,11 +1213,7 @@ void Foam::triSurface::writeStats(Ostream& os) const
pointIsUsed = 0U; pointIsUsed = 0U;
label nPoints = 0; label nPoints = 0;
boundBox bb boundBox bb = boundBox::invertedBox;
(
point(VGREAT, VGREAT, VGREAT),
point(-VGREAT, -VGREAT, -VGREAT)
);
forAll(*this, triI) forAll(*this, triI)
{ {