Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-27 08:53:11

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/orangeinp/detail/CsgUnit.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <map>
0010 #include <set>
0011 #include <variant>
0012 #include <vector>
0013 
0014 #include "corecel/io/Label.hh"
0015 #include "geocel/BoundingBox.hh"
0016 #include "orange/OrangeTypes.hh"
0017 #include "orange/surf/VariantSurface.hh"
0018 #include "orange/transform/VariantTransform.hh"
0019 
0020 #include "BoundingZone.hh"
0021 #include "../CsgTree.hh"
0022 #include "../CsgTypes.hh"
0023 
0024 namespace celeritas
0025 {
0026 namespace orangeinp
0027 {
0028 namespace detail
0029 {
0030 //---------------------------------------------------------------------------//
0031 /*!
0032  * Constructed CSG geometry data for a unit.
0033  *
0034  * This contains all the construction-time surfaces, volumes, and properties.
0035  * These are stored in a way so that they can be remapped and/or optimized
0036  * further before committing them to the constructed GPU data.
0037  *
0038  * All bounding boxes and transforms are "local" within the CSG unit's
0039  * reference frame, not relative to any other CSG node nor to any parent
0040  * universe. (TODO: add bounds and transforms only for finite regions)
0041  *
0042  * TODO (?) map nodes to set of object pointers, for detailed provenance?
0043  */
0044 struct CsgUnit
0045 {
0046     //// TYPES ////
0047 
0048     using Metadata = Label;
0049     using SetMd = std::set<Metadata>;
0050     using Fill = std::variant<std::monostate, GeoMatId, Daughter>;
0051 
0052     //! Attributes about a closed volume of space
0053     struct Region
0054     {
0055         BoundingZone bounds;  //!< Interior/exterior bbox
0056         TransformId trans_id;  //!< Region-to-unit transform
0057     };
0058 
0059     //// DATA ////
0060 
0061     //!@{
0062     //! \name Surfaces
0063     //! Vectors are indexed by LocalSurfaceId.
0064     std::vector<VariantSurface> surfaces;
0065     //!@}
0066 
0067     //!@{
0068     //! \name Nodes
0069     //! Vectors are indexed by NodeId.
0070     CsgTree tree;  //!< CSG tree
0071     std::vector<SetMd> metadata;  //!< CSG node labels
0072     std::map<NodeId, Region> regions;  //!< Bounds and transforms
0073     //!@}
0074 
0075     //!@{
0076     //! \name Volumes
0077     //! Vector is indexed by LocalVolumeId.
0078     std::vector<Fill> fills;  //!< Content of each volume
0079     GeoMatId background;  //!< Optional background fill
0080     //!@}
0081 
0082     //!@{
0083     //! \name Transforms
0084     //! Vectors are indexed by TransformId.
0085     std::vector<VariantTransform> transforms;
0086     //!@}
0087 
0088     //// FUNCTIONS ////
0089 
0090     // Whether the processed unit is valid for use
0091     explicit inline operator bool() const;
0092 
0093     // Whether the unit has no constructed data
0094     inline bool empty() const;
0095 };
0096 
0097 //---------------------------------------------------------------------------//
0098 /*!
0099  * Utility for telling whether a fill is assigned.
0100  */
0101 inline constexpr bool is_filled(CsgUnit::Fill const& fill)
0102 {
0103     return !std::holds_alternative<std::monostate>(fill);
0104 }
0105 
0106 //---------------------------------------------------------------------------//
0107 // INLINE DEFINITIONS
0108 //---------------------------------------------------------------------------//
0109 /*!
0110  * Whether the processed unit is valid for use.
0111  */
0112 CsgUnit::operator bool() const
0113 {
0114     return this->metadata.size() == this->tree.size()
0115            && !this->tree.volumes().empty()
0116            && this->tree.volumes().size() == this->fills.size();
0117     ;
0118 }
0119 
0120 //---------------------------------------------------------------------------//
0121 /*!
0122  * True if the unit has no constructed data.
0123  */
0124 bool CsgUnit::empty() const
0125 {
0126     return this->surfaces.empty() && this->metadata.empty()
0127            && this->regions.empty() && this->tree.volumes().empty()
0128            && this->fills.empty() && this->transforms.empty();
0129 }
0130 
0131 //---------------------------------------------------------------------------//
0132 }  // namespace detail
0133 }  // namespace orangeinp
0134 }  // namespace celeritas