ENH: provide triSurfaceTools::validTri() method to reduce code duplication

- identical code was present in surfaceCheck (original source),
  and isoSurface, isoSurfaceCell (copies).

- add in a MeshedSurface<face> variant as well, since this will likely
  be needed in the near future
This commit is contained in:
Mark Olesen
2016-11-24 15:31:32 +01:00
parent da78cba7da
commit c3005794ab
7 changed files with 183 additions and 227 deletions

View File

@ -33,6 +33,7 @@ License
#include "OFstream.H"
#include "meshTools.H"
#include "triSurfaceSearch.H"
#include "triSurfaceTools.H"
#include "surfaceIntersection.H"
#include "intersectedSurface.H"
#include "searchableBox.H"
@ -1257,76 +1258,6 @@ void Foam::isoSurface::trimToBox
}
bool Foam::isoSurface::validTri(const triSurface& surf, const label facei)
{
// Simple check on indices ok.
const labelledTri& f = surf[facei];
if
(
(f[0] < 0) || (f[0] >= surf.points().size())
|| (f[1] < 0) || (f[1] >= surf.points().size())
|| (f[2] < 0) || (f[2] >= surf.points().size())
)
{
WarningInFunction
<< "triangle " << facei << " vertices " << f
<< " uses point indices outside point range 0.."
<< surf.points().size()-1 << endl;
return false;
}
if ((f[0] == f[1]) || (f[0] == f[2]) || (f[1] == f[2]))
{
WarningInFunction
<< "triangle " << facei
<< " uses non-unique vertices " << f
<< endl;
return false;
}
// duplicate triangle check
const labelList& fFaces = surf.faceFaces()[facei];
// Check if faceNeighbours use same points as this face.
// Note: discards normal information - sides of baffle are merged.
forAll(fFaces, i)
{
label nbrFacei = fFaces[i];
if (nbrFacei <= facei)
{
// lower numbered faces already checked
continue;
}
const labelledTri& nbrF = surf[nbrFacei];
if
(
((f[0] == nbrF[0]) || (f[0] == nbrF[1]) || (f[0] == nbrF[2]))
&& ((f[1] == nbrF[0]) || (f[1] == nbrF[1]) || (f[1] == nbrF[2]))
&& ((f[2] == nbrF[0]) || (f[2] == nbrF[1]) || (f[2] == nbrF[2]))
)
{
WarningInFunction
<< "triangle " << facei << " vertices " << f
<< " fc:" << f.centre(surf.points())
<< " has the same vertices as triangle " << nbrFacei
<< " vertices " << nbrF
<< " fc:" << nbrF.centre(surf.points())
<< endl;
return false;
}
}
return true;
}
Foam::triSurface Foam::isoSurface::subsetMesh
(
const triSurface& s,
@ -1756,8 +1687,7 @@ Foam::isoSurface::isoSurface
forAll(*this, triI)
{
// Copied from surfaceCheck
validTri(*this, triI);
triSurfaceTools::validTri(*this, triI);
}
fileName stlFile = mesh_.time().path() + ".stl";

View File

@ -377,9 +377,6 @@ class isoSurface
List<FixedList<scalar, 3>>& interpolationWeights
);
//- Check single triangle for (topological) validity
static bool validTri(const triSurface&, const label facei);
static triSurface subsetMesh
(
const triSurface& s,

View File

@ -29,6 +29,7 @@ License
#include "mergePoints.H"
#include "tetMatcher.H"
#include "syncTools.H"
#include "triSurfaceTools.H"
#include "addToRunTimeSelectionTable.H"
#include "Time.H"
#include "triPoints.H"
@ -1049,73 +1050,6 @@ Foam::triSurface Foam::isoSurfaceCell::stitchTriPoints
}
bool Foam::isoSurfaceCell::validTri(const triSurface& surf, const label facei)
{
// Simple check on indices ok.
const labelledTri& f = surf[facei];
forAll(f, fp)
{
if (f[fp] < 0 || f[fp] >= surf.points().size())
{
WarningInFunction
<< "triangle " << facei << " vertices " << f
<< " uses point indices outside point range 0.."
<< surf.points().size()-1 << endl;
return false;
}
}
if ((f[0] == f[1]) || (f[0] == f[2]) || (f[1] == f[2]))
{
WarningInFunction
<< "triangle " << facei
<< " uses non-unique vertices " << f
<< endl;
return false;
}
// duplicate triangle check
const labelList& fFaces = surf.faceFaces()[facei];
// Check if faceNeighbours use same points as this face.
// Note: discards normal information - sides of baffle are merged.
forAll(fFaces, i)
{
label nbrFacei = fFaces[i];
if (nbrFacei <= facei)
{
// lower numbered faces already checked
continue;
}
const labelledTri& nbrF = surf[nbrFacei];
if
(
((f[0] == nbrF[0]) || (f[0] == nbrF[1]) || (f[0] == nbrF[2]))
&& ((f[1] == nbrF[0]) || (f[1] == nbrF[1]) || (f[1] == nbrF[2]))
&& ((f[2] == nbrF[0]) || (f[2] == nbrF[1]) || (f[2] == nbrF[2]))
)
{
WarningInFunction
<< "triangle " << facei << " vertices " << f
<< " coords:" << f.points(surf.points())
<< " has the same vertices as triangle " << nbrFacei
<< " vertices " << nbrF
<< endl;
return false;
}
}
return true;
}
void Foam::isoSurfaceCell::calcAddressing
(
const triSurface& surf,
@ -1569,8 +1503,7 @@ Foam::isoSurfaceCell::isoSurfaceCell
forAll(*this, triI)
{
// Copied from surfaceCheck
validTri(*this, triI);
triSurfaceTools::validTri(*this, triI);
}
}

View File

@ -272,9 +272,6 @@ class isoSurfaceCell
labelList& triMap // merged to unmerged triangle
) const;
//- Check single triangle for (topological) validity
static bool validTri(const triSurface&, const label);
//- Determine edge-face addressing
void calcAddressing
(