foamVtkBase64Layer.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2017-2018 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "foamVtkBase64Layer.H"
29#include <limits>
30
31// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32
33const char* Foam::vtk::foamVtkBase64Layer::encoding_ = "base64";
34
35
36// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
37
39(
40 const char* s,
41 std::streamsize n
42)
43{
45}
46
47
48// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49
51:
52 vtk::formatter(os),
54{}
55
56
57// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
58
60{
62}
63
64
65// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
66
68{
69 return encoding_;
70}
71
72
73bool Foam::vtk::foamVtkBase64Layer::writeSize(const uint64_t numbytes)
74{
75 write(reinterpret_cast<const char*>(&numbytes), sizeof(uint64_t));
76 return true;
77}
78
79
81{
83}
84
85
87{
88 // std::cerr<<"label:" << sizeof(val) << "=" << val << '\n';
89 write(reinterpret_cast<const char*>(&val), sizeof(label));
90}
91
92
94{
95 // std::cerr<<"float:" << sizeof(val) << "=" << val << '\n';
96 write(reinterpret_cast<const char*>(&val), sizeof(float));
97}
98
99
101{
102 // std::cerr<<"double as float=" << val << '\n';
103
104 // Limit range of double to float conversion
105 if (val >= std::numeric_limits<float>::max())
106 {
107 write(std::numeric_limits<float>::max());
108 }
109 else if (val <= std::numeric_limits<float>::lowest())
110 {
111 write(std::numeric_limits<float>::lowest());
112 }
113 else
114 {
115 float copy(val);
116 write(copy);
117 }
118}
119
120
122{
124}
125
126
128{
130}
131
132
133// ************************************************************************* //
label n
An output filter layer to write base-64 encoded content.
Definition: base64Layer.H:56
bool close()
End the encoding sequence, padding the final characters with '='.
Definition: base64Layer.C:140
static std::size_t encodedLength(std::size_t n)
The encoded length has 4 bytes out for every 3 bytes in.
Definition: base64Layer.C:50
virtual bool write()
Write the output fields.
Sums a given list of (at least two or more) fields and outputs the result into a new field,...
Definition: add.H:161
Base-64 encoded output layer - normally only used indirectly by formatters.
virtual bool writeSize(const uint64_t numbytes)
Write leading size for binary output.
virtual void write(const float val)
virtual ~foamVtkBase64Layer()
Destructor. Closes/flushes the underlying layer.
virtual void flush()
End the encoding sequence (padding the final characters with '=')
virtual std::size_t encodedLength(std::size_t n) const
The encoded length for base64 encoded output.
virtual const char * encoding() const
Name for the XML append encoding ("base64").
Abstract class for a VTK output stream formatter.
OBJstream os(runTime.globalPath()/outputName)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
runTime write()