diff --git a/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C b/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C index 1d0dfae584..52c5d9c089 100644 --- a/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C +++ b/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C @@ -83,7 +83,7 @@ Description #include "edgeIntersections.H" #include "meshTools.H" #include "DynamicField.H" - +#include "Enum.H" #ifndef NO_CGAL @@ -1514,8 +1514,8 @@ int main(int argc, char *argv[]) { argList::noParallel(); argList::validArgs.append("action"); - argList::validArgs.append("surface file"); - argList::validArgs.append("surface file"); + argList::validArgs.append("surfaceFile1"); + argList::validArgs.append("surfaceFile2"); argList::addBoolOption ( @@ -1553,24 +1553,30 @@ int main(int argc, char *argv[]) " 'mixed' (keep all)" ); + argList::addNote + ( + "Valid actions: \"intersection\", \"union\", \"difference\"" + ); + #include "setRootCase.H" #include "createTime.H" const word action(args[1]); - const HashTable validActions + const Enum validActions { - {"intersection", booleanSurface::INTERSECTION}, - {"union", booleanSurface::UNION}, - {"difference", booleanSurface::DIFFERENCE} + { booleanSurface::INTERSECTION, "intersection" }, + { booleanSurface::UNION, "union" }, + { booleanSurface::DIFFERENCE, "difference" } }; - if (!validActions.found(action)) + if (!validActions.hasEnum(action)) { FatalErrorInFunction << "Unsupported action " << action << endl - << "Supported actions:" << validActions.toc() << abort(FatalError); + << "Supported actions:" << validActions << nl + << abort(FatalError); } diff --git a/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C b/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C index 29187c7cfe..7cd22735a7 100644 --- a/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C +++ b/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C @@ -149,8 +149,21 @@ int main(int argc, char *argv[]) } Info<< "Output : " << outputName << nl; + triSurfaceLoader::loadingOption loadingOption = + triSurfaceLoader::loadingOptionNames.lookupOrDefault + ( + "loadingOption", + surfaceDict, + triSurfaceLoader::loadingOption::OFFSET_REGION + ); + + Info<<"loading with " + << triSurfaceLoader::loadingOptionNames[loadingOption] + << endl; + + // Load a single file, or load and combine multiple selected files - autoPtr surfPtr = loader.load(); + autoPtr surfPtr = loader.load(loadingOption); if (!surfPtr.valid() || surfPtr().empty()) { FatalErrorInFunction @@ -390,14 +403,21 @@ int main(int argc, char *argv[]) feMesh.add(addFeMesh); } - if (surfaceDict.lookupOrDefault("selfIntersection", false)) - { - // TODO: perturbance tolerance? + const surfaceIntersection::intersectionType selfIntersect = + surfaceIntersection::selfIntersectionNames.lookupOrDefault + ( + "intersectionMethod", + surfaceDict, + surfaceIntersection::NONE + ); + if (selfIntersect != surfaceIntersection::NONE) + { triSurfaceSearch query(surf); surfaceIntersection intersect(query, surfaceDict); - intersect.mergePoints(5*SMALL); + // Remove rounding noise - could make adjustable + intersect.mergePoints(10*SMALL); labelPair sizeInfo ( @@ -413,14 +433,15 @@ int main(int argc, char *argv[]) intersect.cutEdges() ); - addMesh.mergePoints(5*SMALL); feMesh.add(addMesh); sizeInfo[0] = addMesh.points().size(); sizeInfo[1] = addMesh.edges().size(); } Info<< nl - << "Self intersection:" << nl + << "intersection: " + << surfaceIntersection::selfIntersectionNames[selfIntersect] + << nl << " points : " << sizeInfo[0] << nl << " edges : " << sizeInfo[1] << nl; } diff --git a/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtractDict b/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtractDict index 6532215298..89f5b9c6b7 100644 --- a/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtractDict +++ b/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtractDict @@ -16,7 +16,7 @@ FoamFile surface1.stl { - // How to obtain raw features (extractFromFile | extractFromSurface | none) + // How to obtain raw features (none | extractFromFile | extractFromSurface) extractionMethod extractFromSurface; // Mark edges whose adjacent surface normals are at an angle less @@ -36,8 +36,8 @@ surface1.stl geometricTestOnly yes; } */ - // Generate additional features from self-intersect - selfIntersection false; + // Generate additional intersection features (none | self | region) + intersectionMethod none; // Tolerance for surface intersections tolerance 1e-3; @@ -51,7 +51,7 @@ surface1.stl surface2.nas { - // How to obtain raw features (extractFromFile | extractFromSurface | none) + // How to obtain raw features (none | extractFromFile | extractFromSurface) extractionMethod extractFromFile; extractFromFileCoeffs @@ -114,8 +114,8 @@ surface2.nas // Out put the closeness of surface elements to other surface elements. closeness no; - // Generate additional features from self-intersect - selfIntersection false; + // Generate additional intersection features (none | self | region) + intersectionMethod none; // Tolerance for surface intersections tolerance 1e-3; @@ -148,8 +148,8 @@ dummyName // Base output name (optional) // output surfaces; - // Generate additional features from self-intersect - selfIntersection true; + // Generate additional intersection features (none | self | region) + intersectionMethod self; // Tolerance for surface intersections tolerance 1e-3; @@ -183,8 +183,8 @@ surfaces // Base output name (optional) // output surfaces; - // Generate additional features from self-intersect - selfIntersection true; + // Generate additional intersection features (none | self | region) + intersectionMethod self; // Tolerance for surface intersections tolerance 1e-3; @@ -193,8 +193,7 @@ surfaces noneCoeffs { includedAngle 0; - } - */ + } */ // Write options diff --git a/src/meshTools/triSurface/booleanOps/surfaceIntersection/surfaceIntersection.C b/src/meshTools/triSurface/booleanOps/surfaceIntersection/surfaceIntersection.C index 5592d95362..8c552335d4 100644 --- a/src/meshTools/triSurface/booleanOps/surfaceIntersection/surfaceIntersection.C +++ b/src/meshTools/triSurface/booleanOps/surfaceIntersection/surfaceIntersection.C @@ -27,6 +27,7 @@ License #include "triSurfaceSearch.H" #include "OBJstream.H" #include "labelPairHashes.H" +#include "PackedBoolList.H" #include "triSurface.H" #include "pointIndexHit.H" #include "mergePoints.H" @@ -40,6 +41,14 @@ namespace Foam defineTypeNameAndDebug(surfaceIntersection, 0); } +const Foam::Enum +Foam::surfaceIntersection::selfIntersectionNames +{ + { intersectionType::SELF, "self" }, + { intersectionType::SELF_REGION, "region" }, + { intersectionType::NONE, "none" }, +}; + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -54,7 +63,7 @@ void Foam::surfaceIntersection::setOptions(const dictionary& dict) void Foam::surfaceIntersection::storeIntersection ( - const enum originatingType cutFrom, + const enum intersectionType cutFrom, const labelList& facesA, const label faceB, const UList& allCutPoints, @@ -85,6 +94,7 @@ void Foam::surfaceIntersection::storeIntersection break; } case surfaceIntersection::SELF: + case surfaceIntersection::SELF_REGION: { // Lookup should be commutativity - use sorted order if (faceA < faceB) @@ -99,6 +109,10 @@ void Foam::surfaceIntersection::storeIntersection } break; } + + case surfaceIntersection::NONE: + return; + break; } @@ -245,7 +259,7 @@ void Foam::surfaceIntersection::classifyHit const triSurface& surf1, const scalarField& surf1PointTol, const triSurface& surf2, - const enum originatingType cutFrom, + const enum intersectionType cutFrom, const label edgeI, const pointIndexHit& pHit, @@ -306,7 +320,11 @@ void Foam::surfaceIntersection::classifyHit // For self-intersection, we have tolerances for each point // (surf2 is actually surf1) so we shift the hit to coincide // identically. - if (cutFrom == surfaceIntersection::SELF) + if + ( + cutFrom == surfaceIntersection::SELF + || cutFrom == surfaceIntersection::SELF_REGION + ) { const point& nearPt = surf1Pts[nearVert]; @@ -392,7 +410,15 @@ void Foam::surfaceIntersection::classifyHit // >0: store point/edge-cut. Attempt to create new edge. // <0: store point/edge-cut only int handling = (allowEdgeHits_ ? 1 : 0); - if (allowEdgeHits_ && cutFrom == surfaceIntersection::SELF) + if + ( + allowEdgeHits_ + && + ( + cutFrom == surfaceIntersection::SELF + || cutFrom == surfaceIntersection::SELF_REGION + ) + ) { // The edge-edge intersection is hashed as an 'edge' to // exploit the commutative lookup. @@ -513,12 +539,18 @@ void Foam::surfaceIntersection::classifyHit switch (cutFrom) { case surfaceIntersection::FIRST: + { handling = 1; break; + } case surfaceIntersection::SECOND: + { handling = -1; break; + } case surfaceIntersection::SELF: + case surfaceIntersection::SELF_REGION: + { // The edge-edge intersection is hashed as an 'edge' to // exploit the commutative lookup. // Ie, only do the cut once @@ -563,6 +595,12 @@ void Foam::surfaceIntersection::classifyHit } } } + + break; + } + + case surfaceIntersection::NONE: + return; break; } @@ -744,7 +782,7 @@ void Foam::surfaceIntersection::doCutEdges ( const triSurface& surf1, const triSurfaceSearch& querySurf2, - const enum originatingType cutFrom, + const enum intersectionType cutFrom, DynamicList& allCutPoints, DynamicList& allCutEdges, @@ -766,13 +804,21 @@ void Foam::surfaceIntersection::doCutEdges const indexedOctree>& searchTree = querySurf2.tree(); - if (cutFrom == surfaceIntersection::SELF) + if + ( + cutFrom == surfaceIntersection::SELF + || cutFrom == surfaceIntersection::SELF_REGION + ) { // An edge may intersect multiple faces // - mask out faces that have already been hit before trying again // - never intersect with faces attached to the edge itself DynamicList