Skip to content

Commit 479ab3c

Browse files
committed
Adjust naming and tracking volume implementation
1 parent 298e3ac commit 479ab3c

File tree

22 files changed

+298
-138
lines changed

22 files changed

+298
-138
lines changed

core/include/detray/builders/detail/volume_connector.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace detray {
2626
template <typename detector_t,
2727
template <typename...> class vector_type = dvector>
2828
void connect_cylindrical_volumes(
29-
detector_t &d, const typename detector_t::volume_finder &volume_grid) {
29+
detector_t &d, const typename detector_t::volume_accelerator &volume_grid) {
3030

3131
using scalar_t = dscalar<typename detector_t::algebra_type>;
3232
typename detector_t::context default_context = {};

core/include/detray/builders/detector_builder.hpp

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

109-
det.set_volume_finder(std::move(m_vol_finder));
109+
det.set_volume_accelerator(std::move(m_vol_finder));
110110

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

@@ -115,9 +115,9 @@ class detector_builder {
115115

116116
/// Put the volumes into a search data structure
117117
template <typename... Args>
118-
DETRAY_HOST void set_volume_finder([[maybe_unused]] Args&&... args) {
118+
DETRAY_HOST void set_volume_accelerator([[maybe_unused]] Args&&... args) {
119119

120-
using vol_finder_t = typename detector_type::volume_finder;
120+
using vol_finder_t = typename detector_type::volume_accelerator;
121121

122122
// Add dummy volume grid for now
123123
if constexpr (concepts::grid<vol_finder_t>) {
@@ -148,7 +148,8 @@ class detector_builder {
148148
}
149149

150150
/// @returns access to the volume finder
151-
DETRAY_HOST typename detector_type::volume_finder& volume_finder() {
151+
DETRAY_HOST typename detector_type::volume_accelerator&
152+
get_volume_accelerator() {
152153
return m_vol_finder;
153154
}
154155

@@ -157,7 +158,7 @@ class detector_builder {
157158
volume_data_t<std::unique_ptr<volume_builder_interface<detector_type>>>
158159
m_volumes{};
159160
/// Data structure to find volumes
160-
typename detector_type::volume_finder m_vol_finder{};
161+
typename detector_type::volume_accelerator m_vol_finder{};
161162
};
162163

163164
} // namespace detray

core/include/detray/core/detector.hpp

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ class detector {
132132

133133
/// Volume finder definition: Make volume index available from track
134134
/// position
135-
using volume_finder =
136-
typename metadata::template volume_finder<container_t>;
135+
using volume_accelerator =
136+
typename metadata::template volume_accelerator<container_t>;
137137

138138
/// Detector view types
139139
/// @TODO: Switch to const_view_type always if possible
@@ -143,7 +143,7 @@ class detector {
143143
typename mask_container::view_type,
144144
typename material_container::view_type,
145145
typename accelerator_container::view_type,
146-
typename volume_finder::view_type>;
146+
typename volume_accelerator::view_type>;
147147

148148
static_assert(concepts::device_view<view_type>,
149149
"Detector view type ill-formed");
@@ -155,7 +155,7 @@ class detector {
155155
typename mask_container::const_view_type,
156156
typename material_container::const_view_type,
157157
typename accelerator_container::const_view_type,
158-
typename volume_finder::const_view_type>;
158+
typename volume_accelerator::const_view_type>;
159159

160160
static_assert(concepts::device_view<const_view_type>,
161161
"Detector const view type ill-formed");
@@ -168,7 +168,7 @@ class detector {
168168
typename mask_container::buffer_type,
169169
typename material_container::buffer_type,
170170
typename accelerator_container::buffer_type,
171-
typename volume_finder::buffer_type>;
171+
typename volume_accelerator::buffer_type>;
172172

173173
static_assert(concepts::device_buffer<buffer_type>,
174174
"Detector buffer type ill-formed");
@@ -196,7 +196,7 @@ class detector {
196196
_masks(resource),
197197
_materials(resource),
198198
_accelerators(resource),
199-
_volume_finder(resource) {}
199+
_volume_accelerator(resource) {}
200200

201201
/// Constructor from detector data view
202202
template <concepts::device_view detector_view_t>
@@ -207,7 +207,7 @@ class detector {
207207
_masks(detray::detail::get<3>(det_data.m_view)),
208208
_materials(detray::detail::get<4>(det_data.m_view)),
209209
_accelerators(detray::detail::get<5>(det_data.m_view)),
210-
_volume_finder(detray::detail::get<6>(det_data.m_view)) {}
210+
_volume_accelerator(detray::detail::get<6>(det_data.m_view)) {}
211211
/// @}
212212

213213
/// @returns a string that contains the detector name
@@ -231,10 +231,10 @@ class detector {
231231
// The 3D cylindrical volume search grid is concentric
232232
const transform3_type identity{};
233233
const auto loc_pos =
234-
_volume_finder.project(identity, p, identity.translation());
234+
_volume_accelerator.project(identity, p, identity.translation());
235235

236236
// Only one entry per bin
237-
dindex volume_index{_volume_finder.search(loc_pos).value()};
237+
dindex volume_index{_volume_accelerator.search(loc_pos).value()};
238238
return _volumes[volume_index];
239239
}
240240

@@ -286,26 +286,30 @@ class detector {
286286

287287
/// @return the volume grid - const access
288288
DETRAY_HOST_DEVICE
289-
inline auto volume_search_grid() const -> const volume_finder & {
290-
return _volume_finder;
289+
inline auto get_volume_accelerator() const -> const volume_accelerator & {
290+
return _volume_accelerator;
291291
}
292292

293293
/// @returns view of a detector
294294
DETRAY_HOST auto get_data() -> view_type {
295-
return view_type{
296-
detray::get_data(_volumes), detray::get_data(_surfaces),
297-
detray::get_data(_transforms), detray::get_data(_masks),
298-
detray::get_data(_materials), detray::get_data(_accelerators),
299-
detray::get_data(_volume_finder)};
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)};
300302
}
301303

302304
/// @returns const view of a detector
303305
DETRAY_HOST auto get_data() const -> const_view_type {
304-
return const_view_type{
305-
detray::get_data(_volumes), detray::get_data(_surfaces),
306-
detray::get_data(_transforms), detray::get_data(_masks),
307-
detray::get_data(_materials), detray::get_data(_accelerators),
308-
detray::get_data(_volume_finder)};
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)};
309313
}
310314

311315
/// @param names maps a volume to its string representation.
@@ -345,16 +349,17 @@ class detector {
345349
///
346350
/// @param v_grid the volume grid to be added
347351
DETRAY_HOST
348-
inline auto set_volume_finder(volume_finder &&v_grid) -> void {
349-
_volume_finder = std::move(v_grid);
352+
inline auto set_volume_accelerator(volume_accelerator &&v_grid) -> void {
353+
_volume_accelerator = std::move(v_grid);
350354
}
351355

352356
/// Add the volume grid - copy semantics
353357
///
354358
/// @param v_grid the volume grid to be added
355359
DETRAY_HOST
356-
inline auto set_volume_finder(const volume_finder &v_grid) -> void {
357-
_volume_finder = v_grid;
360+
inline auto set_volume_accelerator(const volume_accelerator &v_grid)
361+
-> void {
362+
_volume_accelerator = v_grid;
358363
}
359364

360365
private:
@@ -377,7 +382,7 @@ class detector {
377382
accelerator_container _accelerators;
378383

379384
/// Search structure for volumes
380-
volume_finder _volume_finder;
385+
volume_accelerator _volume_accelerator;
381386
};
382387

383388
} // namespace detray

core/include/detray/geometry/tracking_volume.hpp

Lines changed: 93 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class tracking_volume {
5050
public:
5151
/// In case the geometry needs to be printed
5252
using name_map = dmap<dindex, std::string>;
53+
using object_id = descr_t::object_id;
5354

5455
/// Not allowed: always needs a detector and a descriptor.
5556
tracking_volume() = delete;
@@ -67,6 +68,11 @@ class tracking_volume {
6768
constexpr tracking_volume(const detector_t &det, const dindex vol_idx)
6869
: tracking_volume(det, det.volume(vol_idx)) {}
6970

71+
static consteval bool is_surface_id(const object_id id) {
72+
return (id == object_id::e_portal || id == object_id::e_sensitive ||
73+
id == object_id::e_passive);
74+
}
75+
7076
/// @returns access to the underlying detector
7177
DETRAY_HOST_DEVICE
7278
auto detector() const -> const detector_t & { return m_detector; }
@@ -136,16 +142,87 @@ class tracking_volume {
136142
m_desc.template sf_link<surface_id::e_portal>()};
137143
}
138144

139-
/// Apply a functor to all surfaces in the volume's acceleration structures
145+
/// Apply a functor to all surfaces in one of the volume's acceleration
146+
/// structures
140147
///
148+
/// @tparam I type of object to retrieve (passive, portal, sensitive etc)
141149
/// @tparam functor_t the prescription to be applied to the surfaces
142150
/// @tparam Args types of additional arguments to the functor
151+
template <object_id I, typename functor_t, typename... Args>
152+
DETRAY_HOST_DEVICE constexpr void visit_accelerator(Args &&... args) const {
153+
static_assert(I < object_id::e_all);
154+
155+
if (const auto &link{m_desc.template accel_link<I>()};
156+
!link.is_invalid()) {
157+
if constexpr (tracking_volume::is_surface_id(I)) {
158+
// Run over the surfaces in a single acceleration data structure
159+
// and apply the functor to the resulting neighborhood
160+
m_detector.accelerator_store().template visit<functor_t>(
161+
link, std::forward<Args>(args)...);
162+
} else {
163+
// TODO: Call volume accelerator to find daughter volumes
164+
// [...]
165+
}
166+
}
167+
}
168+
169+
/// Apply a functor to all acceleration structures of this volume.
170+
///
171+
/// @tparam I type of object to retrieve (passive, portal, sensitive etc)
172+
/// @tparam functor_t the prescription to be applied to the acc structure
173+
/// @tparam Args types of additional arguments to the functor
143174
template <typename functor_t,
144-
int I = static_cast<int>(descr_t::object_id::e_size) - 1,
145-
typename... Args>
146-
DETRAY_HOST_DEVICE constexpr void visit_surfaces(Args &&... args) const {
147-
visit_surfaces_impl<detail::surface_getter<functor_t>>(
175+
int I = static_cast<int>(object_id::e_all) - 1, typename... Args>
176+
DETRAY_HOST_DEVICE constexpr void visit_accelerators(
177+
Args &&... args) const {
178+
// Get the acceleration data structures for this volume and only visit,
179+
// if object type is contained in volume
180+
visit_accelerator<static_cast<object_id>(I), functor_t>(
148181
std::forward<Args>(args)...);
182+
// Check the next surface type
183+
if constexpr (I > 0) {
184+
visit_accelerators<functor_t, I - 1, Args...>(
185+
std::forward<Args>(args)...);
186+
}
187+
}
188+
189+
/// Apply a functor to all surfaces of a given surface id (portal, passive,
190+
/// sensitive) in the volume
191+
///
192+
/// @tparam functor_t the prescription to be applied to the surfaces
193+
/// @tparam Args types of additional arguments to the functor
194+
template <surface_id I, typename functor_t, typename... Args>
195+
DETRAY_HOST_DEVICE constexpr void visit_surfaces(Args &&... args) const {
196+
using surface_getter_t = detail::surface_getter<functor_t>;
197+
198+
// Dispatch to the correct acceleration structure
199+
switch (I) {
200+
case surface_id::e_portal: {
201+
visit_accelerator<object_id::e_portal, surface_getter_t>(
202+
std::forward<Args>(args)...);
203+
break;
204+
}
205+
case surface_id::e_sensitive: {
206+
visit_accelerator<object_id::e_sensitive, surface_getter_t>(
207+
std::forward<Args>(args)...);
208+
break;
209+
}
210+
case surface_id::e_passive: {
211+
visit_accelerator<object_id::e_passive, surface_getter_t>(
212+
std::forward<Args>(args)...);
213+
break;
214+
}
215+
default: {
216+
// Visit all surface types, but not other geomteric objects
217+
// (e.g. daughter volumes)
218+
visit_accelerator<object_id::e_portal, surface_getter_t>(
219+
std::forward<Args>(args)...);
220+
visit_accelerator<object_id::e_sensitive, surface_getter_t>(
221+
std::forward<Args>(args)...);
222+
visit_accelerator<object_id::e_passive, surface_getter_t>(
223+
std::forward<Args>(args)...);
224+
}
225+
}
149226
}
150227

151228
/// Apply a functor to a neighborhood of surfaces around a track position
@@ -155,14 +232,20 @@ class tracking_volume {
155232
/// customization point for the navigation)
156233
/// @tparam track_t the track around which to build up the neighborhood
157234
/// @tparam Args types of additional arguments to the functor
158-
template <typename functor_t,
159-
int I = static_cast<int>(descr_t::object_id::e_size) - 1,
160-
typename track_t, typename config_t, typename... Args>
235+
template <object_id I, typename functor_t, typename track_t,
236+
typename config_t, typename... Args>
161237
DETRAY_HOST_DEVICE constexpr void visit_neighborhood(
162238
const track_t &track, const config_t &cfg, const context_t &ctx,
163239
Args &&... args) const {
164-
visit_surfaces_impl<detail::neighborhood_getter<functor_t>>(
165-
m_detector, m_desc, track, cfg, ctx, std::forward<Args>(args)...);
240+
if constexpr (I == object_id::e_all) {
241+
visit_accelerators<detail::neighborhood_getter<functor_t>>(
242+
m_detector, m_desc, track, cfg, ctx,
243+
std::forward<Args>(args)...);
244+
} else {
245+
visit_accelerator<I, detail::neighborhood_getter<functor_t>>(
246+
m_detector, m_desc, track, cfg, ctx,
247+
std::forward<Args>(args)...);
248+
}
166249
}
167250

168251
/// Call a functor on the volume material with additional arguments.
@@ -301,32 +384,6 @@ class tracking_volume {
301384
}
302385

303386
private:
304-
/// Apply a functor to all acceleration structures of this volume.
305-
///
306-
/// @tparam functor_t the prescription to be applied to the acc structure
307-
/// @tparam Args types of additional arguments to the functor
308-
template <typename functor_t,
309-
int I = static_cast<int>(descr_t::object_id::e_size) - 1,
310-
typename... Args>
311-
DETRAY_HOST_DEVICE constexpr void visit_surfaces_impl(
312-
Args &&... args) const {
313-
// Get the acceleration data structures for this volume and only visit,
314-
// if object type is contained in volume
315-
if (const auto &link{m_desc.template accel_link<
316-
static_cast<typename descr_t::object_id>(I)>()};
317-
!link.is_invalid()) {
318-
// Run over the surfaces in a single acceleration data structure
319-
// and apply the functor to the resulting neighborhood
320-
m_detector.accelerator_store().template visit<functor_t>(
321-
link, std::forward<Args>(args)...);
322-
}
323-
// Check the next surface type
324-
if constexpr (I > 0) {
325-
visit_surfaces_impl<functor_t, I - 1, Args...>(
326-
std::forward<Args>(args)...);
327-
}
328-
}
329-
330387
/// Access to the detector stores
331388
const detector_t &m_detector;
332389
/// Access to the descriptor

core/include/detray/navigation/navigator.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,8 @@ class navigator {
735735
use_path_tolerance_as_overstep_tolerance ? -cfg.path_tolerance
736736
: cfg.overstep_tolerance;
737737

738-
volume.template visit_neighborhood<candidate_search>(
738+
volume.template visit_neighborhood<volume_type::object_id::e_all,
739+
candidate_search>(
739740
track, cfg, ctx, det, ctx, track, navigation,
740741
darray<scalar_type, 2u>{cfg.min_mask_tolerance,
741742
cfg.max_mask_tolerance},

core/include/detray/navigation/volume_graph.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ class volume_graph {
8888
explicit node(const tracking_volume<detector_t> &volume)
8989
: m_idx(volume.index()) {
9090
// @TODO: Remove duplicates from multiple placements of surfaces
91-
volume.template visit_surfaces<node_builder>(m_half_edges);
91+
volume.template visit_surfaces<surface_id::e_all, node_builder>(
92+
m_half_edges);
9293
}
9394

9495
/// @returns volume index of the node

0 commit comments

Comments
 (0)