Dune Core Modules (2.4.2)

pvtuwriter.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_GRID_IO_FILE_VTK_PVTUWRITER_HH
5#define DUNE_GRID_IO_FILE_VTK_PVTUWRITER_HH
6
7#include <ostream>
8#include <string>
9
11#include <dune/common/indent.hh>
12
14
15namespace Dune {
16
19
20 namespace VTK {
21
23
60 class PVTUWriter {
61 std::ostream& stream;
62
63 std::string fileType;
64
65 Indent indent;
66
67 public:
69
76 inline PVTUWriter(std::ostream& stream_, FileType fileType_)
77 : stream(stream_)
78 {
79 switch(fileType_) {
80 case polyData :
81 fileType = "PPolyData";
82 break;
83 case unstructuredGrid :
84 fileType = "PUnstructuredGrid";
85 break;
86 default :
87 DUNE_THROW(IOError, "PVTUWriter: Unknown fileType: " << fileType_);
88 }
89 const std::string& byteOrder = getEndiannessString();
90
91 stream << indent << "<?xml version=\"1.0\"?>\n";
92 stream << indent << "<VTKFile"
93 << " type=\"" << fileType << "\""
94 << " version=\"0.1\""
95 << " byte_order=\"" << byteOrder << "\">\n";
96 ++indent;
97 }
98
100 inline ~PVTUWriter() {
101 --indent;
102 stream << indent << "</VTKFile>\n"
103 << std::flush;
104 }
105
107
118 inline void beginPointData(const std::string& scalars = "",
119 const std::string& vectors = "") {
120 stream << indent << "<PPointData";
121 if(scalars != "") stream << " Scalars=\"" << scalars << "\"";
122 if(vectors != "") stream << " Vectors=\"" << vectors << "\"";
123 stream << ">\n";
124 ++indent;
125 }
127 inline void endPointData() {
128 --indent;
129 stream << indent << "</PPointData>\n";
130 }
131
133
144 inline void beginCellData(const std::string& scalars = "",
145 const std::string& vectors = "") {
146 stream << indent << "<PCellData";
147 if(scalars != "") stream << " Scalars=\"" << scalars << "\"";
148 if(vectors != "") stream << " Vectors=\"" << vectors << "\"";
149 stream << ">\n";
150 ++indent;
151 }
153 inline void endCellData() {
154 --indent;
155 stream << indent << "</PCellData>\n";
156 }
157
159
164 inline void beginPoints() {
165 stream << indent << "<PPoints>\n";
166 ++indent;
167 }
169 inline void endPoints() {
170 --indent;
171 stream << indent << "</PPoints>\n";
172 }
173
175
187 inline void beginMain(unsigned ghostLevel = 0) {
188 stream << indent << "<" << fileType
189 << " GhostLevel=\"" << ghostLevel << "\">\n";
190 ++indent;
191 }
193 inline void endMain() {
194 --indent;
195 stream << indent << "</" << fileType << ">\n";
196 }
197
199
204 template<typename T>
205 void addArray(const std::string& name, unsigned ncomps) {
206 TypeName<T> tn;
207 stream << indent << "<PDataArray"
208 << " type=\"" << tn() << "\""
209 << " Name=\"" << name << "\""
210 << " NumberOfComponents=\"" << ncomps << "\"/>\n";
211 }
212
214 inline void addPiece(const std::string& filename) {
215 stream << indent << "<Piece "
216 << " Source=\"" << filename << "\"/>\n";
217 }
218 };
219
220 } // namespace VTK
221
223
224} // namespace Dune
225
226#endif // DUNE_GRID_IO_FILE_VTK_PVTUWRITER_HH
Default exception class for I/O errors.
Definition: exceptions.hh:256
Utility class for handling nested indentation in output.
Definition: indent.hh:51
Dump a .vtu/.vtp files contents to a stream.
Definition: pvtuwriter.hh:60
~PVTUWriter()
write footer
Definition: pvtuwriter.hh:100
void endMain()
finish the main PolyData/UnstructuredGrid section
Definition: pvtuwriter.hh:193
void endCellData()
finish CellData section
Definition: pvtuwriter.hh:153
void addArray(const std::string &name, unsigned ncomps)
Add an array to the output file.
Definition: pvtuwriter.hh:205
void beginMain(unsigned ghostLevel=0)
start the main PPolyData/PUnstructuredGrid section
Definition: pvtuwriter.hh:187
void beginCellData(const std::string &scalars="", const std::string &vectors="")
start CellData section
Definition: pvtuwriter.hh:144
void beginPointData(const std::string &scalars="", const std::string &vectors="")
start PointData section
Definition: pvtuwriter.hh:118
void addPiece(const std::string &filename)
Add a serial piece to the output file.
Definition: pvtuwriter.hh:214
PVTUWriter(std::ostream &stream_, FileType fileType_)
create a PVTUWriter object
Definition: pvtuwriter.hh:76
void endPointData()
finish PointData section
Definition: pvtuwriter.hh:127
void endPoints()
finish section for the point coordinates
Definition: pvtuwriter.hh:169
void beginPoints()
start section for the point coordinates
Definition: pvtuwriter.hh:164
map type to its VTK name in data array
Definition: common.hh:124
Common stuff for the VTKWriter.
FileType
which type of VTK file to write
Definition: common.hh:290
@ polyData
for .vtp files (PolyData)
Definition: common.hh:292
@ unstructuredGrid
for .vtu files (UnstructuredGrid)
Definition: common.hh:294
std::string getEndiannessString()
determine endianness of this C++ implementation
Definition: common.hh:270
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:243
Utility class for handling nested indentation in output.
Dune namespace.
Definition: alignment.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)