mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: make indices for boundBox::add() a templated parameter
- allows use with any container with begin(), end() and where the "*iterator" dereference returns a label, which is used for indexing into the list of points. This container could be labelUList, bitSet, labelHashSet, etc
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -32,6 +32,9 @@ Description
|
|||||||
#include "boundBox.H"
|
#include "boundBox.H"
|
||||||
#include "treeBoundBox.H"
|
#include "treeBoundBox.H"
|
||||||
#include "cellModel.H"
|
#include "cellModel.H"
|
||||||
|
#include "bitSet.H"
|
||||||
|
#include "HashSet.H"
|
||||||
|
#include "ListOps.H"
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
@ -117,6 +120,29 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
box1.add(box4);
|
box1.add(box4);
|
||||||
Info<<"union with " << box4 << " => " << box1 << endl;
|
Info<<"union with " << box4 << " => " << box1 << endl;
|
||||||
|
|
||||||
|
labelRange range(10, 25);
|
||||||
|
auto variousPoints = ListOps::create<point>
|
||||||
|
(
|
||||||
|
range.begin(),
|
||||||
|
range.end(),
|
||||||
|
[](const label val) { return vector(val, val, val); }
|
||||||
|
);
|
||||||
|
|
||||||
|
Info<< nl << nl;
|
||||||
|
|
||||||
|
labelHashSet select1{4, 5, 55};
|
||||||
|
bitSet select2(15, {1, 5, 20, 24, 34});
|
||||||
|
|
||||||
|
Info<< "From points: size=" << variousPoints.size() << " from "
|
||||||
|
<< variousPoints.first() << " ... " << variousPoints.last() << nl;
|
||||||
|
Info<< "add points @ " << flatOutput(select1.sortedToc()) << nl;
|
||||||
|
|
||||||
|
box1.add(variousPoints, select1);
|
||||||
|
Info<< "box is now => " << box1 << endl;
|
||||||
|
|
||||||
|
box1.add(variousPoints, select2);
|
||||||
|
Info<< "box is now => " << box1 << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -68,8 +68,7 @@ const Foam::FixedList<Foam::vector, 6> Foam::boundBox::faceNormals
|
|||||||
|
|
||||||
Foam::boundBox::boundBox(const UList<point>& points, bool doReduce)
|
Foam::boundBox::boundBox(const UList<point>& points, bool doReduce)
|
||||||
:
|
:
|
||||||
min_(invertedBox.min()),
|
boundBox()
|
||||||
max_(invertedBox.max())
|
|
||||||
{
|
{
|
||||||
add(points);
|
add(points);
|
||||||
|
|
||||||
@ -82,8 +81,7 @@ Foam::boundBox::boundBox(const UList<point>& points, bool doReduce)
|
|||||||
|
|
||||||
Foam::boundBox::boundBox(const tmp<pointField>& tpoints, bool doReduce)
|
Foam::boundBox::boundBox(const tmp<pointField>& tpoints, bool doReduce)
|
||||||
:
|
:
|
||||||
min_(invertedBox.min()),
|
boundBox()
|
||||||
max_(invertedBox.max())
|
|
||||||
{
|
{
|
||||||
add(tpoints);
|
add(tpoints);
|
||||||
|
|
||||||
@ -101,8 +99,7 @@ Foam::boundBox::boundBox
|
|||||||
bool doReduce
|
bool doReduce
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
min_(invertedBox.min()),
|
boundBox()
|
||||||
max_(invertedBox.max())
|
|
||||||
{
|
{
|
||||||
add(points, indices);
|
add(points, indices);
|
||||||
|
|
||||||
@ -246,29 +243,6 @@ bool Foam::boundBox::contains(const UList<point>& points) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::boundBox::contains
|
|
||||||
(
|
|
||||||
const UList<point>& points,
|
|
||||||
const labelUList& indices
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
if (points.empty() || indices.empty())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const label pointi : indices)
|
|
||||||
{
|
|
||||||
if (!contains(points[pointi]))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Foam::boundBox::containsAny(const UList<point>& points) const
|
bool Foam::boundBox::containsAny(const UList<point>& points) const
|
||||||
{
|
{
|
||||||
if (points.empty())
|
if (points.empty())
|
||||||
@ -288,29 +262,6 @@ bool Foam::boundBox::containsAny(const UList<point>& points) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::boundBox::containsAny
|
|
||||||
(
|
|
||||||
const UList<point>& points,
|
|
||||||
const labelUList& indices
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
if (points.empty() || indices.empty())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const label pointi : indices)
|
|
||||||
{
|
|
||||||
if (contains(points[pointi]))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Foam::point Foam::boundBox::nearest(const point& pt) const
|
Foam::point Foam::boundBox::nearest(const point& pt) const
|
||||||
{
|
{
|
||||||
// Clip the point to the range of the bounding box
|
// Clip the point to the range of the bounding box
|
||||||
|
|||||||
@ -126,7 +126,7 @@ public:
|
|||||||
inline boundBox(Istream& is);
|
inline boundBox(Istream& is);
|
||||||
|
|
||||||
|
|
||||||
// Member functions
|
// Member Functions
|
||||||
|
|
||||||
// Access
|
// Access
|
||||||
|
|
||||||
@ -201,19 +201,11 @@ public:
|
|||||||
//- Extend to include the points from the temporary point field.
|
//- Extend to include the points from the temporary point field.
|
||||||
inline void add(const tmp<pointField>& tpoints);
|
inline void add(const tmp<pointField>& tpoints);
|
||||||
|
|
||||||
//- Extend to include the subset of the point field.
|
|
||||||
// The indices could be from cell/face etc.
|
|
||||||
inline void add
|
|
||||||
(
|
|
||||||
const UList<point>& points,
|
|
||||||
const labelUList& indices
|
|
||||||
);
|
|
||||||
|
|
||||||
//- Extend to include the points.
|
//- Extend to include the points.
|
||||||
template<unsigned Size>
|
template<unsigned Size>
|
||||||
void add(const FixedList<point, Size>& points);
|
void add(const FixedList<point, Size>& points);
|
||||||
|
|
||||||
//- Extend to include the subset of the point field.
|
//- Extend to include a (subsetted) point field.
|
||||||
// The indices could be from edge/triFace etc.
|
// The indices could be from edge/triFace etc.
|
||||||
template<unsigned Size>
|
template<unsigned Size>
|
||||||
void add
|
void add
|
||||||
@ -222,6 +214,17 @@ public:
|
|||||||
const FixedList<label, Size>& indices
|
const FixedList<label, Size>& indices
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//- Extend to include a (subsetted) point field.
|
||||||
|
//
|
||||||
|
// \tparam IntContainer A container with an iterator that
|
||||||
|
// dereferences to an label
|
||||||
|
template<class IntContainer>
|
||||||
|
void add
|
||||||
|
(
|
||||||
|
const UList<point>& points,
|
||||||
|
const IntContainer& indices
|
||||||
|
);
|
||||||
|
|
||||||
//- Inflate box by factor*mag(span) in all dimensions
|
//- Inflate box by factor*mag(span) in all dimensions
|
||||||
void inflate(const scalar s);
|
void inflate(const scalar s);
|
||||||
|
|
||||||
@ -259,17 +262,10 @@ public:
|
|||||||
//- Contains point? (inside only)
|
//- Contains point? (inside only)
|
||||||
inline bool containsInside(const point& pt) const;
|
inline bool containsInside(const point& pt) const;
|
||||||
|
|
||||||
//- Contains all of the points? (inside or on edge)
|
//- Contains all points? (inside or on edge)
|
||||||
bool contains(const UList<point>& points) const;
|
bool contains(const UList<point>& points) const;
|
||||||
|
|
||||||
//- Contains all of the subset of points? (inside or on edge)
|
//- Contains all of the (subsetted) points? (inside or on edge)
|
||||||
bool contains
|
|
||||||
(
|
|
||||||
const UList<point>& points,
|
|
||||||
const labelUList& indices
|
|
||||||
) const;
|
|
||||||
|
|
||||||
//- Contains all of the subset of points? (inside or on edge)
|
|
||||||
template<unsigned Size>
|
template<unsigned Size>
|
||||||
bool contains
|
bool contains
|
||||||
(
|
(
|
||||||
@ -278,17 +274,22 @@ public:
|
|||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
|
||||||
|
//- Contains all of the (subsetted) points? (inside or on edge)
|
||||||
|
//
|
||||||
|
// \tparam IntContainer A container with an iterator that
|
||||||
|
// dereferences to an label
|
||||||
|
template<class IntContainer>
|
||||||
|
bool contains
|
||||||
|
(
|
||||||
|
const UList<point>& points,
|
||||||
|
const IntContainer& indices
|
||||||
|
) const;
|
||||||
|
|
||||||
|
|
||||||
//- Contains any of the points? (inside or on edge)
|
//- Contains any of the points? (inside or on edge)
|
||||||
bool containsAny(const UList<point>& points) const;
|
bool containsAny(const UList<point>& points) const;
|
||||||
|
|
||||||
//- Contains any of the subset of points? (inside or on edge)
|
//- Contains any of the (subsetted) points? (inside or on edge)
|
||||||
bool containsAny
|
|
||||||
(
|
|
||||||
const UList<point>& points,
|
|
||||||
const labelUList& indices
|
|
||||||
) const;
|
|
||||||
|
|
||||||
//- Contains any of the subset of points? (inside or on edge)
|
|
||||||
template<unsigned Size>
|
template<unsigned Size>
|
||||||
bool containsAny
|
bool containsAny
|
||||||
(
|
(
|
||||||
@ -296,6 +297,18 @@ public:
|
|||||||
const FixedList<label, Size>& indices
|
const FixedList<label, Size>& indices
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
//- Contains any of the (subsetted) points? (inside or on edge)
|
||||||
|
//
|
||||||
|
// \tparam IntContainer A container with an iterator that
|
||||||
|
// dereferences to an label
|
||||||
|
template<class IntContainer>
|
||||||
|
bool containsAny
|
||||||
|
(
|
||||||
|
const UList<point>& points,
|
||||||
|
const IntContainer& indices
|
||||||
|
) const;
|
||||||
|
|
||||||
|
|
||||||
//- Return the nearest point on the boundBox to the supplied point.
|
//- Return the nearest point on the boundBox to the supplied point.
|
||||||
// If point is inside the boundBox then the point is returned
|
// If point is inside the boundBox then the point is returned
|
||||||
// unchanged.
|
// unchanged.
|
||||||
|
|||||||
@ -25,7 +25,6 @@ License
|
|||||||
|
|
||||||
#include "boundBox.H"
|
#include "boundBox.H"
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline Foam::boundBox::boundBox()
|
inline Foam::boundBox::boundBox()
|
||||||
@ -195,22 +194,6 @@ inline void Foam::boundBox::add(const tmp<pointField>& tpoints)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::boundBox::add
|
|
||||||
(
|
|
||||||
const UList<point>& points,
|
|
||||||
const labelUList& indices
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if (!points.empty())
|
|
||||||
{
|
|
||||||
for (const label pointi : indices)
|
|
||||||
{
|
|
||||||
add(points[pointi]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::boundBox::overlaps(const boundBox& bb) const
|
inline bool Foam::boundBox::overlaps(const boundBox& bb) const
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
|
|||||||
@ -36,8 +36,7 @@ Foam::boundBox::boundBox
|
|||||||
bool doReduce
|
bool doReduce
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
min_(invertedBox.min()),
|
boundBox()
|
||||||
max_(invertedBox.max())
|
|
||||||
{
|
{
|
||||||
add(points, indices);
|
add(points, indices);
|
||||||
|
|
||||||
@ -56,10 +55,9 @@ void Foam::boundBox::add
|
|||||||
const FixedList<point, Size>& points
|
const FixedList<point, Size>& points
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// a FixedList is never empty
|
for (const point& p : points)
|
||||||
for (unsigned i=0; i < Size; ++i)
|
|
||||||
{
|
{
|
||||||
add(points[i]);
|
add(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,35 +69,96 @@ void Foam::boundBox::add
|
|||||||
const FixedList<label, Size>& indices
|
const FixedList<label, Size>& indices
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// points may be empty, but a FixedList is never empty
|
const label len = points.size();
|
||||||
if (!points.empty())
|
|
||||||
|
// Skip if points is empty
|
||||||
|
if (len)
|
||||||
{
|
{
|
||||||
for (const label pointi : indices)
|
for (const label pointi : indices)
|
||||||
{
|
{
|
||||||
add(points[pointi]);
|
if (pointi >= 0 && pointi < len)
|
||||||
|
{
|
||||||
|
add(points[pointi]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class IntContainer>
|
||||||
|
void Foam::boundBox::add
|
||||||
|
(
|
||||||
|
const UList<point>& points,
|
||||||
|
const IntContainer& indices
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const label len = points.size();
|
||||||
|
|
||||||
|
// Skip if points is empty
|
||||||
|
if (len)
|
||||||
|
{
|
||||||
|
for (const label pointi : indices)
|
||||||
|
{
|
||||||
|
if (pointi >= 0 && pointi < len)
|
||||||
|
{
|
||||||
|
add(points[pointi]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<unsigned Size>
|
template<unsigned Size>
|
||||||
bool Foam::boundBox::contains
|
inline bool Foam::boundBox::contains
|
||||||
(
|
(
|
||||||
const UList<point>& points,
|
const UList<point>& points,
|
||||||
const FixedList<label, Size>& indices
|
const FixedList<label, Size>& indices
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
// points may be empty, but a FixedList is never empty
|
const label len = points.size();
|
||||||
if (points.empty())
|
|
||||||
|
if (!len)
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const label pointi : indices)
|
for (const label pointi : indices)
|
||||||
{
|
{
|
||||||
if (!contains(points[pointi]))
|
if (pointi >= 0 && pointi < len)
|
||||||
{
|
{
|
||||||
return false;
|
if (!contains(points[pointi]))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class IntContainer>
|
||||||
|
inline bool Foam::boundBox::contains
|
||||||
|
(
|
||||||
|
const UList<point>& points,
|
||||||
|
const IntContainer& indices
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
const label len = points.size();
|
||||||
|
|
||||||
|
if (!len)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const label pointi : indices)
|
||||||
|
{
|
||||||
|
if (pointi >= 0 && pointi < len)
|
||||||
|
{
|
||||||
|
if (!contains(points[pointi]))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,27 +167,68 @@ bool Foam::boundBox::contains
|
|||||||
|
|
||||||
|
|
||||||
template<unsigned Size>
|
template<unsigned Size>
|
||||||
bool Foam::boundBox::containsAny
|
inline bool Foam::boundBox::containsAny
|
||||||
(
|
(
|
||||||
const UList<point>& points,
|
const UList<point>& points,
|
||||||
const FixedList<label, Size>& indices
|
const FixedList<label, Size>& indices
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
// points may be empty, but a FixedList is never empty
|
const label len = points.size();
|
||||||
if (points.empty())
|
|
||||||
|
if (!len)
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
label failed = 0;
|
||||||
|
|
||||||
for (const label pointi : indices)
|
for (const label pointi : indices)
|
||||||
{
|
{
|
||||||
if (contains(points[pointi]))
|
if (pointi >= 0 && pointi < len)
|
||||||
{
|
{
|
||||||
return true;
|
if (contains(points[pointi]))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
++failed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return !failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class IntContainer>
|
||||||
|
inline bool Foam::boundBox::containsAny
|
||||||
|
(
|
||||||
|
const UList<point>& points,
|
||||||
|
const IntContainer& indices
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
const label len = points.size();
|
||||||
|
|
||||||
|
if (!len)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
label failed = 0;
|
||||||
|
|
||||||
|
for (const label pointi : indices)
|
||||||
|
{
|
||||||
|
if (pointi >= 0 && pointi < len)
|
||||||
|
{
|
||||||
|
if (contains(points[pointi]))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
++failed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return !failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user