From 2f529221fb044a47b1b7446b355bf87d3853854c Mon Sep 17 00:00:00 2001 From: mattijs Date: Fri, 2 Mar 2012 17:40:57 +0000 Subject: [PATCH] ENH: vtkUnstructuredReader: reader for unstructured-ascii-vtk data (edgeMeshes and surfMeshes) --- src/conversion/Make/files | 2 - src/edgeMesh/Make/options | 2 - src/fileFormats/Make/files | 1 + .../vtk/vtkUnstructuredReader.C | 0 .../vtk/vtkUnstructuredReader.H | 0 .../surfaceFormats/vtk/VTKsurfaceFormat.C | 155 +++++++++++++++++- .../surfaceFormats/vtk/VTKsurfaceFormat.H | 45 ++--- .../surfaceFormats/vtk/VTKsurfaceFormatCore.C | 6 +- .../vtk/VTKsurfaceFormatRunTime.C | 20 ++- 9 files changed, 201 insertions(+), 30 deletions(-) rename src/{conversion => fileFormats}/vtk/vtkUnstructuredReader.C (100%) rename src/{conversion => fileFormats}/vtk/vtkUnstructuredReader.H (100%) diff --git a/src/conversion/Make/files b/src/conversion/Make/files index 3616b0e697..7c5a0aa91c 100644 --- a/src/conversion/Make/files +++ b/src/conversion/Make/files @@ -19,8 +19,6 @@ meshReader/starcd/STARCDMeshReader.C meshWriter/meshWriter.C meshWriter/starcd/STARCDMeshWriter.C -vtk/vtkUnstructuredReader.C - polyDualMesh/polyDualMesh.C LIB = $(FOAM_LIBBIN)/libconversion diff --git a/src/edgeMesh/Make/options b/src/edgeMesh/Make/options index 47cb2e9d4f..3c1b5258d3 100644 --- a/src/edgeMesh/Make/options +++ b/src/edgeMesh/Make/options @@ -1,11 +1,9 @@ EXE_INC = \ -I$(LIB_SRC)/fileFormats/lnInclude \ -I$(LIB_SRC)/triSurface/lnInclude \ - -I$(LIB_SRC)/conversion/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude LIB_LIBS = \ -ltriSurface \ -lmeshTools \ - -lconversion \ -lfileFormats diff --git a/src/fileFormats/Make/files b/src/fileFormats/Make/files index a3acab834d..7845ac9312 100644 --- a/src/fileFormats/Make/files +++ b/src/fileFormats/Make/files @@ -1,3 +1,4 @@ +vtk/vtkUnstructuredReader.C nas/NASCore.C starcd/STARCDCore.C diff --git a/src/conversion/vtk/vtkUnstructuredReader.C b/src/fileFormats/vtk/vtkUnstructuredReader.C similarity index 100% rename from src/conversion/vtk/vtkUnstructuredReader.C rename to src/fileFormats/vtk/vtkUnstructuredReader.C diff --git a/src/conversion/vtk/vtkUnstructuredReader.H b/src/fileFormats/vtk/vtkUnstructuredReader.H similarity index 100% rename from src/conversion/vtk/vtkUnstructuredReader.H rename to src/fileFormats/vtk/vtkUnstructuredReader.H diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C index 8f0c9cf380..3dad786857 100644 --- a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.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 @@ -24,6 +24,8 @@ License \*---------------------------------------------------------------------------*/ #include "VTKsurfaceFormat.H" +#include "vtkUnstructuredReader.H" +#include "scalarIOField.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -50,12 +52,159 @@ void Foam::fileFormats::VTKsurfaceFormat::writeHeaderPolygons // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -Foam::fileFormats::VTKsurfaceFormat::VTKsurfaceFormat() -{} +Foam::fileFormats::VTKsurfaceFormat::VTKsurfaceFormat +( + const fileName& filename +) +{ + read(filename); +} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +bool Foam::fileFormats::VTKsurfaceFormat::read +( + const fileName& filename +) +{ + const bool mustTriangulate = this->isTri(); + this->clear(); + + IFstream is(filename); + if (!is.good()) + { + FatalErrorIn + ( + "fileFormats::VTKsurfaceFormat::read(const fileName&)" + ) << "Cannot read file " << filename + << exit(FatalError); + } + + // assume that the groups are not intermixed + bool sorted = true; + + + // Construct dummy time so we have something to create an objectRegistry + // from + Time dummyTime + ( + "dummyRoot", + "dummyCase", + "system", + "constant", + false // enableFunctionObjects + ); + + // Make dummy object registry + objectRegistry obr + ( + IOobject + ( + "dummy", + dummyTime, + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ) + ); + + // Read all + vtkUnstructuredReader reader(obr, is); + const faceList& faces = reader.faces(); + + // Assume all faces in zone0 unless a region field is present + labelList zones(faces.size(), 0); + if (reader.cellData().foundObject("region")) + { + const scalarIOField& region = + reader.cellData().lookupObject + ( + "region" + ); + forAll(region, i) + { + zones[i] = label(region[i]); + } + } + + // Create zone names + const label nZones = max(zones)+1; + wordList zoneNames(nZones); + forAll(zoneNames, i) + { + zoneNames[i] = "zone" + Foam::name(i); + } + + + // See if needs triangulation + label nTri = 0; + if (mustTriangulate) + { + forAll(faces, faceI) + { + nTri += faces[faceI].size()-2; + } + } + + if (nTri > 0) + { + DynamicList dynFaces(nTri); + DynamicList