diff --git a/applications/utilities/surface/surfaceFeatureExtract/Make/files b/applications/utilities/surface/surfaceFeatureExtract/Make/files index 44b4b18fc..a57125cd6 100644 --- a/applications/utilities/surface/surfaceFeatureExtract/Make/files +++ b/applications/utilities/surface/surfaceFeatureExtract/Make/files @@ -1,4 +1,3 @@ -surfaceFeatureExtractUtilities.C surfaceFeatureExtract.C EXE = $(FOAM_APPBIN)/surfaceFeatureExtract diff --git a/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C b/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C index aa76e308e..39817f4e1 100644 --- a/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C +++ b/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C @@ -23,12 +23,12 @@ License \*---------------------------------------------------------------------------*/ -#include "surfaceFeatureExtract.H" #include "argList.H" #include "Time.H" #include "triSurfaceMesh.H" #include "featureEdgeMesh.H" #include "extendedFeatureEdgeMesh.H" +#include "surfaceFeatures.H" #include "triSurfaceFields.H" #include "vtkSurfaceWriter.H" #include "IOdictionary.H" @@ -37,6 +37,37 @@ using namespace Foam; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +namespace Foam +{ + void writeStats(const extendedFeatureEdgeMesh& fem, Ostream& os) + { + os << " points : " << fem.points().size() << nl + << " of which" << nl + << " convex : " + << fem.concaveStart() << nl + << " concave : " + << (fem.mixedStart() - fem.concaveStart()) << nl + << " mixed : " + << (fem.nonFeatureStart() - fem.mixedStart()) << nl + << " non-feature : " + << (fem.points().size() - fem.nonFeatureStart()) << nl + << " edges : " << fem.edges().size() << nl + << " of which" << nl + << " external edges : " + << fem.internalStart() << nl + << " internal edges : " + << (fem.flatStart() - fem.internalStart()) << nl + << " flat edges : " + << (fem.openStart() - fem.flatStart()) << nl + << " open edges : " + << (fem.multipleStart() - fem.openStart()) << nl + << " multiply connected : " + << (fem.edges().size() - fem.multipleStart()) << endl; + } +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + int main(int argc, char *argv[]) { argList::addNote @@ -234,19 +265,19 @@ int main(int argc, char *argv[]) { treeBoundBox bb(subsetDict.lookup("insideBox")()); - Info<< "Removing all edges outside bb " << bb - << " see subsetBox.obj" << endl; - bb.writeOBJ("subsetBox.obj"); - deleteBox(surf, bb, false, edgeStat); + Info<< "Selecting edges inside bb " << bb + << " see insideBox.obj" << endl; + bb.writeOBJ("insideBox.obj"); + selectBox(surf, bb, true, edgeStat); } else if (subsetDict.found("outsideBox")) { treeBoundBox bb(subsetDict.lookup("outsideBox")()); Info<< "Removing all edges inside bb " << bb - << " see deleteBox.obj" << endl; - bb.writeOBJ("deleteBox.obj"); - deleteBox(surf, bb, true, edgeStat); + << " see outsideBox.obj" << endl; + bb.writeOBJ("outsideBox.obj"); + selectBox(surf, bb, false, edgeStat); } const Switch nonManifoldEdges = @@ -258,7 +289,7 @@ int main(int argc, char *argv[]) << " (edges with > 2 connected faces) unless they" << " cross multiple regions" << endl; - deleteNonManifoldEdges(surf, 1e-5, includedAngle, edgeStat); + selectManifoldEdges(surf, 1e-5, includedAngle, edgeStat); } const Switch openEdges = @@ -280,9 +311,9 @@ int main(int argc, char *argv[]) if (subsetDict.found("plane")) { - plane cutPlane(subsetDict.lookup("plane")()); + const plane cutPlane(subsetDict.lookup("plane")()); - deleteEdges(surf, cutPlane, edgeStat); + selectCutEdges(surf, cutPlane, edgeStat); Info<< "Only edges that intersect the plane with normal " << cutPlane.normal() diff --git a/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.H b/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.H deleted file mode 100644 index 35906de56..000000000 --- a/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.H +++ /dev/null @@ -1,67 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2018 OpenFOAM Foundation - \\/ 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 . - -Application - surfaceFeatureExtract - -Description - Utility functions for surfaceFeatureExtract - -\*---------------------------------------------------------------------------*/ - -#include "surfaceFeatures.H" -#include "extendedFeatureEdgeMesh.H" -#include "plane.H" - -namespace Foam -{ - //- Deletes all edges inside/outside bounding box from set. - void deleteBox - ( - const triSurface& surf, - const boundBox& bb, - const bool removeInside, - List& edgeStat - ); - - //- Deletes all edges inside/outside bounding box from set. - void deleteEdges - ( - const triSurface& surf, - const plane& cutPlane, - List& edgeStat - ); - - void deleteNonManifoldEdges - ( - const triSurface& surf, - const scalar tol, - const scalar includedAngle, - List& edgeStat - ); - - void writeStats(const extendedFeatureEdgeMesh& fem, Ostream& os); -} - - -// ************************************************************************* // diff --git a/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtractUtilities.C b/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtractUtilities.C deleted file mode 100644 index 256eaf768..000000000 --- a/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtractUtilities.C +++ /dev/null @@ -1,151 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation - \\/ 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 . - -Application - surfaceFeatureExtract - -Description - Extracts and writes surface features to file. All but the basic feature - extraction is WIP. - -\*---------------------------------------------------------------------------*/ - -#include "surfaceFeatureExtract.H" -#include "triSurface.H" -#include "Time.H" -#include "tensor2D.H" -#include "symmTensor2D.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -void Foam::deleteBox -( - const triSurface& surf, - const boundBox& bb, - const bool removeInside, - List& edgeStat -) -{ - forAll(edgeStat, edgei) - { - const point eMid = surf.edges()[edgei].centre(surf.localPoints()); - - if (removeInside ? bb.contains(eMid) : !bb.contains(eMid)) - { - edgeStat[edgei] = surfaceFeatures::NONE; - } - } -} - - -void Foam::deleteEdges -( - const triSurface& surf, - const plane& cutPlane, - List& edgeStat -) -{ - const pointField& points = surf.points(); - const labelList& meshPoints = surf.meshPoints(); - - forAll(edgeStat, edgei) - { - const edge& e = surf.edges()[edgei]; - const point& p0 = points[meshPoints[e.start()]]; - const point& p1 = points[meshPoints[e.end()]]; - const linePointRef line(p0, p1); - - // If edge does not intersect the plane, delete. - scalar intersect = cutPlane.lineIntersect(line); - - point featPoint = intersect * (p1 - p0) + p0; - - if (!line.insideBoundBox(featPoint)) - { - edgeStat[edgei] = surfaceFeatures::NONE; - } - } -} - - - - -void Foam::deleteNonManifoldEdges -( - const triSurface& surf, - const scalar tol, - const scalar includedAngle, - List& edgeStat -) -{ - forAll(edgeStat, edgei) - { - const labelList& eFaces = surf.edgeFaces()[edgei]; - - if - ( - eFaces.size() > 2 - && edgeStat[edgei] == surfaceFeatures::REGION - && (eFaces.size() % 2) == 0 - ) - { - edgeStat[edgei] = checkNonManifoldEdge - ( - surf, - tol, - includedAngle, - edgei - ); - } - } -} - - -void Foam::writeStats(const extendedFeatureEdgeMesh& fem, Ostream& os) -{ - os << " points : " << fem.points().size() << nl - << " of which" << nl - << " convex : " - << fem.concaveStart() << nl - << " concave : " - << (fem.mixedStart() - fem.concaveStart()) << nl - << " mixed : " - << (fem.nonFeatureStart() - fem.mixedStart()) << nl - << " non-feature : " - << (fem.points().size() - fem.nonFeatureStart()) << nl - << " edges : " << fem.edges().size() << nl - << " of which" << nl - << " external edges : " - << fem.internalStart() << nl - << " internal edges : " - << (fem.flatStart() - fem.internalStart()) << nl - << " flat edges : " - << (fem.openStart() - fem.flatStart()) << nl - << " open edges : " - << (fem.multipleStart() - fem.openStart()) << nl - << " multiply connected : " - << (fem.edges().size() - fem.multipleStart()) << endl; -} - - -// ************************************************************************* // diff --git a/src/meshTools/searchableSurfaces/closedTriSurfaceMesh/closedTriSurfaceMesh.C b/src/meshTools/searchableSurfaces/closedTriSurfaceMesh/closedTriSurfaceMesh.C index b5ea3d9ec..4f7032c30 100644 --- a/src/meshTools/searchableSurfaces/closedTriSurfaceMesh/closedTriSurfaceMesh.C +++ b/src/meshTools/searchableSurfaces/closedTriSurfaceMesh/closedTriSurfaceMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -30,10 +30,8 @@ License namespace Foam { - -defineTypeNameAndDebug(closedTriSurfaceMesh, 0); -addToRunTimeSelectionTable(searchableSurface, closedTriSurfaceMesh, dict); - + defineTypeNameAndDebug(closedTriSurfaceMesh, 0); + addToRunTimeSelectionTable(searchableSurface, closedTriSurfaceMesh, dict); } diff --git a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H index 2831a8cff..bbf573128 100644 --- a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H +++ b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H @@ -316,12 +316,16 @@ public: // indices) get the specified field. Misses do not get set. virtual void getField(const List&, labelList&) const; + //- Return a pair of triSurfaceScalarFields representing the + // internal and external closeness of regions of the surface Pair> extractCloseness ( const scalar internalAngleTolerance = 80, const scalar externalAngleTolerance = 10 ) const; + //- Return a pair of triSurfaceScalarPointFields representing the + // internal and external closeness of regions of the surface Pair> extractPointCloseness ( const scalar internalAngleTolerance = 80, diff --git a/src/meshTools/triSurface/surfaceFeatures/surfaceFeatures.C b/src/meshTools/triSurface/surfaceFeatures/surfaceFeatures.C index ed4d8edf9..5d394d182 100644 --- a/src/meshTools/triSurface/surfaceFeatures/surfaceFeatures.C +++ b/src/meshTools/triSurface/surfaceFeatures/surfaceFeatures.C @@ -1501,6 +1501,56 @@ void Foam::surfaceFeatures::operator=(const surfaceFeatures& rhs) // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // +void Foam::selectBox +( + const triSurface& surf, + const boundBox& bb, + const bool inside, + List& edgeStat +) +{ + forAll(edgeStat, edgei) + { + const point eMid = surf.edges()[edgei].centre(surf.localPoints()); + + if (!inside ? bb.contains(eMid) : !bb.contains(eMid)) + { + edgeStat[edgei] = surfaceFeatures::NONE; + } + } +} + + +void Foam::selectCutEdges +( + const triSurface& surf, + const plane& cutPlane, + List& edgeStat +) +{ + const pointField& points = surf.points(); + const labelList& meshPoints = surf.meshPoints(); + + forAll(edgeStat, edgei) + { + const edge& e = surf.edges()[edgei]; + const point& p0 = points[meshPoints[e.start()]]; + const point& p1 = points[meshPoints[e.end()]]; + const linePointRef line(p0, p1); + + // If edge does not intersect the plane, delete. + const scalar intersect = cutPlane.lineIntersect(line); + + const point featPoint = intersect*(p1 - p0) + p0; + + if (!line.insideBoundBox(featPoint)) + { + edgeStat[edgei] = surfaceFeatures::NONE; + } + } +} + + Foam::surfaceFeatures::edgeStatus Foam::checkNonManifoldEdge ( const triSurface& surf, @@ -1662,4 +1712,35 @@ Foam::surfaceFeatures::edgeStatus Foam::checkNonManifoldEdge } +void Foam::selectManifoldEdges +( + const triSurface& surf, + const scalar tol, + const scalar includedAngle, + List& edgeStat +) +{ + forAll(edgeStat, edgei) + { + const labelList& eFaces = surf.edgeFaces()[edgei]; + + if + ( + eFaces.size() > 2 + && edgeStat[edgei] == surfaceFeatures::REGION + && (eFaces.size() % 2) == 0 + ) + { + edgeStat[edgei] = checkNonManifoldEdge + ( + surf, + tol, + includedAngle, + edgei + ); + } + } +} + + // ************************************************************************* // diff --git a/src/meshTools/triSurface/surfaceFeatures/surfaceFeatures.H b/src/meshTools/triSurface/surfaceFeatures/surfaceFeatures.H index 1cb73687b..85901413e 100644 --- a/src/meshTools/triSurface/surfaceFeatures/surfaceFeatures.H +++ b/src/meshTools/triSurface/surfaceFeatures/surfaceFeatures.H @@ -51,6 +51,8 @@ SourceFiles #include "pointIndexHit.H" #include "edgeList.H" #include "typeInfo.H" +#include "boundBox.H" +#include "plane.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -419,6 +421,23 @@ public: }; +//- Select edges inside or outside bounding box +void selectBox +( + const triSurface& surf, + const boundBox& bb, + const bool removeInside, + List& edgeStat +); + +//- Select edges that are intersected by the given plane +void selectCutEdges +( + const triSurface& surf, + const plane& cutPlane, + List& edgeStat +); + //- Divide into multiple normal bins // - return REGION if != 2 normals // - return REGION if 2 normals that make feature angle @@ -431,6 +450,15 @@ surfaceFeatures::edgeStatus checkNonManifoldEdge const label edgei ); +//- Select manifold edges +void selectManifoldEdges +( + const triSurface& surf, + const scalar tol, + const scalar includedAngle, + List& edgeStat +); + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //