File indexing completed on 2025-12-11 09:40:21
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Geometry/GeometryContext.hpp"
0012 #include "Acts/Utilities/Axis.hpp"
0013 #include "Acts/Utilities/BinningType.hpp"
0014 #include "ActsPlugins/ActSVG/SvgUtils.hpp"
0015 #include <actsvg/core.hpp>
0016 #include <actsvg/meta.hpp>
0017
0018 #include <array>
0019 #include <optional>
0020 #include <tuple>
0021 #include <vector>
0022
0023 namespace Acts {
0024
0025 class Surface;
0026 }
0027
0028 namespace ActsPlugins::Svg {
0029
0030 using ProtoGrid = actsvg::proto::grid;
0031
0032 namespace GridConverter {
0033
0034
0035 using AxisBound = std::tuple<std::array<double, 2u>, Acts::AxisDirection>;
0036
0037
0038 struct Options {
0039
0040 Style style = defaultGridStyle;
0041
0042 std::optional<AxisBound> optionalBound;
0043 };
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 template <typename grid_type>
0058 ProtoGrid convert(const grid_type& grid,
0059 const std::array<Acts::AxisDirection, grid_type::DIM>& aDirs,
0060 const GridConverter::Options& cOptions) {
0061
0062 ProtoGrid pGrid;
0063
0064
0065 auto axes = grid.axes();
0066
0067
0068
0069 std::vector<double> edges0;
0070 std::vector<double> edges1;
0071
0072
0073 if constexpr (grid_type::DIM == 1u) {
0074 if (aDirs[0u] == Acts::AxisDirection::AxisPhi &&
0075 axes[0]->getBoundaryType() == Acts::AxisBoundaryType::Closed) {
0076
0077 edges1 = axes[0]->getBinEdges();
0078 pGrid._type = actsvg::proto::grid::e_r_phi;
0079 }
0080 if (cOptions.optionalBound.has_value()) {
0081 auto [boundRange, boundValue] = cOptions.optionalBound.value();
0082 if (boundValue == Acts::AxisDirection::AxisR) {
0083
0084 edges0 = {boundRange[0u], boundRange[1u]};
0085 }
0086 }
0087 }
0088
0089 if constexpr (grid_type::DIM == 2u) {
0090
0091 edges0 = axes[0]->getBinEdges();
0092 edges1 = axes[1]->getBinEdges();
0093 if (aDirs[0] == Acts::AxisDirection::AxisPhi &&
0094 aDirs[1] == Acts::AxisDirection::AxisZ) {
0095
0096 std::swap(edges0, edges1);
0097 pGrid._type = actsvg::proto::grid::e_z_phi;
0098 } else if (aDirs[0] == Acts::AxisDirection::AxisPhi &&
0099 aDirs[1] == Acts::AxisDirection::AxisR) {
0100
0101 std::swap(edges0, edges1);
0102 pGrid._type = actsvg::proto::grid::e_r_phi;
0103 } else if (aDirs[0] == Acts::AxisDirection::AxisZ &&
0104 aDirs[1] == Acts::AxisDirection::AxisPhi) {
0105
0106 pGrid._type = actsvg::proto::grid::e_z_phi;
0107 } else if (aDirs[0] == Acts::AxisDirection::AxisR &&
0108 aDirs[1] == Acts::AxisDirection::AxisPhi) {
0109
0110 pGrid._type = actsvg::proto::grid::e_r_phi;
0111 } else if (aDirs[0] == Acts::AxisDirection::AxisX &&
0112 aDirs[1] == Acts::AxisDirection::AxisY) {
0113
0114 pGrid._type = actsvg::proto::grid::e_x_y;
0115 }
0116 }
0117
0118
0119 pGrid._edges_0 = std::vector<actsvg::scalar>(edges0.begin(), edges0.end());
0120 pGrid._edges_1 = std::vector<actsvg::scalar>(edges1.begin(), edges1.end());
0121
0122 auto [fill, stroke] = cOptions.style.fillAndStroke();
0123 pGrid._fill = fill;
0124 pGrid._stroke = stroke;
0125
0126 return pGrid;
0127 }
0128
0129 }
0130 }