From dc488579ca05e8aae956ad028c057ece904bdef4 Mon Sep 17 00:00:00 2001 From: laurence Date: Thu, 11 Apr 2013 20:04:26 +0100 Subject: [PATCH] ENH: Check whether an intersection is unique when using findAll. This check is required because the new octree method for finding all intersections with a surface will return two face intersection hits for a line that passes through the edge shared by two faces. The test is geometric. --- .../triSurfaceSearch/triSurfaceSearch.C | 93 ++++++++++++++++++- .../triSurfaceSearch/triSurfaceSearch.H | 11 ++- 2 files changed, 102 insertions(+), 2 deletions(-) diff --git a/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.C b/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.C index 0a8dc40777..aad1a824eb 100644 --- a/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.C +++ b/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.C @@ -28,6 +28,83 @@ License #include "PatchTools.H" #include "volumeType.H" +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +bool Foam::triSurfaceSearch::checkUniqueHit +( + const pointIndexHit& currHit, + const DynamicList& hits, + const vector& lineVec +) const +{ + // Classify the hit + label nearType = -1; + label nearLabel = -1; + + const labelledTri& f = surface()[currHit.index()]; + + f.nearestPointClassify + ( + currHit.hitPoint(), + surface().points(), + nearType, + nearLabel + ); + + if (nearType == 1) + { + // near point + } + else if (nearType == 2) + { + // near edge + // check if the other face of the edge is already hit + + const labelList& fEdges = surface().faceEdges()[currHit.index()]; + + const label edgeI = fEdges[nearLabel]; + + const labelList& edgeFaces = surface().edgeFaces()[edgeI]; + + forAll(edgeFaces, fI) + { + const label edgeFaceI = edgeFaces[fI]; + + if (edgeFaceI != currHit.index()) + { + forAll(hits, hI) + { + const pointIndexHit& hit = hits[hI]; + + if (hit.index() == edgeFaceI) + { + // Check normals + const vector currHitNormal = + surface().faceNormals()[currHit.index()]; + + const vector existingHitNormal = + surface().faceNormals()[edgeFaceI]; + + const label signCurrHit = + pos(currHitNormal & lineVec); + + const label signExistingHit = + pos(existingHitNormal & lineVec); + + if (signCurrHit == signExistingHit) + { + return false; + } + } + } + } + } + } + + return true; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::triSurfaceSearch::triSurfaceSearch(const triSurface& surface) @@ -306,7 +383,21 @@ void Foam::triSurfaceSearch::findLineAll if (inter.hit()) { - hits.append(inter); + vector lineVec = end[pointI] - start[pointI]; + lineVec /= mag(lineVec) + VSMALL; + + if + ( + checkUniqueHit + ( + inter, + hits, + lineVec + ) + ) + { + hits.append(inter); + } shapeMask.append(inter.index()); } diff --git a/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.H b/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.H index fc138c46f0..bdca1bca83 100644 --- a/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.H +++ b/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.H @@ -50,7 +50,7 @@ namespace Foam class triSurface; /*---------------------------------------------------------------------------*\ - Class triSurfaceSearch Declaration + Class triSurfaceSearch Declaration \*---------------------------------------------------------------------------*/ class triSurfaceSearch @@ -72,6 +72,15 @@ class triSurfaceSearch // Private Member Functions + //- Check whether the current hit on the surface which lies on lineVec + // is unique. + bool checkUniqueHit + ( + const pointIndexHit& currHit, + const DynamicList& hits, + const vector& lineVec + ) const; + //- Disallow default bitwise copy construct triSurfaceSearch(const triSurfaceSearch&);