Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/orange/detail/BIHData.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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/BIHData.hh
0006 //! \todo move to orange/BihTreeData
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/OpaqueId.hh"
0011 #include "corecel/Types.hh"
0012 #include "corecel/cont/EnumArray.hh"
0013 #include "corecel/data/Collection.hh"
0014 #include "geocel/BoundingBox.hh"
0015 
0016 #include "../OrangeTypes.hh"
0017 
0018 namespace celeritas
0019 {
0020 namespace detail
0021 {
0022 //---------------------------------------------------------------------------//
0023 /*!
0024  * Data for a single inner node in a Bounding Interval Hierarchy.
0025  *
0026  * As a convention, a node's LEFT edge corresponds to the half space that is
0027  * less than the partition value. In other words, the LEFT bounding plane
0028  * position is the far right boundary of the left side of the tree, and the
0029  * RIGHT bounding plane position is the far left boundary of the right side of
0030  * the tree. Since the halfspaces created by the bounding planes may overlap,
0031  * the LEFT bounding plane position could be either left or right of the RIGHT
0032  * bounding plane position.
0033  */
0034 struct BIHInnerNode
0035 {
0036     using real_type = fast_real_type;
0037 
0038     struct Edge
0039     {
0040         //! The position of the bounding plane along the partition axis
0041         real_type bounding_plane_pos{};
0042         //! The child node connected to this edge
0043         BIHNodeId child;
0044         //! Bbox created by clipping an inf bbox with the bounding planes
0045         //! between this edge (inclusive) and the root.
0046         FastBBox bbox;
0047     };
0048 
0049     enum class Side
0050     {
0051         left,
0052         right,
0053         size_
0054     };
0055 
0056     BIHNodeId parent;  //!< Parent node ID
0057     Axis axis;  //!< Axis that the partition is peformed on
0058     EnumArray<Side, Edge> edges;  //!< Left/right edges
0059 
0060     explicit CELER_FUNCTION operator bool() const
0061     {
0062         return this->edges[Side::left].child && this->edges[Side::right].child;
0063     }
0064 };
0065 
0066 //---------------------------------------------------------------------------//
0067 /*!
0068  * Data for a single leaf node in a Bounding Interval Hierarchy.
0069  */
0070 struct BIHLeafNode
0071 {
0072     BIHNodeId parent;  //!< Parent node ID
0073     ItemRange<LocalVolumeId> vol_ids;
0074 
0075     explicit CELER_FUNCTION operator bool() const { return !vol_ids.empty(); }
0076 };
0077 
0078 //---------------------------------------------------------------------------//
0079 /*!
0080  * Bounding Interval Hierarchy tree.
0081  *
0082  * Infinite bounding boxes are not included in the main tree.
0083  *
0084  * \todo Rename BihTreeRecord
0085  */
0086 struct BIHTree
0087 {
0088     //! All bounding boxes managed by the BIH
0089     ItemMap<LocalVolumeId, FastBBoxId> bboxes;
0090 
0091     //! Inner nodes, the first being the root
0092     ItemRange<BIHInnerNode> inner_nodes;
0093 
0094     //! Leaf nodes
0095     ItemRange<BIHLeafNode> leaf_nodes;
0096 
0097     //! Local volumes that have infinite bounding boxes
0098     ItemRange<LocalVolumeId> inf_vol_ids;
0099 
0100     explicit CELER_FUNCTION operator bool() const
0101     {
0102         if (!inner_nodes.empty())
0103         {
0104             return !bboxes.empty() && !leaf_nodes.empty();
0105         }
0106         else
0107         {
0108             // Degenerate single leaf node case. This occurs when a tree
0109             // contains either:
0110             // a) a single volume
0111             // b) muliple non-partitionable volumes,
0112             // b) only infinite volumes.
0113             return !bboxes.empty() && leaf_nodes.size() == 1;
0114         }
0115     }
0116 };
0117 
0118 //---------------------------------------------------------------------------//
0119 }  // namespace detail
0120 }  // namespace celeritas