Skip to content

Commit b7f3709

Browse files
committed
Implement generic acceleration structs
1 parent fd920fa commit b7f3709

35 files changed

+593
-393
lines changed

core/include/detray/builders/detector_builder.hpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class detector_builder {
122122
vol_builder->build(det);
123123
}
124124

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

127127
// TODO: Add sorting, data deduplication etc. here later...
128128

@@ -152,7 +152,7 @@ class detector_builder {
152152
}
153153

154154
/// Put the volumes into a search data structure
155-
template <typename... Args>
155+
/*template <typename... Args>
156156
DETRAY_HOST void set_volume_accelerator([[maybe_unused]] Args&&... args) {
157157
DETRAY_DEBUG("Setting volume finder for detector " << name());
158158
@@ -184,13 +184,7 @@ class detector_builder {
184184
} else {
185185
m_vol_finder = vol_finder_t{args...};
186186
}
187-
}
188-
189-
/// @returns access to the volume finder
190-
DETRAY_HOST typename detector_type::volume_accelerator&
191-
get_volume_accelerator() {
192-
return m_vol_finder;
193-
}
187+
}*/
194188

195189
private:
196190
/// Name of the new detector
@@ -199,7 +193,7 @@ class detector_builder {
199193
volume_data_t<std::unique_ptr<volume_builder_interface<detector_type>>>
200194
m_volumes{};
201195
/// Data structure to find volumes
202-
typename detector_type::volume_accelerator m_vol_finder{};
196+
// typename detector_type::volume_accelerator m_vol_finder{};
203197
};
204198

205199
} // namespace detray

core/include/detray/core/detector.hpp

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

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

149143
static_assert(concepts::device_view<view_type>,
150144
"Detector view type ill-formed");
@@ -155,8 +149,7 @@ class detector {
155149
typename transform_container::const_view_type,
156150
typename mask_container::const_view_type,
157151
typename material_container::const_view_type,
158-
typename accelerator_container::const_view_type,
159-
typename volume_accelerator::const_view_type>;
152+
typename accelerator_container::const_view_type>;
160153

161154
static_assert(concepts::device_view<const_view_type>,
162155
"Detector const view type ill-formed");
@@ -168,8 +161,7 @@ class detector {
168161
typename transform_container::buffer_type,
169162
typename mask_container::buffer_type,
170163
typename material_container::buffer_type,
171-
typename accelerator_container::buffer_type,
172-
typename volume_accelerator::buffer_type>;
164+
typename accelerator_container::buffer_type>;
173165

174166
static_assert(concepts::device_buffer<buffer_type>,
175167
"Detector buffer type ill-formed");
@@ -196,8 +188,7 @@ class detector {
196188
_transforms(resource),
197189
_masks(resource),
198190
_materials(resource),
199-
_accelerators(resource),
200-
_volume_accelerator(resource) {}
191+
_accelerators(resource) {}
201192

202193
/// Constructor from detector data view
203194
template <concepts::device_view detector_view_t>
@@ -207,8 +198,7 @@ class detector {
207198
_transforms(detray::detail::get<2>(det_data.m_view)),
208199
_masks(detray::detail::get<3>(det_data.m_view)),
209200
_materials(detray::detail::get<4>(det_data.m_view)),
210-
_accelerators(detray::detail::get<5>(det_data.m_view)),
211-
_volume_accelerator(detray::detail::get<6>(det_data.m_view)) {}
201+
_accelerators(detray::detail::get<5>(det_data.m_view)) {}
212202
/// @}
213203

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

@@ -287,48 +278,20 @@ class detector {
287278
return _accelerators;
288279
}
289280

290-
/// @return the volume grid - const access
291-
DETRAY_HOST_DEVICE
292-
inline auto get_volume_accelerator() const -> const volume_accelerator & {
293-
return _volume_accelerator;
294-
}
295-
296281
/// @returns view of a detector
297282
DETRAY_HOST auto get_data() -> view_type {
298-
return view_type{detray::get_data(_volumes),
299-
detray::get_data(_surfaces),
300-
detray::get_data(_transforms),
301-
detray::get_data(_masks),
302-
detray::get_data(_materials),
303-
detray::get_data(_accelerators),
304-
detray::get_data(_volume_accelerator)};
283+
return view_type{
284+
detray::get_data(_volumes), detray::get_data(_surfaces),
285+
detray::get_data(_transforms), detray::get_data(_masks),
286+
detray::get_data(_materials), detray::get_data(_accelerators)};
305287
}
306288

307289
/// @returns const view of a detector
308290
DETRAY_HOST auto get_data() const -> const_view_type {
309-
return const_view_type{detray::get_data(_volumes),
310-
detray::get_data(_surfaces),
311-
detray::get_data(_transforms),
312-
detray::get_data(_masks),
313-
detray::get_data(_materials),
314-
detray::get_data(_accelerators),
315-
detray::get_data(_volume_accelerator)};
316-
}
317-
/// Add the volume grid - move semantics
318-
///
319-
/// @param v_grid the volume grid to be added
320-
DETRAY_HOST
321-
inline auto set_volume_accelerator(volume_accelerator &&v_grid) -> void {
322-
_volume_accelerator = std::move(v_grid);
323-
}
324-
325-
/// Add the volume grid - copy semantics
326-
///
327-
/// @param v_grid the volume grid to be added
328-
DETRAY_HOST
329-
inline auto set_volume_accelerator(const volume_accelerator &v_grid)
330-
-> void {
331-
_volume_accelerator = v_grid;
291+
return const_view_type{
292+
detray::get_data(_volumes), detray::get_data(_surfaces),
293+
detray::get_data(_transforms), detray::get_data(_masks),
294+
detray::get_data(_materials), detray::get_data(_accelerators)};
332295
}
333296

334297
private:
@@ -340,6 +303,26 @@ class detector {
340303
return os;
341304
}
342305

306+
/// Volume lookup in the volume acceleration data structures
307+
struct volume_search {
308+
///@TODO: Move this to a volume search grid type
309+
template <typename accel_group_t, typename accel_index_t>
310+
DETRAY_HOST_DEVICE inline dindex operator()(
311+
const accel_group_t &group, const accel_index_t index,
312+
const point3_type &p) const {
313+
314+
const auto volume_accelerator = group[index];
315+
316+
// The 3D cylindrical volume search grid is concentric
317+
const transform3_type identity{};
318+
const auto loc_pos =
319+
volume_accelerator.project(identity, p, identity.translation());
320+
321+
// Only one entry per bin
322+
return volume_accelerator.search(loc_pos).value();
323+
}
324+
};
325+
343326
/// Contains the detector sub-volumes.
344327
volume_container _volumes;
345328

@@ -357,9 +340,6 @@ class detector {
357340

358341
/// All surface finder data structures that are used in the detector volumes
359342
accelerator_container _accelerators;
360-
361-
/// Search structure for volumes
362-
volume_accelerator _volume_accelerator;
363343
};
364344

365345
} // 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
@@ -41,7 +41,7 @@ DETRAY_HOST_DEVICE constexpr decltype(auto) get(
4141
&loc_point) noexcept {
4242

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

4747
} // namespace detray::detail::material_accessor

0 commit comments

Comments
 (0)