File indexing completed on 2026-05-27 07:24:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "detray/core/detector.hpp"
0011 #include "detray/tracks/trajectories.hpp"
0012
0013
0014 #include "detray/plugins/svgtools/illustrator.hpp"
0015 #include "detray/plugins/svgtools/utils/groups.hpp"
0016 #include "detray/plugins/svgtools/writer.hpp"
0017
0018
0019 #include "detray/test/common/build_toy_detector.hpp"
0020 #include "detray/test/framework/types.hpp"
0021 #include "detray/test/validation/detector_scanner.hpp"
0022 #include "detray/test/validation/svg_display.hpp"
0023
0024
0025 #include <vecmem/memory/host_memory_resource.hpp>
0026
0027
0028 #include <actsvg/core.hpp>
0029 #include <actsvg/web/web_builder.hpp>
0030
0031
0032 #include <gtest/gtest.h>
0033
0034
0035 #include <array>
0036 #include <filesystem>
0037 #include <string>
0038
0039 GTEST_TEST(svgtools, web) {
0040
0041
0042
0043
0044
0045 const auto axes = actsvg::draw::x_y_axes("axes", {-250, 250}, {-250, 250},
0046 actsvg::style::stroke());
0047
0048
0049 const actsvg::views::x_y view;
0050
0051
0052 vecmem::host_memory_resource host_mr;
0053 const auto [det, names] =
0054 detray::build_toy_detector<detray::test::algebra>(host_mr);
0055 using detector_t = decltype(det);
0056
0057 using test_algebra = typename detector_t::algebra_type;
0058 using scalar = detray::dscalar<test_algebra>;
0059 using vector3 = detray::dvector3D<test_algebra>;
0060
0061 detector_t::geometry_context gctx{};
0062
0063
0064 const detray::svgtools::illustrator il{det, names};
0065
0066
0067 std::vector<actsvg::svg::object> svgs;
0068
0069
0070 std::array indices{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u,
0071 10u, 11u, 12u, 13u, 14u, 15u, 16u, 17u, 18u, 19u};
0072
0073
0074 for (detray::dindex i : indices) {
0075 const auto [svg, _] = il.draw_volume(i, view);
0076 svgs.push_back(svg);
0077 }
0078
0079
0080
0081 for (const auto qop : std::vector{-4, -8, -16}) {
0082 std::string name = "Helix_qop_" + std::to_string(qop) + ")";
0083
0084 const typename detector_t::point3_type ori{0.f, 0.f, 80.f};
0085 const typename detector_t::point3_type dir{0.f, 1.f, 1.f};
0086
0087
0088
0089 vector3 B{0.f * detray::unit<scalar>::T, 0.f * detray::unit<scalar>::T,
0090 1.f * detray::unit<scalar>::T};
0091
0092 const detray::detail::helix<test_algebra> helix(
0093 ori, 0.f, detray::vector::normalize(dir), static_cast<float>(qop), B);
0094 const auto helix_ir =
0095 detray::detector_scanner::run<detray::helix_scan>(gctx, det, helix);
0096
0097
0098 const auto svg_helix =
0099 il.draw_trajectory(name + "_trajectory", helix, view);
0100
0101
0102 auto helix_intersections =
0103 detray::detail::transcribe_intersections(helix_ir);
0104 const auto svg_helix_ir = il.draw_intersections(
0105 name + "_record", helix_intersections, helix.dir(), view);
0106
0107
0108
0109
0110 const auto svg_group = detray::svgtools::utils::group(
0111 name, std::vector{svg_helix, svg_helix_ir});
0112 svgs.push_back(svg_group);
0113 }
0114
0115
0116 const auto current_directory = std::filesystem::current_path();
0117
0118
0119 actsvg::web::web_builder builder{};
0120
0121
0122
0123
0124
0125
0126
0127 auto alphanum_cmp = actsvg::web::compare::alphanumeric;
0128 builder.build(current_directory / "test_svgtools_website", svgs,
0129 alphanum_cmp);
0130
0131
0132
0133
0134
0135 }