ENH: add triFace valid() method

- similar to edge valid(), true if vertices are unique, non-negative
This commit is contained in:
Mark Olesen
2022-03-15 12:54:20 +01:00
parent 46a1e7e21e
commit 079d5f2771
10 changed files with 105 additions and 72 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -58,23 +58,22 @@ static triSurface pack
)
{
List<labelledTri> newTriangles(surf.size());
label newTriangleI = 0;
label nNewTris = 0;
forAll(surf, facei)
// Iterate and work on a copy
for (labelledTri f : surf.localFaces())
{
const labelledTri& f = surf.localFaces()[facei];
// inplace renumber
f[0] = pointMap[f[0]];
f[1] = pointMap[f[1]];
f[2] = pointMap[f[2]];
label newA = pointMap[f[0]];
label newB = pointMap[f[1]];
label newC = pointMap[f[2]];
if ((newA != newB) && (newA != newC) && (newB != newC))
if (f.valid())
{
newTriangles[newTriangleI++] =
labelledTri(newA, newB, newC, f.region());
newTriangles[nNewTris++] = f;
}
}
newTriangles.setSize(newTriangleI);
newTriangles.resize(nNewTris);
return triSurface(newTriangles, surf.patches(), localPoints);
}
@ -92,11 +91,7 @@ label collapseEdge(triSurface& surf, const scalar minLen)
// Mapping from old to new points
labelList pointMap(surf.nPoints());
forAll(pointMap, i)
{
pointMap[i] = i;
}
labelList pointMap(identity(surf.nPoints()));
// Storage for new points.
pointField newPoints(localPoints);

View File

@ -103,6 +103,23 @@ public:
//- Construct from a list of 3 or 4 labels. Default region is 0.
inline explicit labelledTri(std::initializer_list<label>);
//- Copy construct from a subset of point labels
//- and optional region index (0 if unspecified)
inline labelledTri
(
const labelUList& list,
const FixedList<label, 3>& triIndices,
const label region = 0
);
//- Copy construct from a subset of point labels
//- with region index from input labelledTri
inline labelledTri
(
const labelUList& list,
const labelledTri& triIndices
);
//- Construct from Istream
inline labelledTri(Istream& is);

View File

