Commit da8ea0f2 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: refactor code from surfaceFeatureExtract to triSurfaceTools (issue #450)

parent 11c54566
......@@ -25,6 +25,12 @@ $(edgeMeshFormats)/starcd/STARCDedgeFormatRunTime.C
$(edgeMeshFormats)/vtk/VTKedgeFormat.C
$(edgeMeshFormats)/vtk/VTKedgeFormatRunTime.C
edgeMeshTools = $(em)/edgeMeshTools
$(edgeMeshTools)/edgeMeshTools.C
$(edgeMeshTools)/edgeMeshFeatureProximity.C
$(em)/featureEdgeMesh/featureEdgeMesh.C
eem = $(em)/extendedEdgeMesh
......@@ -215,6 +221,8 @@ triSurface/triangleFuncs/triangleFuncs.C
triSurface/surfaceFeatures/surfaceFeatures.C
triSurface/triSurfaceLoader/triSurfaceLoader.C
triSurface/triSurfaceTools/triSurfaceTools.C
triSurface/triSurfaceTools/triSurfaceCloseness.C
triSurface/triSurfaceTools/triSurfaceCurvature.C
triSurface/triSurfaceTools/geompack/geompack.C
triSurface/triSurfaceTools/pointToPointPlanarInterpolation.C
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "edgeMeshTools.H"
#include "extendedEdgeMesh.H"
#include "triSurface.H"
#include "triSurfaceFields.H"
#include "pointIndexHit.H"
#include "MeshedSurface.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
static scalar calcProximityOfFeaturePoints
(
const List<pointIndexHit>& hitList,
const scalar defaultCellSize
)
{
scalar minDist = defaultCellSize;
for
(
label hI1 = 0;
hI1 < hitList.size() - 1;
++hI1
)
{
const pointIndexHit& pHit1 = hitList[hI1];
if (pHit1.hit())
{
for
(
label hI2 = hI1 + 1;
hI2 < hitList.size();
++hI2
)
{
const pointIndexHit& pHit2 = hitList[hI2];
if (pHit2.hit())
{
scalar curDist = mag(pHit1.hitPoint() - pHit2.hitPoint());
minDist = min(curDist, minDist);
}
}
}
}
return minDist;
}
scalar calcProximityOfFeatureEdges
(
const edgeMesh& emesh,
const List<pointIndexHit>& hitList,
const scalar defaultCellSize
)
{
scalar minDist = defaultCellSize;
for
(
label hI1 = 0;
hI1 < hitList.size() - 1;
++hI1
)
{
const pointIndexHit& pHit1 = hitList[hI1];
if (pHit1.hit())
{
const edge& e1 = emesh.edges()[pHit1.index()];
for
(
label hI2 = hI1 + 1;
hI2 < hitList.size();
++hI2
)
{
const pointIndexHit& pHit2 = hitList[hI2];
if (pHit2.hit())
{
const edge& e2 = emesh.edges()[pHit2.index()];
// Don't refine if the edges are connected to each other
if (!e1.connects(e2))
{
scalar curDist =
mag(pHit1.hitPoint() - pHit2.hitPoint());
minDist = min(curDist, minDist);
}
}
}
}
}
return minDist;
}
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::tmp<Foam::scalarField> Foam::edgeMeshTools::featureProximity
(
const extendedEdgeMesh& emesh,
const triSurface& surf,
const scalar searchDistance
)
{
tmp<scalarField> tfld(new scalarField(surf.size(), searchDistance));
scalarField& featureProximity = tfld.ref();
Info<< "Extracting proximity of close feature points and "
<< "edges to the surface" << endl;
forAll(surf, fI)
{
const triPointRef& tri = surf[fI].tri(surf.points());
const point& triCentre = tri.circumCentre();
const scalar radiusSqr = min
(
sqr(4*tri.circumRadius()),
sqr(searchDistance)
);
List<pointIndexHit> hitList;
emesh.allNearestFeatureEdges(triCentre, radiusSqr, hitList);
featureProximity[fI] =
calcProximityOfFeatureEdges
(
emesh,
hitList,
featureProximity[fI]
);
emesh.allNearestFeaturePoints(triCentre, radiusSqr, hitList);
featureProximity[fI] =
calcProximityOfFeaturePoints
(
hitList,
featureProximity[fI]
);
}
return tfld;
}
Foam::tmp<Foam::scalarField> Foam::edgeMeshTools::writeFeatureProximity
(
const Time& runTime,
const word& basename,
const extendedEdgeMesh& emesh,
const triSurface& surf,
const scalar searchDistance
)
{
Info<< nl << "Extracting curvature of surface at the points."
<< endl;
tmp<scalarField> tfld =
edgeMeshTools::featureProximity(emesh, surf, searchDistance);
scalarField& featureProximity = tfld.ref();
triSurfaceScalarField outputField
(
IOobject
(
basename + ".featureProximity",
runTime.constant(),
"triSurface",
runTime,
IOobject::NO_READ,
IOobject::NO_WRITE
),
surf,
dimLength,
scalarField()
);
outputField.swap(featureProximity);
outputField.write();
outputField.swap(featureProximity);
return tfld;
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "edgeMeshTools.H"
#include "extendedFeatureEdgeMesh.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void Foam::edgeMeshTools::writeStats
(
Ostream& os,
const extendedFeatureEdgeMesh& emesh
)
{
os << "Feature set:" << nl
<< " points : " << emesh.points().size() << nl
<< " of which" << nl
<< " convex : "
<< emesh.concaveStart() << nl
<< " concave : "
<< (emesh.mixedStart()-emesh.concaveStart()) << nl
<< " mixed : "
<< (emesh.nonFeatureStart()-emesh.mixedStart()) << nl
<< " non-feature : "
<< (emesh.points().size()-emesh.nonFeatureStart()) << nl
<< " edges : " << emesh.edges().size() << nl
<< " of which" << nl
<< " external edges : "
<< emesh.internalStart() << nl
<< " internal edges : "
<< (emesh.flatStart()- emesh.internalStart()) << nl
<< " flat edges : "
<< (emesh.openStart()- emesh.flatStart()) << nl
<< " open edges : "
<< (emesh.multipleStart()- emesh.openStart()) << nl
<< " multiply connected : "
<< (emesh.edges().size()- emesh.multipleStart()) << endl;
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Namespace
Foam::edgeMeshTools
Description
Collection of static functions related to edgeMesh features.
SourceFiles
edgeMeshTools.C
edgeMeshFeatureProximity.C
\*---------------------------------------------------------------------------*/
#ifndef edgeMeshTools_H
#define edgeMeshTools_H
#include "tmp.H"
#include "scalarField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class edgeMesh;
class extendedEdgeMesh;
class extendedFeatureEdgeMesh;
class triSurface;
class Time;
class Ostream;
/*---------------------------------------------------------------------------*\
Namespace edgeMeshTools Declaration
\*---------------------------------------------------------------------------*/
namespace edgeMeshTools
{
//- Write some information
void writeStats
(
Ostream& os,
const extendedFeatureEdgeMesh& emesh
);
//- Calculate proximity of the features to the surface
tmp<scalarField> featureProximity
(
const extendedEdgeMesh& emesh,
const triSurface& surf,
const scalar searchDistance
);
//- Calculate proximity of the features to the surface and write the field
tmp<scalarField> writeFeatureProximity
(
const Time& runTime,
const word& basename,
const extendedEdgeMesh& emesh,
const triSurface& surf,
const scalar searchDistance
);
} // End namespace edgeMeshTools
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -94,23 +94,22 @@ public:
enum pointStatus
{
CONVEX, // Fully convex point (w.r.t normals)
CONCAVE, // Fully concave point
MIXED, // A point surrounded by both convex and concave edges
NONFEATURE // Not a feature point
CONVEX, //!< Fully convex point (w.r.t normals)
CONCAVE, //!< Fully concave point
MIXED, //!< A point surrounded by both convex and concave edges
NONFEATURE //!< Not a feature point
};
static const Foam::NamedEnum<pointStatus, 4> pointStatusNames_;
enum edgeStatus
{
EXTERNAL, // "Convex" edge
INTERNAL, // "Concave" edge
FLAT, // Neither concave or convex, on a flat surface
OPEN, // i.e. only connected to one face
MULTIPLE, // Multiply connected (connected to more than two faces)
NONE // Not a classified feature edge (consistency with
// surfaceFeatures)
EXTERNAL, //!< "Convex" edge
INTERNAL, //!< "Concave" edge
FLAT, //!< Neither concave or convex, on a flat surface
OPEN, //!< Only connected to a single face
MULTIPLE, //!< Multiply connected (connected to more than two faces)
NONE //!< Unclassified (consistency with surfaceFeatures)
};
static const Foam::NamedEnum<edgeStatus, 6> edgeStatusNames_;
......@@ -118,10 +117,10 @@ public:
//- Normals point to the outside
enum sideVolumeType
{
INSIDE = 0, // mesh inside
OUTSIDE = 1, // mesh outside
BOTH = 2, // e.g. a baffle
NEITHER = 3 // not sure when this may be used
INSIDE = 0, //!< mesh inside
OUTSIDE = 1, //!< mesh outside
BOTH = 2, //!< e.g. a baffle
NEITHER = 3 //!< not sure when this may be used
};
static const Foam::NamedEnum<sideVolumeType, 4> sideVolumeTypeNames_;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -42,7 +42,30 @@ namespace Foam
defineTypeNameAndDebug(surfaceFeatures, 0);
const scalar surfaceFeatures::parallelTolerance = sin(degToRad(1.0));
//! \cond fileScope
// Check if the point is on the line
static bool onLine(const Foam::point& p, const linePointRef& line)
{
const point& a = line.start();
const point& b = line.end();
if
(
(p.x() < min(a.x(), b.x()) || p.x() > max(a.x(), b.x()))
|| (p.y() < min(a.y(), b.y()) || p.y() > max(a.y(), b.y()))
|| (p.z() < min(a.z(), b.z()) || p.z() > max(a.z(), b.z()))
)
{
return false;
}
return true;
}
//! \endcond
} // End namespace Foam
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
......@@ -442,6 +465,181 @@ Foam::surfaceFeatures::labelScalar Foam::surfaceFeatures::walkSegment
}
//- Divide into multiple normal bins
// - return REGION if != 2 normals
// - return REGION if 2 normals that make feature angle
// - otherwise return NONE and set normals,bins
//
// This has been relocated from surfaceFeatureExtract and could be cleaned
// up some more.
//
Foam::surfaceFeatures::edgeStatus
Foam::surfaceFeatures::surfaceFeatures::checkFlatRegionEdge
(
const scalar tol,
const scalar includedAngle,
const label edgeI
) const
{
const triSurface& surf = surf_;
const edge& e = surf.edges()[edgeI];
const labelList& eFaces = surf.edgeFaces()[edgeI];
// Bin according to normal
DynamicList<vector> normals(2);
DynamicList<labelList> bins(2);
forAll(eFaces, eFacei)
{
const vector& n = surf.faceNormals()[eFaces[eFacei]];
// Find the normal in normals
label index = -1;
forAll(normals, normalI)
{
if (mag(n & normals[normalI]) > (1-tol))
{
index = normalI;
break;
}
}
if (index != -1)
{
bins[index].append(eFacei);
}
else if (normals.size() >= 2)
{
// Would be third normal. Mark as feature.
//Pout<< "** at edge:" << surf.localPoints()[e[0]]
// << surf.localPoints()[e[1]]
// << " have normals:" << normals
// << " and " << n << endl;
return surfaceFeatures::REGION;
}
else
{
normals.append(n);
bins.append(labelList(1, eFacei));
}
}
// Check resulting number of bins
if (bins.size() == 1)
{
// Note: should check here whether they are two sets of faces
// that are planar or indeed 4 faces al coming together at an edge.
//Pout<< "** at edge:"
// << surf.localPoints()[e[0]]
// << surf.localPoints()[e[1]]
// << " have single normal:" << normals[0]
// << endl;
return surfaceFeatures::NONE;
}
else
{
// Two bins. Check if normals make an angle
//Pout<< "** at edge:"
// << surf.localPoints()[e[0]]
// << surf.localPoints()[e[1]] << nl
// << " normals:" << normals << nl
// << " bins :" << bins << nl
// << endl;
if (includedAngle >= 0)
{
scalar minCos = Foam::cos(degToRad(180.0 - includedAngle));
forAll(eFaces, i)
{
const vector& ni = surf.faceNormals()[eFaces[i]];
for (label j=i+1; j<eFaces.size(); j++)
{