mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: improved treeDataPoint subset handling (#1359)
- reverse mapping for the original point ids. This can be useful when searching a subset of points, but needing to store access to the original point index. - move constructor. - Allow use/not-use subset as an optional constructor argument for more convenient caller logic.
This commit is contained in:
committed by
Andrew Heather
parent
84bc1cc8a8
commit
b8ccbbdf67
@ -50,12 +50,26 @@ Foam::treeDataPoint::treeDataPoint(const pointField& points)
|
||||
Foam::treeDataPoint::treeDataPoint
|
||||
(
|
||||
const pointField& points,
|
||||
const labelList& pointLabels
|
||||
const labelUList& pointLabels,
|
||||
const bool useSubsetPoints
|
||||
)
|
||||
:
|
||||
points_(points),
|
||||
pointLabels_(pointLabels),
|
||||
useSubset_(true)
|
||||
useSubset_(useSubsetPoints)
|
||||
{}
|
||||
|
||||
|
||||
Foam::treeDataPoint::treeDataPoint
|
||||
(
|
||||
const pointField& points,
|
||||
labelList&& pointLabels,
|
||||
const bool useSubsetPoints
|
||||
)
|
||||
:
|
||||
points_(points),
|
||||
pointLabels_(std::move(pointLabels)),
|
||||
useSubset_(useSubsetPoints)
|
||||
{}
|
||||
|
||||
|
||||
@ -104,8 +118,7 @@ bool Foam::treeDataPoint::overlaps
|
||||
const treeBoundBox& cubeBb
|
||||
) const
|
||||
{
|
||||
label pointi = (useSubset_ ? pointLabels_[index] : index);
|
||||
return cubeBb.contains(points_[pointi]);
|
||||
return cubeBb.contains(shapePoint(index));
|
||||
}
|
||||
|
||||
|
||||
@ -116,14 +129,7 @@ bool Foam::treeDataPoint::overlaps
|
||||
const scalar radiusSqr
|
||||
) const
|
||||
{
|
||||
label pointi = (useSubset_ ? pointLabels_[index] : index);
|
||||
|
||||
if (magSqr(points_[pointi] - centre) <= radiusSqr)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return (magSqr(shapePoint(index) - centre) <= radiusSqr);
|
||||
}
|
||||
|
||||
|
||||
@ -139,19 +145,11 @@ void Foam::treeDataPoint::findNearestOp::operator()
|
||||
{
|
||||
const treeDataPoint& shape = tree_.shapes();
|
||||
|
||||
forAll(indices, i)
|
||||
for (const label index : indices)
|
||||
{
|
||||
const label index = indices[i];
|
||||
label pointi =
|
||||
(
|
||||
shape.useSubset()
|
||||
? shape.pointLabels()[index]
|
||||
: index
|
||||
);
|
||||
const point& pt = shape.shapePoint(index);
|
||||
|
||||
const point& pt = shape.points()[pointi];
|
||||
|
||||
scalar distSqr = magSqr(pt - sample);
|
||||
const scalar distSqr = magSqr(pt - sample);
|
||||
|
||||
if (distSqr < nearestDistSqr)
|
||||
{
|
||||
@ -183,23 +181,15 @@ void Foam::treeDataPoint::findNearestOp::operator()
|
||||
nearestDistSqr = magSqr(linePoint - nearestPoint);
|
||||
}
|
||||
|
||||
forAll(indices, i)
|
||||
for (const label index : indices)
|
||||
{
|
||||
const label index = indices[i];
|
||||
label pointi =
|
||||
(
|
||||
shape.useSubset()
|
||||
? shape.pointLabels()[index]
|
||||
: index
|
||||
);
|
||||
|
||||
const point& shapePt = shape.points()[pointi];
|
||||
const point& shapePt = shape.shapePoint(index);
|
||||
|
||||
if (tightest.contains(shapePt))
|
||||
{
|
||||
// Nearest point on line
|
||||
pointHit pHit = ln.nearestDist(shapePt);
|
||||
scalar distSqr = sqr(pHit.distance());
|
||||
const scalar distSqr = sqr(pHit.distance());
|
||||
|
||||
if (distSqr < nearestDistSqr)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user