face class - triangulation

- plain nTriangles() inline method for face class
  - triFace gets the same for symmetry
  - face::triangles(), face::trianglesQuads() return the number of faces generated
  - face::triangles() can append to a DynamicList
This commit is contained in:
Mark Olesen 2008-11-22 12:29:46 +01:00
parent 129e16f975
commit a1d7080d40
6 changed files with 82 additions and 27 deletions

View File

@ -119,7 +119,7 @@ Foam::label Foam::face::mostConcaveAngle
} }
void Foam::face::split Foam::label Foam::face::split
( (
const face::splitMode mode, const face::splitMode mode,
const pointField& points, const pointField& points,
@ -129,6 +129,8 @@ void Foam::face::split
faceList& quadFaces faceList& quadFaces
) const ) const
{ {
label oldIndices = (triI + quadI);
if (size() <= 2) if (size() <= 2)
{ {
FatalErrorIn FatalErrorIn
@ -143,7 +145,7 @@ void Foam::face::split
if (size() == 3) if (size() == 3)
{ {
// Triangle. Just copy. // Triangle. Just copy.
if ((mode == COUNTQUAD) || (mode == COUNTTRIANGLE)) if (mode == COUNTTRIANGLE || mode == COUNTQUAD)
{ {
triI++; triI++;
} }
@ -250,7 +252,7 @@ void Foam::face::split
} }
else else
{ {
// folded round // folded around
diff = minIndex + size() - startIndex; diff = minIndex + size() - startIndex;
} }
@ -281,6 +283,8 @@ void Foam::face::split
face1.split(mode, points, triI, quadI, triFaces, quadFaces); face1.split(mode, points, triI, quadI, triFaces, quadFaces);
face2.split(mode, points, triI, quadI, triFaces, quadFaces); face2.split(mode, points, triI, quadI, triFaces, quadFaces);
} }
return (triI + quadI - oldIndices);
} }
@ -749,30 +753,27 @@ int Foam::face::edgeDirection(const edge& e) const
// 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(const pointField&) const
(
const pointField&
) const
{ {
return size() - 2; return nTriangles();
} }
void Foam::face::triangles Foam::label Foam::face::triangles
( (
const pointField& points, const pointField& points,
label& triI, label& triI,
faceList& triFaces faceList& triFaces
) const ) const
{ {
faceList quadFaces;
label quadI = 0; label quadI = 0;
faceList quadFaces;
split(SPLITTRIANGLE, points, triI, quadI, triFaces, quadFaces); return split(SPLITTRIANGLE, points, triI, quadI, triFaces, quadFaces);
} }
void Foam::face::nTrianglesQuads Foam::label Foam::face::nTrianglesQuads
( (
const pointField& points, const pointField& points,
label& triI, label& triI,
@ -782,11 +783,11 @@ void Foam::face::nTrianglesQuads
faceList triFaces; faceList triFaces;
faceList quadFaces; faceList quadFaces;
split(COUNTQUAD, points, triI, quadI, triFaces, quadFaces); return split(COUNTQUAD, points, triI, quadI, triFaces, quadFaces);
} }
void Foam::face::trianglesQuads Foam::label Foam::face::trianglesQuads
( (
const pointField& points, const pointField& points,
label& triI, label& triI,
@ -795,7 +796,7 @@ void Foam::face::trianglesQuads
faceList& quadFaces faceList& quadFaces
) const ) const
{ {
split(SPLITQUAD, points, triI, quadI, triFaces, quadFaces); return split(SPLITQUAD, points, triI, quadI, triFaces, quadFaces);
} }

View File

