6 #ifndef DUNE_GRID_IO_FILE_VTK_DATAARRAYWRITER_HH 7 #define DUNE_GRID_IO_FILE_VTK_DATAARRAYWRITER_HH 16 #include <dune/common/exceptions.hh> 17 #include <dune/common/indent.hh> 74 writeFloat32(data);
break;
76 writeFloat64(data);
break;
78 writeUInt32(data);
break;
80 writeUInt8(data);
break;
82 writeInt32(data);
break;
84 DUNE_THROW(Dune::NotImplemented,
"Unknown precision type");
95 virtual void writeFloat32 (
float data) = 0;
97 virtual void writeFloat64 (
double data) = 0;
99 virtual void writeInt32 (std::int32_t data) = 0;
101 virtual void writeUInt8 (std::uint8_t data) = 0;
103 virtual void writeUInt32 (std::uint32_t data) = 0;
123 int ncomps,
const Indent& indent_,
Precision prec_)
124 :
DataArrayWriter(prec_), s(theStream), counter(0), numPerLine(12), indent(indent_)
126 s << indent <<
"<DataArray type=\"" <<
toString(prec_) <<
"\" " 127 <<
"Name=\"" << name <<
"\" ";
128 s <<
"NumberOfComponents=\"" << ncomps <<
"\" ";
129 s <<
"format=\"ascii\">\n";
136 if (counter%numPerLine!=0) s <<
"\n";
138 s << indent <<
"</DataArray>\n";
143 void writeFloat64 (
double data)
final 144 { write_float(data); }
146 void writeFloat32 (
float data)
final 147 { write_float(data); }
149 void writeInt32 (std::int32_t data)
final 152 void writeUInt32 (std::uint32_t data)
final 155 void writeUInt8 (std::uint8_t data)
final 162 if(counter%numPerLine==0) s << indent;
164 const auto original_precision = std::cout.precision();
165 s << std::setprecision(std::numeric_limits<PT>::digits10) << (PT) data;
166 std::cout.precision(original_precision);
168 if (counter%numPerLine==0) s <<
"\n";
172 void write_float(T data)
175 if(counter%numPerLine==0) s << indent;
177 PT out_data = (PT) data;
178 if (std::fpclassify(out_data) == FP_SUBNORMAL)
183 const auto original_precision = std::cout.precision();
184 s << std::setprecision(std::numeric_limits<PT>::digits10) << out_data;
185 std::cout.precision(original_precision);
187 if (counter%numPerLine==0) s <<
"\n";
213 int ncomps,
int nitems,
const Indent& indent_,
Precision prec_)
214 :
DataArrayWriter(prec_), s(theStream), b64(theStream), indent(indent_)
216 s << indent <<
"<DataArray type=\"" <<
toString(prec_) <<
"\" " 217 <<
"Name=\"" << name <<
"\" ";
218 s <<
"NumberOfComponents=\"" << ncomps <<
"\" ";
219 s <<
"format=\"binary\">\n";
224 std::uint32_t size = ncomps*nitems*
typeSize(prec_);
235 s << indent <<
"</DataArray>\n";
241 void writeFloat64 (
double data)
final 244 void writeFloat32 (
float data)
final 247 void writeInt32 (std::int32_t data)
final 250 void writeUInt32 (std::uint32_t data)
final 253 void writeUInt8 (std::uint8_t data)
final 265 const Indent& indent;
287 int ncomps,
unsigned nitems,
unsigned& offset,
291 s << indent <<
"<DataArray type=\"" <<
toString(prec_) <<
"\" " 292 <<
"Name=\"" << name <<
"\" ";
293 s <<
"NumberOfComponents=\"" << ncomps <<
"\" ";
294 s <<
"format=\"appended\" offset=\""<< offset <<
"\" />\n";
296 offset += ncomps*nitems*
typeSize(prec_);
304 void writeFloat64 (
double)
final {}
305 void writeFloat32 (
float)
final {}
306 void writeInt32 (std::int32_t)
final {}
307 void writeUInt32 (std::uint32_t)
final {}
308 void writeUInt8 (std::uint8_t)
final {}
330 int ncomps,
unsigned nitems,
331 unsigned& offset,
const Indent& indent,
Precision prec_)
334 s << indent <<
"<DataArray type=\"" <<
toString(prec_) <<
"\" " 335 <<
"Name=\"" << name <<
"\" ";
336 s <<
"NumberOfComponents=\"" << ncomps <<
"\" ";
337 s <<
"format=\"appended\" offset=\""<< offset <<
"\" />\n";
339 std::size_t bytes = ncomps*nitems*
typeSize(prec_);
350 void writeFloat64 (
double)
final {}
351 void writeFloat32 (
float)
final {}
352 void writeInt32 (std::int32_t)
final {}
353 void writeUInt32 (std::uint32_t)
final {}
354 void writeUInt8 (std::uint8_t)
final {}
379 std::uint32_t size = ncomps*nitems*
typeSize(prec_);
386 void writeFloat64 (
double data)
final 389 void writeFloat32 (
float data)
final 392 void writeInt32 (std::int32_t data)
final 395 void writeUInt32 (std::uint32_t data)
final 398 void writeUInt8 (std::uint8_t data)
final 434 void writeFloat64 (
double data)
final 437 void writeFloat32 (
float data)
final 440 void writeInt32 (std::int32_t data)
final 443 void writeUInt32 (std::uint32_t data)
final 446 void writeUInt8 (std::uint8_t data)
final 469 enum Phase { main, appended };
472 std::ostream& stream;
489 : type(type_), stream(stream_), offset(0), phase(main)
506 case ascii :
return false;
507 case base64 :
return false;
511 DUNE_THROW(IOError,
"Dune::VTK::DataArrayWriter: unsupported " 512 "OutputType " << type);
517 static const std::string rawString =
"raw";
518 static const std::string base64String =
"base64";
523 DUNE_THROW(IOError,
"DataArrayWriterFactory::appendedEncoding(): No " 524 "appended encoding for OutputType " << type);
528 DUNE_THROW(IOError,
"DataArrayWriterFactory::appendedEncoding(): " 529 "unsupported OutputType " << type);
548 unsigned nitems,
const Indent& indent,
561 nitems, offset, indent, prec);
580 DUNE_THROW(IOError,
"Dune::VTK::DataArrayWriter: unsupported " 581 "OutputType " << type <<
" in phase " << phase);
591 #endif // DUNE_GRID_IO_FILE_VTK_DATAARRAYWRITER_HH NakedBase64DataArrayWriter(std::ostream &theStream, int ncomps, int nitems, Precision prec_)
make a new data array writer
Definition: dataarraywriter.hh:374
void write(T data)
write one element of data
Definition: dataarraywriter.hh:69
virtual ~DataArrayWriter()
virtual destructor
Definition: dataarraywriter.hh:91
DataArrayWriter * make(const std::string &name, unsigned ncomps, unsigned nitems, const Indent &indent, Precision prec)
create a DataArrayWriter
Definition: dataarraywriter.hh:547
~AsciiDataArrayWriter()
finish output; writes end tag
Definition: dataarraywriter.hh:134
const std::string & appendedEncoding() const
query encoding string for appended data
Definition: dataarraywriter.hh:516
std::string toString(Precision p)
map precision to VTK type name
Definition: common.hh:280
void write(T data)
write data to stream
Definition: streams.hh:93
DataArrayWriterFactory(OutputType type_, std::ostream &stream_)
create a DataArrayWriterFactory
Definition: dataarraywriter.hh:488
bool beginAppended()
signal start of the appended section
Definition: dataarraywriter.hh:503
Output is to the file is appended raw binary.
Definition: common.hh:49
virtual bool writeIsNoop() const
whether calls to write may be skipped
Definition: dataarraywriter.hh:89
std::size_t typeSize(Precision p)
map precision to byte size
Definition: common.hh:300
a streaming writer for data array tags, uses appended raw format
Definition: dataarraywriter.hh:269
Output to the file is inline base64 binary.
Definition: common.hh:47
bool writeIsNoop() const
whether calls to write may be skipped
Definition: dataarraywriter.hh:300
base class for data array writers
Definition: dataarraywriter.hh:55
bool writeIsNoop() const
whether calls to write may be skipped
Definition: dataarraywriter.hh:346
Output to the file is in ascii.
Definition: common.hh:45
AppendedRawDataArrayWriter(std::ostream &s, std::string name, int ncomps, unsigned nitems, unsigned &offset, const Indent &indent, Precision prec_)
make a new data array writer
Definition: dataarraywriter.hh:286
a streaming writer for appended data array tags, uses base64 format
Definition: dataarraywriter.hh:363
a streaming writer for data array tags, uses binary inline format
Definition: dataarraywriter.hh:197
Include standard header files.
Definition: agrid.hh:59
write out data in binary
Definition: streams.hh:83
a factory for DataArrayWriters
Definition: dataarraywriter.hh:468
Output is to the file is appended base64 binary.
Definition: common.hh:51
a streaming writer for data array tags, uses appended base64 format
Definition: dataarraywriter.hh:312
void write(X &data)
encode a data item
Definition: streams.hh:42
a streaming writer for data array tags, uses ASCII inline format
Definition: dataarraywriter.hh:109
AppendedBase64DataArrayWriter(std::ostream &s, std::string name, int ncomps, unsigned nitems, unsigned &offset, const Indent &indent, Precision prec_)
make a new data array writer
Definition: dataarraywriter.hh:329
~BinaryDataArrayWriter()
finish output; writes end tag
Definition: dataarraywriter.hh:230
AsciiDataArrayWriter(std::ostream &theStream, std::string name, int ncomps, const Indent &indent_, Precision prec_)
make a new data array writer
Definition: dataarraywriter.hh:122
NakedRawDataArrayWriter(std::ostream &theStream, int ncomps, int nitems, Precision prec_)
make a new data array writer
Definition: dataarraywriter.hh:425
a streaming writer for appended data arrays, uses raw format
Definition: dataarraywriter.hh:412
BinaryDataArrayWriter(std::ostream &theStream, std::string name, int ncomps, int nitems, const Indent &indent_, Precision prec_)
make a new data array writer
Definition: dataarraywriter.hh:212
Common stuff for the VTKWriter.
T Type
type to convert T to before putting it into a stream with <<
Definition: common.hh:97
Precision
which precision to use when writing out data to vtk files
Definition: common.hh:271
DataArrayWriter(Precision _prec)
construct a data array writer
Definition: dataarraywriter.hh:63
OutputType
How the bulk data should be stored in the file.
Definition: common.hh:43
void flush()
flush the current unwritten data to the stream.
Definition: streams.hh:64