File indexing completed on 2025-12-16 09:24:39
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0010 #include "Acts/Geometry/GeometryContext.hpp"
0011 #include "Acts/Geometry/Layer.hpp"
0012 #include "Acts/Geometry/Portal.hpp"
0013 #include "Acts/Geometry/PortalLinkBase.hpp"
0014 #include "Acts/Geometry/TrackingGeometry.hpp"
0015 #include "Acts/Geometry/TrackingVolume.hpp"
0016 #include "Acts/Navigation/SurfaceArrayNavigationPolicy.hpp"
0017 #include "Acts/Surfaces/CylinderBounds.hpp"
0018 #include "Acts/Surfaces/DiscBounds.hpp"
0019 #include "Acts/Utilities/Enumerate.hpp"
0020 #include "Acts/Utilities/Helpers.hpp"
0021 #include "ActsPlugins/ActSVG/LayerSvgConverter.hpp"
0022 #include "ActsPlugins/ActSVG/SurfaceArraySvgConverter.hpp"
0023 #include "ActsPlugins/ActSVG/SurfaceSvgConverter.hpp"
0024 #include "ActsPlugins/ActSVG/SvgUtils.hpp"
0025 #include "ActsPlugins/ActSVG/TrackingGeometrySvgConverter.hpp"
0026 #include "ActsPython/Utilities/Helpers.hpp"
0027 #include "ActsPython/Utilities/Macros.hpp"
0028 #include <actsvg/core/draw.hpp>
0029
0030 #include <algorithm>
0031 #include <memory>
0032 #include <ranges>
0033 #include <sstream>
0034 #include <string>
0035 #include <tuple>
0036 #include <vector>
0037
0038 #include <pybind11/pybind11.h>
0039 #include <pybind11/stl.h>
0040
0041 namespace py = pybind11;
0042 using namespace pybind11::literals;
0043
0044 using namespace Acts;
0045 using namespace ActsExamples;
0046 using namespace ActsPlugins;
0047
0048 PYBIND11_MODULE(ActsPluginsPythonBindingsSvg, svg) {
0049 using namespace Acts;
0050 using namespace ActsPlugins;
0051
0052
0053 {
0054 py::class_<actsvg::svg::object>(svg, "object")
0055 .def_readwrite("id", &actsvg::svg::object::_id);
0056
0057 py::class_<actsvg::svg::file>(svg, "file")
0058 .def(py::init<>())
0059 .def("add_object", &actsvg::svg::file::add_object)
0060 .def("add_objects", &actsvg::svg::file::add_objects)
0061 .def("clip",
0062 [](actsvg::svg::file& self, std::array<actsvg::scalar, 4> box) {
0063 self.set_view_box(box);
0064 })
0065 .def("write",
0066 [](const actsvg::svg::file& self, const std::string& filename) {
0067 std::ofstream file(filename);
0068 file << self;
0069 file.close();
0070 });
0071
0072 svg.def("toFile", &Svg::toFile, py::arg("objects"), py::arg("filename"));
0073 }
0074
0075
0076 {
0077 auto c = py::class_<Svg::Style>(svg, "Style").def(py::init<>());
0078 ACTS_PYTHON_STRUCT(c, fillColor, fillOpacity, highlightColor, highlights,
0079 strokeWidth, strokeColor, highlightStrokeWidth,
0080 highlightStrokeColor, fontSize, fontColor,
0081 quarterSegments);
0082 }
0083
0084
0085 {
0086 auto c = py::class_<Svg::SurfaceConverter::Options>(svg, "SurfaceOptions")
0087 .def(py::init<>());
0088 ACTS_PYTHON_STRUCT(c, style, templateSurface);
0089
0090
0091 py::class_<Svg::ProtoSurface>(svg, "ProtoSurface");
0092
0093
0094 svg.def("convertSurface", &Svg::SurfaceConverter::convert);
0095
0096
0097 svg.def("viewSurface", [](const Svg::ProtoSurface& pSurface,
0098 const std::string& identification,
0099 const std::string& view = "xy") {
0100 if (view == "xy") {
0101 return Svg::View::xy(pSurface, identification);
0102 } else if (view == "zr") {
0103 return Svg::View::zr(pSurface, identification);
0104 } else if (view == "zphi") {
0105 return Svg::View::zphi(pSurface, identification);
0106 } else if (view == "zrphi") {
0107 return Svg::View::zrphi(pSurface, identification);
0108 } else {
0109 throw std::invalid_argument("Unknown view type");
0110 }
0111 });
0112 }
0113
0114
0115 {
0116 svg.def("drawArrow", &actsvg::draw::arrow);
0117
0118 svg.def("drawText", &actsvg::draw::text);
0119
0120 svg.def("drawInfoBox", &Svg::infoBox);
0121 }
0122
0123
0124 {
0125 svg.def(
0126 "drawEtaLines",
0127 [](const std::string& id, actsvg ::scalar z, actsvg::scalar r,
0128 const std::vector<actsvg::scalar>& etaMain,
0129 actsvg::scalar strokeWidthMain, unsigned int sizeMain,
0130 bool labelMain, const std::vector<actsvg::scalar>& etaSub,
0131 actsvg::scalar strokeWidthSub, const std::vector<int> strokeDashSub,
0132 unsigned int sizeSub, bool labelSub) {
0133
0134 actsvg::style::stroke strokeMain;
0135 strokeMain._width = strokeWidthMain;
0136 actsvg::style::font fontMain;
0137 fontMain._size = sizeMain;
0138
0139 actsvg::style::stroke strokeSub;
0140 strokeSub._width = strokeWidthSub;
0141 strokeSub._dasharray = strokeDashSub;
0142 actsvg::style::font fontSub;
0143 fontSub._size = sizeSub;
0144
0145 return actsvg::display::eta_lines(
0146 id, z, r,
0147 {std::tie(etaMain, strokeMain, labelMain, fontMain),
0148 std::tie(etaSub, strokeSub, labelSub, fontSub)});
0149 });
0150 }
0151
0152
0153 {
0154 py::class_<Svg::ProtoVolume>(svg, "ProtoVolume");
0155
0156 py::class_<Svg::ProtoGrid>(svg, "ProtoGrid");
0157
0158 py::class_<Svg::ProtoIndexedSurfaceGrid>(svg, "ProtoIndexedSurfaceGrid");
0159 }
0160
0161 { svg.def("drawSurfaceArrays", &Svg::drawSurfaceArrays); }
0162
0163
0164 {
0165 using DefinedStyle = std::pair<GeometryIdentifier, Svg::Style>;
0166 using DefinedStyleSet = std::vector<DefinedStyle>;
0167
0168 auto sm = py::class_<GeometryHierarchyMap<Svg::Style>>(svg, "StyleMap")
0169 .def(py::init<DefinedStyleSet>(), py::arg("elements"));
0170
0171 auto c = py::class_<Svg::LayerConverter::Options>(svg, "LayerOptions")
0172 .def(py::init<>());
0173 ACTS_PYTHON_STRUCT(c, name, surfaceStyles, zRange, phiRange, gridInfo,
0174 moduleInfo, projectionInfo, labelProjection, labelGauge);
0175 }
0176
0177 {
0178 using DefinedLayerOptions =
0179 std::pair<GeometryIdentifier, Svg::LayerConverter::Options>;
0180 using DefinedLayerOptionsSet = std::vector<DefinedLayerOptions>;
0181
0182 auto lom =
0183 py::class_<GeometryHierarchyMap<Svg::LayerConverter::Options>>(
0184 svg, "LayerOptionMap")
0185 .def(py::init<DefinedLayerOptionsSet>(), py::arg("elements"));
0186
0187 auto c = py::class_<Svg::TrackingGeometryConverter::Options>(
0188 svg, "TrackingGeometryOptions")
0189 .def(py::init<>());
0190 ACTS_PYTHON_STRUCT(c, prefix, layerOptions);
0191 }
0192
0193
0194 {
0195 svg.def(
0196 "drawTrackingGeometry",
0197 [](const GeometryContext& gctx, const TrackingGeometry& tGeometry,
0198 const std::string& view, bool drawSurfaces, bool highlightMaterial) {
0199 std::variant<actsvg::views::x_y, actsvg::views::z_r> v;
0200 if (view == "xy") {
0201 v = actsvg::views::x_y();
0202 } else if (view == "zr") {
0203 v = actsvg::views::z_r();
0204 } else {
0205 throw std::invalid_argument("Unknown view type");
0206 }
0207
0208 return Svg::drawTrackingGeometry(gctx, tGeometry, v, drawSurfaces,
0209 highlightMaterial);
0210 },
0211 py::arg("gctx"), py::arg("tGeometry"), py::arg("view"),
0212 py::arg("drawSurfaces") = true, py::arg("highlightMaterial") = false);
0213 }
0214 }