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;
std::ofstream str(patchFileName.c_str());
std::ofstream ostr(patchFileName.c_str());
writeFuns::writeHeader(str, binary, pp.name());
str << "DATASET POLYDATA" << std::endl;
writeFuns::writeHeader(ostr, binary, pp.name());
ostr<< "DATASET POLYDATA" << std::endl;
writePatchGeom
(
binary,
pp().localFaces(),
pp().localPoints(),
str
ostr
);
}
}

View File

@ -56,7 +56,7 @@ Foam::patchWriter::patchWriter
{
writeFuns::writeHeader(os_, binary_, "patches");
}
os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
os_ << "DATASET POLYDATA" << std::endl;
// Write topology
nPoints_ = 0;
@ -88,10 +88,9 @@ Foam::patchWriter::patchWriter
}
writeFuns::write(os_, binary_, ptField);
os_ << "CELLS " << nFaces_ << ' ' << nFaceVerts << std::endl;
os_ << "POLYGONS " << nFaces_ << ' ' << nFaceVerts << std::endl;
DynamicList<label> vertLabels(nFaceVerts);
DynamicList<label> faceTypes(nFaceVerts);
label offset = 0;
@ -103,30 +102,12 @@ Foam::patchWriter::patchWriter
{
const face& f = pp.localFaces()[faceI];
const label fSize = f.size();
vertLabels.append(fSize);
vertLabels.append(f.size());
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();
}
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();
std::ofstream pStream(fileName.c_str());
std::ofstream ostr(fileName.c_str());
pStream
<< "# vtk DataFile Version 2.0" << std::endl
<< set.name() << std::endl;
if (binary)
{
pStream << "BINARY" << std::endl;
}
else
{
pStream << "ASCII" << std::endl;
}
pStream << "DATASET POLYDATA" << std::endl;
writeFuns::writeHeader
(
ostr,
binary,
set.name()
);
ostr<< "DATASET POLYDATA" << std::endl;
//------------------------------------------------------------------
//
@ -79,13 +74,13 @@ void Foam::writeFaceSet
// 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());
writeFuns::insert(fp.localPoints(), ptField);
writeFuns::write(pStream, binary, ptField);
writeFuns::write(ostr, binary, ptField);
label nFaceVerts = 0;
@ -94,8 +89,7 @@ void Foam::writeFaceSet
{
nFaceVerts += fp.localFaces()[faceI].size() + 1;
}
pStream << "POLYGONS " << fp.size() << ' ' << nFaceVerts
<< std::endl;
ostr<< "POLYGONS " << fp.size() << ' ' << nFaceVerts << std::endl;
DynamicList<label> vertLabels(nFaceVerts);
@ -108,7 +102,7 @@ void Foam::writeFaceSet
writeFuns::insert(f, vertLabels);
}
writeFuns::write(pStream, binary, vertLabels);
writeFuns::write(ostr, binary, vertLabels);
//-----------------------------------------------------------------
@ -119,14 +113,14 @@ void Foam::writeFaceSet
// Write faceID
pStream
ostr
<< "CELL_DATA " << fp.size() << std::endl
<< "FIELD attributes 1" << std::endl;
// 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,
const bool binary,
const string& name
const std::string& title
)
{
os << "# vtk DataFile Version 2.0" << std::endl
<< name << std::endl;
<< title << std::endl;
if (binary)
{

View File

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

View File

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

View File

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

View File

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