diff --git a/applications/utilities/mesh/manipulation/setSet/Make/options b/applications/utilities/mesh/manipulation/setSet/Make/options index febadade7b..7c01749935 100644 --- a/applications/utilities/mesh/manipulation/setSet/Make/options +++ b/applications/utilities/mesh/manipulation/setSet/Make/options @@ -1,4 +1,5 @@ EXE_INC = \ + -I$(LIB_SRC)/fileFormats/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ $(COMP_FLAGS) diff --git a/applications/utilities/mesh/manipulation/setSet/setSet.C b/applications/utilities/mesh/manipulation/setSet/setSet.C index 361acf1222..eaa89f2fb7 100644 --- a/applications/utilities/mesh/manipulation/setSet/setSet.C +++ b/applications/utilities/mesh/manipulation/setSet/setSet.C @@ -76,7 +76,7 @@ void writeVTK ( const polyMesh& mesh, const topoSet& currentSet, - const fileName& vtkName + const fileName& vtkBaseName ) { if (isA(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(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(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 " - << endl - << endl - << "The 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 - sets to set to the source set" << endl - << " add - adds all elements from the source set" << endl - << " delete - deletes ,," << endl + << nl + << nl + << "The 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 - sets to set to the source set" << nl + << " add - adds all elements from the source set" << nl + << " delete - deletes ,," << nl << " subset - 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() diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C index 1cc6bed8ec..aff6d2d585 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C @@ -239,24 +239,32 @@ 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) { - if (!args.optionFound("ascii")) + foamVtkOutput::outputOptions opts; + { - if (sizeof(floatScalar) != 4 || sizeof(label) != 4) + opts.legacy(true); + + if (!args.optionFound("ascii")) { - WarningInFunction - << "Using ASCII rather than binary VTK format since " - << "floatScalar and/or label are not 4 bytes in size." - << nl << endl; - } - else - { - return foamVtkOutput::formatType::LEGACY_BINARY; + 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." + << nl << endl; + } + else + { + opts.ascii(false); + } } } - return foamVtkOutput::formatType::LEGACY_ASCII; + return opts; } @@ -398,10 +406,9 @@ 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 bool nearCellValue = args.optionFound("nearCellValue"); - 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) { @@ -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 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 ); diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamVtkLagrangianWriter.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamVtkLagrangianWriter.C index 123357e18d..c01cd0b9a4 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamVtkLagrangianWriter.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamVtkLagrangianWriter.C @@ -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 - foamVtkOutput::legacy::fileHeader(format(), mesh_.time().caseName()) - << "DATASET POLYDATA" << nl; + 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 diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamVtkLagrangianWriter.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamVtkLagrangianWriter.H index 8d4103c53d..1d7e5105d8 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamVtkLagrangianWriter.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamVtkLagrangianWriter.H @@ -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() diff --git a/src/conversion/vtk/output/foamVtkInternalWriter.C b/src/conversion/vtk/output/foamVtkInternalWriter.C index 7466de29e0..1a6a3163b3 100644 --- a/src/conversion/vtk/output/foamVtkInternalWriter.C +++ b/src/conversion/vtk/output/foamVtkInternalWriter.C @@ -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 - foamVtkOutput::legacy::fileHeader(format(), mesh.time().caseName()) - << "DATASET UNSTRUCTURED_GRID" << nl; + 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 * * * * * * * * * * * * * // diff --git a/src/conversion/vtk/output/foamVtkInternalWriter.H b/src/conversion/vtk/output/foamVtkInternalWriter.H index 6a6423b4ff..fc33f9d6ee 100644 --- a/src/conversion/vtk/output/foamVtkInternalWriter.H +++ b/src/conversion/vtk/output/foamVtkInternalWriter.H @@ -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() diff --git a/src/conversion/vtk/output/foamVtkPatchWriter.C b/src/conversion/vtk/output/foamVtkPatchWriter.C index b56d58e3c5..a671d35f2f 100644 --- a/src/conversion/vtk/output/foamVtkPatchWriter.C +++ b/src/conversion/vtk/output/foamVtkPatchWriter.C @@ -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,29 +41,28 @@ 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_, + if (opts.legacy()) + { + foamVtkOutput::legacy::fileHeader ( - binary - ? foamVtkOutput::LEGACY_BINARY - : foamVtkOutput::LEGACY_ASCII - ) - ); - - foamVtkOutput::legacy::fileHeader - ( - format(), - ( - patchIDs_.size() == 1 - ? patches[patchIDs_.first()].name() - : "patches" - ) - ) << "DATASET POLYDATA" << nl; + format(), + ( + patchIDs_.size() == 1 + ? patches[patchIDs_.first()].name() + : "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) diff --git a/src/conversion/vtk/output/foamVtkPatchWriter.H b/src/conversion/vtk/output/foamVtkPatchWriter.H index a43dc54910..10b73e14a9 100644 --- a/src/conversion/vtk/output/foamVtkPatchWriter.H +++ b/src/conversion/vtk/output/foamVtkPatchWriter.H @@ -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() diff --git a/src/conversion/vtk/output/foamVtkSurfaceMeshWriter.C b/src/conversion/vtk/output/foamVtkSurfaceMeshWriter.C index 810620bf11..12aab0acef 100644 --- a/src/conversion/vtk/output/foamVtkSurfaceMeshWriter.C +++ b/src/conversion/vtk/output/foamVtkSurfaceMeshWriter.C @@ -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 - foamVtkOutput::legacy::fileHeader(format(), name) - << "DATASET POLYDATA" << nl; + 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) diff --git a/src/conversion/vtk/output/foamVtkSurfaceMeshWriter.H b/src/conversion/vtk/output/foamVtkSurfaceMeshWriter.H index 7173f53e86..30a5f5de46 100644 --- a/src/conversion/vtk/output/foamVtkSurfaceMeshWriter.H +++ b/src/conversion/vtk/output/foamVtkSurfaceMeshWriter.H @@ -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() diff --git a/src/conversion/vtk/output/foamVtkWriteSurfFields.C b/src/conversion/vtk/output/foamVtkWriteSurfFields.C index 99a006a150..97d85b29f2 100644 --- a/src/conversion/vtk/output/foamVtkWriteSurfFields.C +++ b/src/conversion/vtk/output/foamVtkWriteSurfFields.C @@ -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& surfVectorFields ) { - std::ofstream os(fileName.c_str()); + outputOptions opts(outOpts); + opts.legacy(true); // Legacy only, no append - autoPtr format = foamVtkOutput::newFormatter - ( - os, - ( - binary - ? foamVtkOutput::LEGACY_BINARY - : foamVtkOutput::LEGACY_ASCII - ) - ); + std::ofstream os((baseName + (opts.legacy() ? ".vtk" : ".vtp")).c_str()); + autoPtr format = opts.newFormatter(os); - foamVtkOutput::legacy::fileHeader(format(), "surfaceFields") - << "DATASET POLYDATA" << nl; + if (opts.legacy()) + { + foamVtkOutput::legacy::fileHeader(format(), "surfaceFields") + << "DATASET POLYDATA" << nl; + } const pointField& fc = mesh.faceCentres(); diff --git a/src/conversion/vtk/output/foamVtkWriteSurfFields.H b/src/conversion/vtk/output/foamVtkWriteSurfFields.H index 9ce9f4096c..e34c11d043 100644 --- a/src/conversion/vtk/output/foamVtkWriteSurfFields.H +++ b/src/conversion/vtk/output/foamVtkWriteSurfFields.H @@ -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& surfVectorFields ); diff --git a/src/conversion/vtk/part/foamVtkCells.C b/src/conversion/vtk/part/foamVtkCells.C index b80ae51176..8b9faf7142 100644 --- a/src/conversion/vtk/part/foamVtkCells.C +++ b/src/conversion/vtk/part/foamVtkCells.C @@ -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() diff --git a/src/conversion/vtk/part/foamVtkCells.H b/src/conversion/vtk/part/foamVtkCells.H index b6704e6767..5ad70cda51 100644 --- a/src/conversion/vtk/part/foamVtkCells.H +++ b/src/conversion/vtk/part/foamVtkCells.H @@ -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(); diff --git a/src/fileFormats/sampledSetWriters/vtk/vtkSetWriter.C b/src/fileFormats/sampledSetWriters/vtk/vtkSetWriter.C index 87996eeff5..f48080f69d 100644 --- a/src/fileFormats/sampledSetWriters/vtk/vtkSetWriter.C +++ b/src/fileFormats/sampledSetWriters/vtk/vtkSetWriter.C @@ -79,7 +79,6 @@ void Foam::vtkSetWriter::write os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl; } - os << "POINT_DATA " << points.size() << nl << " FIELD attributes " << valueSetNames.size() << nl; diff --git a/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C b/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C index bacc45c1a5..f54edcabea 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C +++ b/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C @@ -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_; diff --git a/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H b/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H index 2cd289b6e4..0a0dff20e3 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H +++ b/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H @@ -56,15 +56,16 @@ class appendBase64Formatter // Private Data Members static const char* name_; + static const outputOptions opts_; // Private Member Functions - //- Disallow default bitwise copy construct - appendBase64Formatter(const appendBase64Formatter&) = delete; + //- Disallow default bitwise copy construct + appendBase64Formatter(const appendBase64Formatter&) = delete; - //- Disallow default bitwise assignment - void operator=(const appendBase64Formatter&) = delete; + //- Disallow default bitwise assignment + void operator=(const appendBase64Formatter&) = delete; public: @@ -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; diff --git a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C index cc587aae50..40effed271 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C @@ -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_; diff --git a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H index 11de7e9b64..aca458b05e 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H @@ -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; diff --git a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C index b19a3762db..7b05aafaf8 100644 --- a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C @@ -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_; diff --git a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H index 6289e0fd83..c50281779e 100644 --- a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H @@ -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; diff --git a/src/fileFormats/vtk/format/foamVtkBase64Formatter.C b/src/fileFormats/vtk/format/foamVtkBase64Formatter.C index a27d14c129..a4ebc925fe 100644 --- a/src/fileFormats/vtk/format/foamVtkBase64Formatter.C +++ b/src/fileFormats/vtk/format/foamVtkBase64Formatter.C @@ -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_; diff --git a/src/fileFormats/vtk/format/foamVtkBase64Formatter.H b/src/fileFormats/vtk/format/foamVtkBase64Formatter.H index 52f7d025f1..edf64797ed 100644 --- a/src/fileFormats/vtk/format/foamVtkBase64Formatter.H +++ b/src/fileFormats/vtk/format/foamVtkBase64Formatter.H @@ -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; diff --git a/src/fileFormats/vtk/format/foamVtkBase64Layer.H b/src/fileFormats/vtk/format/foamVtkBase64Layer.H index da541bbde2..09b978017b 100644 --- a/src/fileFormats/vtk/format/foamVtkBase64Layer.H +++ b/src/fileFormats/vtk/format/foamVtkBase64Layer.H @@ -64,6 +64,7 @@ class foamVtkBase64Layer //- Disallow default bitwise assignment void operator=(const foamVtkBase64Layer&) = delete; + protected: // Protected Member Functions diff --git a/src/fileFormats/vtk/format/foamVtkFormatter.H b/src/fileFormats/vtk/format/foamVtkFormatter.H index 1ed43fb45e..248730c726 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkFormatter.H @@ -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 formatter& openDataArray(const word& dataName); + //- Open "DataArray" XML tag + // \return formatter for chaining + template + formatter& openDataArray(const vtkFileTag& tagEnum); + //- Insert a single "PDataArray" XML entry tag. // For some entries, the name is optional. diff --git a/src/fileFormats/vtk/format/foamVtkFormatterI.H b/src/fileFormats/vtk/format/foamVtkFormatterI.H index df3a987394..39e1e5a013 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatterI.H +++ b/src/fileFormats/vtk/format/foamVtkFormatterI.H @@ -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() { diff --git a/src/fileFormats/vtk/format/foamVtkFormatterTemplates.C b/src/fileFormats/vtk/format/foamVtkFormatterTemplates.C index 1c1ec9b35f..79e3b7a239 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatterTemplates.C +++ b/src/fileFormats/vtk/format/foamVtkFormatterTemplates.C @@ -68,6 +68,17 @@ Foam::foamVtkOutput::formatter::openDataArray } +template +Foam::foamVtkOutput::formatter& +Foam::foamVtkOutput::formatter::openDataArray +( + const vtkFileTag& tagEnum +) +{ + return openDataArray(vtkFileTagNames[tagEnum]); +} + + template Foam::foamVtkOutput::formatter& Foam::foamVtkOutput::formatter::PDataArray diff --git a/src/fileFormats/vtk/format/foamVtkLegacyAsciiFormatter.C b/src/fileFormats/vtk/format/foamVtkLegacyAsciiFormatter.C index 226ee3a48f..4e31fc46af 100644 --- a/src/fileFormats/vtk/format/foamVtkLegacyAsciiFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkLegacyAsciiFormatter.C @@ -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_; diff --git a/src/fileFormats/vtk/format/foamVtkLegacyAsciiFormatter.H b/src/fileFormats/vtk/format/foamVtkLegacyAsciiFormatter.H index 248c848cc1..cb764b2992 100644 --- a/src/fileFormats/vtk/format/foamVtkLegacyAsciiFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkLegacyAsciiFormatter.H @@ -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; diff --git a/src/fileFormats/vtk/format/foamVtkLegacyRawFormatter.C b/src/fileFormats/vtk/format/foamVtkLegacyRawFormatter.C index 733d7a4ab0..b533d0c56e 100644 --- a/src/fileFormats/vtk/format/foamVtkLegacyRawFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkLegacyRawFormatter.C @@ -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_; diff --git a/src/fileFormats/vtk/format/foamVtkLegacyRawFormatter.H b/src/fileFormats/vtk/format/foamVtkLegacyRawFormatter.H index 47717a598b..2b558fc977 100644 --- a/src/fileFormats/vtk/format/foamVtkLegacyRawFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkLegacyRawFormatter.H @@ -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; diff --git a/src/fileFormats/vtk/output/foamVtkOutput.C b/src/fileFormats/vtk/output/foamVtkOutput.C index 1e66e1cfcc..7c2385c07a 100644 --- a/src/fileFormats/vtk/output/foamVtkOutput.C +++ b/src/fileFormats/vtk/output/foamVtkOutput.C @@ -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; } diff --git a/src/fileFormats/vtk/output/foamVtkOutput.H b/src/fileFormats/vtk/output/foamVtkOutput.H index 7c04be9b9d..5be62c87c9 100644 --- a/src/fileFormats/vtk/output/foamVtkOutput.H +++ b/src/fileFormats/vtk/output/foamVtkOutput.H @@ -70,7 +70,6 @@ namespace foamVtkOutput //- Return a default asciiFormatter autoPtr newFormatter(std::ostream& os); - //- Return a new formatter based on the specified format type autoPtr newFormatter ( diff --git a/src/fileFormats/vtk/output/foamVtkOutputOptions.C b/src/fileFormats/vtk/output/foamVtkOutputOptions.C index 232ea5f0ab..d58cf3849b 100644 --- a/src/fileFormats/vtk/output/foamVtkOutputOptions.C +++ b/src/fileFormats/vtk/output/foamVtkOutputOptions.C @@ -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 ""; diff --git a/src/fileFormats/vtk/output/foamVtkOutputOptions.H b/src/fileFormats/vtk/output/foamVtkOutputOptions.H index 826dc75128..c93dbd5f1f 100644 --- a/src/fileFormats/vtk/output/foamVtkOutputOptions.H +++ b/src/fileFormats/vtk/output/foamVtkOutputOptions.H @@ -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; }; diff --git a/src/fileFormats/vtk/output/foamVtkOutputOptionsI.H b/src/fileFormats/vtk/output/foamVtkOutputOptionsI.H index f4a0aafcff..7d398ee7ea 100644 --- a/src/fileFormats/vtk/output/foamVtkOutputOptionsI.H +++ b/src/fileFormats/vtk/output/foamVtkOutputOptionsI.H @@ -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_; } diff --git a/src/fileFormats/vtk/type/foamVtkOutputTypes.H b/src/fileFormats/vtk/type/foamVtkOutputTypes.H index d4dbe0d5c8..3eab6006f8 100644 --- a/src/fileFormats/vtk/type/foamVtkOutputTypes.H +++ b/src/fileFormats/vtk/type/foamVtkOutputTypes.H @@ -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, diff --git a/src/functionObjects/utilities/writeVTK/writeVTK.C b/src/functionObjects/utilities/writeVTK/writeVTK.C index 2b7c58dca8..2fe616effd 100644 --- a/src/functionObjects/utilities/writeVTK/writeVTK.C +++ b/src/functionObjects/utilities/writeVTK/writeVTK.C @@ -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 ); diff --git a/src/meshTools/output/foamVtkWriteCellSetFaces.C b/src/meshTools/output/foamVtkWriteCellSetFaces.C index 54772cf7f7..0c9c33d55d 100644 --- a/src/meshTools/output/foamVtkWriteCellSetFaces.C +++ b/src/meshTools/output/foamVtkWriteCellSetFaces.C @@ -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 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 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) diff --git a/src/meshTools/output/foamVtkWriteCellSetFaces.H b/src/meshTools/output/foamVtkWriteCellSetFaces.H index 621dbb0e06..047f4b16f8 100644 --- a/src/meshTools/output/foamVtkWriteCellSetFaces.H +++ b/src/meshTools/output/foamVtkWriteCellSetFaces.H @@ -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 diff --git a/src/meshTools/output/foamVtkWriteFaceSet.C b/src/meshTools/output/foamVtkWriteFaceSet.C index e1221177c1..8d2b4bb4f6 100644 --- a/src/meshTools/output/foamVtkWriteFaceSet.C +++ b/src/meshTools/output/foamVtkWriteFaceSet.C @@ -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 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 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 ( diff --git a/src/meshTools/output/foamVtkWriteFaceSet.H b/src/meshTools/output/foamVtkWriteFaceSet.H index c44437f03f..d709b0a681 100644 --- a/src/meshTools/output/foamVtkWriteFaceSet.H +++ b/src/meshTools/output/foamVtkWriteFaceSet.H @@ -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 ); diff --git a/src/meshTools/output/foamVtkWritePointSet.C b/src/meshTools/output/foamVtkWritePointSet.C index d58346d803..f111ac75fe 100644 --- a/src/meshTools/output/foamVtkWritePointSet.C +++ b/src/meshTools/output/foamVtkWritePointSet.C @@ -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 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 format = opts.newFormatter(os); + + if (opts.legacy()) + { + foamVtkOutput::legacy::fileHeader(format(), set.name()) + << "DATASET POLYDATA" << nl; + } //------------------------------------------------------------------------- diff --git a/src/meshTools/output/foamVtkWritePointSet.H b/src/meshTools/output/foamVtkWritePointSet.H index f06e07cb01..3ceda2914e 100644 --- a/src/meshTools/output/foamVtkWritePointSet.H +++ b/src/meshTools/output/foamVtkWritePointSet.H @@ -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 );