diff --git a/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C b/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C index 93d385104f..c9b5678dfb 100644 --- a/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C +++ b/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C @@ -71,6 +71,7 @@ int main(int argc, char *argv[]) argList::validOptions.insert("scale", "scale"); argList::validOptions.insert("triSurface", ""); argList::validOptions.insert("unsorted", ""); + argList::validOptions.insert("triFace", ""); # include "setRootCase.H" const stringList& params = args.additionalArgs(); @@ -125,7 +126,7 @@ int main(int argc, char *argv[]) } else if (args.options().found("unsorted")) { - unsortedMeshedSurface surf(importName); + UnsortedMeshedSurface surf(importName); if (args.options().found("clean")) { @@ -146,9 +147,33 @@ int main(int argc, char *argv[]) surf.write(exportName); } +#if 1 + else if (args.options().found("triFace")) + { + MeshedSurface surf(importName); + + if (args.options().found("clean")) + { + surf.cleanup(true); + surf.checkOrientation(true); + } + + Info<< "writing " << exportName; + if (scaleFactor <= 0) + { + Info<< " without scaling" << endl; + } + else + { + Info<< " with scaling " << scaleFactor << endl; + surf.scalePoints(scaleFactor); + } + surf.write(exportName); + } +#endif else { - meshedSurface surf(importName); + MeshedSurface surf(importName); if (args.options().found("clean")) { diff --git a/src/surfMesh/MeshedSurface/MeshedSurface.C b/src/surfMesh/MeshedSurface/MeshedSurface.C index 724a51e640..2e528a710e 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurface.C +++ b/src/surfMesh/MeshedSurface/MeshedSurface.C @@ -44,6 +44,13 @@ License // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // +template +inline bool Foam::MeshedSurface::isTri() +{ + return false; +} + + template bool Foam::MeshedSurface::canRead(const word& ext, const bool verbose) { @@ -165,8 +172,8 @@ Foam::MeshedSurface::MeshedSurface ParentType(List(), pointField()), patches_(patchLst) { - points().transfer(pointLst()); - faces().transfer(faceLst()); + storedPoints().transfer(pointLst()); + storedFaces().transfer(faceLst()); } @@ -182,8 +189,8 @@ Foam::MeshedSurface::MeshedSurface : ParentType(List(), pointField()) { - points().transfer(pointLst()); - faces().transfer(faceLst()); + storedPoints().transfer(pointLst()); + storedFaces().transfer(faceLst()); surfGroupList newPatches(patchSizes.size()); @@ -216,8 +223,8 @@ Foam::MeshedSurface::MeshedSurface : ParentType(List(), pointField()) { - points().transfer(pointLst()); - faces().transfer(faceLst()); + storedPoints().transfer(pointLst()); + storedFaces().transfer(faceLst()); if ( @@ -257,8 +264,8 @@ Foam::MeshedSurface::MeshedSurface : ParentType(List(), pointField()) { - points().transfer(pointLst()); - faces().transfer(faceLst()); + storedPoints().transfer(pointLst()); + storedFaces().transfer(faceLst()); if (regionIds.size() != nFaces()) { @@ -316,14 +323,14 @@ Foam::MeshedSurface::MeshedSurface if (useGlobalPoints) { // copy in the global points and the global face addressing - points() = mesh.points(); - faces() = allBoundary; + storedPoints() = mesh.points(); + storedFaces() = allBoundary; } else { // copy in the local points and the local face addressing - points() = allBoundary.localPoints(); - faces() = allBoundary.localFaces(); + storedPoints() = allBoundary.localPoints(); + storedFaces() = allBoundary.localFaces(); } // create patch list @@ -405,7 +412,7 @@ Foam::MeshedSurface::MeshedSurface newFaces[faceI] = origFaces[faceMap[faceI]]; } - faces().transfer(newFaces); + storedFaces().transfer(newFaces); } @@ -595,7 +602,7 @@ void Foam::MeshedSurface::sortFacesByRegion } faceMap.clear(); - faces().transfer(newFaces); + storedFaces().transfer(newFaces); } } @@ -610,8 +617,8 @@ void Foam::MeshedSurface::clear() { ParentType::clearOut(); - points().clear(); - faces().clear(); + storedPoints().clear(); + storedFaces().clear(); patches_.clear(); } @@ -626,7 +633,7 @@ void Foam::MeshedSurface::movePoints(const pointField& newPoints) ParentType::movePoints(newPoints); // Copy new points - points() = newPoints; + storedPoints() = newPoints; } @@ -642,7 +649,7 @@ void Foam::MeshedSurface::scalePoints(const scalar& scaleFactor) // Adapt for new point position ParentType::movePoints(pointField()); - points() *= scaleFactor; + storedPoints() *= scaleFactor; } } @@ -741,8 +748,8 @@ void Foam::MeshedSurface::transfer { clear(); - points().transfer(surf.points()); - faces().transfer(surf.faces()); + storedPoints().transfer(surf.storedPoints()); + storedFaces().transfer(surf.storedFaces()); patches_.transfer(surf.patches_); surf.clear(); @@ -756,7 +763,7 @@ void Foam::MeshedSurface::transfer ) { clear(); - points().transfer(surf.points()); + storedPoints().transfer(surf.storedPoints()); labelList faceMap; surfGroupList patchLst = surf.sortedRegions(faceMap); @@ -765,7 +772,7 @@ void Foam::MeshedSurface::transfer surf.regions_.clear(); surf.patches_.clear(); - List& oldFaces = surf.faces(); + const List& oldFaces = surf.faces(); List newFaces(oldFaces.size()); // this is somewhat like ListOps reorder and/or IndirectList @@ -774,7 +781,7 @@ void Foam::MeshedSurface::transfer newFaces[faceI] = oldFaces[faceMap[faceI]]; } - faces().transfer(newFaces); + storedFaces().transfer(newFaces); surf.clear(); } @@ -852,8 +859,8 @@ void Foam::MeshedSurface::operator=(const MeshedSurface& surf) { clear(); - faces() = surf.faces(); - points() = surf.points(); + storedPoints() = surf.points(); + storedFaces() = surf.faces(); patches_ = surf.patches_; } diff --git a/src/surfMesh/MeshedSurface/MeshedSurface.H b/src/surfMesh/MeshedSurface/MeshedSurface.H index 0498bce023..68d4524049 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurface.H +++ b/src/surfMesh/MeshedSurface/MeshedSurface.H @@ -87,7 +87,6 @@ class MeshedSurface private: //- Private typedefs for convenience - typedef MeshedSurface ThisType; typedef PrimitivePatchExtra < Face, @@ -117,6 +116,22 @@ private: //- Read OpenFOAM Surface format bool read(Istream&); +protected: + + // Protected member functions + + //- Return non-const access to global points + pointField& storedPoints() + { + return const_cast(ParentType::points()); + } + + //- Return non-const access to the faces + List& storedFaces() + { + return static_cast &>(*this); + } + public: //- Runtime type information @@ -124,6 +139,9 @@ public: // Static + //- Only handles triangulated faces + inline static bool isTri(); + //- Can we read this file format? static bool canRead(const word& ext, const bool verbose=false); @@ -270,7 +288,7 @@ public: //- Return the number of points label nPoints() const { - return points().size(); + return ParentType::points().size(); } //- Return the number of faces @@ -291,30 +309,13 @@ public: return ParentType::points(); } - //- Return non-const access to global points - pointField& points() - { - return const_cast(ParentType::points()); - } - //- Return const access to the faces const List& faces() const { return static_cast &>(*this); } - //- Return non-const access to the faces - List& faces() - { - return static_cast &>(*this); - } - - const surfGroupList& patches() const - { - return patches_; - } - - surfGroupList& patches() + const List& patches() const { return patches_; } @@ -403,6 +404,22 @@ public: }; +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Specialization for holding triangulated information +template<> +inline bool MeshedSurface::isTri() +{ + return true; +} + +//- Specialization for holding triangulated information +template<> +inline label MeshedSurface::triangulate() +{ + return 0; +} + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/surfMesh/MeshedSurface/MeshedSurfaceCleanup.C b/src/surfMesh/MeshedSurface/MeshedSurfaceCleanup.C index c6642f17e9..7a287ec763 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurfaceCleanup.C +++ b/src/surfMesh/MeshedSurface/MeshedSurfaceCleanup.C @@ -48,7 +48,7 @@ bool Foam::MeshedSurface::stitchFaces const bool verbose ) { - pointField& pointLst = points(); + pointField& pointLst = storedPoints(); // Merge points labelList pointMap(pointLst.size()); @@ -70,7 +70,7 @@ bool Foam::MeshedSurface::stitchFaces // Set the coordinates to the merged ones pointLst.transfer(newPoints); - List& faceLst = faces(); + List& faceLst = storedFaces(); // ensure we have at some patches, and they cover all the faces checkPatches(); @@ -78,7 +78,7 @@ bool Foam::MeshedSurface::stitchFaces // Reset the point labels to the unique points array label oldFaceI = 0; label newFaceI = 0; - forAll (patches_, patchI) + forAll(patches_, patchI) { surfGroup& p = patches_[patchI]; @@ -89,7 +89,7 @@ bool Foam::MeshedSurface::stitchFaces for (; oldFaceI < patchEnd; ++oldFaceI) { Face& f = faceLst[oldFaceI]; - forAll (f, fp) + forAll(f, fp) { f[fp] = pointMap[f[fp]]; } @@ -141,14 +141,14 @@ void Foam::MeshedSurface::checkFaces(const bool verbose) // Simple check on indices ok. const label maxPointI = points().size() - 1; - List& faceLst = faces(); + List& faceLst = storedFaces(); // Phase 0: detect badly labelled faces - forAll (faceLst, faceI) + forAll(faceLst, faceI) { const Face& f = faceLst[faceI]; - forAll (f, fp) + forAll(f, fp) { if (f[fp] < 0 || f[fp] > maxPointI) { @@ -170,7 +170,7 @@ void Foam::MeshedSurface::checkFaces(const bool verbose) label oldFaceI = 0; label newFaceI = 0; - forAll (patches_, patchI) + forAll(patches_, patchI) { surfGroup& p = patches_[patchI]; @@ -191,7 +191,7 @@ void Foam::MeshedSurface::checkFaces(const bool verbose) // Check if faceNeighbours use same points as this face. // Note: discards normal information - sides of baffle are merged. - forAll (neighbours, neighI) + forAll(neighbours, neighI) { if (neighbours[neighI] <= oldFaceI) { @@ -199,7 +199,7 @@ void Foam::MeshedSurface::checkFaces(const bool verbose) continue; } - const face& nei = faceLst[neighbours[neighI]]; + const Face& nei = faceLst[neighbours[neighI]]; if (f == nei) { @@ -271,10 +271,10 @@ template Foam::label Foam::MeshedSurface::triangulate() { label nTri = 0; - List& faceLst = faces(); + List& faceLst = storedFaces(); // determine how many triangles are needed - forAll (faceLst, faceI) + forAll(faceLst, faceI) { nTri += faceLst[faceI].size() - 2; } @@ -293,7 +293,7 @@ Foam::label Foam::MeshedSurface::triangulate() // Reset the point labels to the unique points array label oldFaceI = 0; label newFaceI = 0; - forAll (patches_, patchI) + forAll(patches_, patchI) { surfGroup& p = patches_[patchI]; diff --git a/src/surfMesh/MeshedSurface/MeshedSurfaceIO.C b/src/surfMesh/MeshedSurface/MeshedSurfaceIO.C index cc0d8efd41..0997d8d14f 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurfaceIO.C +++ b/src/surfMesh/MeshedSurface/MeshedSurfaceIO.C @@ -61,17 +61,17 @@ bool Foam::MeshedSurface::read(Istream& is) } // read points: - is >> points(); + is >> storedPoints(); // read faces: // TODO - specialization to triangulate on-the-fly if (mustTriangulate) { - is >> faces(); + is >> storedFaces(); } else { - is >> faces(); + is >> storedFaces(); } return is.good(); diff --git a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C index b530cd9d9d..c314847882 100644 --- a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C +++ b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C @@ -39,6 +39,13 @@ License // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // +template +inline bool Foam::UnsortedMeshedSurface::isTri() +{ + return false; +} + + template bool Foam::UnsortedMeshedSurface::canRead ( @@ -205,8 +212,8 @@ Foam::UnsortedMeshedSurface::UnsortedMeshedSurface regions_(regionIds), patches_(patchLst) { - points().transfer(pointLst()); - faces().transfer(faceLst()); + storedPoints().transfer(pointLst()); + storedFaces().transfer(faceLst()); } @@ -222,8 +229,8 @@ Foam::UnsortedMeshedSurface::UnsortedMeshedSurface ParentType(List(), pointField()), regions_(regionIds) { - faces().transfer(faceLst()); - points().transfer(pointLst()); + storedPoints().transfer(pointLst()); + storedFaces().transfer(faceLst()); if (®ionNames) { @@ -250,8 +257,8 @@ Foam::UnsortedMeshedSurface::UnsortedMeshedSurface ParentType(List(), pointField()), regions_(regionIds) { - points().transfer(pointLst()); - faces().transfer(faceLst()); + storedPoints().transfer(pointLst()); + storedFaces().transfer(faceLst()); // set patch names from (name => id) mapping setPatches(labelToRegion); @@ -269,8 +276,8 @@ Foam::UnsortedMeshedSurface::UnsortedMeshedSurface regions_(faceLst().size(), 0), // single default patch patches_() { - points().transfer(pointLst()); - faces().transfer(faceLst()); + storedPoints().transfer(pointLst()); + storedFaces().transfer(faceLst()); setPatches(0); } @@ -310,12 +317,12 @@ Foam::UnsortedMeshedSurface::UnsortedMeshedSurface if (useGlobalPoints) { // copy in the global points - points() = mesh.points(); + storedPoints() = mesh.points(); } else { // copy in the local points - points() = allBoundary.localPoints(); + storedPoints() = allBoundary.localPoints(); } // global or local face addressing @@ -345,7 +352,7 @@ Foam::UnsortedMeshedSurface::UnsortedMeshedSurface } } - faces().transfer(newFaces); + storedFaces().transfer(newFaces); regions_.transfer(newRegions); patches_.transfer(newPatches); } @@ -380,7 +387,7 @@ Foam::UnsortedMeshedSurface::UnsortedMeshedSurface } } - faces().transfer(newFaces); + storedFaces().transfer(newFaces); regions_.transfer(newRegions); patches_.transfer(newPatches); } @@ -606,8 +613,8 @@ void Foam::UnsortedMeshedSurface::clear() { ParentType::clearOut(); - points().clear(); - faces().clear(); + storedPoints().clear(); + storedFaces().clear(); regions_.clear(); patches_.clear(); } @@ -640,7 +647,7 @@ void Foam::UnsortedMeshedSurface::movePoints(const pointField& newPoints) ParentType::movePoints(newPoints); // Copy new points - points() = newPoints; + storedPoints() = newPoints; } @@ -656,7 +663,7 @@ void Foam::UnsortedMeshedSurface::scalePoints(const scalar& scaleFactor) // Adapt for new point position ParentType::movePoints(pointField()); - points() *= scaleFactor; + storedPoints() *= scaleFactor; } } @@ -722,8 +729,8 @@ void Foam::UnsortedMeshedSurface::transfer { clear(); - faces().transfer(surf.faces()); - points().transfer(surf.points()); + storedPoints().transfer(surf.storedPoints()); + storedFaces().transfer(surf.storedFaces()); regions_.transfer(surf.regions_); patches_.transfer(surf.patches_); @@ -742,8 +749,8 @@ void Foam::UnsortedMeshedSurface::transfer clear(); - points().transfer(surf.points()); - faces().transfer(surf.faces()); + storedPoints().transfer(surf.storedPoints()); + storedFaces().transfer(surf.storedFaces()); regions_.setSize(size()); patches_.setSize(patchLst.size()); @@ -839,8 +846,8 @@ void Foam::UnsortedMeshedSurface::operator= ) { clear(); - faces() = surf.faces(); - points() = surf.points(); + storedPoints() = surf.points(); + storedFaces() = surf.faces(); regions_ = surf.regions_; patches_ = surf.patches_; } diff --git a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H index ad3968acb9..2101ae155c 100644 --- a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H +++ b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H @@ -89,17 +89,9 @@ class UnsortedMeshedSurface { friend class MeshedSurface; -protected: - - // Protected Member Data - - //- Typedef for type holding the region (patch) informationm - typedef surfPatchIdentifier PatchRegionType; - private: //- Private typedefs for convenience - typedef UnsortedMeshedSurface ThisType; typedef PrimitivePatchExtra < Face, @@ -109,6 +101,9 @@ private: > ParentType; + //- Typedef for type holding the region (patch) informationm + typedef surfPatchIdentifier PatchRegionType; + // Private Member Data //- The regions associated with the faces @@ -146,6 +141,25 @@ protected: //- Sets patch names from hashed values (name -> id) void setPatches(const HashTable