20 "Unexpected region type");
22 constexpr std::array<char, 5> symbols = {
33 return symbols[
static_cast<std::size_t
>(region_type)];
41 "Unexpected halfspace");
43 constexpr std::array<char, 2> symbols = {
50 return symbols[
static_cast<std::size_t
>(halfspace)];
57 if (tokens.size() != other_tokens.size())
63 const auto &
token = tokens[i];
64 const auto & other_token = other_tokens[i];
65 if (std::holds_alternative<std::reference_wrapper<const CSGSurface>>(
token))
68 if (!std::holds_alternative<std::reference_wrapper<const CSGSurface>>(other_token))
70 const auto & surf_ref = std::get<std::reference_wrapper<const CSGSurface>>(
token);
71 const auto & other_surf_ref = std::get<std::reference_wrapper<const CSGSurface>>(other_token);
72 if (surf_ref.get() != other_surf_ref.get())
78 mooseAssert(std::holds_alternative<RegionType>(
token) ||
79 std::holds_alternative<CSGSurface::Halfspace>(
token),
80 "Unexpected token type");
81 if (std::holds_alternative<std::reference_wrapper<const CSGSurface>>(other_token))
109 const std::string & region_type)
117 " cannot be performed on an empty region.");
151 return nlohmann::json::parse(
"[]");
154 std::stack<std::string> postfix_stack;
159 if (
const auto surface_ref_ptr = std::get_if<std::reference_wrapper<const CSGSurface>>(&
token))
160 postfix_stack.push(surface_ref_ptr->get().getName());
164 std::string region_string;
166 if (
const auto halfspace_ptr = std::get_if<CSGSurface::Halfspace>(&
token))
169 region_string =
"\"" + symbol + postfix_stack.top() +
"\"";
175 const auto region = std::get<RegionType>(
token);
179 region_string = postfix_stack.top();
181 if (region_string[0] ==
'[')
182 region_string =
"\"" + symbol +
"\", " + region_string;
184 region_string =
"\"" + symbol +
"\", [" + region_string +
"]";
188 auto region_string_b = postfix_stack.top();
190 auto region_string_a = postfix_stack.top();
192 region_string = region_string_a +
", \"" + symbol +
"\", " + region_string_b;
196 region_string =
"[" + region_string +
"]";
199 postfix_stack.push(region_string);
205 std::string region_string = postfix_stack.top();
208 if (region_string[0] !=
'[')
209 region_string =
"[" + region_string +
"]";
210 return nlohmann::json::parse(region_string);
213 std::vector<std::string>
216 std::vector<std::string> postfix_string_list;
220 return postfix_string_list;
228 [](
auto && arg) -> std::string
230 using T = std::decay_t<decltype(arg)>;
231 if constexpr (std::is_same_v<T, std::reference_wrapper<const CSGSurface>>)
232 return arg.get().getName();
233 else if constexpr (std::is_same_v<T, RegionType>)
243 const std::size_t postfix_token_index)
const 246 if (
const auto region_ptr = std::get_if<RegionType>(&
_postfix_tokens[i]))
247 return region == *region_ptr;
253 std::map<std::string, std::reference_wrapper<const CSGSurface>> & identical_surface_refs)
256 if (std::holds_alternative<std::reference_wrapper<const CSGSurface>>(
token))
258 const auto & surf_ref = std::get<std::reference_wrapper<const CSGSurface>>(
token);
259 const auto & surf_name = surf_ref.get().getName();
260 if (identical_surface_refs.find(surf_name) != identical_surface_refs.end())
261 token = identical_surface_refs.at(surf_name);
265 std::vector<std::reference_wrapper<const CSGSurface>>
268 std::vector<std::reference_wrapper<const CSGSurface>> surface_references;
270 if (std::holds_alternative<std::reference_wrapper<const CSGSurface>>(
token))
271 surface_references.push_back(std::get<std::reference_wrapper<const CSGSurface>>(
token));
273 return surface_references;
279 if (
this != &other_region)
280 *
this =
CSGRegion(*
this, other_region,
"INTERSECTION");
287 if (
this != &other_region)
288 *
this =
CSGRegion(*
this, other_region,
"UNION");
312 return CSGRegion(region_a, region_b,
"INTERSECTION");
319 return CSGRegion(region_a, region_b,
"UNION");
339 return !(*
this == other);
static char halfspaceSymbol(const CSGSurface::Halfspace halfspace)
std::vector< std::string > toPostfixStringList() const
gets the list of postfix tokens of the region in string representation
CSGRegions creates an internal representation of a CSG region, which can refer to an intersection...
CSGRegion()
Default Constructor.
std::variant< std::reference_wrapper< const CSGSurface >, RegionType, CSGSurface::Halfspace > PostfixTokenVariant
Type definition for a variant that represents the datatypes for entries within the list that represen...
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
static char regionSymbol(const RegionType region_type)
Halfspace
Enum for the sign of the half-space being represented by a point and surface.
const CSGRegion operator|(const CSGRegion ®ion_a, const CSGRegion ®ion_b)
Overload for creating a region from the union (|) of two regions.
bool operator!=(const CSGRegion &other) const
Operator overload for checking if two CSGRegion objects are not equal.
std::vector< PostfixTokenVariant > _postfix_tokens
List of tokens representing the region in postfix notation.
std::vector< std::reference_wrapper< const CSGSurface > > getSurfaces() const
Get the list of surfaces associated with the region.
bool nextRegionOpIsIdentical(const RegionType region, const std::size_t postfix_token_index) const
Iterate through postfix tokens and check if next region operator matches the given operator...
const CSGRegion operator+(const CSGSurface &surf)
Operation overloads for operation based region construction.
const std::vector< PostfixTokenVariant > & getPostfixTokens() const
Get the list of postfix tokens associated with the region.
CSGRegion & operator|=(const CSGRegion &other_region)
Operator overload for |= which creates a union of the current region with the other_region.
bool operator==(const CSGRegion &other) const
Operator overload for checking if two CSGRegion objects are equal.
const CSGRegion operator &(const CSGRegion ®ion_a, const CSGRegion ®ion_b)
Overload for creating a region from the the intersection (&) of two regions.
void updateSurfaceReferences(std::map< std::string, std::reference_wrapper< const CSGSurface >> &identical_surface_refs)
Update surface references of region based on map of input surface references.
RegionType getRegionType() const
Get the region type.
CSGRegion & operator &=(const CSGRegion &other_region)
Operator overload for &= which creates an intersection between the current region and the other_regio...
MooseEnum _region_type
An enum for type of type of operation that defines region.
RegionType
Enum for representing region types, defined to match _region_type MooseEnum.
std::string postfixTokenToString(const PostfixTokenVariant &token) const
converts postfix token from PostfixTokenVariant to string representation
IntRange< T > make_range(T beg, T end)
CSGSurface creates an internal representation of a Constructive Solid Geometry (CSG) surface...
const CSGRegion operator~(const CSGRegion ®ion)
Overload for creating a region from the complement (~) of another region.
nlohmann::json toInfixJSON() const
gets the infix JSON representation of the region, which involves converting region representation fro...
bool checkRegionEquality(const std::vector< PostfixTokenVariant > &other_tokens) const
Loop through postfix tokens and check equality with another list of postfix tokens.
auto index_range(const T &sizable)
const std::string getRegionTypeString() const
Get the region type as a string.
const CSGRegion operator-(const CSGSurface &surf)
Overload for creating a region from the negative half-space (-) of a surface.