From d2fc2c9edcea49c9a904d22107cef1097a1fa482 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 3 Nov 2016 14:24:00 +0100 Subject: [PATCH] ENH: improved infrastructure for writing VTK content Note: classes are prefixed with 'foamVtk' instead of 'vtk' to avoid potential conflicts with VTK itself. foamVtkCore ~~~~~~~~~~~ - General very low-level functionality. foamVtkPTraits ~~~~~~~~~~~~~~ - Traits type of functionality for VTK foamVtkOutputOptions ~~~~~~~~~~~~~~~~~~~~ - The various format output options as a class that can be passed to formatters etc. foamVtkCells ~~~~~~~~~~~~ - Intended for unifying vtkTopo and PV-Reader code in the future. - Handles polyhedron decompose internally etc foamVtkOutput, foamVtkFormatter ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Output helpers. - Selector for individual formatters. Currently write all scalar data a 'float' (not 'double'). Can revisit this in the future. --- .../PVFoamReader/vtkPVFoam/Make/options | 4 +- src/conversion/Make/files | 3 + src/conversion/vtk/output/foamVtkOutput.C | 126 ++++ src/conversion/vtk/output/foamVtkOutput.H | 216 ++++++ .../vtk/output/foamVtkOutputTemplates.C | 94 +++ src/conversion/vtk/part/foamVtkCells.C | 649 ++++++++++++++++++ src/conversion/vtk/part/foamVtkCells.H | 350 ++++++++++ src/conversion/vtk/part/foamVtkCellsI.H | 239 +++++++ src/fileFormats/Make/files | 11 +- src/fileFormats/vtk/foamVtkCore.C | 54 ++ src/fileFormats/vtk/foamVtkCore.H | 109 +++ .../vtk/format/foamVtkAppendBase64Formatter.C | 65 ++ .../vtk/format/foamVtkAppendBase64Formatter.H | 99 +++ .../vtk/format/foamVtkAppendRawFormatter.C | 112 +++ .../vtk/format/foamVtkAppendRawFormatter.H | 115 ++++ .../vtk/format/foamVtkAsciiFormatter.C | 136 ++++ .../vtk/format/foamVtkAsciiFormatter.H | 120 ++++ .../vtk/format/foamVtkBase64Formatter.C | 120 ++++ .../vtk/format/foamVtkBase64Formatter.H | 116 ++++ src/fileFormats/vtk/format/foamVtkFormatter.C | 315 +++++++++ src/fileFormats/vtk/format/foamVtkFormatter.H | 233 +++++++ .../vtk/format/foamVtkFormatterTemplates.C | 70 ++ .../vtk/format/foamVtkLegacyFormatter.C | 139 ++++ .../vtk/format/foamVtkLegacyFormatter.H | 119 ++++ .../vtk/format/foamVtkOutputOptions.C | 240 +++++++ .../vtk/format/foamVtkOutputOptions.H | 156 +++++ .../vtk/format/foamVtkOutputOptionsI.H | 56 ++ .../vtk/{ => read}/vtkUnstructuredReader.C | 22 +- .../vtk/{ => read}/vtkUnstructuredReader.H | 30 +- .../vtkUnstructuredReaderTemplates.C | 2 +- src/fileFormats/vtk/type/foamVtkPTraits.C | 70 ++ src/fileFormats/vtk/type/foamVtkPTraits.H | 93 +++ 32 files changed, 4244 insertions(+), 39 deletions(-) create mode 100644 src/conversion/vtk/output/foamVtkOutput.C create mode 100644 src/conversion/vtk/output/foamVtkOutput.H create mode 100644 src/conversion/vtk/output/foamVtkOutputTemplates.C create mode 100644 src/conversion/vtk/part/foamVtkCells.C create mode 100644 src/conversion/vtk/part/foamVtkCells.H create mode 100644 src/conversion/vtk/part/foamVtkCellsI.H create mode 100644 src/fileFormats/vtk/foamVtkCore.C create mode 100644 src/fileFormats/vtk/foamVtkCore.H create mode 100644 src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C create mode 100644 src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H create mode 100644 src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C create mode 100644 src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H create mode 100644 src/fileFormats/vtk/format/foamVtkAsciiFormatter.C create mode 100644 src/fileFormats/vtk/format/foamVtkAsciiFormatter.H create mode 100644 src/fileFormats/vtk/format/foamVtkBase64Formatter.C create mode 100644 src/fileFormats/vtk/format/foamVtkBase64Formatter.H create mode 100644 src/fileFormats/vtk/format/foamVtkFormatter.C create mode 100644 src/fileFormats/vtk/format/foamVtkFormatter.H create mode 100644 src/fileFormats/vtk/format/foamVtkFormatterTemplates.C create mode 100644 src/fileFormats/vtk/format/foamVtkLegacyFormatter.C create mode 100644 src/fileFormats/vtk/format/foamVtkLegacyFormatter.H create mode 100644 src/fileFormats/vtk/format/foamVtkOutputOptions.C create mode 100644 src/fileFormats/vtk/format/foamVtkOutputOptions.H create mode 100644 src/fileFormats/vtk/format/foamVtkOutputOptionsI.H rename src/fileFormats/vtk/{ => read}/vtkUnstructuredReader.C (98%) rename src/fileFormats/vtk/{ => read}/vtkUnstructuredReader.H (90%) rename src/fileFormats/vtk/{ => read}/vtkUnstructuredReaderTemplates.C (98%) create mode 100644 src/fileFormats/vtk/type/foamVtkPTraits.C create mode 100644 src/fileFormats/vtk/type/foamVtkPTraits.H diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options index d0cdd781d7..9f63402d64 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options @@ -3,6 +3,8 @@ EXE_INC = \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/dynamicMesh/lnInclude \ -I$(LIB_SRC)/lagrangian/basic/lnInclude \ + -I$(LIB_SRC)/fileFormats/lnInclude \ + -I$(LIB_SRC)/conversion/lnInclude \ -I$(ParaView_INCLUDE_DIR) \ -I$(ParaView_INCLUDE_DIR)/vtkkwiml \ -I../../vtkPVReaders/lnInclude \ @@ -10,7 +12,7 @@ EXE_INC = \ LIB_LIBS = \ -ldynamicMesh \ - -ldynamicMesh \ + -lconversion \ -lgenericPatchFields \ -llagrangian \ -L$(FOAM_LIBBIN) -lvtkPVReaders \ diff --git a/src/conversion/Make/files b/src/conversion/Make/files index 0266423e35..3f2c0a0c98 100644 --- a/src/conversion/Make/files +++ b/src/conversion/Make/files @@ -24,4 +24,7 @@ starcd/STARCDMeshWriter.C polyDualMesh/polyDualMesh.C +vtk/part/foamVtkCells.C +vtk/output/foamVtkOutput.C + LIB = $(FOAM_LIBBIN)/libconversion diff --git a/src/conversion/vtk/output/foamVtkOutput.C b/src/conversion/vtk/output/foamVtkOutput.C new file mode 100644 index 0000000000..4ece681a85 --- /dev/null +++ b/src/conversion/vtk/output/foamVtkOutput.C @@ -0,0 +1,126 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "foamVtkOutput.H" +#include "foamVtkAsciiFormatter.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +const Foam::word Foam::foamVtkOutput::legacy::EXT = "vtk"; + + +//! \cond fileScope +static inline std::ostream& legacyDataHeader +( + std::ostream& os, + const char* tag, + const Foam::label nItems, + const Foam::label nFields +) +{ + os << tag << ' ' << nItems << '\n' + << "FIELD attributes " << nFields << '\n'; + + return os; +} +//! \endcond + + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +Foam::label Foam::foamVtkOutput::writeVtmFile +( + std::ostream& os, + const UList& files +) +{ + const word& content = "vtkMultiBlockDataSet"; + + foamVtkAsciiFormatter vtmFile(os); + + vtmFile + .xmlHeader() + .openTag("VTKFile") + ( "type", content ) + ( "version", "1.0" ) + ( "byte_order", foamVtkFormatter::byteOrder ) + ( "header_type", foamVtkFormatter::headerType ) + .closeTag(); + + vtmFile.tag(content); + + forAll(files, i) + { + vtmFile + .openTag("DataSet") + ( "index", i ) + ( "file", files[i] ) + .closeTag(true); + } + + vtmFile.endTag(content).endTag("VTKFile"); + + return files.size(); +} + + +std::ostream& Foam::foamVtkOutput::legacy::writeHeader +( + std::ostream& os, + const std::string& title, + const bool binary +) +{ + os << "# vtk DataFile Version 2.0" << nl + << title << nl + << (binary ? "BINARY" : "ASCII") << nl; + + return os; +} + + +std::ostream& Foam::foamVtkOutput::legacy::writeCellDataHeader +( + std::ostream& os, + const label nCells, + const label nFields +) +{ + return legacyDataHeader(os, "CELL_DATA", nCells, nFields); +} + + +std::ostream& Foam::foamVtkOutput::legacy::writePointDataHeader +( + std::ostream& os, + const label nPoints, + const label nFields +) +{ + return legacyDataHeader(os, "POINT_DATA", nPoints, nFields); +} + + +// ************************************************************************* // diff --git a/src/conversion/vtk/output/foamVtkOutput.H b/src/conversion/vtk/output/foamVtkOutput.H new file mode 100644 index 0000000000..ad7964bfff --- /dev/null +++ b/src/conversion/vtk/output/foamVtkOutput.H @@ -0,0 +1,216 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + foamVtkOutput + +Description + A collection of functions for writing vtk file content. + +SourceFiles + foamVtkOutput.C + foamVtkOutputTemplates.C + +\*---------------------------------------------------------------------------*/ + +#ifndef foamVtkOutput_H +#define foamVtkOutput_H + +#include "floatScalar.H" +#include "volFields.H" +#include "foamVtkFormatter.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class foamVtkOutput Declaration +\*---------------------------------------------------------------------------*/ + +class foamVtkOutput +{ + // Private Member Functions + + //- Disallow construction + foamVtkOutput() = delete; + +public: + + // Forward declarations + class legacy; + + + // Static Members + + //- Write vtm datasets for specified files + static Foam::label writeVtmFile + ( + std::ostream& os, + const UList& files + ); + + + //- Write a value component-wise. + template + inline static void write(foamVtkFormatter&, const Type&); + + + //- Write a list of values. + // The output does not include the payload size. + template + static void writeList + ( + foamVtkFormatter&, + const UList& + ); + + + //- Write a list of values via indirect addressing. + // The output does not include the payload size. + template + static void writeList + ( + foamVtkFormatter&, + const UList&, + const UList