From a1d7080d40dcbd68ab1ebf51b54a2f7a4341a89a Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sat, 22 Nov 2008 12:29:46 +0100 Subject: [PATCH] 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 --- src/OpenFOAM/meshes/meshShapes/face/face.C | 31 ++++++------- src/OpenFOAM/meshes/meshShapes/face/face.H | 45 ++++++++++++++----- src/OpenFOAM/meshes/meshShapes/face/faceI.H | 5 +++ .../meshes/meshShapes/face/faceTemplates.C | 19 ++++++++ .../meshes/meshShapes/triFace/triFace.H | 3 ++ .../meshes/meshShapes/triFace/triFaceI.H | 6 +++ 6 files changed, 82 insertions(+), 27 deletions(-) diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.C b/src/OpenFOAM/meshes/meshShapes/face/face.C index 16d71fe9b0..27f3eb0f6d 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.C +++ b/src/OpenFOAM/meshes/meshShapes/face/face.C @@ -119,7 +119,7 @@ Foam::label Foam::face::mostConcaveAngle } -void Foam::face::split +Foam::label Foam::face::split ( const face::splitMode mode, const pointField& points, @@ -129,6 +129,8 @@ void Foam::face::split faceList& quadFaces ) const { + label oldIndices = (triI + quadI); + if (size() <= 2) { FatalErrorIn @@ -143,7 +145,7 @@ void Foam::face::split if (size() == 3) { // Triangle. Just copy. - if ((mode == COUNTQUAD) || (mode == COUNTTRIANGLE)) + if (mode == COUNTTRIANGLE || mode == COUNTQUAD) { triI++; } @@ -250,7 +252,7 @@ void Foam::face::split } else { - // folded round + // folded around diff = minIndex + size() - startIndex; } @@ -281,6 +283,8 @@ void Foam::face::split face1.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 -Foam::label Foam::face::nTriangles -( - const pointField& -) const +Foam::label Foam::face::nTriangles(const pointField&) const { - return size() - 2; + return nTriangles(); } -void Foam::face::triangles +Foam::label Foam::face::triangles ( const pointField& points, label& triI, faceList& triFaces ) const { - faceList quadFaces; 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, label& triI, @@ -782,11 +783,11 @@ void Foam::face::nTrianglesQuads faceList triFaces; 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, label& triI, @@ -795,7 +796,7 @@ void Foam::face::trianglesQuads faceList& quadFaces ) const { - split(SPLITQUAD, points, triI, quadI, triFaces, quadFaces); + return split(SPLITQUAD, points, triI, quadI, triFaces, quadFaces); } diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.H b/src/OpenFOAM/meshes/meshShapes/face/face.H index 875df60495..8032c47ac5 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.H +++ b/src/OpenFOAM/meshes/meshShapes/face/face.H @@ -57,11 +57,14 @@ namespace Foam class face; class triFace; + +template +class DynamicList; + inline bool operator==(const face& a, const face& b); inline bool operator!=(const face& a, const face& b); inline Istream& operator>>(Istream&, face&); - /*---------------------------------------------------------------------------*\ Class face Declaration \*---------------------------------------------------------------------------*/ @@ -108,9 +111,10 @@ class face SPLITQUAD // split into triangles&quads }; - //- Split face into triangles or triangles&quads. Stores results - // quadFaces[quadI], triFaces[triI] - void split + //- Split face into triangles or triangles&quads. + // Stores results quadFaces[quadI], triFaces[triI] + // Returns number of new faces created + label split ( const splitMode mode, const pointField& points, @@ -270,30 +274,47 @@ public: // Face splitting utilities + //- Number of triangles after splitting + inline label nTriangles() const; + //- Number of triangles after splitting label nTriangles(const pointField& points) const; - //- Split into triangles using existing points. Result in - // triFaces[triI..triI+nTri]. Splits intelligently to maximize - // triangle quality. - void triangles + //- Split into triangles using existing points. + // Result in triFaces[triI..triI+nTri]. + // Splits intelligently to maximize triangle quality. + // Returns number of faces created. + label triangles ( const pointField& points, label& triI, faceList& triFaces ) const; + //- Split into triangles using existing points. + // Append to DynamicList. + // Returns number of faces created. + template + label triangles + ( + const pointField& points, + DynamicList& triFaces + ) const; + //- Number of triangles and quads after splitting - void nTrianglesQuads + // Returns the sum of both + label nTrianglesQuads ( const pointField& points, label& nTris, label& nQuads ) const; - //- Split into triangles and quads. Result in triFaces (starting at - // triI and quadFaces (starting at quadI) - void trianglesQuads + //- Split into triangles and quads. + // Results in triFaces (starting at triI) and quadFaces + // (starting at quadI). + // Returns number of new faces created. + label trianglesQuads ( const pointField& points, label& triI, diff --git a/src/OpenFOAM/meshes/meshShapes/face/faceI.H b/src/OpenFOAM/meshes/meshShapes/face/faceI.H index 8b1d9a38ab..92670523be 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/faceI.H +++ b/src/OpenFOAM/meshes/meshShapes/face/faceI.H @@ -127,6 +127,11 @@ inline Foam::label Foam::face::prevLabel(const label i) const 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 * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/meshes/meshShapes/face/faceTemplates.C b/src/OpenFOAM/meshes/meshShapes/face/faceTemplates.C index 5d48a8d147..0ae9155824 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/faceTemplates.C +++ b/src/OpenFOAM/meshes/meshShapes/face/faceTemplates.C @@ -25,9 +25,28 @@ License \*---------------------------------------------------------------------------*/ #include "face.H" +#include "DynamicList.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +Foam::label Foam::face::triangles +( + const pointField& points, + DynamicList& 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 Type Foam::face::average ( diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H index e14e676aa6..8b33c722cc 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H @@ -124,6 +124,9 @@ public: //- Return vector normal inline vector normal(const pointField&) const; + //- Number of triangles after splitting + inline label nTriangles() const; + //- Return face with reverse direction inline triFace reverseFace() const; diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H index cba6d8a04c..e14f2fcee8 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H @@ -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 { // The starting points of the original and reverse face are identical.