File indexing completed on 2025-08-05 08:10:13
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Plugins/ActSVG/LayerSvgConverter.hpp"
0010
0011 #include "Acts/Geometry/Layer.hpp"
0012 #include "Acts/Plugins/ActSVG/SurfaceArraySvgConverter.hpp"
0013 #include "Acts/Plugins/ActSVG/SurfaceSvgConverter.hpp"
0014
0015 #include <set>
0016 #include <sstream>
0017
0018 std::vector<actsvg::svg::object> Acts::Svg::LayerConverter::convert(
0019 const GeometryContext& gctx, const Layer& layer,
0020 const LayerConverter::Options& cOptions) {
0021
0022 std::vector<actsvg::svg::object> sheets;
0023
0024
0025 Acts::Svg::ProtoVolume volume;
0026 volume._name = cOptions.name;
0027
0028
0029 if (layer.surfaceArray() != nullptr) {
0030 SurfaceArrayConverter::Options sacOptions;
0031 sacOptions.surfaceStyles = cOptions.surfaceStyles;
0032 auto [surfaces, grid, associations] = SurfaceArrayConverter::convert(
0033 gctx, *(layer.surfaceArray()), sacOptions);
0034 volume._surfaces = surfaces;
0035 volume._surface_grid = grid;
0036 volume._grid_associations = associations;
0037 }
0038
0039
0040 actsvg::svg::object module_sheet;
0041 actsvg::svg::object grid_sheet;
0042 actsvg::svg::object xy_layer;
0043 actsvg::svg::object zr_layer;
0044
0045
0046 const auto& layerSurface = layer.surfaceRepresentation();
0047 if (layerSurface.type() == Acts::Surface::Disc) {
0048 if (cOptions.moduleInfo) {
0049 module_sheet = actsvg::display::endcap_sheet(
0050 cOptions.name + "_modules", volume, {800, 800},
0051 actsvg::display::e_module_info);
0052 }
0053 if (cOptions.gridInfo) {
0054 grid_sheet = actsvg::display::endcap_sheet(cOptions.name + "_grid",
0055 volume, {800, 800},
0056 actsvg::display::e_grid_info);
0057 }
0058 } else if (layerSurface.type() == Acts::Surface::Cylinder) {
0059 if (cOptions.moduleInfo) {
0060 module_sheet = actsvg::display::barrel_sheet(
0061 cOptions.name + "_modules", volume, {800, 800},
0062 actsvg::display::e_module_info);
0063 }
0064 if (cOptions.gridInfo) {
0065 grid_sheet = actsvg::display::barrel_sheet(cOptions.name + "_grid",
0066 volume, {800, 800},
0067 actsvg::display::e_grid_info);
0068 }
0069 }
0070
0071
0072 actsvg::views::z_r z_r_view;
0073 actsvg::views::x_y x_y_view;
0074
0075 if (layer.surfaceArray() != nullptr) {
0076
0077 xy_layer._tag = "g";
0078 xy_layer._id = cOptions.name + "_xy_view";
0079
0080 zr_layer._tag = "g";
0081 zr_layer._id = cOptions.name + "_zr_view";
0082 unsigned int m = 0;
0083
0084 Acts::ActsScalar avgRadius = 0.;
0085
0086 for (const auto& sf : layer.surfaceArray()->surfaces()) {
0087
0088 const Acts::Vector3 rCenter = sf->binningPosition(gctx, Acts::binR);
0089 const Acts::Vector3 sfCenter = sf->center(gctx);
0090 Acts::ActsScalar radius = Acts::VectorHelpers::perp(rCenter);
0091 Acts::ActsScalar phi = Acts::VectorHelpers::phi(rCenter);
0092 Acts::ActsScalar z = sfCenter.z();
0093
0094 avgRadius += radius;
0095
0096 actsvg::proto::surface<std::vector<Acts::Vector3>> projSurface;
0097 projSurface._vertices = sf->polyhedronRepresentation(gctx, 1u).vertices;
0098
0099 if (phi >= cOptions.phiRange[0] && phi <= cOptions.phiRange[1]) {
0100 std::string m_zr_id = std::string("zr_") + std::to_string(m++);
0101 zr_layer.add_object(Acts::Svg::View::zr(projSurface, m_zr_id));
0102 }
0103
0104 if (z >= cOptions.zRange[0] && z <= cOptions.zRange[1]) {
0105 std::string m_xy_id = std::string("xy_") + std::to_string(m++);
0106 xy_layer.add_object(Acts::Svg::View::xy(projSurface, m_xy_id));
0107 }
0108 }
0109
0110 avgRadius /= layer.surfaceArray()->surfaces().size();
0111
0112
0113 if (cOptions.labelProjection) {
0114 ActsScalar xEnd = avgRadius * std::cos(cOptions.labelGauge);
0115 ActsScalar yEnd = avgRadius * std::sin(cOptions.labelGauge);
0116 xy_layer.add_object(measure(0., 0., xEnd, yEnd, "r", avgRadius, "mm"));
0117 }
0118 }
0119
0120
0121 sheets.push_back(module_sheet);
0122 sheets.push_back(grid_sheet);
0123 sheets.push_back(xy_layer);
0124 sheets.push_back(zr_layer);
0125
0126
0127 return sheets;
0128 }