12#include "detray/core/concepts.hpp"
13#include "detray/definitions/indexing.hpp"
14#include "detray/definitions/math.hpp"
15#include "detray/geometry/tracking_volume.hpp"
16#include "detray/utils/ranges.hpp"
17#include "detray/utils/type_traits.hpp"
32template <
typename node_t>
40template <
typename node_t>
57template <concepts::detector detector_t,
58 typename node_inspector =
59 void_node_inspector<typename detector_t::volume_type>,
60 template <
typename...>
class vector_t =
dvector>
84 const typename detector_t::surface_type &sf,
85 vector_t<typename detector_t::surface_type::mask_link> &half_edges)
87 half_edges.push_back(sf.mask());
100 volume.template visit_surfaces<surface_id::e_all, node_builder>(
120 using volume_iter = detray::ranges::const_iterator_t<volume_container_t>;
127 using pointer =
typename std::iterator_traits<volume_iter>::pointer;
132 typename std::iterator_traits<volume_iter>::iterator_category;
142 : m_vol_itr(std::move(vol_itr)), m_det(det) {}
148 return m_vol_itr == rhs.m_vol_itr;
187 return {itr.m_vol_itr + j, itr.m_det};
199 return lhs.m_vol_itr - rhs.m_vol_itr;
206 const detector_t &
m_det;
244 using mask_edge_t =
typename detector_t::surface_type::navigation_link;
286 template <
typename mask_group_t,
typename mask_range_t>
287 inline vector_t<edge>
operator()(
const mask_group_t &mask_group,
288 const mask_range_t &mask_range,
290 vector_t<edge>
edges{};
291 for (
const auto &
mask :
359 : _nodes(det.volumes(), det), _edges(det.mask_store()), _adj_matrix{0} {
370 const auto &
nodes()
const {
return _nodes; }
377 return static_cast<dindex>(n.half_edges().size());
381 const auto &
edges()
const {
return _edges; }
434 std::stringstream stream;
436 for (
const auto &n : _nodes) {
437 stream <<
"[>>] Node with index " << n.index() << std::endl;
438 stream <<
" -> edges: " << std::endl;
439 for (
unsigned int i = 0u; i < dim; ++i) {
440 const dindex degr = _adj_matrix[dim * n.index() + i];
444 std::string n_occur =
445 degr > 1 ?
"\t\t\t\t(" + std::to_string(degr) +
"x)" :
"";
448 if (i == dim - 1u && degr != 0u) {
449 stream <<
" -> leaving world " + n_occur << std::endl;
451 stream <<
" -> " << std::to_string(i) +
"\t" + n_occur
461 std::stringstream stream;
464 stream <<
"strict graph {" << std::endl;
465 stream <<
" layout=neato;" << std::endl;
466 stream <<
" node [margin=0,shape=circle,style=filled];" << std::endl;
467 stream <<
" overlap=scale;" << std::endl;
468 stream <<
" splines=true;" << std::endl;
469 stream <<
" mode=KK;" << std::endl;
471 stream << R
"( exit [label="OOB",fillcolor="firebrick1"];)" << std::endl;
473 for (
const auto &n : _nodes) {
474 stream <<
" v" << n.index() <<
";" << std::endl;
479 for (
const auto &n : _nodes) {
480 for (
unsigned int i = 0u; i < dim; ++i) {
481 const dindex degr = _adj_matrix[dim * n.index() + i];
486 bool to_oob = i == dim - 1u;
487 bool to_self = n.index() == i;
489 std::string label = degr > 1 ? std::to_string(degr) :
"";
490 std::string dest = to_oob ?
"exit" : (
"v" + std::to_string(i));
491 std::string dir = (to_oob || to_self) ?
"forward" :
"both";
493 stream <<
" v" << n.index() <<
" -- " << dest <<
" [label=\""
494 << label <<
"\", dir=" << dir <<
"];" << std::endl;
498 stream <<
"}" << std::endl;
510 _adj_matrix.resize(dim * dim);
512 for (
const auto &n : _nodes) {
514 for (
const auto &edg_link : n.half_edges()) {
516 for (
const auto edg : _edges(n.index(), edg_link)) {
518 edg.to() < detail::invalid_value<
520 ? dim * n.index() + edg.to()
521 : dim * n.index() + dim - 1u;
535 vector_t<dindex> _adj_matrix;
Mask a region on a surface and link it to a volume.
Definition mask.hpp:46
auto volume_link() const -> const links_type &
Definition mask.hpp:255
Defines a detray 'view'.
Definition ranges.hpp:190
Facade for a detray detector volume.
Definition tracking_volume.hpp:44
std::string to_dot_string() const
Definition volume_graph.hpp:460
typename node_generator::node node_type
Type representing a volume graph node.
Definition volume_graph.hpp:344
const auto & nodes() const
Definition volume_graph.hpp:370
const auto & edges() const
Definition volume_graph.hpp:381
typename edge_generator::edge edge_type
Type representing a volume graph edge.
Definition volume_graph.hpp:347
typename detector_t::mask_container mask_container_t
Detector mask container type.
Definition volume_graph.hpp:68
typename detector_t::geo_obj_ids geo_obj_ids
Geometry object identifier type provided by the detector.
Definition volume_graph.hpp:64
~volume_graph()=default
Default destructor: we don't own anything.
dindex n_edges(dindex volume_id) const
Definition volume_graph.hpp:374
volume_graph()=delete
Default constructor.
const auto & adjacency_matrix() const
Definition volume_graph.hpp:384
std::string to_string() const
Walks breadth first through the geometry objects.
Definition volume_graph.hpp:433
vector_t< typename detector_t::volume_type > volume_container_t
Container type used to access detector volumes.
Definition volume_graph.hpp:66
volume_graph(const detector_t &det)
Build from existing nodes and edges, which are provide by the detector.
Definition volume_graph.hpp:358
dindex n_nodes() const
Definition volume_graph.hpp:367
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
vecmem::vector< value_t > dvector
Vector container backed by vecmem.
Definition containers.hpp:34
unsigned int dindex
Default index type.
Definition indexing.hpp:18
interface type to construct a subrange_view with CTAD
Definition subrange.hpp:90
Placeholder struct for an action while walking through the graph.
Definition volume_graph.hpp:41
void operator()(const node_t &, const dindex_range &) const
Ignore a visited node and its edge range.
Definition volume_graph.hpp:43
Placeholder struct for the implementation of an inspection function that will be executed,...
Definition volume_graph.hpp:33
bool operator()(const node_t &) const
Accept a node without performing an inspection.
Definition volume_graph.hpp:36
An edge in the graph connects two nodes (volumes).
Definition volume_graph.hpp:250
dindex from() const
Definition volume_graph.hpp:258
edge(const dindex volume_id, const dindex link)
Construct an edge between two volume indices.
Definition volume_graph.hpp:254
dindex _to
Destination volume index.
Definition volume_graph.hpp:265
dindex _from
Source volume index.
Definition volume_graph.hpp:263
dindex to() const
Definition volume_graph.hpp:260
Nested functor that fills the edges from a mask container.
Definition volume_graph.hpp:269
vector_t< edge > operator()(const mask_group_t &mask_group, const mask_range_t &mask_range, const dindex volume_id)
Builds the collection of graph edges for a given node.
Definition volume_graph.hpp:287
Builds graph edges from the detector mask collection on the fly.
Definition volume_graph.hpp:242
edge_generator & operator()(dindex volume_id, const mask_link_t mask_link)
Rebuild edges for a new volume and mask link.
Definition volume_graph.hpp:323
typename detector_t::surface_type::mask_link mask_link_t
The link to the surfaces mask.
Definition volume_graph.hpp:246
edge_generator(const typename detector_t::mask_container &masks, const dindex volume_id=0, const mask_link_t mask_link={})
Constructor from the detector masks store.
Definition volume_graph.hpp:306
typename detector_t::surface_type::navigation_link mask_edge_t
The link to the next volume.
Definition volume_graph.hpp:244
mask_link_t _mask_link
Link identifying the mask range used to generate edges.
Definition volume_graph.hpp:339
auto begin()
Definition volume_graph.hpp:314
dindex _volume_id
Current source volume index.
Definition volume_graph.hpp:337
vector_t< edge > _edges
Edges generated for the current volume and mask link.
Definition volume_graph.hpp:335
edge_generator()=delete
No default constructor (holds member reference).
auto end()
Definition volume_graph.hpp:317
const mask_container_t & _masks
Referenced detector mask container.
Definition volume_graph.hpp:333
Iterator over the graph nodes.
Definition volume_graph.hpp:117
std::iter_reference_t< volume_iter > reference
Reference type of the underlying volume iterator.
Definition volume_graph.hpp:129
iterator()=delete
No default construction because of reference member.
bool operator==(const iterator &rhs) const
Equality operator.
Definition volume_graph.hpp:147
typename std::iterator_traits< volume_iter >::iterator_category iterator_category
Category of the underlying volume iterator.
Definition volume_graph.hpp:131
std::iter_difference_t< volume_iter > difference_type
Difference type of the underlying volume iterator.
Definition volume_graph.hpp:123
constexpr auto operator+=(const difference_type j) -> iterator &
Advances iterator by j.
Definition volume_graph.hpp:171
friend constexpr auto operator+(const difference_type j, const iterator &itr) -> iterator
Definition volume_graph.hpp:185
friend constexpr auto operator-(const difference_type j, const iterator &itr) -> iterator
Definition volume_graph.hpp:191
iterator(volume_iter &&vol_itr, const detector_t &det)
Constructor from an iterator on the detector volume container and a reference to its surface containe...
Definition volume_graph.hpp:141
node value_type
Value type produced by dereferencing this iterator.
Definition volume_graph.hpp:125
typename std::iterator_traits< volume_iter >::pointer pointer
Pointer type of the underlying volume iterator.
Definition volume_graph.hpp:127
constexpr auto operator-=(const difference_type j) -> iterator &
Advances iterator by - j.
Definition volume_graph.hpp:179
iterator & operator++()
Prefix increment.
Definition volume_graph.hpp:156
friend constexpr auto operator-(const iterator &lhs, const iterator &rhs) -> difference_type
Definition volume_graph.hpp:197
node operator*()
Dereference operator.
Definition volume_graph.hpp:152
detray::ranges::const_iterator_t< volume_container_t > volume_iter
Iterator type used to traverse the detector's volumes.
Definition volume_graph.hpp:120
iterator & operator--()
Prefix decrement.
Definition volume_graph.hpp:163
A functor to retrieve the half-edges of a node.
Definition volume_graph.hpp:79
void operator()(const typename detector_t::surface_type &sf, vector_t< typename detector_t::surface_type::mask_link > &half_edges) const
Append a surface's mask link to the node's half-edge collection.
Definition volume_graph.hpp:83
A node in the graph has an index (volume index) and a collection of edges that belong to it (mask lin...
Definition volume_graph.hpp:94
dindex m_idx
Node(volume) index.
Definition volume_graph.hpp:111
node(const tracking_volume< detector_t > &volume)
Constructor from a detectors volume and surface collections.
Definition volume_graph.hpp:97
vector_t< typename detector_t::surface_type::mask_link > m_half_edges
Vector of half edges towards other volumes.
Definition volume_graph.hpp:113
const auto & half_edges() const
Definition volume_graph.hpp:108
dindex index() const
Definition volume_graph.hpp:105
Builds a graph node from the detector collections on the fly.
Definition volume_graph.hpp:77
iterator begin() const
Definition volume_graph.hpp:222
const detector_t & m_det
Detector used to access volume surfaces.
Definition volume_graph.hpp:233
iterator end() const
Definition volume_graph.hpp:225
const volume_container_t & m_volumes
Referenced detector volumes.
Definition volume_graph.hpp:231
iterator iterator_t
Node iterator type.
Definition volume_graph.hpp:210
node_generator()=delete
No default constructor (holds member reference).
dindex size() const
Definition volume_graph.hpp:228
node_generator(const volume_container_t &volumes, const detector_t &det)
Constructor from a detector containers.
Definition volume_graph.hpp:218