From ffbad655386a74ccc746cb61f295d26248075099 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 24 Oct 2022 16:21:18 +0200 Subject: [PATCH] ENH: replace triangleFuncs::intersectBb usage with boundBox::intersect --- src/meshTools/indexedOctree/treeDataFace.C | 21 +++++---- .../indexedOctree/treeDataPrimitivePatch.C | 38 +++++++--------- .../distributedTriSurfaceMesh.C | 43 ++++++------------- .../distributedTriSurfaceMesh.H | 11 +++-- 4 files changed, 45 insertions(+), 68 deletions(-) diff --git a/src/meshTools/indexedOctree/treeDataFace.C b/src/meshTools/indexedOctree/treeDataFace.C index f6cec8259c..d410b52094 100644 --- a/src/meshTools/indexedOctree/treeDataFace.C +++ b/src/meshTools/indexedOctree/treeDataFace.C @@ -28,7 +28,7 @@ License #include "treeDataFace.H" #include "polyMesh.H" -#include "triangleFuncs.H" +#include "triangle.H" #include // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -551,11 +551,18 @@ bool Foam::treeDataFace::overlaps const pointField& points = mesh_.points(); - // 2. Check if one or more face points inside const label facei = objectIndex(index); 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)) { return true; @@ -563,19 +570,17 @@ bool Foam::treeDataFace::overlaps // 3. Difficult case: all points are outside but connecting edges might // go through cube. Use triangle-bounding box intersection. + const point& fc = mesh_.faceCentres()[facei]; forAll(f, fp) { - bool triIntersects = triangleFuncs::intersectBb + const triPointRef tri ( - points[f[fp]], - points[f[f.fcIndex(fp)]], - fc, - searchBox + points[f.thisLabel(fp)], points[f.nextLabel(fp)], fc ); - if (triIntersects) + if (searchBox.intersects(tri)) { return true; } diff --git a/src/meshTools/indexedOctree/treeDataPrimitivePatch.C b/src/meshTools/indexedOctree/treeDataPrimitivePatch.C index 51b39a820b..62fac283e6 100644 --- a/src/meshTools/indexedOctree/treeDataPrimitivePatch.C +++ b/src/meshTools/indexedOctree/treeDataPrimitivePatch.C @@ -28,7 +28,7 @@ License #include "treeDataPrimitivePatch.H" #include "indexedOctree.H" -#include "triangleFuncs.H" +#include "triangle.H" #include "triSurfaceTools.H" #include "triFace.H" #include @@ -416,6 +416,13 @@ bool Foam::treeDataPrimitivePatch::overlaps const pointField& points = patch_.points(); 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)) { return true; @@ -423,34 +430,19 @@ bool Foam::treeDataPrimitivePatch::overlaps // 3. Difficult case: all points are outside but connecting edges might // go through cube. Use triangle-bounding box intersection. + const point fc = f.centre(points); - if (f.size() == 3) + forAll(f, fp) { - return triangleFuncs::intersectBb + const triPointRef tri ( - points[f[0]], - points[f[1]], - points[f[2]], - searchBox + points[f.thisLabel(fp)], points[f.nextLabel(fp)], fc ); - } - else - { - forAll(f, fp) - { - bool triIntersects = triangleFuncs::intersectBb - ( - points[f[fp]], - points[f[f.fcIndex(fp)]], - fc, - searchBox - ); - if (triIntersects) - { - return true; - } + if (searchBox.intersects(tri)) + { + return true; } } diff --git a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C index 8265d7b527..5d53b49ead 100644 --- a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C +++ b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C @@ -30,7 +30,7 @@ License #include "mapDistribute.H" #include "Random.H" #include "addToRunTimeSelectionTable.H" -#include "triangleFuncs.H" +#include "triangle.H" #include "matchPoints.H" #include "globalIndex.H" #include "Time.H" @@ -2185,41 +2185,23 @@ Foam::distributedTriSurfaceMesh::independentlyDistributedBbs bool Foam::distributedTriSurfaceMesh::overlaps ( const List& bbs, - const point& p0, - const point& p1, - const point& p2 + const triPointRef& tri ) { - treeBoundBox triBb(p0); - triBb.add(p1); - triBb.add(p2); + treeBoundBox triBb(tri.a()); + triBb.add(tri.b()); + triBb.add(tri.c()); - forAll(bbs, bbi) + for (const treeBoundBox& bb : bbs) { - const treeBoundBox& bb = bbs[bbi]; - // Exact test of triangle intersecting bb // Quick rejection. If whole bounding box of tri is outside cubeBb then // there will be no intersection. - if (bb.overlaps(triBb)) + + if (bb.overlaps(triBb) && bb.intersects(tri)) { - // Check if one or more triangle point inside - 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 true; } } return false; @@ -4501,11 +4483,10 @@ void Foam::distributedTriSurfaceMesh::overlappingSurface forAll(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; } diff --git a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.H b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.H index d5417c14f5..514d675f3d 100644 --- a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.H +++ b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -57,8 +57,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef distributedTriSurfaceMesh_H -#define distributedTriSurfaceMesh_H +#ifndef Foam_distributedTriSurfaceMesh_H +#define Foam_distributedTriSurfaceMesh_H #include "triSurfaceMesh.H" #include "localIOdictionary.H" @@ -66,6 +66,7 @@ SourceFiles #include "Pair.H" #include "globalIndex.H" #include "DynamicField.H" +#include "triangleFwd.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -330,9 +331,7 @@ private: static bool overlaps ( const List& bb, - const point& p0, - const point& p1, - const point& p2 + const triPointRef& tri ); //- Find points used in subset