GCC Code Coverage Report


Directory: gridformat/
File: gridformat/vtk/vts_reader.hpp
Date: 2024-11-20 14:41:59
Exec Total Coverage
Lines: 40 40 100.0%
Functions: 13 13 100.0%
Branches: 15 30 50.0%

Line Branch Exec Source
1 // SPDX-FileCopyrightText: 2022-2023 Dennis Gläser <dennis.glaeser@iws.uni-stuttgart.de>
2 // SPDX-License-Identifier: MIT
3 /*!
4 * \file
5 * \ingroup VTK
6 * \copydoc GridFormat::VTSReader
7 */
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>
16 #include <gridformat/common/field.hpp>
17
18 #include <gridformat/grid/reader.hpp>
19 #include <gridformat/vtk/common.hpp>
20 #include <gridformat/vtk/xml.hpp>
21
22 namespace GridFormat {
23
24 /*!
25 * \ingroup VTK
26 * \brief Reader for .vts file format
27 */
28 class VTSReader : public GridReader {
29 private:
30 228 void _open(const std::string& filename, typename GridReader::FieldNames& fields) override {
31
1/2
✓ Branch 2 taken 228 times.
✗ Branch 3 not taken.
228 auto helper = VTK::XMLReaderHelper::make_from(filename, "StructuredGrid");
32
3/6
✓ Branch 2 taken 228 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 228 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 228 times.
✗ Branch 10 not taken.
228 _extents = Ranges::array_from_string<std::size_t, 6>(helper.get("StructuredGrid/Piece").get_attribute("Extent"));
33
2/4
✓ Branch 2 taken 228 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 228 times.
✗ Branch 6 not taken.
228 VTK::XMLDetail::copy_field_names_from(helper.get("StructuredGrid"), fields);
34 228 _helper.emplace(std::move(helper));
35 228 }
36
37 42 void _close() override {
38 42 _helper.reset();
39 42 _extents.reset();
40 42 }
41
42 1 std::string _name() const override {
43
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 return "VTSReader";
44 }
45
46 857 std::size_t _number_of_cells() const override {
47 857 return VTK::CommonDetail::number_of_entities(_extents.value());
48 }
49
50 1127 std::size_t _number_of_points() const override {
51
1/2
✓ Branch 1 taken 1127 times.
✗ Branch 2 not taken.
1127 auto pextents = _extents.value();
52 1127 pextents[1] += 1;
53 1127 pextents[3] += 1;
54 1127 pextents[5] += 1;
55
1/2
✓ Branch 1 taken 1127 times.
✗ Branch 2 not taken.
2254 return VTK::CommonDetail::number_of_entities(pextents);
56 }
57
58 7 std::size_t _number_of_pieces() const override {
59 7 return 1;
60 }
61
62 296 typename GridReader::PieceLocation _location() const override {
63 296 const auto& ex = _extents.value();
64 typename GridReader::PieceLocation result;
65 296 result.lower_left = {ex[0], ex[2], ex[4]};
66 296 result.upper_right = {ex[1], ex[3], ex[5]};
67 296 return result;
68 }
69
70 84 bool _is_sequence() const override {
71 84 return false;
72 }
73
74 158 FieldPtr _points() const override {
75
1/2
✓ Branch 4 taken 158 times.
✗ Branch 5 not taken.
158 return _helper.value().make_points_field("StructuredGrid/Piece/Points", _number_of_points());
76 }
77
78 262 void _visit_cells(const typename GridReader::CellVisitor& visitor) const override {
79 262 VTK::CommonDetail::visit_structured_cells(visitor, _extents.value(), false);
80 262 }
81
82 631 FieldPtr _cell_field(std::string_view name) const override {
83
2/4
✓ Branch 2 taken 631 times.
✗ Branch 3 not taken.
✓ Branch 7 taken 631 times.
✗ Branch 8 not taken.
631 return _helper.value().make_data_array_field(name, "StructuredGrid/Piece/CellData", _number_of_cells());
84 }
85
86 631 FieldPtr _point_field(std::string_view name) const override {
87
2/4
✓ Branch 2 taken 631 times.
✗ Branch 3 not taken.
✓ Branch 7 taken 631 times.
✗ Branch 8 not taken.
631 return _helper.value().make_data_array_field(name, "StructuredGrid/Piece/PointData", _number_of_points());
88 }
89
90 54 FieldPtr _meta_data_field(std::string_view name) const override {
91
1/2
✓ Branch 4 taken 54 times.
✗ Branch 5 not taken.
54 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_
101