https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CSGRegion.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://www.mooseframework.org
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include "CSGSurface.h"
13#include "MooseEnum.h"
14
15namespace CSG
16{
17
23{
24public:
26 enum class RegionType
27 {
28 EMPTY,
32 UNION
33 };
34
40 typedef std::variant<std::reference_wrapper<const CSGSurface>, RegionType, CSGSurface::Halfspace>
42
46 static char regionSymbol(const RegionType region_type);
47
51 static char halfspaceSymbol(const CSGSurface::Halfspace halfspace);
52
56 static std::string regionTypeName(const RegionType region_type);
57
61 CSGRegion();
62
69 CSGRegion(const CSGSurface & surf, const CSGSurface::Halfspace halfspace);
70
78 CSGRegion(const CSGRegion & region_a,
79 const CSGRegion & region_b,
80 const std::string & region_type);
81
88 CSGRegion(const CSGRegion & region, const std::string & region_type);
89
93 virtual ~CSGRegion() = default;
94
101 nlohmann::json toInfixJSON() const;
102
108 std::vector<std::string> toPostfixStringList() const;
109
116 std::string postfixTokenToString(const PostfixTokenVariant & token) const;
117
124
130 const std::string getRegionTypeString() const { return _region_type; }
131
137 std::vector<std::reference_wrapper<const CSGSurface>> getSurfaces() const;
138
146 std::map<std::string, std::reference_wrapper<const CSGSurface>> & identical_surface_refs);
147
149 CSGRegion & operator&=(const CSGRegion & other_region);
150
152 CSGRegion & operator|=(const CSGRegion & other_region);
153
155 bool operator==(const CSGRegion & other) const;
156
158 bool operator!=(const CSGRegion & other) const;
159
160protected:
166 const std::vector<PostfixTokenVariant> & getPostfixTokens() const { return _postfix_tokens; }
167
181 void replaceWithSubRegion(const CSGSurface & old_surf, const CSGRegion & sub_region);
182
192 bool nextRegionOpIsIdentical(const RegionType region,
193 const std::size_t postfix_token_index) const;
194
201 bool checkRegionEquality(const std::vector<PostfixTokenVariant> & other_tokens) const;
202
203 // Only CSGBase should be calling replaceWithSubRegion()
204 friend class CSGBase;
205
207 MooseEnum _region_type{"EMPTY=0 HALFSPACE=1 COMPLEMENT=2 INTERSECTION=3 UNION=4"};
208
210 std::vector<PostfixTokenVariant> _postfix_tokens;
211};
212
214
216const CSGRegion operator+(const CSGSurface & surf);
217
219const CSGRegion operator-(const CSGSurface & surf);
220
222const CSGRegion operator&(const CSGRegion & region_a, const CSGRegion & region_b);
223
225const CSGRegion operator|(const CSGRegion & region_a, const CSGRegion & region_b);
226
228const CSGRegion operator~(const CSGRegion & region);
229
230} // namespace CSG
CSGBase creates an internal representation of a Constructive Solid Geometry (CSG) model.
Definition CSGBase.h:54
CSGRegions creates an internal representation of a CSG region, which can refer to an intersection,...
Definition CSGRegion.h:23
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.
Definition CSGRegion.C:275
RegionType getRegionType() const
Get the region type.
Definition CSGRegion.h:123
void replaceWithSubRegion(const CSGSurface &old_surf, const CSGRegion &sub_region)
Replace all occurrences of old_surf in this region's postfix token stream with the tokens of sub_regi...
Definition CSGRegion.C:366
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.
Definition CSGRegion.C:265
static char regionSymbol(const RegionType region_type)
Definition CSGRegion.C:16
std::vector< PostfixTokenVariant > _postfix_tokens
List of tokens representing the region in postfix notation.
Definition CSGRegion.h:210
virtual ~CSGRegion()=default
Destructor.
MooseEnum _region_type
An enum for type of type of operation that defines region.
Definition CSGRegion.h:207
bool operator==(const CSGRegion &other) const
Operator overload for checking if two CSGRegion objects are equal.
Definition CSGRegion.C:353
bool operator!=(const CSGRegion &other) const
Operator overload for checking if two CSGRegion objects are not equal.
Definition CSGRegion.C:360
bool checkRegionEquality(const std::vector< PostfixTokenVariant > &other_tokens) const
Loop through postfix tokens and check equality with another list of postfix tokens.
Definition CSGRegion.C:54
RegionType
Enum for representing region types, defined to match _region_type MooseEnum.
Definition CSGRegion.h:27
CSGRegion & operator&=(const CSGRegion &other_region)
Operator overload for &= which creates an intersection between the current region and the other_regio...
Definition CSGRegion.C:300
std::vector< std::reference_wrapper< const CSGSurface > > getSurfaces() const
Get the list of surfaces associated with the region.
Definition CSGRegion.C:289
static char halfspaceSymbol(const CSGSurface::Halfspace halfspace)
Definition CSGRegion.C:37
static std::string regionTypeName(const RegionType region_type)
Definition CSGRegion.C:91
std::vector< std::string > toPostfixStringList() const
gets the list of postfix tokens of the region in string representation
Definition CSGRegion.C:237
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...
Definition CSGRegion.h:41
nlohmann::json toInfixJSON() const
gets the infix JSON representation of the region, which involves converting region representation fro...
Definition CSGRegion.C:170
const std::string getRegionTypeString() const
Get the region type as a string.
Definition CSGRegion.h:130
CSGRegion()
Default Constructor.
Definition CSGRegion.C:113
const std::vector< PostfixTokenVariant > & getPostfixTokens() const
Get the list of postfix tokens associated with the region.
Definition CSGRegion.h:166
std::string postfixTokenToString(const PostfixTokenVariant &token) const
converts postfix token from PostfixTokenVariant to string representation
Definition CSGRegion.C:247
CSGRegion & operator|=(const CSGRegion &other_region)
Operator overload for |= which creates a union of the current region with the other_region.
Definition CSGRegion.C:308
CSGSurface creates an internal representation of a Constructive Solid Geometry (CSG) surface,...
Definition CSGSurface.h:27
Halfspace
Enum for the sign of the half-space being represented by a point and surface.
Definition CSGSurface.h:31
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
T getEnum() const
get the current value cast to the enum type T
Definition MooseEnum.h:172
const CSGRegion operator|(const CSGRegion &region_a, const CSGRegion &region_b)
Overload for creating a region from the union (|) of two regions.
Definition CSGRegion.C:340
const CSGRegion operator~(const CSGRegion &region)
Overload for creating a region from the complement (~) of another region.
Definition CSGRegion.C:347
const CSGRegion operator&(const CSGRegion &region_a, const CSGRegion &region_b)
Overload for creating a region from the the intersection (&) of two regions.
Definition CSGRegion.C:333
const CSGRegion operator-(const CSGSurface &surf)
Overload for creating a region from the negative half-space (-) of a surface.
Definition CSGRegion.C:326
const CSGRegion operator+(const CSGSurface &surf)
Operation overloads for operation based region construction.
Definition CSGRegion.C:319