ENH: add face/triFace find(edge) method (#3004)
- returns the edge index within the face, -1 if not found
This commit is contained in:
parent
29e2718162
commit
dc7d0ffeaa
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -128,6 +128,25 @@ int main(int argc, char *argv[])
|
||||
Info<< "face:"; faceInfo(f1, points1); Info << nl;
|
||||
testSign(f1, points1, testPoints);
|
||||
|
||||
Info<< "find within " << f1 << nl;
|
||||
for
|
||||
(
|
||||
const edge& e
|
||||
: edgeList
|
||||
({
|
||||
{0, 1},
|
||||
{2, 1},
|
||||
{4, 1},
|
||||
f1.edge(1),
|
||||
{4, 3},
|
||||
{8, 1},
|
||||
}))
|
||||
{
|
||||
Info<< " edge:" << e << " = " << f1.find(e)
|
||||
<< " direction:" << f1.edgeDirection(e)
|
||||
<< " contains:" << f1.contains(e) << nl;
|
||||
}
|
||||
|
||||
Info<< "face:"; faceInfo(f1, points2); Info << nl;
|
||||
testSign(f1, points2, testPoints);
|
||||
Info<< nl;
|
||||
@ -146,6 +165,25 @@ int main(int argc, char *argv[])
|
||||
Info<< "triFace:"; faceInfo(t1, points1); Info << nl;
|
||||
testSign(t1, points1, testPoints);
|
||||
|
||||
Info<< "find within " << t1 << nl;
|
||||
for
|
||||
(
|
||||
const edge& e
|
||||
: edgeList
|
||||
({
|
||||
{0, 1},
|
||||
{2, 1},
|
||||
{4, 1},
|
||||
t1.edge(1),
|
||||
{4, 3},
|
||||
{8, 1},
|
||||
}))
|
||||
{
|
||||
Info<< " edge:" << e << " = " << t1.find(e)
|
||||
<< " direction:" << t1.edgeDirection(e)
|
||||
<< " contains:" << t1.contains(e) << nl;
|
||||
}
|
||||
|
||||
{
|
||||
scalarField fld({0, 20, 20, 30});
|
||||
Info<< "avg:" << t1.average(pointField::null(), fld) << nl;
|
||||
|
@ -810,14 +810,47 @@ Foam::edgeList Foam::face::rcEdges() const
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::face::find(const Foam::edge& e) const
|
||||
{
|
||||
const label idx = labelList::find(e.first());
|
||||
|
||||
// NB: the point index is simultaneously the edge index.
|
||||
// ie, face point 0 starts edge 0, point 1 starts edge 1, ...
|
||||
|
||||
if (idx != -1)
|
||||
{
|
||||
if (e.second() == nextLabel(idx))
|
||||
{
|
||||
// Current edge matches forward
|
||||
return idx;
|
||||
}
|
||||
if (e.second() == prevLabel(idx))
|
||||
{
|
||||
// Previous edge matches reverse
|
||||
return rcIndex(idx);
|
||||
}
|
||||
}
|
||||
|
||||
return -1; // Not found
|
||||
}
|
||||
|
||||
|
||||
int Foam::face::edgeDirection(const Foam::edge& e) const
|
||||
{
|
||||
const label idx = labelList::find(e.first());
|
||||
|
||||
if (idx != -1)
|
||||
{
|
||||
if (e.second() == nextLabel(idx)) return 1; // Forward
|
||||
if (e.second() == prevLabel(idx)) return -1; // Reverse
|
||||
if (e.second() == nextLabel(idx))
|
||||
{
|
||||
// Current edge matches forward. Could encode: (idx+1)
|
||||
return 1;
|
||||
}
|
||||
if (e.second() == prevLabel(idx))
|
||||
{
|
||||
// Previous edge matches reverse. Could encode: -(rcIndex(idx)+1)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0; // Not found
|
||||
|
@ -374,6 +374,13 @@ public:
|
||||
//- True if face contains(edge)
|
||||
inline bool contains(const Foam::edge& e) const;
|
||||
|
||||
//- Regular find pointi within face
|
||||
using labelList::find;
|
||||
|
||||
//- Find the edge within the face.
|
||||
// \return the edge index or -1 if not found
|
||||
label find(const Foam::edge& e) const;
|
||||
|
||||
//- Test the edge direction on the face
|
||||
// \return
|
||||
// - 0: edge not found on the face
|
||||
|
@ -234,6 +234,7 @@ inline bool Foam::face::connected(const FixedList<label, N>& other) const
|
||||
|
||||
inline bool Foam::face::contains(const Foam::edge& e) const
|
||||
{
|
||||
// or (find(e) >= 0)
|
||||
return (edgeDirection(e) != 0);
|
||||
}
|
||||
|
||||
|
@ -328,6 +328,13 @@ public:
|
||||
//- True if face contains(edge)
|
||||
inline bool contains(const Foam::edge& e) const;
|
||||
|
||||
//- Regular find pointi within face
|
||||
using FixedList<label, 3>::find;
|
||||
|
||||
//- Find the edge within the face.
|
||||
// \return the edge index or -1 if not found
|
||||
inline label find(const Foam::edge& e) const;
|
||||
|
||||
//- Test the edge direction on the face
|
||||
// \return
|
||||
// - +1: forward (counter-clockwise) on the face
|
||||
|
@ -446,26 +446,49 @@ inline int Foam::triFace::edgeDirection(const Foam::edge& e) const
|
||||
{
|
||||
if (e.first() == a())
|
||||
{
|
||||
if (e.second() == b()) return 1; // edge 0 - forward
|
||||
if (e.second() == c()) return -1; // edge 2 - reverse
|
||||
if (e.second() == b()) return 1; // Forward edge 0 (encoded 1)
|
||||
if (e.second() == c()) return -1; // Reverse edge 2 (encoded -3)
|
||||
}
|
||||
if (e.first() == b())
|
||||
{
|
||||
if (e.second() == c()) return 1; // edge 1 - forward
|
||||
if (e.second() == a()) return -1; // edge 0 - reverse
|
||||
if (e.second() == c()) return 1; // Forward edge 1 (encoded 2)
|
||||
if (e.second() == a()) return -1; // Reverse edge 0 (encoded -1)
|
||||
}
|
||||
if (e.first() == c())
|
||||
{
|
||||
if (e.second() == a()) return 1; // edge 2 - forward
|
||||
if (e.second() == b()) return -1; // edge 1 - reverse
|
||||
if (e.second() == a()) return 1; // Forward edge 2 (encoded 3)
|
||||
if (e.second() == b()) return -1; // Reverse edge 1 (encoded -2)
|
||||
}
|
||||
|
||||
return 0; // Not found
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::triFace::find(const Foam::edge& e) const
|
||||
{
|
||||
if (e.first() == a())
|
||||
{
|
||||
if (e.second() == b()) return 0; // Forward edge 0
|
||||
if (e.second() == c()) return 2; // Reverse edge 2
|
||||
}
|
||||
if (e.first() == b())
|
||||
{
|
||||
if (e.second() == c()) return 1; // Forward edge 1
|
||||
if (e.second() == a()) return 0; // Reverse edge 0
|
||||
}
|
||||
if (e.first() == c())
|
||||
{
|
||||
if (e.second() == a()) return 2; // Forward edge 2
|
||||
if (e.second() == b()) return 1; // Reverse edge 1
|
||||
}
|
||||
|
||||
return -1; // Not found
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::triFace::contains(const Foam::edge& e) const
|
||||
{
|
||||
// or (find(e) >= 0)
|
||||
return (edgeDirection(e) != 0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user