ENH: write patches as vtkPolyData instead of vtkUnstructuredGrid

- slightly better memory efficiency and file sizes
- consistent with library reader
This commit is contained in:
Mark Olesen
2010-05-07 09:35:40 +02:00
parent 64ac5cbc78
commit 1b4450890a
9 changed files with 64 additions and 89 deletions

View File

@ -989,17 +989,17 @@ int main(int argc, char *argv[])
Info<< " FaceZone : " << patchFileName << endl; Info<< " FaceZone : " << patchFileName << endl;
std::ofstream str(patchFileName.c_str()); std::ofstream ostr(patchFileName.c_str());
writeFuns::writeHeader(str, binary, pp.name()); writeFuns::writeHeader(ostr, binary, pp.name());
str << "DATASET POLYDATA" << std::endl; ostr<< "DATASET POLYDATA" << std::endl;
writePatchGeom writePatchGeom
( (
binary, binary,
pp().localFaces(), pp().localFaces(),
pp().localPoints(), pp().localPoints(),
str ostr
); );
} }
} }

View File

@ -56,7 +56,7 @@ Foam::patchWriter::patchWriter
{ {
writeFuns::writeHeader(os_, binary_, "patches"); writeFuns::writeHeader(os_, binary_, "patches");
} }
os_ << "DATASET UNSTRUCTURED_GRID" << std::endl; os_ << "DATASET POLYDATA" << std::endl;
// Write topology // Write topology
nPoints_ = 0; nPoints_ = 0;
@ -88,10 +88,9 @@ Foam::patchWriter::patchWriter
} }
writeFuns::write(os_, binary_, ptField); writeFuns::write(os_, binary_, ptField);
os_ << "CELLS " << nFaces_ << ' ' << nFaceVerts << std::endl; os_ << "POLYGONS " << nFaces_ << ' ' << nFaceVerts << std::endl;
DynamicList<label> vertLabels(nFaceVerts); DynamicList<label> vertLabels(nFaceVerts);
DynamicList<label> faceTypes(nFaceVerts);
label offset = 0; label offset = 0;
@ -103,30 +102,12 @@ Foam::patchWriter::patchWriter
{ {
const face& f = pp.localFaces()[faceI]; const face& f = pp.localFaces()[faceI];
const label fSize = f.size(); vertLabels.append(f.size());
vertLabels.append(fSize);
writeFuns::insert(f + offset, vertLabels); writeFuns::insert(f + offset, vertLabels);
if (fSize == 3)
{
faceTypes.append(vtkTopo::VTK_TRIANGLE);
}
else if (fSize == 4)
{
faceTypes.append(vtkTopo::VTK_QUAD);
}
else
{
faceTypes.append(vtkTopo::VTK_POLYGON);
}
} }
offset += pp.nPoints(); offset += pp.nPoints();
} }
writeFuns::write(os_, binary_, vertLabels); writeFuns::write(os_, binary_, vertLabels);
os_ << "CELL_TYPES " << nFaces_ << std::endl;
writeFuns::write(os_, binary_, faceTypes);
} }

View File

@ -39,21 +39,16 @@ void Foam::writeFaceSet
{ {
const faceList& faces = vMesh.mesh().faces(); const faceList& faces = vMesh.mesh().faces();
std::ofstream pStream(fileName.c_str()); std::ofstream ostr(fileName.c_str());
pStream writeFuns::writeHeader
<< "# vtk DataFile Version 2.0" << std::endl (
<< set.name() << std::endl; ostr,
if (binary) binary,
{ set.name()
pStream << "BINARY" << std::endl; );
}
else
{
pStream << "ASCII" << std::endl;
}
pStream << "DATASET POLYDATA" << std::endl;
ostr<< "DATASET POLYDATA" << std::endl;
//------------------------------------------------------------------ //------------------------------------------------------------------
// //
@ -79,13 +74,13 @@ void Foam::writeFaceSet
// Write points and faces as polygons // Write points and faces as polygons
pStream << "POINTS " << fp.nPoints() << " float" << std::endl; ostr<< "POINTS " << fp.nPoints() << " float" << std::endl;
DynamicList<floatScalar> ptField(3*fp.nPoints()); DynamicList<floatScalar> ptField(3*fp.nPoints());
writeFuns::insert(fp.localPoints(), ptField); writeFuns::insert(fp.localPoints(), ptField);
writeFuns::write(pStream, binary, ptField); writeFuns::write(ostr, binary, ptField);
label nFaceVerts = 0; label nFaceVerts = 0;
@ -94,8 +89,7 @@ void Foam::writeFaceSet
{ {
nFaceVerts += fp.localFaces()[faceI].size() + 1; nFaceVerts += fp.localFaces()[faceI].size() + 1;
} }
pStream << "POLYGONS " << fp.size() << ' ' << nFaceVerts ostr<< "POLYGONS " << fp.size() << ' ' << nFaceVerts << std::endl;
<< std::endl;
DynamicList<label> vertLabels(nFaceVerts); DynamicList<label> vertLabels(nFaceVerts);
@ -108,7 +102,7 @@ void Foam::writeFaceSet
writeFuns::insert(f, vertLabels); writeFuns::insert(f, vertLabels);
} }
writeFuns::write(pStream, binary, vertLabels); writeFuns::write(ostr, binary, vertLabels);
//----------------------------------------------------------------- //-----------------------------------------------------------------
@ -119,14 +113,14 @@ void Foam::writeFaceSet
// Write faceID // Write faceID
pStream ostr
<< "CELL_DATA " << fp.size() << std::endl << "CELL_DATA " << fp.size() << std::endl
<< "FIELD attributes 1" << std::endl; << "FIELD attributes 1" << std::endl;
// Cell ids first // Cell ids first
pStream << "faceID 1 " << fp.size() << " int" << std::endl; ostr<< "faceID 1 " << fp.size() << " int" << std::endl;
writeFuns::write(pStream, binary, setFaceLabels); writeFuns::write(ostr, binary, setFaceLabels);
} }

