From 25da337ddeaa8635f1121ad35a9776ab7c1b0d53 Mon Sep 17 00:00:00 2001 From: mattijs Date: Fri, 8 Aug 2008 12:13:14 +0100 Subject: [PATCH] allow one intersection per triangle/face only --- src/meshTools/searchableSurface/searchableBox.C | 58 +++++++++++++++--------- src/meshTools/searchableSurface/triSurfaceMesh.C | 57 ++++++++++++++--------- 2 files changed, 73 insertions(+), 42 deletions(-) diff --git a/src/meshTools/searchableSurface/searchableBox.C b/src/meshTools/searchableSurface/searchableBox.C index cb664b5..b1776b3 100644 --- a/src/meshTools/searchableSurface/searchableBox.C +++ b/src/meshTools/searchableSurface/searchableBox.C @@ -436,7 +436,13 @@ void Foam::searchableBox::findLineAll // Work array DynamicList hits; - // Tolerances +//XXX + // Tolerances: + // To find all intersections we add a small vector to the last intersection + // This is chosen such that + // - it is significant (SMALL is smallest representative relative tolerance; + // we need something bigger since we're doing calculations) + // - if the start-end vector is zero we still progress const vectorField dirVec(end-start); const scalarField magSqrDirVec(magSqr(dirVec)); const vectorField smallVec @@ -447,34 +453,44 @@ void Foam::searchableBox::findLineAll forAll(start, pointI) { - hits.clear(); + // See if any intersection between pt and end + pointIndexHit inter = findLine(start[pointI], end[pointI]); - // Current starting point of ray. - point pt = start[pointI]; - - while (true) + if (inter.hit()) { - // See if any intersection between pt and end - pointIndexHit inter = findLine(pt, end[pointI]); - - if (!inter.hit()) - { - break; - } + hits.clear(); hits.append(inter); - pt = inter.hitPoint() + smallVec[pointI]; + point pt = inter.hitPoint() + smallVec[pointI]; - if (((pt-start[pointI])&dirVec[pointI]) > magSqrDirVec[pointI]) + while (((pt-start[pointI])&dirVec[pointI]) <= magSqrDirVec[pointI]) { - // Adding smallVec has taken us beyond end - break; + // See if any intersection between pt and end + pointIndexHit inter = findLine(pt, end[pointI]); + + // Check for not hit or hit same face as before (can happen + // if vector along surface of face) + if + ( + !inter.hit() + || (inter.index() == hits[hits.size()-1].index()) + ) + { + break; + } + hits.append(inter); + + pt = inter.hitPoint() + smallVec[pointI]; } - } - hits.shrink(); - info[pointI].transfer(hits); - hits.clear(); + hits.shrink(); + info[pointI].transfer(hits); + hits.clear(); + } + else + { + info[pointI].clear(); + } } } diff --git a/src/meshTools/searchableSurface/triSurfaceMesh.C b/src/meshTools/searchableSurface/triSurfaceMesh.C index 9751e3a..61b7606 100644 --- a/src/meshTools/searchableSurface/triSurfaceMesh.C +++ b/src/meshTools/searchableSurface/triSurfaceMesh.C @@ -443,7 +443,12 @@ void Foam::triSurfaceMesh::findLineAll // Work array DynamicList hits; - // Tolerances + // Tolerances: + // To find all intersections we add a small vector to the last intersection + // This is chosen such that + // - it is significant (SMALL is smallest representative relative tolerance; + // we need something bigger since we're doing calculations) + // - if the start-end vector is zero we still progress const vectorField dirVec(end-start); const scalarField magSqrDirVec(magSqr(dirVec)); const vectorField smallVec @@ -454,34 +459,44 @@ void Foam::triSurfaceMesh::findLineAll forAll(start, pointI) { - hits.clear(); + // See if any intersection between pt and end + pointIndexHit inter = octree.findLine(start[pointI], end[pointI]); - // Current starting point of ray. - point pt = start[pointI]; - - while (true) + if (inter.hit()) { - // See if any intersection between pt and end - pointIndexHit inter = octree.findLine(pt, end[pointI]); - - if (!inter.hit()) - { - break; - } + hits.clear(); hits.append(inter); - pt = inter.hitPoint() + smallVec[pointI]; + point pt = inter.hitPoint() + smallVec[pointI]; - if (((pt-start[pointI])&dirVec[pointI]) > magSqrDirVec[pointI]) + while (((pt-start[pointI])&dirVec[pointI]) <= magSqrDirVec[pointI]) { - // Adding smallVec has taken us beyond end - break; + // See if any intersection between pt and end + pointIndexHit inter = octree.findLine(pt, end[pointI]); + + // Check for not hit or hit same triangle as before (can happen + // if vector along surface of triangle) + if + ( + !inter.hit() + || (inter.index() == hits[hits.size()-1].index()) + ) + { + break; + } + hits.append(inter); + + pt = inter.hitPoint() + smallVec[pointI]; } - } - hits.shrink(); - info[pointI].transfer(hits); - hits.clear(); + hits.shrink(); + info[pointI].transfer(hits); + hits.clear(); + } + else + { + info[pointI].clear(); + } } } -- 2.11.4.GIT