ENH: pass through format options from sampledSurface to proxy writers

- preliminary work to #1057

- add dictionary selectable format (ascii|binary) to
  VTKsurfaceFormat, VTPsurfaceFormat
This commit is contained in:
Mark Olesen
2018-11-01 14:09:53 +00:00
parent 30dcac006f
commit 3366a16b35
29 changed files with 247 additions and 222 deletions

View File

@ -53,7 +53,13 @@ Description
// Output surface format // Output surface format
surfaceFormat vtk; surfaceFormat vtk;
formatOptions { } formatOptions
{
vtk
{
precision 10;
}
}
surfaces surfaces
( (

View File

@ -45,6 +45,18 @@ Foam::proxySurfaceWriter::proxySurfaceWriter(const word& fileExt)
{} {}
Foam::proxySurfaceWriter::proxySurfaceWriter
(
const word& fileExt,
const dictionary& options
)
:
surfaceWriter(),
fileExtension_(fileExt),
options_(options)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::fileName Foam::proxySurfaceWriter::write Foam::fileName Foam::proxySurfaceWriter::write
@ -73,8 +85,16 @@ Foam::fileName Foam::proxySurfaceWriter::write
Info<< "Writing geometry to " << outputFile << endl; Info<< "Writing geometry to " << outputFile << endl;
} }
MeshedSurfaceProxy<face>(surf.points(), surf.faces()) MeshedSurfaceProxy<face>
.write(outputFile, fileExtension_); (
surf.points(),
surf.faces()
).write
(
outputFile,
fileExtension_,
options_
);
return outputFile; return outputFile;
} }

View File

