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

@ -1,4 +1,5 @@
EXE_INC = \
-I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
$(COMP_FLAGS)

View File

@ -76,7 +76,7 @@ void writeVTK
(
const polyMesh& mesh,
const topoSet& currentSet,
const fileName& vtkName
const fileName& vtkBaseName
)
{
if (isA<faceSet>(currentSet))
@ -84,10 +84,10 @@ void writeVTK
// Faces of set with OpenFOAM faceID as value
foamVtkOutput::writeFaceSet
(
true,
mesh,
currentSet,
mesh.time().path()/vtkName
mesh.time().path()/vtkBaseName,
foamVtkOutput::formatType::LEGACY_BINARY
);
}
else if (isA<cellSet>(currentSet))
@ -95,20 +95,20 @@ void writeVTK
// External faces of cellset with OpenFOAM cellID as value
foamVtkOutput::writeCellSetFaces
(
true,
mesh,
currentSet,
mesh.time().path()/vtkName
mesh.time().path()/vtkBaseName,
foamVtkOutput::formatType::LEGACY_BINARY
);
}
else if (isA<pointSet>(currentSet))
{
foamVtkOutput::writePointSet
(
true,
mesh,
currentSet,
mesh.time().path()/vtkName
mesh.time().path()/vtkBaseName,
foamVtkOutput::formatType::LEGACY_BINARY
);
}
else
@ -123,58 +123,58 @@ void writeVTK
void printHelp(Ostream& os)
{
os << "Please type 'help', 'list', 'quit', 'time ddd'"
<< " or a set command after prompt." << endl
<< "'list' will show all current cell/face/point sets." << endl
<< "'time ddd' will change the current time." << endl
<< endl
<< "A set command should be of the following form" << endl
<< endl
<< " or a set command after prompt." << nl
<< "'list' will show all current cell/face/point sets." << nl
<< "'time ddd' will change the current time." << nl
<< nl
<< "A set command should be of the following form" << nl
<< nl
<< " cellSet|faceSet|pointSet <setName> <action> <source>"
<< endl
<< endl
<< "The <action> is one of" << endl
<< " list - prints the contents of the set" << endl
<< " clear - clears the set" << endl
<< " invert - inverts the set" << endl
<< " remove - remove the set" << endl
<< " new <source> - sets to set to the source set" << endl
<< " add <source> - adds all elements from the source set" << endl
<< " delete <source> - deletes ,," << endl
<< nl
<< nl
<< "The <action> is one of" << nl
<< " list - prints the contents of the set" << nl
<< " clear - clears the set" << nl
<< " invert - inverts the set" << nl
<< " remove - remove the set" << nl
<< " new <source> - sets to set to the source set" << nl
<< " add <source> - adds all elements from the source set" << nl
<< " delete <source> - deletes ,," << nl
<< " subset <source> - combines current set with the source set"
<< endl
<< endl
<< nl
<< nl
<< "The sources come in various forms. Type a wrong source"
<< " to see all the types available." << endl
<< endl
<< " to see all the types available." << nl
<< nl
<< "Example: pick up all cells connected by point or face to patch"
<< " movingWall" << endl
<< endl
<< "Pick up all faces of patch:" << endl
<< " faceSet f0 new patchToFace movingWall" << endl
<< "Add faces 0,1,2:" << endl
<< " faceSet f0 add labelToFace (0 1 2)" << endl
<< "Pick up all points used by faces in faceSet f0:" << endl
<< " pointSet p0 new faceToPoint f0 all" << endl
<< "Pick up cell which has any face in f0:" << endl
<< " cellSet c0 new faceToCell f0 any" << endl
<< "Add cells which have any point in p0:" << endl
<< " cellSet c0 add pointToCell p0 any" << endl
<< "List set:" << endl
<< " cellSet c0 list" << endl
<< endl
<< "Zones can be set using zoneSets from corresponding sets:" << endl
<< " cellZoneSet c0Zone new setToCellZone c0" << endl
<< " faceZoneSet f0Zone new setToFaceZone f0" << endl
<< endl
<< "or if orientation is important:" << endl
<< " faceZoneSet f0Zone new setsToFaceZone f0 c0" << endl
<< endl
<< "ZoneSets can be manipulated using the general actions:" << endl
<< " list - prints the contents of the set" << endl
<< " clear - clears the set" << endl
<< " movingWall" << nl
<< nl
<< "Pick up all faces of patch:" << nl
<< " faceSet f0 new patchToFace movingWall" << nl
<< "Add faces 0,1,2:" << nl
<< " faceSet f0 add labelToFace (0 1 2)" << nl
<< "Pick up all points used by faces in faceSet f0:" << nl
<< " pointSet p0 new faceToPoint f0 all" << nl
<< "Pick up cell which has any face in f0:" << nl
<< " cellSet c0 new faceToCell f0 any" << nl
<< "Add cells which have any point in p0:" << nl
<< " cellSet c0 add pointToCell p0 any" << nl
<< "List set:" << nl
<< " cellSet c0 list" << nl
<< nl
<< "Zones can be set using zoneSets from corresponding sets:" << nl
<< " cellZoneSet c0Zone new setToCellZone c0" << nl
<< " faceZoneSet f0Zone new setToFaceZone f0" << nl
<< nl
<< "or if orientation is important:" << nl
<< " faceZoneSet f0Zone new setsToFaceZone f0 c0" << nl
<< nl
<< "ZoneSets can be manipulated using the general actions:" << nl
<< " list - prints the contents of the set" << nl
<< " clear - clears the set" << nl
<< " invert - inverts the set (undefined orientation)"
<< endl
<< " remove - remove the set" << endl
<< nl
<< " remove - remove the set" << nl
<< endl;
}
@ -513,7 +513,6 @@ bool doCommand
"VTK"/currentSet.name()/currentSet.name()
+ "_"
+ name(mesh.time().timeIndex())
+ ".vtk"
);
Info<< " Writing " << currentSet.name()

