File indexing completed on 2026-05-27 07:24:07
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011
0012 #include "detray/io/backend/detail/grid_writer.hpp"
0013 #include "detray/io/backend/detail/type_info.hpp"
0014 #include "detray/io/backend/homogeneous_material_writer.hpp"
0015 #include "detray/io/frontend/payloads.hpp"
0016 #include "detray/material/material_slab.hpp"
0017
0018
0019 #include <string_view>
0020
0021 namespace detray::io {
0022
0023
0024
0025
0026 class material_map_writer : public detail::grid_writer {
0027 using base_type = detail::grid_writer;
0028 using grid_writer_t = base_type;
0029 using mat_writer_t = homogeneous_material_writer;
0030
0031 public:
0032
0033 static constexpr std::string_view tag = "material_maps";
0034
0035
0036 using payload_type =
0037 detector_grids_payload<surface_material_payload, io::material_id>;
0038
0039
0040 using base_type::base_type;
0041
0042
0043 template <class detector_t>
0044 static auto header_to_payload(const detector_t& det,
0045 const std::string_view det_name) {
0046 return grid_writer_t::header_to_payload(tag, det.material_store(),
0047 det_name);
0048 }
0049
0050
0051
0052 template <class detector_t>
0053 static payload_type to_payload(
0054 const detector_t& det, const typename detector_t::name_map& ) {
0055 using algebra_t = typename detector_t::algebra_type;
0056 using material_t = material_slab<typename detector_t::scalar_type>;
0057
0058 payload_type grids_data;
0059
0060 for (const auto& vol_desc : det.volumes()) {
0061
0062 dindex offset{dindex_invalid};
0063
0064
0065 auto vol = tracking_volume{det, vol_desc};
0066 for (const auto& sf_desc : vol.surfaces()) {
0067 if (sf_desc.index() < offset) {
0068 offset = sf_desc.index();
0069 }
0070
0071 const auto& mat_link = sf_desc.material();
0072
0073 if (mat_link.is_invalid() ||
0074 mat_link.id() == detector_t::material::id::e_none) {
0075 continue;
0076 }
0077
0078
0079 if constexpr (detray::concepts::has_material_slabs<detector_t>) {
0080 if (mat_link.id() == detector_t::material::id::e_material_slab) {
0081 continue;
0082 }
0083 }
0084 if constexpr (detray::concepts::has_material_rods<detector_t>) {
0085 if (mat_link.id() == detector_t::material::id::e_material_rod) {
0086 continue;
0087 }
0088 }
0089
0090
0091 auto mat_converter = [&sf_desc](const material_t& mat) {
0092 return mat_writer_t::to_payload<algebra_t>(mat, sf_desc.index());
0093 };
0094
0095
0096 grid_writer_t::to_payload(det.material_store(), mat_link,
0097 vol_desc.index(), sf_desc.index() - offset,
0098 grids_data, mat_converter);
0099 }
0100 }
0101
0102 return grids_data;
0103 }
0104 };
0105
0106 }