mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Added compare methods for edge/triFace.
Added edgeDirection methods for face/triFace. Added extra constructors for converting faces to triFaces. The collapse() method now returns the new face size and can be used to check if the collapse face is valid.
This commit is contained in:
@ -119,6 +119,12 @@ public:
|
|||||||
//- Return edge line
|
//- Return edge line
|
||||||
inline linePointRef line(const pointField&) const;
|
inline linePointRef line(const pointField&) const;
|
||||||
|
|
||||||
|
//- compare edges
|
||||||
|
// - 0: different
|
||||||
|
// - +1: identical
|
||||||
|
// - -1: same edge, but different orientation
|
||||||
|
static inline int compare(const edge&, const edge&);
|
||||||
|
|
||||||
|
|
||||||
// Friend Operators
|
// Friend Operators
|
||||||
|
|
||||||
@ -127,7 +133,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//- Hash<edge> specialisation
|
//- Hash<edge> specialisation
|
||||||
// Simple commutative hash.
|
// Simple commutative hash.
|
||||||
template<>
|
template<>
|
||||||
inline label Hash<edge>::operator()(const edge& e) const
|
inline label Hash<edge>::operator()(const edge& e) const
|
||||||
|
|||||||
@ -26,6 +26,30 @@ License
|
|||||||
|
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
// - 0: different
|
||||||
|
// - +1: identical
|
||||||
|
// - -1: same edge, but different orientation
|
||||||
|
inline int Foam::edge::compare(const edge& a, const edge& b)
|
||||||
|
{
|
||||||
|
if (a[0] == b[0] && a[1] == b[1])
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if (a[0] == b[1] && a[1] == b[0])
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline Foam::edge::edge()
|
inline Foam::edge::edge()
|
||||||
@ -146,17 +170,13 @@ inline Foam::linePointRef Foam::edge::line(const pointField& p) const
|
|||||||
|
|
||||||
inline bool Foam::operator==(const edge& a, const edge& b)
|
inline bool Foam::operator==(const edge& a, const edge& b)
|
||||||
{
|
{
|
||||||
return
|
return edge::compare(a,b) != 0;
|
||||||
(
|
|
||||||
(a[0] == b[0] && a[1] == b[1])
|
|
||||||
|| (a[0] == b[1] && a[1] == b[0])
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::operator!=(const edge& a, const edge& b)
|
inline bool Foam::operator!=(const edge& a, const edge& b)
|
||||||
{
|
{
|
||||||
return !(a == b);
|
return edge::compare(a,b) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -438,7 +438,7 @@ int Foam::face::compare(const face& a, const face& b)
|
|||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|
||||||
void Foam::face::collapse()
|
Foam::label Foam::face::collapse()
|
||||||
{
|
{
|
||||||
if (size() > 1)
|
if (size() > 1)
|
||||||
{
|
{
|
||||||
@ -458,6 +458,8 @@ void Foam::face::collapse()
|
|||||||
|
|
||||||
setSize(ci);
|
setSize(ci);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -696,6 +698,47 @@ Foam::edgeList Foam::face::edges() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Foam::face::edgeDirection(const edge& e) const
|
||||||
|
{
|
||||||
|
if (size() > 2)
|
||||||
|
{
|
||||||
|
edge found(-1,-1);
|
||||||
|
|
||||||
|
// find start/end points - this breaks down for degenerate faces
|
||||||
|
forAll (*this, i)
|
||||||
|
{
|
||||||
|
if (operator[](i) == e.start())
|
||||||
|
{
|
||||||
|
found.start() = i;
|
||||||
|
}
|
||||||
|
else if (operator[](i) == e.end())
|
||||||
|
{
|
||||||
|
found.end() = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
label diff = found.end() - found.start();
|
||||||
|
if (!diff || found.start() < 0 || found.end() < 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// forward direction
|
||||||
|
if (diff == 1 || diff == 1 - size())
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
// reverse direction
|
||||||
|
if (diff == -1 || diff == -1 + size())
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Number of triangles directly known from number of vertices
|
// Number of triangles directly known from number of vertices
|
||||||
Foam::label Foam::face::nTriangles
|
Foam::label Foam::face::nTriangles
|
||||||
(
|
(
|
||||||
|
|||||||
@ -145,7 +145,8 @@ public:
|
|||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
//- Collapse face by removing duplicate point labels
|
//- Collapse face by removing duplicate point labels
|
||||||
void collapse();
|
// return the collapsed size
|
||||||
|
label collapse();
|
||||||
|
|
||||||
//- Return the points corresponding to this face
|
//- Return the points corresponding to this face
|
||||||
inline pointField points(const pointField& meshPoints) const;
|
inline pointField points(const pointField& meshPoints) const;
|
||||||
@ -251,6 +252,11 @@ public:
|
|||||||
//- Return n-th face edge
|
//- Return n-th face edge
|
||||||
inline edge faceEdge(const label n) const;
|
inline edge faceEdge(const label n) const;
|
||||||
|
|
||||||
|
//- Return the edge direction on the face
|
||||||
|
// - 0: edge not found on the face
|
||||||
|
// - +1: forward (counter-clockwise) on the face
|
||||||
|
// - -1: reverse (clockwise) on the face
|
||||||
|
int edgeDirection(const edge&) const;
|
||||||
|
|
||||||
// Face splitting utilities
|
// Face splitting utilities
|
||||||
|
|
||||||
|
|||||||
@ -81,18 +81,35 @@ public:
|
|||||||
const label c
|
const label c
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//- Construct from a face, discarding excess points
|
||||||
|
inline triFace(const face&);
|
||||||
|
|
||||||
|
//- Construct from a labelList, discarding excess points
|
||||||
|
explicit inline triFace(const labelList&);
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
inline triFace(Istream&);
|
inline triFace(Istream&);
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
|
//- Collapse face by removing duplicate point labels
|
||||||
|
// return the collapsed size, set collapsed point labels to -1
|
||||||
|
inline label collapse();
|
||||||
|
|
||||||
|
//- Return the edge direction on the face
|
||||||
|
// - +1: forward (counter-clockwise) on the face
|
||||||
|
// - -1: reverse (clockwise) on the face
|
||||||
|
// - 0: edge not found on the face
|
||||||
|
inline int edgeDirection(const edge&) const;
|
||||||
|
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
|
|
||||||
//- Return the points corresponding to this face
|
//- Return the points corresponding to this face
|
||||||
inline pointField points(const pointField& points) const;
|
inline pointField points(const pointField& points) const;
|
||||||
|
|
||||||
//- Return triagle as a face
|
//- Return triangle as a face
|
||||||
inline face triFaceFace() const;
|
inline face triFaceFace() const;
|
||||||
|
|
||||||
//- Return number of edges
|
//- Return number of edges
|
||||||
@ -128,9 +145,14 @@ public:
|
|||||||
const intersection::direction dir = intersection::VECTOR
|
const intersection::direction dir = intersection::VECTOR
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Return the tetrahedron
|
//- Return the triangle
|
||||||
inline triPointRef tri(const pointField&) const;
|
inline triPointRef tri(const pointField&) const;
|
||||||
|
|
||||||
|
//- compare triFaces
|
||||||
|
// - 0: different
|
||||||
|
// - +1: identical
|
||||||
|
// - -1: same face, but different orientation
|
||||||
|
static inline int compare(const triFace&, const triFace&);
|
||||||
|
|
||||||
// Friend Operators
|
// Friend Operators
|
||||||
|
|
||||||
@ -139,7 +161,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//- Hash<triFace> specialisation
|
//- Hash<triFace> specialisation
|
||||||
// Simple commutative hash.
|
// Simple commutative hash.
|
||||||
template<>
|
template<>
|
||||||
inline label Hash<triFace>::operator()(const triFace& t) const
|
inline label Hash<triFace>::operator()(const triFace& t) const
|
||||||
|
|||||||
@ -33,14 +33,45 @@ License
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|
||||||
|
inline int triFace::compare(const triFace& a, const triFace& b)
|
||||||
|
{
|
||||||
|
if
|
||||||
|
(
|
||||||
|
(a[0] == b[0] && a[1] == b[1] && a[2] == b[2])
|
||||||
|
|| (a[0] == b[1] && a[1] == b[2] && a[2] == b[0])
|
||||||
|
|| (a[0] == b[2] && a[1] == b[0] && a[2] == b[1])
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// identical
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if
|
||||||
|
(
|
||||||
|
(a[0] == b[2] && a[1] == b[1] && a[2] == b[0])
|
||||||
|
|| (a[0] == b[1] && a[1] == b[0] && a[2] == b[2])
|
||||||
|
|| (a[0] == b[0] && a[1] == b[2] && a[2] == b[1])
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// same face, but reversed orientation
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
//- Construct null
|
// Construct null
|
||||||
inline triFace::triFace()
|
inline triFace::triFace()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
//- Construct from components
|
// Construct from components
|
||||||
inline triFace::triFace
|
inline triFace::triFace
|
||||||
(
|
(
|
||||||
const label a,
|
const label a,
|
||||||
@ -53,6 +84,18 @@ inline triFace::triFace
|
|||||||
operator[](2) = c;
|
operator[](2) = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Construct from a face
|
||||||
|
inline triFace::triFace(const face& f)
|
||||||
|
:
|
||||||
|
FixedList<label, 3>(SubList<label>(f,3))
|
||||||
|
{}
|
||||||
|
|
||||||
|
// Construct from a labelList
|
||||||
|
inline triFace::triFace(const labelList& l)
|
||||||
|
:
|
||||||
|
FixedList<label, 3>(SubList<label>(l,3))
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
inline triFace::triFace(Istream& is)
|
inline triFace::triFace(Istream& is)
|
||||||
:
|
:
|
||||||
@ -62,6 +105,34 @@ inline triFace::triFace(Istream& is)
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::label Foam::triFace::collapse()
|
||||||
|
{
|
||||||
|
// we cannot resize a FixedList, so mark duplicates with '-1'
|
||||||
|
// (the lower vertex is retained)
|
||||||
|
// catch any '-1' - ie, if called twice
|
||||||
|
|
||||||
|
label n = 3;
|
||||||
|
if (operator[](0) == operator[](1) || operator[](1) == -1)
|
||||||
|
{
|
||||||
|
operator[](1) = -1;
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
else if (operator[](1) == operator[](2) || operator[](2) == -1)
|
||||||
|
{
|
||||||
|
operator[](2) = -1;
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
if (operator[](0) == operator[](2))
|
||||||
|
{
|
||||||
|
operator[](2) = -1;
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Return the points associated with this face
|
// Return the points associated with this face
|
||||||
inline pointField triFace::points(const pointField& points) const
|
inline pointField triFace::points(const pointField& points) const
|
||||||
{
|
{
|
||||||
@ -111,6 +182,37 @@ inline edgeList triFace::edges() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// return
|
||||||
|
// - +1: forward (counter-clockwise) on the face
|
||||||
|
// - -1: reverse (clockwise) on the face
|
||||||
|
// - 0: edge not found on the face
|
||||||
|
inline int triFace::edgeDirection(const edge& e) const
|
||||||
|
{
|
||||||
|
if
|
||||||
|
(
|
||||||
|
(operator[](0) == e.start() && operator[](1) == e.end())
|
||||||
|
|| (operator[](1) == e.start() && operator[](2) == e.end())
|
||||||
|
|| (operator[](2) == e.start() && operator[](0) == e.end())
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if
|
||||||
|
(
|
||||||
|
(operator[](0) == e.end() && operator[](1) == e.start())
|
||||||
|
|| (operator[](1) == e.end() && operator[](2) == e.start())
|
||||||
|
|| (operator[](2) == e.end() && operator[](0) == e.start())
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline point triFace::centre(const pointField& points) const
|
inline point triFace::centre(const pointField& points) const
|
||||||
{
|
{
|
||||||
return (1.0/3.0)*
|
return (1.0/3.0)*
|
||||||
@ -202,23 +304,15 @@ inline triPointRef triFace::tri(const pointField& points) const
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline bool operator==(const triFace& tf1, const triFace& tf2)
|
inline bool operator==(const triFace& a, const triFace& b)
|
||||||
{
|
{
|
||||||
return
|
return triFace::compare(a,b) != 0;
|
||||||
(
|
|
||||||
(tf1[0] == tf2[0] && tf1[1] == tf2[1] && tf1[2] == tf2[2])
|
|
||||||
|| (tf1[0] == tf2[1] && tf1[1] == tf2[2] && tf1[2] == tf2[0])
|
|
||||||
|| (tf1[0] == tf2[2] && tf1[1] == tf2[0] && tf1[2] == tf2[1])
|
|
||||||
|| (tf1[0] == tf2[2] && tf1[1] == tf2[1] && tf1[2] == tf2[0])
|
|
||||||
|| (tf1[0] == tf2[1] && tf1[1] == tf2[0] && tf1[2] == tf2[2])
|
|
||||||
|| (tf1[0] == tf2[0] && tf1[1] == tf2[2] && tf1[2] == tf2[1])
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool operator!=(const triFace& tf1, const triFace& tf2)
|
inline bool operator!=(const triFace& a, const triFace& b)
|
||||||
{
|
{
|
||||||
return !(tf1 == tf2);
|
return triFace::compare(a,b) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user