View File

@ -239,12 +239,19 @@ labelList getSelectedPatches
// Process args for output options
// Default from foamVtkOutputOptions is inline ASCII xml
//
enum foamVtkOutput::formatType getOutputOptions(const argList& args)
foamVtkOutput::outputOptions getOutputOptions(const argList& args)
{
foamVtkOutput::outputOptions opts;
{
opts.legacy(true);
if (!args.optionFound("ascii"))
{
if (sizeof(floatScalar) != 4 || sizeof(label) != 4)
{
opts.ascii(true);
WarningInFunction
<< "Using ASCII rather than binary VTK format since "
<< "floatScalar and/or label are not 4 bytes in size."
@ -252,11 +259,12 @@ enum foamVtkOutput::formatType getOutputOptions(const argList& args)
}
else
{
return foamVtkOutput::formatType::LEGACY_BINARY;
opts.ascii(false);
}
}
}
return foamVtkOutput::formatType::LEGACY_ASCII;
return opts;
}
@ -398,11 +406,10 @@ int main(int argc, char *argv[])
const bool doLinks = !args.optionFound("noLinks");
const bool useTimeName = args.optionFound("useTimeName");
const bool noLagrangian = args.optionFound("noLagrangian");
const enum foamVtkOutput::formatType fmtType = getOutputOptions(args);
const bool binary = (fmtType == foamVtkOutput::formatType::LEGACY_BINARY);
const bool nearCellValue = args.optionFound("nearCellValue");
const foamVtkOutput::outputOptions fmtType = getOutputOptions(args);
if (nearCellValue)
{
WarningInFunction
@ -495,11 +502,7 @@ int main(int argc, char *argv[])
meshSubsetHelper meshRef(mesh, meshSubsetHelper::SET, cellSetName);
// Collect decomposition information etc.
foamVtkCells foamVtkMeshCells
(
foamVtkCells::contentType::LEGACY,
decomposePoly
);
foamVtkCells foamVtkMeshCells(fmtType, decomposePoly);
Info<< "VTK mesh topology: "
<< timer.cpuTimeIncrement() << " s, "
@ -545,17 +548,16 @@ int main(int argc, char *argv[])
fvPath/set.name()/set.name()
+ "_"
+ timeDesc
+ ".vtk"
);
Info<< " faceSet : "
<< relativeName(runTime, outputName) << nl;
foamVtkOutput::writeFaceSet
(
binary,
meshRef.mesh(),
set,
outputName
outputName,
fmtType
);
continue;
}
@ -574,17 +576,16 @@ int main(int argc, char *argv[])
fvPath/set.name()/set.name()
+ "_"
+ timeDesc
+ ".vtk"
);
Info<< " pointSet : "
<< relativeName(runTime, outputName) << nl;
foamVtkOutput::writePointSet
(
binary,
meshRef.mesh(),
set,
outputName
outputName,
fmtType
);
continue;
}
@ -594,7 +595,7 @@ int main(int argc, char *argv[])
IOobjectList objects(mesh, runTime.timeName());
HashSet<word> selectedFields;
bool specifiedFields = args.optionReadIfPresent
const bool specifiedFields = args.optionReadIfPresent
(
"fields",
selectedFields
@ -836,7 +837,6 @@ int main(int argc, char *argv[])
fvPath/vtkName
+ "_"
+ timeDesc
+ ".vtk"
);
Info<< " Internal : "
<< relativeName(runTime, outputName) << endl;
@ -845,9 +845,9 @@ int main(int argc, char *argv[])
foamVtkOutput::internalWriter writer
(
meshRef.baseMesh(),
fmtType,
foamVtkMeshCells,
outputName
outputName,
fmtType
);
// CellData
@ -963,14 +963,13 @@ int main(int argc, char *argv[])
/ "surfaceFields"
+ "_"
+ timeDesc
+ ".vtk"
);
foamVtkOutput::writeSurfFields
(
binary,
meshRef.mesh(),
outputName,
fmtType,
sVectorFld
);
}
@ -995,7 +994,6 @@ int main(int argc, char *argv[])
/ (meshRef.useSubMesh() ? cellSetName : "allPatches")
+ "_"
+ timeDesc
+ ".vtk"
);
Info<< " Combined patches : "
<< relativeName(runTime, outputName) << nl;
@ -1003,9 +1001,9 @@ int main(int argc, char *argv[])
foamVtkOutput::patchWriter writer
(
meshRef.mesh(),
binary,
nearCellValue,
outputName,
fmtType,
nearCellValue,
getSelectedPatches(patches, excludePatches)
);
@ -1064,7 +1062,6 @@ int main(int argc, char *argv[])
/ (meshRef.useSubMesh() ? cellSetName : pp.name())
+ "_"
+ timeDesc
+ ".vtk"
);
Info<< " Patch : "
<< relativeName(runTime, outputName) << nl;
@ -1072,9 +1069,9 @@ int main(int argc, char *argv[])
foamVtkOutput::patchWriter writer
(
meshRef.mesh(),
binary,
nearCellValue,
outputName,
fmtType,
nearCellValue,
labelList{patchi}
);
@ -1168,7 +1165,6 @@ int main(int argc, char *argv[])
/ (meshRef.useSubMesh() ? cellSetName : fz.name())
+ "_"
+ timeDesc
+ ".vtk"
);
Info<< " FaceZone : "
<< relativeName(runTime, outputName) << nl;
@ -1181,10 +1177,10 @@ int main(int argc, char *argv[])
foamVtkOutput::surfaceMeshWriter writer
(
binary,
pp,
fz.name(),
outputName
outputName,
fmtType
);
// Number of fields
@ -1214,7 +1210,7 @@ int main(int argc, char *argv[])
fileName outputName
(
fvPath/cloud::prefix/cloudName/cloudName
+ "_" + timeDesc + ".vtk"
+ "_" + timeDesc
);
Info<< " Lagrangian: "
<< relativeName(runTime, outputName) << nl;
@ -1267,10 +1263,9 @@ int main(int argc, char *argv[])
foamVtkOutput::lagrangianWriter writer
(
meshRef.mesh(),
binary,
outputName,
cloudName,
false
outputName,
fmtType
);
// Write number of fields
@ -1299,9 +1294,9 @@ int main(int argc, char *argv[])
foamVtkOutput::lagrangianWriter writer
(
meshRef.mesh(),
binary,
outputName,
cloudName,
outputName,
fmtType,
true
);

