File indexing completed on 2025-01-18 09:12:15
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Plugins/ActSVG/SurfaceSvgConverter.hpp"
0010
0011 #include "Acts/Surfaces/AnnulusBounds.hpp"
0012 #include "Acts/Surfaces/PlanarBounds.hpp"
0013 #include "Acts/Surfaces/Surface.hpp"
0014
0015 Acts::Svg::ProtoSurface Acts::Svg::SurfaceConverter::convert(
0016 const GeometryContext& gctx, const Surface& surface,
0017 const SurfaceConverter::Options& cOptions) {
0018 ProtoSurface pSurface;
0019
0020
0021 if (!cOptions.templateSurface) {
0022
0023 Polyhedron surfaceHedron =
0024 surface.polyhedronRepresentation(gctx, cOptions.style.quarterSegments);
0025 auto vertices3D = surfaceHedron.vertices;
0026 pSurface._vertices = vertices3D;
0027 } else {
0028
0029
0030 auto planarBounds =
0031 dynamic_cast<const Acts::PlanarBounds*>(&(surface.bounds()));
0032 if (planarBounds != nullptr) {
0033 auto vertices2D = planarBounds->vertices(cOptions.style.quarterSegments);
0034 pSurface._vertices.reserve(vertices2D.size());
0035 for (const auto& v2 : vertices2D) {
0036 pSurface._vertices.push_back({v2[0], v2[1], 0.});
0037 }
0038 } else {
0039
0040 auto annulusBounds =
0041 dynamic_cast<const Acts::AnnulusBounds*>(&(surface.bounds()));
0042 if (annulusBounds != nullptr) {
0043 auto vertices2D =
0044 annulusBounds->vertices(cOptions.style.quarterSegments);
0045 pSurface._vertices.reserve(vertices2D.size());
0046 for (const auto& v2 : vertices2D) {
0047 pSurface._vertices.push_back({v2[0], v2[1], 0.});
0048 }
0049 } else if (surface.type() == Acts::Surface::SurfaceType::Disc) {
0050
0051 const auto& boundValues = surface.bounds().values();
0052 if (surface.bounds().type() == Acts::SurfaceBounds::BoundsType::eDisc) {
0053
0054 actsvg::scalar ri = static_cast<actsvg::scalar>(boundValues[0]);
0055 actsvg::scalar ro = static_cast<actsvg::scalar>(boundValues[1]);
0056 pSurface._radii = {ri, ro};
0057 pSurface._opening = {
0058 static_cast<actsvg::scalar>(boundValues[3] - boundValues[2]),
0059 static_cast<actsvg::scalar>(boundValues[3] + boundValues[2])};
0060
0061 actsvg::scalar pl = pSurface._opening[0];
0062 actsvg::scalar ph = pSurface._opening[1];
0063
0064 pSurface._vertices = {
0065 {static_cast<actsvg::scalar>(ri * std::cos(pl)),
0066 static_cast<actsvg::scalar>(ri * std::sin(pl)), 0.},
0067 {static_cast<actsvg::scalar>(ro * std::cos(ph)),
0068 static_cast<actsvg::scalar>(ro * std::sin(ph)), 0.},
0069 {static_cast<actsvg::scalar>(ri * std::cos(pl)),
0070 static_cast<actsvg::scalar>(ri * std::sin(pl)), 0.},
0071 {static_cast<actsvg::scalar>(ro * std::cos(ph)),
0072 static_cast<actsvg::scalar>(ro * std::sin(ph)), 0.}};
0073 }
0074 }
0075 }
0076 }
0077
0078
0079 const auto& boundValues = surface.bounds().values();
0080 auto bType = surface.bounds().type();
0081 auto bValues = surface.bounds().values();
0082 if (bType == Acts::SurfaceBounds::BoundsType::eRectangle) {
0083 pSurface._type = ProtoSurface::type::e_rectangle;
0084
0085 pSurface._measures = {
0086 static_cast<actsvg::scalar>(0.5 * (boundValues[2] - boundValues[0])),
0087 static_cast<actsvg::scalar>(0.5 * (boundValues[3] - boundValues[1]))};
0088 } else if (bType == Acts::SurfaceBounds::BoundsType::eTrapezoid) {
0089 pSurface._type = ProtoSurface::type::e_trapez;
0090
0091 pSurface._measures = {static_cast<actsvg::scalar>(boundValues[0]),
0092 static_cast<actsvg::scalar>(boundValues[1]),
0093 static_cast<actsvg::scalar>(boundValues[2])};
0094 } else if (bType == Acts::SurfaceBounds::BoundsType::eDiamond) {
0095
0096 for (const auto& bv : boundValues) {
0097 pSurface._measures.push_back(static_cast<actsvg::scalar>(bv));
0098 }
0099 } else if (bType == Acts::SurfaceBounds::BoundsType::eAnnulus) {
0100 pSurface._type = ProtoSurface::type::e_trapez;
0101
0102 for (const auto& bv : boundValues) {
0103 pSurface._measures.push_back(static_cast<actsvg::scalar>(bv));
0104 }
0105 } else if (bType == Acts::SurfaceBounds::BoundsType::eDisc) {
0106 pSurface._type = ProtoSurface::type::e_disc;
0107
0108 actsvg::scalar ri = static_cast<actsvg::scalar>(boundValues[0]);
0109 actsvg::scalar ro = static_cast<actsvg::scalar>(boundValues[1]);
0110 actsvg::scalar zp = static_cast<actsvg::scalar>(surface.center(gctx).z());
0111 pSurface._radii = {ri, ro};
0112 pSurface._zparameters = {zp, zp};
0113 pSurface._opening = {
0114 static_cast<actsvg::scalar>(boundValues[3] - boundValues[2]),
0115 static_cast<actsvg::scalar>(boundValues[3] + boundValues[2])};
0116
0117 for (const auto& bv : boundValues) {
0118 pSurface._measures.push_back(static_cast<actsvg::scalar>(bv));
0119 }
0120 }
0121
0122
0123
0124 if (surface.surfaceMaterial() != nullptr) {
0125 pSurface._decorations["material"] = actsvg::svg::object{};
0126 }
0127
0128
0129 actsvg::svg::object geoId{};
0130 geoId._id = std::to_string(surface.geometryId().value());
0131 pSurface._decorations["geo_id"] = geoId;
0132
0133 auto [surfaceFill, surfaceStroke] = cOptions.style.fillAndStroke();
0134 pSurface._fill = surfaceFill;
0135 pSurface._stroke = surfaceStroke;
0136
0137 return pSurface;
0138 }