@ -57,11 +57,14 @@ namespace Foam
class face; class face;
class triFace; class triFace;
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
class DynamicList;
inline bool operator==(const face& a, const face& b); inline bool operator==(const face& a, const face& b);
inline bool operator!=(const face& a, const face& b); inline bool operator!=(const face& a, const face& b);
inline Istream& operator>>(Istream&, face&); inline Istream& operator>>(Istream&, face&);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class face Declaration Class face Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -108,9 +111,10 @@ class face
SPLITQUAD // split into triangles&quads SPLITQUAD // split into triangles&quads
}; };
//- Split face into triangles or triangles&quads. Stores results //- Split face into triangles or triangles&quads.
// quadFaces[quadI], triFaces[triI] // Stores results quadFaces[quadI], triFaces[triI]
void split // Returns number of new faces created
label split
( (
const splitMode mode, const splitMode mode,
const pointField& points, const pointField& points,
@ -270,30 +274,47 @@ public:
// Face splitting utilities // Face splitting utilities
//- Number of triangles after splitting
inline label nTriangles() const;
//- Number of triangles after splitting //- Number of triangles after splitting
label nTriangles(const pointField& points) const; label nTriangles(const pointField& points) const;
//- Split into triangles using existing points. Result in //- Split into triangles using existing points.
// triFaces[triI..triI+nTri]. Splits intelligently to maximize // Result in triFaces[triI..triI+nTri].
// triangle quality. // Splits intelligently to maximize triangle quality.
void triangles // Returns number of faces created.
label triangles
( (
const pointField& points, const pointField& points,
label& triI, label& triI,
faceList& triFaces faceList& triFaces
) const; ) const;
//- Split into triangles using existing points.
// Append to DynamicList.
// Returns number of faces created.
template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
label triangles
(
const pointField& points,
DynamicList<face, SizeInc,SizeMult, SizeDiv>& triFaces
) const;
//- Number of triangles and quads after splitting //- Number of triangles and quads after splitting
void nTrianglesQuads // Returns the sum of both
label nTrianglesQuads
( (
const pointField& points, const pointField& points,
label& nTris, label& nTris,
label& nQuads label& nQuads
) const; ) const;
//- Split into triangles and quads. Result in triFaces (starting at //- Split into triangles and quads.
// triI and quadFaces (starting at quadI) // Results in triFaces (starting at triI) and quadFaces
void trianglesQuads // (starting at quadI).
// Returns number of new faces created.
label trianglesQuads
( (
const pointField& points, const pointField& points,
label& triI, label& triI,

View File

@ -127,6 +127,11 @@ inline Foam::label Foam::face::prevLabel(const label i) const
return operator[](rcIndex(i)); return operator[](rcIndex(i));
} }
// Number of triangles directly known from number of vertices
inline Foam::label Foam::face::nTriangles() const
{
return size() - 2;
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //

View File

@ -25,9 +25,28 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "face.H" #include "face.H"
#include "DynamicList.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
Foam::label Foam::face::triangles
(
const pointField& points,
DynamicList<face, SizeInc, SizeMult, SizeDiv>& triFaces
) const
{
label triI = triFaces.size();
label quadI = 0;
faceList quadFaces;
// adjusts the addressable size (and allocate space if needed)
triFaces(triI + nTriangles());
return split(SPLITTRIANGLE, points, triI, quadI, triFaces, quadFaces);
}
template<class Type> template<class Type>
Type Foam::face::average Type Foam::face::average
( (

View File

@ -124,6 +124,9 @@ public:
//- Return vector normal //- Return vector normal
inline vector normal(const pointField&) const; inline vector normal(const pointField&) const;
//- Number of triangles after splitting
inline label nTriangles() const;
//- Return face with reverse direction //- Return face with reverse direction
inline triFace reverseFace() const; inline triFace reverseFace() const;

View File

@ -224,6 +224,12 @@ inline Foam::vector Foam::triFace::normal(const pointField& points) const
} }
inline Foam::label Foam::triFace::nTriangles() const
{
return 1;
}
inline Foam::triFace Foam::triFace::reverseFace() const inline Foam::triFace Foam::triFace::reverseFace() const
{ {
// The starting points of the original and reverse face are identical. // The starting points of the original and reverse face are identical.