use triFace when triangulating surfaces

This commit is contained in:
Mark Olesen
2008-11-07 22:01:23 +01:00
parent c7dc41bfd9
commit f9ec26bada
14 changed files with 75 additions and 71 deletions

View File

@ -25,10 +25,12 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "AC3DfileFormat.H" #include "AC3DfileFormat.H"
#include "triFace.H"
#include "clock.H" #include "clock.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "IStringStream.H"
#include "tensor.H" #include "tensor.H"
#include "triFace.H"
#include "primitivePatch.H" #include "primitivePatch.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H" #include "addToMemberFunctionSelectionTable.H"
@ -232,7 +234,7 @@ Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
label patchVertOffset = 0; label patchVertOffset = 0;
DynamicList<point> pointLst; DynamicList<point> pointLst;
DynamicList<face> faceLst; DynamicList<FaceType> faceLst;
DynamicList<label> regionLst; DynamicList<label> regionLst;
// patchId => patchName // patchId => patchName
@ -349,7 +351,7 @@ Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
if (triangulate && verts.size() > 3) if (triangulate && verts.size() > 3)
{ {
face fTri(3); triFace fTri;
// simple face triangulation about f[0]. // simple face triangulation about f[0].
// cannot use face::triangulation // cannot use face::triangulation
@ -535,7 +537,7 @@ void Foam::fileFormats::AC3DfileFormat::write
) )
{ {
const pointField& pointLst = surf.points(); const pointField& pointLst = surf.points();
const List<face>& faceLst = surf.faces(); const List<FaceType>& faceLst = surf.faces();
const List<surfGroup>& patchLst = surf.patches(); const List<surfGroup>& patchLst = surf.patches();
writeHeader(os, patchLst); writeHeader(os, patchLst);

View File

@ -25,6 +25,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "GTSfileFormat.H" #include "GTSfileFormat.H"
#include "triFace.H"
#include "clock.H" #include "clock.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "IStringStream.H"
@ -115,7 +116,7 @@ Foam::fileFormats::GTSfileFormat::GTSfileFormat
// write directly into the lists: // write directly into the lists:
pointField& pointLst = points(); pointField& pointLst = points();
List<face>& faceLst = faces(); List<FaceType>& faceLst = faces();
List<label>& regionLst = regions(); List<label>& regionLst = regions();
pointLst.setSize(nPoints); pointLst.setSize(nPoints);
@ -239,13 +240,7 @@ Foam::fileFormats::GTSfileFormat::GTSfileFormat
<< exit(FatalError); << exit(FatalError);
} }
face& fTri = faceLst[faceI]; faceLst[faceI] = triFace(e0Far, common01, e1Far);
fTri.setSize(3);
fTri[0] = e0Far;
fTri[1] = common01;
fTri[2] = e1Far;
regionLst[faceI] = regionI; regionLst[faceI] = regionI;
} }
@ -263,7 +258,7 @@ void Foam::fileFormats::GTSfileFormat::write
) )
{ {
const pointField& pointLst = surf.points(); const pointField& pointLst = surf.points();
const List<face>& faceLst = surf.faces(); const List<FaceType>& faceLst = surf.faces();
// It is too annoying to triangulate on-the-fly // It is too annoying to triangulate on-the-fly
// just issue a warning and get out // just issue a warning and get out
@ -356,7 +351,7 @@ void Foam::fileFormats::GTSfileFormat::write
) )
{ {
const pointField& pointLst = surf.points(); const pointField& pointLst = surf.points();
const List<face>& faceLst = surf.faces(); const List<FaceType>& faceLst = surf.faces();
const List<surfGroup>& patchLst = surf.patches(); const List<surfGroup>& patchLst = surf.patches();
// It is too annoying to triangulate on-the-fly // It is too annoying to triangulate on-the-fly

View File

@ -25,6 +25,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "NASfileFormat.H" #include "NASfileFormat.H"
#include "triFace.H"
#include "clock.H" #include "clock.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "IStringStream.H"
@ -131,7 +132,7 @@ Foam::fileFormats::NASfileFormat::NASfileFormat
DynamicList<point> pointLst; DynamicList<point> pointLst;
// Nastran index of points // Nastran index of points
DynamicList<label> pointId; DynamicList<label> pointId;
DynamicList<face> faceLst; DynamicList<FaceType> faceLst;
DynamicList<label> regionLst; DynamicList<label> regionLst;
HashTable<label> groupToPatch; HashTable<label> groupToPatch;
@ -265,7 +266,7 @@ Foam::fileFormats::NASfileFormat::NASfileFormat
if (cmd == "CTRIA3") if (cmd == "CTRIA3")
{ {
face fTri(3); triFace fTri;
label groupId = readLabel(IStringStream(line.substr(16,8))()); label groupId = readLabel(IStringStream(line.substr(16,8))());
fTri[0] = readLabel(IStringStream(line.substr(24,8))()); fTri[0] = readLabel(IStringStream(line.substr(24,8))());
@ -317,7 +318,7 @@ Foam::fileFormats::NASfileFormat::NASfileFormat
if (triangulate) if (triangulate)
{ {
face fTri(3); triFace fTri;
// simple face triangulation about f[0]. // simple face triangulation about f[0].
// cannot use face::triangulation since points are incomplete // cannot use face::triangulation since points are incomplete

View File

@ -25,6 +25,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "OBJfileFormat.H" #include "OBJfileFormat.H"
#include "triFace.H"
#include "clock.H" #include "clock.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "IStringStream.H"
@ -72,7 +73,7 @@ void Foam::fileFormats::OBJfileFormat::writeHead
( (
Ostream& os, Ostream& os,
const pointField& pointLst, const pointField& pointLst,
const List<face>& faceLst, const List<FaceType>& faceLst,
const List<surfGroup>& patchLst const List<surfGroup>& patchLst
) )
{ {
@ -137,7 +138,7 @@ Foam::fileFormats::OBJfileFormat::OBJfileFormat
} }
DynamicList<point> pointLst; DynamicList<point> pointLst;
DynamicList<face> faceLst; DynamicList<FaceType> faceLst;
DynamicList<label> regionLst; DynamicList<label> regionLst;
HashTable<label> groupToPatch; HashTable<label> groupToPatch;
@ -193,7 +194,7 @@ Foam::fileFormats::OBJfileFormat::OBJfileFormat
} }
else if (cmd == "f") else if (cmd == "f")
{ {
DynamicList<label> verts; DynamicList<label> dynVertices;
// Assume 'f' is followed by space. // Assume 'f' is followed by space.
string::size_type endNum = 1; string::size_type endNum = 1;
@ -235,23 +236,25 @@ Foam::fileFormats::OBJfileFormat::OBJfileFormat
intStream >> vertI; intStream >> vertI;
} }
verts.append(vertI - 1); dynVertices.append(vertI - 1);
} }
verts.shrink(); dynVertices.shrink();
if (triangulate && verts.size() > 3) FaceType f(SubList<label>(dynVertices, dynVertices.size()));
if (triangulate && f.size() > 3)
{ {
face fTri(3); triFace fTri;
// simple face triangulation about f[0]. // simple face triangulation about f[0].
// Cannot use face::triangulation since points are incomplete // Cannot use face::triangulation since points are incomplete
fTri[0] = verts[0]; fTri[0] = f[0];
for (label fp1 = 1; fp1 < verts.size() - 1; fp1++) for (label fp1 = 1; fp1 < f.size() - 1; fp1++)
{ {
label fp2 = (fp1 + 1) % verts.size(); label fp2 = (fp1 + 1) % f.size();
fTri[1] = verts[fp1]; fTri[1] = f[fp1];
fTri[2] = verts[fp2]; fTri[2] = f[fp2];
faceLst.append(fTri); faceLst.append(fTri);
regionLst.append(groupID); regionLst.append(groupID);
@ -259,7 +262,7 @@ Foam::fileFormats::OBJfileFormat::OBJfileFormat
} }
else else
{ {
faceLst.append(face(verts)); faceLst.append(f);
regionLst.append(groupID); regionLst.append(groupID);
} }
} }
@ -282,7 +285,7 @@ void Foam::fileFormats::OBJfileFormat::write
const keyedSurface& surf const keyedSurface& surf
) )
{ {
const List<face>& faceLst = surf.faces(); const List<FaceType>& faceLst = surf.faces();
labelList faceMap; labelList faceMap;
List<surfGroup> patchLst = surf.sortedRegions(faceMap); List<surfGroup> patchLst = surf.sortedRegions(faceMap);
@ -320,7 +323,7 @@ void Foam::fileFormats::OBJfileFormat::write
const meshedSurface& surf const meshedSurface& surf
) )
{ {
const List<face>& faceLst = surf.faces(); const List<FaceType>& faceLst = surf.faces();
const List<surfGroup>& patchLst = surf.patches(); const List<surfGroup>& patchLst = surf.patches();
writeHead(os, surf.points(), faceLst, patchLst); writeHead(os, surf.points(), faceLst, patchLst);

View File

@ -71,7 +71,7 @@ class OBJfileFormat
( (
Ostream&, Ostream&,
const pointField&, const pointField&,
const List<face>&, const List<FaceType>&,
const List<surfGroup>& const List<surfGroup>&
); );

View File

@ -25,6 +25,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "OFFfileFormat.H" #include "OFFfileFormat.H"
#include "triFace.H"
#include "clock.H" #include "clock.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "IStringStream.H"
@ -72,7 +73,7 @@ void Foam::fileFormats::OFFfileFormat::writeHead
( (
Ostream& os, Ostream& os,
const pointField& pointLst, const pointField& pointLst,
const List<face>& faceLst, const List<FaceType>& faceLst,
const List<surfGroup>& patchLst const List<surfGroup>& patchLst
) )
{ {
@ -178,7 +179,7 @@ Foam::fileFormats::OFFfileFormat::OFFfileFormat
// Read faces - ignore optional region information // Read faces - ignore optional region information
// use a DynamicList for possible on-the-fly triangulation // use a DynamicList for possible on-the-fly triangulation
DynamicList<face> faceLst(nElems); DynamicList<FaceType> faceLst(nElems);
forAll(faceLst, faceI) forAll(faceLst, faceI)
{ {
@ -198,7 +199,7 @@ Foam::fileFormats::OFFfileFormat::OFFfileFormat
if (triangulate && f.size() > 3) if (triangulate && f.size() > 3)
{ {
face fTri(3); triFace fTri;
// simple face triangulation about f[0]. // simple face triangulation about f[0].
// cannot use face::triangulation since points are incomplete // cannot use face::triangulation since points are incomplete
@ -241,7 +242,7 @@ void Foam::fileFormats::OFFfileFormat::write
const keyedSurface& surf const keyedSurface& surf
) )
{ {
const List<face>& faceLst = surf.faces(); const List<FaceType>& faceLst = surf.faces();
labelList faceMap; labelList faceMap;
List<surfGroup> patchLst = surf.sortedRegions(faceMap); List<surfGroup> patchLst = surf.sortedRegions(faceMap);
@ -278,7 +279,7 @@ void Foam::fileFormats::OFFfileFormat::write
const meshedSurface& surf const meshedSurface& surf
) )
{ {
const List<face>& faceLst = surf.faces(); const List<FaceType>& faceLst = surf.faces();
const List<surfGroup>& patchLst = surf.patches(); const List<surfGroup>& patchLst = surf.patches();
writeHead(os, surf.points(), faceLst, patchLst); writeHead(os, surf.points(), faceLst, patchLst);

View File

@ -78,7 +78,7 @@ class OFFfileFormat
( (
Ostream&, Ostream&,
const pointField&, const pointField&,
const List<face>&, const List<FaceType>&,
const List<surfGroup>& const List<surfGroup>&
); );

View File

@ -25,6 +25,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "STLfileFormat.H" #include "STLfileFormat.H"
#include "triFace.H"
#include "clock.H" #include "clock.H"
#include "OSspecific.H" #include "OSspecific.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
@ -216,9 +217,7 @@ bool Foam::fileFormats::STLfileFormat::readBINARY
label pointI = 0; label pointI = 0;
forAll(faceLst, faceI) forAll(faceLst, faceI)
{ {
face& fTri = faceLst[faceI]; triFace fTri;
fTri.setSize(3);
// Read an STL triangle // Read an STL triangle
STLtriangle stlTri(is); STLtriangle stlTri(is);
@ -235,14 +234,16 @@ bool Foam::fileFormats::STLfileFormat::readBINARY
pointLst[pointI] = stlTri.c(); pointLst[pointI] = stlTri.c();
fTri[2] = pointI++; fTri[2] = pointI++;
faceLst[faceI] = fTri;
// interprete colour as a region
regionLst[faceI] = stlTri.region();
if (maxRegionId < stlTri.region()) if (maxRegionId < stlTri.region())
{ {
maxRegionId = stlTri.region(); maxRegionId = stlTri.region();
} }
// interprete colour as a region
regionLst[faceI] = stlTri.region();
#ifdef DEBUG_STLBINARY #ifdef DEBUG_STLBINARY
if if
( (

View File

@ -33,6 +33,7 @@ License
\* ------------------------------------------------------------------------ */ \* ------------------------------------------------------------------------ */
#include "STLfileFormat.H" #include "STLfileFormat.H"
#include "triFace.H"
using namespace Foam; using namespace Foam;
@ -395,18 +396,19 @@ Foam::fileFormats::STLfileFormat::readASCII
regions().transfer(lexer.facets()); regions().transfer(lexer.facets());
// make our triangles directly // make our triangles directly
List<face>& faceLst = faces(); List<FaceType>& faceLst = faces();
faceLst.setSize(regions().size()); faceLst.setSize(regions().size());
label ptI = 0; label ptI = 0;
forAll(faceLst, faceI) forAll(faceLst, faceI)
{ {
face& fTri = faceLst[faceI]; triFace fTri;
fTri.setSize(3);
fTri[0] = ptI++; fTri[0] = ptI++;
fTri[1] = ptI++; fTri[1] = ptI++;
fTri[2] = ptI++; fTri[2] = ptI++;
faceLst[faceI] = fTri;
} }
setPatches(lexer.groupToPatch()); setPatches(lexer.groupToPatch());

View File

@ -25,6 +25,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "TRIfileFormat.H" #include "TRIfileFormat.H"
#include "triFace.H"
#include "clock.H" #include "clock.H"
#include "IFstream.H" #include "IFstream.H"
#include "IOmanip.H" #include "IOmanip.H"
@ -214,18 +215,19 @@ Foam::fileFormats::TRIfileFormat::TRIfileFormat
regions().transfer(regionLst); regions().transfer(regionLst);
// make our triangles directly // make our triangles directly
List<face>& faceLst = faces(); List<FaceType>& faceLst = faces();
faceLst.setSize(regions().size()); faceLst.setSize(regions().size());
label ptI = 0; label ptI = 0;
forAll(faceLst, faceI) forAll(faceLst, faceI)
{ {
face& fTri = faceLst[faceI]; triFace fTri;
fTri.setSize(3);
fTri[0] = ptI++; fTri[0] = ptI++;
fTri[1] = ptI++; fTri[1] = ptI++;
fTri[2] = ptI++; fTri[2] = ptI++;
faceLst[faceI] = fTri;
} }
setPatches(groupToPatch); setPatches(groupToPatch);

View File

@ -26,6 +26,7 @@ License
#include "keyedSurface.H" #include "keyedSurface.H"
#include "mergePoints.H" #include "mergePoints.H"
#include "triFace.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -259,8 +260,7 @@ Foam::label Foam::keyedSurface::triangulate()
forAll (faceLst, faceI) forAll (faceLst, faceI)
{ {
const FaceType& f = faceLst[faceI]; const FaceType& f = faceLst[faceI];
triFace fTri;
FaceType fTri(3);
// Do simple face triangulation around f[0]. // Do simple face triangulation around f[0].
// we could also use face::triangulation // we could also use face::triangulation

View File

@ -26,6 +26,7 @@ License
#include "meshedSurface.H" #include "meshedSurface.H"
#include "mergePoints.H" #include "mergePoints.H"
#include "triFace.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -296,7 +297,7 @@ Foam::label Foam::meshedSurface::triangulate()
for (; oldFaceI < patchEnd; ++oldFaceI) for (; oldFaceI < patchEnd; ++oldFaceI)
{ {
const FaceType& f = faceLst[oldFaceI]; const FaceType& f = faceLst[oldFaceI];
FaceType fTri(3); triFace fTri;
// Do simple face triangulation around f[0]. // Do simple face triangulation around f[0].
// we could also use face::triangulation // we could also use face::triangulation

View File

@ -88,7 +88,7 @@ Foam::surfGroup::surfGroup
{} {}
Foam::surfGroup::surfGroup(const Foam::surfGroup& p) Foam::surfGroup::surfGroup(const surfGroup& p)
: :
surfPatchIdentifier(p, p.index()), surfPatchIdentifier(p, p.index()),
size_(p.size()), size_(p.size()),
@ -96,7 +96,7 @@ Foam::surfGroup::surfGroup(const Foam::surfGroup& p)
{} {}
Foam::surfGroup::surfGroup(const Foam::surfGroup& p, const label index) Foam::surfGroup::surfGroup(const surfGroup& p, const label index)
: :
surfPatchIdentifier(p, index), surfPatchIdentifier(p, index),
size_(p.size()), size_(p.size()),

View File

@ -107,11 +107,7 @@ public:
surfGroup(const surfGroup&); surfGroup(const surfGroup&);
//- Construct from another patch, resetting the index //- Construct from another patch, resetting the index
surfGroup surfGroup(const surfGroup&, const label index);
(
const surfGroup&,
const label index
);
//- Return clone //- Return clone
autoPtr<surfGroup> clone() const autoPtr<surfGroup> clone() const