Skip to content
Snippets Groups Projects
Commit 2f529221 authored by mattijs's avatar mattijs
Browse files

ENH: vtkUnstructuredReader: reader for unstructured-ascii-vtk data (edgeMeshes and surfMeshes)

parent 7e389364
Branches
Tags
No related merge requests found
......@@ -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
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
vtk/vtkUnstructuredReader.C
nas/NASCore.C
starcd/STARCDCore.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<Face>::writeHeaderPolygons
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::fileFormats::VTKsurfaceFormat<Face>::VTKsurfaceFormat()
{}
Foam::fileFormats::VTKsurfaceFormat<Face>::VTKsurfaceFormat
(
const fileName& filename
)
{
read(filename);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Face>
bool Foam::fileFormats::VTKsurfaceFormat<Face>::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<scalarIOField>("region"))
{
const scalarIOField& region =
reader.cellData().lookupObject<scalarIOField>
(
"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<Face> dynFaces(nTri);
DynamicList<label> dynZones(nTri);
forAll(faces, faceI)
{
const face& f = faces[faceI];
for (label fp1 = 1; fp1 < f.size() - 1; fp1++)
{
label fp2 = f.fcIndex(fp1);
dynFaces.append(triFace(f[0], f[fp1], f[fp2]));
dynZones.append(zones[faceI]);
}
}
// Count
labelList zoneSizes(nZones, 0);
forAll(dynZones, triI)
{
zoneSizes[dynZones[triI]]++;
}
this->sortFacesAndStore(dynFaces.xfer(), dynZones.xfer(), sorted);
// add zones, culling empty ones
this->addZones(zoneSizes, zoneNames, true);
}
else
{
DynamicList<Face> dynFaces(faces.size());
forAll(faces, faceI)
{
const face& f = faces[faceI];
dynFaces.append(Face(f));
}
// Count
labelList zoneSizes(nZones, 0);
forAll(zones, faceI)
{
zoneSizes[zones[faceI]]++;
}
this->sortFacesAndStore(dynFaces.xfer(), zones.xfer(), sorted);
// add zones, culling empty ones
this->addZones(zoneSizes, zoneNames, true);
}
// transfer to normal lists
this->storedPoints().transfer(reader.points());
return true;
}
template<class Face>
void Foam::fileFormats::VTKsurfaceFormat<Face>::write
(
......
......@@ -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
......@@ -25,7 +25,7 @@ Class
Foam::fileFormats::VTKsurfaceFormat
Description
Provide a means of writing VTK legacy format.
Provide a means of reading/writing VTK legacy format.
The output is never sorted by zone.
SourceFiles
......@@ -74,10 +74,21 @@ public:
// Constructors
//- Construct null
VTKsurfaceFormat();
//- Construct from file name
VTKsurfaceFormat(const fileName&);
// Selectors
//- Read file and return surface
static autoPtr<MeshedSurface<Face> > New(const fileName& name)
{
return autoPtr<MeshedSurface<Face> >
(
new VTKsurfaceFormat<Face>(name)
);
}
//- Destructor
virtual ~VTKsurfaceFormat()
{}
......@@ -87,24 +98,20 @@ public:
// Write
//- Write surface mesh components by proxy
static void write
(
const fileName&, const MeshedSurfaceProxy<Face>&
);
//- Write surface mesh components by proxy
static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
//- Write UnsortedMeshedSurface, the output remains unsorted
static void write
(
const fileName&, const UnsortedMeshedSurface<Face>&
);
//- Write UnsortedMeshedSurface, the output remains unsorted
static void write(const fileName&, const UnsortedMeshedSurface<Face>&);
//- Read from file
virtual bool read(const fileName&);
//- Write object
virtual void write(Ostream& os) const
{
write(os, MeshedSurfaceProxy<Face>(*this));
}
//- Write object file
virtual void write(const fileName& name) const
{
write(name, MeshedSurfaceProxy<Face>(*this));
}
};
......
......@@ -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
......@@ -68,7 +68,7 @@ void Foam::fileFormats::VTKsurfaceFormatCore::writeTail
os << nl
<< "CELL_DATA " << nFaces << nl
<< "FIELD attributes 1" << nl
<< "zone 1 " << nFaces << " float" << nl;
<< "region 1 " << nFaces << " float" << nl;
forAll(zoneLst, zoneI)
......@@ -103,7 +103,7 @@ void Foam::fileFormats::VTKsurfaceFormatCore::writeTail
os << nl
<< "CELL_DATA " << zoneIds.size() << nl
<< "FIELD attributes 1" << nl
<< "zone 1 " << zoneIds.size() << " float" << nl;
<< "region 1 " << zoneIds.size() << " float" << nl;
forAll(zoneIds, faceI)
{
......
......@@ -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
......@@ -35,6 +35,24 @@ namespace Foam
namespace fileFormats
{
// read MeshedSurface
addNamedTemplatedToRunTimeSelectionTable
(
MeshedSurface,
VTKsurfaceFormat,
face,
fileExtension,
vtk
);
addNamedTemplatedToRunTimeSelectionTable
(
MeshedSurface,
VTKsurfaceFormat,
triFace,
fileExtension,
vtk
);
// write MeshedSurfaceProxy
addNamedTemplatedToMemberFunctionSelectionTable
(
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment