mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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.
This commit is contained in:
@ -11,7 +11,16 @@ nas/NASCore.C
|
||||
fire/FIRECore.C
|
||||
starcd/STARCDCore.C
|
||||
|
||||
vtk/vtkUnstructuredReader.C
|
||||
vtk/foamVtkCore.C
|
||||
vtk/format/foamVtkAppendBase64Formatter.C
|
||||
vtk/format/foamVtkAppendRawFormatter.C
|
||||
vtk/format/foamVtkAsciiFormatter.C
|
||||
vtk/format/foamVtkBase64Formatter.C
|
||||
vtk/format/foamVtkLegacyFormatter.C
|
||||
vtk/format/foamVtkFormatter.C
|
||||
vtk/format/foamVtkOutputOptions.C
|
||||
vtk/read/vtkUnstructuredReader.C
|
||||
vtk/type/foamVtkPTraits.C
|
||||
|
||||
coordSet/coordSet.C
|
||||
|
||||
|
||||
54
src/fileFormats/vtk/foamVtkCore.C
Normal file
54
src/fileFormats/vtk/foamVtkCore.C
Normal file
@ -0,0 +1,54 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "foamVtkCore.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::foamVtkCore::foamVtkCore()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
/*
|
||||
Foam::fileName Foam::fileFormats::foamVtkCore::vtkFileName
|
||||
(
|
||||
const fileName& base,
|
||||
const enum fileExt ext
|
||||
)
|
||||
{
|
||||
return base + '.' + fileExtensions_[ext];
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
109
src/fileFormats/vtk/foamVtkCore.H
Normal file
109
src/fileFormats/vtk/foamVtkCore.H
Normal file
@ -0,0 +1,109 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::foamVtkCore
|
||||
|
||||
Description
|
||||
Core routines for dealing with VTK files.
|
||||
|
||||
SourceFiles
|
||||
foamVtkCore.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef foamVtkCore_H
|
||||
#define foamVtkCore_H
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class fileFormats::foamVtkCore Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class foamVtkCore
|
||||
{
|
||||
public:
|
||||
|
||||
// Public Data, Declarations
|
||||
|
||||
//- The context when outputting a VTK file (XML or legacy).
|
||||
enum OutputContext
|
||||
{
|
||||
INLINE, //<! Generate header and inline data
|
||||
HEADER, //<! Generate header only
|
||||
APPEND //<! Generate append-data
|
||||
};
|
||||
|
||||
|
||||
//- Equivalent to enumeration in "vtkCellType.h"
|
||||
enum vtkTypes
|
||||
{
|
||||
VTK_EMPTY_CELL = 0,
|
||||
VTK_VERTEX = 1,
|
||||
VTK_POLY_VERTEX = 2,
|
||||
VTK_LINE = 3,
|
||||
VTK_POLY_LINE = 4,
|
||||
VTK_TRIANGLE = 5,
|
||||
VTK_TRIANGLE_STRIP = 6,
|
||||
VTK_POLYGON = 7,
|
||||
VTK_PIXEL = 8,
|
||||
VTK_QUAD = 9,
|
||||
VTK_TETRA = 10,
|
||||
VTK_VOXEL = 11,
|
||||
VTK_HEXAHEDRON = 12,
|
||||
VTK_WEDGE = 13,
|
||||
VTK_PYRAMID = 14,
|
||||
VTK_PENTAGONAL_PRISM = 15,
|
||||
VTK_HEXAGONAL_PRISM = 16,
|
||||
VTK_POLYHEDRON = 42
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
foamVtkCore();
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace fileFormats
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
65
src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C
Normal file
65
src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C
Normal file
@ -0,0 +1,65 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "foamVtkAppendBase64Formatter.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
const char* Foam::foamVtkAppendBase64Formatter::name_ = "append";
|
||||
const char* Foam::foamVtkAppendBase64Formatter::encoding_ = "base64";
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::foamVtkAppendBase64Formatter::foamVtkAppendBase64Formatter
|
||||
(
|
||||
std::ostream& os
|
||||
)
|
||||
:
|
||||
foamVtkBase64Formatter(os)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::foamVtkAppendBase64Formatter::~foamVtkAppendBase64Formatter()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
const char* Foam::foamVtkAppendBase64Formatter::name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
|
||||
const char* Foam::foamVtkAppendBase64Formatter::encoding() const
|
||||
{
|
||||
return encoding_;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
99
src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H
Normal file
99
src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H
Normal file
@ -0,0 +1,99 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
foamVtkAppendBase64Formatter
|
||||
|
||||
Description
|
||||
Appended base-64 encoded binary output.
|
||||
Uses an output filter layer to write base-64 encoded content.
|
||||
|
||||
SourceFiles
|
||||
foamVtkAppendBase64Formatter.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef foamVtkAppendBase64Formatter_H
|
||||
#define foamVtkAppendBase64Formatter_H
|
||||
|
||||
#include "foamVtkBase64Formatter.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class foamVtkAppendBase64Formatter Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class foamVtkAppendBase64Formatter
|
||||
:
|
||||
public foamVtkBase64Formatter
|
||||
{
|
||||
// Private Data Members
|
||||
|
||||
static const char* name_;
|
||||
static const char* encoding_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
foamVtkAppendBase64Formatter(const foamVtkAppendBase64Formatter&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const foamVtkAppendBase64Formatter&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct and attach to an output stream
|
||||
foamVtkAppendBase64Formatter(std::ostream&);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~foamVtkAppendBase64Formatter();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Output name for XML type ("append")
|
||||
virtual const char* name() const;
|
||||
|
||||
//- Name for the XML append encoding ("base64").
|
||||
virtual const char* encoding() const;
|
||||
|
||||
};
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
112
src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C
Normal file
112
src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C
Normal file
@ -0,0 +1,112 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "foamVtkAppendRawFormatter.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
const char* Foam::foamVtkAppendRawFormatter::name_ = "append";
|
||||
const char* Foam::foamVtkAppendRawFormatter::encoding_ = "raw";
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::foamVtkAppendRawFormatter::write
|
||||
(
|
||||
const char* s,
|
||||
std::streamsize n
|
||||
)
|
||||
{
|
||||
os().write(s, n);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::foamVtkAppendRawFormatter::foamVtkAppendRawFormatter(std::ostream& os)
|
||||
:
|
||||
foamVtkFormatter(os)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::foamVtkAppendRawFormatter::~foamVtkAppendRawFormatter()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
const char* Foam::foamVtkAppendRawFormatter::name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
|
||||
const char* Foam::foamVtkAppendRawFormatter::encoding() const
|
||||
{
|
||||
return encoding_;
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkAppendRawFormatter::writeSize(const uint64_t val)
|
||||
{
|
||||
write(reinterpret_cast<const char*>(&val), sizeof(uint64_t));
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkAppendRawFormatter::write(const uint8_t val)
|
||||
{
|
||||
write(reinterpret_cast<const char*>(&val), sizeof(uint8_t));
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkAppendRawFormatter::write(const label val)
|
||||
{
|
||||
// std::cerr<<"label is:" << sizeof(val) << '\n';
|
||||
write(reinterpret_cast<const char*>(&val), sizeof(label));
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkAppendRawFormatter::write(const float val)
|
||||
{
|
||||
// std::cerr<<"float is:" << sizeof(val) << '\n';
|
||||
write(reinterpret_cast<const char*>(&val), sizeof(float));
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkAppendRawFormatter::write(const double val)
|
||||
{
|
||||
// std::cerr<<"write double as float:" << val << '\n';
|
||||
float copy(val);
|
||||
write(copy);
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkAppendRawFormatter::flush()
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
115
src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H
Normal file
115
src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H
Normal file
@ -0,0 +1,115 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
foamVtkAppendRawFormatter
|
||||
|
||||
Description
|
||||
Appended raw binary output.
|
||||
|
||||
SourceFiles
|
||||
foamVtkAppendRawFormatter.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef foamVtkAppendRawFormatter_H
|
||||
#define foamVtkAppendRawFormatter_H
|
||||
|
||||
#include "foamVtkFormatter.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class foamVtkAppendRawFormatter Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class foamVtkAppendRawFormatter
|
||||
:
|
||||
public foamVtkFormatter
|
||||
{
|
||||
// Private Data Members
|
||||
|
||||
static const char* name_;
|
||||
static const char* encoding_;
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
foamVtkAppendRawFormatter(const foamVtkAppendRawFormatter&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const foamVtkAppendRawFormatter&) = delete;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Write
|
||||
void write(const char* s, std::streamsize n);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct and attach to an output stream
|
||||
foamVtkAppendRawFormatter(std::ostream&);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~foamVtkAppendRawFormatter();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Output name for XML type ("append")
|
||||
virtual const char* name() const;
|
||||
|
||||
//- Output name for append encoding type ("raw")
|
||||
virtual const char* encoding() const;
|
||||
|
||||
|
||||
//- Write leading size for binary output
|
||||
virtual void writeSize(const uint64_t);
|
||||
|
||||
virtual void write(const uint8_t);
|
||||
virtual void write(const label);
|
||||
virtual void write(const float);
|
||||
virtual void write(const double);
|
||||
virtual void flush();
|
||||
|
||||
};
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
136
src/fileFormats/vtk/format/foamVtkAsciiFormatter.C
Normal file
136
src/fileFormats/vtk/format/foamVtkAsciiFormatter.C
Normal file
@ -0,0 +1,136 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "foamVtkAsciiFormatter.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
const char* Foam::foamVtkAsciiFormatter::name_ = "ascii";
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
inline void Foam::foamVtkAsciiFormatter::next()
|
||||
{
|
||||
if (pos_ == 6)
|
||||
{
|
||||
os()<< '\n';
|
||||
pos_ = 0;
|
||||
}
|
||||
else if (pos_)
|
||||
{
|
||||
os()<< ' ';
|
||||
}
|
||||
++pos_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::foamVtkAsciiFormatter::foamVtkAsciiFormatter(std::ostream& os)
|
||||
:
|
||||
foamVtkFormatter(os),
|
||||
pos_(0)
|
||||
{}
|
||||
|
||||
|
||||
Foam::foamVtkAsciiFormatter::foamVtkAsciiFormatter
|
||||
(
|
||||
std::ostream& os,
|
||||
unsigned precision
|
||||
)
|
||||
:
|
||||
foamVtkFormatter(os),
|
||||
pos_(0)
|
||||
{
|
||||
os.precision(precision);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::foamVtkAsciiFormatter::~foamVtkAsciiFormatter()
|
||||
{
|
||||
flush();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
const char* Foam::foamVtkAsciiFormatter::name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
|
||||
const char* Foam::foamVtkAsciiFormatter::encoding() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkAsciiFormatter::writeSize(const uint64_t)
|
||||
{/*nop*/}
|
||||
|
||||
|
||||
void Foam::foamVtkAsciiFormatter::write(const uint8_t val)
|
||||
{
|
||||
next();
|
||||
os()<< int(val);
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkAsciiFormatter::write(const label val)
|
||||
{
|
||||
next();
|
||||
os()<< val;
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkAsciiFormatter::write(const float val)
|
||||
{
|
||||
next();
|
||||
os()<< val;
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkAsciiFormatter::write(const double val)
|
||||
{
|
||||
next();
|
||||
os()<< float(val);
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkAsciiFormatter::flush()
|
||||
{
|
||||
if (pos_)
|
||||
{
|
||||
os()<< '\n';
|
||||
}
|
||||
pos_ = 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
120
src/fileFormats/vtk/format/foamVtkAsciiFormatter.H
Normal file
120
src/fileFormats/vtk/format/foamVtkAsciiFormatter.H
Normal file
@ -0,0 +1,120 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
foamVtkAsciiFormatter
|
||||
|
||||
Description
|
||||
Inline ASCII binary output.
|
||||
Adds spaces between entries and a newline every 6 items
|
||||
(for consistency with what VTK itself outputs).
|
||||
|
||||
SourceFiles
|
||||
foamVtkAsciiFormatter.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef foamVtkAsciiFormatter_H
|
||||
#define foamVtkAsciiFormatter_H
|
||||
|
||||
#include "foamVtkFormatter.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class foamVtkAsciiFormatter Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class foamVtkAsciiFormatter
|
||||
:
|
||||
public foamVtkFormatter
|
||||
{
|
||||
// Private Data Members
|
||||
|
||||
static const char* name_;
|
||||
|
||||
//- Track the current output position
|
||||
unsigned short pos_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Advance to next position, adding space or newline as required
|
||||
inline void next();
|
||||
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
foamVtkAsciiFormatter(const foamVtkAsciiFormatter&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const foamVtkAsciiFormatter&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct and attach to an output stream, use default precision
|
||||
foamVtkAsciiFormatter(std::ostream&);
|
||||
|
||||
//- Construct and attach to an output stream, use specified precision
|
||||
foamVtkAsciiFormatter(std::ostream&, unsigned precision);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~foamVtkAsciiFormatter();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Name for the XML output type ("ascii")
|
||||
// The legacy output type is an uppercase version of this.
|
||||
virtual const char* name() const;
|
||||
|
||||
//- Name for the XML append encoding - unused.
|
||||
// Currently simply "ASCII", but this should not be relied upon.
|
||||
virtual const char* encoding() const;
|
||||
|
||||
|
||||
//- Write leading size - this is a no-op for ascii output
|
||||
virtual void writeSize(const uint64_t);
|
||||
|
||||
virtual void write(const uint8_t);
|
||||
virtual void write(const label);
|
||||
virtual void write(const float);
|
||||
virtual void write(const double);
|
||||
virtual void flush();
|
||||
};
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
120
src/fileFormats/vtk/format/foamVtkBase64Formatter.C
Normal file
120
src/fileFormats/vtk/format/foamVtkBase64Formatter.C
Normal file
@ -0,0 +1,120 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "foamVtkBase64Formatter.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
const char* Foam::foamVtkBase64Formatter::name_ = "binary";
|
||||
const char* Foam::foamVtkBase64Formatter::encoding_ = "base64";
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::foamVtkBase64Formatter::write
|
||||
(
|
||||
const char* s,
|
||||
std::streamsize n
|
||||
)
|
||||
{
|
||||
base64Layer::write(s, n);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::foamVtkBase64Formatter::foamVtkBase64Formatter(std::ostream& os)
|
||||
:
|
||||
foamVtkFormatter(os),
|
||||
base64Layer(os)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::foamVtkBase64Formatter::~foamVtkBase64Formatter()
|
||||
{
|
||||
flush();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
const char* Foam::foamVtkBase64Formatter::name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
|
||||
const char* Foam::foamVtkBase64Formatter::encoding() const
|
||||
{
|
||||
return encoding_;
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkBase64Formatter::writeSize(const uint64_t val)
|
||||
{
|
||||
write(reinterpret_cast<const char*>(&val), sizeof(uint64_t));
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkBase64Formatter::write(const uint8_t val)
|
||||
{
|
||||
base64Layer::add(val);
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkBase64Formatter::write(const label val)
|
||||
{
|
||||
// std::cerr<<"label is:" << sizeof(val) << '\n';
|
||||
write(reinterpret_cast<const char*>(&val), sizeof(label));
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkBase64Formatter::write(const float val)
|
||||
{
|
||||
// std::cerr<<"float is:" << sizeof(val) << '\n';
|
||||
write(reinterpret_cast<const char*>(&val), sizeof(float));
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkBase64Formatter::write(const double val)
|
||||
{
|
||||
// std::cerr<<"write double as float:" << val << '\n';
|
||||
float copy(val);
|
||||
write(copy);
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkBase64Formatter::flush()
|
||||
{
|
||||
if (base64Layer::close())
|
||||
{
|
||||
os().put('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
116
src/fileFormats/vtk/format/foamVtkBase64Formatter.H
Normal file
116
src/fileFormats/vtk/format/foamVtkBase64Formatter.H
Normal file
@ -0,0 +1,116 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
foamVtkBase64Formatter
|
||||
|
||||
Description
|
||||
Inline base-64 encoded binary output.
|
||||
Uses an output filter layer to write base-64 encoded content.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef foamVtkBase64Formatter_H
|
||||
#define foamVtkBase64Formatter_H
|
||||
|
||||
#include "foamVtkFormatter.H"
|
||||
#include "base64Layer.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class foamVtkBase64Formatter Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class foamVtkBase64Formatter
|
||||
:
|
||||
public foamVtkFormatter,
|
||||
private base64Layer
|
||||
{
|
||||
// Private Data Members
|
||||
|
||||
static const char* name_;
|
||||
static const char* encoding_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
foamVtkBase64Formatter(const foamVtkBase64Formatter&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const foamVtkBase64Formatter&) = delete;
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Write
|
||||
void write(const char* s, std::streamsize n);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct and attach to an output stream
|
||||
foamVtkBase64Formatter(std::ostream&);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~foamVtkBase64Formatter();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Name for the XML output type ("binary")
|
||||
// The lowercase version of the Legacy output type.
|
||||
virtual const char* name() const;
|
||||
|
||||
//- Name for the XML append encoding.
|
||||
virtual const char* encoding() const;
|
||||
|
||||
|
||||
//- Write leading size for binary output
|
||||
virtual void writeSize(const uint64_t);
|
||||
|
||||
virtual void write(const uint8_t);
|
||||
virtual void write(const label);
|
||||
virtual void write(const float);
|
||||
virtual void write(const double);
|
||||
virtual void flush();
|
||||
|
||||
};
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
315
src/fileFormats/vtk/format/foamVtkFormatter.C
Normal file
315
src/fileFormats/vtk/format/foamVtkFormatter.C
Normal file
@ -0,0 +1,315 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "foamVtkFormatter.H"
|
||||
#include "foamVtkPTraits.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
const char* const Foam::foamVtkFormatter::byteOrder
|
||||
= Foam::foamVtkPTraits<endian>::typeName;
|
||||
|
||||
const char* const Foam::foamVtkFormatter::headerType =
|
||||
Foam::foamVtkPTraits<uint64_t>::typeName;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::foamVtkFormatter::foamVtkFormatter(std::ostream& os)
|
||||
:
|
||||
os_(os),
|
||||
xmlTags_(),
|
||||
inTag_(false)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::foamVtkFormatter::~foamVtkFormatter()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::foamVtkFormatter::indent()
|
||||
{
|
||||
label n = xmlTags_.size() * 2;
|
||||
while (n--)
|
||||
{
|
||||
os_ << ' ';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::foamVtkFormatter&
|
||||
Foam::foamVtkFormatter::xmlHeader()
|
||||
{
|
||||
if (inTag_)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "xml header, but already within a tag!"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
os_ << "<?xml version='1.0'?>" << nl;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::foamVtkFormatter&
|
||||
Foam::foamVtkFormatter::comment(const std::string& text)
|
||||
{
|
||||
if (inTag_)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "adding xml comment inside a tag??"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
indent();
|
||||
os_ << "<!-- " << text << " -->" << nl;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::foamVtkFormatter&
|
||||
Foam::foamVtkFormatter::openTag(const word& tag)
|
||||
{
|
||||
if (inTag_)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "open XML tag '" << tag << "', but already within a tag!"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
indent();
|
||||
os_ << '<' << tag;
|
||||
|
||||
xmlTags_.push(tag);
|
||||
inTag_ = true;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::foamVtkFormatter&
|
||||
Foam::foamVtkFormatter::closeTag(bool isEmpty)
|
||||
{
|
||||
if (!inTag_)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "close XML tag, but not within a tag!"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
if (isEmpty)
|
||||
{
|
||||
// eg, <tag ... />
|
||||
xmlTags_.pop();
|
||||
os_ << " /";
|
||||
}
|
||||
os_ << '>' << nl;
|
||||
|
||||
inTag_ = false;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::foamVtkFormatter&
|
||||
Foam::foamVtkFormatter::tag(const word& tag)
|
||||
{
|
||||
openTag(tag);
|
||||
closeTag();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Foam::foamVtkFormatter&
|
||||
Foam::foamVtkFormatter::endTag(const word& tag)
|
||||
{
|
||||
const word curr = xmlTags_.pop();
|
||||
indent();
|
||||
|
||||
if (inTag_)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "adding XML endTag '" << curr
|
||||
<< "' but already in another tag!"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
// verify inTag_
|
||||
if (!tag.empty() && tag != curr)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "expected to end xml-tag '" << tag
|
||||
<< "' but found '" << curr << "' instead"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
os_ << "</" << curr << '>' << nl;
|
||||
|
||||
inTag_ = false;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Foam::foamVtkFormatter&
|
||||
Foam::foamVtkFormatter::xmlAttr
|
||||
(
|
||||
const word& k,
|
||||
const std::string& v,
|
||||
const char quote
|
||||
)
|
||||
{
|
||||
if (!inTag_)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "xml attribute '" << k << "' but not within a tag!"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
os_ << ' ' << k << '=' << quote << v.c_str() << quote;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::foamVtkFormatter&
|
||||
Foam::foamVtkFormatter::xmlAttr
|
||||
(
|
||||
const word& k,
|
||||
const label v,
|
||||
const char quote
|
||||
)
|
||||
{
|
||||
if (!inTag_)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "xml attribute '" << k << "' but not within a tag!"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
os_ << ' ' << k << '=' << quote << v << quote;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::foamVtkFormatter&
|
||||
Foam::foamVtkFormatter::xmlAttr
|
||||
(
|
||||
const word& k,
|
||||
const uint64_t v,
|
||||
const char quote
|
||||
)
|
||||
{
|
||||
if (!inTag_)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "xml attribute '" << k << "' but not within a tag!"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
os_ << ' ' << k << '=' << quote << v << quote;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::foamVtkFormatter&
|
||||
Foam::foamVtkFormatter::xmlAttr
|
||||
(
|
||||
const word& k,
|
||||
const scalar v,
|
||||
const char quote
|
||||
)
|
||||
{
|
||||
if (!inTag_)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "xml attribute '" << k << "' but not within a tag!"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
os_ << ' ' << k << '=' << quote << v << quote;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::foamVtkFormatter&
|
||||
Foam::foamVtkFormatter::operator()
|
||||
(
|
||||
const word& k,
|
||||
const std::string& v
|
||||
)
|
||||
{
|
||||
return xmlAttr(k, v);
|
||||
}
|
||||
|
||||
|
||||
Foam::foamVtkFormatter&
|
||||
Foam::foamVtkFormatter::operator()
|
||||
(
|
||||
const word& k,
|
||||
const label v
|
||||
)
|
||||
{
|
||||
return xmlAttr(k, v);
|
||||
}
|
||||
|
||||
|
||||
Foam::foamVtkFormatter&
|
||||
Foam::foamVtkFormatter::operator()
|
||||
(
|
||||
const word& k,
|
||||
const uint64_t v
|
||||
)
|
||||
{
|
||||
return xmlAttr(k, v);
|
||||
}
|
||||
|
||||
|
||||
Foam::foamVtkFormatter&
|
||||
Foam::foamVtkFormatter::operator()
|
||||
(
|
||||
const word& k,
|
||||
const scalar v
|
||||
)
|
||||
{
|
||||
return xmlAttr(k, v);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
233
src/fileFormats/vtk/format/foamVtkFormatter.H
Normal file
233
src/fileFormats/vtk/format/foamVtkFormatter.H
Normal file
@ -0,0 +1,233 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
foamVtkFormatter
|
||||
|
||||
Description
|
||||
Abstract class for a VTK output stream formatter.
|
||||
|
||||
Includes very simple support for writing XML tags.
|
||||
|
||||
SourceFiles
|
||||
foamVtkFormatter.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef foamVtkFormatter_H
|
||||
#define foamVtkFormatter_H
|
||||
|
||||
#include "int.H"
|
||||
#include "uint64.H"
|
||||
#include "label.H"
|
||||
#include "word.H"
|
||||
#include "UList.H"
|
||||
#include "LIFOStack.H"
|
||||
#include "foamVtkPTraits.H"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class foamVtkFormatter Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class foamVtkFormatter
|
||||
{
|
||||
// Private Data
|
||||
|
||||
//- The output stream for the formatter
|
||||
std::ostream& os_;
|
||||
|
||||
//- Stack of current XML tags
|
||||
LIFOStack<word> xmlTags_;
|
||||
|
||||
//- Tag open/closed/ended state
|
||||
mutable bool inTag_;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Construct and attach to an output stream
|
||||
foamVtkFormatter(std::ostream& os);
|
||||
|
||||
public:
|
||||
|
||||
// Static Data
|
||||
|
||||
//- VTK name for the 'byte_order' attribute
|
||||
static const char* const byteOrder;
|
||||
|
||||
//- VTK name for the 'header_type' attribute (UInt64)
|
||||
static const char* const headerType;
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~foamVtkFormatter();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Access to the underlying output stream
|
||||
inline std::ostream& os()
|
||||
{
|
||||
return os_;
|
||||
}
|
||||
|
||||
|
||||
//- Name for the XML output type.
|
||||
// Possibly the lowercase version of the Legacy output type
|
||||
virtual const char* name() const = 0;
|
||||
|
||||
//- Name for the XML append encoding
|
||||
virtual const char* encoding() const = 0;
|
||||
|
||||
|
||||
//- Write leading size for binary output
|
||||
virtual void writeSize(const uint64_t) = 0;
|
||||
|
||||
virtual void write(const uint8_t) = 0;
|
||||
virtual void write(const label) = 0;
|
||||
virtual void write(const float) = 0;
|
||||
virtual void write(const double) = 0;
|
||||
virtual void flush() = 0;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Indent according to the currently nested XML tags
|
||||
void indent();
|
||||
|
||||
//- Write XML header
|
||||
foamVtkFormatter& xmlHeader();
|
||||
|
||||
//- Write XML comment (at the current indentation level)
|
||||
foamVtkFormatter& comment(const std::string&);
|
||||
|
||||
|
||||
//- Open XML tag
|
||||
foamVtkFormatter& openTag(const word& tag);
|
||||
|
||||
//- Close XML tag, optional as an empty container.
|
||||
// Always adds a trailing newline.
|
||||
foamVtkFormatter& closeTag(bool isEmpty = false);
|
||||
|
||||
//- End XML tag, optional with sanity check
|
||||
// Always adds a trailing newline.
|
||||
foamVtkFormatter& endTag(const word& tag = word::null);
|
||||
|
||||
//- Write XML tag without any attributes. Combines openTag/closeTag.
|
||||
foamVtkFormatter& tag(const word& tag);
|
||||
|
||||
|
||||
//- Open "DataArray" XML tag
|
||||
template<class Type, int nComp=0>
|
||||
foamVtkFormatter& openDataArray(const word& dataName);
|
||||
|
||||
|
||||
//- Insert a single "PDataArray" XML entry tag.
|
||||
// For some entries, the name is optional.
|
||||
template<class Type, int nComp=0>
|
||||
foamVtkFormatter& PDataArray(const word& dataName);
|
||||
|
||||
|
||||
//- End "DataArray" XML tag
|
||||
foamVtkFormatter& endDataArray()
|
||||
{
|
||||
return endTag("DataArray");
|
||||
}
|
||||
|
||||
|
||||
|
||||
//- Write XML attribute
|
||||
foamVtkFormatter& xmlAttr
|
||||
(
|
||||
const word&,
|
||||
const std::string&,
|
||||
const char quote='\''
|
||||
);
|
||||
|
||||
//- Write XML attribute
|
||||
foamVtkFormatter& xmlAttr
|
||||
(
|
||||
const word&,
|
||||
const label,
|
||||
const char quote='\''
|
||||
);
|
||||
|
||||
//- Write XML attribute
|
||||
foamVtkFormatter& xmlAttr
|
||||
(
|
||||
const word&,
|
||||
const uint64_t,
|
||||
const char quote='\''
|
||||
);
|
||||
|
||||
//- Write XML attribute
|
||||
foamVtkFormatter& xmlAttr
|
||||
(
|
||||
const word&,
|
||||
const scalar,
|
||||
const char quote='\''
|
||||
);
|
||||
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
//- Write XML attribute
|
||||
foamVtkFormatter& operator()(const word&, const std::string&);
|
||||
|
||||
//- Write XML attribute
|
||||
foamVtkFormatter& operator()(const word&, const label);
|
||||
|
||||
//- Write XML attribute
|
||||
foamVtkFormatter& operator()(const word&, const uint64_t);
|
||||
|
||||
//- Write XML attribute
|
||||
foamVtkFormatter& operator()(const word&, const scalar);
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "foamVtkFormatterTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
70
src/fileFormats/vtk/format/foamVtkFormatterTemplates.C
Normal file
70
src/fileFormats/vtk/format/foamVtkFormatterTemplates.C
Normal file
@ -0,0 +1,70 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "foamVtkPTraits.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type, int nComp>
|
||||
Foam::foamVtkFormatter& Foam::foamVtkFormatter::openDataArray
|
||||
(
|
||||
const word& dataName
|
||||
)
|
||||
{
|
||||
openTag("DataArray");
|
||||
xmlAttr("type", foamVtkPTraits<Type>::typeName);
|
||||
xmlAttr("Name", dataName);
|
||||
if (nComp > 1)
|
||||
{
|
||||
xmlAttr("NumberOfComponents", nComp);
|
||||
}
|
||||
xmlAttr("format", name());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class Type, int nComp>
|
||||
Foam::foamVtkFormatter& Foam::foamVtkFormatter::PDataArray
|
||||
(
|
||||
const word& dataName
|
||||
)
|
||||
{
|
||||
openTag("PDataArray");
|
||||
xmlAttr("type", foamVtkPTraits<Type>::typeName);
|
||||
if (dataName.size())
|
||||
{
|
||||
xmlAttr("Name", dataName);
|
||||
}
|
||||
if (nComp > 1)
|
||||
{
|
||||
xmlAttr("NumberOfComponents", nComp);
|
||||
}
|
||||
|
||||
closeTag(true);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
139
src/fileFormats/vtk/format/foamVtkLegacyFormatter.C
Normal file
139
src/fileFormats/vtk/format/foamVtkLegacyFormatter.C
Normal file
@ -0,0 +1,139 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "foamVtkLegacyFormatter.H"
|
||||
#include "endian.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
const char* Foam::foamVtkLegacyFormatter::name_ = "BINARY";
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::foamVtkLegacyFormatter::write
|
||||
(
|
||||
const char* s,
|
||||
std::streamsize n
|
||||
)
|
||||
{
|
||||
os().write(s, n);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::foamVtkLegacyFormatter::foamVtkLegacyFormatter(std::ostream& os)
|
||||
:
|
||||
foamVtkFormatter(os)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::foamVtkLegacyFormatter::~foamVtkLegacyFormatter()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
const char* Foam::foamVtkLegacyFormatter::name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
|
||||
const char* Foam::foamVtkLegacyFormatter::encoding() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkLegacyFormatter::writeSize(const uint64_t)
|
||||
{}
|
||||
|
||||
|
||||
void Foam::foamVtkLegacyFormatter::write(const uint8_t val)
|
||||
{
|
||||
// Can only handle integers
|
||||
int copy(val);
|
||||
write(copy);
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkLegacyFormatter::write(const label val)
|
||||
{
|
||||
// std::cerr<<"label is:" << sizeof(val) << '\n';
|
||||
|
||||
// Not entirely correct: the legacy format only supports 32-bit integers.
|
||||
// Either limit size for 64-bit label, or simply do not support for 64-bit.
|
||||
#ifdef WM_LITTLE_ENDIAN
|
||||
# if WM_LABEL_SIZE == 32
|
||||
uint32_t swapped = endian::swap32(val);
|
||||
write(reinterpret_cast<const char*>(&swapped), sizeof(uint32_t));
|
||||
# elif WM_LABEL_SIZE == 64
|
||||
uint64_t swapped = endian::swap64(val);
|
||||
write(reinterpret_cast<const char*>(&swapped), sizeof(uint64_t));
|
||||
#endif
|
||||
#else
|
||||
write(reinterpret_cast<const char*>(&val), sizeof(label));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkLegacyFormatter::write(const float val)
|
||||
{
|
||||
// std::cerr<<"float is:" << sizeof(val) << '\n';
|
||||
|
||||
#ifdef WM_LITTLE_ENDIAN
|
||||
// De-reference in two stages to avoid the warning
|
||||
// dereferencing type-punned pointer will break strict-aliasing rules
|
||||
// [-Wstrict-aliasing]
|
||||
|
||||
const uint32_t* ptr = reinterpret_cast<const uint32_t*>(&val);
|
||||
uint32_t swapped = endian::swap32(*ptr);
|
||||
write(reinterpret_cast<const char*>(&swapped), sizeof(uint32_t));
|
||||
#else
|
||||
write(reinterpret_cast<const char*>(&val), sizeof(float));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkLegacyFormatter::write(const double val)
|
||||
{
|
||||
// Legacy cannot support Float64 anyhow.
|
||||
// std::cerr<<"write double as float:" << val << '\n';
|
||||
float copy(val);
|
||||
write(copy);
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkLegacyFormatter::flush()
|
||||
{
|
||||
os()<< '\n';
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
119
src/fileFormats/vtk/format/foamVtkLegacyFormatter.H
Normal file
119
src/fileFormats/vtk/format/foamVtkLegacyFormatter.H
Normal file
@ -0,0 +1,119 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
foamVtkLegacyFormatter
|
||||
|
||||
Description
|
||||
Binary output for the VTK legacy format, always written as big-endian.
|
||||
|
||||
The legacy files are always written as big endian.
|
||||
Since integers in the legacy format are limited to 32-bit,
|
||||
this format should not be used for OpenFOAM with 64-bit label sizes.
|
||||
|
||||
SourceFiles
|
||||
foamVtkLegacyFormatter.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef foamVtkLegacyFormatter_H
|
||||
#define foamVtkLegacyFormatter_H
|
||||
|
||||
#include "foamVtkFormatter.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class foamVtkLegacyFormatter Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class foamVtkLegacyFormatter
|
||||
:
|
||||
public foamVtkFormatter
|
||||
{
|
||||
// Private Data Members
|
||||
|
||||
static const char* name_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
foamVtkLegacyFormatter(const foamVtkLegacyFormatter&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const foamVtkLegacyFormatter&) = delete;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Write
|
||||
void write(const char* s, std::streamsize n);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct and attach to an output stream
|
||||
foamVtkLegacyFormatter(std::ostream&);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~foamVtkLegacyFormatter();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Name for the Legacy output type ("BINARY")
|
||||
virtual const char* name() const;
|
||||
|
||||
//- Name for the XML append encoding (unused)
|
||||
// Currently simply "BINARY", but this should not be relied upon.
|
||||
virtual const char* encoding() const;
|
||||
|
||||
|
||||
//- Write leading size - a no-op for legacy binary output
|
||||
virtual void writeSize(const uint64_t);
|
||||
|
||||
virtual void write(const uint8_t);
|
||||
virtual void write(const label);
|
||||
virtual void write(const float);
|
||||
virtual void write(const double);
|
||||
virtual void flush();
|
||||
};
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
240
src/fileFormats/vtk/format/foamVtkOutputOptions.C
Normal file
240
src/fileFormats/vtk/format/foamVtkOutputOptions.C
Normal file
@ -0,0 +1,240 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "foamVtkOutputOptions.H"
|
||||
|
||||
#include "foamVtkAppendBase64Formatter.H"
|
||||
#include "foamVtkAppendRawFormatter.H"
|
||||
#include "foamVtkAsciiFormatter.H"
|
||||
#include "foamVtkBase64Formatter.H"
|
||||
#include "foamVtkLegacyFormatter.H"
|
||||
|
||||
#include "IOstream.H"
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * //
|
||||
|
||||
Foam::foamVtkOutputOptions::foamVtkOutputOptions()
|
||||
:
|
||||
type_(ASCII),
|
||||
style_(NONE),
|
||||
precision_(IOstream::defaultPrecision())
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::autoPtr<Foam::foamVtkFormatter>
|
||||
Foam::foamVtkOutputOptions::newFormatter
|
||||
(
|
||||
std::ostream& os
|
||||
) const
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
case (LEGACY | BINARY):
|
||||
return autoPtr<foamVtkFormatter>
|
||||
(
|
||||
new foamVtkLegacyFormatter(os)
|
||||
);
|
||||
|
||||
case BASE64: // xml insitu
|
||||
return autoPtr<foamVtkFormatter>
|
||||
(
|
||||
new foamVtkBase64Formatter(os)
|
||||
);
|
||||
|
||||
case (APPEND | BASE64):
|
||||
return autoPtr<foamVtkFormatter>
|
||||
(
|
||||
new foamVtkAppendBase64Formatter(os)
|
||||
);
|
||||
|
||||
case (APPEND | BINARY):
|
||||
return autoPtr<foamVtkFormatter>
|
||||
(
|
||||
new foamVtkAppendRawFormatter(os)
|
||||
);
|
||||
|
||||
default: // ASCII (legacy or xml) must always work
|
||||
return autoPtr<foamVtkFormatter>
|
||||
(
|
||||
new foamVtkAsciiFormatter(os, precision_)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::foamVtkOutputOptions::ascii(bool b)
|
||||
{
|
||||
if (b)
|
||||
{
|
||||
// Force ASCII:
|
||||
|
||||
if (type_ & APPEND)
|
||||
{
|
||||
// Append: ascii = base64 (vs raw binary)
|
||||
type_ = (APPEND | BASE64);
|
||||
}
|
||||
else if (type_ & LEGACY)
|
||||
{
|
||||
// Legacy: ascii = ascii
|
||||
type_ = (LEGACY | ASCII);
|
||||
}
|
||||
else
|
||||
{
|
||||
// XML: ascii = ascii
|
||||
type_ = ASCII;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Non-ASCII:
|
||||
|
||||
if (type_ & APPEND)
|
||||
{
|
||||
// Append: binary == (raw) binary
|
||||
type_ = APPEND | BINARY;
|
||||
}
|
||||
else if (type_ & LEGACY)
|
||||
{
|
||||
// Legacy: binary = binary
|
||||
type_ = LEGACY | BINARY;
|
||||
}
|
||||
else
|
||||
{
|
||||
// XML: binary == (inline) binary == base64
|
||||
type_ = BASE64;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkOutputOptions::append(bool b)
|
||||
{
|
||||
if (b)
|
||||
{
|
||||
if (!(type_ & APPEND))
|
||||
{
|
||||
// XML: base64 -> raw binary, ascii -> base64
|
||||
// Legacy: binary -> raw binary, ascii -> base64
|
||||
type_ = APPEND | ((type_ & (BASE64 | BINARY)) ? BINARY : BASE64);
|
||||
}
|
||||
}
|
||||
else if (type_ & APPEND)
|
||||
{
|
||||
// Only revert back to inline XML base64 versions
|
||||
// ASCII needs another step.
|
||||
|
||||
type_ = BASE64;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkOutputOptions::legacy(bool b)
|
||||
{
|
||||
if (b)
|
||||
{
|
||||
if (type_ & APPEND)
|
||||
{
|
||||
// Append: base64 -> ascii, binary -> binary
|
||||
type_ = (LEGACY | ((type_ & BINARY) ? BINARY : ASCII));
|
||||
}
|
||||
else if (type_ & LEGACY)
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
else
|
||||
{
|
||||
// XML: ascii -> ascii, base64 -> binary
|
||||
type_ = (LEGACY | ((type_ & BASE64) ? BINARY : ASCII));
|
||||
}
|
||||
}
|
||||
else if (type_ & LEGACY)
|
||||
{
|
||||
// Legacy: ascii -> xml ascii, binary -> xml base64
|
||||
type_ = (type_ & BINARY) ? BASE64 : ASCII;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::foamVtkOutputOptions::precision(unsigned val) const
|
||||
{
|
||||
precision_ = val;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream&
|
||||
Foam::foamVtkOutputOptions::info(Ostream& os) const
|
||||
{
|
||||
os << "type: " << type_;
|
||||
|
||||
switch (type_)
|
||||
{
|
||||
case (LEGACY | ASCII):
|
||||
os << " legacy ascii";
|
||||
break;
|
||||
|
||||
case (LEGACY | BINARY):
|
||||
os << " legacy binary";
|
||||
break;
|
||||
|
||||
case BASE64:
|
||||
os << " xml insitu base64";
|
||||
break;
|
||||
|
||||
case (APPEND | BASE64):
|
||||
os << " xml-append base64";
|
||||
break;
|
||||
|
||||
case (APPEND | BINARY):
|
||||
os << " xml-append binary";
|
||||
break;
|
||||
|
||||
case ASCII:
|
||||
os << " xml insitu ascii";
|
||||
break;
|
||||
|
||||
case BINARY:
|
||||
os << " xml insitu binary - WRONG";
|
||||
break;
|
||||
|
||||
default:
|
||||
os << " unknown";
|
||||
break;
|
||||
}
|
||||
|
||||
if (legacy()) os << " legacy";
|
||||
if (xml()) os << " xml";
|
||||
if (append()) os << " append";
|
||||
if (ascii()) os << " ascii";
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
156
src/fileFormats/vtk/format/foamVtkOutputOptions.H
Normal file
156
src/fileFormats/vtk/format/foamVtkOutputOptions.H
Normal file
@ -0,0 +1,156 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
foamVtkOutputOptions
|
||||
|
||||
Description
|
||||
Encapsulate combinations of output format options.
|
||||
|
||||
SourceFiles
|
||||
foamVtkOutputOptions.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef foamVtkOutputOptions_H
|
||||
#define foamVtkOutputOptions_H
|
||||
|
||||
#include "autoPtr.H"
|
||||
#include "foamVtkFormatter.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
class Ostream;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class foamVtkOutputOptions Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class foamVtkOutputOptions
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- The supported output/format types
|
||||
enum foamVtkOptionTypes
|
||||
{
|
||||
ASCII = 0x0000, //!< ASCII formatting for data
|
||||
BINARY = 0x0001, //!< Raw binary formatting for data
|
||||
BASE64 = 0x0002, //!< Base64 encoding for data
|
||||
LEGACY = 0x0100, //!< Legacy vtk file format
|
||||
APPEND = 0x0200 //!< XML append format
|
||||
};
|
||||
|
||||
//- The output style tuning
|
||||
enum foamVtkStyleOptions
|
||||
{
|
||||
NONE = 0x0000, //!< Normal
|
||||
HEADER = 0x0001 //!< Emit xml header
|
||||
};
|
||||
|
||||
|
||||
//- The output format type
|
||||
unsigned short type_;
|
||||
|
||||
//- The output style tuning
|
||||
unsigned short style_;
|
||||
|
||||
|
||||
//- ASCII write precision
|
||||
mutable unsigned precision_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null - XML insitu ASCII format with default precision
|
||||
foamVtkOutputOptions();
|
||||
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Return new data formatter based on the writer options
|
||||
autoPtr<foamVtkFormatter> newFormatter(std::ostream&) const;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
//- True if writer uses legacy file format
|
||||
inline bool legacy() const;
|
||||
|
||||
//- True if writer uses XML file format (non-legacy)
|
||||
inline bool xml() const;
|
||||
|
||||
//- True if output format uses an append mode
|
||||
inline bool append() const;
|
||||
|
||||
//- True if output format does not use an append mode
|
||||
inline bool insitu() const;
|
||||
|
||||
//- True if output format is ASCII
|
||||
inline bool ascii() const;
|
||||
|
||||
|
||||
// Edit
|
||||
|
||||
//- Toggle ASCII mode on/off.
|
||||
// In append mode, this switches between base64 and raw binary.
|
||||
// In XML mode, this switches between ASCII and base64.
|
||||
// In legacy mode, this switches between ASCII and binary.
|
||||
void ascii(bool);
|
||||
|
||||
//- Toggle append mode on/off.
|
||||
void append(bool);
|
||||
|
||||
//- Toggle legacy mode on/off.
|
||||
void legacy(bool);
|
||||
|
||||
//- Set the write precision to be used for new ASCII formatters
|
||||
void precision(unsigned val) const;
|
||||
|
||||
|
||||
// Other
|
||||
|
||||
//- Report information about the options
|
||||
Ostream& info(Ostream&) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "foamVtkOutputOptionsI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
56
src/fileFormats/vtk/format/foamVtkOutputOptionsI.H
Normal file
56
src/fileFormats/vtk/format/foamVtkOutputOptionsI.H
Normal file
@ -0,0 +1,56 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
inline bool Foam::foamVtkOutputOptions::legacy() const
|
||||
{
|
||||
return (type_ & LEGACY);
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::foamVtkOutputOptions::xml() const
|
||||
{
|
||||
return !legacy();
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::foamVtkOutputOptions::append() const
|
||||
{
|
||||
return (type_ & APPEND);
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::foamVtkOutputOptions::insitu() const
|
||||
{
|
||||
return !(type_ & APPEND);
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::foamVtkOutputOptions::ascii() const
|
||||
{
|
||||
return !(type_ & (BINARY | BASE64));
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -136,7 +136,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
{
|
||||
switch (cellTypes[i])
|
||||
{
|
||||
case VTK_VERTEX:
|
||||
case foamVtkCore::VTK_VERTEX:
|
||||
{
|
||||
warnUnhandledType(inFile, cellTypes[i], warningGiven);
|
||||
label nRead = cellVertData[dataIndex++];
|
||||
@ -152,7 +152,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
}
|
||||
break;
|
||||
|
||||
case VTK_POLY_VERTEX:
|
||||
case foamVtkCore::VTK_POLY_VERTEX:
|
||||
{
|
||||
warnUnhandledType(inFile, cellTypes[i], warningGiven);
|
||||
label nRead = cellVertData[dataIndex++];
|
||||
@ -160,7 +160,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
}
|
||||
break;
|
||||
|
||||
case VTK_LINE:
|
||||
case foamVtkCore::VTK_LINE:
|
||||
{
|
||||
//warnUnhandledType(inFile, cellTypes[i], warningGiven);
|
||||
label nRead = cellVertData[dataIndex++];
|
||||
@ -180,7 +180,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
}
|
||||
break;
|
||||
|
||||
case VTK_POLY_LINE:
|
||||
case foamVtkCore::VTK_POLY_LINE:
|
||||
{
|
||||
//warnUnhandledType(inFile, cellTypes[i], warningGiven);
|
||||
label nRead = cellVertData[dataIndex++];
|
||||
@ -194,7 +194,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
}
|
||||
break;
|
||||
|
||||
case VTK_TRIANGLE:
|
||||
case foamVtkCore::VTK_TRIANGLE:
|
||||
{
|
||||
faceMap_[facei] = i;
|
||||
face& f = faces_[facei++];
|
||||
@ -214,7 +214,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
}
|
||||
break;
|
||||
|
||||
case VTK_QUAD:
|
||||
case foamVtkCore::VTK_QUAD:
|
||||
{
|
||||
faceMap_[facei] = i;
|
||||
face& f = faces_[facei++];
|
||||
@ -235,7 +235,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
}
|
||||
break;
|
||||
|
||||
case VTK_POLYGON:
|
||||
case foamVtkCore::VTK_POLYGON:
|
||||
{
|
||||
faceMap_[facei] = i;
|
||||
face& f = faces_[facei++];
|
||||
@ -248,7 +248,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
}
|
||||
break;
|
||||
|
||||
case VTK_TETRA:
|
||||
case foamVtkCore::VTK_TETRA:
|
||||
{
|
||||
label nRead = cellVertData[dataIndex++];
|
||||
if (nRead != 4)
|
||||
@ -268,7 +268,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
}
|
||||
break;
|
||||
|
||||
case VTK_PYRAMID:
|
||||
case foamVtkCore::VTK_PYRAMID:
|
||||
{
|
||||
label nRead = cellVertData[dataIndex++];
|
||||
if (nRead != 5)
|
||||
@ -289,7 +289,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
}
|
||||
break;
|
||||
|
||||
case VTK_WEDGE:
|
||||
case foamVtkCore::VTK_WEDGE:
|
||||
{
|
||||
label nRead = cellVertData[dataIndex++];
|
||||
if (nRead != 6)
|
||||
@ -311,7 +311,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
}
|
||||
break;
|
||||
|
||||
case VTK_HEXAHEDRON:
|
||||
case foamVtkCore::VTK_HEXAHEDRON:
|
||||
{
|
||||
label nRead = cellVertData[dataIndex++];
|
||||
if (nRead != 8)
|
||||
@ -25,8 +25,8 @@ Class
|
||||
Foam::vtkUnstructuredReader
|
||||
|
||||
Description
|
||||
Reader for vtk unstructured_grid legacy files. Supports single CELLS, POINTS
|
||||
etc. entry only.
|
||||
Reader for vtk UNSTRUCTURED_GRID legacy files.
|
||||
Supports single CELLS, POINTS etc. entry only.
|
||||
|
||||
- all integer types (int, unsigned_int, long etc.) become Foam::label
|
||||
- all real types (float, double) become Foam::scalar
|
||||
@ -47,6 +47,7 @@ SourceFiles
|
||||
#ifndef vtkUnstructuredReader_H
|
||||
#define vtkUnstructuredReader_H
|
||||
|
||||
#include "foamVtkCore.H"
|
||||
#include "objectRegistry.H"
|
||||
#include "cellShapeList.H"
|
||||
#include "HashSet.H"
|
||||
@ -62,6 +63,8 @@ namespace Foam
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class vtkUnstructuredReader
|
||||
:
|
||||
public fileFormats::foamVtkCore
|
||||
{
|
||||
public:
|
||||
|
||||
@ -108,29 +111,6 @@ public:
|
||||
static const NamedEnum<parseMode, 5> parseModeNames;
|
||||
|
||||
|
||||
//- Enumeration defining the cell types
|
||||
enum vtkTypes
|
||||
{
|
||||
VTK_EMPTY_CELL = 0,
|
||||
VTK_VERTEX = 1,
|
||||
VTK_POLY_VERTEX = 2,
|
||||
VTK_LINE = 3,
|
||||
VTK_POLY_LINE = 4,
|
||||
VTK_TRIANGLE = 5,
|
||||
VTK_TRIANGLE_STRIP = 6,
|
||||
VTK_POLYGON = 7,
|
||||
VTK_PIXEL = 8,
|
||||
VTK_QUAD = 9,
|
||||
VTK_TETRA = 10,
|
||||
VTK_VOXEL = 11,
|
||||
VTK_HEXAHEDRON = 12,
|
||||
VTK_WEDGE = 13,
|
||||
VTK_PYRAMID = 14,
|
||||
VTK_PENTAGONAL_PRISM = 15,
|
||||
VTK_HEXAGONAL_PRISM = 16,
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
//- Header
|
||||
@ -56,7 +56,7 @@ void Foam::vtkUnstructuredReader::printFieldStats
|
||||
{
|
||||
wordList fieldNames(obj.names(Type::typeName));
|
||||
|
||||
if (fieldNames.size() > 0)
|
||||
if (fieldNames.size())
|
||||
{
|
||||
Info<< "Read " << fieldNames.size() << " " << Type::typeName
|
||||
<< " fields:" << endl;
|
||||
70
src/fileFormats/vtk/type/foamVtkPTraits.C
Normal file
70
src/fileFormats/vtk/type/foamVtkPTraits.C
Normal file
@ -0,0 +1,70 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "foamVtkPTraits.H"
|
||||
#include "endian.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
template<>
|
||||
const char* const
|
||||
Foam::foamVtkPTraits<uint8_t>::typeName = "UInt8";
|
||||
|
||||
template<>
|
||||
const char * const
|
||||
Foam::foamVtkPTraits<int32_t>::typeName = "Int32";
|
||||
|
||||
template<>
|
||||
const char * const
|
||||
Foam::foamVtkPTraits<uint32_t>::typeName = "UInt32";
|
||||
|
||||
template<>
|
||||
const char * const
|
||||
Foam::foamVtkPTraits<int64_t>::typeName = "Int64";
|
||||
|
||||
template<>
|
||||
const char * const
|
||||
Foam::foamVtkPTraits<uint64_t>::typeName = "UInt64";
|
||||
|
||||
template<>
|
||||
const char * const
|
||||
Foam::foamVtkPTraits<float>::typeName = "Float32";
|
||||
|
||||
template<>
|
||||
const char * const
|
||||
Foam::foamVtkPTraits<double>::typeName = "Float64";
|
||||
|
||||
#ifdef WM_LITTLE_ENDIAN
|
||||
template<>
|
||||
const char* const
|
||||
Foam::foamVtkPTraits<::Foam::endian>::typeName = "LittleEndian";
|
||||
#else
|
||||
template<>
|
||||
const char* const
|
||||
Foam::foamVtkPTraits<::Foam::endian>::typeName = "BigEndian";
|
||||
#endif
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
93
src/fileFormats/vtk/type/foamVtkPTraits.H
Normal file
93
src/fileFormats/vtk/type/foamVtkPTraits.H
Normal file
@ -0,0 +1,93 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::foamVtkPTraits
|
||||
|
||||
Description
|
||||
Names for VTK primitive types.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef foamVtkPTraits_H
|
||||
#define foamVtkPTraits_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
class endian;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class foamVtkPTraits Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class PrimitiveType>
|
||||
class foamVtkPTraits
|
||||
{
|
||||
public:
|
||||
|
||||
// Static data members
|
||||
|
||||
static const char* const typeName;
|
||||
};
|
||||
|
||||
|
||||
template<>
|
||||
const char* const foamVtkPTraits<uint8_t>::typeName; // = UInt8
|
||||
|
||||
template<>
|
||||
const char* const foamVtkPTraits<int32_t>::typeName; // = Int32
|
||||
|
||||
template<>
|
||||
const char* const foamVtkPTraits<int32_t>::typeName; // = UInt32
|
||||
|
||||
template<>
|
||||
const char* const foamVtkPTraits<int32_t>::typeName; // = Int64
|
||||
|
||||
template<>
|
||||
const char* const foamVtkPTraits<int64_t>::typeName; // = UInt64
|
||||
|
||||
template<>
|
||||
const char* const foamVtkPTraits<float>::typeName; // = Float32
|
||||
|
||||
template<>
|
||||
const char* const foamVtkPTraits<double>::typeName; // = Float64
|
||||
|
||||
template<>
|
||||
const char* const foamVtkPTraits<::Foam::endian>::typeName;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user