mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Construct bounding box as subset of the pointField.
STYLE: move inline functions into boundBoxI.H STYLE: reduce duplicate methods in treeBoundBox
This commit is contained in:
@ -47,7 +47,7 @@ const Foam::boundBox Foam::boundBox::invertedBox
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::boundBox::calculate(const pointField& points, const bool doReduce)
|
void Foam::boundBox::calculate(const UList<point>& points, const bool doReduce)
|
||||||
{
|
{
|
||||||
if (points.empty())
|
if (points.empty())
|
||||||
{
|
{
|
||||||
@ -84,7 +84,7 @@ void Foam::boundBox::calculate(const pointField& points, const bool doReduce)
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::boundBox::boundBox(const pointField& points, const bool doReduce)
|
Foam::boundBox::boundBox(const UList<point>& points, const bool doReduce)
|
||||||
:
|
:
|
||||||
min_(point::zero),
|
min_(point::zero),
|
||||||
max_(point::zero)
|
max_(point::zero)
|
||||||
@ -103,9 +103,43 @@ Foam::boundBox::boundBox(const tmp<pointField>& points, const bool doReduce)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::boundBox::boundBox(Istream& is)
|
Foam::boundBox::boundBox
|
||||||
|
(
|
||||||
|
const UList<point>& points,
|
||||||
|
const labelUList& indices,
|
||||||
|
const bool doReduce
|
||||||
|
)
|
||||||
|
:
|
||||||
|
min_(point::zero),
|
||||||
|
max_(point::zero)
|
||||||
{
|
{
|
||||||
operator>>(is, *this);
|
if (points.empty() || indices.empty())
|
||||||
|
{
|
||||||
|
if (doReduce && Pstream::parRun())
|
||||||
|
{
|
||||||
|
// Use values that get overwritten by reduce minOp, maxOp below
|
||||||
|
min_ = point(VGREAT, VGREAT, VGREAT);
|
||||||
|
max_ = point(-VGREAT, -VGREAT, -VGREAT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
min_ = points[indices[0]];
|
||||||
|
max_ = points[indices[0]];
|
||||||
|
|
||||||
|
for (label i=1; i < indices.size(); ++i)
|
||||||
|
{
|
||||||
|
min_ = ::Foam::min(min_, points[indices[i]]);
|
||||||
|
max_ = ::Foam::max(max_, points[indices[i]]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reduce parallel information
|
||||||
|
if (doReduce)
|
||||||
|
{
|
||||||
|
reduce(min_, minOp<point>());
|
||||||
|
reduce(max_, maxOp<point>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -172,4 +206,5 @@ Foam::Istream& Foam::operator>>(Istream& is, boundBox& bb)
|
|||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -44,7 +44,8 @@ namespace Foam
|
|||||||
class boundBox;
|
class boundBox;
|
||||||
template<class T> class tmp;
|
template<class T> class tmp;
|
||||||
|
|
||||||
Ostream& operator<<(Ostream& os, const boundBox& b);
|
Istream& operator>>(Istream&, boundBox&);
|
||||||
|
Ostream& operator<<(Ostream&, const boundBox&);
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
@ -60,9 +61,9 @@ class boundBox
|
|||||||
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
//- Calculate the bounding box from the given pointField.
|
//- Calculate the bounding box from the given points.
|
||||||
// Does parallel communication (doReduce = true)
|
// Does parallel communication (doReduce = true)
|
||||||
void calculate(const pointField&, const bool doReduce = true);
|
void calculate(const UList<point>&, const bool doReduce = true);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -81,29 +82,42 @@ public:
|
|||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct null, setting points to zero
|
//- Construct null, setting points to zero
|
||||||
boundBox()
|
inline boundBox();
|
||||||
:
|
|
||||||
min_(point::zero),
|
|
||||||
max_(point::zero)
|
|
||||||
{}
|
|
||||||
|
|
||||||
//- Construct from components
|
//- Construct from components
|
||||||
boundBox(const point& min, const point& max)
|
inline boundBox(const point& min, const point& max);
|
||||||
:
|
|
||||||
min_(min),
|
|
||||||
max_(max)
|
|
||||||
{}
|
|
||||||
|
|
||||||
//- Construct as the bounding box of the given pointField.
|
//- Construct as the bounding box of the given points
|
||||||
// Does parallel communication (doReduce = true)
|
// Does parallel communication (doReduce = true)
|
||||||
boundBox(const pointField&, const bool doReduce = true);
|
boundBox(const UList<point>&, const bool doReduce = true);
|
||||||
|
|
||||||
//- Construct as the bounding box of the given temporary pointField.
|
//- Construct as the bounding box of the given temporary pointField.
|
||||||
// Does parallel communication (doReduce = true)
|
// Does parallel communication (doReduce = true)
|
||||||
boundBox(const tmp<pointField>&, const bool doReduce = true);
|
boundBox(const tmp<pointField>&, const bool doReduce = true);
|
||||||
|
|
||||||
|
//- Construct bounding box as subset of the pointField.
|
||||||
|
// The indices could be from cell/face etc.
|
||||||
|
// Does parallel communication (doReduce = true)
|
||||||
|
boundBox
|
||||||
|
(
|
||||||
|
const UList<point>&,
|
||||||
|
const labelUList& indices,
|
||||||
|
const bool doReduce = true
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Construct bounding box as subset of the pointField.
|
||||||
|
// The indices could be from edge/triFace etc.
|
||||||
|
// Does parallel communication (doReduce = true)
|
||||||
|
template<unsigned Size>
|
||||||
|
boundBox
|
||||||
|
(
|
||||||
|
const UList<point>&,
|
||||||
|
const FixedList<label, Size>& indices,
|
||||||
|
const bool doReduce = true
|
||||||
|
);
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
boundBox(Istream&);
|
inline boundBox(Istream&);
|
||||||
|
|
||||||
|
|
||||||
// Member functions
|
// Member functions
|
||||||
@ -111,70 +125,37 @@ public:
|
|||||||
// Access
|
// Access
|
||||||
|
|
||||||
//- Minimum describing the bounding box
|
//- Minimum describing the bounding box
|
||||||
const point& min() const
|
inline const point& min() const;
|
||||||
{
|
|
||||||
return min_;
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Maximum describing the bounding box
|
//- Maximum describing the bounding box
|
||||||
const point& max() const
|
inline const point& max() const;
|
||||||
{
|
|
||||||
return max_;
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Minimum describing the bounding box, non-const access
|
//- Minimum describing the bounding box, non-const access
|
||||||
point& min()
|
inline point& min();
|
||||||
{
|
|
||||||
return min_;
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Maximum describing the bounding box, non-const access
|
//- Maximum describing the bounding box, non-const access
|
||||||
point& max()
|
inline point& max();
|
||||||
{
|
|
||||||
return max_;
|
|
||||||
}
|
|
||||||
|
|
||||||
//- The midpoint of the bounding box
|
//- The midpoint of the bounding box
|
||||||
point midpoint() const
|
inline point midpoint() const;
|
||||||
{
|
|
||||||
return 0.5 * (max_ + min_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- The bounding box span (from minimum to maximum)
|
//- The bounding box span (from minimum to maximum)
|
||||||
vector span() const
|
inline vector span() const;
|
||||||
{
|
|
||||||
return (max_ - min_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- The magnitude of the bounding box span
|
//- The magnitude of the bounding box span
|
||||||
scalar mag() const
|
inline scalar mag() const;
|
||||||
{
|
|
||||||
return ::Foam::mag(max_ - min_);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- The volume of the bound box
|
//- The volume of the bound box
|
||||||
scalar volume() const
|
inline scalar volume() const;
|
||||||
{
|
|
||||||
return cmptProduct(span());
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Smallest length/height/width dimension
|
//- Smallest length/height/width dimension
|
||||||
scalar minDim() const
|
inline scalar minDim() const;
|
||||||
{
|
|
||||||
return cmptMin(span());
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Largest length/height/width dimension
|
//- Largest length/height/width dimension
|
||||||
scalar maxDim() const
|
inline scalar maxDim() const;
|
||||||
{
|
|
||||||
return cmptMax(span());
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Average length/height/width dimension
|
//- Average length/height/width dimension
|
||||||
scalar avgDim() const
|
inline scalar avgDim() const;
|
||||||
{
|
|
||||||
return cmptAv(span());
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Return corner points in an order corresponding to a 'hex' cell
|
//- Return corner points in an order corresponding to a 'hex' cell
|
||||||
tmp<pointField> corners() const;
|
tmp<pointField> corners() const;
|
||||||
@ -182,56 +163,28 @@ public:
|
|||||||
// Query
|
// Query
|
||||||
|
|
||||||
//- Overlaps/touches boundingBox?
|
//- Overlaps/touches boundingBox?
|
||||||
bool overlaps(const boundBox& bb) const
|
inline bool overlaps(const boundBox&) const;
|
||||||
{
|
|
||||||
return
|
|
||||||
(
|
|
||||||
bb.max_.x() >= min_.x() && bb.min_.x() <= max_.x()
|
|
||||||
&& bb.max_.y() >= min_.y() && bb.min_.y() <= max_.y()
|
|
||||||
&& bb.max_.z() >= min_.z() && bb.min_.z() <= max_.z()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Contains point? (inside or on edge)
|
//- Contains point? (inside or on edge)
|
||||||
bool contains(const point& pt) const
|
inline bool contains(const point&) const;
|
||||||
{
|
|
||||||
return
|
//- Fully contains other boundingBox?
|
||||||
(
|
inline bool contains(const boundBox&) const;
|
||||||
pt.x() >= min_.x() && pt.x() <= max_.x()
|
|
||||||
&& pt.y() >= min_.y() && pt.y() <= max_.y()
|
|
||||||
&& pt.z() >= min_.z() && pt.z() <= max_.z()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Contains point? (inside only)
|
//- Contains point? (inside only)
|
||||||
bool containsInside(const point& pt) const
|
inline bool containsInside(const point&) 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()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Friend Operators
|
// Friend Operators
|
||||||
|
|
||||||
friend bool operator==(const boundBox& a, const boundBox& b)
|
inline friend bool operator==(const boundBox&, const boundBox&);
|
||||||
{
|
inline friend bool operator!=(const boundBox&, const boundBox&);
|
||||||
return (a.min_ == b.min_) && (a.max_ == b.max_);
|
|
||||||
}
|
|
||||||
|
|
||||||
friend bool operator!=(const boundBox& a, const boundBox& b)
|
|
||||||
{
|
|
||||||
return !(a == b);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// IOstream operator
|
// IOstream operator
|
||||||
|
|
||||||
friend Istream& operator>>(Istream& is, boundBox&);
|
friend Istream& operator>>(Istream&, boundBox&);
|
||||||
friend Ostream& operator<<(Ostream& os, const boundBox&);
|
friend Ostream& operator<<(Ostream&, const boundBox&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -244,7 +197,11 @@ inline bool contiguous<boundBox>() {return contiguous<point>();}
|
|||||||
|
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|
||||||
// #include "boundBoxI.H"
|
#include "boundBoxI.H"
|
||||||
|
|
||||||
|
#ifdef NoRepository
|
||||||
|
# include "boundBoxTemplates.C"
|
||||||
|
#endif
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|||||||
174
src/OpenFOAM/meshes/boundBox/boundBoxI.H
Normal file
174
src/OpenFOAM/meshes/boundBox/boundBoxI.H
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "boundBox.H"
|
||||||
|
#include "pointField.H"
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline Foam::boundBox::boundBox()
|
||||||
|
:
|
||||||
|
min_(point::zero),
|
||||||
|
max_(point::zero)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::boundBox::boundBox(const point& min, const point& max)
|
||||||
|
:
|
||||||
|
min_(min),
|
||||||
|
max_(max)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::boundBox::boundBox(Istream& is)
|
||||||
|
{
|
||||||
|
operator>>(is, *this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline const Foam::point& Foam::boundBox::min() const
|
||||||
|
{
|
||||||
|
return min_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline const Foam::point& Foam::boundBox::max() const
|
||||||
|
{
|
||||||
|
return max_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::point& Foam::boundBox::min()
|
||||||
|
{
|
||||||
|
return min_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::point& Foam::boundBox::max()
|
||||||
|
{
|
||||||
|
return max_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::point Foam::boundBox::midpoint() const
|
||||||
|
{
|
||||||
|
return 0.5 * (max_ + min_);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::vector Foam::boundBox::span() const
|
||||||
|
{
|
||||||
|
return (max_ - min_);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::scalar Foam::boundBox::mag() const
|
||||||
|
{
|
||||||
|
return ::Foam::mag(max_ - min_);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::scalar Foam::boundBox::volume() const
|
||||||
|
{
|
||||||
|
return cmptProduct(span());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::scalar Foam::boundBox::minDim() const
|
||||||
|
{
|
||||||
|
return cmptMin(span());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::scalar Foam::boundBox::maxDim() const
|
||||||
|
{
|
||||||
|
return cmptMax(span());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::scalar Foam::boundBox::avgDim() const
|
||||||
|
{
|
||||||
|
return cmptAv(span());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::boundBox::overlaps(const boundBox& bb) const
|
||||||
|
{
|
||||||
|
return
|
||||||
|
(
|
||||||
|
bb.max_.x() >= min_.x() && bb.min_.x() <= max_.x()
|
||||||
|
&& bb.max_.y() >= min_.y() && bb.min_.y() <= max_.y()
|
||||||
|
&& bb.max_.z() >= min_.z() && bb.min_.z() <= max_.z()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// this.bb fully contains bb
|
||||||
|
inline bool Foam::boundBox::contains(const boundBox& bb) const
|
||||||
|
{
|
||||||
|
return contains(bb.min()) && contains(bb.max());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline bool Foam::operator==(const boundBox& a, const boundBox& b)
|
||||||
|
{
|
||||||
|
return (a.min_ == b.min_) && (a.max_ == b.max_);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::operator!=(const boundBox& a, const boundBox& b)
|
||||||
|
{
|
||||||
|
return !(a == b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
76
src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C
Normal file
76
src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "boundBox.H"
|
||||||
|
#include "FixedList.H"
|
||||||
|
#include "PstreamReduceOps.H"
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|
||||||
|
template<unsigned Size>
|
||||||
|
Foam::boundBox::boundBox
|
||||||
|
(
|
||||||
|
const UList<point>& points,
|
||||||
|
const FixedList<label, Size>& indices,
|
||||||
|
const bool doReduce
|
||||||
|
)
|
||||||
|
:
|
||||||
|
min_(point::zero),
|
||||||
|
max_(point::zero)
|
||||||
|
{
|
||||||
|
// a FixedList is never empty
|
||||||
|
if (points.empty())
|
||||||
|
{
|
||||||
|
if (doReduce && Pstream::parRun())
|
||||||
|
{
|
||||||
|
// Use values that get overwritten by reduce minOp, maxOp below
|
||||||
|
min_ = point(VGREAT, VGREAT, VGREAT);
|
||||||
|
max_ = point(-VGREAT, -VGREAT, -VGREAT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
min_ = points[indices[0]];
|
||||||
|
max_ = points[indices[0]];
|
||||||
|
|
||||||
|
for (unsigned i=1; i < Size; ++i)
|
||||||
|
{
|
||||||
|
min_ = ::Foam::min(min_, points[indices[i]]);
|
||||||
|
max_ = ::Foam::max(max_, points[indices[i]]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reduce parallel information
|
||||||
|
if (doReduce)
|
||||||
|
{
|
||||||
|
reduce(min_, minOp<point>());
|
||||||
|
reduce(max_, maxOp<point>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -209,8 +209,8 @@ public:
|
|||||||
|
|
||||||
// Friend Operators
|
// Friend Operators
|
||||||
|
|
||||||
friend bool operator==(const triFace&, const triFace&);
|
inline friend bool operator==(const triFace&, const triFace&);
|
||||||
friend bool operator!=(const triFace&, const triFace&);
|
inline friend bool operator!=(const triFace&, const triFace&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -124,10 +124,9 @@ Foam::FixedList<Foam::vector, 6> Foam::treeBoundBox::calcFaceNormals()
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
// Construct as the bounding box of the given pointField
|
|
||||||
Foam::treeBoundBox::treeBoundBox(const UList<point>& points)
|
Foam::treeBoundBox::treeBoundBox(const UList<point>& points)
|
||||||
:
|
:
|
||||||
boundBox()
|
boundBox(points, false)
|
||||||
{
|
{
|
||||||
if (points.empty())
|
if (points.empty())
|
||||||
{
|
{
|
||||||
@ -139,57 +138,31 @@ Foam::treeBoundBox::treeBoundBox(const UList<point>& points)
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
min() = points[0];
|
|
||||||
max() = points[0];
|
|
||||||
|
|
||||||
for (label i = 1; i < points.size(); i++)
|
|
||||||
{
|
|
||||||
min() = ::Foam::min(min(), points[i]);
|
|
||||||
max() = ::Foam::max(max(), points[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Construct as the bounding box of the given pointField
|
|
||||||
Foam::treeBoundBox::treeBoundBox
|
Foam::treeBoundBox::treeBoundBox
|
||||||
(
|
(
|
||||||
const UList<point>& points,
|
const UList<point>& points,
|
||||||
const labelUList& meshPoints
|
const labelUList& indices
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
boundBox()
|
boundBox(points, indices, false)
|
||||||
{
|
{
|
||||||
if (points.empty() || meshPoints.empty())
|
if (points.empty() || indices.empty())
|
||||||
{
|
{
|
||||||
WarningIn
|
WarningIn
|
||||||
(
|
(
|
||||||
"treeBoundBox::treeBoundBox"
|
"treeBoundBox::treeBoundBox"
|
||||||
"(const UList<point>&, const labelUList&)"
|
"(const UList<point>&, const labelUList&)"
|
||||||
) << "cannot find bounding box for zero-sized pointField"
|
) << "cannot find bounding box for zero-sized pointField, "
|
||||||
<< "returning zero" << endl;
|
<< "returning zero" << endl;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
min() = points[meshPoints[0]];
|
|
||||||
max() = points[meshPoints[0]];
|
|
||||||
|
|
||||||
for (label i = 1; i < meshPoints.size(); i++)
|
|
||||||
{
|
|
||||||
min() = ::Foam::min(min(), points[meshPoints[i]]);
|
|
||||||
max() = ::Foam::max(max(), points[meshPoints[i]]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Construct from Istream
|
|
||||||
Foam::treeBoundBox::treeBoundBox(Istream& is)
|
|
||||||
:
|
|
||||||
boundBox(is)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::pointField Foam::treeBoundBox::points() const
|
Foam::pointField Foam::treeBoundBox::points() const
|
||||||
@ -458,13 +431,6 @@ bool Foam::treeBoundBox::intersects
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// this.bb fully contains bb
|
|
||||||
bool Foam::treeBoundBox::contains(const treeBoundBox& bb) const
|
|
||||||
{
|
|
||||||
return contains(bb.min()) && contains(bb.max());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Foam::treeBoundBox::contains(const vector& dir, const point& pt) const
|
bool Foam::treeBoundBox::contains(const vector& dir, const point& pt) const
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
|||||||
@ -50,6 +50,7 @@ Description
|
|||||||
SourceFiles
|
SourceFiles
|
||||||
treeBoundBoxI.H
|
treeBoundBoxI.H
|
||||||
treeBoundBox.C
|
treeBoundBox.C
|
||||||
|
treeBoundBoxTemplates.C
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -69,7 +70,7 @@ namespace Foam
|
|||||||
class Random;
|
class Random;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class treeBoundBox Declaration
|
Class treeBoundBox Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
class treeBoundBox
|
class treeBoundBox
|
||||||
@ -165,11 +166,11 @@ public:
|
|||||||
//- Construct null setting points to zero
|
//- Construct null setting points to zero
|
||||||
inline treeBoundBox();
|
inline treeBoundBox();
|
||||||
|
|
||||||
//- Construct from components
|
//- Construct from a boundBox
|
||||||
inline treeBoundBox(const point& min, const point& max);
|
explicit inline treeBoundBox(const boundBox& bb);
|
||||||
|
|
||||||
//- Construct from components
|
//- Construct from components
|
||||||
explicit inline treeBoundBox(const boundBox& bb);
|
inline treeBoundBox(const point& min, const point& max);
|
||||||
|
|
||||||
//- Construct as the bounding box of the given pointField.
|
//- Construct as the bounding box of the given pointField.
|
||||||
// Local processor domain only (no reduce as in boundBox)
|
// Local processor domain only (no reduce as in boundBox)
|
||||||
@ -177,10 +178,21 @@ public:
|
|||||||
|
|
||||||
//- Construct as subset of points
|
//- Construct as subset of points
|
||||||
// Local processor domain only (no reduce as in boundBox)
|
// Local processor domain only (no reduce as in boundBox)
|
||||||
treeBoundBox(const UList<point>&, const labelUList& meshPoints);
|
treeBoundBox(const UList<point>&, const labelUList& indices);
|
||||||
|
|
||||||
|
//- Construct as subset of points
|
||||||
|
// The indices could be from edge/triFace etc.
|
||||||
|
// Local processor domain only (no reduce as in boundBox)
|
||||||
|
template<unsigned Size>
|
||||||
|
treeBoundBox
|
||||||
|
(
|
||||||
|
const UList<point>&,
|
||||||
|
const FixedList<label, Size>& indices
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
treeBoundBox(Istream&);
|
inline treeBoundBox(Istream&);
|
||||||
|
|
||||||
|
|
||||||
// Member functions
|
// Member functions
|
||||||
@ -257,8 +269,8 @@ public:
|
|||||||
FixedList<direction, 8>& octantOrder
|
FixedList<direction, 8>& octantOrder
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Overlaps other boundingbox?
|
//- Overlaps other bounding box?
|
||||||
inline bool overlaps(const treeBoundBox&) const;
|
using boundBox::overlaps;
|
||||||
|
|
||||||
//- Overlaps boundingSphere (centre + sqr(radius))?
|
//- Overlaps boundingSphere (centre + sqr(radius))?
|
||||||
bool overlaps(const point&, const scalar radiusSqr) const;
|
bool overlaps(const point&, const scalar radiusSqr) const;
|
||||||
@ -289,18 +301,15 @@ public:
|
|||||||
point& pt
|
point& pt
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- fully contains other boundingBox?
|
//- Contains point or other bounding box?
|
||||||
inline bool contains(const treeBoundBox&) const;
|
using boundBox::contains;
|
||||||
|
|
||||||
//- Contains point? (inside or on edge)
|
|
||||||
inline bool contains(const point&) const;
|
|
||||||
|
|
||||||
//- Contains point (inside or on edge) and moving in direction
|
//- Contains point (inside or on edge) and moving in direction
|
||||||
// dir would cause it to go inside.
|
// dir would cause it to go inside.
|
||||||
bool contains(const vector& dir, const point&) const;
|
bool contains(const vector& dir, const point&) const;
|
||||||
|
|
||||||
//- Code position of pt on bounding box faces
|
//- Code position of point on bounding box faces
|
||||||
direction faceBits(const point& pt) const;
|
direction faceBits(const point&) const;
|
||||||
|
|
||||||
//- Position of point relative to bounding box
|
//- Position of point relative to bounding box
|
||||||
direction posBits(const point&) const;
|
direction posBits(const point&) const;
|
||||||
@ -355,6 +364,10 @@ inline bool contiguous<treeBoundBox>() {return contiguous<boundBox>();}
|
|||||||
|
|
||||||
#include "treeBoundBoxI.H"
|
#include "treeBoundBoxI.H"
|
||||||
|
|
||||||
|
#ifdef NoRepository
|
||||||
|
# include "treeBoundBoxTemplates.C"
|
||||||
|
#endif
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -46,6 +46,12 @@ inline Foam::treeBoundBox::treeBoundBox(const boundBox& bb)
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::treeBoundBox::treeBoundBox(Istream& is)
|
||||||
|
:
|
||||||
|
boundBox(is)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline Foam::scalar Foam::treeBoundBox::typDim() const
|
inline Foam::scalar Foam::treeBoundBox::typDim() const
|
||||||
@ -306,20 +312,6 @@ inline void Foam::treeBoundBox::searchOrder
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// true if bb's intersect or overlap.
|
|
||||||
// Note: <= to make sure we catch all.
|
|
||||||
inline bool Foam::treeBoundBox::overlaps(const treeBoundBox& bb) const
|
|
||||||
{
|
|
||||||
return boundBox::overlaps(bb);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::treeBoundBox::contains(const point& pt) const
|
|
||||||
{
|
|
||||||
return boundBox::contains(pt);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//- Return slightly wider bounding box
|
//- Return slightly wider bounding box
|
||||||
inline Foam::treeBoundBox Foam::treeBoundBox::extend
|
inline Foam::treeBoundBox Foam::treeBoundBox::extend
|
||||||
(
|
(
|
||||||
@ -346,6 +338,4 @@ inline Foam::treeBoundBox Foam::treeBoundBox::extend
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
56
src/meshTools/octree/treeBoundBoxTemplates.C
Normal file
56
src/meshTools/octree/treeBoundBoxTemplates.C
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "treeBoundBox.H"
|
||||||
|
#include "FixedList.H"
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|
||||||
|
template<unsigned Size>
|
||||||
|
Foam::treeBoundBox::treeBoundBox
|
||||||
|
(
|
||||||
|
const UList<point>& points,
|
||||||
|
const FixedList<label, Size>& indices
|
||||||
|
)
|
||||||
|
:
|
||||||
|
boundBox(points, indices, false)
|
||||||
|
{
|
||||||
|
// points may be empty, but a FixedList is never empty
|
||||||
|
if (points.empty())
|
||||||
|
{
|
||||||
|
WarningIn
|
||||||
|
(
|
||||||
|
"treeBoundBox::treeBoundBox"
|
||||||
|
"(const UList<point>&, const FixedList<label, Size>&)"
|
||||||
|
) << "cannot find bounding box for zero-sized pointField, "
|
||||||
|
<< "returning zero" << endl;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
Reference in New Issue
Block a user