mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Add extra octree functionality
+ Make intersection and nearest functions functors. This makes adding different intersection and nearest routines easier. + treeDataPrimitivePatch takes its tolerance as a constructor argument + Make treeDataTriSurface a typedef of treeDataPrimitivePatch Conflicts: src/OpenFOAM/algorithms/indexedOctree/indexedOctree.C src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C src/meshTools/indexedOctree/treeDataTriSurface.C
This commit is contained in:
@ -576,6 +576,7 @@ Foam::indexedOctree<Type>::getSide
|
|||||||
|
|
||||||
// Find nearest point starting from nodeI
|
// Find nearest point starting from nodeI
|
||||||
template<class Type>
|
template<class Type>
|
||||||
|
template<class FindNearestOp>
|
||||||
void Foam::indexedOctree<Type>::findNearest
|
void Foam::indexedOctree<Type>::findNearest
|
||||||
(
|
(
|
||||||
const label nodeI,
|
const label nodeI,
|
||||||
@ -583,7 +584,9 @@ void Foam::indexedOctree<Type>::findNearest
|
|||||||
|
|
||||||
scalar& nearestDistSqr,
|
scalar& nearestDistSqr,
|
||||||
label& nearestShapeI,
|
label& nearestShapeI,
|
||||||
point& nearestPoint
|
point& nearestPoint,
|
||||||
|
|
||||||
|
const FindNearestOp& fnOp
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
const node& nod = nodes_[nodeI];
|
const node& nod = nodes_[nodeI];
|
||||||
@ -614,7 +617,9 @@ void Foam::indexedOctree<Type>::findNearest
|
|||||||
|
|
||||||
nearestDistSqr,
|
nearestDistSqr,
|
||||||
nearestShapeI,
|
nearestShapeI,
|
||||||
nearestPoint
|
nearestPoint,
|
||||||
|
|
||||||
|
fnOp
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -631,7 +636,7 @@ void Foam::indexedOctree<Type>::findNearest
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
shapes_.findNearest
|
fnOp
|
||||||
(
|
(
|
||||||
contents_[getContent(index)],
|
contents_[getContent(index)],
|
||||||
sample,
|
sample,
|
||||||
@ -648,6 +653,7 @@ void Foam::indexedOctree<Type>::findNearest
|
|||||||
|
|
||||||
// Find nearest point to line.
|
// Find nearest point to line.
|
||||||
template<class Type>
|
template<class Type>
|
||||||
|
template<class FindNearestOp>
|
||||||
void Foam::indexedOctree<Type>::findNearest
|
void Foam::indexedOctree<Type>::findNearest
|
||||||
(
|
(
|
||||||
const label nodeI,
|
const label nodeI,
|
||||||
@ -656,7 +662,9 @@ void Foam::indexedOctree<Type>::findNearest
|
|||||||
treeBoundBox& tightest,
|
treeBoundBox& tightest,
|
||||||
label& nearestShapeI,
|
label& nearestShapeI,
|
||||||
point& linePoint,
|
point& linePoint,
|
||||||
point& nearestPoint
|
point& nearestPoint,
|
||||||
|
|
||||||
|
const FindNearestOp& fnOp
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
const node& nod = nodes_[nodeI];
|
const node& nod = nodes_[nodeI];
|
||||||
@ -687,7 +695,9 @@ void Foam::indexedOctree<Type>::findNearest
|
|||||||
tightest,
|
tightest,
|
||||||
nearestShapeI,
|
nearestShapeI,
|
||||||
linePoint,
|
linePoint,
|
||||||
nearestPoint
|
nearestPoint,
|
||||||
|
|
||||||
|
fnOp
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -697,7 +707,7 @@ void Foam::indexedOctree<Type>::findNearest
|
|||||||
|
|
||||||
if (subBb.overlaps(tightest))
|
if (subBb.overlaps(tightest))
|
||||||
{
|
{
|
||||||
shapes_.findNearest
|
fnOp
|
||||||
(
|
(
|
||||||
contents_[getContent(index)],
|
contents_[getContent(index)],
|
||||||
ln,
|
ln,
|
||||||
@ -1620,6 +1630,7 @@ Foam::word Foam::indexedOctree<Type>::faceString
|
|||||||
// hitInfo.point = coordinate of intersection of ray with bounding box
|
// hitInfo.point = coordinate of intersection of ray with bounding box
|
||||||
// hitBits = posbits of point on bounding box
|
// hitBits = posbits of point on bounding box
|
||||||
template<class Type>
|
template<class Type>
|
||||||
|
template<class FindIntersectOp>
|
||||||
void Foam::indexedOctree<Type>::traverseNode
|
void Foam::indexedOctree<Type>::traverseNode
|
||||||
(
|
(
|
||||||
const bool findAny,
|
const bool findAny,
|
||||||
@ -1632,7 +1643,9 @@ void Foam::indexedOctree<Type>::traverseNode
|
|||||||
const direction octant,
|
const direction octant,
|
||||||
|
|
||||||
pointIndexHit& hitInfo,
|
pointIndexHit& hitInfo,
|
||||||
direction& hitBits
|
direction& hitBits,
|
||||||
|
|
||||||
|
const FindIntersectOp& fiOp
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
@ -1667,7 +1680,7 @@ void Foam::indexedOctree<Type>::traverseNode
|
|||||||
label shapeI = indices[elemI];
|
label shapeI = indices[elemI];
|
||||||
|
|
||||||
point pt;
|
point pt;
|
||||||
bool hit = shapes_.intersects(shapeI, start, end, pt);
|
bool hit = fiOp(shapeI, start, end, pt);
|
||||||
|
|
||||||
// Note that intersection of shape might actually be
|
// Note that intersection of shape might actually be
|
||||||
// in a neighbouring box. For findAny this is not important.
|
// in a neighbouring box. For findAny this is not important.
|
||||||
@ -1695,13 +1708,7 @@ void Foam::indexedOctree<Type>::traverseNode
|
|||||||
label shapeI = indices[elemI];
|
label shapeI = indices[elemI];
|
||||||
|
|
||||||
point pt;
|
point pt;
|
||||||
bool hit = shapes_.intersects
|
bool hit = fiOp(shapeI, start, nearestPoint, pt);
|
||||||
(
|
|
||||||
shapeI,
|
|
||||||
start,
|
|
||||||
nearestPoint,
|
|
||||||
pt
|
|
||||||
);
|
|
||||||
|
|
||||||
// Note that intersection of shape might actually be
|
// Note that intersection of shape might actually be
|
||||||
// in a neighbouring box. Since we need to maintain strict
|
// in a neighbouring box. Since we need to maintain strict
|
||||||
@ -1774,7 +1781,9 @@ void Foam::indexedOctree<Type>::traverseNode
|
|||||||
octant,
|
octant,
|
||||||
|
|
||||||
hitInfo,
|
hitInfo,
|
||||||
hitBits
|
hitBits,
|
||||||
|
|
||||||
|
fiOp
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1782,6 +1791,7 @@ void Foam::indexedOctree<Type>::traverseNode
|
|||||||
|
|
||||||
// Find first intersection
|
// Find first intersection
|
||||||
template<class Type>
|
template<class Type>
|
||||||
|
template<class FindIntersectOp>
|
||||||
Foam::pointIndexHit Foam::indexedOctree<Type>::findLine
|
Foam::pointIndexHit Foam::indexedOctree<Type>::findLine
|
||||||
(
|
(
|
||||||
const bool findAny,
|
const bool findAny,
|
||||||
@ -1789,6 +1799,7 @@ Foam::pointIndexHit Foam::indexedOctree<Type>::findLine
|
|||||||
const point& treeEnd,
|
const point& treeEnd,
|
||||||
const label startNodeI,
|
const label startNodeI,
|
||||||
const direction startOctant,
|
const direction startOctant,
|
||||||
|
const FindIntersectOp& fiOp,
|
||||||
const bool verbose
|
const bool verbose
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
@ -1864,7 +1875,9 @@ Foam::pointIndexHit Foam::indexedOctree<Type>::findLine
|
|||||||
octant,
|
octant,
|
||||||
|
|
||||||
hitInfo,
|
hitInfo,
|
||||||
hitFaceID
|
hitFaceID,
|
||||||
|
|
||||||
|
fiOp
|
||||||
);
|
);
|
||||||
|
|
||||||
// Did we hit a triangle?
|
// Did we hit a triangle?
|
||||||
@ -1948,7 +1961,8 @@ Foam::pointIndexHit Foam::indexedOctree<Type>::findLine
|
|||||||
treeEnd,
|
treeEnd,
|
||||||
startNodeI,
|
startNodeI,
|
||||||
startOctant,
|
startOctant,
|
||||||
true //verbose
|
fiOp,
|
||||||
|
true //verbose,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (debug)
|
if (debug)
|
||||||
@ -2007,11 +2021,13 @@ Foam::pointIndexHit Foam::indexedOctree<Type>::findLine
|
|||||||
|
|
||||||
// Find first intersection
|
// Find first intersection
|
||||||
template<class Type>
|
template<class Type>
|
||||||
|
template<class FindIntersectOp>
|
||||||
Foam::pointIndexHit Foam::indexedOctree<Type>::findLine
|
Foam::pointIndexHit Foam::indexedOctree<Type>::findLine
|
||||||
(
|
(
|
||||||
const bool findAny,
|
const bool findAny,
|
||||||
const point& start,
|
const point& start,
|
||||||
const point& end
|
const point& end,
|
||||||
|
const FindIntersectOp& fiOp
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
pointIndexHit hitInfo;
|
pointIndexHit hitInfo;
|
||||||
@ -2069,7 +2085,8 @@ Foam::pointIndexHit Foam::indexedOctree<Type>::findLine
|
|||||||
trackStart,
|
trackStart,
|
||||||
trackEnd,
|
trackEnd,
|
||||||
parentNodeI,
|
parentNodeI,
|
||||||
octant
|
octant,
|
||||||
|
fiOp
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2656,6 +2673,25 @@ Foam::pointIndexHit Foam::indexedOctree<Type>::findNearest
|
|||||||
const point& sample,
|
const point& sample,
|
||||||
const scalar startDistSqr
|
const scalar startDistSqr
|
||||||
) const
|
) const
|
||||||
|
{
|
||||||
|
return findNearest
|
||||||
|
(
|
||||||
|
sample,
|
||||||
|
startDistSqr,
|
||||||
|
typename Type::findNearestOp(*this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <class Type>
|
||||||
|
template <class FindNearestOp>
|
||||||
|
Foam::pointIndexHit Foam::indexedOctree<Type>::findNearest
|
||||||
|
(
|
||||||
|
const point& sample,
|
||||||
|
const scalar startDistSqr,
|
||||||
|
|
||||||
|
const FindNearestOp& fnOp
|
||||||
|
) const
|
||||||
{
|
{
|
||||||
scalar nearestDistSqr = startDistSqr;
|
scalar nearestDistSqr = startDistSqr;
|
||||||
label nearestShapeI = -1;
|
label nearestShapeI = -1;
|
||||||
@ -2670,7 +2706,9 @@ Foam::pointIndexHit Foam::indexedOctree<Type>::findNearest
|
|||||||
|
|
||||||
nearestDistSqr,
|
nearestDistSqr,
|
||||||
nearestShapeI,
|
nearestShapeI,
|
||||||
nearestPoint
|
nearestPoint,
|
||||||
|
|
||||||
|
fnOp
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2685,6 +2723,27 @@ Foam::pointIndexHit Foam::indexedOctree<Type>::findNearest
|
|||||||
treeBoundBox& tightest,
|
treeBoundBox& tightest,
|
||||||
point& linePoint
|
point& linePoint
|
||||||
) const
|
) const
|
||||||
|
{
|
||||||
|
return findNearest
|
||||||
|
(
|
||||||
|
ln,
|
||||||
|
tightest,
|
||||||
|
linePoint,
|
||||||
|
typename Type::findNearestOp(*this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <class Type>
|
||||||
|
template <class FindNearestOp>
|
||||||
|
Foam::pointIndexHit Foam::indexedOctree<Type>::findNearest
|
||||||
|
(
|
||||||
|
const linePointRef& ln,
|
||||||
|
treeBoundBox& tightest,
|
||||||
|
point& linePoint,
|
||||||
|
|
||||||
|
const FindNearestOp& fnOp
|
||||||
|
) const
|
||||||
{
|
{
|
||||||
label nearestShapeI = -1;
|
label nearestShapeI = -1;
|
||||||
point nearestPoint = vector::zero;
|
point nearestPoint = vector::zero;
|
||||||
@ -2699,7 +2758,9 @@ Foam::pointIndexHit Foam::indexedOctree<Type>::findNearest
|
|||||||
tightest,
|
tightest,
|
||||||
nearestShapeI,
|
nearestShapeI,
|
||||||
linePoint,
|
linePoint,
|
||||||
nearestPoint
|
nearestPoint,
|
||||||
|
|
||||||
|
fnOp
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2715,7 +2776,13 @@ Foam::pointIndexHit Foam::indexedOctree<Type>::findLine
|
|||||||
const point& end
|
const point& end
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
return findLine(false, start, end);
|
return findLine
|
||||||
|
(
|
||||||
|
false,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
typename Type::findIntersectOp(*this)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2727,7 +2794,41 @@ Foam::pointIndexHit Foam::indexedOctree<Type>::findLineAny
|
|||||||
const point& end
|
const point& end
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
return findLine(true, start, end);
|
return findLine
|
||||||
|
(
|
||||||
|
true,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
typename Type::findIntersectOp(*this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Find nearest intersection
|
||||||
|
template <class Type>
|
||||||
|
template <class FindIntersectOp>
|
||||||
|
Foam::pointIndexHit Foam::indexedOctree<Type>::findLine
|
||||||
|
(
|
||||||
|
const point& start,
|
||||||
|
const point& end,
|
||||||
|
const FindIntersectOp& fiOp
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return findLine(false, start, end, fiOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Find nearest intersection
|
||||||
|
template <class Type>
|
||||||
|
template <class FindIntersectOp>
|
||||||
|
Foam::pointIndexHit Foam::indexedOctree<Type>::findLineAny
|
||||||
|
(
|
||||||
|
const point& start,
|
||||||
|
const point& end,
|
||||||
|
const FindIntersectOp& fiOp
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return findLine(true, start, end, fiOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -212,6 +212,7 @@ private:
|
|||||||
// Query
|
// Query
|
||||||
|
|
||||||
//- Find nearest point to line.
|
//- Find nearest point to line.
|
||||||
|
template <class FindNearestOp>
|
||||||
void findNearest
|
void findNearest
|
||||||
(
|
(
|
||||||
const label nodeI,
|
const label nodeI,
|
||||||
@ -220,7 +221,9 @@ private:
|
|||||||
treeBoundBox& tightest,
|
treeBoundBox& tightest,
|
||||||
label& nearestShapeI,
|
label& nearestShapeI,
|
||||||
point& linePoint,
|
point& linePoint,
|
||||||
point& nearestPoint
|
point& nearestPoint,
|
||||||
|
|
||||||
|
const FindNearestOp& fnOp
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Return bbox of octant
|
//- Return bbox of octant
|
||||||
@ -294,6 +297,7 @@ private:
|
|||||||
// intersection point.
|
// intersection point.
|
||||||
// findAny=true : return any intersection
|
// findAny=true : return any intersection
|
||||||
// findAny=false: return nearest (to start) intersection
|
// findAny=false: return nearest (to start) intersection
|
||||||
|
template <class FindIntersectOp>
|
||||||
void traverseNode
|
void traverseNode
|
||||||
(
|
(
|
||||||
const bool findAny,
|
const bool findAny,
|
||||||
@ -306,10 +310,13 @@ private:
|
|||||||
const direction octantI,
|
const direction octantI,
|
||||||
|
|
||||||
pointIndexHit& hitInfo,
|
pointIndexHit& hitInfo,
|
||||||
direction& faceID
|
direction& faceID,
|
||||||
|
|
||||||
|
const FindIntersectOp& fiOp
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Find any or nearest intersection
|
//- Find any or nearest intersection
|
||||||
|
template <class FindIntersectOp>
|
||||||
pointIndexHit findLine
|
pointIndexHit findLine
|
||||||
(
|
(
|
||||||
const bool findAny,
|
const bool findAny,
|
||||||
@ -317,6 +324,7 @@ private:
|
|||||||
const point& treeEnd,
|
const point& treeEnd,
|
||||||
const label startNodeI,
|
const label startNodeI,
|
||||||
const direction startOctantI,
|
const direction startOctantI,
|
||||||
|
const FindIntersectOp& fiOp,
|
||||||
const bool verbose = false
|
const bool verbose = false
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
@ -328,11 +336,13 @@ private:
|
|||||||
// ) const;
|
// ) const;
|
||||||
|
|
||||||
//- Find any or nearest intersection of line between start and end.
|
//- Find any or nearest intersection of line between start and end.
|
||||||
|
template <class FindIntersectOp>
|
||||||
pointIndexHit findLine
|
pointIndexHit findLine
|
||||||
(
|
(
|
||||||
const bool findAny,
|
const bool findAny,
|
||||||
const point& start,
|
const point& start,
|
||||||
const point& end
|
const point& end,
|
||||||
|
const FindIntersectOp& fiOp
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Find all elements intersecting box.
|
//- Find all elements intersecting box.
|
||||||
@ -528,15 +538,24 @@ public:
|
|||||||
|
|
||||||
// Queries
|
// Queries
|
||||||
|
|
||||||
|
pointIndexHit findNearest
|
||||||
|
(
|
||||||
|
const point& sample,
|
||||||
|
const scalar nearestDistSqr
|
||||||
|
) const;
|
||||||
|
|
||||||
//- Calculate nearest point on nearest shape.
|
//- Calculate nearest point on nearest shape.
|
||||||
// Returns
|
// Returns
|
||||||
// - bool : any point found nearer than nearestDistSqr
|
// - bool : any point found nearer than nearestDistSqr
|
||||||
// - label: index in shapes
|
// - label: index in shapes
|
||||||
// - point: actual nearest point found
|
// - point: actual nearest point found
|
||||||
|
template <class FindNearestOp>
|
||||||
pointIndexHit findNearest
|
pointIndexHit findNearest
|
||||||
(
|
(
|
||||||
const point& sample,
|
const point& sample,
|
||||||
const scalar nearestDistSqr
|
const scalar nearestDistSqr,
|
||||||
|
|
||||||
|
const FindNearestOp& fnOp
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
// bool findAnyOverlap
|
// bool findAnyOverlap
|
||||||
@ -553,6 +572,7 @@ public:
|
|||||||
// ) const;
|
// ) const;
|
||||||
|
|
||||||
//- Low level: calculate nearest starting from subnode.
|
//- Low level: calculate nearest starting from subnode.
|
||||||
|
template <class FindNearestOp>
|
||||||
void findNearest
|
void findNearest
|
||||||
(
|
(
|
||||||
const label nodeI,
|
const label nodeI,
|
||||||
@ -560,7 +580,9 @@ public:
|
|||||||
|
|
||||||
scalar& nearestDistSqr,
|
scalar& nearestDistSqr,
|
||||||
label& nearestShapeI,
|
label& nearestShapeI,
|
||||||
point& nearestPoint
|
point& nearestPoint,
|
||||||
|
|
||||||
|
const FindNearestOp& fnOp
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Find nearest to line.
|
//- Find nearest to line.
|
||||||
@ -577,6 +599,16 @@ public:
|
|||||||
point& linePoint
|
point& linePoint
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
template <class FindNearestOp>
|
||||||
|
pointIndexHit findNearest
|
||||||
|
(
|
||||||
|
const linePointRef& ln,
|
||||||
|
treeBoundBox& tightest,
|
||||||
|
point& linePoint,
|
||||||
|
|
||||||
|
const FindNearestOp& fnOp
|
||||||
|
) const;
|
||||||
|
|
||||||
//- Find nearest intersection of line between start and end.
|
//- Find nearest intersection of line between start and end.
|
||||||
pointIndexHit findLine
|
pointIndexHit findLine
|
||||||
(
|
(
|
||||||
@ -591,6 +623,24 @@ public:
|
|||||||
const point& end
|
const point& end
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
//- Find nearest intersection of line between start and end.
|
||||||
|
template <class FindIntersectOp>
|
||||||
|
pointIndexHit findLine
|
||||||
|
(
|
||||||
|
const point& start,
|
||||||
|
const point& end,
|
||||||
|
const FindIntersectOp& fiOp
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Find any intersection of line between start and end.
|
||||||
|
template <class FindIntersectOp>
|
||||||
|
pointIndexHit findLineAny
|
||||||
|
(
|
||||||
|
const point& start,
|
||||||
|
const point& end,
|
||||||
|
const FindIntersectOp& fiOp
|
||||||
|
) const;
|
||||||
|
|
||||||
//- Find (in no particular order) indices of all shapes inside or
|
//- Find (in no particular order) indices of all shapes inside or
|
||||||
// overlapping bounding box (i.e. all shapes not outside box)
|
// overlapping bounding box (i.e. all shapes not outside box)
|
||||||
labelList findBox(const treeBoundBox& bb) const;
|
labelList findBox(const treeBoundBox& bb) const;
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -133,6 +133,24 @@ Foam::treeDataCell::treeDataCell
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::treeDataCell::findNearestOp::findNearestOp
|
||||||
|
(
|
||||||
|
const indexedOctree<treeDataCell>& tree
|
||||||
|
)
|
||||||
|
:
|
||||||
|
tree_(tree)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::treeDataCell::findIntersectOp::findIntersectOp
|
||||||
|
(
|
||||||
|
const indexedOctree<treeDataCell>& tree
|
||||||
|
)
|
||||||
|
:
|
||||||
|
tree_(tree)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::pointField Foam::treeDataCell::shapePoints() const
|
Foam::pointField Foam::treeDataCell::shapePoints() const
|
||||||
@ -175,7 +193,7 @@ bool Foam::treeDataCell::contains
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::treeDataCell::findNearest
|
void Foam::treeDataCell::findNearestOp::operator()
|
||||||
(
|
(
|
||||||
const labelUList& indices,
|
const labelUList& indices,
|
||||||
const point& sample,
|
const point& sample,
|
||||||
@ -185,23 +203,51 @@ void Foam::treeDataCell::findNearest
|
|||||||
point& nearestPoint
|
point& nearestPoint
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
|
const treeDataCell& shape = tree_.shapes();
|
||||||
|
|
||||||
forAll(indices, i)
|
forAll(indices, i)
|
||||||
{
|
{
|
||||||
label index = indices[i];
|
label index = indices[i];
|
||||||
label cellI = cellLabels_[index];
|
label cellI = shape.cellLabels()[index];
|
||||||
scalar distSqr = magSqr(sample - mesh_.cellCentres()[cellI]);
|
scalar distSqr = magSqr(sample - shape.mesh().cellCentres()[cellI]);
|
||||||
|
|
||||||
if (distSqr < nearestDistSqr)
|
if (distSqr < nearestDistSqr)
|
||||||
{
|
{
|
||||||
nearestDistSqr = distSqr;
|
nearestDistSqr = distSqr;
|
||||||
minIndex = index;
|
minIndex = index;
|
||||||
nearestPoint = mesh_.cellCentres()[cellI];
|
nearestPoint = shape.mesh().cellCentres()[cellI];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::treeDataCell::intersects
|
void Foam::treeDataCell::findNearestOp::operator()
|
||||||
|
(
|
||||||
|
const labelUList& indices,
|
||||||
|
const linePointRef& ln,
|
||||||
|
|
||||||
|
treeBoundBox& tightest,
|
||||||
|
label& minIndex,
|
||||||
|
point& linePoint,
|
||||||
|
point& nearestPoint
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
notImplemented
|
||||||
|
(
|
||||||
|
"treeDataCell::findNearestOp::operator()"
|
||||||
|
"("
|
||||||
|
" const labelUList&,"
|
||||||
|
" const linePointRef&,"
|
||||||
|
" treeBoundBox&,"
|
||||||
|
" label&,"
|
||||||
|
" point&,"
|
||||||
|
" point&"
|
||||||
|
") const"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::treeDataCell::findIntersectOp::operator()
|
||||||
(
|
(
|
||||||
const label index,
|
const label index,
|
||||||
const point& start,
|
const point& start,
|
||||||
@ -209,10 +255,12 @@ bool Foam::treeDataCell::intersects
|
|||||||
point& intersectionPoint
|
point& intersectionPoint
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
|
const treeDataCell& shape = tree_.shapes();
|
||||||
|
|
||||||
// Do quick rejection test
|
// Do quick rejection test
|
||||||
if (cacheBb_)
|
if (shape.cacheBb_)
|
||||||
{
|
{
|
||||||
const treeBoundBox& cellBb = bbs_[index];
|
const treeBoundBox& cellBb = shape.bbs_[index];
|
||||||
|
|
||||||
if ((cellBb.posBits(start) & cellBb.posBits(end)) != 0)
|
if ((cellBb.posBits(start) & cellBb.posBits(end)) != 0)
|
||||||
{
|
{
|
||||||
@ -222,7 +270,7 @@ bool Foam::treeDataCell::intersects
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const treeBoundBox cellBb = calcCellBb(cellLabels_[index]);
|
const treeBoundBox cellBb = shape.calcCellBb(shape.cellLabels_[index]);
|
||||||
|
|
||||||
if ((cellBb.posBits(start) & cellBb.posBits(end)) != 0)
|
if ((cellBb.posBits(start) & cellBb.posBits(end)) != 0)
|
||||||
{
|
{
|
||||||
@ -238,7 +286,7 @@ bool Foam::treeDataCell::intersects
|
|||||||
// Disable picking up intersections behind us.
|
// Disable picking up intersections behind us.
|
||||||
scalar oldTol = intersection::setPlanarTol(0.0);
|
scalar oldTol = intersection::setPlanarTol(0.0);
|
||||||
|
|
||||||
const cell& cFaces = mesh_.cells()[cellLabels_[index]];
|
const cell& cFaces = shape.mesh_.cells()[shape.cellLabels_[index]];
|
||||||
|
|
||||||
const vector dir(end - start);
|
const vector dir(end - start);
|
||||||
scalar minDistSqr = magSqr(dir);
|
scalar minDistSqr = magSqr(dir);
|
||||||
@ -246,13 +294,13 @@ bool Foam::treeDataCell::intersects
|
|||||||
|
|
||||||
forAll(cFaces, i)
|
forAll(cFaces, i)
|
||||||
{
|
{
|
||||||
const face& f = mesh_.faces()[cFaces[i]];
|
const face& f = shape.mesh_.faces()[cFaces[i]];
|
||||||
|
|
||||||
pointHit inter = f.ray
|
pointHit inter = f.ray
|
||||||
(
|
(
|
||||||
start,
|
start,
|
||||||
dir,
|
dir,
|
||||||
mesh_.points(),
|
shape.mesh_.points(),
|
||||||
intersection::HALF_RAY
|
intersection::HALF_RAY
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -80,6 +80,56 @@ class treeDataCell
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
class findNearestOp
|
||||||
|
{
|
||||||
|
const indexedOctree<treeDataCell>& tree_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
findNearestOp(const indexedOctree<treeDataCell>& tree);
|
||||||
|
|
||||||
|
void operator()
|
||||||
|
(
|
||||||
|
const labelUList& indices,
|
||||||
|
const point& sample,
|
||||||
|
|
||||||
|
scalar& nearestDistSqr,
|
||||||
|
label& minIndex,
|
||||||
|
point& nearestPoint
|
||||||
|
) const;
|
||||||
|
|
||||||
|
void operator()
|
||||||
|
(
|
||||||
|
const labelUList& indices,
|
||||||
|
const linePointRef& ln,
|
||||||
|
|
||||||
|
treeBoundBox& tightest,
|
||||||
|
label& minIndex,
|
||||||
|
point& linePoint,
|
||||||
|
point& nearestPoint
|
||||||
|
) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class findIntersectOp
|
||||||
|
{
|
||||||
|
const indexedOctree<treeDataCell>& tree_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
findIntersectOp(const indexedOctree<treeDataCell>& tree);
|
||||||
|
|
||||||
|
bool operator()
|
||||||
|
(
|
||||||
|
const label index,
|
||||||
|
const point& start,
|
||||||
|
const point& end,
|
||||||
|
point& intersectionPoint
|
||||||
|
) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Declare name of the class and its debug switch
|
// Declare name of the class and its debug switch
|
||||||
ClassName("treeDataCell");
|
ClassName("treeDataCell");
|
||||||
|
|
||||||
@ -173,49 +223,6 @@ public:
|
|||||||
const label index,
|
const label index,
|
||||||
const point& sample
|
const point& sample
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Calculates nearest (to sample) point in shape.
|
|
||||||
// Returns actual point and distance (squared)
|
|
||||||
void findNearest
|
|
||||||
(
|
|
||||||
const labelUList& indices,
|
|
||||||
const point& sample,
|
|
||||||
|
|
||||||
scalar& nearestDistSqr,
|
|
||||||
label& nearestIndex,
|
|
||||||
point& nearestPoint
|
|
||||||
) const;
|
|
||||||
|
|
||||||
//- Calculates nearest (to line) point in shape.
|
|
||||||
// Returns point and distance (squared)
|
|
||||||
void findNearest
|
|
||||||
(
|
|
||||||
const labelUList& indices,
|
|
||||||
const linePointRef& ln,
|
|
||||||
|
|
||||||
treeBoundBox& tightest,
|
|
||||||
label& minIndex,
|
|
||||||
point& linePoint,
|
|
||||||
point& nearestPoint
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
notImplemented
|
|
||||||
(
|
|
||||||
"treeDataCell::findNearest"
|
|
||||||
"(const labelUList&, const linePointRef&, ..)"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Calculate intersection of shape with ray. Sets result
|
|
||||||
// accordingly
|
|
||||||
bool intersects
|
|
||||||
(
|
|
||||||
const label index,
|
|
||||||
const point& start,
|
|
||||||
const point& end,
|
|
||||||
point& result
|
|
||||||
) const;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -924,6 +924,11 @@ Foam::labelList Foam::boundaryMesh::getNearest
|
|||||||
bbMax.y() += 2*tol;
|
bbMax.y() += 2*tol;
|
||||||
bbMax.z() += 2*tol;
|
bbMax.z() += 2*tol;
|
||||||
|
|
||||||
|
const scalar planarTol =
|
||||||
|
indexedOctree<treeDataPrimitivePatch<uindirectPrimitivePatch> >::
|
||||||
|
perturbTol();
|
||||||
|
|
||||||
|
|
||||||
// Create the octrees
|
// Create the octrees
|
||||||
indexedOctree
|
indexedOctree
|
||||||
<
|
<
|
||||||
@ -933,7 +938,8 @@ Foam::labelList Foam::boundaryMesh::getNearest
|
|||||||
treeDataPrimitivePatch<uindirectPrimitivePatch>
|
treeDataPrimitivePatch<uindirectPrimitivePatch>
|
||||||
(
|
(
|
||||||
false, // cacheBb
|
false, // cacheBb
|
||||||
leftPatch
|
leftPatch,
|
||||||
|
planarTol
|
||||||
),
|
),
|
||||||
overallBb,
|
overallBb,
|
||||||
10, // maxLevel
|
10, // maxLevel
|
||||||
@ -948,7 +954,8 @@ Foam::labelList Foam::boundaryMesh::getNearest
|
|||||||
treeDataPrimitivePatch<uindirectPrimitivePatch>
|
treeDataPrimitivePatch<uindirectPrimitivePatch>
|
||||||
(
|
(
|
||||||
false, // cacheBb
|
false, // cacheBb
|
||||||
rightPatch
|
rightPatch,
|
||||||
|
planarTol
|
||||||
),
|
),
|
||||||
overallBb,
|
overallBb,
|
||||||
10, // maxLevel
|
10, // maxLevel
|
||||||
|
|||||||
@ -241,7 +241,7 @@ surfaceInterpolationScheme<Type>::interpolate
|
|||||||
|
|
||||||
|
|
||||||
//- Return the face-interpolate of the given cell field
|
//- Return the face-interpolate of the given cell field
|
||||||
// with the given weigting factors
|
// with the given weighting factors
|
||||||
template<class Type>
|
template<class Type>
|
||||||
tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
|
tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
|
||||||
surfaceInterpolationScheme<Type>::interpolate
|
surfaceInterpolationScheme<Type>::interpolate
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -34,6 +34,7 @@ License
|
|||||||
#include "ListOps.H"
|
#include "ListOps.H"
|
||||||
#include "meshTools.H"
|
#include "meshTools.H"
|
||||||
#include "cpuTime.H"
|
#include "cpuTime.H"
|
||||||
|
#include "triSurface.H"
|
||||||
#include "globalMeshData.H"
|
#include "globalMeshData.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -107,9 +107,7 @@ namespace Foam
|
|||||||
class triSurfaceSearch;
|
class triSurfaceSearch;
|
||||||
class meshSearch;
|
class meshSearch;
|
||||||
class polyMesh;
|
class polyMesh;
|
||||||
class polyMesh;
|
|
||||||
class primitiveMesh;
|
class primitiveMesh;
|
||||||
class triSurface;
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class cellClassification Declaration
|
Class cellClassification Declaration
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -96,6 +96,24 @@ Foam::treeDataEdge::treeDataEdge
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::treeDataEdge::findNearestOp::findNearestOp
|
||||||
|
(
|
||||||
|
const indexedOctree<treeDataEdge>& tree
|
||||||
|
)
|
||||||
|
:
|
||||||
|
tree_(tree)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::treeDataEdge::findIntersectOp::findIntersectOp
|
||||||
|
(
|
||||||
|
const indexedOctree<treeDataEdge>& tree
|
||||||
|
)
|
||||||
|
:
|
||||||
|
tree_(tree)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::pointField Foam::treeDataEdge::shapePoints() const
|
Foam::pointField Foam::treeDataEdge::shapePoints() const
|
||||||
@ -165,9 +183,7 @@ bool Foam::treeDataEdge::overlaps
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex,
|
void Foam::treeDataEdge::findNearestOp::operator()
|
||||||
// nearestPoint.
|
|
||||||
void Foam::treeDataEdge::findNearest
|
|
||||||
(
|
(
|
||||||
const labelUList& indices,
|
const labelUList& indices,
|
||||||
const point& sample,
|
const point& sample,
|
||||||
@ -177,13 +193,15 @@ void Foam::treeDataEdge::findNearest
|
|||||||
point& nearestPoint
|
point& nearestPoint
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
|
const treeDataEdge& shape = tree_.shapes();
|
||||||
|
|
||||||
forAll(indices, i)
|
forAll(indices, i)
|
||||||
{
|
{
|
||||||
const label index = indices[i];
|
const label index = indices[i];
|
||||||
|
|
||||||
const edge& e = edges_[edgeLabels_[index]];
|
const edge& e = shape.edges()[shape.edgeLabels()[index]];
|
||||||
|
|
||||||
pointHit nearHit = e.line(points_).nearestDist(sample);
|
pointHit nearHit = e.line(shape.points()).nearestDist(sample);
|
||||||
|
|
||||||
scalar distSqr = sqr(nearHit.distance());
|
scalar distSqr = sqr(nearHit.distance());
|
||||||
|
|
||||||
@ -197,9 +215,7 @@ void Foam::treeDataEdge::findNearest
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//- Calculates nearest (to line) point in shape.
|
void Foam::treeDataEdge::findNearestOp::operator()
|
||||||
// Returns point and distance (squared)
|
|
||||||
void Foam::treeDataEdge::findNearest
|
|
||||||
(
|
(
|
||||||
const labelUList& indices,
|
const labelUList& indices,
|
||||||
const linePointRef& ln,
|
const linePointRef& ln,
|
||||||
@ -210,6 +226,8 @@ void Foam::treeDataEdge::findNearest
|
|||||||
point& nearestPoint
|
point& nearestPoint
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
|
const treeDataEdge& shape = tree_.shapes();
|
||||||
|
|
||||||
// Best so far
|
// Best so far
|
||||||
scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
|
scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
|
||||||
|
|
||||||
@ -217,13 +235,13 @@ void Foam::treeDataEdge::findNearest
|
|||||||
{
|
{
|
||||||
const label index = indices[i];
|
const label index = indices[i];
|
||||||
|
|
||||||
const edge& e = edges_[edgeLabels_[index]];
|
const edge& e = shape.edges()[shape.edgeLabels()[index]];
|
||||||
|
|
||||||
// Note: could do bb test ? Worthwhile?
|
// Note: could do bb test ? Worthwhile?
|
||||||
|
|
||||||
// Nearest point on line
|
// Nearest point on line
|
||||||
point ePoint, lnPt;
|
point ePoint, lnPt;
|
||||||
scalar dist = e.line(points_).nearestDist(ln, ePoint, lnPt);
|
scalar dist = e.line(shape.points()).nearestDist(ln, ePoint, lnPt);
|
||||||
scalar distSqr = sqr(dist);
|
scalar distSqr = sqr(dist);
|
||||||
|
|
||||||
if (distSqr < nearestDistSqr)
|
if (distSqr < nearestDistSqr)
|
||||||
@ -252,4 +270,21 @@ void Foam::treeDataEdge::findNearest
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::treeDataEdge::findIntersectOp::operator()
|
||||||
|
(
|
||||||
|
const label index,
|
||||||
|
const point& start,
|
||||||
|
const point& end,
|
||||||
|
point& result
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
notImplemented
|
||||||
|
(
|
||||||
|
"treeDataEdge::intersects(const label, const point&,"
|
||||||
|
"const point&, point&)"
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -86,6 +86,58 @@ class treeDataEdge
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
class findNearestOp
|
||||||
|
{
|
||||||
|
const indexedOctree<treeDataEdge>& tree_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
findNearestOp(const indexedOctree<treeDataEdge>& tree);
|
||||||
|
|
||||||
|
void operator()
|
||||||
|
(
|
||||||
|
const labelUList& indices,
|
||||||
|
const point& sample,
|
||||||
|
|
||||||
|
scalar& nearestDistSqr,
|
||||||
|
label& minIndex,
|
||||||
|
point& nearestPoint
|
||||||
|
) const;
|
||||||
|
|
||||||
|
void operator()
|
||||||
|
(
|
||||||
|
const labelUList& indices,
|
||||||
|
const linePointRef& ln,
|
||||||
|
|
||||||
|
treeBoundBox& tightest,
|
||||||
|
label& minIndex,
|
||||||
|
point& linePoint,
|
||||||
|
point& nearestPoint
|
||||||
|
) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class findIntersectOp
|
||||||
|
{
|
||||||
|
const indexedOctree<treeDataEdge>& tree_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
findIntersectOp(const indexedOctree<treeDataEdge>& tree);
|
||||||
|
|
||||||
|
//- Calculate intersection of triangle with ray. Sets result
|
||||||
|
// accordingly
|
||||||
|
bool operator()
|
||||||
|
(
|
||||||
|
const label index,
|
||||||
|
const point& start,
|
||||||
|
const point& end,
|
||||||
|
point& intersectionPoint
|
||||||
|
) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Declare name of the class and its debug switch
|
// Declare name of the class and its debug switch
|
||||||
ClassName("treeDataEdge");
|
ClassName("treeDataEdge");
|
||||||
|
|
||||||
@ -116,6 +168,16 @@ public:
|
|||||||
|
|
||||||
// Access
|
// Access
|
||||||
|
|
||||||
|
const edgeList& edges() const
|
||||||
|
{
|
||||||
|
return edges_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pointField& points() const
|
||||||
|
{
|
||||||
|
return points_;
|
||||||
|
}
|
||||||
|
|
||||||
const labelList& edgeLabels() const
|
const labelList& edgeLabels() const
|
||||||
{
|
{
|
||||||
return edgeLabels_;
|
return edgeLabels_;
|
||||||
@ -155,50 +217,6 @@ public:
|
|||||||
const point& centre,
|
const point& centre,
|
||||||
const scalar radiusSqr
|
const scalar radiusSqr
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Calculates nearest (to sample) point in shape.
|
|
||||||
// Returns actual point and distance (squared)
|
|
||||||
void findNearest
|
|
||||||
(
|
|
||||||
const labelUList& indices,
|
|
||||||
const point& sample,
|
|
||||||
|
|
||||||
scalar& nearestDistSqr,
|
|
||||||
label& nearestIndex,
|
|
||||||
point& nearestPoint
|
|
||||||
) const;
|
|
||||||
|
|
||||||
//- Calculates nearest (to line) point in shape.
|
|
||||||
// Returns point and distance (squared)
|
|
||||||
void findNearest
|
|
||||||
(
|
|
||||||
const labelUList& indices,
|
|
||||||
const linePointRef& ln,
|
|
||||||
|
|
||||||
treeBoundBox& tightest,
|
|
||||||
label& minIndex,
|
|
||||||
point& linePoint,
|
|
||||||
point& nearestPoint
|
|
||||||
) const;
|
|
||||||
|
|
||||||
//- Calculate intersection of shape with ray. Sets result
|
|
||||||
// accordingly
|
|
||||||
bool intersects
|
|
||||||
(
|
|
||||||
const label index,
|
|
||||||
const point& start,
|
|
||||||
const point& end,
|
|
||||||
point& result
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
notImplemented
|
|
||||||
(
|
|
||||||
"treeDataEdge::intersects(const label, const point&,"
|
|
||||||
"const point&, point&)"
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -145,6 +145,24 @@ Foam::treeDataFace::treeDataFace
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::treeDataFace::findNearestOp::findNearestOp
|
||||||
|
(
|
||||||
|
const indexedOctree<treeDataFace>& tree
|
||||||
|
)
|
||||||
|
:
|
||||||
|
tree_(tree)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::treeDataFace::findIntersectOp::findIntersectOp
|
||||||
|
(
|
||||||
|
const indexedOctree<treeDataFace>& tree
|
||||||
|
)
|
||||||
|
:
|
||||||
|
tree_(tree)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::pointField Foam::treeDataFace::shapePoints() const
|
Foam::pointField Foam::treeDataFace::shapePoints() const
|
||||||
@ -477,9 +495,7 @@ bool Foam::treeDataFace::overlaps
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex,
|
void Foam::treeDataFace::findNearestOp::operator()
|
||||||
// nearestPoint.
|
|
||||||
void Foam::treeDataFace::findNearest
|
|
||||||
(
|
(
|
||||||
const labelUList& indices,
|
const labelUList& indices,
|
||||||
const point& sample,
|
const point& sample,
|
||||||
@ -489,13 +505,15 @@ void Foam::treeDataFace::findNearest
|
|||||||
point& nearestPoint
|
point& nearestPoint
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
|
const treeDataFace& shape = tree_.shapes();
|
||||||
|
|
||||||
forAll(indices, i)
|
forAll(indices, i)
|
||||||
{
|
{
|
||||||
const label index = indices[i];
|
const label index = indices[i];
|
||||||
|
|
||||||
const face& f = mesh_.faces()[faceLabels_[index]];
|
const face& f = shape.mesh().faces()[shape.faceLabels()[index]];
|
||||||
|
|
||||||
pointHit nearHit = f.nearestPoint(sample, mesh_.points());
|
pointHit nearHit = f.nearestPoint(sample, shape.mesh().points());
|
||||||
scalar distSqr = sqr(nearHit.distance());
|
scalar distSqr = sqr(nearHit.distance());
|
||||||
|
|
||||||
if (distSqr < nearestDistSqr)
|
if (distSqr < nearestDistSqr)
|
||||||
@ -508,7 +526,33 @@ void Foam::treeDataFace::findNearest
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::treeDataFace::intersects
|
void Foam::treeDataFace::findNearestOp::operator()
|
||||||
|
(
|
||||||
|
const labelUList& indices,
|
||||||
|
const linePointRef& ln,
|
||||||
|
|
||||||
|
treeBoundBox& tightest,
|
||||||
|
label& minIndex,
|
||||||
|
point& linePoint,
|
||||||
|
point& nearestPoint
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
notImplemented
|
||||||
|
(
|
||||||
|
"treeDataFace::findNearestOp::operator()"
|
||||||
|
"("
|
||||||
|
" const labelUList&,"
|
||||||
|
" const linePointRef&,"
|
||||||
|
" treeBoundBox&,"
|
||||||
|
" label&,"
|
||||||
|
" point&,"
|
||||||
|
" point&"
|
||||||
|
") const"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::treeDataFace::findIntersectOp::operator()
|
||||||
(
|
(
|
||||||
const label index,
|
const label index,
|
||||||
const point& start,
|
const point& start,
|
||||||
@ -516,10 +560,12 @@ bool Foam::treeDataFace::intersects
|
|||||||
point& intersectionPoint
|
point& intersectionPoint
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
|
const treeDataFace& shape = tree_.shapes();
|
||||||
|
|
||||||
// Do quick rejection test
|
// Do quick rejection test
|
||||||
if (cacheBb_)
|
if (shape.cacheBb_)
|
||||||
{
|
{
|
||||||
const treeBoundBox& faceBb = bbs_[index];
|
const treeBoundBox& faceBb = shape.bbs_[index];
|
||||||
|
|
||||||
if ((faceBb.posBits(start) & faceBb.posBits(end)) != 0)
|
if ((faceBb.posBits(start) & faceBb.posBits(end)) != 0)
|
||||||
{
|
{
|
||||||
@ -528,16 +574,16 @@ bool Foam::treeDataFace::intersects
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const label faceI = faceLabels_[index];
|
const label faceI = shape.faceLabels_[index];
|
||||||
|
|
||||||
const vector dir(end - start);
|
const vector dir(end - start);
|
||||||
|
|
||||||
pointHit inter = mesh_.faces()[faceI].intersection
|
pointHit inter = shape.mesh_.faces()[faceI].intersection
|
||||||
(
|
(
|
||||||
start,
|
start,
|
||||||
dir,
|
dir,
|
||||||
mesh_.faceCentres()[faceI],
|
shape.mesh_.faceCentres()[faceI],
|
||||||
mesh_.points(),
|
shape.mesh_.points(),
|
||||||
intersection::HALF_RAY
|
intersection::HALF_RAY
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -39,6 +39,7 @@ SourceFiles
|
|||||||
#include "indexedOctree.H"
|
#include "indexedOctree.H"
|
||||||
#include "treeBoundBoxList.H"
|
#include "treeBoundBoxList.H"
|
||||||
#include "PackedBoolList.H"
|
#include "PackedBoolList.H"
|
||||||
|
#include "primitiveMesh.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ namespace Foam
|
|||||||
{
|
{
|
||||||
|
|
||||||
// Forward declaration of classes
|
// Forward declaration of classes
|
||||||
class primitiveMesh;
|
//class primitiveMesh;
|
||||||
//template<class Type> class indexedOctree;
|
//template<class Type> class indexedOctree;
|
||||||
class polyPatch;
|
class polyPatch;
|
||||||
|
|
||||||
@ -90,6 +91,58 @@ class treeDataFace
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
class findNearestOp
|
||||||
|
{
|
||||||
|
const indexedOctree<treeDataFace>& tree_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
findNearestOp(const indexedOctree<treeDataFace>& tree);
|
||||||
|
|
||||||
|
void operator()
|
||||||
|
(
|
||||||
|
const labelUList& indices,
|
||||||
|
const point& sample,
|
||||||
|
|
||||||
|
scalar& nearestDistSqr,
|
||||||
|
label& minIndex,
|
||||||
|
point& nearestPoint
|
||||||
|
) const;
|
||||||
|
|
||||||
|
void operator()
|
||||||
|
(
|
||||||
|
const labelUList& indices,
|
||||||
|
const linePointRef& ln,
|
||||||
|
|
||||||
|
treeBoundBox& tightest,
|
||||||
|
label& minIndex,
|
||||||
|
point& linePoint,
|
||||||
|
point& nearestPoint
|
||||||
|
) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class findIntersectOp
|
||||||
|
{
|
||||||
|
const indexedOctree<treeDataFace>& tree_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
findIntersectOp(const indexedOctree<treeDataFace>& tree);
|
||||||
|
|
||||||
|
//- Calculate intersection of triangle with ray. Sets result
|
||||||
|
// accordingly
|
||||||
|
bool operator()
|
||||||
|
(
|
||||||
|
const label index,
|
||||||
|
const point& start,
|
||||||
|
const point& end,
|
||||||
|
point& intersectionPoint
|
||||||
|
) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Declare name of the class and its debug switch
|
// Declare name of the class and its debug switch
|
||||||
ClassName("treeDataFace");
|
ClassName("treeDataFace");
|
||||||
|
|
||||||
@ -159,49 +212,6 @@ public:
|
|||||||
const label index,
|
const label index,
|
||||||
const treeBoundBox& sampleBb
|
const treeBoundBox& sampleBb
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Calculates nearest (to sample) point in shape.
|
|
||||||
// Returns actual point and distance (squared)
|
|
||||||
void findNearest
|
|
||||||
(
|
|
||||||
const labelUList& indices,
|
|
||||||
const point& sample,
|
|
||||||
|
|
||||||
scalar& nearestDistSqr,
|
|
||||||
label& nearestIndex,
|
|
||||||
point& nearestPoint
|
|
||||||
) const;
|
|
||||||
|
|
||||||
//- Calculates nearest (to line) point in shape.
|
|
||||||
// Returns point and distance (squared)
|
|
||||||
void findNearest
|
|
||||||
(
|
|
||||||
const labelUList& indices,
|
|
||||||
const linePointRef& ln,
|
|
||||||
|
|
||||||
treeBoundBox& tightest,
|
|
||||||
label& minIndex,
|
|
||||||
point& linePoint,
|
|
||||||
point& nearestPoint
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
notImplemented
|
|
||||||
(
|
|
||||||
"treeDataFace::findNearest"
|
|
||||||
"(const labelUList&, const linePointRef&, ..)"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Calculate intersection of shape with ray. Sets result
|
|
||||||
// accordingly
|
|
||||||
bool intersects
|
|
||||||
(
|
|
||||||
const label index,
|
|
||||||
const point& start,
|
|
||||||
const point& end,
|
|
||||||
point& result
|
|
||||||
) const;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -57,6 +57,24 @@ Foam::treeDataPoint::treeDataPoint
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::treeDataPoint::findNearestOp::findNearestOp
|
||||||
|
(
|
||||||
|
const indexedOctree<treeDataPoint>& tree
|
||||||
|
)
|
||||||
|
:
|
||||||
|
tree_(tree)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::treeDataPoint::findIntersectOp::findIntersectOp
|
||||||
|
(
|
||||||
|
const indexedOctree<treeDataPoint>& tree
|
||||||
|
)
|
||||||
|
:
|
||||||
|
tree_(tree)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::pointField Foam::treeDataPoint::shapePoints() const
|
Foam::pointField Foam::treeDataPoint::shapePoints() const
|
||||||
@ -115,9 +133,7 @@ bool Foam::treeDataPoint::overlaps
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex,
|
void Foam::treeDataPoint::findNearestOp::operator()
|
||||||
// nearestPoint.
|
|
||||||
void Foam::treeDataPoint::findNearest
|
|
||||||
(
|
(
|
||||||
const labelUList& indices,
|
const labelUList& indices,
|
||||||
const point& sample,
|
const point& sample,
|
||||||
@ -127,12 +143,19 @@ void Foam::treeDataPoint::findNearest
|
|||||||
point& nearestPoint
|
point& nearestPoint
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
|
const treeDataPoint& shape = tree_.shapes();
|
||||||
|
|
||||||
forAll(indices, i)
|
forAll(indices, i)
|
||||||
{
|
{
|
||||||
const label index = indices[i];
|
const label index = indices[i];
|
||||||
label pointI = (useSubset_ ? pointLabels_[index] : index);
|
label pointI =
|
||||||
|
(
|
||||||
|
shape.useSubset()
|
||||||
|
? shape.pointLabels()[index]
|
||||||
|
: index
|
||||||
|
);
|
||||||
|
|
||||||
const point& pt = points_[pointI];
|
const point& pt = shape.points()[pointI];
|
||||||
|
|
||||||
scalar distSqr = magSqr(pt - sample);
|
scalar distSqr = magSqr(pt - sample);
|
||||||
|
|
||||||
@ -146,9 +169,7 @@ void Foam::treeDataPoint::findNearest
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//- Calculates nearest (to line) point in shape.
|
void Foam::treeDataPoint::findNearestOp::operator()
|
||||||
// Returns point and distance (squared)
|
|
||||||
void Foam::treeDataPoint::findNearest
|
|
||||||
(
|
(
|
||||||
const labelUList& indices,
|
const labelUList& indices,
|
||||||
const linePointRef& ln,
|
const linePointRef& ln,
|
||||||
@ -159,6 +180,8 @@ void Foam::treeDataPoint::findNearest
|
|||||||
point& nearestPoint
|
point& nearestPoint
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
|
const treeDataPoint& shape = tree_.shapes();
|
||||||
|
|
||||||
// Best so far
|
// Best so far
|
||||||
scalar nearestDistSqr = GREAT;
|
scalar nearestDistSqr = GREAT;
|
||||||
if (minIndex >= 0)
|
if (minIndex >= 0)
|
||||||
@ -169,9 +192,14 @@ void Foam::treeDataPoint::findNearest
|
|||||||
forAll(indices, i)
|
forAll(indices, i)
|
||||||
{
|
{
|
||||||
const label index = indices[i];
|
const label index = indices[i];
|
||||||
label pointI = (useSubset_ ? pointLabels_[index] : index);
|
label pointI =
|
||||||
|
(
|
||||||
|
shape.useSubset()
|
||||||
|
? shape.pointLabels()[index]
|
||||||
|
: index
|
||||||
|
);
|
||||||
|
|
||||||
const point& shapePt = points_[pointI];
|
const point& shapePt = shape.points()[pointI];
|
||||||
|
|
||||||
if (tightest.contains(shapePt))
|
if (tightest.contains(shapePt))
|
||||||
{
|
{
|
||||||
@ -206,4 +234,21 @@ void Foam::treeDataPoint::findNearest
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::treeDataPoint::findIntersectOp::operator()
|
||||||
|
(
|
||||||
|
const label index,
|
||||||
|
const point& start,
|
||||||
|
const point& end,
|
||||||
|
point& result
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
notImplemented
|
||||||
|
(
|
||||||
|
"treeDataPoint::intersects(const label, const point&,"
|
||||||
|
"const point&, point&)"
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -69,6 +69,58 @@ class treeDataPoint
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
class findNearestOp
|
||||||
|
{
|
||||||
|
const indexedOctree<treeDataPoint>& tree_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
findNearestOp(const indexedOctree<treeDataPoint>& tree);
|
||||||
|
|
||||||
|
void operator()
|
||||||
|
(
|
||||||
|
const labelUList& indices,
|
||||||
|
const point& sample,
|
||||||
|
|
||||||
|
scalar& nearestDistSqr,
|
||||||
|
label& minIndex,
|
||||||
|
point& nearestPoint
|
||||||
|
) const;
|
||||||
|
|
||||||
|
void operator()
|
||||||
|
(
|
||||||
|
const labelUList& indices,
|
||||||
|
const linePointRef& ln,
|
||||||
|
|
||||||
|
treeBoundBox& tightest,
|
||||||
|
label& minIndex,
|
||||||
|
point& linePoint,
|
||||||
|
point& nearestPoint
|
||||||
|
) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class findIntersectOp
|
||||||
|
{
|
||||||
|
const indexedOctree<treeDataPoint>& tree_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
findIntersectOp(const indexedOctree<treeDataPoint>& tree);
|
||||||
|
|
||||||
|
//- Calculate intersection of triangle with ray. Sets result
|
||||||
|
// accordingly
|
||||||
|
bool operator()
|
||||||
|
(
|
||||||
|
const label index,
|
||||||
|
const point& start,
|
||||||
|
const point& end,
|
||||||
|
point& intersectionPoint
|
||||||
|
) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Declare name of the class and its debug switch
|
// Declare name of the class and its debug switch
|
||||||
ClassName("treeDataPoint");
|
ClassName("treeDataPoint");
|
||||||
|
|
||||||
@ -106,6 +158,11 @@ public:
|
|||||||
return points_;
|
return points_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool useSubset() const
|
||||||
|
{
|
||||||
|
return useSubset_;
|
||||||
|
}
|
||||||
|
|
||||||
//- Get representative point cloud for all shapes inside
|
//- Get representative point cloud for all shapes inside
|
||||||
// (one point per shape)
|
// (one point per shape)
|
||||||
pointField shapePoints() const;
|
pointField shapePoints() const;
|
||||||
@ -135,50 +192,6 @@ public:
|
|||||||
const point& centre,
|
const point& centre,
|
||||||
const scalar radiusSqr
|
const scalar radiusSqr
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Calculates nearest (to sample) point in shape.
|
|
||||||
// Returns actual point and distance (squared)
|
|
||||||
void findNearest
|
|
||||||
(
|
|
||||||
const labelUList& indices,
|
|
||||||
const point& sample,
|
|
||||||
|
|
||||||
scalar& nearestDistSqr,
|
|
||||||
label& nearestIndex,
|
|
||||||
point& nearestPoint
|
|
||||||
) const;
|
|
||||||
|
|
||||||
//- Calculates nearest (to line) point in shape.
|
|
||||||
// Returns point and distance (squared)
|
|
||||||
void findNearest
|
|
||||||
(
|
|
||||||
const labelUList& indices,
|
|
||||||
const linePointRef& ln,
|
|
||||||
|
|
||||||
treeBoundBox& tightest,
|
|
||||||
label& minIndex,
|
|
||||||
point& linePoint,
|
|
||||||
point& nearestPoint
|
|
||||||
) const;
|
|
||||||
|
|
||||||
//- Calculate intersection of shape with ray. Sets result
|
|
||||||
// accordingly
|
|
||||||
bool intersects
|
|
||||||
(
|
|
||||||
const label index,
|
|
||||||
const point& start,
|
|
||||||
const point& end,
|
|
||||||
point& result
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
notImplemented
|
|
||||||
(
|
|
||||||
"treeDataPoint::intersects(const label, const point&,"
|
|
||||||
"const point&, point&)"
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -26,12 +26,8 @@ License
|
|||||||
#include "treeDataPrimitivePatch.H"
|
#include "treeDataPrimitivePatch.H"
|
||||||
#include "indexedOctree.H"
|
#include "indexedOctree.H"
|
||||||
#include "triangleFuncs.H"
|
#include "triangleFuncs.H"
|
||||||
|
#include "triSurfaceTools.H"
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
#include "triFace.H"
|
||||||
|
|
||||||
template<class PatchType>
|
|
||||||
Foam::scalar Foam::treeDataPrimitivePatch<PatchType>::tolSqr = sqr(1e-6);
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -70,6 +66,75 @@ void Foam::treeDataPrimitivePatch<PatchType>::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class PatchType>
|
||||||
|
bool Foam::treeDataPrimitivePatch<PatchType>::findIntersection
|
||||||
|
(
|
||||||
|
const indexedOctree<treeDataPrimitivePatch<PatchType> >& tree,
|
||||||
|
const label index,
|
||||||
|
const point& start,
|
||||||
|
const point& end,
|
||||||
|
point& intersectionPoint
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const treeDataPrimitivePatch<PatchType>& shape = tree.shapes();
|
||||||
|
const PatchType& patch = shape.patch();
|
||||||
|
|
||||||
|
const pointField& points = patch.points();
|
||||||
|
const typename PatchType::FaceType& f = patch[index];
|
||||||
|
|
||||||
|
// Do quick rejection test
|
||||||
|
if (shape.cacheBb_)
|
||||||
|
{
|
||||||
|
const treeBoundBox& faceBb = shape.bbs_[index];
|
||||||
|
|
||||||
|
if ((faceBb.posBits(start) & faceBb.posBits(end)) != 0)
|
||||||
|
{
|
||||||
|
// start and end in same block outside of faceBb.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const vector dir(end - start);
|
||||||
|
pointHit inter;
|
||||||
|
|
||||||
|
if (f.size() == 3)
|
||||||
|
{
|
||||||
|
inter = triPointRef
|
||||||
|
(
|
||||||
|
points[f[0]],
|
||||||
|
points[f[1]],
|
||||||
|
points[f[2]]
|
||||||
|
).intersection(start, dir, intersection::HALF_RAY, shape.planarTol_);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const pointField& faceCentres = patch.faceCentres();
|
||||||
|
|
||||||
|
inter = f.intersection
|
||||||
|
(
|
||||||
|
start,
|
||||||
|
dir,
|
||||||
|
faceCentres[index],
|
||||||
|
points,
|
||||||
|
intersection::HALF_RAY
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inter.hit() && inter.distance() <= 1)
|
||||||
|
{
|
||||||
|
// Note: no extra test on whether intersection is in front of us
|
||||||
|
// since using half_ray
|
||||||
|
intersectionPoint = inter.hitPoint();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
// Construct from components
|
// Construct from components
|
||||||
@ -77,16 +142,50 @@ template<class PatchType>
|
|||||||
Foam::treeDataPrimitivePatch<PatchType>::treeDataPrimitivePatch
|
Foam::treeDataPrimitivePatch<PatchType>::treeDataPrimitivePatch
|
||||||
(
|
(
|
||||||
const bool cacheBb,
|
const bool cacheBb,
|
||||||
const PatchType& patch
|
const PatchType& patch,
|
||||||
|
const scalar planarTol
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
patch_(patch),
|
patch_(patch),
|
||||||
cacheBb_(cacheBb)
|
cacheBb_(cacheBb),
|
||||||
|
planarTol_(planarTol)
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class PatchType>
|
||||||
|
Foam::treeDataPrimitivePatch<PatchType>::findNearestOp::findNearestOp
|
||||||
|
(
|
||||||
|
const indexedOctree<treeDataPrimitivePatch<PatchType> >& tree
|
||||||
|
)
|
||||||
|
:
|
||||||
|
tree_(tree)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class PatchType>
|
||||||
|
Foam::treeDataPrimitivePatch<PatchType>::findIntersectOp::findIntersectOp
|
||||||
|
(
|
||||||
|
const indexedOctree<treeDataPrimitivePatch<PatchType> >& tree
|
||||||
|
)
|
||||||
|
:
|
||||||
|
tree_(tree)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class PatchType>
|
||||||
|
Foam::treeDataPrimitivePatch<PatchType>::findAllIntersectOp::findAllIntersectOp
|
||||||
|
(
|
||||||
|
const indexedOctree<treeDataPrimitivePatch<PatchType> >& tree,
|
||||||
|
DynamicList<label>& shapeMask
|
||||||
|
)
|
||||||
|
:
|
||||||
|
tree_(tree),
|
||||||
|
shapeMask_(shapeMask)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class PatchType>
|
template<class PatchType>
|
||||||
@ -106,7 +205,7 @@ Foam::pointField Foam::treeDataPrimitivePatch<PatchType>::shapePoints() const
|
|||||||
//- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
|
//- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
|
||||||
// Only makes sense for closed surfaces.
|
// Only makes sense for closed surfaces.
|
||||||
template<class PatchType>
|
template<class PatchType>
|
||||||
Foam::label Foam::treeDataPrimitivePatch<PatchType>:: getVolumeType
|
Foam::label Foam::treeDataPrimitivePatch<PatchType>::getVolumeType
|
||||||
(
|
(
|
||||||
const indexedOctree<treeDataPrimitivePatch<PatchType> >& oc,
|
const indexedOctree<treeDataPrimitivePatch<PatchType> >& oc,
|
||||||
const point& sample
|
const point& sample
|
||||||
@ -136,7 +235,6 @@ Foam::label Foam::treeDataPrimitivePatch<PatchType>:: getVolumeType
|
|||||||
<< abort(FatalError);
|
<< abort(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Get actual intersection point on face
|
// Get actual intersection point on face
|
||||||
label faceI = info.index();
|
label faceI = info.index();
|
||||||
|
|
||||||
@ -147,7 +245,7 @@ Foam::label Foam::treeDataPrimitivePatch<PatchType>:: getVolumeType
|
|||||||
}
|
}
|
||||||
|
|
||||||
const pointField& points = patch_.localPoints();
|
const pointField& points = patch_.localPoints();
|
||||||
const face& f = patch_.localFaces()[faceI];
|
const typename PatchType::FaceType& f = patch_.localFaces()[faceI];
|
||||||
|
|
||||||
// Retest to classify where on face info is. Note: could be improved. We
|
// Retest to classify where on face info is. Note: could be improved. We
|
||||||
// already have point.
|
// already have point.
|
||||||
@ -188,9 +286,10 @@ Foam::label Foam::treeDataPrimitivePatch<PatchType>:: getVolumeType
|
|||||||
|
|
||||||
const scalar typDimSqr = mag(area) + VSMALL;
|
const scalar typDimSqr = mag(area) + VSMALL;
|
||||||
|
|
||||||
|
|
||||||
forAll(f, fp)
|
forAll(f, fp)
|
||||||
{
|
{
|
||||||
if ((magSqr(points[f[fp]] - curPt)/typDimSqr) < tolSqr)
|
if ((magSqr(points[f[fp]] - curPt)/typDimSqr) < planarTol_)
|
||||||
{
|
{
|
||||||
// Face intersection point equals face vertex fp
|
// Face intersection point equals face vertex fp
|
||||||
|
|
||||||
@ -207,7 +306,7 @@ Foam::label Foam::treeDataPrimitivePatch<PatchType>:: getVolumeType
|
|||||||
|
|
||||||
const point fc(f.centre(points));
|
const point fc(f.centre(points));
|
||||||
|
|
||||||
if ((magSqr(fc - curPt)/typDimSqr) < tolSqr)
|
if ((magSqr(fc - curPt)/typDimSqr) < planarTol_)
|
||||||
{
|
{
|
||||||
// Face intersection point equals face centre. Normal at face centre
|
// Face intersection point equals face centre. Normal at face centre
|
||||||
// is already average of face normals
|
// is already average of face normals
|
||||||
@ -240,7 +339,7 @@ Foam::label Foam::treeDataPrimitivePatch<PatchType>:: getVolumeType
|
|||||||
|
|
||||||
pointHit edgeHit = e.line(points).nearestDist(sample);
|
pointHit edgeHit = e.line(points).nearestDist(sample);
|
||||||
|
|
||||||
if ((magSqr(edgeHit.rawPoint() - curPt)/typDimSqr) < tolSqr)
|
if ((magSqr(edgeHit.rawPoint() - curPt)/typDimSqr) < planarTol_)
|
||||||
{
|
{
|
||||||
// Face intersection point lies on edge e
|
// Face intersection point lies on edge e
|
||||||
|
|
||||||
@ -285,7 +384,7 @@ Foam::label Foam::treeDataPrimitivePatch<PatchType>:: getVolumeType
|
|||||||
fc
|
fc
|
||||||
).nearestDist(sample);
|
).nearestDist(sample);
|
||||||
|
|
||||||
if ((magSqr(edgeHit.rawPoint() - curPt)/typDimSqr) < tolSqr)
|
if ((magSqr(edgeHit.rawPoint() - curPt)/typDimSqr) < planarTol_)
|
||||||
{
|
{
|
||||||
// Face intersection point lies on edge between two face triangles
|
// Face intersection point lies on edge between two face triangles
|
||||||
|
|
||||||
@ -368,7 +467,7 @@ bool Foam::treeDataPrimitivePatch<PatchType>::overlaps
|
|||||||
// 2. Check if one or more face points inside
|
// 2. Check if one or more face points inside
|
||||||
|
|
||||||
const pointField& points = patch_.points();
|
const pointField& points = patch_.points();
|
||||||
const face& f = patch_[index];
|
const typename PatchType::FaceType& f = patch_[index];
|
||||||
|
|
||||||
if (cubeBb.containsAny(points, f))
|
if (cubeBb.containsAny(points, f))
|
||||||
{
|
{
|
||||||
@ -379,21 +478,35 @@ bool Foam::treeDataPrimitivePatch<PatchType>::overlaps
|
|||||||
// 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);
|
||||||
|
|
||||||
forAll(f, fp)
|
if (f.size() == 3)
|
||||||
{
|
{
|
||||||
bool triIntersects = triangleFuncs::intersectBb
|
return triangleFuncs::intersectBb
|
||||||
(
|
(
|
||||||
points[f[fp]],
|
points[f[0]],
|
||||||
points[f[f.fcIndex(fp)]],
|
points[f[1]],
|
||||||
fc,
|
points[f[2]],
|
||||||
cubeBb
|
cubeBb
|
||||||
);
|
);
|
||||||
|
}
|
||||||
if (triIntersects)
|
else
|
||||||
|
{
|
||||||
|
forAll(f, fp)
|
||||||
{
|
{
|
||||||
return true;
|
bool triIntersects = triangleFuncs::intersectBb
|
||||||
|
(
|
||||||
|
points[f[fp]],
|
||||||
|
points[f[f.fcIndex(fp)]],
|
||||||
|
fc,
|
||||||
|
cubeBb
|
||||||
|
);
|
||||||
|
|
||||||
|
if (triIntersects)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,10 +552,8 @@ bool Foam::treeDataPrimitivePatch<PatchType>::overlaps
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex,
|
|
||||||
// nearestPoint.
|
|
||||||
template<class PatchType>
|
template<class PatchType>
|
||||||
void Foam::treeDataPrimitivePatch<PatchType>::findNearest
|
void Foam::treeDataPrimitivePatch<PatchType>::findNearestOp::operator()
|
||||||
(
|
(
|
||||||
const labelUList& indices,
|
const labelUList& indices,
|
||||||
const point& sample,
|
const point& sample,
|
||||||
@ -452,13 +563,15 @@ void Foam::treeDataPrimitivePatch<PatchType>::findNearest
|
|||||||
point& nearestPoint
|
point& nearestPoint
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
const pointField& points = patch_.points();
|
const treeDataPrimitivePatch<PatchType>& shape = tree_.shapes();
|
||||||
|
const PatchType& patch = shape.patch();
|
||||||
|
|
||||||
|
const pointField& points = patch.points();
|
||||||
|
|
||||||
forAll(indices, i)
|
forAll(indices, i)
|
||||||
{
|
{
|
||||||
const label index = indices[i];
|
const label index = indices[i];
|
||||||
|
const typename PatchType::FaceType& f = patch[index];
|
||||||
const face& f = patch_[index];
|
|
||||||
|
|
||||||
pointHit nearHit = f.nearestPoint(sample, points);
|
pointHit nearHit = f.nearestPoint(sample, points);
|
||||||
scalar distSqr = sqr(nearHit.distance());
|
scalar distSqr = sqr(nearHit.distance());
|
||||||
@ -474,7 +587,34 @@ void Foam::treeDataPrimitivePatch<PatchType>::findNearest
|
|||||||
|
|
||||||
|
|
||||||
template<class PatchType>
|
template<class PatchType>
|
||||||
bool Foam::treeDataPrimitivePatch<PatchType>::intersects
|
void Foam::treeDataPrimitivePatch<PatchType>::findNearestOp::operator()
|
||||||
|
(
|
||||||
|
const labelUList& indices,
|
||||||
|
const linePointRef& ln,
|
||||||
|
|
||||||
|
treeBoundBox& tightest,
|
||||||
|
label& minIndex,
|
||||||
|
point& linePoint,
|
||||||
|
point& nearestPoint
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
notImplemented
|
||||||
|
(
|
||||||
|
"treeDataPrimitivePatch<PatchType>::findNearestOp::operator()"
|
||||||
|
"("
|
||||||
|
" const labelUList&,"
|
||||||
|
" const linePointRef&,"
|
||||||
|
" treeBoundBox&,"
|
||||||
|
" label&,"
|
||||||
|
" point&,"
|
||||||
|
" point&"
|
||||||
|
") const"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class PatchType>
|
||||||
|
bool Foam::treeDataPrimitivePatch<PatchType>::findIntersectOp::operator()
|
||||||
(
|
(
|
||||||
const label index,
|
const label index,
|
||||||
const point& start,
|
const point& start,
|
||||||
@ -482,43 +622,25 @@ bool Foam::treeDataPrimitivePatch<PatchType>::intersects
|
|||||||
point& intersectionPoint
|
point& intersectionPoint
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
// Do quick rejection test
|
return findIntersection(tree_, index, start, end, intersectionPoint);
|
||||||
if (cacheBb_)
|
}
|
||||||
{
|
|
||||||
const treeBoundBox& faceBb = bbs_[index];
|
|
||||||
|
|
||||||
if ((faceBb.posBits(start) & faceBb.posBits(end)) != 0)
|
|
||||||
{
|
|
||||||
// start and end in same block outside of faceBb.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const pointField& points = patch_.points();
|
template<class PatchType>
|
||||||
const face& f = patch_[index];
|
bool Foam::treeDataPrimitivePatch<PatchType>::findAllIntersectOp::operator()
|
||||||
const point fc = f.centre(points);
|
(
|
||||||
const vector dir(end - start);
|
const label index,
|
||||||
|
const point& start,
|
||||||
pointHit inter = patch_[index].intersection
|
const point& end,
|
||||||
(
|
point& intersectionPoint
|
||||||
start,
|
) const
|
||||||
dir,
|
{
|
||||||
fc,
|
if (!shapeMask_.empty() && findIndex(shapeMask_, index) != -1)
|
||||||
points,
|
|
||||||
intersection::HALF_RAY
|
|
||||||
);
|
|
||||||
|
|
||||||
if (inter.hit() && inter.distance() <= 1)
|
|
||||||
{
|
|
||||||
// Note: no extra test on whether intersection is in front of us
|
|
||||||
// since using half_ray
|
|
||||||
intersectionPoint = inter.hitPoint();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return findIntersection(tree_, index, start, end, intersectionPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -35,8 +35,6 @@ SourceFiles
|
|||||||
#ifndef treeDataPrimitivePatch_H
|
#ifndef treeDataPrimitivePatch_H
|
||||||
#define treeDataPrimitivePatch_H
|
#define treeDataPrimitivePatch_H
|
||||||
|
|
||||||
#include "PrimitivePatch.H"
|
|
||||||
//#include "indexedOctree.H"
|
|
||||||
#include "treeBoundBoxList.H"
|
#include "treeBoundBoxList.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
@ -64,11 +62,6 @@ class treeDataPrimitivePatch
|
|||||||
:
|
:
|
||||||
public treeDataPrimitivePatchName
|
public treeDataPrimitivePatchName
|
||||||
{
|
{
|
||||||
// Static data
|
|
||||||
|
|
||||||
//- tolerance on linear dimensions
|
|
||||||
static scalar tolSqr;
|
|
||||||
|
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
//- Underlying geometry
|
//- Underlying geometry
|
||||||
@ -77,6 +70,9 @@ class treeDataPrimitivePatch
|
|||||||
//- Whether to precalculate and store face bounding box
|
//- Whether to precalculate and store face bounding box
|
||||||
const bool cacheBb_;
|
const bool cacheBb_;
|
||||||
|
|
||||||
|
//- Tolerance to use for intersection tests
|
||||||
|
const scalar planarTol_;
|
||||||
|
|
||||||
//- face bounding boxes (valid only if cacheBb_)
|
//- face bounding boxes (valid only if cacheBb_)
|
||||||
treeBoundBoxList bbs_;
|
treeBoundBoxList bbs_;
|
||||||
|
|
||||||
@ -89,15 +85,107 @@ class treeDataPrimitivePatch
|
|||||||
//- Initialise all member data
|
//- Initialise all member data
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
//- Find intersection of line with shapes
|
||||||
|
static bool findIntersection
|
||||||
|
(
|
||||||
|
const indexedOctree<treeDataPrimitivePatch<PatchType> >& tree,
|
||||||
|
const label index,
|
||||||
|
const point& start,
|
||||||
|
const point& end,
|
||||||
|
point& intersectionPoint
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
class findNearestOp
|
||||||
|
{
|
||||||
|
const indexedOctree<treeDataPrimitivePatch>& tree_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
findNearestOp(const indexedOctree<treeDataPrimitivePatch>& tree);
|
||||||
|
|
||||||
|
void operator()
|
||||||
|
(
|
||||||
|
const labelUList& indices,
|
||||||
|
const point& sample,
|
||||||
|
|
||||||
|
scalar& nearestDistSqr,
|
||||||
|
label& minIndex,
|
||||||
|
point& nearestPoint
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Calculates nearest (to line) point in shape.
|
||||||
|
// Returns point and distance (squared)
|
||||||
|
void operator()
|
||||||
|
(
|
||||||
|
const labelUList& indices,
|
||||||
|
const linePointRef& ln,
|
||||||
|
|
||||||
|
treeBoundBox& tightest,
|
||||||
|
label& minIndex,
|
||||||
|
point& linePoint,
|
||||||
|
point& nearestPoint
|
||||||
|
) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class findIntersectOp
|
||||||
|
{
|
||||||
|
const indexedOctree<treeDataPrimitivePatch>& tree_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
findIntersectOp(const indexedOctree<treeDataPrimitivePatch>& tree);
|
||||||
|
|
||||||
|
//- Calculate intersection of triangle with ray. Sets result
|
||||||
|
// accordingly
|
||||||
|
bool operator()
|
||||||
|
(
|
||||||
|
const label index,
|
||||||
|
const point& start,
|
||||||
|
const point& end,
|
||||||
|
point& intersectionPoint
|
||||||
|
) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class findAllIntersectOp
|
||||||
|
{
|
||||||
|
const indexedOctree<treeDataPrimitivePatch>& tree_;
|
||||||
|
|
||||||
|
DynamicList<label>& shapeMask_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
findAllIntersectOp
|
||||||
|
(
|
||||||
|
const indexedOctree<treeDataPrimitivePatch>& tree,
|
||||||
|
DynamicList<label>& shapeMask
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Calculate intersection of triangle with ray. Sets result
|
||||||
|
// accordingly
|
||||||
|
bool operator()
|
||||||
|
(
|
||||||
|
const label index,
|
||||||
|
const point& start,
|
||||||
|
const point& end,
|
||||||
|
point& intersectionPoint
|
||||||
|
) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from patch.
|
//- Construct from patch.
|
||||||
treeDataPrimitivePatch
|
treeDataPrimitivePatch
|
||||||
(
|
(
|
||||||
const bool cacheBb,
|
const bool cacheBb,
|
||||||
const PatchType&
|
const PatchType&,
|
||||||
|
const scalar planarTol
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@ -145,49 +233,6 @@ public:
|
|||||||
const point& centre,
|
const point& centre,
|
||||||
const scalar radiusSqr
|
const scalar radiusSqr
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Calculates nearest (to sample) point in shape.
|
|
||||||
// Returns actual point and distance (squared)
|
|
||||||
void findNearest
|
|
||||||
(
|
|
||||||
const labelUList& indices,
|
|
||||||
const point& sample,
|
|
||||||
|
|
||||||
scalar& nearestDistSqr,
|
|
||||||
label& nearestIndex,
|
|
||||||
point& nearestPoint
|
|
||||||
) const;
|
|
||||||
|
|
||||||
//- Calculates nearest (to line) point in shape.
|
|
||||||
// Returns point and distance (squared)
|
|
||||||
void findNearest
|
|
||||||
(
|
|
||||||
const labelUList& indices,
|
|
||||||
const linePointRef& ln,
|
|
||||||
|
|
||||||
treeBoundBox& tightest,
|
|
||||||
label& minIndex,
|
|
||||||
point& linePoint,
|
|
||||||
point& nearestPoint
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
notImplemented
|
|
||||||
(
|
|
||||||
"treeDataPrimitivePatch::findNearest"
|
|
||||||
"(const labelUList&, const linePointRef&, ..)"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Calculate intersection of shape with ray. Sets result
|
|
||||||
// accordingly
|
|
||||||
bool intersects
|
|
||||||
(
|
|
||||||
const label index,
|
|
||||||
const point& start,
|
|
||||||
const point& end,
|
|
||||||
point& result
|
|
||||||
) const;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -25,491 +25,58 @@ License
|
|||||||
|
|
||||||
#include "treeDataTriSurface.H"
|
#include "treeDataTriSurface.H"
|
||||||
#include "triSurfaceTools.H"
|
#include "triSurfaceTools.H"
|
||||||
#include "triangleFuncs.H"
|
|
||||||
#include "indexedOctree.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
template<>
|
||||||
{
|
Foam::label Foam::treeDataPrimitivePatch<Foam::triSurface>::getVolumeType
|
||||||
defineTypeNameAndDebug(treeDataTriSurface, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
|
||||||
|
|
||||||
// // Fast distance to triangle calculation. From
|
|
||||||
// // "Distance Between Point and Triangle in 3D"
|
|
||||||
// // David Eberly, Magic Software Inc. Aug. 2003.
|
|
||||||
// // Works on function Q giving distance to point and tries to minimize this.
|
|
||||||
// Foam::scalar Foam::treeDataTriSurface::nearestCoords
|
|
||||||
// (
|
|
||||||
// const point& base,
|
|
||||||
// const point& E0,
|
|
||||||
// const point& E1,
|
|
||||||
// const scalar a,
|
|
||||||
// const scalar b,
|
|
||||||
// const scalar c,
|
|
||||||
// const point& P,
|
|
||||||
// scalar& s,
|
|
||||||
// scalar& t
|
|
||||||
// )
|
|
||||||
// {
|
|
||||||
// // distance vector
|
|
||||||
// const vector D(base - P);
|
|
||||||
|
|
||||||
// // Precalculate distance factors.
|
|
||||||
// const scalar d = E0 & D;
|
|
||||||
// const scalar e = E1 & D;
|
|
||||||
|
|
||||||
// // Do classification
|
|
||||||
// const scalar det = a*c - b*b;
|
|
||||||
|
|
||||||
// s = b*e - c*d;
|
|
||||||
// t = b*d - a*e;
|
|
||||||
|
|
||||||
// if (s+t < det)
|
|
||||||
// {
|
|
||||||
// if (s < 0)
|
|
||||||
// {
|
|
||||||
// if (t < 0)
|
|
||||||
// {
|
|
||||||
// //region 4
|
|
||||||
// if (e > 0)
|
|
||||||
// {
|
|
||||||
// //min on edge t = 0
|
|
||||||
// t = 0;
|
|
||||||
// s = (d >= 0 ? 0 : (-d >= a ? 1 : -d/a));
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// //min on edge s=0
|
|
||||||
// s = 0;
|
|
||||||
// t = (e >= 0 ? 0 : (-e >= c ? 1 : -e/c));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// //region 3. Min on edge s = 0
|
|
||||||
// s = 0;
|
|
||||||
// t = (e >= 0 ? 0 : (-e >= c ? 1 : -e/c));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else if (t < 0)
|
|
||||||
// {
|
|
||||||
// //region 5
|
|
||||||
// t = 0;
|
|
||||||
// s = (d >= 0 ? 0 : (-d >= a ? 1 : -d/a));
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// //region 0
|
|
||||||
// const scalar invDet = 1/det;
|
|
||||||
// s *= invDet;
|
|
||||||
// t *= invDet;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// if (s < 0)
|
|
||||||
// {
|
|
||||||
// //region 2
|
|
||||||
// const scalar tmp0 = b + d;
|
|
||||||
// const scalar tmp1 = c + e;
|
|
||||||
// if (tmp1 > tmp0)
|
|
||||||
// {
|
|
||||||
// //min on edge s+t=1
|
|
||||||
// const scalar numer = tmp1 - tmp0;
|
|
||||||
// const scalar denom = a-2*b+c;
|
|
||||||
// s = (numer >= denom ? 1 : numer/denom);
|
|
||||||
// t = 1 - s;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// //min on edge s=0
|
|
||||||
// s = 0;
|
|
||||||
// t = (tmp1 <= 0 ? 1 : (e >= 0 ? 0 : - e/c));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else if (t < 0)
|
|
||||||
// {
|
|
||||||
// //region 6
|
|
||||||
// const scalar tmp0 = b + d;
|
|
||||||
// const scalar tmp1 = c + e;
|
|
||||||
// if (tmp1 > tmp0)
|
|
||||||
// {
|
|
||||||
// //min on edge s+t=1
|
|
||||||
// const scalar numer = tmp1 - tmp0;
|
|
||||||
// const scalar denom = a-2*b+c;
|
|
||||||
// s = (numer >= denom ? 1 : numer/denom);
|
|
||||||
// t = 1 - s;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// //min on edge t=0
|
|
||||||
// t = 0;
|
|
||||||
// s = (tmp1 <= 0 ? 1 : (d >= 0 ? 0 : - d/a));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// //region 1
|
|
||||||
// const scalar numer = c+e-(b+d);
|
|
||||||
// if (numer <= 0)
|
|
||||||
// {
|
|
||||||
// s = 0;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// const scalar denom = a-2*b+c;
|
|
||||||
// s = (numer >= denom ? 1 : numer/denom);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// t = 1 - s;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// // Calculate distance.
|
|
||||||
// // Note: abs should not be needed but truncation error causes problems
|
|
||||||
// // with points very close to one of the triangle vertices.
|
|
||||||
// // (seen up to -9e-15). Alternatively add some small value.
|
|
||||||
|
|
||||||
// const scalar f = D & D;
|
|
||||||
// return Foam::mag(a*s*s + 2*b*s*t + c*t*t + 2*d*s + 2*e*t + f);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
// Construct from components
|
|
||||||
Foam::treeDataTriSurface::treeDataTriSurface
|
|
||||||
(
|
(
|
||||||
const triSurface& surface,
|
const indexedOctree<treeDataPrimitivePatch<triSurface> >& oc,
|
||||||
const scalar planarTol
|
|
||||||
)
|
|
||||||
:
|
|
||||||
surface_(surface),
|
|
||||||
planarTol_(planarTol)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
Foam::pointField Foam::treeDataTriSurface::shapePoints() const
|
|
||||||
{
|
|
||||||
const pointField& points = surface_.points();
|
|
||||||
|
|
||||||
pointField centres(surface_.size());
|
|
||||||
|
|
||||||
forAll(surface_, triI)
|
|
||||||
{
|
|
||||||
centres[triI] = surface_[triI].centre(points);
|
|
||||||
}
|
|
||||||
return centres;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//- Get type of sample (inside/outside/mixed) w.r.t. surface.
|
|
||||||
Foam::label Foam::treeDataTriSurface::getVolumeType
|
|
||||||
(
|
|
||||||
const indexedOctree<treeDataTriSurface>& tree,
|
|
||||||
const point& sample
|
const point& sample
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
// Find nearest point
|
// Find nearest face to sample
|
||||||
const treeBoundBox& treeBb = tree.bb();
|
pointIndexHit info = oc.findNearest(sample, sqr(GREAT));
|
||||||
|
|
||||||
pointIndexHit pHit = tree.findNearest
|
if (info.index() == -1)
|
||||||
(
|
|
||||||
sample,
|
|
||||||
max
|
|
||||||
(
|
|
||||||
Foam::sqr(GREAT),
|
|
||||||
Foam::magSqr(treeBb.span())
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!pHit.hit())
|
|
||||||
{
|
{
|
||||||
FatalErrorIn("treeDataTriSurface::getVolumeType(..)")
|
FatalErrorIn
|
||||||
<< "treeBb:" << treeBb
|
(
|
||||||
<< " sample:" << sample
|
"treeDataPrimitivePatch::getSampleType"
|
||||||
<< " pHit:" << pHit
|
"(indexedOctree<treeDataPrimitivePatch>&, const point&)"
|
||||||
|
) << "Could not find " << sample << " in octree."
|
||||||
<< abort(FatalError);
|
<< abort(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get actual intersection point on face
|
||||||
|
label faceI = info.index();
|
||||||
|
|
||||||
triSurfaceTools::sideType t = triSurfaceTools::surfaceSide
|
triSurfaceTools::sideType t = triSurfaceTools::surfaceSide
|
||||||
(
|
(
|
||||||
surface_,
|
patch_,
|
||||||
sample,
|
sample,
|
||||||
pHit.index()
|
faceI
|
||||||
);
|
);
|
||||||
|
|
||||||
if (t == triSurfaceTools::UNKNOWN)
|
if (t == triSurfaceTools::UNKNOWN)
|
||||||
{
|
{
|
||||||
return indexedOctree<treeDataTriSurface>::UNKNOWN;
|
return indexedOctree<treeDataPrimitivePatch<triSurface> >::UNKNOWN;
|
||||||
}
|
}
|
||||||
else if (t == triSurfaceTools::INSIDE)
|
else if (t == triSurfaceTools::INSIDE)
|
||||||
{
|
{
|
||||||
return indexedOctree<treeDataTriSurface>::INSIDE;
|
return indexedOctree<treeDataPrimitivePatch<triSurface> >::INSIDE;
|
||||||
}
|
}
|
||||||
else if (t == triSurfaceTools::OUTSIDE)
|
else if (t == triSurfaceTools::OUTSIDE)
|
||||||
{
|
{
|
||||||
return indexedOctree<treeDataTriSurface>::OUTSIDE;
|
return indexedOctree<treeDataPrimitivePatch<triSurface> >::OUTSIDE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FatalErrorIn("treeDataTriSurface::getVolumeType(..)")
|
FatalErrorIn("treeDataPrimitivePatch<PatchType>::getVolumeType(..)")
|
||||||
<< "problem" << abort(FatalError);
|
<< "problem" << abort(FatalError);
|
||||||
return indexedOctree<treeDataTriSurface>::UNKNOWN;
|
return indexedOctree<treeDataPrimitivePatch<triSurface> >::UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Check if any point on triangle is inside cubeBb.
|
|
||||||
bool Foam::treeDataTriSurface::overlaps
|
|
||||||
(
|
|
||||||
const label index,
|
|
||||||
const treeBoundBox& cubeBb
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
const pointField& points = surface_.points();
|
|
||||||
const labelledTri& f = surface_[index];
|
|
||||||
|
|
||||||
treeBoundBox triBb(points, surface_[index]);
|
|
||||||
|
|
||||||
//- For testing: robust one
|
|
||||||
//return cubeBb.overlaps(triBb);
|
|
||||||
|
|
||||||
//- Exact test of triangle intersecting bb
|
|
||||||
|
|
||||||
// Quick rejection. If whole bounding box of tri is outside cubeBb then
|
|
||||||
// there will be no intersection.
|
|
||||||
if (!cubeBb.overlaps(triBb))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if one or more triangle point inside
|
|
||||||
if (cubeBb.containsAny(points, f))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Triangle points
|
|
||||||
const point& p0 = points[f[0]];
|
|
||||||
const point& p1 = points[f[1]];
|
|
||||||
const point& p2 = points[f[2]];
|
|
||||||
|
|
||||||
|
|
||||||
// Now we have the difficult case: all points are outside but connecting
|
|
||||||
// edges might go through cube. Use fast intersection of bounding box.
|
|
||||||
|
|
||||||
//return triangleFuncs::intersectBbExact(p0, p1, p2, cubeBb);
|
|
||||||
return triangleFuncs::intersectBb(p0, p1, p2, cubeBb);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex,
|
|
||||||
// nearestPoint.
|
|
||||||
void Foam::treeDataTriSurface::findNearest
|
|
||||||
(
|
|
||||||
const labelUList& indices,
|
|
||||||
const point& sample,
|
|
||||||
|
|
||||||
scalar& nearestDistSqr,
|
|
||||||
label& minIndex,
|
|
||||||
point& nearestPoint
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
const pointField& points = surface_.points();
|
|
||||||
|
|
||||||
forAll(indices, i)
|
|
||||||
{
|
|
||||||
label index = indices[i];
|
|
||||||
const triSurface::FaceType& f = surface_[index];
|
|
||||||
|
|
||||||
////- Possible optimization: do quick rejection of triangle if bounding
|
|
||||||
//// sphere does not intersect triangle bounding box. From simplistic
|
|
||||||
//// test was not found to speed up things.
|
|
||||||
//
|
|
||||||
//// Triangle bounding box.
|
|
||||||
//point triBbMin = min(p0, min(p1, p2));
|
|
||||||
//point triBbMax = max(p0, max(p1, p2));
|
|
||||||
//
|
|
||||||
//if
|
|
||||||
//(
|
|
||||||
// indexedOctree<treeDataTriSurface>::intersects
|
|
||||||
// (
|
|
||||||
// triBbMin,
|
|
||||||
// triBbMax,
|
|
||||||
// nearestDistSqr,
|
|
||||||
// sample
|
|
||||||
// )
|
|
||||||
//)
|
|
||||||
{
|
|
||||||
// // Get spanning vectors of triangle
|
|
||||||
// vector base(p1);
|
|
||||||
// vector E0(p0 - p1);
|
|
||||||
// vector E1(p2 - p1);
|
|
||||||
|
|
||||||
// scalar a(E0& E0);
|
|
||||||
// scalar b(E0& E1);
|
|
||||||
// scalar c(E1& E1);
|
|
||||||
|
|
||||||
// // Get nearest point in s,t coordinates (s is along E0, t
|
|
||||||
// // is along E1)
|
|
||||||
// scalar s;
|
|
||||||
// scalar t;
|
|
||||||
|
|
||||||
// scalar distSqr = nearestCoords
|
|
||||||
// (
|
|
||||||
// base,
|
|
||||||
// E0,
|
|
||||||
// E1,
|
|
||||||
// a,
|
|
||||||
// b,
|
|
||||||
// c,
|
|
||||||
// sample,
|
|
||||||
|
|
||||||
// s,
|
|
||||||
// t
|
|
||||||
// );
|
|
||||||
|
|
||||||
pointHit pHit = f.nearestPoint(sample, points);
|
|
||||||
|
|
||||||
scalar distSqr = sqr(pHit.distance());
|
|
||||||
|
|
||||||
if (distSqr < nearestDistSqr)
|
|
||||||
{
|
|
||||||
nearestDistSqr = distSqr;
|
|
||||||
minIndex = index;
|
|
||||||
nearestPoint = pHit.rawPoint();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Calculate nearest point to line. Updates (if any) nearestDistSqr, minIndex,
|
|
||||||
// nearestPoint.
|
|
||||||
void Foam::treeDataTriSurface::findNearest
|
|
||||||
(
|
|
||||||
const labelUList& indices,
|
|
||||||
const linePointRef& ln,
|
|
||||||
|
|
||||||
treeBoundBox& tightest,
|
|
||||||
label& minIndex,
|
|
||||||
point& linePoint,
|
|
||||||
point& nearestPoint
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
// Best so far
|
|
||||||
scalar nearestDistSqr = VGREAT;
|
|
||||||
if (minIndex >= 0)
|
|
||||||
{
|
|
||||||
nearestDistSqr = magSqr(linePoint - nearestPoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
const pointField& points = surface_.points();
|
|
||||||
|
|
||||||
forAll(indices, i)
|
|
||||||
{
|
|
||||||
label index = indices[i];
|
|
||||||
const triSurface::FaceType& f = surface_[index];
|
|
||||||
|
|
||||||
triPointRef tri(f.tri(points));
|
|
||||||
|
|
||||||
pointHit lineInfo(point::max);
|
|
||||||
pointHit pHit = tri.nearestPoint(ln, lineInfo);
|
|
||||||
|
|
||||||
scalar distSqr = sqr(pHit.distance());
|
|
||||||
|
|
||||||
if (distSqr < nearestDistSqr)
|
|
||||||
{
|
|
||||||
nearestDistSqr = distSqr;
|
|
||||||
minIndex = index;
|
|
||||||
linePoint = lineInfo.rawPoint();
|
|
||||||
nearestPoint = pHit.rawPoint();
|
|
||||||
|
|
||||||
{
|
|
||||||
point& minPt = tightest.min();
|
|
||||||
minPt = min(ln.start(), ln.end());
|
|
||||||
minPt.x() -= pHit.distance();
|
|
||||||
minPt.y() -= pHit.distance();
|
|
||||||
minPt.z() -= pHit.distance();
|
|
||||||
}
|
|
||||||
{
|
|
||||||
point& maxPt = tightest.max();
|
|
||||||
maxPt = max(ln.start(), ln.end());
|
|
||||||
maxPt.x() += pHit.distance();
|
|
||||||
maxPt.y() += pHit.distance();
|
|
||||||
maxPt.z() += pHit.distance();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Foam::treeDataTriSurface::intersects
|
|
||||||
(
|
|
||||||
const label index,
|
|
||||||
const point& start,
|
|
||||||
const point& end,
|
|
||||||
point& intersectionPoint
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
const pointField& points = surface_.points();
|
|
||||||
|
|
||||||
const triSurface::FaceType& f = surface_[index];
|
|
||||||
|
|
||||||
// Do quick rejection test
|
|
||||||
treeBoundBox triBb(points, f);
|
|
||||||
|
|
||||||
const direction startBits(triBb.posBits(start));
|
|
||||||
const direction endBits(triBb.posBits(end));
|
|
||||||
|
|
||||||
if ((startBits & endBits) != 0)
|
|
||||||
{
|
|
||||||
// start and end in same block outside of triBb.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const vector dir(end - start);
|
|
||||||
|
|
||||||
// Use relative tolerance (from octree) to determine intersection.
|
|
||||||
pointHit inter = f.intersection
|
|
||||||
(
|
|
||||||
start,
|
|
||||||
dir,
|
|
||||||
points,
|
|
||||||
intersection::HALF_RAY,
|
|
||||||
planarTol_
|
|
||||||
);
|
|
||||||
|
|
||||||
if (inter.hit() && inter.distance() <= 1)
|
|
||||||
{
|
|
||||||
// Note: no extra test on whether intersection is in front of us
|
|
||||||
// since using half_ray.
|
|
||||||
intersectionPoint = inter.hitPoint();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//- Using exact intersections
|
|
||||||
//pointHit info = f.tri(points).intersectionExact(start, end);
|
|
||||||
//
|
|
||||||
//if (info.hit())
|
|
||||||
//{
|
|
||||||
// intersectionPoint = info.hitPoint();
|
|
||||||
//}
|
|
||||||
//return info.hit();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -25,7 +25,7 @@ Class
|
|||||||
Foam::treeDataTriSurface
|
Foam::treeDataTriSurface
|
||||||
|
|
||||||
Description
|
Description
|
||||||
Encapsulates data for (indexedOc)tree searches on triSurface.
|
Encapsulates data for (indexedOc)tree searches on a triSurface.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
treeDataTriSurface.C
|
treeDataTriSurface.C
|
||||||
@ -35,139 +35,26 @@ SourceFiles
|
|||||||
#ifndef treeDataTriSurface_H
|
#ifndef treeDataTriSurface_H
|
||||||
#define treeDataTriSurface_H
|
#define treeDataTriSurface_H
|
||||||
|
|
||||||
|
#include "treeDataPrimitivePatch.H"
|
||||||
#include "triSurface.H"
|
#include "triSurface.H"
|
||||||
|
#include "point.H"
|
||||||
|
#include "indexedOctree.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
typedef treeDataPrimitivePatch<triSurface> treeDataTriSurface;
|
||||||
|
|
||||||
// Forward declaration of classes
|
//- Template specialisation of getVolumeType for treeDataTriSurface
|
||||||
class treeBoundBox;
|
template<>
|
||||||
class treeDataTriSurface;
|
label treeDataPrimitivePatch<triSurface>::getVolumeType
|
||||||
template<class Type> class indexedOctree;
|
(
|
||||||
|
const indexedOctree<treeDataPrimitivePatch<triSurface> >& oc,
|
||||||
|
const point& sample
|
||||||
|
) const;
|
||||||
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
Class treeDataTriSurface Declaration
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
class treeDataTriSurface
|
|
||||||
{
|
|
||||||
// Private data
|
|
||||||
|
|
||||||
//- Reference to triSurface
|
|
||||||
const triSurface& surface_;
|
|
||||||
|
|
||||||
//- Tolerance to use for intersection tests
|
|
||||||
const scalar planarTol_;
|
|
||||||
|
|
||||||
// Private Member Functions
|
|
||||||
|
|
||||||
// //- fast triangle nearest point calculation. Returns point in E0, E1
|
|
||||||
// // coordinate system: base + s*E0 + t*E1
|
|
||||||
// static scalar nearestCoords
|
|
||||||
// (
|
|
||||||
// const point& base,
|
|
||||||
// const point& E0,
|
|
||||||
// const point& E1,
|
|
||||||
// const scalar a,
|
|
||||||
// const scalar b,
|
|
||||||
// const scalar c,
|
|
||||||
// const point& P,
|
|
||||||
// scalar& s,
|
|
||||||
// scalar& t
|
|
||||||
// );
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// Declare name of the class and its debug switch
|
|
||||||
ClassName("treeDataTriSurface");
|
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
//- Construct from triSurface and tolerance for intersection
|
|
||||||
// tests. Holds reference.
|
|
||||||
treeDataTriSurface(const triSurface&, const scalar planarTol);
|
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
|
||||||
|
|
||||||
// Access
|
|
||||||
|
|
||||||
inline const triSurface& surface() const
|
|
||||||
{
|
|
||||||
return surface_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline label size() const
|
|
||||||
{
|
|
||||||
return surface_.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Get representative point cloud for all shapes inside
|
|
||||||
// (one point per shape)
|
|
||||||
pointField shapePoints() const;
|
|
||||||
|
|
||||||
|
|
||||||
// Search
|
|
||||||
|
|
||||||
//- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
|
|
||||||
// Only makes sense for closed surfaces.
|
|
||||||
label getVolumeType
|
|
||||||
(
|
|
||||||
const indexedOctree<treeDataTriSurface>&,
|
|
||||||
const point&
|
|
||||||
) const;
|
|
||||||
|
|
||||||
//- Does (bb of) shape at index overlap bb
|
|
||||||
bool overlaps
|
|
||||||
(
|
|
||||||
const label index,
|
|
||||||
const treeBoundBox& sampleBb
|
|
||||||
) const;
|
|
||||||
|
|
||||||
//- Calculates nearest (to sample) point in shape.
|
|
||||||
// Returns actual point and distance (squared)
|
|
||||||
void findNearest
|
|
||||||
(
|
|
||||||
const labelUList& indices,
|
|
||||||
const point& sample,
|
|
||||||
|
|
||||||
scalar& nearestDistSqr,
|
|
||||||
label& nearestIndex,
|
|
||||||
point& nearestPoint
|
|
||||||
) const;
|
|
||||||
|
|
||||||
//- Calculates nearest (to line) point in shape.
|
|
||||||
// Returns point and distance (squared)
|
|
||||||
void findNearest
|
|
||||||
(
|
|
||||||
const labelUList& indices,
|
|
||||||
const linePointRef& ln,
|
|
||||||
|
|
||||||
treeBoundBox& tightest,
|
|
||||||
label& minIndex,
|
|
||||||
point& linePoint,
|
|
||||||
point& nearestPoint
|
|
||||||
) const;
|
|
||||||
|
|
||||||
//- Calculate intersection of triangle with ray. Sets result
|
|
||||||
// accordingly
|
|
||||||
bool intersects
|
|
||||||
(
|
|
||||||
const label index,
|
|
||||||
const point& start,
|
|
||||||
const point& end,
|
|
||||||
point& result
|
|
||||||
) const;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
} // End namespace Foam
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -564,7 +564,7 @@ Foam::triSurfaceMesh::tree() const
|
|||||||
(
|
(
|
||||||
new indexedOctree<treeDataTriSurface>
|
new indexedOctree<treeDataTriSurface>
|
||||||
(
|
(
|
||||||
treeDataTriSurface(*this, tolerance_),
|
treeDataTriSurface(true, *this, tolerance_),
|
||||||
bb,
|
bb,
|
||||||
maxTreeDepth_, // maxLevel
|
maxTreeDepth_, // maxLevel
|
||||||
10, // leafsize
|
10, // leafsize
|
||||||
@ -609,7 +609,7 @@ Foam::triSurfaceMesh::edgeTree() const
|
|||||||
bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
|
bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
|
||||||
bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
|
bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
|
||||||
|
|
||||||
scalar oldTol = indexedOctree<treeDataTriSurface>::perturbTol();
|
scalar oldTol = indexedOctree<treeDataEdge>::perturbTol();
|
||||||
indexedOctree<treeDataEdge>::perturbTol() = tolerance_;
|
indexedOctree<treeDataEdge>::perturbTol() = tolerance_;
|
||||||
|
|
||||||
edgeTree_.reset
|
edgeTree_.reset
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -26,6 +26,7 @@ License
|
|||||||
#include "surfaceToPoint.H"
|
#include "surfaceToPoint.H"
|
||||||
#include "polyMesh.H"
|
#include "polyMesh.H"
|
||||||
#include "triSurfaceSearch.H"
|
#include "triSurfaceSearch.H"
|
||||||
|
#include "triSurface.H"
|
||||||
#include "cpuTime.H"
|
#include "cpuTime.H"
|
||||||
|
|
||||||
#include "addToRunTimeSelectionTable.H"
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -66,6 +66,7 @@ Foam::triSurfaceSearch::triSurfaceSearch(const triSurface& surface)
|
|||||||
(
|
(
|
||||||
treeDataTriSurface
|
treeDataTriSurface
|
||||||
(
|
(
|
||||||
|
true,
|
||||||
surface_,
|
surface_,
|
||||||
indexedOctree<treeDataTriSurface>::perturbTol()
|
indexedOctree<treeDataTriSurface>::perturbTol()
|
||||||
),
|
),
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -48,7 +48,6 @@ namespace Foam
|
|||||||
|
|
||||||
// Forward declaration of classes
|
// Forward declaration of classes
|
||||||
class triSurface;
|
class triSurface;
|
||||||
class treeDataTriSurface;
|
|
||||||
template<class Type> class indexedOctree;
|
template<class Type> class indexedOctree;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
|
|||||||
Reference in New Issue
Block a user