Commit 96f8bfb5 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Merge branch 'feature/flexible_header_type' into 'master'

flexible header type

See merge request extensions/dune-vtk!9
parents 015c79eb 8a4544c8
......@@ -25,7 +25,7 @@ class Vtk[Type]Writer
{
public:
// Constructor
Vtk[Type]Writer(GridView, Vtk::FormatTypes = Vtk::BINARY, Vtk::DataTypes = Vtk::FLOAT32);
Vtk[Type]Writer(GridView, Vtk::FormatTypes = Vtk::FormatTypes::BINARY, Vtk::DataTypes = Vtk::DataTypes::FLOAT32);
// Bind data to the writer
Vtk[Type]Writer& addPointData(Function [, std::string name, int numComponents, Vtk::FormatTypes]);
......@@ -37,17 +37,17 @@ public:
```
where `Function` is either a `GridViewFunction`, i.e. supports `bind()`, `unbind()`, and `localFunction(Function)`, or is a legacy `VTKFunction` from Dune-Grid. The optional parameters `name`, `numComponents` and `format` may be given for a `GridViewFunction`.
The parameter `Vtk::FormatTypes` is one of `Vtk::ASCII`, `Vtk::BINARY`, or `Vtk::COMPRESSED` and `Vtk::DataTypes` is one of `Vtk::FLOAT32`, or `Vtk::FLOAT64`. The `[Type]` of a VtkWriter is one of `UnstructuredGrid`, `StructuredGrid`, `RectilinearGrid`, `ImageData`, or `Timeseries`, see below for details. A `DataCollector` may be specified to control how point and cell values are extracted from the `GridView` and the bound data. See `dune/vtk/datacollectors/` of a list of poissible types. The default datacollector extracts a connected grid with continuous data, where points are grid vertices.
The parameter `Vtk::FormatTypes` is one of `Vtk::FormatTypes::ASCII`, `Vtk::FormatTypes::BINARY`, or `Vtk::COMPRESSED` and `Vtk::DataTypes` is one of `Vtk::DataTypes::FLOAT32`, or `Vtk::DataTypes::FLOAT64`. The `[Type]` of a VtkWriter is one of `UnstructuredGrid`, `StructuredGrid`, `RectilinearGrid`, `ImageData`, or `Timeseries`, see below for details. A `DataCollector` may be specified to control how point and cell values are extracted from the `GridView` and the bound data. See `dune/vtk/datacollectors/` of a list of poissible types. The default datacollector extracts a connected grid with continuous data, where points are grid vertices.
See also the `src/` directory for more examples.
## Comparison with Dune::VTKWriter
In Dune-Grid there is a VTK writer available, that is a bit different from the
proposed one. A comparions:
proposed one. A comparison:
| **Property** | **Dune-Grid** | **Dune-Vtk** |
| ------------------ | :-----------: | :----------: |
| VTK version | 0.1 | 1.0 |
| VTK version | 0.1 | 0.1/1.0 |
| UnstructuredGrid | **x** | **x** |
| PolyData | (1d) | - |
| StructuredGrid | - | **x** |
......@@ -110,7 +110,7 @@ format. Supports all VtkWriters for the timestep output. In each timestep a coll
### VtkTimseriesWriter
A timeseries is a collection of timesteps stored in one file, instead of separate
files for each timestep value. Since in the `Vtk::APPENDED` mode, the data is written
files for each timestep value. Since in the `Vtk::FormatTypes::APPENDED` mode, the data is written
as binary blocks in the appended section of the file and references by an offset
in the XML DataArray attributes, it allows to reuse written data. An example of
usage is when the grid points and cells do not change over time, but just the
......
......@@ -51,14 +51,14 @@ namespace Dune
/// Constructor VtkFunction from legacy VTKFunction
/**
* \param fct The VTKFunction to wrap
* \param type The VTK datatype how to write the function values to the output [Vtk::FLOAT64]
* \param type The VTK datatype how to write the function values to the output [Vtk::DataTypes::FLOAT64]
**/
Function (std::shared_ptr<VTKFunction<GridView> const> const& fct,
std::optional<Vtk::DataTypes> type = {})
: localFct_(fct)
, name_(fct->name())
, ncomps_(fct->ncomps())
, type_(type ? *type : Vtk::FLOAT64)
, type_(type ? *type : Vtk::DataTypes::FLOAT32)
{}
/// Construct VtkFunction from dune-functions GridFunction with Signature
......@@ -124,7 +124,7 @@ namespace Dune
Vtk::LocalFunction<GridView> localFct_;
std::string name_;
int ncomps_ = 1;
Vtk::DataTypes type_ = Vtk::FLOAT32;
Vtk::DataTypes type_ = Vtk::DataTypes::FLOAT32;
};
} // end namespace Vtk
......
......@@ -39,7 +39,7 @@ void PvdWriter<W>
assert(out.is_open());
out.imbue(std::locale::classic());
out << std::setprecision(datatype_ == Vtk::FLOAT32
out << std::setprecision(datatype_ == Vtk::DataTypes::FLOAT32
? std::numeric_limits<float>::max_digits10
: std::numeric_limits<double>::max_digits10);
......@@ -66,7 +66,7 @@ std::string PvdWriter<W>
assert(out.is_open());
out.imbue(std::locale::classic());
out << std::setprecision(datatype_ == Vtk::FLOAT32
out << std::setprecision(datatype_ == Vtk::DataTypes::FLOAT32
? std::numeric_limits<float>::max_digits10
: std::numeric_limits<double>::max_digits10);
......@@ -85,7 +85,7 @@ void PvdWriter<W>
out << "<VTKFile"
<< " type=\"Collection\""
<< " version=\"0.1\""
<< (format_ != Vtk::ASCII ? " byte_order=\"" + vtkWriter_.getEndian() + "\"" : "")
<< (format_ != Vtk::FormatTypes::ASCII ? " byte_order=\"" + vtkWriter_.getEndian() + "\"" : "")
<< (format_ == Vtk::COMPRESSED ? " compressor=\"vtkZLibDataCompressor\"" : "")
<< ">\n";
......
......@@ -57,14 +57,14 @@ int testGridView (std::string prefix, Dune::VTKChecker& vtkChecker, GridView con
// ASCII files
{
vtk.setFormat(Dune::Vtk::ASCII);
vtk.setFormat(Dune::Vtk::FormatTypes::ASCII);
std::string name = vtk.write(prefix + "_ascii");
if (gridView.comm().rank() == 0) vtkChecker.push(name);
}
// BINARY files
{
vtk.setFormat(Dune::Vtk::BINARY);
vtk.setFormat(Dune::Vtk::FormatTypes::BINARY);
std::string name = vtk.write(prefix + "_binary");
if (gridView.comm().rank() == 0) vtkChecker.push(name);
}
......
......@@ -39,6 +39,18 @@ std::string to_string (DataTypes type)
}
}
std::string to_string (CompressorTypes type)
{
switch (type) {
case ZLIB: return "vtkZLibDataCompressor";
case LZ4: return "vtkLZ4DataCompressor";
case LZMA: return "vtkLZMADataCompressor";
default:
DUNE_THROW(RangeError, "CompressorTypes not found.");
std::abort();
}
}
GeometryType to_geometry (std::uint8_t cell)
{
switch (cell) {
......
......@@ -39,6 +39,7 @@ namespace Dune
LZ4,
LZMA
};
std::string to_string (CompressorTypes);
enum CellParametrization {
LINEAR,
......
......@@ -42,11 +42,11 @@ template <class Grid, class Creator, class Field>
void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& input, bool fillCreator)
{
clear();
compressor_ = Vtk::NONE;
Vtk::DataTypes header_type = Vtk::UINT32;
compressor_ = Vtk::CompressorTypes::NONE;
Vtk::DataTypes header_type = Vtk::DataTypes::UINT32;
std::string data_id = "";
std::string data_format = "";
Vtk::DataTypes data_type = Vtk::UNKNOWN;
Vtk::DataTypes data_type = Vtk::DataTypes::UNKNOWN;
unsigned int data_components = 0;
std::uint64_t data_offset = 0;
......@@ -64,16 +64,16 @@ void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& inp
VTK_ASSERT_MSG(attr["byte_order"] == "LittleEndian", "LittleEndian byte order supported");
if (attr["header_type"] == "UInt32")
header_type = Vtk::UINT32;
header_type = Vtk::DataTypes::UINT32;
else if (attr["header_type"] == "UInt64")
header_type = Vtk::UINT64;
header_type = Vtk::DataTypes::UINT64;
if (attr["compressor"] == "vtkZLibDataCompressor")
compressor_ = Vtk::ZLIB;
compressor_ = Vtk::CompressorTypes::ZLIB;
else if (attr["compressor"] == "vtkLZ4DataCompressor")
compressor_ = Vtk::LZ4;
compressor_ = Vtk::CompressorTypes::LZ4;
else if (attr["compressor"] == "vtkLZMADataCompressor")
compressor_ = Vtk::LZMA;
compressor_ = Vtk::CompressorTypes::LZMA;
section = VTK_FILE;
}
......@@ -133,9 +133,9 @@ void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& inp
// determine FormatType
data_format = Vtk::to_lower(attr["format"]);
if (data_format == "appended") {
format_ = compressor_ != Vtk::NONE ? Vtk::COMPRESSED : Vtk::BINARY;
format_ = compressor_ != Vtk::CompressorTypes::NONE ? Vtk::FormatTypes::COMPRESSED : Vtk::FormatTypes::BINARY;
} else {
format_ = Vtk::ASCII;
format_ = Vtk::FormatTypes::ASCII;
}
// Offset makes sense in appended mode only
......@@ -249,8 +249,8 @@ void VtkReader<Grid,Creator,Field>::readParallelFileFromStream (std::ifstream& i
{
clear();
[[maybe_unused]] Vtk::DataTypes header_type = Vtk::UINT32;
compressor_ = Vtk::NONE;
[[maybe_unused]] Vtk::DataTypes header_type = Vtk::DataTypes::UINT32;
compressor_ = Vtk::CompressorTypes::NONE;
Sections section = NO_SECTION;
for (std::string line; std::getline(input, line); ) {
......@@ -268,16 +268,16 @@ void VtkReader<Grid,Creator,Field>::readParallelFileFromStream (std::ifstream& i
VTK_ASSERT_MSG(attr["byte_order"] == "LittleEndian", "LittleEndian byte order supported");
if (attr["header_type"] == "UInt32")
header_type = Vtk::UINT32;
header_type = Vtk::DataTypes::UINT32;
else if (attr["header_type"] == "UInt64")
header_type = Vtk::UINT64;
header_type = Vtk::DataTypes::UINT64;
if (attr["compressor"] == "vtkZLibDataCompressor")
compressor_ = Vtk::ZLIB;
compressor_ = Vtk::CompressorTypes::ZLIB;
else if (attr["compressor"] == "vtkLZ4DataCompressor")
compressor_ = Vtk::LZ4;
compressor_ = Vtk::CompressorTypes::LZ4;
else if (attr["compressor"] == "vtkLZMADataCompressor")
compressor_ = Vtk::LZMA;
compressor_ = Vtk::CompressorTypes::LZMA;
section = VTK_FILE;
}
......@@ -511,7 +511,7 @@ void VtkReader<Grid,Creator,Field>::readCellsAppended (MetaType<HeaderType>, std
auto offsets_data = dataArray_["Cells.offsets"];
auto connectivity_data = dataArray_["Cells.connectivity"];
VTK_ASSERT(types_data.type == Vtk::UINT8);
VTK_ASSERT(types_data.type == Vtk::DataTypes::UINT8);
readAppended(input, vec_types, HeaderType(types_data.offset));
VTK_ASSERT(vec_types.size() == numberOfCells_);
......@@ -539,7 +539,7 @@ void VtkReader<Grid,Creator,Field>::readCellsAppended (MetaType<HeaderType>, std
if (dataArray_.count("Cells.global_point_ids") > 0) {
auto point_id_data = dataArray_["Cells.global_point_ids"];
VTK_ASSERT(point_id_data.type == Vtk::UINT64);
VTK_ASSERT(point_id_data.type == Vtk::DataTypes::UINT64);
readAppended(input, vec_point_ids, HeaderType(point_id_data.offset));
VTK_ASSERT(vec_point_ids.size() == numberOfPoints_);
}
......@@ -625,7 +625,7 @@ void VtkReader<Grid,Creator,Field>::readAppended (std::ifstream& input, std::vec
std::vector<HeaderType> cbs; // compressed block sizes
// read total size / block-size(s)
if (compressor_ != Vtk::NONE) {
if (compressor_ != Vtk::CompressorTypes::NONE) {
input.read((char*)&num_blocks, sizeof(HeaderType));
input.read((char*)&block_size, sizeof(HeaderType));
input.read((char*)&last_block_size, sizeof(HeaderType));
......@@ -644,7 +644,7 @@ void VtkReader<Grid,Creator,Field>::readAppended (std::ifstream& input, std::vec
VTK_ASSERT(size > 0 && (size % sizeof(FloatType)) == 0);
values.resize(size / sizeof(FloatType));
if (compressor_ != Vtk::NONE) {
if (compressor_ != Vtk::CompressorTypes::NONE) {
// upper bound for compressed block-size
HeaderType compressed_block_size = block_size + (block_size + 999)/1000 + 12;
// number of values in the full blocks
......@@ -655,13 +655,13 @@ void VtkReader<Grid,Creator,Field>::readAppended (std::ifstream& input, std::vec
HeaderType bs = i < std::size_t(num_blocks-1) ? block_size : last_block_size;
switch (compressor_) {
case Vtk::ZLIB:
case Vtk::CompressorTypes::ZLIB:
read_compressed_zlib(values.data() + i*num_values, buffer_in.data(), bs, cbs[i], input);
break;
case Vtk::LZ4:
case Vtk::CompressorTypes::LZ4:
read_compressed_lz4(values.data() + i*num_values, buffer_in.data(), bs, cbs[i], input);
break;
case Vtk::LZMA:
case Vtk::CompressorTypes::LZMA:
read_compressed_lzma(values.data() + i*num_values, buffer_in.data(), bs, cbs[i], input);
break;
default:
......
......@@ -42,7 +42,7 @@ namespace Dune
VtkTimeseriesWriter (Args&&... args)
: vtkWriter_{std::forward<Args>(args)...}
{
assert(vtkWriter_.format_ != Vtk::ASCII && "Timeseries writer requires APPENDED mode");
assert(vtkWriter_.format_ != Vtk::FormatTypes::ASCII && "Timeseries writer requires APPENDED mode");
std::srand(std::time(nullptr));
// put temporary file to /tmp directory
......
......@@ -104,7 +104,7 @@ std::string VtkTimeseriesWriter<W>
assert(serial_out.is_open());
serial_out.imbue(std::locale::classic());
serial_out << std::setprecision(vtkWriter_.getDatatype() == Vtk::FLOAT32
serial_out << std::setprecision(vtkWriter_.getDatatype() == Vtk::DataTypes::FLOAT32
? std::numeric_limits<float>::digits10+2
: std::numeric_limits<double>::digits10+2);
......@@ -118,7 +118,7 @@ std::string VtkTimeseriesWriter<W>
assert(parallel_out.is_open());
parallel_out.imbue(std::locale::classic());
parallel_out << std::setprecision(vtkWriter_.getDatatype() == Vtk::FLOAT32
parallel_out << std::setprecision(vtkWriter_.getDatatype() == Vtk::DataTypes::FLOAT32
? std::numeric_limits<float>::digits10+2
: std::numeric_limits<double>::digits10+2);
......
......@@ -47,7 +47,7 @@ namespace Dune
// deduction guide
template <class GridView,
class = std::void_t<typename GridView::IndexSet>>
VtkWriter (GridView const&, Vtk::FormatTypes = Vtk::BINARY, Vtk::DataTypes = Vtk::FLOAT32)
VtkWriter (GridView const&, Vtk::FormatTypes = Vtk::FormatTypes::BINARY, Vtk::DataTypes = Vtk::DataTypes::FLOAT32)
-> VtkWriter<GridView>;
......
......@@ -49,30 +49,35 @@ namespace Dune
* the passed gridView.
*
* \param gridView Implementation of Dune::GridView
* \param format Format of the VTK file, either Vtk::BINARY, Vtk::ASCII, or Vtk::COMPRESSED
* \param datatype Output datatype used for coordinates and other global floating point values
* \param format Format of the VTK file, either Vtk::FormatTypes::BINARY, Vtk::FormatTypes::ASCII, or Vtk::COMPRESSED
* \param datatype Data type of a single component of the point coordinates [Vtk::DataTypes::FLOAT32]
* \param headertype Integer type used in binary data headers [Vtk::DataTypes::UINT32]
**/
VtkWriterInterface (GridView const& gridView,
Vtk::FormatTypes format = Vtk::BINARY,
Vtk::DataTypes datatype = Vtk::FLOAT32)
: VtkWriterInterface(std::make_shared<DataCollector>(gridView), format, datatype)
Vtk::FormatTypes format = Vtk::FormatTypes::BINARY,
Vtk::DataTypes datatype = Vtk::DataTypes::FLOAT32,
Vtk::DataTypes headertype = Vtk::DataTypes::UINT32)
: VtkWriterInterface(std::make_shared<DataCollector>(gridView), format, datatype, headertype)
{}
/// \brief Constructor, wraps the passed DataCollector in a non-destroying shared_ptr
VtkWriterInterface (DataCollector& dataCollector,
Vtk::FormatTypes format = Vtk::BINARY,
Vtk::DataTypes datatype = Vtk::FLOAT32)
: VtkWriterInterface(stackobject_to_shared_ptr(dataCollector), format, datatype)
Vtk::FormatTypes format = Vtk::FormatTypes::BINARY,
Vtk::DataTypes datatype = Vtk::DataTypes::FLOAT32,
Vtk::DataTypes headertype = Vtk::DataTypes::UINT32)
: VtkWriterInterface(stackobject_to_shared_ptr(dataCollector), format, datatype, headertype)
{}
/// \brief Constructor, stores the passed DataCollector
VtkWriterInterface (std::shared_ptr<DataCollector> dataCollector,
Vtk::FormatTypes format = Vtk::BINARY,
Vtk::DataTypes datatype = Vtk::FLOAT32)
Vtk::FormatTypes format = Vtk::FormatTypes::BINARY,
Vtk::DataTypes datatype = Vtk::DataTypes::FLOAT32,
Vtk::DataTypes headertype = Vtk::DataTypes::UINT32)
: dataCollector_(std::move(dataCollector))
{
setFormat(format);
setDatatype(datatype);
setHeadertype(headertype);
}
......@@ -120,20 +125,43 @@ namespace Dune
{
format_ = format;
#if !HAVE_VTK_ZLIB
if (format_ == Vtk::COMPRESSED) {
if (format_ == Vtk::FormatTypes::COMPRESSED) {
#if HAVE_VTK_ZLIB
compressor_ = Vtk::CompressorTypes::ZLIB;
#else
std::cout << "Dune is compiled without compression. Falling back to BINARY VTK output!\n";
format_ = Vtk::BINARY;
}
format_ = Vtk::FormatTypes::BINARY;
#endif
} else {
compressor_ = Vtk::CompressorTypes::NONE;
}
}
// Sets the global datatype used for coordinates and other global float values
/// Sets the global datatype used for coordinates and other global float values
void setDatatype (Vtk::DataTypes datatype)
{
datatype_ = datatype;
}
/// Sets the integer type used in binary data headers
void setHeadertype (Vtk::DataTypes datatype)
{
headertype_ = datatype;
}
/// Sets the compressor type used in binary data headers, Additionally a compression
/// level can be passed with level = -1 means: default compression level. Level must be in [0-9]
void setCompressor (Vtk::CompressorTypes compressor, int level = -1)
{
compressor_ = compressor;
compression_level = level;
VTK_ASSERT(level >= -1 && level <= 9);
if (compressor_ != Vtk::CompressorTypes::NONE)
format_ = Vtk::FormatTypes::COMPRESSED;
}
private:
/// Write a serial VTK file in Unstructured format
virtual void writeSerialFile (std::ofstream& out) const = 0;
......@@ -174,8 +202,8 @@ namespace Dune
// Write the `values` in blocks (possibly compressed) to the output
// stream `out`. Return the written block size.
template <class T>
std::uint64_t writeValuesAppended (std::ofstream& out, std::vector<T> const& values) const;
template <class HeaderType, class FloatType>
std::uint64_t writeValuesAppended (std::ofstream& out, std::vector<FloatType> const& values) const;
// Write the `values` in a space and newline separated list of ascii representations.
// The precision is controlled by the datatype and numerical_limits::digits10.
......@@ -224,6 +252,8 @@ namespace Dune
Vtk::FormatTypes format_;
Vtk::DataTypes datatype_;
Vtk::DataTypes headertype_;
Vtk::CompressorTypes compressor_ = Vtk::CompressorTypes::NONE;
// attached data
std::vector<VtkFunction> pointData_;
......
......@@ -17,6 +17,7 @@
#include <dune/geometry/type.hh>
#include <dune/vtk/utility/enum.hh>
#include <dune/vtk/utility/errors.hh>
#include <dune/vtk/utility/filesystem.hh>
#include <dune/vtk/utility/string.hh>
......@@ -51,7 +52,7 @@ std::string VtkWriterInterface<GV,DC>
assert(serial_out.is_open());
serial_out.imbue(std::locale::classic());
serial_out << std::setprecision(datatype_ == Vtk::FLOAT32
serial_out << std::setprecision(datatype_ == Vtk::DataTypes::FLOAT32
? std::numeric_limits<float>::max_digits10
: std::numeric_limits<double>::max_digits10);
......@@ -65,7 +66,7 @@ std::string VtkWriterInterface<GV,DC>
assert(parallel_out.is_open());
parallel_out.imbue(std::locale::classic());
parallel_out << std::setprecision(datatype_ == Vtk::FLOAT32
parallel_out << std::setprecision(datatype_ == Vtk::DataTypes::FLOAT32
? std::numeric_limits<float>::max_digits10
: std::numeric_limits<double>::max_digits10);
......@@ -83,11 +84,11 @@ void VtkWriterInterface<GV,DC>
std::optional<std::size_t> timestep) const
{
out << "<DataArray Name=\"" << fct.name() << "\" type=\"" << to_string(fct.type()) << "\""
<< " NumberOfComponents=\"" << fct.ncomps() << "\" format=\"" << (format_ == Vtk::ASCII ? "ascii\"" : "appended\"");
<< " NumberOfComponents=\"" << fct.ncomps() << "\" format=\"" << (format_ == Vtk::FormatTypes::ASCII ? "ascii\"" : "appended\"");
if (timestep)
out << " TimeStep=\"" << *timestep << "\"";
if (format_ == Vtk::ASCII) {
if (format_ == Vtk::FormatTypes::ASCII) {
out << ">\n";
if (type == POINT_DATA)
writeValuesAscii(out, dataCollector_->template pointData<double>(fct));
......@@ -109,11 +110,11 @@ void VtkWriterInterface<GV,DC>
std::optional<std::size_t> timestep) const
{
out << "<DataArray type=\"" << to_string(datatype_) << "\""
<< " NumberOfComponents=\"3\" format=\"" << (format_ == Vtk::ASCII ? "ascii\"" : "appended\"");
<< " NumberOfComponents=\"3\" format=\"" << (format_ == Vtk::FormatTypes::ASCII ? "ascii\"" : "appended\"");
if (timestep)
out << " TimeStep=\"" << *timestep << "\"";
if (format_ == Vtk::ASCII) {
if (format_ == Vtk::FormatTypes::ASCII) {
out << ">\n";
writeValuesAscii(out, dataCollector_->template points<double>());
out << "</DataArray>\n";
......@@ -125,19 +126,27 @@ void VtkWriterInterface<GV,DC>
}
}
template <class GV, class DC>
void VtkWriterInterface<GV,DC>
::writeDataAppended (std::ofstream& out, std::vector<std::uint64_t>& blocks) const
{
for (auto const& v : pointData_) {
blocks.push_back( v.type() == Vtk::FLOAT32
? this->writeValuesAppended(out, dataCollector_->template pointData<float>(v))
: this->writeValuesAppended(out, dataCollector_->template pointData<double>(v)));
Vtk::mapDataTypes<std::is_floating_point, std::is_integral>(v.type(), headertype_,
[&](auto f, auto h) {
using F = typename decltype(f)::type;
using H = typename decltype(h)::type;
blocks.push_back(this->template writeValuesAppended<H>(out, dataCollector_->template pointData<F>(v)));
});
}
for (auto const& v : cellData_) {
blocks.push_back( v.type() == Vtk::FLOAT32
? this->writeValuesAppended(out, dataCollector_->template cellData<float>(v))
: this->writeValuesAppended(out, dataCollector_->template cellData<double>(v)));
Vtk::mapDataTypes<std::is_floating_point, std::is_integral>(v.type(), headertype_,
[&](auto f, auto h) {
using F = typename decltype(f)::type;
using H = typename decltype(h)::type;
blocks.push_back(this->template writeValuesAppended<H>(out, dataCollector_->template cellData<F>(v)));
});
}
}
......@@ -146,7 +155,7 @@ template <class GV, class DC>
void VtkWriterInterface<GV,DC>
::writeAppended (std::ofstream& out, std::vector<pos_type> const& offsets) const
{
if (is_a(format_, Vtk::APPENDED)) {
if (is_a(format_, Vtk::FormatTypes::APPENDED)) {
out << "<AppendedData encoding=\"raw\">\n_";
std::vector<std::uint64_t> blocks;
writeGridAppended(out, blocks);
......@@ -182,7 +191,7 @@ template <class GV, class DC>
void VtkWriterInterface<GV,DC>
::writeValuesAscii (std::ofstream& out, std::vector<T> const& values) const
{
assert(is_a(format_, Vtk::ASCII) && "Function should by called only in ascii mode!\n");
assert(is_a(format_, Vtk::FormatTypes::ASCII) && "Function should by called only in ascii mode!\n");
std::size_t i = 0;
for (auto const& v : values)
out << Impl::printable(v) << (++i % 6 != 0 ? ' ' : '\n');
......@@ -197,11 +206,11 @@ void VtkWriterInterface<GV,DC>
out << "<VTKFile"
<< " type=\"" << type << "\""
<< " version=\"1.0\""
<< " header_type=\"UInt64\"";
if (format_ != Vtk::ASCII)
<< " header_type=\"" << to_string(headertype_) << "\"";
if (format_ != Vtk::FormatTypes::ASCII)
out << " byte_order=\"" << getEndian() << "\"";
if (format_ == Vtk::COMPRESSED)
out << " compressor=\"vtkZLibDataCompressor\"";
if (compressor_ != Vtk::CompressorTypes::NONE)
out << " compressor=\"" << to_string(compressor_) << "\"";
out << ">\n";
}
......@@ -218,10 +227,8 @@ std::uint64_t writeValuesToBuffer (std::size_t max_num_values, unsigned char* bu
return bs;
}
template <class OStream>
std::uint64_t writeCompressed (unsigned char const* buffer, unsigned char* buffer_out,
std::uint64_t bs, std::uint64_t cbs, int level, OStream& outb)
inline std::uint64_t compressBuffer_zlib (unsigned char const* buffer, unsigned char* buffer_out,
std::uint64_t bs, std::uint64_t cbs, int level)
{
#if HAVE_VTK_ZLIB
uLongf uncompressed_space = uLongf(bs);
......@@ -233,8 +240,6 @@ std::uint64_t writeCompressed (unsigned char const* buffer, unsigned char* buffe
if (compress2(out, &compressed_space, in, uncompressed_space, level) != Z_OK) {
std::cerr << "Zlib error while compressing data.\n";
std::abort();
} else {
outb.write((char*)out, compressed_space);
}
return compressed_space;
......@@ -245,55 +250,97 @@ std::uint64_t writeCompressed (unsigned char const* buffer, unsigned char* buffe
#endif
}
inline std::uint64_t compressBuffer_lz4 (unsigned char const* /* buffer */, unsigned char* /* buffer_out */,
std::uint64_t /* bs */, std::uint64_t /* cbs */, int /* level */)
{
#if HAVE_VTK_LZ4
std::cerr << "LZ4 Compression not yet implemented" << std::endl;
std::abort();
return 0;
#else
std::cerr << "LZ4 Compression not supported. Provide the LZ4 package to CMake." << std::endl;
std::abort();
return 0;
#endif
}
inline std::uint64_t compressBuffer_lzma (unsigned char const* /* buffer */, unsigned char* /* buffer_out */,
std::uint64_t /* bs */, std::uint64_t /* cbs */, int /* level */)
{
#if HAVE_VTK_LZMA
std::cerr << "LZMA Compression not yet implemented" << std::endl;
std::abort();
return 0;
#else
std::cerr << "LZMA Compression not supported. Provide the LZMA package to CMake." << std::endl;
std::abort();
return 0;
#endif
}
} // end namespace Impl
template <class GV, class DC>
template <class T>
template <class HeaderType, class FloatType>