Skip to content
Snippets Groups Projects
Commit 3366a16b authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: pass through format options from sampledSurface to proxy writers

- preliminary work to #1057

- add dictionary selectable format (ascii|binary) to
  VTKsurfaceFormat, VTPsurfaceFormat
parent 30dcac00
Branches
Tags
No related merge requests found
Showing
with 125 additions and 166 deletions
......@@ -53,7 +53,13 @@ Description
// Output surface format
surfaceFormat vtk;
formatOptions { }
formatOptions
{
vtk
{
precision 10;
}
}
surfaces
(
......
......@@ -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 * * * * * * * * * * * * * //
Foam::fileName Foam::proxySurfaceWriter::write
......@@ -73,8 +85,16 @@ Foam::fileName Foam::proxySurfaceWriter::write
Info<< "Writing geometry to " << outputFile << endl;
}
MeshedSurfaceProxy<face>(surf.points(), surf.faces())
.write(outputFile, fileExtension_);
MeshedSurfaceProxy<face>
(
surf.points(),
surf.faces()
).write
(
outputFile,
fileExtension_,
options_
);
return outputFile;
}
......
......@@ -40,6 +40,9 @@ Description
`-- surfaceName.{obj|stl|..}
\endverbatim
Note
The formatOptions for proxy are file-type dependent.
SourceFiles
proxySurfaceWriter.C
......@@ -63,12 +66,14 @@ class proxySurfaceWriter
:
public surfaceWriter
{
// Private data
//- The file extension associated with the proxy
word fileExtension_;
//- Format options
dictionary options_;
public:
......@@ -79,7 +84,10 @@ public:
// Constructors
//- 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
......
......@@ -54,46 +54,70 @@ namespace Foam
Foam::autoPtr<Foam::surfaceWriter>
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))
{
// generally unknown, but can be written via MeshedSurfaceProxy
// use 'proxy' handler instead
return autoPtr<surfaceWriter>(new proxySurfaceWriter(writeType));
}
if (!cstrIter.found())
{
FatalErrorInFunction
<< "Unknown write type \"" << writeType << "\"\n\n"
<< "Valid types : "
<< wordConstructorTablePtr_->sortedToc() << nl
<< "Valid proxy types : "
<< MeshedSurfaceProxy<face>::writeTypes() << endl
<< exit(FatalError);
}
return autoPtr<surfaceWriter>(cstrIter()());
}
else if (MeshedSurfaceProxy<face>::canWriteType(writeType))
{
// Unknown, but proxy handler can manage it
return autoPtr<surfaceWriter>(new proxySurfaceWriter(writeType));
}
FatalErrorInFunction
<< "Unknown write type \"" << writeType << "\"\n\n"
<< "Valid types : "
<< wordConstructorTablePtr_->sortedToc() << nl
<< "Valid proxy types : "
<< MeshedSurfaceProxy<face>::writeTypes() << endl
<< exit(FatalError);
return autoPtr<surfaceWriter>(cstrIter()());
return nullptr;
}
Foam::autoPtr<Foam::surfaceWriter>
Foam::surfaceWriter::New(const word& writeType, const dictionary& options)
{
// Constructors with dictionary options
auto cstrIter = wordDictConstructorTablePtr_->cfind(writeType);
{
// Constructor with options (dictionary)
const auto cstrIter = wordDictConstructorTablePtr_->cfind(writeType);
if (!cstrIter.found())
if (cstrIter.found())
{
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))
{
// Revert to version without options
return Foam::surfaceWriter::New(writeType);
// Unknown, but proxy handler can manage it
return autoPtr<surfaceWriter>
(
new proxySurfaceWriter(writeType, options)
);
}
return autoPtr<surfaceWriter>(cstrIter()(options));
FatalErrorInFunction
<< "Unknown write type \"" << writeType << "\"\n\n"
<< "Valid types : "
<< wordConstructorTablePtr_->sortedToc() << nl
<< "Valid proxy types : "
<< MeshedSurfaceProxy<face>::writeTypes() << endl
<< exit(FatalError);
return nullptr;
}
......
......@@ -142,7 +142,7 @@ public:
vtkSurfaceWriter();
//- Construct with some output options
vtkSurfaceWriter(const dictionary& options);
explicit vtkSurfaceWriter(const dictionary& options);
//- Destructor
......
......@@ -51,7 +51,7 @@ SourceFiles
namespace Foam
{
// Forward declaration of friend functions and operators
// Forward declarations
template<class Face> class MeshedSurface;
......
......@@ -64,15 +64,6 @@ class AC3DsurfaceFormat
public MeshedSurface<Face>,
public AC3DsurfaceFormatCore
{
// Private Member Functions
//- No copy construct
AC3DsurfaceFormat(const AC3DsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const AC3DsurfaceFormat<Face>&) = delete;
public:
// Constructors
......@@ -109,7 +100,7 @@ public:
//- Read from file
virtual bool read(const fileName& filename);
//- Write object
//- Write surface mesh to file
virtual void write
(
const fileName& name,
......
......@@ -61,12 +61,6 @@ class FLMAsurfaceFormat
static inline void writeShell(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:
......@@ -114,7 +108,7 @@ public:
// Member Functions
//- Write flma file
//- Write surface mesh as flma file
virtual void write
(
const fileName& name,
......@@ -136,15 +130,6 @@ class FLMAZsurfaceFormat
:
public FLMAsurfaceFormat<Face>
{
// Private Member Functions
//- No copy construct
FLMAZsurfaceFormat(const FLMAZsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const FLMAZsurfaceFormat<Face>&) = delete;
public:
// Constructors
......@@ -170,7 +155,7 @@ public:
// Member Functions
//- Write flmaz file
//- Write surface mesh as flmaz file
virtual void write
(
const fileName& name,
......
......@@ -30,7 +30,6 @@ License
#include "StringStream.H"
#include "faceTraits.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Face>
......
......@@ -64,12 +64,6 @@ class GTSsurfaceFormat
// Triangulating on-the-fly is otherwise too annoying
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:
......@@ -107,7 +101,7 @@ public:
//- Read from file
virtual bool read(const fileName& filename);
//- Write object
//- Write surface mesh to file
virtual void write
(
const fileName& name,
......
......@@ -35,6 +35,8 @@ Description
GRID 28 10.20269-.030265-2.358-8
\endverbatim
The Nastran writer uses FREE format only.
SourceFiles
NASsurfaceFormat.C
......@@ -76,12 +78,6 @@ class NASsurfaceFormat
label elementId
);
//- No copy construct
NASsurfaceFormat(const NASsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const NASsurfaceFormat<Face>&) = delete;
public:
......@@ -108,10 +104,10 @@ public:
// Member Functions
//- Read from a file
//- Read from file
virtual bool read(const fileName& filename);
//- Write object file
//- Write surface mesh to file
virtual void write
(
const fileName& name,
......
......@@ -57,15 +57,6 @@ class OBJsurfaceFormat
:
public MeshedSurface<Face>
{
// Private Member Functions
//- No copy construct
OBJsurfaceFormat(const OBJsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const OBJsurfaceFormat<Face>&) = delete;
public:
// Constructors
......@@ -94,7 +85,7 @@ public:
//- Read from file
virtual bool read(const fileName& filename);
//- Write object file
//- Write surface mesh to file
virtual void write
(
const fileName& name,
......
......@@ -64,15 +64,6 @@ class OFFsurfaceFormat
:
public MeshedSurface<Face>
{
// Private Member Functions
//- No copy construct
OFFsurfaceFormat(const OFFsurfaceFormat&) = delete;
//- No copy assignment
void operator=(const OFFsurfaceFormat&) = delete;
public:
// Constructors
......@@ -101,7 +92,7 @@ public:
//- Read from file
virtual bool read(const fileName& filename);
//- Write object
//- Write surface mesh to file
virtual void write
(
const fileName& name,
......
......@@ -61,15 +61,6 @@ class SMESHsurfaceFormat
:
public MeshedSurface<Face>
{
// Private Member Functions
//- No copy construct
SMESHsurfaceFormat(const SMESHsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const SMESHsurfaceFormat<Face>&) = delete;
public:
// Constructors
......@@ -95,7 +86,7 @@ public:
// Member Functions
//- Write object
//- Write surface mesh to file
virtual void write
(
const fileName& name,
......
......@@ -73,12 +73,6 @@ class STARCDsurfaceFormat
const label cellTableId
);
//- No copy construct
STARCDsurfaceFormat(const STARCDsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const STARCDsurfaceFormat<Face>&) = delete;
public:
......@@ -108,7 +102,7 @@ public:
//- Read from file
virtual bool read(const fileName& filename);
//- Write object
//- Write surface mesh to file
virtual void write
(
const fileName& name,
......
......@@ -82,13 +82,6 @@ class STLsurfaceFormat
);
//- No copy construct
STLsurfaceFormat(const STLsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const STLsurfaceFormat<Face>&) = delete;
public:
// Constructors
......@@ -174,7 +167,7 @@ public:
//- Read from file
virtual bool read(const fileName& filename);
//- Write object
//- Write surface mesh to file
virtual void write
(
const fileName& name,
......
......@@ -78,12 +78,6 @@ class TRIReader
bool readFile(const fileName& filename);
//- No copy construct
TRIReader(const TRIReader&) = delete;
//- No copy assignment
TRIReader& operator=(const TRIReader&) = delete;
public:
......
......@@ -69,12 +69,6 @@ class TRIsurfaceFormat
const label zoneI
);
//- No copy construct
TRIsurfaceFormat(const TRIsurfaceFormat<Face>&) = delete;
//- No copy assignment
void operator=(const TRIsurfaceFormat<Face>&) = delete;
public:
......@@ -98,8 +92,7 @@ public:
const dictionary& options = dictionary::null
);
//- Write UnsortedMeshedSurface,
// by default the output is not sorted by zones
//- Write UnsortedMeshedSurface, the output remains unsorted
static void write
(
const fileName& filename,
......@@ -113,7 +106,7 @@ public:
//- Read from file
virtual bool read(const fileName& filename);
//- Write object
//- Write surface mesh to file
virtual void write
(
const fileName& name,
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / 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
This file is part of OpenFOAM.
......@@ -27,20 +27,7 @@ License
#include "vtkUnstructuredReader.H"
#include "scalarIOField.H"
#include "faceTraits.H"
#include "OFstream.H"
#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;
#include <fstream>
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
......@@ -278,10 +265,11 @@ void Foam::fileFormats::VTKsurfaceFormat<Face>::write
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
std::ofstream os(filename);
vtk::outputOptions opts = formatOptions(options);
std::ofstream os(filename, std::ios::binary);
autoPtr<vtk::formatter> format =
vtk::newFormatter(os, fmtType);
autoPtr<vtk::formatter> format = opts.newFormatter(os);
writeHeader(format(), pointLst);
......@@ -337,10 +325,11 @@ void Foam::fileFormats::VTKsurfaceFormat<Face>::write
const dictionary& options
)
{
std::ofstream os(filename);
vtk::outputOptions opts = formatOptions(options);
std::ofstream os(filename, std::ios::binary);
autoPtr<vtk::formatter> format =
vtk::newFormatter(os, fmtType);
autoPtr<vtk::formatter> format = opts.newFormatter(os);
writeHeader(format(), surf.points());
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / 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
This file is part of OpenFOAM.
......@@ -29,6 +29,13 @@ Description
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
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:
// Constructors
......@@ -112,7 +112,7 @@ public:
//- Read from file
virtual bool read(const fileName& filename);
//- Write object file
//- Write meshed surface to file
virtual void write
(
const fileName& name,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment