12#include "detray/definitions/detail/qualifiers.hpp"
13#include "detray/definitions/geometry.hpp"
14#include "detray/definitions/indexing.hpp"
35template <
typename ID,
typename acc_link_t = dtyped_index<dindex, dindex>,
36 typename mat_link_t = dtyped_index<dindex, dindex>>
45 static_cast<std::size_t
>(
46 static_cast<std::underlying_type_t<surface_id>
>(
76 return (
id == object_id::e_portal ||
id == object_id::e_sensitive ||
77 id == object_id::e_passive);
83 return (
id == object_id::e_volume);
105 m_transform = trf_idx;
114 template <surface_
id id>
115 DETRAY_HOST_DEVICE
constexpr auto sf_link() const -> const
117 return detail::get<static_cast<uint>(
id)>(m_sf_links);
121 template <surface_
id id>
122 DETRAY_HOST_DEVICE
constexpr auto sf_link() ->
123 typename sf_link_type::index_type& {
124 return detail::get<static_cast<uint>(
id)>(m_sf_links);
130 using idx_range_t =
typename sf_link_type::index_type;
137 dindex min{detail::get<0>(pt_range)};
138 dindex max{detail::get<1>(pt_range)};
140 constexpr idx_range_t empty{};
141 if (sen_range != empty) {
142 min = detail::get<0>(sen_range) < min ? detail::get<0>(sen_range) : min;
143 max = detail::get<1>(sen_range) > max ? detail::get<1>(sen_range) : max;
146 if (psv_range != empty) {
147 min = detail::get<0>(psv_range) < min ? detail::get<0>(psv_range) : min;
148 max = detail::get<1>(psv_range) > max ? detail::get<1>(psv_range) : max;
151 return idx_range_t{min, max};
158 assert(sf_idx_range[1] > sf_idx_range[0]);
159 return sf_idx_range[1] - sf_idx_range[0];
167 assert(full_range[0] <= sf_idx);
168 assert(sf_idx < full_range[1]);
170 return sf_idx - full_range[0];
177 dindex glob_index{sf_idx + full_range[0]};
179 assert(full_range[0] <= glob_index);
180 assert(glob_index < full_range[1]);
192 template <surface_
id id>
194 const typename sf_link_type::index_type& other)
noexcept ->
void {
197 if (
constexpr typename sf_link_type::index_type empty{}; rg == empty) {
201 assert(detail::get<1>(rg) == detail::get<0>(other));
202 rg.set_upper(other.upper());
214 template <surface_
id id>
216 std::size_t
n_surfaces = 0) noexcept ->
void {
219 if (
constexpr typename sf_link_type::index_type empty{}; rg == empty) {
223 rg.shift(
static_cast<dindex>(shift));
233 m_mat_link = mat_link;
241 m_mat_link = {mat_id,
242 static_cast<typename material_link::index_type
>(mat_idx)};
248 return (m_mat_link.id() != material_link::id_type::e_none) &&
249 !m_mat_link.is_invalid();
255 return m_accel_links;
261 DETRAY_HOST_DEVICE
constexpr auto accel_link(
const ID&
id)
const
262 ->
const acc_link_t& {
263 static_assert(
static_cast<std::size_t
>(ID::e_size) >= 1);
264 assert(
static_cast<std::size_t
>(
id) <
static_cast<std::size_t
>(ID::e_size));
265 return accel_link_helper<static_cast<ID>(
266 static_cast<std::size_t
>(ID::e_size) - 1)>(
id);
271 DETRAY_HOST_DEVICE
constexpr auto accel_link() const -> const acc_link_t& {
272 return detail::get<obj_id>(m_accel_links);
278 detail::get<obj_id>(m_accel_links) = link;
285 const typename acc_link_t::id_type
id,
286 const typename acc_link_t::index_type
index) ->
void {
287 detail::get<obj_id>(m_accel_links) = acc_link_t{
id,
index};
297 const ID obj_id,
const typename acc_link_t::id_type accel_id,
298 const typename acc_link_t::index_type
index) ->
void {
299 m_accel_links[obj_id] = acc_link_t{accel_id,
index};
308 return (m_id == rhs.m_id && m_index == rhs.m_index &&
309 m_accel_links == rhs.m_accel_links);
316 os <<
"id = " << v_desc.
id() <<
"(" <<
static_cast<int>(v_desc.
id()) <<
")";
317 os <<
" | index = " << v_desc.
index();
318 os <<
" | trf. = " << v_desc.
transform();
320 os <<
" | sf link: " << v_desc.
sf_link();
321 os <<
" | mat link: " << v_desc.
material();
329 DETRAY_HOST_DEVICE
constexpr auto accel_link_helper(
const ID&
id)
const
330 ->
const acc_link_t& {
333 }
else if constexpr (
static_cast<std::size_t
>(obj_id) > 0) {
334 return accel_link_helper<static_cast<ID>(
335 static_cast<std::size_t
>(obj_id) - 1)>(
id);
337 __builtin_unreachable();
constexpr auto set_transform(const dindex trf_idx) -> void
Definition volume_descriptor.hpp:104
constexpr auto index() const -> dindex
Definition volume_descriptor.hpp:92
constexpr auto set_material(const material_id mat_id, const dindex mat_idx) -> void
Set the volume material link using the given material type id.
Definition volume_descriptor.hpp:239
static consteval bool is_volume_id(const object_id id)
Definition volume_descriptor.hpp:82
constexpr auto accel_link() const -> const acc_link_t &
Definition volume_descriptor.hpp:271
constexpr auto full_sf_range() const -> typename sf_link_type::index_type
Definition volume_descriptor.hpp:128
static consteval bool is_surface_id(const object_id id)
Definition volume_descriptor.hpp:75
constexpr auto transform() const -> dindex
Definition volume_descriptor.hpp:100
constexpr auto accel_link(const ID &id) const -> const acc_link_t &
Definition volume_descriptor.hpp:261
constexpr auto accel_link() const -> const accel_link_type &
Definition volume_descriptor.hpp:253
constexpr auto material() const -> const material_link &
Definition volume_descriptor.hpp:228
constexpr auto set_index(const dindex index) -> void
Definition volume_descriptor.hpp:96
constexpr auto sf_link() const -> const sf_link_type &
Definition volume_descriptor.hpp:109
constexpr auto sf_link() const -> const typename sf_link_type::index_type &
Definition volume_descriptor.hpp:115
constexpr auto id() const -> volume_id
Definition volume_descriptor.hpp:88
constexpr dindex to_global_sf_index(dindex sf_idx) const
Definition volume_descriptor.hpp:175
constexpr dindex to_local_sf_index(dindex sf_idx) const
Definition volume_descriptor.hpp:164
constexpr auto set_accel_link(const typename acc_link_t::id_type id, const typename acc_link_t::index_type index) -> void
Set link from.
Definition volume_descriptor.hpp:284
dmulti_index< dindex_range, static_cast< std::size_t >(static_cast< std::underlying_type_t< surface_id > >(surface_id::e_all))> sf_link_type
Definition volume_descriptor.hpp:43
constexpr auto set_accel_link(const ID obj_id, const typename acc_link_t::id_type accel_id, const typename acc_link_t::index_type index) -> void
Set link for a type of surfaces ( obj_id ) from accel_id and index of the acceleration data structure...
Definition volume_descriptor.hpp:296
constexpr volume_descriptor(const volume_id id)
Constructor from shape id.
Definition volume_descriptor.hpp:71
constexpr auto has_material() const -> bool
Definition volume_descriptor.hpp:247
auto update_sf_link(const typename sf_link_type::index_type &other) noexcept -> void
Set or update the index into a geometry container identified by the obj_id.
Definition volume_descriptor.hpp:193
constexpr volume_descriptor()=default
Default constructor builds an ~infinitely long cylinder.
constexpr auto sf_link() -> typename sf_link_type::index_type &
Definition volume_descriptor.hpp:122
material_link material_link
Definition volume_descriptor.hpp:61
constexpr auto set_accel_link(const acc_link_t link) -> void
Set surface finder link from.
Definition volume_descriptor.hpp:277
auto update_sf_link(std::size_t shift, std::size_t n_surfaces=0) noexcept -> void
Set or update the index into a geometry container identified by the obj_id.
Definition volume_descriptor.hpp:215
dmulti_index< accel_link, geo_obj_ids::e_size > accel_link_type
Definition volume_descriptor.hpp:58
friend std::ostream & operator<<(std::ostream &os, const volume_descriptor &v_desc)
Definition volume_descriptor.hpp:314
constexpr auto operator==(const volume_descriptor &rhs) const -> bool
Equality operator.
Definition volume_descriptor.hpp:307
typename material_link::id_type material_id
Definition volume_descriptor.hpp:63
constexpr dindex n_surfaces() const
Definition volume_descriptor.hpp:155
constexpr auto set_material(const material_link &mat_link) -> void
Set the volume material link to.
Definition volume_descriptor.hpp:232
geo_obj_ids object_id
Definition volume_descriptor.hpp:40
Detray include(s).
Definition array_operators.hpp:18
volume_id
Shape of a detector volume.
Definition geometry.hpp:27
detail::index_range< dindex > dindex_range
Index ranges and sequences.
Definition indexing.hpp:24
unsigned int dindex
Default index type.
Definition indexing.hpp:18
constexpr dindex dindex_invalid
Global invalid index definition.
Definition indexing.hpp:21
detail::multi_index< index_t, DIM > dmulti_index
Index that consists of multiple subindices.
Definition indexing.hpp:33