@ -40,6 +40,9 @@ Description
`-- surfaceName.{obj|stl|..} `-- surfaceName.{obj|stl|..}
\endverbatim \endverbatim
Note
The formatOptions for proxy are file-type dependent.
SourceFiles SourceFiles
proxySurfaceWriter.C proxySurfaceWriter.C
@ -63,12 +66,14 @@ class proxySurfaceWriter
: :
public surfaceWriter public surfaceWriter
{ {
// Private data // Private data
//- The file extension associated with the proxy //- The file extension associated with the proxy
word fileExtension_; word fileExtension_;
//- Format options
dictionary options_;
public: public:
@ -79,7 +84,10 @@ public:
// Constructors // Constructors
//- Construct for a given extension //- Construct for a given extension
proxySurfaceWriter(const word& fileExt); explicit proxySurfaceWriter(const word& fileExt);
//- Construct for a given extension, with some output options
proxySurfaceWriter(const word& fileExt, const dictionary& options);
//- Destructor //- Destructor

View File

@ -54,19 +54,18 @@ namespace Foam
Foam::autoPtr<Foam::surfaceWriter> Foam::autoPtr<Foam::surfaceWriter>
Foam::surfaceWriter::New(const word& writeType) Foam::surfaceWriter::New(const word& writeType)
{ {
auto cstrIter = wordConstructorTablePtr_->cfind(writeType); const auto cstrIter = wordConstructorTablePtr_->cfind(writeType);
if (!cstrIter.found()) if (cstrIter.found())
{ {
if (MeshedSurfaceProxy<face>::canWriteType(writeType)) return autoPtr<surfaceWriter>(cstrIter()());
}
else if (MeshedSurfaceProxy<face>::canWriteType(writeType))
{ {
// generally unknown, but can be written via MeshedSurfaceProxy // Unknown, but proxy handler can manage it
// use 'proxy' handler instead
return autoPtr<surfaceWriter>(new proxySurfaceWriter(writeType)); return autoPtr<surfaceWriter>(new proxySurfaceWriter(writeType));
} }
if (!cstrIter.found())
{
FatalErrorInFunction FatalErrorInFunction
<< "Unknown write type \"" << writeType << "\"\n\n" << "Unknown write type \"" << writeType << "\"\n\n"
<< "Valid types : " << "Valid types : "
@ -74,26 +73,51 @@ Foam::surfaceWriter::New(const word& writeType)
<< "Valid proxy types : " << "Valid proxy types : "
<< MeshedSurfaceProxy<face>::writeTypes() << endl << MeshedSurfaceProxy<face>::writeTypes() << endl
<< exit(FatalError); << exit(FatalError);
}
}
return autoPtr<surfaceWriter>(cstrIter()()); return nullptr;
} }
Foam::autoPtr<Foam::surfaceWriter> Foam::autoPtr<Foam::surfaceWriter>
Foam::surfaceWriter::New(const word& writeType, const dictionary& options) Foam::surfaceWriter::New(const word& writeType, const dictionary& options)
{ {
// Constructors with dictionary options
auto cstrIter = wordDictConstructorTablePtr_->cfind(writeType);
if (!cstrIter.found())
{ {
// Revert to version without options // Constructor with options (dictionary)
return Foam::surfaceWriter::New(writeType); const auto cstrIter = wordDictConstructorTablePtr_->cfind(writeType);
if (cstrIter.found())
{
return autoPtr<surfaceWriter>(cstrIter()(options));
}
} }
return autoPtr<surfaceWriter>(cstrIter()(options));
// Drop through to version without options
const auto cstrIter = wordConstructorTablePtr_->cfind(writeType);
if (cstrIter.found())
{
return autoPtr<surfaceWriter>(cstrIter()());
}
else if (MeshedSurfaceProxy<face>::canWriteType(writeType))
{
// Unknown, but proxy handler can manage it
return autoPtr<surfaceWriter>
(
new proxySurfaceWriter(writeType, options)
);
}
FatalErrorInFunction
<< "Unknown write type \"" << writeType << "\"\n\n"
<< "Valid types : "
<< wordConstructorTablePtr_->sortedToc() << nl
<< "Valid proxy types : "
<< MeshedSurfaceProxy<face>::writeTypes() << endl
<< exit(FatalError);
return nullptr;
} }

View File

@ -142,7 +142,7 @@ public:
vtkSurfaceWriter(); vtkSurfaceWriter();
//- Construct with some output options //- Construct with some output options
vtkSurfaceWriter(const dictionary& options); explicit vtkSurfaceWriter(const dictionary& options);
//- Destructor //- Destructor

View File

@ -51,7 +51,7 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declaration of friend functions and operators // Forward declarations
template<class Face> class MeshedSurface; template<class Face> class MeshedSurface;

View File

@ -64,15 +64,6 @@ class AC3DsurfaceFormat
public MeshedSurface<Face>, public MeshedSurface<Face>,
public AC3DsurfaceFormatCore public AC3DsurfaceFormatCore
{ {
// Private Member Functions
//- No copy construct
AC3DsurfaceFormat(const AC3DsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const AC3DsurfaceFormat<Face>&) = delete;
public: public:
// Constructors // Constructors
@ -109,7 +100,7 @@ public:
//- Read from file //- Read from file
virtual bool read(const fileName& filename); virtual bool read(const fileName& filename);
//- Write object //- Write surface mesh to file
virtual void write virtual void write
( (
const fileName& name, const fileName& name,

View File

@ -61,12 +61,6 @@ class FLMAsurfaceFormat
static inline void writeShell(OSstream& os, const Face& f); static inline void writeShell(OSstream& os, const Face& f);
static inline void writeType(OSstream& os, const Face& f); static inline void writeType(OSstream& os, const Face& f);
//- No copy construct
FLMAsurfaceFormat(const FLMAsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const FLMAsurfaceFormat<Face>&) = delete;
protected: protected:
@ -114,7 +108,7 @@ public:
// Member Functions // Member Functions
//- Write flma file //- Write surface mesh as flma file
virtual void write virtual void write
( (
const fileName& name, const fileName& name,
@ -136,15 +130,6 @@ class FLMAZsurfaceFormat
: :
public FLMAsurfaceFormat<Face> public FLMAsurfaceFormat<Face>
{ {
// Private Member Functions
//- No copy construct
FLMAZsurfaceFormat(const FLMAZsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const FLMAZsurfaceFormat<Face>&) = delete;
public: public:
// Constructors // Constructors
@ -170,7 +155,7 @@ public:
// Member Functions // Member Functions
//- Write flmaz file //- Write surface mesh as flmaz file
virtual void write virtual void write
( (
const fileName& name, const fileName& name,

View File

@ -30,7 +30,6 @@ License
#include "StringStream.H" #include "StringStream.H"
#include "faceTraits.H" #include "faceTraits.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Face> template<class Face>

View File

@ -64,12 +64,6 @@ class GTSsurfaceFormat
// Triangulating on-the-fly is otherwise too annoying // Triangulating on-the-fly is otherwise too annoying
static bool checkIfTriangulated(const UList<Face>& faceLst); static bool checkIfTriangulated(const UList<Face>& faceLst);
//- No copy construct
GTSsurfaceFormat(const GTSsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const GTSsurfaceFormat<Face>&) = delete;
public: public:
@ -107,7 +101,7 @@ public:
//- Read from file //- Read from file
virtual bool read(const fileName& filename); virtual bool read(const fileName& filename);
//- Write object //- Write surface mesh to file
virtual void write virtual void write
( (
const fileName& name, const fileName& name,

View File

@ -35,6 +35,8 @@ Description
GRID 28 10.20269-.030265-2.358-8 GRID 28 10.20269-.030265-2.358-8
\endverbatim \endverbatim
The Nastran writer uses FREE format only.
SourceFiles SourceFiles
NASsurfaceFormat.C NASsurfaceFormat.C
@ -76,12 +78,6 @@ class NASsurfaceFormat
label elementId label elementId
); );
//- No copy construct
NASsurfaceFormat(const NASsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const NASsurfaceFormat<Face>&) = delete;
public: public:
@ -108,10 +104,10 @@ public:
// Member Functions // Member Functions
//- Read from a file //- Read from file
virtual bool read(const fileName& filename); virtual bool read(const fileName& filename);
//- Write object file //- Write surface mesh to file
virtual void write virtual void write
( (
const fileName& name, const fileName& name,

View File

@ -57,15 +57,6 @@ class OBJsurfaceFormat
: :
public MeshedSurface<Face> public MeshedSurface<Face>
{ {
// Private Member Functions
//- No copy construct
OBJsurfaceFormat(const OBJsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const OBJsurfaceFormat<Face>&) = delete;
public: public:
// Constructors // Constructors
@ -94,7 +85,7 @@ public:
//- Read from file //- Read from file
virtual bool read(const fileName& filename); virtual bool read(const fileName& filename);
//- Write object file //- Write surface mesh to file
virtual void write virtual void write
( (
const fileName& name, const fileName& name,

View File

@ -64,15 +64,6 @@ class OFFsurfaceFormat
: :
public MeshedSurface<Face> public MeshedSurface<Face>
{ {
// Private Member Functions
//- No copy construct
OFFsurfaceFormat(const OFFsurfaceFormat&) = delete;
//- No copy assignment
void operator=(const OFFsurfaceFormat&) = delete;
public: public:
// Constructors // Constructors
@ -101,7 +92,7 @@ public:
//- Read from file //- Read from file
virtual bool read(const fileName& filename); virtual bool read(const fileName& filename);
//- Write object //- Write surface mesh to file
virtual void write virtual void write
( (
const fileName& name, const fileName& name,

View File

@ -61,15 +61,6 @@ class SMESHsurfaceFormat
: :
public MeshedSurface<Face> public MeshedSurface<Face>
{ {
// Private Member Functions
//- No copy construct
SMESHsurfaceFormat(const SMESHsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const SMESHsurfaceFormat<Face>&) = delete;
public: public:
// Constructors // Constructors
@ -95,7 +86,7 @@ public:
// Member Functions // Member Functions
//- Write object //- Write surface mesh to file
virtual void write virtual void write
( (
const fileName& name, const fileName& name,

View File

@ -73,12 +73,6 @@ class STARCDsurfaceFormat
const label cellTableId const label cellTableId
); );
//- No copy construct
STARCDsurfaceFormat(const STARCDsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const STARCDsurfaceFormat<Face>&) = delete;
public: public:
@ -108,7 +102,7 @@ public:
//- Read from file //- Read from file
virtual bool read(const fileName& filename); virtual bool read(const fileName& filename);
//- Write object //- Write surface mesh to file
virtual void write virtual void write
( (
const fileName& name, const fileName& name,

View File

@ -82,13 +82,6 @@ class STLsurfaceFormat
); );
//- No copy construct
STLsurfaceFormat(const STLsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const STLsurfaceFormat<Face>&) = delete;
public: public:
// Constructors // Constructors
@ -174,7 +167,7 @@ public:
//- Read from file //- Read from file
virtual bool read(const fileName& filename); virtual bool read(const fileName& filename);
//- Write object //- Write surface mesh to file
virtual void write virtual void write
( (
const fileName& name, const fileName& name,

View File

@ -78,12 +78,6 @@ class TRIReader
bool readFile(const fileName& filename); bool readFile(const fileName& filename);
//- No copy construct
TRIReader(const TRIReader&) = delete;
//- No copy assignment
TRIReader& operator=(const TRIReader&) = delete;
public: public:

View File

@ -69,12 +69,6 @@ class TRIsurfaceFormat
const label zoneI const label zoneI
); );
//- No copy construct
TRIsurfaceFormat(const TRIsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const TRIsurfaceFormat<Face>&) = delete;
public: public:
@ -98,8 +92,7 @@ public:
const dictionary& options = dictionary::null const dictionary& options = dictionary::null
); );
//- Write UnsortedMeshedSurface, //- Write UnsortedMeshedSurface, the output remains unsorted
// by default the output is not sorted by zones
static void write static void write
( (
const fileName& filename, const fileName& filename,
@ -113,7 +106,7 @@ public:
//- Read from file //- Read from file
virtual bool read(const fileName& filename); virtual bool read(const fileName& filename);
//- Write object //- Write surface mesh to file
virtual void write virtual void write
( (
const fileName& name, const fileName& name,

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -27,20 +27,7 @@ License
#include "vtkUnstructuredReader.H" #include "vtkUnstructuredReader.H"
#include "scalarIOField.H" #include "scalarIOField.H"
#include "faceTraits.H" #include "faceTraits.H"
#include "OFstream.H" #include <fstream>
#include "foamVtkOutput.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// File-scope constant.
//
// TODO: make this run-time selectable (ASCII | BINARY)
// - Legacy mode only
static const Foam::vtk::formatType fmtType =
Foam::vtk::formatType::LEGACY_ASCII;
// Foam::vtk::formatType::LEGACY_BINARY;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -278,10 +265,11 @@ void Foam::fileFormats::VTKsurfaceFormat<Face>::write
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
std::ofstream os(filename); vtk::outputOptions opts = formatOptions(options);
autoPtr<vtk::formatter> format = std::ofstream os(filename, std::ios::binary);
vtk::newFormatter(os, fmtType);
autoPtr<vtk::formatter> format = opts.newFormatter(os);
writeHeader(format(), pointLst); writeHeader(format(), pointLst);
@ -337,10 +325,11 @@ void Foam::fileFormats::VTKsurfaceFormat<Face>::write
const dictionary& options const dictionary& options
) )
{ {
std::ofstream os(filename); vtk::outputOptions opts = formatOptions(options);
autoPtr<vtk::formatter> format = std::ofstream os(filename, std::ios::binary);
vtk::newFormatter(os, fmtType);
autoPtr<vtk::formatter> format = opts.newFormatter(os);
writeHeader(format(), surf.points()); writeHeader(format(), surf.points());

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -29,6 +29,13 @@ Description
The output is never sorted by zone. The output is never sorted by zone.
\heading Output Options
\table
Property | Description | Required | Default
format | ascii or binary format | no | ascii
precision | Write precision in ascii | no | same as IOstream
\endtable
SourceFiles SourceFiles
VTKsurfaceFormat.C VTKsurfaceFormat.C
@ -69,13 +76,6 @@ class VTKsurfaceFormat
); );
//- No copy construct
VTKsurfaceFormat(const VTKsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const VTKsurfaceFormat<Face>&) = delete;
public: public:
// Constructors // Constructors
@ -112,7 +112,7 @@ public:
//- Read from file //- Read from file
virtual bool read(const fileName& filename); virtual bool read(const fileName& filename);
//- Write object file //- Write meshed surface to file
virtual void write virtual void write
( (
const fileName& name, const fileName& name,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -25,10 +25,38 @@ License
#include "VTKsurfaceFormatCore.H" #include "VTKsurfaceFormatCore.H"
#include "clock.H" #include "clock.H"
#include "foamVtkOutput.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
Foam::vtk::outputOptions
Foam::fileFormats::VTKsurfaceFormatCore::formatOptions
(
const dictionary& dict,
vtk::outputOptions opts
)
{
opts.legacy(true); // Legacy. Use VTPsurfaceFormat for non-legacy
opts.append(false); // No append format for legacy
const word formatName = dict.lookupOrDefault<word>("format", "");
if (formatName.size())
{
opts.ascii(IOstream::formatEnum(formatName) == IOstream::ASCII);
}
opts.precision
(
dict.lookupOrDefault
(
"precision",
IOstream::defaultPrecision()
)
);
return opts;
}
void Foam::fileFormats::VTKsurfaceFormatCore::writeHeader void Foam::fileFormats::VTKsurfaceFormatCore::writeHeader
( (
vtk::formatter& format, vtk::formatter& format,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -26,6 +26,14 @@ Class
Description Description
Internal class used by the VTKsurfaceFormat Internal class used by the VTKsurfaceFormat
Format is LEGACY_ASCII
\heading Output Options
\table
Property | Description | Required | Default
format | ascii or binary format | no | ascii
precision | Write precision in ascii | no | same as IOstream
\endtable
SourceFiles SourceFiles
VTKsurfaceFormatCore.C VTKsurfaceFormatCore.C
@ -35,9 +43,9 @@ SourceFiles
#ifndef VTKsurfaceFormatCore_H #ifndef VTKsurfaceFormatCore_H
#define VTKsurfaceFormatCore_H #define VTKsurfaceFormatCore_H
#include "foamVtkFormatter.H"
#include "point.H" #include "point.H"
#include "surfZone.H" #include "surfZone.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -56,6 +64,13 @@ protected:
// Protected Static Member Functions // Protected Static Member Functions
//- Extract format options (default format LEGACY_ASCII)
static vtk::outputOptions formatOptions
(
const dictionary& dict,
vtk::outputOptions opts = vtk::formatType::LEGACY_ASCII
);
//- Write header information with points //- Write header information with points
static void writeHeader static void writeHeader
( (
@ -76,7 +91,6 @@ protected:
vtk::formatter& format, vtk::formatter& format,
const labelUList& zoneIds const labelUList& zoneIds
); );
}; };

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -24,21 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "VTPsurfaceFormat.H" #include "VTPsurfaceFormat.H"
#include "OFstream.H" #include <fstream>
#include "foamVtkOutput.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// File-scope constant.
//
// TODO: make this run-time selectable
// - No append mode supported
// - Legacy mode is dispatched via 'VTKsurfaceFormat' instead
static const Foam::vtk::formatType fmtType =
Foam::vtk::formatType::INLINE_ASCII;
// Foam::vtk::formatType::INLINE_BASE64;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -127,10 +113,11 @@ void Foam::fileFormats::VTPsurfaceFormat<Face>::write
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
vtk::outputOptions opts = formatOptions(options);
std::ofstream os(filename, std::ios::binary); std::ofstream os(filename, std::ios::binary);
autoPtr<vtk::formatter> format = autoPtr<vtk::formatter> format = opts.newFormatter(os);
vtk::newFormatter(os, fmtType);
writeHeader(format(), pointLst, faceLst.size()); writeHeader(format(), pointLst, faceLst.size());
@ -224,10 +211,11 @@ void Foam::fileFormats::VTPsurfaceFormat<Face>::write
const dictionary& options const dictionary& options
) )
{ {
vtk::outputOptions opts = formatOptions(options);
std::ofstream os(filename, std::ios::binary); std::ofstream os(filename, std::ios::binary);
autoPtr<vtk::formatter> format = autoPtr<vtk::formatter> format = opts.newFormatter(os);
vtk::newFormatter(os, fmtType);
const UList<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -26,9 +26,17 @@ Class
Description Description
Write surfaces in VTP (xml) format. Write surfaces in VTP (xml) format.
The default format is INLINE_BASE64
The output is never sorted by zone. The output is never sorted by zone.
\heading Output Options
\table
Property | Description | Required | Default
format | ascii or binary format | no | binary
precision | Write precision in ascii | no | same as IOstream
\endtable
SourceFiles SourceFiles
VTPsurfaceFormat.C VTPsurfaceFormat.C
@ -69,13 +77,6 @@ class VTPsurfaceFormat
); );
//- No copy construct
VTPsurfaceFormat(const VTPsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const VTPsurfaceFormat<Face>&) = delete;
public: public:
// Constructors // Constructors
@ -109,7 +110,7 @@ public:
// Member Functions // Member Functions
//- Write object file //- Write meshed surface to a file
virtual void write virtual void write
( (
const fileName& name, const fileName& name,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -25,10 +25,38 @@ License
#include "VTPsurfaceFormatCore.H" #include "VTPsurfaceFormatCore.H"
#include "clock.H" #include "clock.H"
#include "foamVtkOutput.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
Foam::vtk::outputOptions
Foam::fileFormats::VTPsurfaceFormatCore::formatOptions
(
const dictionary& dict,
vtk::outputOptions opts
)
{
opts.legacy(false); // Non-legacy. Use VTKsurfaceFormat for legacy
opts.append(false); // No append format
const word formatName = dict.lookupOrDefault<word>("format", "");
if (formatName.size())
{
opts.ascii(IOstream::formatEnum(formatName) == IOstream::ASCII);
}
opts.precision
(
dict.lookupOrDefault
(
"precision",
IOstream::defaultPrecision()
)
);
return opts;
}
void Foam::fileFormats::VTPsurfaceFormatCore::writeHeader void Foam::fileFormats::VTPsurfaceFormatCore::writeHeader
( (
vtk::formatter& format, vtk::formatter& format,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -25,7 +25,15 @@ Class
Foam::fileFormats::VTPsurfaceFormatCore Foam::fileFormats::VTPsurfaceFormatCore
Description Description
Internal class used by the VTPsurfaceFormat Internal class used by the VTPsurfaceFormat.
The default format is INLINE_BASE64
\heading Output Options
\table
Property | Description | Required | Default
format | ascii or binary format | no | binary
precision | Write precision in ascii | no | same as IOstream
\endtable
SourceFiles SourceFiles
VTPsurfaceFormatCore.C VTPsurfaceFormatCore.C
@ -35,9 +43,9 @@ SourceFiles
#ifndef VTPsurfaceFormatCore_H #ifndef VTPsurfaceFormatCore_H
#define VTPsurfaceFormatCore_H #define VTPsurfaceFormatCore_H
#include "foamVtkFormatter.H"
#include "point.H" #include "point.H"
#include "surfZone.H" #include "surfZone.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -56,6 +64,13 @@ protected:
// Protected Static Member Functions // Protected Static Member Functions
//- Extract format options (default format INLINE_BASE64)
static vtk::outputOptions formatOptions
(
const dictionary& dict,
vtk::outputOptions opts = vtk::formatType::INLINE_BASE64
);
//- Write header information with points //- Write header information with points
static void writeHeader static void writeHeader
( (

View File

@ -84,9 +84,9 @@ void Foam::fileFormats::X3DsurfaceFormat<Face>::write
{ {
const Face& f = faceLst[faceMap[faceIndex++]]; const Face& f = faceLst[faceMap[faceIndex++]];
forAll(f, fp) for (const label vrti : f)
{ {
os << f[fp] << ' '; os << vrti << ' ';
} }
os << "-1\n"; os << "-1\n";
} }
@ -97,9 +97,9 @@ void Foam::fileFormats::X3DsurfaceFormat<Face>::write
{ {
const Face& f = faceLst[faceIndex++]; const Face& f = faceLst[faceIndex++];
forAll(f, fp) for (const label vrti : f)
{ {
os << f[fp] << ' '; os << vrti << ' ';
} }
os << "-1\n"; os << "-1\n";
} }
@ -110,9 +110,9 @@ void Foam::fileFormats::X3DsurfaceFormat<Face>::write
"' >\n" "' >\n"
" <Coordinate point='\n"; " <Coordinate point='\n";
for (const point& pt : pointLst) for (const point& p : pointLst)
{ {
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl; os << p.x() << ' ' << p.y() << ' ' << p.z() << nl;
} }
os << os <<

View File

@ -57,14 +57,6 @@ class X3DsurfaceFormat
public MeshedSurface<Face>, public MeshedSurface<Face>,
public X3DsurfaceFormatCore public X3DsurfaceFormatCore
{ {
// Private Member Functions
//- No copy construct
X3DsurfaceFormat(const X3DsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const X3DsurfaceFormat<Face>&) = delete;
public: public:
// Constructors // Constructors
@ -90,7 +82,7 @@ public:
// Member Functions // Member Functions
//- Write object //- Write surface mesh to file
virtual void write virtual void write
( (
const fileName& name, const fileName& name,
@ -99,7 +91,6 @@ public:
{ {
write(name, MeshedSurfaceProxy<Face>(*this), options); write(name, MeshedSurfaceProxy<Face>(*this), options);
} }
}; };

View File

@ -51,6 +51,7 @@ namespace fileFormats
class X3DsurfaceFormatCore class X3DsurfaceFormatCore
{ {
protected: protected:
// Protected Member Functions // Protected Member Functions
//- Write file header //- Write file header