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 -------------------------------------------------------------------------------
10 License
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 
33 const 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 
50 Foam::vtk::foamVtkBase64Layer::foamVtkBase64Layer(std::ostream& os)
51 :
52  formatter(os),
54 {}
55 
56 
57 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
58 
60 {
62 }
63 
64 
65 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
66 
68 {
69  return encoding_;
70 }
71 
72 
73 bool 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 
80 void Foam::vtk::foamVtkBase64Layer::write(const uint8_t val)
81 {
82  base64Layer::add(val);
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  {
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 
127 std::size_t Foam::vtk::foamVtkBase64Layer::encodedLength(std::size_t n) const
128 {
130 }
131 
132 
133 // ************************************************************************* //
s
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))
Definition: gmvOutputSpray.H:25
foamVtkBase64Layer.H
Foam::base64Layer::close
bool close()
End the encoding sequence, padding the final characters with '='.
Definition: base64Layer.C:140
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::vtk::foamVtkBase64Layer::~foamVtkBase64Layer
virtual ~foamVtkBase64Layer()
Destructor. Closes/flushes the underlying layer.
Definition: foamVtkBase64Layer.C:59
Foam::vtk::foamVtkBase64Layer::flush
virtual void flush()
End the encoding sequence (padding the final characters with '=')
Definition: foamVtkBase64Layer.C:121
Foam::vtk::foamVtkBase64Layer::writeSize
virtual bool writeSize(const uint64_t numbytes)
Write leading size for binary output.
Definition: foamVtkBase64Layer.C:73
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
os
OBJstream os(runTime.globalPath()/outputName)
Foam::base64Layer::add
void add(char c)
Add a character to the group, outputting when the group is full.
Definition: base64Layer.C:83
Foam::vtk::foamVtkBase64Layer::encoding
virtual const char * encoding() const
Name for the XML append encoding ("base64").
Definition: foamVtkBase64Layer.C:67
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:36
Foam::base64Layer
An output filter layer to write base-64 encoded content.
Definition: base64Layer.H:55
Foam::base64Layer::encodedLength
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
Foam::vtk::foamVtkBase64Layer::write
void write(const char *s, std::streamsize n)
Write.
Definition: foamVtkBase64Layer.C:39
Foam::vtk::foamVtkBase64Layer::encodedLength
virtual std::size_t encodedLength(std::size_t n) const
The encoded length for base64 encoded output.
Definition: foamVtkBase64Layer.C:127
Foam::vtk::formatter
Abstract class for a VTK output stream formatter.
Definition: foamVtkFormatter.H:68