Skip to content

Commit d1cd2cc

Browse files
committed
Implement generic acceleration structs
1 parent 479ab3c commit d1cd2cc

File tree

35 files changed

+500
-300
lines changed

35 files changed

+500
-300
lines changed

core/include/detray/builders/detector_builder.hpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ class detector_builder {
106106
vol_builder->build(det);
107107
}
108108

109-
det.set_volume_accelerator(std::move(m_vol_finder));
109+
// TODO: Make fully generic for more volume accelerator types
110110

111111
// TODO: Add sorting, data deduplication etc. here later...
112112

113113
return det;
114114
}
115115

116116
/// Put the volumes into a search data structure
117-
template <typename... Args>
117+
/*template <typename... Args>
118118
DETRAY_HOST void set_volume_accelerator([[maybe_unused]] Args&&... args) {
119119
120120
using vol_finder_t = typename detector_type::volume_accelerator;
@@ -145,20 +145,14 @@ class detector_builder {
145145
} else {
146146
m_vol_finder = vol_finder_t{args...};
147147
}
148-
}
149-
150-
/// @returns access to the volume finder
151-
DETRAY_HOST typename detector_type::volume_accelerator&
152-
get_volume_accelerator() {
153-
return m_vol_finder;
154-
}
148+
}*/
155149

156150
private:
157151
/// Data structure that holds a volume builder for every detector volume
158152
volume_data_t<std::unique_ptr<volume_builder_interface<detector_type>>>
159153
m_volumes{};
160154
/// Data structure to find volumes
161-
typename detector_type::volume_accelerator m_vol_finder{};
155+
// typename detector_type::volume_accelerator m_vol_finder{};
162156
};
163157

164158
} // namespace detray

core/include/detray/core/detector.hpp

