Commit 015c79eb authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Merge branch 'issue/dune_grid_files' into 'master'

Implement reader for dune-grid vtu files

See merge request extensions/dune-vtk!8
parents 0a3e5716 fb2d5501
...@@ -33,6 +33,13 @@ namespace Dune ...@@ -33,6 +33,13 @@ namespace Dune
}; };
std::string to_string (DataTypes); std::string to_string (DataTypes);
enum CompressorTypes {
NONE = 0,
ZLIB,
LZ4,
LZMA
};
enum CellParametrization { enum CellParametrization {
LINEAR, LINEAR,
QUADRATIC, QUADRATIC,
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <vector> #include <vector>
#include <dune/common/shared_ptr.hh> #include <dune/common/shared_ptr.hh>
#include <dune/common/typelist.hh>
#include <dune/common/typeutilities.hh> #include <dune/common/typeutilities.hh>
#include <dune/vtk/filereader.hh> #include <dune/vtk/filereader.hh>
...@@ -165,35 +166,35 @@ namespace Dune ...@@ -165,35 +166,35 @@ namespace Dune
#endif #endif
private: private:
// Read values stored on the cells with name `name` // Read values stored on the cells with ID `id`
Sections readCellData (std::ifstream& /*input*/, std::string /*name*/); Sections readCellData (std::ifstream& input, std::string id);
template <class T> template <class F, class H>
void readCellDataAppended (std::ifstream& /*input*/, std::string /*name*/); void readCellDataAppended (MetaType<F>, MetaType<H>, std::ifstream& input, std::string id);
// Read values stored on the points with name `name` // Read values stored on the points with ID `id`
Sections readPointData (std::ifstream& /*input*/, std::string /*name*/); Sections readPointData (std::ifstream& input, std::string id);
template <class T> template <class F, class H>
void readPointDataAppended (std::ifstream& /*input*/, std::string /*name*/); void readPointDataAppended (MetaType<F>, MetaType<H>, std::ifstream& input, std::string id);
// Read vertex coordinates from `input` stream and store in into `factory` // Read vertex coordinates from `input` stream and store in into `factory`
Sections readPoints (std::ifstream& input, std::string name); Sections readPoints (std::ifstream& input, std::string id);
template <class T> template <class F, class H>
void readPointsAppended (std::ifstream& input); void readPointsAppended (MetaType<F>, MetaType<H>, std::ifstream& input);
// Read cell type, cell offsets and connectivity from `input` stream // Read cell type, cell offsets and connectivity from `input` stream
Sections readCells (std::ifstream& input, std::string name); Sections readCells (std::ifstream& input, std::string id);
void readCellsAppended (std::ifstream& input);
template <class H>
void readCellsAppended (MetaType<H>, std::ifstream& input);
// Read data from appended section in vtk file, starting from `offset` // Read data from appended section in vtk file, starting from `offset`
template <class T> template <class FloatType, class HeaderType>
void readAppended (std::ifstream& input, std::vector<T>& values, std::uint64_t offset); void readAppended (std::ifstream& input, std::vector<FloatType>& values, HeaderType offset);
// Test whether line belongs to section // Test whether line belongs to section
bool isSection (std::string line, bool isSection (std::string line,
...@@ -230,6 +231,9 @@ namespace Dune ...@@ -230,6 +231,9 @@ namespace Dune
/// Data format, i.e. ASCII, BINARY or COMPRESSED. Read from xml attributes. /// Data format, i.e. ASCII, BINARY or COMPRESSED. Read from xml attributes.
Vtk::FormatTypes format_; Vtk::FormatTypes format_;
/// Type of compression algorithm used for binary data
Vtk::CompressorTypes compressor_;
// Temporary data to construct the grid elements // Temporary data to construct the grid elements
std::vector<GlobalCoordinate> vec_points; std::vector<GlobalCoordinate> vec_points;
std::vector<std::uint64_t> vec_point_ids; //< Global unique vertex ID std::vector<std::uint64_t> vec_point_ids; //< Global unique vertex ID
......
...@@ -42,8 +42,10 @@ template <class Grid, class Creator, class Field> ...@@ -42,8 +42,10 @@ template <class Grid, class Creator, class Field>
void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& input, bool fillCreator) void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& input, bool fillCreator)
{ {
clear(); clear();
std::string compressor = ""; compressor_ = Vtk::NONE;
std::string data_id = "", data_format = ""; Vtk::DataTypes header_type = Vtk::UINT32;
std::string data_id = "";
std::string data_format = "";
Vtk::DataTypes data_type = Vtk::UNKNOWN; Vtk::DataTypes data_type = Vtk::UNKNOWN;
unsigned int data_components = 0; unsigned int data_components = 0;
std::uint64_t data_offset = 0; std::uint64_t data_offset = 0;
...@@ -58,20 +60,27 @@ void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& inp ...@@ -58,20 +60,27 @@ void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& inp
if (!attr["type"].empty()) if (!attr["type"].empty())
VTK_ASSERT_MSG(attr["type"] == "UnstructuredGrid", "VtkReader supports UnstructuredGrid types"); VTK_ASSERT_MSG(attr["type"] == "UnstructuredGrid", "VtkReader supports UnstructuredGrid types");
if (!attr["version"].empty())
VTK_ASSERT_MSG(std::stod(attr["version"]) == 1.0, "File format must be 1.0");
if (!attr["byte_order"].empty()) if (!attr["byte_order"].empty())
VTK_ASSERT_MSG(attr["byte_order"] == "LittleEndian", "LittleEndian byte order supported"); VTK_ASSERT_MSG(attr["byte_order"] == "LittleEndian", "LittleEndian byte order supported");
if (!attr["header_type"].empty())
VTK_ASSERT_MSG(attr["header_type"] == "UInt64", "Header integer type must be UInt64"); if (attr["header_type"] == "UInt32")
if (!attr["compressor"].empty()) { header_type = Vtk::UINT32;
compressor = attr["compressor"]; else if (attr["header_type"] == "UInt64")
VTK_ASSERT_MSG(compressor == "vtkZLibDataCompressor", "Only ZLib compression supported"); header_type = Vtk::UINT64;
}
if (attr["compressor"] == "vtkZLibDataCompressor")
compressor_ = Vtk::ZLIB;
else if (attr["compressor"] == "vtkLZ4DataCompressor")
compressor_ = Vtk::LZ4;
else if (attr["compressor"] == "vtkLZMADataCompressor")
compressor_ = Vtk::LZMA;
section = VTK_FILE; section = VTK_FILE;
} }
else if (isSection(line, "/VTKFile", section, VTK_FILE)) else if (isSection(line, "/VTKFile", section, VTK_FILE)) {
section = NO_SECTION; section = NO_SECTION;
break;
}
else if (isSection(line, "UnstructuredGrid", section, VTK_FILE)) else if (isSection(line, "UnstructuredGrid", section, VTK_FILE))
section = UNSTRUCTURED_GRID; section = UNSTRUCTURED_GRID;
else if (isSection(line, "/UnstructuredGrid", section, UNSTRUCTURED_GRID)) else if (isSection(line, "/UnstructuredGrid", section, UNSTRUCTURED_GRID))
...@@ -124,7 +133,7 @@ void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& inp ...@@ -124,7 +133,7 @@ void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& inp
// determine FormatType // determine FormatType
data_format = Vtk::to_lower(attr["format"]); data_format = Vtk::to_lower(attr["format"]);
if (data_format == "appended") { if (data_format == "appended") {
format_ = !compressor.empty() ? Vtk::COMPRESSED : Vtk::BINARY; format_ = compressor_ != Vtk::NONE ? Vtk::COMPRESSED : Vtk::BINARY;
} else { } else {
format_ = Vtk::ASCII; format_ = Vtk::ASCII;
} }
...@@ -181,30 +190,30 @@ void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& inp ...@@ -181,30 +190,30 @@ void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& inp
VTK_ASSERT_MSG(attr["encoding"] == "raw", "base64 encoding not supported"); VTK_ASSERT_MSG(attr["encoding"] == "raw", "base64 encoding not supported");
offset0_ = findAppendedDataPosition(input); offset0_ = findAppendedDataPosition(input);
if (dataArray_["Points"].type == Vtk::FLOAT32) Vtk::mapDataTypes<std::is_floating_point, std::is_integral>(dataArray_["Points"].type, header_type,
readPointsAppended<float>(input); [&](auto f, auto h) {
else this->readPointsAppended(f,h,input);
readPointsAppended<double>(input); this->readCellsAppended(h,input);
});
readCellsAppended(input);
// read point an cell data // read point and cell data
for (auto const& [id,data] : dataArray_) { for (auto const& d : dataArray_) {
if (data.section == POINT_DATA) { if (d.second.section == POINT_DATA) {
if (data.type == Vtk::FLOAT32) Vtk::mapDataTypes<std::is_floating_point, std::is_integral>(d.second.type, header_type,
readPointDataAppended<float>(input, id); [&](auto f, auto h) {
else this->readPointDataAppended(f,h,input,d.first);
readPointDataAppended<double>(input, id); });
} }
else if (data.section == CELL_DATA) { else if (d.second.section == CELL_DATA) {
if (data.type == Vtk::FLOAT32) Vtk::mapDataTypes<std::is_floating_point, std::is_integral>(d.second.type, header_type,
readCellDataAppended<float>(input, id); [&](auto f, auto h) {
else this->readCellDataAppended(f,h,input,d.first);
readCellDataAppended<double>(input, id); });
} }
} }
section = NO_SECTION; // finish reading after appended section section = NO_SECTION; // finish reading after appended section
break;
} }
else if (isSection(line, "/AppendedData", section, APPENDED_DATA)) else if (isSection(line, "/AppendedData", section, APPENDED_DATA))
section = VTK_FILE; section = VTK_FILE;
...@@ -223,12 +232,8 @@ void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& inp ...@@ -223,12 +232,8 @@ void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& inp
section = readCells(input, data_id); section = readCells(input, data_id);
break; break;
default: default:
// do nothing
break; break;
} }
if (section == NO_SECTION)
break;
} }
if (section != NO_SECTION) if (section != NO_SECTION)
...@@ -240,10 +245,13 @@ void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& inp ...@@ -240,10 +245,13 @@ void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& inp
template <class Grid, class Creator, class Field> template <class Grid, class Creator, class Field>
void VtkReader<Grid,Creator,Field>::readParallelFileFromStream (std::ifstream& input, int commRank, int commSize, bool fillCreator) void VtkReader<Grid,Creator,Field>::readParallelFileFromStream (std::ifstream& input, int /* commRank */, int /* commSize */, bool fillCreator)
{ {
clear(); clear();
[[maybe_unused]] Vtk::DataTypes header_type = Vtk::UINT32;
compressor_ = Vtk::NONE;
Sections section = NO_SECTION; Sections section = NO_SECTION;
for (std::string line; std::getline(input, line); ) { for (std::string line; std::getline(input, line); ) {
Vtk::ltrim(line); Vtk::ltrim(line);
...@@ -258,15 +266,25 @@ void VtkReader<Grid,Creator,Field>::readParallelFileFromStream (std::ifstream& i ...@@ -258,15 +266,25 @@ void VtkReader<Grid,Creator,Field>::readParallelFileFromStream (std::ifstream& i
VTK_ASSERT_MSG(std::stod(attr["version"]) == 1.0, "File format must be 1.0"); VTK_ASSERT_MSG(std::stod(attr["version"]) == 1.0, "File format must be 1.0");
if (!attr["byte_order"].empty()) if (!attr["byte_order"].empty())
VTK_ASSERT_MSG(attr["byte_order"] == "LittleEndian", "LittleEndian byte order supported"); VTK_ASSERT_MSG(attr["byte_order"] == "LittleEndian", "LittleEndian byte order supported");
if (!attr["header_type"].empty())
VTK_ASSERT_MSG(attr["header_type"] == "UInt64", "Header integer type must be UInt64"); if (attr["header_type"] == "UInt32")
if (!attr["compressor"].empty()) header_type = Vtk::UINT32;
VTK_ASSERT_MSG(attr["compressor"] == "vtkZLibDataCompressor", "Only ZLib compression supported"); else if (attr["header_type"] == "UInt64")
header_type = Vtk::UINT64;
if (attr["compressor"] == "vtkZLibDataCompressor")
compressor_ = Vtk::ZLIB;
else if (attr["compressor"] == "vtkLZ4DataCompressor")
compressor_ = Vtk::LZ4;
else if (attr["compressor"] == "vtkLZMADataCompressor")
compressor_ = Vtk::LZMA;
section = VTK_FILE; section = VTK_FILE;
} }
else if (isSection(line, "/VTKFile", section, VTK_FILE)) else if (isSection(line, "/VTKFile", section, VTK_FILE)) {
section = NO_SECTION; section = NO_SECTION;
else if (isSection(line, "PUnstructuredGrid", section, VTK_FILE)) break;
} else if (isSection(line, "PUnstructuredGrid", section, VTK_FILE))
section = UNSTRUCTURED_GRID; section = UNSTRUCTURED_GRID;
else if (isSection(line, "/PUnstructuredGrid", section, UNSTRUCTURED_GRID)) else if (isSection(line, "/PUnstructuredGrid", section, UNSTRUCTURED_GRID))
section = VTK_FILE; section = VTK_FILE;
...@@ -277,9 +295,6 @@ void VtkReader<Grid,Creator,Field>::readParallelFileFromStream (std::ifstream& i ...@@ -277,9 +295,6 @@ void VtkReader<Grid,Creator,Field>::readParallelFileFromStream (std::ifstream& i
VTK_ASSERT_MSG(attr.count("Source") > 0, "No source files for partitions provided"); VTK_ASSERT_MSG(attr.count("Source") > 0, "No source files for partitions provided");
pieces_.push_back(attr["Source"]); pieces_.push_back(attr["Source"]);
} }
if (section == NO_SECTION)
break;
} }
VTK_ASSERT_MSG(section == NO_SECTION, "VTK-File is incomplete. It must end with </VTKFile>!"); VTK_ASSERT_MSG(section == NO_SECTION, "VTK-File is incomplete. It must end with </VTKFile>!");
...@@ -357,14 +372,14 @@ VtkReader<Grid,Creator,Field>::readCellData (std::ifstream& input, std::string i ...@@ -357,14 +372,14 @@ VtkReader<Grid,Creator,Field>::readCellData (std::ifstream& input, std::string i
template <class Grid, class Creator, class Field> template <class Grid, class Creator, class Field>
template <class T> template <class FloatType, class HeaderType>
void VtkReader<Grid,Creator,Field>::readCellDataAppended (std::ifstream& input, std::string id) void VtkReader<Grid,Creator,Field>::readCellDataAppended (MetaType<FloatType>, MetaType<HeaderType>, std::ifstream& input, std::string id)
{ {
VTK_ASSERT(numberOfCells_ > 0); VTK_ASSERT(numberOfCells_ > 0);
unsigned int components = dataArray_[id].components; unsigned int components = dataArray_[id].components;
std::vector<T> values; std::vector<FloatType> values;
readAppended(input, values, dataArray_[id].offset); readAppended(input, values, HeaderType(dataArray_[id].offset));
VTK_ASSERT(values.size() == components*numberOfCells_); VTK_ASSERT(values.size() == components*numberOfCells_);
cellData_[id].resize(values.size()); cellData_[id].resize(values.size());
...@@ -392,14 +407,14 @@ VtkReader<Grid,Creator,Field>::readPointData (std::ifstream& input, std::string ...@@ -392,14 +407,14 @@ VtkReader<Grid,Creator,Field>::readPointData (std::ifstream& input, std::string
template <class Grid, class Creator, class Field> template <class Grid, class Creator, class Field>
template <class T> template <class FloatType, class HeaderType>
void VtkReader<Grid,Creator,Field>::readPointDataAppended (std::ifstream& input, std::string id) void VtkReader<Grid,Creator,Field>::readPointDataAppended (MetaType<FloatType>, MetaType<HeaderType>, std::ifstream& input, std::string id)
{ {
VTK_ASSERT(numberOfPoints_ > 0); VTK_ASSERT(numberOfPoints_ > 0);
unsigned int components = dataArray_[id].components; unsigned int components = dataArray_[id].components;
std::vector<T> values; std::vector<FloatType> values;
readAppended(input, values, dataArray_[id].offset); readAppended(input, values, HeaderType(dataArray_[id].offset));
VTK_ASSERT(values.size() == components*numberOfPoints_); VTK_ASSERT(values.size() == components*numberOfPoints_);
pointData_[id].resize(values.size()); pointData_[id].resize(values.size());
...@@ -413,6 +428,7 @@ VtkReader<Grid,Creator,Field>::readPoints (std::ifstream& input, std::string id) ...@@ -413,6 +428,7 @@ VtkReader<Grid,Creator,Field>::readPoints (std::ifstream& input, std::string id)
{ {
using T = typename GlobalCoordinate::value_type; using T = typename GlobalCoordinate::value_type;
VTK_ASSERT(numberOfPoints_ > 0); VTK_ASSERT(numberOfPoints_ > 0);
VTK_ASSERT(id == "Points");
VTK_ASSERT(dataArray_["Points"].components == 3u); VTK_ASSERT(dataArray_["Points"].components == 3u);
Sections sec; Sections sec;
...@@ -440,13 +456,13 @@ VtkReader<Grid,Creator,Field>::readPoints (std::ifstream& input, std::string id) ...@@ -440,13 +456,13 @@ VtkReader<Grid,Creator,Field>::readPoints (std::ifstream& input, std::string id)
template <class Grid, class Creator, class Field> template <class Grid, class Creator, class Field>
template <class T> template <class FloatType, class HeaderType>
void VtkReader<Grid,Creator,Field>::readPointsAppended (std::ifstream& input) void VtkReader<Grid,Creator,Field>::readPointsAppended (MetaType<FloatType>, MetaType<HeaderType>, std::ifstream& input)
{ {
VTK_ASSERT(numberOfPoints_ > 0); VTK_ASSERT(numberOfPoints_ > 0);
VTK_ASSERT(dataArray_["Points"].components == 3u); VTK_ASSERT(dataArray_["Points"].components == 3u);
std::vector<T> point_values; std::vector<FloatType> point_values;
readAppended(input, point_values, dataArray_["Points"].offset); readAppended(input, point_values, HeaderType(dataArray_["Points"].offset));
VTK_ASSERT(point_values.size() == 3*numberOfPoints_); VTK_ASSERT(point_values.size() == 3*numberOfPoints_);
// extract points from continuous values // extract points from continuous values
...@@ -455,7 +471,7 @@ void VtkReader<Grid,Creator,Field>::readPointsAppended (std::ifstream& input) ...@@ -455,7 +471,7 @@ void VtkReader<Grid,Creator,Field>::readPointsAppended (std::ifstream& input)
std::size_t idx = 0; std::size_t idx = 0;
for (std::size_t i = 0; i < numberOfPoints_; ++i) { for (std::size_t i = 0; i < numberOfPoints_; ++i) {
for (std::size_t j = 0; j < p.size(); ++j) for (std::size_t j = 0; j < p.size(); ++j)
p[j] = T(point_values[idx++]); p[j] = FloatType(point_values[idx++]);
idx += (3u - p.size()); idx += (3u - p.size());
vec_points.push_back(p); vec_points.push_back(p);
} }
...@@ -487,7 +503,8 @@ VtkReader<Grid,Creator,Field>::readCells (std::ifstream& input, std::string id) ...@@ -487,7 +503,8 @@ VtkReader<Grid,Creator,Field>::readCells (std::ifstream& input, std::string id)
template <class Grid, class Creator, class Field> template <class Grid, class Creator, class Field>
void VtkReader<Grid,Creator,Field>::readCellsAppended (std::ifstream& input) template <class HeaderType>
void VtkReader<Grid,Creator,Field>::readCellsAppended (MetaType<HeaderType>, std::ifstream& input)
{ {
VTK_ASSERT(numberOfCells_ > 0); VTK_ASSERT(numberOfCells_ > 0);
auto types_data = dataArray_["Cells.types"]; auto types_data = dataArray_["Cells.types"];
...@@ -495,14 +512,14 @@ void VtkReader<Grid,Creator,Field>::readCellsAppended (std::ifstream& input) ...@@ -495,14 +512,14 @@ void VtkReader<Grid,Creator,Field>::readCellsAppended (std::ifstream& input)
auto connectivity_data = dataArray_["Cells.connectivity"]; auto connectivity_data = dataArray_["Cells.connectivity"];
VTK_ASSERT(types_data.type == Vtk::UINT8); VTK_ASSERT(types_data.type == Vtk::UINT8);
readAppended(input, vec_types, types_data.offset); readAppended(input, vec_types, HeaderType(types_data.offset));
VTK_ASSERT(vec_types.size() == numberOfCells_); VTK_ASSERT(vec_types.size() == numberOfCells_);
if (offsets_data.type == Vtk::INT64) if (offsets_data.type == Vtk::INT64)
readAppended(input, vec_offsets, offsets_data.offset); readAppended(input, vec_offsets, HeaderType(offsets_data.offset));
else if (offsets_data.type == Vtk::INT32) { else if (offsets_data.type == Vtk::INT32) {
std::vector<std::int32_t> offsets; std::vector<std::int32_t> offsets;
readAppended(input, offsets, offsets_data.offset); readAppended(input, offsets, HeaderType(offsets_data.offset));
vec_offsets.resize(offsets.size()); vec_offsets.resize(offsets.size());
std::copy(offsets.begin(), offsets.end(), vec_offsets.begin()); std::copy(offsets.begin(), offsets.end(), vec_offsets.begin());
} }
...@@ -510,10 +527,10 @@ void VtkReader<Grid,Creator,Field>::readCellsAppended (std::ifstream& input) ...@@ -510,10 +527,10 @@ void VtkReader<Grid,Creator,Field>::readCellsAppended (std::ifstream& input)
VTK_ASSERT(vec_offsets.size() == numberOfCells_); VTK_ASSERT(vec_offsets.size() == numberOfCells_);
if (connectivity_data.type == Vtk::INT64) if (connectivity_data.type == Vtk::INT64)
readAppended(input, vec_connectivity, connectivity_data.offset); readAppended(input, vec_connectivity, HeaderType(connectivity_data.offset));
else if (connectivity_data.type == Vtk::INT32) { else if (connectivity_data.type == Vtk::INT32) {
std::vector<std::int32_t> connectivity; std::vector<std::int32_t> connectivity;
readAppended(input, connectivity, connectivity_data.offset); readAppended(input, connectivity, HeaderType(connectivity_data.offset));
vec_connectivity.resize(connectivity.size()); vec_connectivity.resize(connectivity.size());
std::copy(connectivity.begin(), connectivity.end(), vec_connectivity.begin()); std::copy(connectivity.begin(), connectivity.end(), vec_connectivity.begin());
} }
...@@ -523,13 +540,15 @@ void VtkReader<Grid,Creator,Field>::readCellsAppended (std::ifstream& input) ...@@ -523,13 +540,15 @@ void VtkReader<Grid,Creator,Field>::readCellsAppended (std::ifstream& input)
if (dataArray_.count("Cells.global_point_ids") > 0) { if (dataArray_.count("Cells.global_point_ids") > 0) {
auto point_id_data = dataArray_["Cells.global_point_ids"]; auto point_id_data = dataArray_["Cells.global_point_ids"];
VTK_ASSERT(point_id_data.type == Vtk::UINT64); VTK_ASSERT(point_id_data.type == Vtk::UINT64);
readAppended(input, vec_point_ids, point_id_data.offset); readAppended(input, vec_point_ids, HeaderType(point_id_data.offset));
VTK_ASSERT(vec_point_ids.size() == numberOfPoints_); VTK_ASSERT(vec_point_ids.size() == numberOfPoints_);
} }
} }
// @{ implementation detail // @{ implementation detail
namespace {
/** /**
* Read compressed data into `buffer_in`, uncompress it and store the result in * Read compressed data into `buffer_in`, uncompress it and store the result in
* the concrete-data-type `buffer` * the concrete-data-type `buffer`
...@@ -538,7 +557,7 @@ void VtkReader<Grid,Creator,Field>::readCellsAppended (std::ifstream& input) ...@@ -538,7 +557,7 @@ void VtkReader<Grid,Creator,Field>::readCellsAppended (std::ifstream& input)
* \param input Stream to read from. * \param input Stream to read from.
**/ **/
template <class T, class IStream> template <class T, class IStream>
void read_compressed (T* buffer, unsigned char* buffer_in, void read_compressed_zlib (T* buffer, unsigned char* buffer_in,
std::uint64_t bs, std::uint64_t cbs, IStream& input) std::uint64_t bs, std::uint64_t cbs, IStream& input)
{ {
#if HAVE_VTK_ZLIB #if HAVE_VTK_ZLIB
...@@ -557,56 +576,98 @@ void read_compressed (T* buffer, unsigned char* buffer_in, ...@@ -557,56 +576,98 @@ void read_compressed (T* buffer, unsigned char* buffer_in,
} }
VTK_ASSERT(uLongf(bs) == uncompressed_space); VTK_ASSERT(uLongf(bs) == uncompressed_space);
#else #else
std::cerr << "Can not call read_compressed without compression enabled!\n"; std::cerr << "ZLib Compression not supported. Provide the ZLIB package to CMake." << std::endl;
std::abort(); std::abort();
#endif #endif
}
template <class T, class IStream>
void read_compressed_lz4 (T* /* buffer */, unsigned char* /* buffer_in */,
std::uint64_t /* bs */, std::uint64_t /* cbs */, IStream& /* input */)
{
#if HAVE_VTK_LZ4
std::cerr << "LZ4 Compression not yet implemented" << std::endl;
std::abort();
#else
std::cerr << "LZ4 Compression not supported. Provide the LZ4 package to CMake." << std::endl;
std::abort();
#endif
}
template <class T, class IStream>
void read_compressed_lzma (T* /* buffer */, unsigned char* /* buffer_in */,
std::uint64_t /* bs */, std::uint64_t /* cbs */, IStream& /* input */)
{
#if HAVE_VTK_LZMA
std::cerr << "LZMA Compression not yet implemented" << std::endl;
std::abort();
#else
std::cerr << "LZMA Compression not supported. Provide the LZMA package to CMake." << std::endl;
std::abort();
#endif
}
} }
// @} // @}
template <class Grid, class Creator, class Field> template <class Grid, class Creator, class Field>
template <class T> template <class FloatType, class HeaderType>
void VtkReader<Grid,Creator,Field>::readAppended (std::ifstream& input, std::vector<T>& values, std::uint64_t offset) void VtkReader<Grid,Creator,Field>::readAppended (std::ifstream& input, std::vector<FloatType>& values, HeaderType offset)
{ {
input.seekg(offset0_ + offset); input.seekg(offset0_ + offset);
std::uint64_t size = 0; HeaderType size = 0;