View File

@ -186,11 +186,11 @@ void Foam::writeFuns::writeHeader
( (
std::ostream& os, std::ostream& os,
const bool binary, const bool binary,
const string& name const std::string& title
) )
{ {
os << "# vtk DataFile Version 2.0" << std::endl os << "# vtk DataFile Version 2.0" << std::endl
<< name << std::endl; << title << std::endl;
if (binary) if (binary)
{ {

View File

@ -73,13 +73,23 @@ public:
// Write header // Write header
static void writeHeader(std::ostream&, const bool, const string&); static void writeHeader
static void writeCellDataHeader(std::ostream&, const label, const label); (
std::ostream&,
const bool isBinary,
const std::string& title
);
static void writeCellDataHeader
(
std::ostream&,
const label nCells,
const label nFields
);
static void writePointDataHeader static void writePointDataHeader
( (
std::ostream&, std::ostream&,
const label, const label nPoints,
const label const label nFields
); );

View File

@ -40,16 +40,16 @@ void writePatchGeom
const bool binary, const bool binary,
const faceList& faces, const faceList& faces,
const pointField& points, const pointField& points,
std::ofstream& pStream std::ofstream& ostr
) )
{ {
pStream << "POINTS " << points.size() << " float" << std::endl; ostr<< "POINTS " << points.size() << " float" << std::endl;
DynamicList<floatScalar> ptField(3*points.size()); DynamicList<floatScalar> ptField(3*points.size());
writeFuns::insert(points, ptField); writeFuns::insert(points, ptField);
writeFuns::write(pStream, binary, ptField); writeFuns::write(ostr, binary, ptField);
label nFaceVerts = 0; label nFaceVerts = 0;
@ -58,8 +58,7 @@ void writePatchGeom
{ {
nFaceVerts += faces[faceI].size() + 1; nFaceVerts += faces[faceI].size() + 1;
} }
pStream << "POLYGONS " << faces.size() << ' ' << nFaceVerts ostr<< "POLYGONS " << faces.size() << ' ' << nFaceVerts << std::endl;
<< std::endl;
DynamicList<label> vertLabels(nFaceVerts); DynamicList<label> vertLabels(nFaceVerts);
@ -72,7 +71,7 @@ void writePatchGeom
writeFuns::insert(f, vertLabels); writeFuns::insert(f, vertLabels);
} }
writeFuns::write(pStream, binary, vertLabels); writeFuns::write(ostr, binary, vertLabels);
} }

View File

@ -43,13 +43,13 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Write lagrangian fields. // Write patch geometry
void writePatchGeom void writePatchGeom
( (
const bool binary, const bool binary,
const faceList& faces, const faceList& faces,
const pointField& points, const pointField& points,
std::ofstream& pStream std::ofstream&
); );
} // End namespace Foam } // End namespace Foam

View File

@ -42,21 +42,16 @@ void writePointSet
const fileName& fileName const fileName& fileName
) )
{ {
std::ofstream pStream(fileName.c_str()); std::ofstream ostr(fileName.c_str());
pStream writeFuns::writeHeader
<< "# vtk DataFile Version 2.0" << std::endl (
<< set.name() << std::endl; ostr,
if (binary) binary,
{ set.name()
pStream << "BINARY" << std::endl; );
}
else
{
pStream << "ASCII" << std::endl;
}
pStream << "DATASET POLYDATA" << std::endl;
ostr<< "DATASET POLYDATA" << std::endl;
//------------------------------------------------------------------ //------------------------------------------------------------------
// //
@ -67,7 +62,7 @@ void writePointSet
// Write points // Write points
pStream << "POINTS " << set.size() << " float" << std::endl; ostr<< "POINTS " << set.size() << " float" << std::endl;
DynamicList<floatScalar> ptField(3*set.size()); DynamicList<floatScalar> ptField(3*set.size());
@ -77,7 +72,7 @@ void writePointSet
ptField ptField
); );
writeFuns::write(pStream, binary, ptField); writeFuns::write(ostr, binary, ptField);
//----------------------------------------------------------------- //-----------------------------------------------------------------
@ -88,16 +83,16 @@ void writePointSet
// Write faceID // Write faceID
pStream ostr
<< "POINT_DATA " << set.size() << std::endl << "POINT_DATA " << set.size() << std::endl
<< "FIELD attributes 1" << std::endl; << "FIELD attributes 1" << std::endl;
// Cell ids first // Cell ids first
pStream << "pointID 1 " << set.size() << " int" << std::endl; ostr<< "pointID 1 " << set.size() << " int" << std::endl;
labelList pointIDs(set.toc()); labelList pointIDs(set.toc());
writeFuns::write(pStream, binary, pointIDs); writeFuns::write(ostr, binary, pointIDs);
} }

View File

@ -49,17 +49,13 @@ void writeSurfFields
std::ofstream str(fileName.c_str()); std::ofstream str(fileName.c_str());
str << "# vtk DataFile Version 2.0" << std::endl writeFuns::writeHeader
<< "surfaceFields" << std::endl; (
str,
binary,
"surfaceFields"
);
if (binary)
{
str << "BINARY" << std::endl;
}
else
{
str << "ASCII" << std::endl;
}
str << "DATASET POLYDATA" << std::endl; str << "DATASET POLYDATA" << std::endl;
const pointField& fc = mesh.faceCentres(); const pointField& fc = mesh.faceCentres();