Lines changed: 41 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,14 @@ class detector {
130130
volume_descriptor<geo_obj_ids, accel_link, material_link>;
131131
using volume_container = vector_type<volume_type>;
132132

133-
/// Volume finder definition: Make volume index available from track
134-
/// position
135-
using volume_accelerator =
136-
typename metadata::template volume_accelerator<container_t>;
137-
138133
/// Detector view types
139134
/// @TODO: Switch to const_view_type always if possible
140135
using view_type = dmulti_view<dvector_view<volume_type>,
141136
typename surface_lookup_container::view_type,
142137
typename transform_container::view_type,
143138
typename mask_container::view_type,
144139
typename material_container::view_type,
145-
typename accelerator_container::view_type,
146-
typename volume_accelerator::view_type>;
140+
typename accelerator_container::view_type>;
147141

148142
static_assert(concepts::device_view<view_type>,
149143
"Detector view type ill-formed");
@@ -154,8 +148,7 @@ class detector {
154148
typename transform_container::const_view_type,
155149
typename mask_container::const_view_type,
156150
typename material_container::const_view_type,
157-
typename accelerator_container::const_view_type,
158-
typename volume_accelerator::const_view_type>;
151+
typename accelerator_container::const_view_type>;
159152

160153
static_assert(concepts::device_view<const_view_type>,
161154
"Detector const view type ill-formed");
@@ -167,8 +160,7 @@ class detector {
167160
typename transform_container::buffer_type,
168161
typename mask_container::buffer_type,
169162
typename material_container::buffer_type,
170-
typename accelerator_container::buffer_type,
171-
typename volume_accelerator::buffer_type>;
163+
typename accelerator_container::buffer_type>;
172164

173165
static_assert(concepts::device_buffer<buffer_type>,
174166
"Detector buffer type ill-formed");
@@ -195,8 +187,7 @@ class detector {
195187
_transforms(resource),
196188
_masks(resource),
197189
_materials(resource),
198-
_accelerators(resource),
199-
_volume_accelerator(resource) {}
190+
_accelerators(resource) {}
200191

201192
/// Constructor from detector data view
202193
template <concepts::device_view detector_view_t>
@@ -206,8 +197,7 @@ class detector {
206197
_transforms(detray::detail::get<2>(det_data.m_view)),
207198
_masks(detray::detail::get<3>(det_data.m_view)),
208199
_materials(detray::detail::get<4>(det_data.m_view)),
209-
_accelerators(detray::detail::get<5>(det_data.m_view)),
210-
_volume_accelerator(detray::detail::get<6>(det_data.m_view)) {}
200+
_accelerators(detray::detail::get<5>(det_data.m_view)) {}
211201
/// @}
212202

213203
/// @returns a string that contains the detector name
@@ -228,13 +218,14 @@ class detector {
228218
/// @return the volume by global cartesian @param position - const access
229219
DETRAY_HOST_DEVICE
230220
inline const auto &volume(const point3_type &p) const {
231-
// The 3D cylindrical volume search grid is concentric
232-
const transform3_type identity{};
233-
const auto loc_pos =
234-
_volume_accelerator.project(identity, p, identity.translation());
235-
236-
// Only one entry per bin
237-
dindex volume_index{_volume_accelerator.search(loc_pos).value()};
221+
volume_type v_desc{};
222+
// Allow to call the volume search data structure
223+
v_desc.set_accel_link(geo_obj_ids::e_volume, 0u);
224+
tracking_volume world{v_desc, *this};
225+
226+
const dindex volume_index =
227+
world.template visit_accelerator<geo_obj_ids::e_volume,
228+
volume_search>(p);
238229
return _volumes[volume_index];
239230
}
240231

@@ -284,32 +275,20 @@ class detector {
284275
return _accelerators;
285276
}
286277

287-
/// @return the volume grid - const access
288-
DETRAY_HOST_DEVICE
289-
inline auto get_volume_accelerator() const -> const volume_accelerator & {
290-
return _volume_accelerator;
291-
}
292-
293278
/// @returns view of a detector
294279
DETRAY_HOST auto get_data() -> view_type {
295-
return view_type{detray::get_data(_volumes),
296-
detray::get_data(_surfaces),
297-
detray::get_data(_transforms),
298-
detray::get_data(_masks),
299-
detray::get_data(_materials),
300-
detray::get_data(_accelerators),
301-
detray::get_data(_volume_accelerator)};
280+
return view_type{
281+
detray::get_data(_volumes), detray::get_data(_surfaces),
282+
detray::get_data(_transforms), detray::get_data(_masks),
283+
detray::get_data(_materials), detray::get_data(_accelerators)};
302284
}
303285

304286
/// @returns const view of a detector
305287
DETRAY_HOST auto get_data() const -> const_view_type {
306-
return const_view_type{detray::get_data(_volumes),
307-
detray::get_data(_surfaces),
308-
detray::get_data(_transforms),
309-
detray::get_data(_masks),
310-
detray::get_data(_materials),
311-
detray::get_data(_accelerators),
312-
detray::get_data(_volume_accelerator)};
288+
return const_view_type{
289+
detray::get_data(_volumes), detray::get_data(_surfaces),
290+
detray::get_data(_transforms), detray::get_data(_masks),
291+
detray::get_data(_materials), detray::get_data(_accelerators)};
313292
}
314293

315294
/// @param names maps a volume to its string representation.
@@ -345,24 +324,27 @@ class detector {
345324
return ss.str();
346325
}
347326

348-
/// Add the volume grid - move semantics
349-
///
350-
/// @param v_grid the volume grid to be added
351-
DETRAY_HOST
352-
inline auto set_volume_accelerator(volume_accelerator &&v_grid) -> void {
353-
_volume_accelerator = std::move(v_grid);
354-
}
355-
356-
/// Add the volume grid - copy semantics
357-
///
358-
/// @param v_grid the volume grid to be added
359-
DETRAY_HOST
360-
inline auto set_volume_accelerator(const volume_accelerator &v_grid)
361-
-> void {
362-
_volume_accelerator = v_grid;
363-
}
364-
365327
private:
328+
/// Volume lookup in the volume acceleration data structures
329+
struct volume_search {
330+
///@TODO: Move this to a volume search grid type
331+
template <typename accel_group_t, typename accel_index_t>
332+
DETRAY_HOST_DEVICE inline dindex operator()(
333+
const accel_group_t &group, const accel_index_t index,
334+
const point3_type &p) const {
335+
336+
const auto volume_accelerator = group[index];
337+
338+
// The 3D cylindrical volume search grid is concentric
339+
const transform3_type identity{};
340+
const auto loc_pos =
341+
volume_accelerator.project(identity, p, identity.translation());
342+
343+
// Only one entry per bin
344+
return volume_accelerator.search(loc_pos).value();
345+
}
346+
};
347+
366348
/// Contains the detector sub-volumes.
367349
volume_container _volumes;
368350

@@ -380,9 +362,6 @@ class detector {
380362

381363
/// All surface finder data structures that are used in the detector volumes
382364
accelerator_container _accelerators;
383-
384-
/// Search structure for volumes
385-
volume_accelerator _volume_accelerator;
386365
};
387366

388367
} // namespace detray

core/include/detray/geometry/detail/volume_kernels.hpp

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "detray/materials/detail/concepts.hpp"
1515
#include "detray/materials/detail/material_accessor.hpp"
1616
#include "detray/materials/material.hpp"
17+
#include "detray/navigation/concepts.hpp"
1718

1819
namespace detray::detail {
1920

@@ -43,20 +44,44 @@ struct get_material_params {
4344
}
4445
};
4546

46-
/// A functor to access the surfaces of a volume
47+
/// A functor to access the surfaces of a volume in a particular acceleration
48+
/// structure
4749
template <typename functor_t>
4850
struct surface_getter {
4951

50-
/// Call operator that forwards the neighborhood search call in a volume
51-
/// to a surface finder data structure
52+
/// Call operator that forwards the functor to all contained surfaces
5253
template <typename accel_group_t, typename accel_index_t, typename... Args>
5354
DETRAY_HOST_DEVICE inline void operator()(const accel_group_t &group,
5455
const accel_index_t index,
5556
Args &&... args) const {
5657

57-
// Run over the surfaces in a single acceleration data structure
58-
for (const auto &sf : group[index].all()) {
59-
functor_t{}(sf, std::forward<Args>(args)...);
58+
using accel_type = typename accel_group_t::value_type;
59+
60+
if constexpr (concepts::surface_accelerator<accel_type>) {
61+
// Run over the surfaces in a single acceleration data structure
62+
for (const auto &sf : group[index].all()) {
63+
functor_t{}(sf, std::forward<Args>(args)...);
64+
}
65+
}
66+
}
67+
};
68+
69+
/// A functor to access the daughter volumes of a volume
70+
template <typename functor_t>
71+
struct daughter_volume_getter {
72+
73+
/// Call operator that forwards the functor call to all contained daughter
74+
/// volumes
75+
template <typename accel_group_t, typename accel_index_t, typename... Args>
76+
DETRAY_HOST_DEVICE inline void operator()(const accel_group_t &group,
77+
const accel_index_t index,
78+
Args &&... args) const {
79+
80+
using accel_type = typename accel_group_t::value_type;
81+
82+
if constexpr (concepts::volume_accelerator<accel_type>) {
83+
// Run over all the daughter volumes
84+
// TODO: Implement e.g. BVH
6085
}
6186
}
6287
};

core/include/detray/geometry/tracking_volume.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,17 @@ class tracking_volume {
6868
constexpr tracking_volume(const detector_t &det, const dindex vol_idx)
6969
: tracking_volume(det, det.volume(vol_idx)) {}
7070

71+
/// @returns true if the object ID corresponds to a surface
7172
static consteval bool is_surface_id(const object_id id) {
7273
return (id == object_id::e_portal || id == object_id::e_sensitive ||
7374
id == object_id::e_passive);
7475
}
7576

77+
/// @returns true if the object ID corresponds to a [daughter] volume
78+
static consteval bool is_volume_id(const object_id id) {
79+
return (id == object_id::e_volume);
80+
}
81+
7682
/// @returns access to the underlying detector
7783
DETRAY_HOST_DEVICE
7884
auto detector() const -> const detector_t & { return m_detector; }

core/include/detray/materials/detail/material_accessor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ requires concepts::material_map<typename material_coll_t::value_type>
4040
&loc_point) noexcept {
4141

4242
// Find the material slab (only one entry per bin)
43-
return material_coll[idx].search(loc_point).ref();
43+
return material_coll[idx].bin(loc_point).ref();
4444
}
4545

4646
} // namespace detray::detail::material_accessor

0 commit comments

Comments
 (0)