File indexing completed on 2026-10-27 09:40:41
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <functional>
0010 #include <type_traits>
0011 #include <vector>
0012
0013 #include "corecel/cont/VariantUtils.hh"
0014 #include "orange/OrangeTypes.hh"
0015 #include "orange/orangeinp/CsgTree.hh"
0016 #include "orange/orangeinp/CsgTypes.hh"
0017
0018 namespace celeritas
0019 {
0020 namespace orangeinp
0021 {
0022 namespace detail
0023 {
0024
0025
0026
0027
0028 struct BuildLogicResult
0029 {
0030 using VecLogic = std::vector<logic_int>;
0031 using VecSurface = std::vector<LocalSurfaceId>;
0032
0033 VecSurface faces;
0034 VecLogic logic;
0035 };
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 template<class LogicPolicy>
0054 BuildLogicResult build_logic(LogicPolicy const& policy, NodeId n);
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 template<class VisitorImpl>
0067 class BaseLogicBuilder
0068 {
0069 public:
0070
0071
0072 using VecLogic = std::vector<logic_int>;
0073 using VecSurface = std::vector<LocalSurfaceId>;
0074
0075
0076 static_assert(std::is_same_v<LocalSurfaceId::size_type, logic_int>,
0077 "unsupported: add enum logic conversion for different-sized "
0078 "face and surface ints");
0079
0080 public:
0081
0082 BaseLogicBuilder(
0083 CsgTree const& tree, VecLogic& logic, VecSurface const* vs = nullptr);
0084
0085 void operator()(NodeId const& n);
0086
0087
0088
0089
0090 void operator()(True const&);
0091
0092 void operator()(False const&);
0093
0094 void operator()(Surface const&);
0095
0096 void operator()(Aliased const&);
0097
0098
0099 protected:
0100
0101 void push_back(logic_int lgc) { logic_.push_back(lgc); }
0102
0103 private:
0104 VecLogic& logic_;
0105 ContainerVisitor<CsgTree const&, NodeId> visit_node_;
0106 VecSurface const* mapping_{nullptr};
0107 };
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118 class PostfixLogicBuilder : public BaseLogicBuilder<PostfixLogicBuilder>
0119 {
0120 public:
0121 using BaseLogicBuilder::BaseLogicBuilder;
0122
0123
0124
0125 using BaseLogicBuilder::operator();
0126
0127
0128 void operator()(Negated const& n);
0129
0130
0131 void operator()(Joined const& n);
0132
0133 };
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144 class InfixLogicBuilder : public BaseLogicBuilder<InfixLogicBuilder>
0145 {
0146 public:
0147 using BaseLogicBuilder::BaseLogicBuilder;
0148
0149
0150
0151 using BaseLogicBuilder::operator();
0152
0153
0154 void operator()(Negated const& n);
0155
0156
0157 void operator()(Joined const& n);
0158
0159
0160 private:
0161 int depth_{0};
0162 };
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174 template<class LogicBuilder>
0175 class StaticBuildLogicPolicy
0176 {
0177 static_assert(std::is_invocable_v<LogicBuilder, NodeId>);
0178
0179 public:
0180
0181
0182 using VecLogic = std::vector<logic_int>;
0183 using VecSurface = std::vector<LocalSurfaceId>;
0184
0185
0186 public:
0187
0188 explicit StaticBuildLogicPolicy(CsgTree const& tree) : tree_{tree} {}
0189
0190 StaticBuildLogicPolicy(CsgTree const& tree, VecSurface const& vs)
0191 : tree_{tree}, mapping_{&vs}
0192 {
0193 }
0194
0195
0196 auto operator()(VecLogic& logic) const
0197 {
0198 return LogicBuilder{tree_, logic, mapping_};
0199 }
0200
0201 private:
0202 CsgTree const& tree_;
0203 VecSurface const* mapping_{nullptr};
0204 };
0205
0206
0207
0208 using PostfixBuildLogicPolicy = StaticBuildLogicPolicy<PostfixLogicBuilder>;
0209 using InfixBuildLogicPolicy = StaticBuildLogicPolicy<InfixLogicBuilder>;
0210
0211
0212
0213
0214
0215
0216
0217
0218 class DynamicBuildLogicPolicy
0219 {
0220 public:
0221
0222
0223 using VecLogic = std::vector<logic_int>;
0224 using VecSurface = std::vector<LocalSurfaceId>;
0225 using Builder = std::function<void(NodeId)>;
0226
0227
0228 public:
0229
0230 DynamicBuildLogicPolicy(LogicNotation notation,
0231 CsgTree const& tree,
0232 VecSurface const* mapping);
0233
0234
0235 Builder operator()(VecLogic& logic) const;
0236
0237 private:
0238 LogicNotation notation_;
0239 CsgTree const& tree_;
0240 VecSurface const* mapping_{nullptr};
0241 };
0242
0243
0244
0245
0246
0247 extern template class BaseLogicBuilder<PostfixLogicBuilder>;
0248 extern template class BaseLogicBuilder<InfixLogicBuilder>;
0249
0250 extern template BuildLogicResult build_logic(PostfixBuildLogicPolicy const&,
0251 NodeId);
0252 extern template BuildLogicResult build_logic(InfixBuildLogicPolicy const&,
0253 NodeId);
0254 extern template BuildLogicResult build_logic(DynamicBuildLogicPolicy const&,
0255 NodeId);
0256
0257
0258 }
0259 }
0260 }