ENH: replace triangleFuncs::intersectBb usage with boundBox::intersect

This commit is contained in:
Mark Olesen
2022-10-24 16:21:18 +02:00
committed by Andrew Heather
parent 38b663b6a8
commit ffbad65538
4 changed files with 45 additions and 68 deletions

View File

@ -28,7 +28,7 @@ License
#include "treeDataFace.H" #include "treeDataFace.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "triangleFuncs.H" #include "triangle.H"
#include <algorithm> #include <algorithm>
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -551,11 +551,18 @@ bool Foam::treeDataFace::overlaps
const pointField& points = mesh_.points(); const pointField& points = mesh_.points();
// 2. Check if one or more face points inside // 2. Check if one or more face points inside
const label facei = objectIndex(index); const label facei = objectIndex(index);
const face& f = mesh_.faces()[facei]; const face& f = mesh_.faces()[facei];
if (f.size() == 3)
{
const triPointRef tri(points[f[0]], points[f[1]], points[f[2]]);
return searchBox.intersects(tri);
}
if (searchBox.containsAny(points, f)) if (searchBox.containsAny(points, f))
{ {
return true; return true;
@ -563,19 +570,17 @@ bool Foam::treeDataFace::overlaps
// 3. Difficult case: all points are outside but connecting edges might // 3. Difficult case: all points are outside but connecting edges might
// go through cube. Use triangle-bounding box intersection. // go through cube. Use triangle-bounding box intersection.
const point& fc = mesh_.faceCentres()[facei]; const point& fc = mesh_.faceCentres()[facei];
forAll(f, fp) forAll(f, fp)
{ {
bool triIntersects = triangleFuncs::intersectBb const triPointRef tri
( (
points[f[fp]], points[f.thisLabel(fp)], points[f.nextLabel(fp)], fc
points[f[f.fcIndex(fp)]],
fc,
searchBox
); );
if (triIntersects) if (searchBox.intersects(tri))
{ {
return true; return true;
} }

View File

@ -28,7 +28,7 @@ License
#include "treeDataPrimitivePatch.H" #include "treeDataPrimitivePatch.H"
#include "indexedOctree.H" #include "indexedOctree.H"
#include "triangleFuncs.H" #include "triangle.H"
#include "triSurfaceTools.H" #include "triSurfaceTools.H"
#include "triFace.H" #include "triFace.H"
#include <algorithm> #include <algorithm>
@ -416,6 +416,13 @@ bool Foam::treeDataPrimitivePatch<PatchType>::overlaps
const pointField& points = patch_.points(); const pointField& points = patch_.points();
const typename PatchType::face_type& f = patch_[index]; const typename PatchType::face_type& f = patch_[index];
if (f.size() == 3)
{
const triPointRef tri(points[f[0]], points[f[1]], points[f[2]]);
return searchBox.intersects(tri);
}
if (searchBox.containsAny(points, f)) if (searchBox.containsAny(points, f))
{ {
return true; return true;
@ -423,34 +430,19 @@ bool Foam::treeDataPrimitivePatch<PatchType>::overlaps
// 3. Difficult case: all points are outside but connecting edges might // 3. Difficult case: all points are outside but connecting edges might
// go through cube. Use triangle-bounding box intersection. // go through cube. Use triangle-bounding box intersection.
const point fc = f.centre(points); const point fc = f.centre(points);
if (f.size() == 3) forAll(f, fp)
{ {
return triangleFuncs::intersectBb const triPointRef tri
( (
points[f[0]], points[f.thisLabel(fp)], points[f.nextLabel(fp)], fc
points[f[1]],
points[f[2]],
searchBox
); );
}
else
{
forAll(f, fp)
{
bool triIntersects = triangleFuncs::intersectBb
(
points[f[fp]],
points[f[f.fcIndex(fp)]],
fc,
searchBox
);
if (triIntersects) if (searchBox.intersects(tri))
{ {
return true; return true;
}
} }
} }

View File

@ -30,7 +30,7 @@ License
#include "mapDistribute.H" #include "mapDistribute.H"
#include "Random.H" #include "Random.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "triangleFuncs.H" #include "triangle.H"
#include "matchPoints.H" #include "matchPoints.H"
#include "globalIndex.H" #include "globalIndex.H"
#include "Time.H" #include "Time.H"
@ -2185,41 +2185,23 @@ Foam::distributedTriSurfaceMesh::independentlyDistributedBbs
bool Foam::distributedTriSurfaceMesh::overlaps bool Foam::distributedTriSurfaceMesh::overlaps
( (
const List<treeBoundBox>& bbs, const List<treeBoundBox>& bbs,
const point& p0, const triPointRef& tri
const point& p1,
const point& p2
) )
{ {
treeBoundBox triBb(p0); treeBoundBox triBb(tri.a());
triBb.add(p1); triBb.add(tri.b());
triBb.add(p2); triBb.add(tri.c());
forAll(bbs, bbi) for (const treeBoundBox& bb : bbs)
{ {
const treeBoundBox& bb = bbs[bbi];
// Exact test of triangle intersecting bb // Exact test of triangle intersecting bb
// Quick rejection. If whole bounding box of tri is outside cubeBb then // Quick rejection. If whole bounding box of tri is outside cubeBb then
// there will be no intersection. // there will be no intersection.
if (bb.overlaps(triBb))
if (bb.overlaps(triBb) && bb.intersects(tri))
{ {
// Check if one or more triangle point inside return true;
if (bb.contains(p0) || bb.contains(p1) || bb.contains(p2))
{
// One or more points inside
return true;
}
// Now we have the difficult case: all points are outside but
// connecting edges might go through cube. Use fast intersection
// of bounding box.
bool intersect = triangleFuncs::intersectBb(p0, p1, p2, bb);
if (intersect)
{
return true;
}
} }
} }
return false; return false;
@ -4501,11 +4483,10 @@ void Foam::distributedTriSurfaceMesh::overlappingSurface
forAll(s, trii) forAll(s, trii)
{ {
const labelledTri& f = s[trii]; const labelledTri& f = s[trii];
const point& p0 = s.points()[f[0]];
const point& p1 = s.points()[f[1]];
const point& p2 = s.points()[f[2]];
if (overlaps(bbsX, p0, p1, p2)) triPointRef tri(s.points(), f);
if (overlaps(bbsX, tri))
{ {
includedFace[trii] = true; includedFace[trii] = true;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -57,8 +57,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef distributedTriSurfaceMesh_H #ifndef Foam_distributedTriSurfaceMesh_H
#define distributedTriSurfaceMesh_H #define Foam_distributedTriSurfaceMesh_H
#include "triSurfaceMesh.H" #include "triSurfaceMesh.H"
#include "localIOdictionary.H" #include "localIOdictionary.H"
@ -66,6 +66,7 @@ SourceFiles
#include "Pair.H" #include "Pair.H"
#include "globalIndex.H" #include "globalIndex.H"
#include "DynamicField.H" #include "DynamicField.H"
#include "triangleFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -330,9 +331,7 @@ private:
static bool overlaps static bool overlaps
( (
const List<treeBoundBox>& bb, const List<treeBoundBox>& bb,
const point& p0, const triPointRef& tri
const point& p1,
const point& p2
); );
//- Find points used in subset //- Find points used in subset