mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: vtkUnstructuredReader: reader for unstructured-ascii-vtk data (edgeMeshes and surfMeshes)
This commit is contained in:
@ -19,8 +19,6 @@ meshReader/starcd/STARCDMeshReader.C
|
|||||||
meshWriter/meshWriter.C
|
meshWriter/meshWriter.C
|
||||||
meshWriter/starcd/STARCDMeshWriter.C
|
meshWriter/starcd/STARCDMeshWriter.C
|
||||||
|
|
||||||
vtk/vtkUnstructuredReader.C
|
|
||||||
|
|
||||||
polyDualMesh/polyDualMesh.C
|
polyDualMesh/polyDualMesh.C
|
||||||
|
|
||||||
LIB = $(FOAM_LIBBIN)/libconversion
|
LIB = $(FOAM_LIBBIN)/libconversion
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
EXE_INC = \
|
EXE_INC = \
|
||||||
-I$(LIB_SRC)/fileFormats/lnInclude \
|
-I$(LIB_SRC)/fileFormats/lnInclude \
|
||||||
-I$(LIB_SRC)/triSurface/lnInclude \
|
-I$(LIB_SRC)/triSurface/lnInclude \
|
||||||
-I$(LIB_SRC)/conversion/lnInclude \
|
|
||||||
-I$(LIB_SRC)/meshTools/lnInclude
|
-I$(LIB_SRC)/meshTools/lnInclude
|
||||||
|
|
||||||
LIB_LIBS = \
|
LIB_LIBS = \
|
||||||
-ltriSurface \
|
-ltriSurface \
|
||||||
-lmeshTools \
|
-lmeshTools \
|
||||||
-lconversion \
|
|
||||||
-lfileFormats
|
-lfileFormats
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
vtk/vtkUnstructuredReader.C
|
||||||
nas/NASCore.C
|
nas/NASCore.C
|
||||||
starcd/STARCDCore.C
|
starcd/STARCDCore.C
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -24,6 +24,8 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "VTKsurfaceFormat.H"
|
#include "VTKsurfaceFormat.H"
|
||||||
|
#include "vtkUnstructuredReader.H"
|
||||||
|
#include "scalarIOField.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -50,12 +52,159 @@ void Foam::fileFormats::VTKsurfaceFormat<Face>::writeHeaderPolygons
|
|||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class Face>
|
template<class Face>
|
||||||
Foam::fileFormats::VTKsurfaceFormat<Face>::VTKsurfaceFormat()
|
Foam::fileFormats::VTKsurfaceFormat<Face>::VTKsurfaceFormat
|
||||||
{}
|
(
|
||||||
|
const fileName& filename
|
||||||
|
)
|
||||||
|
{
|
||||||
|
read(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * 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>
|
template<class Face>
|
||||||
void Foam::fileFormats::VTKsurfaceFormat<Face>::write
|
void Foam::fileFormats::VTKsurfaceFormat<Face>::write
|
||||||
(
|
(
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -25,7 +25,7 @@ Class
|
|||||||
Foam::fileFormats::VTKsurfaceFormat
|
Foam::fileFormats::VTKsurfaceFormat
|
||||||
|
|
||||||
Description
|
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.
|
The output is never sorted by zone.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
@ -74,10 +74,21 @@ public:
|
|||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct null
|
//- Construct from file name
|
||||||
VTKsurfaceFormat();
|
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
|
//- Destructor
|
||||||
virtual ~VTKsurfaceFormat()
|
virtual ~VTKsurfaceFormat()
|
||||||
{}
|
{}
|
||||||
@ -87,24 +98,20 @@ public:
|
|||||||
|
|
||||||
// Write
|
// Write
|
||||||
|
|
||||||
//- Write surface mesh components by proxy
|
//- Write surface mesh components by proxy
|
||||||
static void write
|
static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
|
||||||
(
|
|
||||||
const fileName&, const MeshedSurfaceProxy<Face>&
|
|
||||||
);
|
|
||||||
|
|
||||||
//- Write UnsortedMeshedSurface, the output remains unsorted
|
//- Write UnsortedMeshedSurface, the output remains unsorted
|
||||||
static void write
|
static void write(const fileName&, const UnsortedMeshedSurface<Face>&);
|
||||||
(
|
|
||||||
const fileName&, const UnsortedMeshedSurface<Face>&
|
|
||||||
);
|
|
||||||
|
|
||||||
|
//- Read from file
|
||||||
|
virtual bool read(const fileName&);
|
||||||
|
|
||||||
//- Write object
|
//- Write object file
|
||||||
virtual void write(Ostream& os) const
|
virtual void write(const fileName& name) const
|
||||||
{
|
{
|
||||||
write(os, MeshedSurfaceProxy<Face>(*this));
|
write(name, MeshedSurfaceProxy<Face>(*this));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -68,7 +68,7 @@ void Foam::fileFormats::VTKsurfaceFormatCore::writeTail
|
|||||||
os << nl
|
os << nl
|
||||||
<< "CELL_DATA " << nFaces << nl
|
<< "CELL_DATA " << nFaces << nl
|
||||||
<< "FIELD attributes 1" << nl
|
<< "FIELD attributes 1" << nl
|
||||||
<< "zone 1 " << nFaces << " float" << nl;
|
<< "region 1 " << nFaces << " float" << nl;
|
||||||
|
|
||||||
|
|
||||||
forAll(zoneLst, zoneI)
|
forAll(zoneLst, zoneI)
|
||||||
@ -103,7 +103,7 @@ void Foam::fileFormats::VTKsurfaceFormatCore::writeTail
|
|||||||
os << nl
|
os << nl
|
||||||
<< "CELL_DATA " << zoneIds.size() << nl
|
<< "CELL_DATA " << zoneIds.size() << nl
|
||||||
<< "FIELD attributes 1" << nl
|
<< "FIELD attributes 1" << nl
|
||||||
<< "zone 1 " << zoneIds.size() << " float" << nl;
|
<< "region 1 " << zoneIds.size() << " float" << nl;
|
||||||
|
|
||||||
forAll(zoneIds, faceI)
|
forAll(zoneIds, faceI)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -35,6 +35,24 @@ namespace Foam
|
|||||||
namespace fileFormats
|
namespace fileFormats
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// read MeshedSurface
|
||||||
|
addNamedTemplatedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
MeshedSurface,
|
||||||
|
VTKsurfaceFormat,
|
||||||
|
face,
|
||||||
|
fileExtension,
|
||||||
|
vtk
|
||||||
|
);
|
||||||
|
addNamedTemplatedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
MeshedSurface,
|
||||||
|
VTKsurfaceFormat,
|
||||||
|
triFace,
|
||||||
|
fileExtension,
|
||||||
|
vtk
|
||||||
|
);
|
||||||
|
|
||||||
// write MeshedSurfaceProxy
|
// write MeshedSurfaceProxy
|
||||||
addNamedTemplatedToMemberFunctionSelectionTable
|
addNamedTemplatedToMemberFunctionSelectionTable
|
||||||
(
|
(
|
||||||
|
|||||||
Reference in New Issue
Block a user