Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 09:06:12

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file orange/detail/BIHView.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "../OrangeData.hh"
0010 
0011 namespace celeritas
0012 {
0013 namespace detail
0014 {
0015 //---------------------------------------------------------------------------//
0016 /*!
0017  * Traverse BIH tree using a depth-first search.
0018  *
0019  * \todo move to top-level orange directory out of detail namespace
0020  */
0021 class BIHView
0022 {
0023   public:
0024     //!@{
0025     //! \name Type aliases
0026     using Storage = NativeCRef<BIHTreeData>;
0027     //!@}
0028 
0029     // Construct from vector of bounding boxes and storage for LocalVolumeIds
0030     inline CELER_FUNCTION BIHView(BIHTree const& tree, Storage const& storage);
0031 
0032     // Determine if a node is inner, i.e., not a leaf
0033     inline CELER_FUNCTION bool is_inner(BIHNodeId id) const;
0034 
0035     // Get an inner node for a given BIHNodeId
0036     inline CELER_FUNCTION BIHInnerNode const& inner_node(BIHNodeId id) const;
0037 
0038     // Get a leaf node for a given BIHNodeId
0039     inline CELER_FUNCTION BIHLeafNode const& leaf_node(BIHNodeId id) const;
0040 
0041     // Get the bbox for a given vol_id.
0042     inline CELER_FUNCTION FastBBox const& bbox(LocalVolumeId vol_id) const;
0043 
0044     // Get the vol_ids on a given leaf node
0045     inline CELER_FUNCTION Span<LocalVolumeId const>
0046     leaf_vol_ids(BIHLeafNode const& leaf) const;
0047 
0048     // Get the inf_vol_ids
0049     inline CELER_FUNCTION Span<LocalVolumeId const> inf_vol_ids() const;
0050 
0051   private:
0052     //// DATA ////
0053     BIHTree const& tree_;
0054     Storage const& storage_;
0055 };
0056 
0057 //---------------------------------------------------------------------------//
0058 // INLINE DEFINITIONS
0059 //---------------------------------------------------------------------------//
0060 /*!
0061  * Construct from vector of bounding boxes and storage.
0062  */
0063 CELER_FUNCTION
0064 BIHView::BIHView(BIHTree const& tree, BIHView::Storage const& storage)
0065     : tree_(tree), storage_(storage)
0066 {
0067     CELER_EXPECT(tree);
0068 }
0069 
0070 //---------------------------------------------------------------------------//
0071 /*!
0072  *  Determine if a node is inner, i.e., not a leaf.
0073  */
0074 CELER_FUNCTION
0075 bool BIHView::is_inner(BIHNodeId id) const
0076 {
0077     return id.unchecked_get() < tree_.inner_nodes.size();
0078 }
0079 
0080 //---------------------------------------------------------------------------//
0081 /*!
0082  *  Get an inner node for a given BIHNodeId.
0083  */
0084 CELER_FUNCTION
0085 BIHInnerNode const& BIHView::inner_node(BIHNodeId id) const
0086 {
0087     CELER_EXPECT(this->is_inner(id));
0088     return storage_.inner_nodes[tree_.inner_nodes[id.unchecked_get()]];
0089 }
0090 
0091 //---------------------------------------------------------------------------//
0092 /*!
0093  *  Get a leaf node for a given BIHNodeId.
0094  */
0095 CELER_FUNCTION
0096 BIHLeafNode const& BIHView::leaf_node(BIHNodeId id) const
0097 {
0098     CELER_EXPECT(!this->is_inner(id));
0099     return storage_.leaf_nodes[tree_.leaf_nodes[id.unchecked_get()
0100                                                 - tree_.inner_nodes.size()]];
0101 }
0102 
0103 //---------------------------------------------------------------------------//
0104 /*!
0105  *  Get the bbox for a given vol_id.
0106  */
0107 CELER_FUNCTION FastBBox const& BIHView::bbox(LocalVolumeId vol_id) const
0108 {
0109     CELER_EXPECT(vol_id.unchecked_get() < tree_.bboxes.size());
0110     return storage_.bboxes[tree_.bboxes[vol_id]];
0111 }
0112 
0113 //---------------------------------------------------------------------------//
0114 /*!
0115  *  Get the vol_ids on a given leaf node.
0116  */
0117 CELER_FUNCTION Span<LocalVolumeId const>
0118 BIHView::leaf_vol_ids(BIHLeafNode const& leaf) const
0119 {
0120     return storage_.local_volume_ids[leaf.vol_ids];
0121 }
0122 
0123 //---------------------------------------------------------------------------//
0124 /*!
0125  *  Get the inf_vol_ids.
0126  */
0127 CELER_FUNCTION Span<LocalVolumeId const> BIHView::inf_vol_ids() const
0128 {
0129     return storage_.local_volume_ids[tree_.inf_vol_ids];
0130 }
0131 
0132 //---------------------------------------------------------------------------//
0133 }  // namespace detail
0134 }  // namespace celeritas