File indexing completed on 2025-01-18 10:05:55
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include "corecel/Assert.hh"
0011 #include "corecel/io/Label.hh"
0012 #include "orange/OrangeTypes.hh"
0013
0014 #include "CsgUnit.hh"
0015 #include "LocalSurfaceInserter.hh"
0016 #include "TransformInserter.hh"
0017 #include "../CsgTypes.hh"
0018
0019 namespace celeritas
0020 {
0021 namespace orangeinp
0022 {
0023 namespace detail
0024 {
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 class CsgUnitBuilder
0043 {
0044 public:
0045
0046
0047 using Tol = Tolerance<>;
0048 using Metadata = CsgUnit::Metadata;
0049 using NodeInsertion = CsgTree::Insertion;
0050
0051
0052 public:
0053
0054 CsgUnitBuilder(CsgUnit*, Tol const& tol, BBox const& extents);
0055
0056
0057
0058
0059 Tol const& tol() const { return tol_; }
0060
0061
0062 BBox const& extents() const { return bbox_; }
0063
0064
0065 template<class S>
0066 inline S const& surface(NodeId) const;
0067
0068
0069 template<class T>
0070 inline T const& node(NodeId) const;
0071
0072
0073 BoundingZone const& bounds(NodeId) const;
0074
0075
0076 inline VariantTransform const& transform(TransformId) const;
0077
0078
0079
0080
0081 template<class... Args>
0082 inline NodeInsertion insert_surface(Args&&... args);
0083
0084
0085 template<class... Args>
0086 inline NodeInsertion insert_csg(Args&&... args);
0087
0088
0089 TransformId insert_transform(VariantTransform const& vt);
0090
0091
0092 inline void insert_md(NodeId node, Metadata&& md);
0093
0094
0095 void insert_region(NodeId, BoundingZone const&, TransformId trans_id);
0096
0097
0098 LocalVolumeId insert_volume(NodeId);
0099
0100
0101 void fill_exterior();
0102
0103
0104 void fill_volume(LocalVolumeId, GeoMaterialId);
0105
0106
0107 void
0108 fill_volume(LocalVolumeId, UniverseId, VariantTransform const& transform);
0109
0110 private:
0111 CsgUnit* unit_;
0112 Tol tol_;
0113 BBox bbox_;
0114 LocalSurfaceInserter insert_surface_;
0115 TransformInserter insert_transform_;
0116
0117
0118 VariantSurface const& get_surface_impl(NodeId nid) const;
0119
0120
0121 };
0122
0123
0124
0125
0126
0127
0128
0129 template<class S>
0130 S const& CsgUnitBuilder::surface(NodeId nid) const
0131 {
0132 VariantSurface const& vs = this->get_surface_impl(nid);
0133 CELER_ASSUME(std::holds_alternative<S>(vs));
0134 return std::get<S>(vs);
0135 }
0136
0137
0138
0139
0140
0141 template<class T>
0142 T const& CsgUnitBuilder::node(NodeId nid) const
0143 {
0144 auto const& node = unit_->tree[nid];
0145 CELER_ASSUME(std::holds_alternative<T>(node));
0146 return std::get<T>(node);
0147 }
0148
0149
0150
0151
0152
0153 VariantTransform const& CsgUnitBuilder::transform(TransformId tid) const
0154 {
0155 CELER_EXPECT(tid < unit_->transforms.size());
0156 return unit_->transforms[tid.unchecked_get()];
0157 }
0158
0159
0160
0161
0162
0163 template<class... Args>
0164 auto CsgUnitBuilder::insert_surface(Args&&... args) -> NodeInsertion
0165 {
0166 LocalSurfaceId lsid = insert_surface_(std::forward<Args>(args)...);
0167 return this->insert_csg(lsid);
0168 }
0169
0170
0171
0172
0173
0174 template<class... Args>
0175 auto CsgUnitBuilder::insert_csg(Args&&... args) -> NodeInsertion
0176 {
0177 auto result = unit_->tree.insert(std::forward<Args>(args)...);
0178 if (result.second)
0179 {
0180 unit_->metadata.resize(unit_->tree.size());
0181 }
0182 return result;
0183 }
0184
0185
0186
0187
0188
0189 void CsgUnitBuilder::insert_md(NodeId node, Metadata&& md)
0190 {
0191 CELER_EXPECT(node < unit_->metadata.size());
0192 unit_->metadata[node.unchecked_get()].insert(std::move(md));
0193 }
0194
0195
0196 }
0197 }
0198 }