View File

@ -32,30 +32,30 @@ License
Foam::foamVtkOutput::lagrangianWriter::lagrangianWriter
(
const fvMesh& mesh,
const bool binary,
const fileName& fName,
const word& cloudName,
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts,
const bool dummyCloud
)
:
mesh_(mesh),
format_(),
cloudName_(cloudName),
os_(fName.c_str()),
os_(),
nParcels_(0)
{
format_ = foamVtkOutput::newFormatter
(
os_,
(
binary
? foamVtkOutput::LEGACY_BINARY
: foamVtkOutput::LEGACY_ASCII
)
);
outputOptions opts(outOpts);
opts.legacy(true); // Legacy only, no append
os_.open((baseName + (opts.legacy() ? ".vtk" : ".vtp")).c_str());
format_ = opts.newFormatter(os_);
if (opts.legacy())
{
foamVtkOutput::legacy::fileHeader(format(), mesh_.time().caseName())
<< "DATASET POLYDATA" << nl;
}
if (dummyCloud)
{
@ -80,6 +80,12 @@ Foam::foamVtkOutput::lagrangianWriter::lagrangianWriter
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::foamVtkOutput::lagrangianWriter::~lagrangianWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::foamVtkOutput::lagrangianWriter::beginParcelData

View File

@ -40,7 +40,7 @@ SourceFiles
#include "Cloud.H"
#include "volFields.H"
#include "pointFields.H"
#include "foamVtkOutput.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -76,13 +76,17 @@ public:
lagrangianWriter
(
const fvMesh& mesh,
const bool binary,
const fileName&,
const word&,
const bool dummyCloud
const word& cloudName,
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts,
const bool dummyCloud = false
);
//- Destructor
~lagrangianWriter();
// Member Functions
inline std::ofstream& os()

View File

@ -30,21 +30,27 @@ License
Foam::foamVtkOutput::internalWriter::internalWriter
(
const fvMesh& mesh,
enum foamVtkOutput::formatType fmtType,
const foamVtkCells& cells,
const fileName& outputName
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
)
:
mesh_(mesh),
format_(),
vtkCells_(cells),
os_(outputName.c_str())
os_()
{
format_ = foamVtkOutput::newFormatter(os_, fmtType);
outputOptions opts(outOpts);
opts.legacy(true); // Legacy only, no append
// Write header
os_.open((baseName + (opts.legacy() ? ".vtk" : ".vtu")).c_str());
format_ = opts.newFormatter(os_);
if (opts.legacy())
{
foamVtkOutput::legacy::fileHeader(format(), mesh.time().caseName())
<< "DATASET UNSTRUCTURED_GRID" << nl;
}
//------------------------------------------------------------------
//
@ -84,6 +90,12 @@ Foam::foamVtkOutput::internalWriter::internalWriter
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::foamVtkOutput::internalWriter::~internalWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

View File

@ -42,6 +42,7 @@ SourceFiles
#include "foamVtkCells.H"
#include "foamVtkOutputFields.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -78,12 +79,16 @@ public:
internalWriter
(
const fvMesh& mesh,
enum foamVtkOutput::formatType fmtType,
const foamVtkCells& cells,
const fileName& outputName
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
);
//- Destructor
~internalWriter();
// Member Functions
inline std::ofstream& os()

View File

@ -31,9 +31,9 @@ License
Foam::foamVtkOutput::patchWriter::patchWriter
(
const fvMesh& mesh,
const bool binary,
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts,
const bool nearCellValue,
const fileName& fName,
const labelList& patchIDs
)
:
@ -41,20 +41,18 @@ Foam::foamVtkOutput::patchWriter::patchWriter
format_(),
nearCellValue_(nearCellValue),
patchIDs_(patchIDs),
os_(fName.c_str())
os_()
{
outputOptions opts(outOpts);
opts.legacy(true); // Legacy only, no append
os_.open((baseName + (opts.legacy() ? ".vtk" : ".vtp")).c_str());
format_ = opts.newFormatter(os_);
const polyBoundaryMesh& patches = mesh.boundaryMesh();
format_ = foamVtkOutput::newFormatter
(
os_,
(
binary
? foamVtkOutput::LEGACY_BINARY
: foamVtkOutput::LEGACY_ASCII
)
);
if (opts.legacy())
{
foamVtkOutput::legacy::fileHeader
(
format(),
@ -64,6 +62,7 @@ Foam::foamVtkOutput::patchWriter::patchWriter
: "patches"
)
) << "DATASET POLYDATA" << nl;
}
//------------------------------------------------------------------
@ -120,6 +119,12 @@ Foam::foamVtkOutput::patchWriter::patchWriter
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::foamVtkOutput::patchWriter::~patchWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::foamVtkOutput::patchWriter::beginCellData(label nFields)

View File

@ -42,7 +42,7 @@ SourceFiles
#include "pointFields.H"
#include "indirectPrimitivePatch.H"
#include "PrimitivePatchInterpolation.H"
#include "foamVtkOutput.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -82,13 +82,17 @@ public:
patchWriter
(
const fvMesh& mesh,
const bool binary,
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts,
const bool nearCellValue,
const fileName& fName,
const labelList& patchIDs
);
//- Destructor
~patchWriter();
// Member Functions
inline std::ofstream& os()

View File

@ -30,28 +30,27 @@ License
Foam::foamVtkOutput::surfaceMeshWriter::surfaceMeshWriter
(
const bool binary,
const indirectPrimitivePatch& pp,
const word& name,
const fileName& fName
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
)
:
pp_(pp),
format_(),
os_(fName.c_str())
os_()
{
format_ = foamVtkOutput::newFormatter
(
os_,
(
binary
? foamVtkOutput::LEGACY_BINARY
: foamVtkOutput::LEGACY_ASCII
)
);
outputOptions opts(outOpts);
opts.legacy(true); // Legacy only, no append
os_.open((baseName + (opts.legacy() ? ".vtk" : ".vtp")).c_str());
format_ = opts.newFormatter(os_);
if (opts.legacy())
{
foamVtkOutput::legacy::fileHeader(format(), name)
<< "DATASET POLYDATA" << nl;
}
//------------------------------------------------------------------
@ -81,6 +80,12 @@ Foam::foamVtkOutput::surfaceMeshWriter::surfaceMeshWriter
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::foamVtkOutput::surfaceMeshWriter::~surfaceMeshWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::foamVtkOutput::surfaceMeshWriter::beginCellData(label nFields)

View File

@ -41,7 +41,7 @@ SourceFiles
#include "volFields.H"
#include "surfaceFields.H"
#include "indirectPrimitivePatch.H"
#include "foamVtkOutput.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -72,13 +72,17 @@ public:
//- Construct from components
surfaceMeshWriter
(
const bool binary,
const indirectPrimitivePatch& pp,
const word& name,
const fileName&
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
);
//- Destructor
~surfaceMeshWriter();
// Member Functions
inline std::ofstream& os()

View File

@ -34,26 +34,23 @@ License
void Foam::foamVtkOutput::writeSurfFields
(
const bool binary,
const fvMesh& mesh,
const fileName& fileName,
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts,
const UPtrList<const surfaceVectorField>& surfVectorFields
)
{
std::ofstream os(fileName.c_str());
outputOptions opts(outOpts);
opts.legacy(true); // Legacy only, no append
autoPtr<foamVtkOutput::formatter> format = foamVtkOutput::newFormatter
(
os,
(
binary
? foamVtkOutput::LEGACY_BINARY
: foamVtkOutput::LEGACY_ASCII
)
);
std::ofstream os((baseName + (opts.legacy() ? ".vtk" : ".vtp")).c_str());
autoPtr<foamVtkOutput::formatter> format = opts.newFormatter(os);
if (opts.legacy())
{
foamVtkOutput::legacy::fileHeader(format(), "surfaceFields")
<< "DATASET POLYDATA" << nl;
}
const pointField& fc = mesh.faceCentres();

View File

@ -38,6 +38,7 @@ SourceFiles
#include "fvMesh.H"
#include "surfaceMesh.H"
#include "surfaceFieldsFwd.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -49,9 +50,9 @@ namespace foamVtkOutput
//- Write surface vector fields
void writeSurfFields
(
const bool binary,
const fvMesh& mesh,
const fileName& fileName,
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts,
const UPtrList<const surfaceVectorField>& surfVectorFields
);

View File

@ -23,8 +23,9 @@ License
\*---------------------------------------------------------------------------*/
#include "foamVtkCells.H"
#include "polyMesh.H"
#include "foamVtkCells.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -59,6 +60,33 @@ Foam::foamVtkCells::foamVtkCells
}
Foam::foamVtkCells::foamVtkCells
(
const foamVtkOutput::outputOptions outOpts,
const bool decompose
)
:
foamVtkCells
(
(outOpts.legacy() ? contentType::LEGACY : contentType::XML),
decompose
)
{}
Foam::foamVtkCells::foamVtkCells
(
const polyMesh& mesh,
const foamVtkOutput::outputOptions outOpts,
const bool decompose
)
:
foamVtkCells(outOpts, decompose)
{
reset(mesh);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::foamVtkCells::~foamVtkCells()

View File

@ -61,6 +61,12 @@ namespace Foam
// Forward declaration of classes
class polyMesh;
namespace foamVtkOutput
{
class outputOptions;
}
/*---------------------------------------------------------------------------*\
Class foamVtkCells Declaration
\*---------------------------------------------------------------------------*/
@ -132,6 +138,23 @@ public:
const bool decompose = false
);
//- Construct from components.
// Optionally with polyhedral decomposition.
foamVtkCells
(
const foamVtkOutput::outputOptions outOpts,
const bool decompose = false
);
//- Construct from components and create the output information
// immediately
foamVtkCells
(
const polyMesh& mesh,
const foamVtkOutput::outputOptions outOpts,
const bool decompose = false
);
//- Destructor
~foamVtkCells();

View File

@ -79,7 +79,6 @@ void Foam::vtkSetWriter<Type>::write
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
}
os << "POINT_DATA " << points.size() << nl
<< " FIELD attributes " << valueSetNames.size() << nl;

View File

@ -24,11 +24,15 @@ License
\*---------------------------------------------------------------------------*/
#include "foamVtkAppendBase64Formatter.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const char* Foam::foamVtkOutput::appendBase64Formatter::name_ = "append";
const Foam::foamVtkOutput::outputOptions
Foam::foamVtkOutput::appendBase64Formatter::opts_(formatType::APPEND_BASE64);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -51,6 +55,13 @@ Foam::foamVtkOutput::appendBase64Formatter::~appendBase64Formatter()
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::foamVtkOutput::outputOptions&
Foam::foamVtkOutput::appendBase64Formatter::opts() const
{
return opts_;
}
const char* Foam::foamVtkOutput::appendBase64Formatter::name() const
{
return name_;

View File

@ -56,6 +56,7 @@ class appendBase64Formatter
// Private Data Members
static const char* name_;
static const outputOptions opts_;
// Private Member Functions
@ -81,11 +82,8 @@ public:
// Member Functions
//- The output formatType is APPEND_BASE64.
virtual enum formatType format() const
{
return formatType::APPEND_BASE64;
}
//- The output is APPEND_BASE64.
virtual const outputOptions& opts() const;
//- Output name for XML type ("append")
virtual const char* name() const;

View File

@ -24,12 +24,16 @@ License
\*---------------------------------------------------------------------------*/
#include "foamVtkAppendRawFormatter.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const char* Foam::foamVtkOutput::appendRawFormatter::name_ = "append";
const char* Foam::foamVtkOutput::appendRawFormatter::encoding_ = "raw";
const Foam::foamVtkOutput::outputOptions
Foam::foamVtkOutput::appendRawFormatter::opts_(formatType::APPEND_BINARY);
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
@ -59,6 +63,13 @@ Foam::foamVtkOutput::appendRawFormatter::~appendRawFormatter()
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::foamVtkOutput::outputOptions&
Foam::foamVtkOutput::appendRawFormatter::opts() const
{
return opts_;
}
const char* Foam::foamVtkOutput::appendRawFormatter::name() const
{
return name_;

View File

@ -56,6 +56,8 @@ class appendRawFormatter
static const char* name_;
static const char* encoding_;
static const outputOptions opts_;
// Private Member Functions
@ -88,11 +90,8 @@ public:
// Member Functions
//- The output formatType is APPEND_BINARY.
virtual enum formatType format() const
{
return formatType::APPEND_BINARY;
}
//- The output is APPEND_BINARY.
virtual const outputOptions& opts() const;
//- Output name for XML type ("append")
virtual const char* name() const;

View File

@ -24,11 +24,15 @@ License
\*---------------------------------------------------------------------------*/
#include "foamVtkAsciiFormatter.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const char* Foam::foamVtkOutput::asciiFormatter::name_ = "ascii";
const Foam::foamVtkOutput::outputOptions
Foam::foamVtkOutput::asciiFormatter::opts_(formatType::INLINE_ASCII);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -89,6 +93,13 @@ Foam::foamVtkOutput::asciiFormatter::~asciiFormatter()
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::foamVtkOutput::outputOptions&
Foam::foamVtkOutput::asciiFormatter::opts() const
{
return opts_;
}
const char* Foam::foamVtkOutput::asciiFormatter::name() const
{
return name_;

View File

@ -57,6 +57,7 @@ class asciiFormatter
// Private Data Members
static const char* name_;
static const outputOptions opts_;
//- Track the current output position
unsigned short pos_;
@ -95,11 +96,8 @@ public:
// Member Functions
//- The output formatType is INLINE_ASCII.
virtual enum formatType format() const
{
return formatType::INLINE_ASCII;
}
//- The output is INLINE_ASCII.
virtual const outputOptions& opts() const;
//- Name for the XML output type ("ascii")
virtual const char* name() const;

View File

@ -24,11 +24,15 @@ License
\*---------------------------------------------------------------------------*/
#include "foamVtkBase64Formatter.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const char* Foam::foamVtkOutput::base64Formatter::name_ = "binary";
const Foam::foamVtkOutput::outputOptions
Foam::foamVtkOutput::base64Formatter::opts_(formatType::INLINE_BASE64);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -51,6 +55,13 @@ Foam::foamVtkOutput::base64Formatter::~base64Formatter()
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::foamVtkOutput::outputOptions&
Foam::foamVtkOutput::base64Formatter::opts() const
{
return opts_;
}
const char* Foam::foamVtkOutput::base64Formatter::name() const
{
return name_;

View File

@ -33,6 +33,7 @@ Description
#ifndef foamVtkBase64Formatter_H
#define foamVtkBase64Formatter_H
#include "foamVtkFormatter.H"
#include "foamVtkBase64Layer.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -53,7 +54,7 @@ class base64Formatter
// Private Data Members
static const char* name_;
static const char* encoding_;
static const outputOptions opts_;
// Private Member Functions
@ -64,6 +65,7 @@ class base64Formatter
//- Disallow default bitwise assignment
void operator=(const base64Formatter&) = delete;
public:
// Constructors
@ -78,11 +80,8 @@ public:
// Member Functions
//- The output formatType is INLINE_BASE64.
virtual enum formatType format() const
{
return formatType::INLINE_BASE64;
}
//- The output is INLINE_BASE64.
virtual const outputOptions& opts() const;
//- Name for the XML output type ("binary")
virtual const char* name() const;

View File

@ -64,6 +64,7 @@ class foamVtkBase64Layer
//- Disallow default bitwise assignment
void operator=(const foamVtkBase64Layer&) = delete;
protected:
// Protected Member Functions

View File

@ -57,6 +57,8 @@ namespace Foam
namespace foamVtkOutput
{
class outputOptions;
/*---------------------------------------------------------------------------*\
Class formatter Declaration
\*---------------------------------------------------------------------------*/
@ -111,8 +113,8 @@ public:
//- Access to the underlying output stream
inline std::ostream& os();
//- The output formatType.
virtual enum formatType format() const = 0;
//- The format-type / output options.
virtual const outputOptions& opts() const = 0;
//- Name for the XML output type or the legacy output type.
virtual const char* name() const = 0;
@ -195,6 +197,17 @@ public:
const bool leaveOpen = false
);
//- Add a "VTKFile" XML tag for contentType, followed by a tag for
// the contentType itself. Optionally leave the contentType tag
// open for adding additional attributes.
// \return formatter for chaining
inline formatter& beginVTKFile
(
const vtkFileTag& contentType,
const word& contentVersion,
const bool leaveOpen = false
);
//- Add a "AppendedData" XML tag with the current encoding and output
// the requisite '_' prefix.
// \return formatter for chaining
@ -206,6 +219,11 @@ public:
template<class Type, int nComp=0>
formatter& openDataArray(const word& dataName);
//- Open "DataArray" XML tag
// \return formatter for chaining
template<class Type, int nComp=0>
formatter& openDataArray(const vtkFileTag& tagEnum);
//- Insert a single "PDataArray" XML entry tag.
// For some entries, the name is optional.

View File

@ -72,6 +72,23 @@ Foam::foamVtkOutput::formatter::tag(const vtkFileTag& tagEnum)
}
inline Foam::foamVtkOutput::formatter&
Foam::foamVtkOutput::formatter::beginVTKFile
(
const vtkFileTag& contentType,
const word& contentVersion,
const bool leaveOpen
)
{
return beginVTKFile
(
vtkFileTagNames[contentType],
contentVersion,
leaveOpen
);
}
inline Foam::foamVtkOutput::formatter&
Foam::foamVtkOutput::formatter::endDataArray()
{

View File

@ -68,6 +68,17 @@ Foam::foamVtkOutput::formatter::openDataArray
}
template<class Type, int nComp>
Foam::foamVtkOutput::formatter&
Foam::foamVtkOutput::formatter::openDataArray
(
const vtkFileTag& tagEnum
)
{
return openDataArray<Type, nComp>(vtkFileTagNames[tagEnum]);
}
template<class Type, int nComp>
Foam::foamVtkOutput::formatter&
Foam::foamVtkOutput::formatter::PDataArray

View File

@ -24,11 +24,15 @@ License
\*---------------------------------------------------------------------------*/
#include "foamVtkLegacyAsciiFormatter.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const char* Foam::foamVtkOutput::legacyAsciiFormatter::legacyName_ = "ASCII";
const Foam::foamVtkOutput::outputOptions
Foam::foamVtkOutput::legacyAsciiFormatter::opts_(formatType::LEGACY_ASCII);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -59,6 +63,13 @@ Foam::foamVtkOutput::legacyAsciiFormatter::~legacyAsciiFormatter()
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::foamVtkOutput::outputOptions&
Foam::foamVtkOutput::legacyAsciiFormatter::opts() const
{
return opts_;
}
const char* Foam::foamVtkOutput::legacyAsciiFormatter::name() const
{
return legacyName_;

View File

@ -56,6 +56,10 @@ class legacyAsciiFormatter
// Private Data Members
static const char* legacyName_;
static const outputOptions opts_;
// Private Member Functions
//- Disallow default bitwise copy construct
legacyAsciiFormatter(const legacyAsciiFormatter&) = delete;
@ -81,11 +85,8 @@ public:
// Member Functions
//- The output formatType is LEGACY_ASCII.
virtual enum formatType format() const
{
return formatType::LEGACY_ASCII;
}
//- The output is LEGACY_ASCII.
virtual const outputOptions& opts() const;
//- Name for the legacy ascii output type ("ASCII")
virtual const char* name() const;

View File

@ -24,12 +24,16 @@ License
\*---------------------------------------------------------------------------*/
#include "foamVtkLegacyRawFormatter.H"
#include "foamVtkOutputOptions.H"
#include "endian.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const char* Foam::foamVtkOutput::legacyRawFormatter::legacyName_ = "BINARY";
const Foam::foamVtkOutput::outputOptions
Foam::foamVtkOutput::legacyRawFormatter::opts_(formatType::LEGACY_BINARY);
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
@ -62,6 +66,13 @@ Foam::foamVtkOutput::legacyRawFormatter::~legacyRawFormatter()
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::foamVtkOutput::outputOptions&
Foam::foamVtkOutput::legacyRawFormatter::opts() const
{
return opts_;
}
const char* Foam::foamVtkOutput::legacyRawFormatter::name() const
{
return legacyName_;

View File

@ -58,6 +58,7 @@ class legacyRawFormatter
// Private Data Members
static const char* legacyName_;
static const outputOptions opts_;
// Private Member Functions
@ -91,11 +92,8 @@ public:
// Member Functions
//- The output formatType is LEGACY_BINARY.
virtual enum formatType format() const
{
return formatType::LEGACY_BINARY;
}
//- The output is LEGACY_BINARY.
virtual const outputOptions& opts() const;
//- Name for the legacy binary output type ("BINARY")
virtual const char* name() const;

View File

@ -70,27 +70,27 @@ Foam::foamVtkOutput::newFormatter
switch (fmtType)
{
case INLINE_ASCII:
case formatType::INLINE_ASCII:
fmt.set(new foamVtkOutput::asciiFormatter(os, prec));
break;
case INLINE_BASE64:
case formatType::INLINE_BASE64:
fmt.set(new foamVtkOutput::base64Formatter(os));
break;
case APPEND_BASE64:
case formatType::APPEND_BASE64:
fmt.set(new foamVtkOutput::appendBase64Formatter(os));
break;
case APPEND_BINARY:
case formatType::APPEND_BINARY:
fmt.set(new foamVtkOutput::appendRawFormatter(os));
break;
case LEGACY_ASCII:
case formatType::LEGACY_ASCII:
fmt.set(new foamVtkOutput::legacyAsciiFormatter(os, prec));
break;
case LEGACY_BINARY:
case formatType::LEGACY_BINARY:
fmt.set(new foamVtkOutput::legacyRawFormatter(os));
break;
}

View File

@ -70,7 +70,6 @@ namespace foamVtkOutput
//- Return a default asciiFormatter
autoPtr<foamVtkOutput::formatter> newFormatter(std::ostream& os);
//- Return a new formatter based on the specified format type
autoPtr<foamVtkOutput::formatter> newFormatter
(

View File

@ -35,20 +35,40 @@ Foam::foamVtkOutput::outputOptions::ascii(bool on)
{
switch (fmtType_)
{
case INLINE_BASE64: fmtType_ = INLINE_ASCII; break;
case APPEND_BINARY: fmtType_ = APPEND_BASE64; break;
case LEGACY_BINARY: fmtType_ = LEGACY_ASCII; break;
default: break; // no change
case formatType::INLINE_BASE64:
fmtType_ = formatType::INLINE_ASCII;
break;
case formatType::APPEND_BINARY:
fmtType_ = formatType::APPEND_BASE64;
break;
case formatType::LEGACY_BINARY:
fmtType_ = formatType::LEGACY_ASCII;
break;
default: // No change
break;
}
}
else
{
switch (fmtType_)
{
case INLINE_ASCII: fmtType_ = INLINE_BASE64; break;
case APPEND_BASE64: fmtType_ = APPEND_BINARY; break;
case LEGACY_ASCII: fmtType_ = LEGACY_BINARY; break;
default: break; // no change
case formatType::INLINE_ASCII:
fmtType_ = formatType::INLINE_BASE64;
break;
case formatType::APPEND_BASE64:
fmtType_ = formatType::APPEND_BINARY;
break;
case formatType::LEGACY_ASCII:
fmtType_ = formatType::LEGACY_BINARY;
break;
default: // No change
break;
}
}
@ -63,20 +83,34 @@ Foam::foamVtkOutput::outputOptions::append(bool on)
{
switch (fmtType_)
{
case INLINE_ASCII: fmtType_ = APPEND_BASE64; break;
case LEGACY_ASCII: fmtType_ = APPEND_BASE64; break;
case INLINE_BASE64: fmtType_ = APPEND_BINARY; break;
case LEGACY_BINARY: fmtType_ = APPEND_BINARY; break;
default: break; // no change
case formatType::INLINE_ASCII:
case formatType::LEGACY_ASCII:
fmtType_ = formatType::APPEND_BASE64;
break;
case formatType::INLINE_BASE64:
case formatType::LEGACY_BINARY:
fmtType_ = formatType::APPEND_BINARY;
break;
default: // No change
break;
}
}
else
{
switch (fmtType_)
{
case APPEND_BASE64: fmtType_ = INLINE_ASCII; break;
case APPEND_BINARY: fmtType_ = INLINE_BASE64; break;
default: break; // no change
case formatType::APPEND_BASE64:
fmtType_ = formatType::INLINE_ASCII;
break;
case formatType::APPEND_BINARY:
fmtType_ = formatType::INLINE_BASE64;
break;
default: // No change
break;
}
}
@ -91,20 +125,34 @@ Foam::foamVtkOutput::outputOptions::legacy(bool on)
{
switch (fmtType_)
{
case INLINE_ASCII: fmtType_ = LEGACY_ASCII; break;
case INLINE_BASE64: fmtType_ = LEGACY_BINARY; break;
case APPEND_BASE64: fmtType_ = LEGACY_ASCII; break;
case APPEND_BINARY: fmtType_ = LEGACY_BINARY; break;
default: break; // no change
case formatType::INLINE_ASCII:
case formatType::APPEND_BASE64:
fmtType_ = formatType::LEGACY_ASCII;
break;
case formatType::INLINE_BASE64:
case formatType::APPEND_BINARY:
fmtType_ = formatType::LEGACY_BINARY;
break;
default: // no change
break;
}
}
else
{
switch (fmtType_)
{
case LEGACY_ASCII: fmtType_ = INLINE_ASCII; break;
case LEGACY_BINARY: fmtType_ = INLINE_BASE64; break;
default: break; // no change
case formatType::LEGACY_ASCII:
fmtType_ = formatType::INLINE_ASCII;
break;
case formatType::LEGACY_BINARY:
fmtType_ = formatType::INLINE_BASE64;
break;
default: // no change
break;
}
}
@ -112,16 +160,24 @@ Foam::foamVtkOutput::outputOptions::legacy(bool on)
}
Foam::foamVtkOutput::outputOptions&
Foam::foamVtkOutput::outputOptions::precision(unsigned prec)
{
precision_ = prec;
return *this;
}
Foam::string Foam::foamVtkOutput::outputOptions::description() const
{
switch (fmtType_)
{
case INLINE_ASCII: return "xml ascii";
case INLINE_BASE64: return "xml base64";
case APPEND_BASE64: return "xml-append base64";
case APPEND_BINARY: return "xml-append binary";
case LEGACY_ASCII: return "legacy ascii";
case LEGACY_BINARY: return "legacy binary";
case formatType::INLINE_ASCII: return "xml ascii";
case formatType::INLINE_BASE64: return "xml base64";
case formatType::APPEND_BASE64: return "xml-append base64";
case formatType::APPEND_BINARY: return "xml-append binary";
case formatType::LEGACY_ASCII: return "legacy ascii";
case formatType::LEGACY_BINARY: return "legacy binary";
}
return "";

View File

@ -28,6 +28,9 @@ Description
Encapsulated combinations of output format options.
This is primarily useful when defining the output type based on some
command-line arguments or dictionary contents.
However, it can also be a useful alternative to using the underlying
enumeration directly, since this class provides additional methods
not possible with an enum.
SourceFiles
foamVtkOutputOptions.C
@ -53,8 +56,6 @@ namespace foamVtkOutput
class outputOptions
{
private:
// Private Member Data
//- The output style tuning
@ -64,7 +65,6 @@ private:
HEADER = 0x01 //!< Emit xml header
};
//- The output format type
formatType fmtType_;
@ -79,7 +79,8 @@ public:
//- Construct null - XML insitu ASCII format with default precision
inline outputOptions();
//- Construct with specified format
//- Construct with specified format.
// This constructor should remain non-explicit.
inline outputOptions(enum formatType fmtType);
@ -94,7 +95,7 @@ public:
// Access
//- The output format type
inline formatType format() const;
inline formatType fmt() const;
//- True if writer uses legacy file format
inline bool legacy() const;
@ -111,6 +112,9 @@ public:
//- True if output format is ASCII
inline bool ascii() const;
//- Return the ASCII write precision
inline unsigned precision() const;
// Edit
@ -131,12 +135,12 @@ public:
//- Set the write precision to be used for new ASCII formatters
// \return outputOptions for chaining
inline const outputOptions& precision(unsigned prec) const;
outputOptions& precision(unsigned prec);
// Other
//- Report description about the option selected
//- A text description about the output option selected
string description() const;
};

View File

@ -23,12 +23,14 @@ License
\*---------------------------------------------------------------------------*/
#include "foamVtkOutput.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::foamVtkOutput::outputOptions::outputOptions()
:
fmtType_(INLINE_ASCII),
fmtType_(formatType::INLINE_ASCII),
precision_(IOstream::defaultPrecision())
{}
@ -55,7 +57,7 @@ Foam::foamVtkOutput::outputOptions::newFormatter(std::ostream& os) const
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
inline Foam::foamVtkOutput::formatType
Foam::foamVtkOutput::outputOptions::format() const
Foam::foamVtkOutput::outputOptions::fmt() const
{
return fmtType_;
}
@ -63,7 +65,11 @@ Foam::foamVtkOutput::outputOptions::format() const
inline bool Foam::foamVtkOutput::outputOptions::legacy() const
{
return (fmtType_ & formatType::LEGACY_ASCII & formatType::LEGACY_BINARY);
return
(
fmtType_ == formatType::LEGACY_ASCII
|| fmtType_ == formatType::LEGACY_BINARY
);
}
@ -75,7 +81,11 @@ inline bool Foam::foamVtkOutput::outputOptions::xml() const
inline bool Foam::foamVtkOutput::outputOptions::append() const
{
return (fmtType_ & formatType::APPEND_BASE64 & formatType::APPEND_BINARY);
return
(
fmtType_ == formatType::APPEND_BASE64
|| fmtType_ == formatType::APPEND_BINARY
);
}
@ -87,15 +97,13 @@ inline bool Foam::foamVtkOutput::outputOptions::insitu() const
inline bool Foam::foamVtkOutput::outputOptions::ascii() const
{
return !(fmtType_ & 0xF);
return !(unsigned(fmtType_) & 0x0F);
}
inline const Foam::foamVtkOutput::outputOptions&
Foam::foamVtkOutput::outputOptions::precision(unsigned prec) const
inline unsigned Foam::foamVtkOutput::outputOptions::precision() const
{
precision_ = prec;
return *this;
return precision_;
}

View File

@ -48,7 +48,7 @@ namespace foamVtkOutput
//- The output format type for file contents.
// Upper bits for output type, lower bits for the format itself.
enum formatType
enum class formatType
{
/** XML inline ASCII, using the asciiFormatter */
INLINE_ASCII = 0,

View File

@ -106,12 +106,11 @@ bool Foam::functionObjects::writeVTK::write()
}
// Create file and write header
fileName outputName
const fileName outputName
(
fvPath/vtkName
+ "_"
+ timeDesc
+ ".vtk"
);
Info<< " Internal : " << outputName << endl;
@ -127,9 +126,9 @@ bool Foam::functionObjects::writeVTK::write()
foamVtkOutput::internalWriter writer
(
mesh_,
foamVtkOutput::LEGACY_ASCII,
foamVtkMeshCells,
outputName
outputName,
foamVtkOutput::formatType::LEGACY_ASCII
);

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());
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());
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());
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
);