Back to home page

EIC code displayed by LXR

 
 

    


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

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/CsgObject.hh
0006 //! \brief CSG operations on Object instances: negation, union, intersection
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <string>
0011 #include <vector>
0012 
0013 #include "ObjectInterface.hh"
0014 
0015 namespace celeritas
0016 {
0017 namespace orangeinp
0018 {
0019 //---------------------------------------------------------------------------//
0020 /*!
0021  * Everywhere *but* the embedded object.
0022  */
0023 class NegatedObject : public ObjectInterface
0024 {
0025   public:
0026     // Construct with the object to negate and an empty name
0027     explicit NegatedObject(SPConstObject obj);
0028 
0029     // Construct with a name and object
0030     NegatedObject(std::string&& label, SPConstObject obj);
0031 
0032     //! Access the daughter object
0033     SPConstObject const& daughter() const { return obj_; }
0034 
0035     //! Get the user-provided label
0036     std::string_view label() const final { return label_; }
0037 
0038     // Construct a volume from this object
0039     NodeId build(VolumeBuilder&) const final;
0040 
0041     // Write the object to JSON
0042     void output(JsonPimpl*) const final;
0043 
0044   private:
0045     std::string label_;
0046     SPConstObject obj_;
0047 };
0048 
0049 //---------------------------------------------------------------------------//
0050 /*!
0051  * Join all of the given objects with an intersection or union.
0052  */
0053 template<OperatorToken Op>
0054 class JoinObjects : public ObjectInterface
0055 {
0056     static_assert(Op == op_and || Op == op_or);
0057 
0058   public:
0059     //!@{
0060     //! \name Type aliases
0061     using VecObject = std::vector<SPConstObject>;
0062     //!@}
0063 
0064     //! Operation joining the daughters ("and" or "or")
0065     static constexpr OperatorToken op_token = Op;
0066 
0067   public:
0068     // Construct a joined object if nontrivial, or return the original
0069     static SPConstObject or_object(std::string&& label, VecObject&& objects);
0070 
0071     // Construct with a label and vector of objects
0072     JoinObjects(std::string&& label, VecObject&& objects);
0073 
0074     //! Access the vector of daughter objects
0075     VecObject const& daughters() const { return objects_; }
0076 
0077     //! Get the user-provided label
0078     std::string_view label() const final { return label_; }
0079 
0080     // Construct a volume from this object
0081     NodeId build(VolumeBuilder&) const final;
0082 
0083     // Write the object to JSON
0084     void output(JsonPimpl*) const final;
0085 
0086   private:
0087     std::string label_;
0088     VecObject objects_;
0089 };
0090 
0091 //---------------------------------------------------------------------------//
0092 // TYPE ALIASES
0093 //---------------------------------------------------------------------------//
0094 
0095 //! Union of the given objects
0096 using AnyObjects = JoinObjects<op_or>;
0097 //! Intersection of the given objects
0098 using AllObjects = JoinObjects<op_and>;
0099 
0100 //! Shared pointer to an object
0101 using SPConstObject = std::shared_ptr<ObjectInterface const>;
0102 //! Type used for defining a Region Definition Vector (RDV)
0103 using VecSenseObj = std::vector<std::pair<Sense, SPConstObject>>;
0104 
0105 //---------------------------------------------------------------------------//
0106 // FREE FUNCTIONS
0107 //---------------------------------------------------------------------------//
0108 
0109 // Make a new object that is the second object subtracted from the first
0110 std::shared_ptr<AllObjects const>
0111 make_subtraction(std::string&& label,
0112                  SPConstObject const& minuend,
0113                  SPConstObject const& subtrahend);
0114 
0115 // Make a combination of possibly negated objects
0116 std::shared_ptr<AllObjects const>
0117 make_rdv(std::string&& label, VecSenseObj&& rdv);
0118 
0119 //---------------------------------------------------------------------------//
0120 }  // namespace orangeinp
0121 }  // namespace celeritas