From 6e857fc8dcfa4e33eb0a6ec114ef0d8c3e0b2231 Mon Sep 17 00:00:00 2001 From: mattijs <mattijs> Date: Fri, 7 Jun 2013 14:36:04 +0100 Subject: [PATCH] ENH: treDataPrimitivePatch: added self intersection operator --- .../indexedOctree/treeDataPrimitivePatch.C | 55 +++++++++++++++++++ .../indexedOctree/treeDataPrimitivePatch.H | 34 ++++++++++-- 2 files changed, 85 insertions(+), 4 deletions(-) diff --git a/src/meshTools/indexedOctree/treeDataPrimitivePatch.C b/src/meshTools/indexedOctree/treeDataPrimitivePatch.C index 488104a3451..7f2c7f93279 100644 --- a/src/meshTools/indexedOctree/treeDataPrimitivePatch.C +++ b/src/meshTools/indexedOctree/treeDataPrimitivePatch.C @@ -187,6 +187,19 @@ Foam::treeDataPrimitivePatch<PatchType>::findAllIntersectOp::findAllIntersectOp {} +template<class PatchType> +Foam::treeDataPrimitivePatch<PatchType>:: +findSelfIntersectOp::findSelfIntersectOp +( + const indexedOctree<treeDataPrimitivePatch<PatchType> >& tree, + const label edgeID +) +: + tree_(tree), + edgeID_(edgeID) +{} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template<class PatchType> @@ -645,4 +658,46 @@ bool Foam::treeDataPrimitivePatch<PatchType>::findAllIntersectOp::operator() } +template<class PatchType> +bool Foam::treeDataPrimitivePatch<PatchType>::findSelfIntersectOp::operator() +( + const label index, + const point& start, + const point& end, + point& intersectionPoint +) const +{ + if (edgeID_ == -1) + { + FatalErrorIn + ( + "findSelfIntersectOp::operator()\n" + "(\n" + " const label index,\n" + " const point& start,\n" + " const point& end,\n" + " point& intersectionPoint\n" + ") const" + ) << "EdgeID not set. Please set edgeID to the index of" + << " the edge you are testing" + << exit(FatalError); + } + + const treeDataPrimitivePatch<PatchType>& shape = tree_.shapes(); + const PatchType& patch = shape.patch(); + + const typename PatchType::FaceType& f = patch.localFaces()[index]; + const edge& e = patch.edges()[edgeID_]; + + if (findIndex(f, e[0]) == -1 && findIndex(f, e[1]) == -1) + { + return findIntersection(tree_, index, start, end, intersectionPoint); + } + else + { + return false; + } +} + + // ************************************************************************* // diff --git a/src/meshTools/indexedOctree/treeDataPrimitivePatch.H b/src/meshTools/indexedOctree/treeDataPrimitivePatch.H index 9d43d2ba851..6cce11c7965 100644 --- a/src/meshTools/indexedOctree/treeDataPrimitivePatch.H +++ b/src/meshTools/indexedOctree/treeDataPrimitivePatch.H @@ -141,8 +141,8 @@ public: findIntersectOp(const indexedOctree<treeDataPrimitivePatch>& tree); - //- Calculate intersection of triangle with ray. Sets result - // accordingly + //- Calculate intersection of any face with ray. Sets result + // accordingly. Used to find first intersection. bool operator() ( const label index, @@ -167,8 +167,34 @@ public: DynamicList<label>& shapeMask ); - //- Calculate intersection of triangle with ray. Sets result - // accordingly + //- Calculate intersection of unique face with ray. Sets result + // accordingly. Used to find all faces. + bool operator() + ( + const label index, + const point& start, + const point& end, + point& intersectionPoint + ) const; + }; + + + class findSelfIntersectOp + { + const indexedOctree<treeDataPrimitivePatch>& tree_; + + const label edgeID_; + + public: + + findSelfIntersectOp + ( + const indexedOctree<treeDataPrimitivePatch>& tree, + const label edgeID + ); + + //- Calculate intersection of face with edge of patch. Excludes + // faces that use edgeID. Used to find self intersection. bool operator() ( const label index, -- GitLab