Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-12-06 10:29:57

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  * The CsgUnit is created in \c UnitProto::build to convert input Objects into
0045  * this CSG unit.
0046  */
0047 struct CsgUnit
0048 {
0049     //// TYPES ////
0050 
0051     using Metadata = Label;
0052     using SetMd = std::set<Metadata>;
0053     using Fill = std::variant<std::monostate, GeoMatId, Daughter>;
0054 
0055     //! Attributes about a closed volume of space
0056     struct Region
0057     {
0058         BoundingZone bounds;  //!< Interior/exterior bbox
0059         TransformId trans_id;  //!< Region-to-unit transform
0060     };
0061 
0062     //// DATA ////
0063 
0064     //!@{
0065     //! \name Surfaces
0066     //! Vectors are indexed by LocalSurfaceId.
0067     std::vector<VariantSurface> surfaces;
0068     //!@}
0069 
0070     //!@{
0071     //! \name Nodes
0072     //! Vectors are indexed by NodeId.
0073     CsgTree tree;  //!< CSG tree
0074     std::vector<SetMd> metadata;  //!< CSG node labels
0075     std::map<NodeId, Region> regions;  //!< Bounds and transforms
0076     //!@}
0077 
0078     //!@{
0079     //! \name Volumes
0080     //! Vector is indexed by LocalVolumeId.
0081     std::vector<Fill> fills;  //!< Content of each volume
0082     GeoMatId background;  //!< Optional background fill
0083     //!@}
0084 
0085     //! The CSG tree stores the actual volume nodes since it may reorder
0086     CsgTree::VecNodeId const& volumes() const { return tree.volumes(); }
0087 
0088     //!@{
0089     //! \name Transforms
0090     //! Vectors are indexed by TransformId.
0091     std::vector<VariantTransform> transforms;
0092     //!@}
0093 
0094     //// FUNCTIONS ////
0095 
0096     // Whether the processed unit is valid for use
0097     explicit inline operator bool() const;
0098 
0099     // Whether the unit has no constructed data
0100     inline bool empty() const;
0101 };
0102 
0103 //---------------------------------------------------------------------------//
0104 /*!
0105  * Utility for telling whether a fill is assigned.
0106  */
0107 inline constexpr bool is_filled(CsgUnit::Fill const& fill)
0108 {
0109     return !std::holds_alternative<std::monostate>(fill);
0110 }
0111 
0112 //---------------------------------------------------------------------------//
0113 // INLINE DEFINITIONS
0114 //---------------------------------------------------------------------------//
0115 /*!
0116  * Whether the processed unit is valid for use.
0117  */
0118 CsgUnit::operator bool() const
0119 {
0120     return this->metadata.size() == this->tree.size()
0121            && !this->volumes().empty()
0122            && this->volumes().size() == this->fills.size();
0123 }
0124 
0125 //---------------------------------------------------------------------------//
0126 /*!
0127  * True if the unit has no constructed data.
0128  */
0129 bool CsgUnit::empty() const
0130 {
0131     return this->surfaces.empty() && this->metadata.empty()
0132            && this->regions.empty() && this->volumes().empty()
0133            && this->fills.empty() && this->transforms.empty();
0134 }
0135 
0136 //---------------------------------------------------------------------------//
0137 }  // namespace detail
0138 }  // namespace orangeinp
0139 }  // namespace celeritas