Peano
Loading...
Searching...
No Matches
VTKBinaryFileWriter.h
Go to the documentation of this file.
1// This file is part of the Peano project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#pragma once
4
5
6#include "../../../PVDTimeSeriesWriter.h"
7#include "tarch/logging/Log.h"
9
10
11namespace tarch {
12 namespace plotter {
13 namespace griddata {
14 namespace unstructured {
15 namespace vtk {
16 class VTKBinaryFileWriter;
17 }
18 }
19 }
20 }
21}
22
23
52 private:
57
58 static const std::string HEADER;
59
61
63 const int _precision;
64
66 const std::string _doubleOrFloat;
67
72
77
82
83 std::stringstream _vertexDescription;
84 std::stringstream _cellDescription;
85 std::stringstream _cellTypeDescription;
86 std::stringstream _vertexDataDescription;
87 std::stringstream _cellDataDescription;
88
89 std::string _fileName;
90
91 void validateDataWriterIdentifier( const std::string& identifier ) const;
92
93
94 std::string setDoubleOrFloatString(const int precision){
95 if (precision < 7){
96 return "float";
97 } else {
98 return "double";
99 }
100 }
101
102 public:
103 VTKBinaryFileWriter(const std::string& fileName, const std::string& indexFileName, tarch::plotter::PVDTimeSeriesWriter::IndexFileMode modeFile, double timeStamp, const int precision=6);
105
106 virtual bool isOpen() override;
107
108 virtual bool writeToFile() override;
109
110 virtual void clear() override;
111
112 virtual VertexWriter* createVertexWriter() override;
113 virtual CellWriter* createCellWriter() override;
114 virtual CellDataWriter* createCellDataWriter( const std::string& identifier, int recordsPerCell ) override;
115 virtual VertexDataWriter* createVertexDataWriter( const std::string& identifier, int recordsPerVertex ) override;
116
127 private:
132
137
142
146 std::stringstream _out;
147
149
155 _myWriter(writer._myWriter),
156 _out() {
157 assertion(false);
158 }
159 public:
160 virtual ~VertexWriter();
161
162 virtual int plotVertex(const tarch::la::Vector<2,double>& position) override;
163 virtual int plotVertex(const tarch::la::Vector<3,double>& position) override;
164
165 virtual void close() override;
166 };
167
173 private:
178
183
188
199
203 std::stringstream _cellOut;
204
208 std::stringstream _cellTypeOut;
209
211
212 CellWriter(const CellWriter& writer):
214 _myWriter(writer._myWriter),
216 _cellOut(),
217 _cellTypeOut() {
218 assertion(false);
219 }
220 public:
221 virtual ~CellWriter();
222
223 virtual int plotHexahedron(int vertexIndex[8]) override;
224
225 virtual int plotQuadrangle(int vertexIndex[4]) override;
226
227 virtual int plotLine(int vertexIndex[2]) override;
228
229 virtual int plotTriangle(int vertexIndex[3]) override;
230
231 virtual int plotPoint(int vertexIndex) override;
232
233 virtual void close() override;
234 };
235
238 private:
243
247 const std::string _identifier;
248
254
259
263 std::stringstream _out;
264
266
267 double _minValue;
268 double _maxValue;
269 CellDataWriter(const std::string& dataIdentifier, VTKBinaryFileWriter& writer, int recordsPerCell);
270
272 _identifier("undef"),
274 _myWriter(copy._myWriter),
275 _out(),
276 _recordsPerCell(-1),
277 _minValue(0.0),
278 _maxValue(0.0) {
279 assertion(false);
280 }
281 public:
283
284 virtual void close() override;
285
286 virtual void plotCell( int index, double value ) override;
287 virtual void plotCell( int index, const tarch::la::Vector<2,double>& value ) override;
288 virtual void plotCell( int index, const tarch::la::Vector<3,double>& value ) override;
289 virtual void plotCell( int index, double* values, int numberOfValues ) override;
290
291 double getMinValue() const;
292 double getMaxValue() const;
293
294 virtual void assignRemainingCellsDefaultValues() override;
295 };
296
299 private:
304
309
314
318 std::stringstream _out;
319
321
322 double _minValue;
323 double _maxValue;
324
325 std::string _identifier;
326
327 VertexDataWriter(const std::string& dataIdentifier, VTKBinaryFileWriter& writer, int recordsPerVertex);
328
331 _myWriter(copy._myWriter),
332 _out(),
334 _minValue(0.0),
335 _maxValue(0.0) {
336 assertion(false);
337 }
338 public:
340
341 virtual void close() override;
342
343 virtual void plotVertex( int index, double value ) override;
344 virtual void plotVertex( int index, const tarch::la::Vector<2,double>& value ) override;
345 virtual void plotVertex( int index, const tarch::la::Vector<3,double>& value ) override;
346 virtual void plotVertex( int index, double* values, int numberOfValues ) override;
347
348 double getMinValue() const;
349 double getMaxValue() const;
350
352 };
353};
354
#define assertion(expr)
Log Device.
Definition Log.h:517
This is the vertex writer you have to create to plot the vertices.
CellDataWriter(const std::string &dataIdentifier, VTKBinaryFileWriter &writer, int recordsPerCell)
int _lastWriteCommandCellNumber
Is set to -1 in the beginning and then incremented by each data plot call.
virtual void plotCell(int index, double value) override
Write data for one cell.
virtual void plotCell(int index, const tarch::la::Vector< 2, double > &value) override
virtual void plotCell(int index, const tarch::la::Vector< 3, double > &value) override
virtual void plotCell(int index, double *values, int numberOfValues) override
virtual void close() override
If you close your writer, each cell/vertex has to be assigned a value, i.e.
int _cellListEntries
The tag CELLS in a vtk file requires the number of total entries in the following list of cell-interc...
virtual void plotVertex(int index, double value) override
Write data for one cell.
virtual void plotVertex(int index, const tarch::la::Vector< 2, double > &value) override
virtual void plotVertex(int index, const tarch::la::Vector< 3, double > &value) override
VertexDataWriter(const std::string &dataIdentifier, VTKBinaryFileWriter &writer, int recordsPerVertex)
virtual void plotVertex(int index, double *values, int numberOfValues) override
This is the vertex writer you have to create to plot the vertices.
VertexWriter(const VertexWriter &writer)
Do not copy a vertex writer.
virtual int plotVertex(const tarch::la::Vector< 3, double > &position) override
virtual int plotVertex(const tarch::la::Vector< 2, double > &position) override
virtual VertexWriter * createVertexWriter() override
Caller has to destroy this instance manually.
virtual void clear() override
Clear the writer, i.e.
virtual CellWriter * createCellWriter() override
Caller has to destroy this instance manually.
virtual CellDataWriter * createCellDataWriter(const std::string &identifier, int recordsPerCell) override
Caller has to destroy this instance manually.
const std::string _doubleOrFloat
either "float" or "double" depending on _precision
virtual VertexDataWriter * createVertexDataWriter(const std::string &identifier, int recordsPerVertex) override
Caller has to destroy this instance manually.
VTKBinaryFileWriter(const std::string &fileName, const std::string &indexFileName, tarch::plotter::PVDTimeSeriesWriter::IndexFileMode modeFile, double timeStamp, const int precision=6)
void validateDataWriterIdentifier(const std::string &identifier) const
Have to include this header, as I need access to the SYCL_EXTERNAL keyword.
Definition accelerator.h:19
Simple vector class.
Definition Vector.h:159