GridFormat 0.2.1
I/O-Library for grid-like data structures
Loading...
Searching...
No Matches
vts_reader.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022-2023 Dennis Gläser <dennis.glaeser@iws.uni-stuttgart.de>
2// SPDX-License-Identifier: MIT
8#ifndef GRIDFORMAT_VTK_VTS_READER_HPP_
9#define GRIDFORMAT_VTK_VTS_READER_HPP_
10
11#include <string>
12#include <optional>
13#include <array>
14
15#include <gridformat/common/ranges.hpp>
17
21
22namespace GridFormat {
23
28class VTSReader : public GridReader {
29 private:
30 void _open(const std::string& filename, typename GridReader::FieldNames& fields) override {
31 auto helper = VTK::XMLReaderHelper::make_from(filename, "StructuredGrid");
32 _extents = Ranges::array_from_string<std::size_t, 6>(helper.get("StructuredGrid/Piece").get_attribute("Extent"));
33 VTK::XMLDetail::copy_field_names_from(helper.get("StructuredGrid"), fields);
34 _helper.emplace(std::move(helper));
35 }
36
37 void _close() override {
38 _helper.reset();
39 _extents.reset();
40 }
41
42 std::string _name() const override {
43 return "VTSReader";
44 }
45
46 std::size_t _number_of_cells() const override {
47 return VTK::CommonDetail::number_of_entities(_extents.value());
48 }
49
50 std::size_t _number_of_points() const override {
51 auto pextents = _extents.value();
52 pextents[1] += 1;
53 pextents[3] += 1;
54 pextents[5] += 1;
55 return VTK::CommonDetail::number_of_entities(pextents);
56 }
57
58 std::size_t _number_of_pieces() const override {
59 return 1;
60 }
61
62 typename GridReader::PieceLocation _location() const override {
63 const auto& ex = _extents.value();
64 typename GridReader::PieceLocation result;
65 result.lower_left = {ex[0], ex[2], ex[4]};
66 result.upper_right = {ex[1], ex[3], ex[5]};
67 return result;
68 }
69
70 bool _is_sequence() const override {
71 return false;
72 }
73
74 FieldPtr _points() const override {
75 return _helper.value().make_points_field("StructuredGrid/Piece/Points", _number_of_points());
76 }
77
78 void _visit_cells(const typename GridReader::CellVisitor& visitor) const override {
79 VTK::CommonDetail::visit_structured_cells(visitor, _extents.value(), false);
80 }
81
82 FieldPtr _cell_field(std::string_view name) const override {
83 return _helper.value().make_data_array_field(name, "StructuredGrid/Piece/CellData", _number_of_cells());
84 }
85
86 FieldPtr _point_field(std::string_view name) const override {
87 return _helper.value().make_data_array_field(name, "StructuredGrid/Piece/PointData", _number_of_points());
88 }
89
90 FieldPtr _meta_data_field(std::string_view name) const override {
91 return _helper.value().make_data_array_field(name, "StructuredGrid/FieldData");
92 }
93
94 std::optional<VTK::XMLReaderHelper> _helper;
95 std::optional<std::array<std::size_t, 6>> _extents;
96};
97
98} // namespace GridFormat
99
100#endif // GRIDFORMAT_VTK_VTS_READER_HPP_
Abstract base class for all readers, defines the common interface.
Definition: reader.hpp:51
const std::string & filename() const
Return the name of the opened grid file (empty string until open() is called)
Definition: reader.hpp:92
std::string name() const
Return the name of this reader.
Definition: reader.hpp:73
Reader for .vts file format.
Definition: vts_reader.hpp:28
Base class for grid data readers.
std::shared_ptr< const Field > FieldPtr
Pointer type used by writers/readers for fields.
Definition: field.hpp:186
Definition: reader.hpp:266
Describes the location of a piece within a distributed structured grid.
Definition: reader.hpp:57
Common functionality for VTK writers.
Helper classes and functions for VTK XML-type file format writers & readers.