@ -106,6 +106,29 @@ inline Foam::labelledTri::labelledTri(std::initializer_list<label> list)
}
inline Foam::labelledTri::labelledTri
(
const labelUList& list,
const FixedList<label, 3>& triIndices,
const label region
)
:
triFace(list, triIndices),
index_(region)
{}
inline Foam::labelledTri::labelledTri
(
const labelUList& list,
const labelledTri& triIndices
)
:
triFace(list, triIndices),
index_(triIndices.region())
{}
inline Foam::labelledTri::labelledTri(Istream& is)
{
operator>>(is, *this);

View File

@ -40,8 +40,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef triFace_H
#define triFace_H
#ifndef Foam_triFace_H
#define Foam_triFace_H
#include "FixedList.H"
#include "edgeList.H"
@ -120,6 +120,12 @@ public:
label second() const { return operator[](1); }
// Queries
//- Return true if the vertices are unique and non-negative.
inline bool valid() const;
// Other
//- 'Collapse' face by marking duplicate point labels.

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -111,6 +111,17 @@ inline Foam::triFace::triFace(Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline bool Foam::triFace::valid() const
{
return
(
operator[](0) >= 0 && operator[](0) != operator[](1)
&& operator[](1) >= 0 && operator[](1) != operator[](2)
&& operator[](2) >= 0 && operator[](0) != operator[](2)
);
}
inline Foam::label Foam::triFace::collapse()
{
// Cannot resize FixedList, so mark duplicates with '-1'

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,7 +27,6 @@ License
\*---------------------------------------------------------------------------*/
#include "triSurfaceTools.H"
#include "triSurface.H"
#include "MeshedSurface.H"
#include "OFstream.H"
@ -1594,12 +1593,7 @@ Foam::triSurface Foam::triSurfaceTools::collapseEdges
pointField newPoints(localPoints);
// Map for old to new points
labelList pointMap(localPoints.size());
forAll(localPoints, pointi)
{
pointMap[pointi] = pointi;
}
labelList pointMap(identity(localPoints.size()));
// Do actual 'collapsing' of edges
@ -1688,43 +1682,36 @@ Foam::triSurface Foam::triSurfaceTools::collapseEdges
// Storage for new triangles
List<labelledTri> newTris(surf.size());
label newTriI = 0;
List<labelledTri> newTriangles(surf.size());
label nNewTris = 0;
const List<labelledTri>& localFaces = surf.localFaces();
// Get only non-collapsed triangles and renumber vertex labels.
forAll(localFaces, facei)
{
const labelledTri& f = localFaces[facei];
const label a = pointMap[f[0]];
const label b = pointMap[f[1]];
const label c = pointMap[f[2]];
if
(
(a != b) && (a != c) && (b != c)
&& (faceStatus[facei] != COLLAPSED)
)
if (faceStatus[facei] != COLLAPSED)
{
// uncollapsed triangle
newTris[newTriI++] = labelledTri(a, b, c, f.region());
}
else
{
//Pout<< "Collapsed triangle " << facei
// << " vertices:" << f << endl;
}
}
newTris.setSize(newTriI);
// Uncollapsed triangle
labelledTri f(localFaces[facei]);
// inplace renumber
f[0] = pointMap[f[0]];
f[1] = pointMap[f[1]];
f[2] = pointMap[f[2]];
if (f.valid())
{
newTriangles[nNewTris++] = f;
}
}
}
newTriangles.resize(nNewTris);
// Pack faces
triSurface tempSurf(newTris, surf.patches(), newPoints);
triSurface tempSurf(newTriangles, surf.patches(), newPoints);
return
triSurface
@ -1919,23 +1906,22 @@ Foam::triSurface Foam::triSurfaceTools::mergePoints
// Storage for new triangles
List<labelledTri> newTriangles(surf.size());
label newTriangleI = 0;
label nNewTris = 0;
forAll(surf, facei)
// Iterate and work on a copy
for (labelledTri f : surf.localFaces())
{
const labelledTri& f = surf.localFaces()[facei];
// inplace renumber
f[0] = pointMap[f[0]];
f[1] = pointMap[f[1]];
f[2] = pointMap[f[2]];
label newA = pointMap[f[0]];
label newB = pointMap[f[1]];
label newC = pointMap[f[2]];
if ((newA != newB) && (newA != newC) && (newB != newC))
if (f.valid())
{
newTriangles[newTriangleI++] =
labelledTri(newA, newB, newC, f.region());
newTriangles[nNewTris++] = f;
}
}
newTriangles.setSize(newTriangleI);
newTriangles.resize(nNewTris);
return triSurface
(

View File

@ -820,7 +820,7 @@ Foam::triSurface Foam::isoSurfaceCell::stitchTriPoints
triPointReverseMap[rawPointi+2],
0
);
if ((tri[0] != tri[1]) && (tri[0] != tri[2]) && (tri[1] != tri[2]))
if (tri.valid())
{
newToOldTri.append(oldTriI);
dynTris.append(tri);

View File

@ -949,7 +949,7 @@ Foam::triSurface Foam::isoSurfacePoint::stitchTriPoints
);
rawPointi += 3;
if ((tri[0] != tri[1]) && (tri[0] != tri[2]) && (tri[1] != tri[2]))
if (tri.valid())
{
newToOldTri.append(oldTriI);
dynTris.append(tri);

View File

@ -211,7 +211,7 @@ void Foam::triSurface::checkTriangles(const bool verbose)
{
const labelledTri& f = (*this)[facei];
if ((f[0] == f[1]) || (f[0] == f[2]) || (f[1] == f[2]))
if (!f.valid())
{
// 'degenerate' triangle check
valid.unset(facei);

View File

@ -68,12 +68,7 @@ bool Foam::triSurface::stitchTriangles
tri.region()
);
if
(
(newTri[0] != newTri[1])
&& (newTri[0] != newTri[2])
&& (newTri[1] != newTri[2])
)
if (newTri.valid())
{
operator[](newTriangleI++) = newTri;
}