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