File indexing completed on 2026-05-27 07:23:58
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011
0012 #include "detray/definitions/algebra.hpp"
0013 #include "detray/definitions/containers.hpp"
0014 #include "detray/definitions/math.hpp"
0015 #include "detray/geometry/surface.hpp"
0016 #include "detray/utils/ranges.hpp"
0017
0018 namespace detray::detail {
0019
0020 template <concepts::point2D point2_t, concepts::point3D point3_t>
0021 struct vertexer;
0022
0023
0024
0025
0026
0027
0028
0029
0030 template <typename detector_t>
0031 DETRAY_HOST constexpr auto get_global_vertices(
0032 const typename detector_t::geometry_context &ctx,
0033 geometry::surface<detector_t> sf, const dindex n_seg) {
0034 using algebra_t = typename detector_t::algebra_type;
0035 using point2_t = dpoint2D<algebra_t>;
0036 using point3_t = dpoint3D<algebra_t>;
0037
0038 auto vertices = sf.template visit_mask<vertexer<point2_t, point3_t>>(n_seg);
0039 const auto &trf = sf.transform(ctx);
0040
0041 const std::size_t n_vertices{vertices.size()};
0042 for (std::size_t i = 0u; i < n_vertices; ++i) {
0043 vertices[i] = trf.point_to_global(vertices[i]);
0044 }
0045
0046 return vertices;
0047 }
0048
0049
0050
0051
0052
0053
0054
0055
0056 template <concepts::scalar scalar_t>
0057 static inline dvector<scalar_t> phi_values(scalar_t start_phi, scalar_t end_phi,
0058 dindex n_seg) {
0059 dvector<scalar_t> values;
0060 values.reserve(n_seg + 1u);
0061 scalar_t step_phi = (end_phi - start_phi) / static_cast<scalar_t>(n_seg);
0062 for (unsigned int istep = 0u; istep <= n_seg; ++istep) {
0063 values.push_back(start_phi + static_cast<scalar_t>(istep) * step_phi);
0064 }
0065 return values;
0066 }
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 template <concepts::scalar scalar_t, concepts::point2D point2_t>
0077 inline std::vector<point2_t> r_phi_polygon(scalar_t rmin, scalar_t rmax,
0078 scalar_t phimin, scalar_t phimax,
0079 unsigned int n_segments = 1u) {
0080 std::vector<point2_t> r_phi_poly;
0081 r_phi_poly.reserve(2u * n_segments + 2u);
0082
0083 scalar_t cos_min_phi = math::cos(phimin);
0084 scalar_t sin_min_phi = math::sin(phimin);
0085 scalar_t cos_max_phi = math::cos(phimax);
0086 scalar_t sin_max_phi = math::sin(phimax);
0087
0088
0089 r_phi_poly.push_back({rmin * cos_min_phi, rmin * sin_min_phi});
0090 r_phi_poly.push_back({rmin * cos_max_phi, rmin * sin_max_phi});
0091 r_phi_poly.push_back({rmax * cos_max_phi, rmax * sin_max_phi});
0092 r_phi_poly.push_back({rmax * cos_min_phi, rmax * sin_min_phi});
0093
0094 return r_phi_poly;
0095 }
0096
0097
0098 template <concepts::point2D point2_t, concepts::point3D point3_t>
0099 struct vertexer {
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 template <typename mask_group_t, typename mask_range_t>
0110 dvector<dvector<point3_t>> operator()(const mask_group_t &masks,
0111 const mask_range_t &range,
0112 unsigned int n_segments = 1) {
0113 dvector<dvector<point3_t>> mask_vertices = {};
0114 for (auto i : detray::views::iota(range)) {
0115 mask_vertices.push_back(masks[i].vertices(n_segments));
0116 }
0117 return mask_vertices;
0118 }
0119 };
0120
0121 }