File indexing completed on 2026-05-27 07:23:59
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011
0012 #include "detray/definitions/detail/qualifiers.hpp"
0013 #include "detray/definitions/geometry.hpp"
0014 #include "detray/definitions/indexing.hpp"
0015 #include "detray/geometry/identifier.hpp"
0016
0017
0018 #include <memory>
0019
0020 namespace detray {
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 template <typename mask_link_t = dtyped_index<dindex, dindex>,
0032 typename material_link_t = dtyped_index<dindex, dindex>,
0033 typename transform_link_t = dindex,
0034 typename navigation_link_t = std::uint_least16_t>
0035 class surface_descriptor {
0036 public:
0037
0038 using navigation_link = navigation_link_t;
0039
0040 using transform_link = transform_link_t;
0041
0042 using mask_link = mask_link_t;
0043 using mask_id = typename mask_link::id_type;
0044 using material_link = material_link_t;
0045 using material_id = typename material_link::id_type;
0046
0047
0048 constexpr surface_descriptor() = default;
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 DETRAY_HOST
0059 constexpr surface_descriptor(const transform_link trf, const mask_link mask,
0060 const material_link material,
0061 const dindex volume, const surface_id sf_id)
0062 : m_identifier{geometry::identifier{}
0063 .set_volume(volume)
0064 .set_id(sf_id)
0065 .set_transform(trf)},
0066 m_mask(mask),
0067 m_material(material) {}
0068
0069
0070
0071
0072 DETRAY_HOST_DEVICE
0073 constexpr auto operator==(const surface_descriptor &rhs) const -> bool {
0074 return (m_mask == rhs.m_mask && m_material == rhs.m_material &&
0075 m_identifier == rhs.m_identifier);
0076 }
0077
0078
0079 DETRAY_HOST_DEVICE
0080 auto set_identifier(const geometry::identifier geo_id) -> void {
0081 m_identifier = geo_id;
0082 }
0083
0084
0085 DETRAY_HOST_DEVICE
0086 constexpr auto identifier() const -> geometry::identifier {
0087 return m_identifier;
0088 }
0089
0090
0091 DETRAY_HOST_DEVICE
0092 auto set_id(const surface_id new_id) -> void { m_identifier.set_id(new_id); }
0093
0094
0095 DETRAY_HOST_DEVICE
0096 constexpr auto id() const -> surface_id { return m_identifier.id(); }
0097
0098
0099 DETRAY_HOST
0100 auto set_volume(const dindex new_idx) -> void {
0101 m_identifier.set_volume(new_idx);
0102 }
0103
0104
0105 DETRAY_HOST_DEVICE
0106 constexpr auto volume() const -> dindex { return m_identifier.volume(); }
0107
0108
0109 DETRAY_HOST_DEVICE
0110 auto set_index(const dindex new_idx) -> void {
0111 m_identifier.set_index(new_idx);
0112 }
0113
0114
0115 DETRAY_HOST_DEVICE
0116 constexpr auto index() const -> dindex { return m_identifier.index(); }
0117
0118
0119
0120
0121 DETRAY_HOST
0122 auto update_transform(dindex offset) -> void {
0123 m_identifier.set_transform(transform() + offset);
0124 }
0125
0126
0127 DETRAY_HOST_DEVICE
0128 constexpr auto transform() const -> dindex {
0129 return m_identifier.transform();
0130 }
0131
0132
0133
0134
0135 DETRAY_HOST
0136 auto update_mask(dindex offset) -> void { m_mask.shift(offset); }
0137
0138
0139 DETRAY_HOST_DEVICE
0140 constexpr auto mask() const -> const mask_link & { return m_mask; }
0141
0142
0143
0144
0145 DETRAY_HOST
0146 auto update_material(dindex offset) -> void { m_material.shift(offset); }
0147
0148
0149 DETRAY_HOST_DEVICE
0150 constexpr auto material() -> material_link & { return m_material; }
0151
0152
0153 DETRAY_HOST_DEVICE
0154 constexpr auto material() const -> const material_link & {
0155 return m_material;
0156 }
0157
0158
0159 DETRAY_HOST_DEVICE
0160 constexpr auto has_material() const -> bool {
0161 return (m_material.id() != material_link::id_type::e_none) &&
0162 !m_material.is_invalid();
0163 }
0164
0165
0166 DETRAY_HOST_DEVICE
0167 constexpr auto is_sensitive() const -> bool {
0168 return m_identifier.id() == surface_id::e_sensitive;
0169 }
0170
0171
0172 DETRAY_HOST_DEVICE
0173 constexpr auto is_portal() const -> bool {
0174 return m_identifier.id() == surface_id::e_portal;
0175 }
0176
0177
0178 DETRAY_HOST_DEVICE
0179 constexpr auto is_passive() const -> bool {
0180 return m_identifier.id() == surface_id::e_passive;
0181 }
0182
0183
0184 DETRAY_HOST
0185 friend std::ostream &operator<<(std::ostream &os,
0186 const surface_descriptor &sf) {
0187 os << sf.m_identifier;
0188 os << " | mask: " << sf.m_mask;
0189 os << " | mat.: " << sf.m_material;
0190 return os;
0191 }
0192
0193 private:
0194 geometry::identifier m_identifier{};
0195 mask_link m_mask{};
0196 material_link m_material{};
0197 };
0198
0199 }
0200
0201 namespace std {
0202
0203
0204 template <typename mask_link_t, typename material_link_t,
0205 typename transform_link_t, typename navigation_link_t>
0206 struct hash<detray::surface_descriptor<mask_link_t, material_link_t,
0207 transform_link_t, navigation_link_t>> {
0208 using descr_t =
0209 detray::surface_descriptor<mask_link_t, material_link_t, transform_link_t,
0210 navigation_link_t>;
0211
0212 auto operator()(const descr_t sf_desc) const noexcept {
0213 return std::hash<detray::geometry::identifier::value_t>()(
0214 sf_desc.identifier().value());
0215 }
0216 };
0217
0218 }