ENH: construct VTK writers with the outputOptions and adjust internally

- this shifts responsibility away from caller to the individual writers
  for knowing which file formats are supported and which file ending is
  appropriate. When the writer receives the output format request,
  it can elect to downgrade or otherwise adjust it to what it can
  actually manage (eg, legacy vs xml vs xml-append).

  But currently still just with legacy format backends.
This commit is contained in:
Mark Olesen
2017-05-31 22:08:54 +02:00
parent 03944c2a26
commit c4f1349496
45 changed files with 593 additions and 322 deletions

View File

@ -34,22 +34,24 @@ License
void Foam::foamVtkOutput::writeCellSetFaces
(
const bool binary,
const primitiveMesh& mesh,
const cellSet& set,
const fileName& fileName
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
)
{
std::ofstream os(fileName.c_str());
outputOptions opts(outOpts);
opts.legacy(true); // Legacy only, no append
autoPtr<foamVtkOutput::formatter> format =
foamVtkOutput::outputOptions().legacy(true).ascii(!binary).newFormatter
(
os
);
std::ofstream os((baseName + (opts.legacy() ? ".vtk" : ".vtp")).c_str());
foamVtkOutput::legacy::fileHeader(format(), set.name())
<< "DATASET POLYDATA" << nl;
autoPtr<foamVtkOutput::formatter> format = opts.newFormatter(os);
if (opts.legacy())
{
foamVtkOutput::legacy::fileHeader(format(), set.name())
<< "DATASET POLYDATA" << nl;
}
//-------------------------------------------------------------------------
@ -87,7 +89,7 @@ void Foam::foamVtkOutput::writeCellSetFaces
}
}
labelList faceLabels = cellFaces.sortedToc();
const labelList faceLabels = cellFaces.sortedToc();
labelList faceValues(cellFaces.size());
forAll(faceLabels, facei)

View File

@ -39,6 +39,7 @@ SourceFiles
#include "primitiveMesh.H"
#include "uindirectPrimitivePatch.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -55,10 +56,10 @@ namespace foamVtkOutput
// The data are the original cell ids
void writeCellSetFaces
(
const bool binary,
const primitiveMesh& mesh,
const cellSet& set,
const fileName& fileName
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
);
} // End namespace foamVtkOutput

View File

@ -34,27 +34,29 @@ License
void Foam::foamVtkOutput::writeFaceSet
(
const bool binary,
const primitiveMesh& mesh,
const faceSet& set,
const fileName& fileName
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
)
{
std::ofstream os(fileName.c_str());
outputOptions opts(outOpts);
opts.legacy(true); // Legacy only, no append
autoPtr<foamVtkOutput::formatter> format =
foamVtkOutput::outputOptions().legacy(true).ascii(!binary).newFormatter
(
os
);
std::ofstream os((baseName + (opts.legacy() ? ".vtk" : ".vtp")).c_str());
foamVtkOutput::legacy::fileHeader(format(), set.name())
<< "DATASET POLYDATA" << nl;
autoPtr<foamVtkOutput::formatter> format = opts.newFormatter(os);
if (opts.legacy())
{
foamVtkOutput::legacy::fileHeader(format(), set.name())
<< "DATASET POLYDATA" << nl;
}
//-------------------------------------------------------------------------
// Faces of set with OpenFOAM faceID as value
labelList faceLabels = set.sortedToc();
const labelList faceLabels = set.sortedToc();
uindirectPrimitivePatch pp
(

View File

@ -36,6 +36,8 @@ SourceFiles
#ifndef foamVtkWriteFaceSet_H
#define foamVtkWriteFaceSet_H
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
@ -51,10 +53,10 @@ namespace foamVtkOutput
// Only one data which is original pointID.
void writeFaceSet
(
const bool binary,
const primitiveMesh& mesh,
const faceSet& set,
const fileName& fileName
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
);

View File

@ -33,22 +33,24 @@ License
void Foam::foamVtkOutput::writePointSet
(
const bool binary,
const primitiveMesh& mesh,
const pointSet& set,
const fileName& fileName
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
)
{
std::ofstream os(fileName.c_str());
outputOptions opts(outOpts);
opts.legacy(true); // Legacy only, no append
autoPtr<foamVtkOutput::formatter> format =
foamVtkOutput::outputOptions().legacy(true).ascii(!binary).newFormatter
(
os
);
std::ofstream os((baseName + (opts.legacy() ? ".vtk" : ".vtp")).c_str());
foamVtkOutput::legacy::fileHeader(format(), set.name())
<< "DATASET POLYDATA" << nl;
autoPtr<foamVtkOutput::formatter> format = opts.newFormatter(os);
if (opts.legacy())
{
foamVtkOutput::legacy::fileHeader(format(), set.name())
<< "DATASET POLYDATA" << nl;
}
//-------------------------------------------------------------------------

View File

@ -36,6 +36,8 @@ SourceFiles
#ifndef foamVtkWritePointSet_H
#define foamVtkWritePointSet_H
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
@ -51,10 +53,10 @@ namespace foamVtkOutput
// The data are the original point ids.
void writePointSet
(
const bool binary,
const primitiveMesh& mesh,
const pointSet& set,
const fileName& fileName
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
);