diff --git a/src/Allwmake b/src/Allwmake index 27b72295ae..c4cbe16c95 100755 --- a/src/Allwmake +++ b/src/Allwmake @@ -28,10 +28,10 @@ OSspecific/${WM_OSTYPE:-POSIX}/Allwmake wmake $makeType OpenFOAM wmake $makeType fileFormats +wmake $makeType surfMesh wmake $makeType triSurface wmake $makeType meshTools wmake $makeType edgeMesh -wmake $makeType surfMesh # Decomposition methods needed by dummyThirdParty parallel/decompose/AllwmakeLnInclude diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.C b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.C index c69fed1773..cd2f92e61e 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.C +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -63,6 +63,42 @@ PrimitivePatch {} +template +< + class Face, + template class FaceList, + class PointField, + class PointType +> +Foam::PrimitivePatch:: +PrimitivePatch +( + const Xfer >& faces, + const Xfer >& points +) +: + FaceList(faces), + points_(points), + edgesPtr_(NULL), + nInternalEdges_(-1), + boundaryPointsPtr_(NULL), + faceFacesPtr_(NULL), + edgeFacesPtr_(NULL), + faceEdgesPtr_(NULL), + pointEdgesPtr_(NULL), + pointFacesPtr_(NULL), + localFacesPtr_(NULL), + meshPointsPtr_(NULL), + meshPointMapPtr_(NULL), + edgeLoopsPtr_(NULL), + localPointsPtr_(NULL), + localPointOrderPtr_(NULL), + faceCentresPtr_(NULL), + faceNormalsPtr_(NULL), + pointNormalsPtr_(NULL) +{} + + template < class Face, diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.H b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.H index c3d359016a..db8f216c2d 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.H +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -243,6 +243,13 @@ public: const Field& points ); + //- Construct from components + PrimitivePatch + ( + const Xfer >& faces, + const Xfer >& points + ); + //- Construct from components, reuse storage PrimitivePatch ( diff --git a/src/fileFormats/vtk/vtkUnstructuredReader.C b/src/fileFormats/vtk/vtkUnstructuredReader.C index aabedc884b..2fbe435242 100644 --- a/src/fileFormats/vtk/vtkUnstructuredReader.C +++ b/src/fileFormats/vtk/vtkUnstructuredReader.C @@ -125,8 +125,11 @@ void Foam::vtkUnstructuredReader::extractCells cells_.setSize(cellTypes.size()); + cellMap_.setSize(cellTypes.size(), -1); faces_.setSize(cellTypes.size()); + faceMap_.setSize(cellTypes.size(), -1); lines_.setSize(cellTypes.size()); + lineMap_.setSize(cellTypes.size(), -1); label dataIndex = 0; label cellI = 0; @@ -179,6 +182,7 @@ void Foam::vtkUnstructuredReader::extractCells ) << "Expected size 2 for VTK_LINE but found " << nRead << exit(FatalIOError); } + lineMap_[lineI] = i; labelList& segment = lines_[lineI++]; segment.setSize(2); segment[0] = cellVertData[dataIndex++]; @@ -190,6 +194,7 @@ void Foam::vtkUnstructuredReader::extractCells { //warnUnhandledType(inFile, cellTypes[i], warningGiven); label nRead = cellVertData[dataIndex++]; + lineMap_[lineI] = i; labelList& segment = lines_[lineI++]; segment.setSize(nRead); forAll(segment, i) @@ -201,6 +206,7 @@ void Foam::vtkUnstructuredReader::extractCells case VTK_TRIANGLE: { + faceMap_[faceI] = i; face& f = faces_[faceI++]; f.setSize(3); label nRead = cellVertData[dataIndex++]; @@ -221,6 +227,7 @@ void Foam::vtkUnstructuredReader::extractCells case VTK_QUAD: { + faceMap_[faceI] = i; face& f = faces_[faceI++]; f.setSize(4); label nRead = cellVertData[dataIndex++]; @@ -242,6 +249,7 @@ void Foam::vtkUnstructuredReader::extractCells case VTK_POLYGON: { + faceMap_[faceI] = i; face& f = faces_[faceI++]; label nRead = cellVertData[dataIndex++]; f.setSize(nRead); @@ -268,6 +276,7 @@ void Foam::vtkUnstructuredReader::extractCells tetPoints[1] = cellVertData[dataIndex++]; tetPoints[2] = cellVertData[dataIndex++]; tetPoints[3] = cellVertData[dataIndex++]; + cellMap_[cellI] = i; cells_[cellI++] = cellShape(tet, tetPoints, true); } break; @@ -289,6 +298,7 @@ void Foam::vtkUnstructuredReader::extractCells pyrPoints[2] = cellVertData[dataIndex++]; pyrPoints[3] = cellVertData[dataIndex++]; pyrPoints[4] = cellVertData[dataIndex++]; + cellMap_[cellI] = i; cells_[cellI++] = cellShape(pyr, pyrPoints, true); } break; @@ -311,6 +321,7 @@ void Foam::vtkUnstructuredReader::extractCells prismPoints[3] = cellVertData[dataIndex++]; prismPoints[4] = cellVertData[dataIndex++]; prismPoints[5] = cellVertData[dataIndex++]; + cellMap_[cellI] = i; cells_[cellI++] = cellShape(prism, prismPoints, true); } break; @@ -335,6 +346,7 @@ void Foam::vtkUnstructuredReader::extractCells hexPoints[5] = cellVertData[dataIndex++]; hexPoints[6] = cellVertData[dataIndex++]; hexPoints[7] = cellVertData[dataIndex++]; + cellMap_[cellI] = i; cells_[cellI++] = cellShape(hex, hexPoints, true); } break; @@ -351,8 +363,11 @@ void Foam::vtkUnstructuredReader::extractCells Info<< "Read " << cellI << " cells;" << faceI << " faces." << endl; } cells_.setSize(cellI); + cellMap_.setSize(cellI); faces_.setSize(faceI); + faceMap_.setSize(faceI); lines_.setSize(lineI); + lineMap_.setSize(lineI); } @@ -655,9 +670,11 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile) labelList lineVerts; readBlock(inFile, nNumbers, lineVerts); lines_.setSize(nLines); + lineMap_.setSize(nLines); label elemI = 0; forAll(lines_, lineI) { + lineMap_[lineI] = lineI; labelList& f = lines_[lineI]; f.setSize(lineVerts[elemI++]); forAll(f, fp) @@ -682,6 +699,7 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile) label elemI = 0; forAll(faces_, faceI) { + faceMap_[faceI] = faceI; face& f = faces_[faceI]; f.setSize(faceVerts[elemI++]); forAll(f, fp) diff --git a/src/fileFormats/vtk/vtkUnstructuredReader.H b/src/fileFormats/vtk/vtkUnstructuredReader.H index 70df667741..d33fb01d01 100644 --- a/src/fileFormats/vtk/vtkUnstructuredReader.H +++ b/src/fileFormats/vtk/vtkUnstructuredReader.H @@ -25,7 +25,8 @@ Class Foam::vtkUnstructuredReader Description - Reader for vtk unstructured legacy files + Reader for vtk unstructured legacy files. Supports single CELLS, POINTS + etc. entry only. SourceFiles vtkUnstructuredReader.C @@ -45,9 +46,6 @@ SourceFiles namespace Foam { -// Forward declaration of friend functions and operators - - /*---------------------------------------------------------------------------*\ Class vtkUnstructuredReader Declaration \*---------------------------------------------------------------------------*/ @@ -137,12 +135,20 @@ private: //- 3D cells. cellShapeList cells_; + //- Map from cells back to original ID + labelList cellMap_; + //- 2D cells (=faces) faceList faces_; + //- Map from faces back to original ID + labelList faceMap_; + //- 1D cells (=edges) labelListList lines_; + labelList lineMap_; + // Data @@ -258,6 +264,11 @@ public: return cells_; } + const labelList& cellMap() const + { + return cellMap_; + } + //- 2D cells (=faces) const faceList& faces() const { @@ -269,6 +280,11 @@ public: return faces_; } + const labelList& faceMap() const + { + return faceMap_; + } + //- 1D cells (=open lines) const labelListList& lines() const { @@ -280,6 +296,11 @@ public: return lines_; } + const labelList& lineMap() const + { + return lineMap_; + } + //- cell based fields const objectRegistry& cellData() const { diff --git a/src/triSurface/Make/files b/src/triSurface/Make/files index 3f6548208d..d2384b3113 100644 --- a/src/triSurface/Make/files +++ b/src/triSurface/Make/files @@ -25,6 +25,7 @@ $(interfaces)/TRI/readTRI.C $(interfaces)/DX/writeDX.C $(interfaces)/AC3D/readAC.C $(interfaces)/AC3D/writeAC.C +$(interfaces)/VTK/readVTK.C $(interfaces)/VTK/writeVTK.C $(interfaces)/NAS/readNAS.C diff --git a/src/triSurface/Make/options b/src/triSurface/Make/options index 7e207d0dbe..9ee5884e59 100644 --- a/src/triSurface/Make/options +++ b/src/triSurface/Make/options @@ -1,5 +1,7 @@ EXE_INC = \ - -I$(LIB_SRC)/fileFormats/lnInclude + -I$(LIB_SRC)/fileFormats/lnInclude \ + -I$(LIB_SRC)/surfMesh/lnInclude LIB_LIBS = \ - -lfileFormats + -lfileFormats \ + -lsurfMesh diff --git a/src/triSurface/triSurface/interfaces/VTK/readVTK.C b/src/triSurface/triSurface/interfaces/VTK/readVTK.C new file mode 100644 index 0000000000..71b3e791aa --- /dev/null +++ b/src/triSurface/triSurface/interfaces/VTK/readVTK.C @@ -0,0 +1,111 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 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 . + +\*---------------------------------------------------------------------------*/ + +#include "triSurface.H" +#include "VTKsurfaceFormat.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::triSurface::readVTK(const fileName& fName) +{ + // Read (and triagulate) point, faces, zone info + fileFormats::VTKsurfaceFormat surf(fName); + + List tris(surf.faces().size()); + forAll(tris, i) + { + const triFace& f = surf[i]; + tris[i] = labelledTri(f[0], f[1], f[2], 0); + } + + // Add regions from zone + const List& surfZones = surf.surfZones(); + + geometricSurfacePatchList patches; + + if (surfZones.size()) + { + patches.setSize(surfZones.size()); + forAll(surfZones, zoneI) + { + const surfZone& zone = surfZones[zoneI]; + + // Add patch. Convert synthetic 'zone' name into 'patch' for now. + // (vtk format does not contain region names) + word regionName = zone.name(); + if (regionName != (string("zone") + name(zoneI))) + { + regionName = string("patch") + name(zoneI); + } + + patches[zoneI] = geometricSurfacePatch + ( + ( + zone.geometricType() != word::null + ? zone.geometricType() + : "empty" + ), + regionName, + zoneI + ); + + // Set triangle regions + for (label i = zone.start(); i < zone.start()+zone.size(); i++) + { + tris[i].region() = zoneI; + } + } + } + else + { + // Add single patch + patches[0] = geometricSurfacePatch("empty", "patch0", 0); + + // Triangle regions already set to 0 + } + + + // Create triSurface + *this = triSurface + ( + tris.xfer(), + patches, + xferCopy >(surf.points()) + ); + + return true; +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/src/triSurface/triSurface/triSurface.C b/src/triSurface/triSurface/triSurface.C index 075a0b3dd5..6ae73266ee 100644 --- a/src/triSurface/triSurface/triSurface.C +++ b/src/triSurface/triSurface/triSurface.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -412,6 +412,10 @@ bool Foam::triSurface::read { return readNAS(name); } + else if (ext == "vtk") + { + return readVTK(name); + } else { FatalErrorIn @@ -419,7 +423,7 @@ bool Foam::triSurface::read "triSurface::read(const fileName&, const word&)" ) << "unknown file extension " << ext << ". Supported extensions are '.ftr', '.stl', '.stlb', '.gts'" - << ", '.obj', '.ac', '.off', '.nas' and '.tri'" + << ", '.obj', '.ac', '.off', '.nas', '.tri' and '.vtk'" << exit(FatalError); return false; @@ -639,6 +643,20 @@ Foam::triSurface::triSurface {} +Foam::triSurface::triSurface +( + const Xfer >& triangles, + const geometricSurfacePatchList& patches, + const Xfer >& points +) +: + ParentType(triangles, points), + patches_(patches), + sortedEdgeFacesPtr_(NULL), + edgeOwnerPtr_(NULL) +{} + + Foam::triSurface::triSurface ( const List& triangles, diff --git a/src/triSurface/triSurface/triSurface.H b/src/triSurface/triSurface/triSurface.H index 8a8fad9971..62c6cd3d6f 100644 --- a/src/triSurface/triSurface/triSurface.H +++ b/src/triSurface/triSurface/triSurface.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -131,6 +131,7 @@ class triSurface bool readTRI(const fileName&); bool readAC(const fileName&); bool readNAS(const fileName&); + bool readVTK(const fileName&); //- Generic write routine. Chooses writer based on extension. void write(const fileName&, const word& ext, const bool sort) const; @@ -258,6 +259,14 @@ public: const bool reUse ); + //- Construct from triangles, patches, points. + triSurface + ( + const Xfer >&, + const geometricSurfacePatchList&, + const Xfer >& + ); + //- Construct from triangles, points. Set patchnames to default. triSurface(const List&, const pointField&);