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