https://mooseframework.inl.gov
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 
15 namespace CSG
16 {
17 
22 class CSGRegion
23 {
24 public:
26  enum class RegionType
27  {
28  EMPTY,
29  HALFSPACE,
30  COMPLEMENT,
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);
50  static char halfspaceSymbol(const CSGSurface::Halfspace halfspace);
51 
55  CSGRegion();
56 
63  CSGRegion(const CSGSurface & surf, const CSGSurface::Halfspace halfspace);
64 
72  CSGRegion(const CSGRegion & region_a,
73  const CSGRegion & region_b,
74  const std::string & region_type);
75 
82  CSGRegion(const CSGRegion & region, const std::string & region_type);
83 
87  virtual ~CSGRegion() = default;
88 
95  nlohmann::json toInfixJSON() const;
96 
102  std::vector<std::string> toPostfixStringList() const;
103 
110  std::string postfixTokenToString(const PostfixTokenVariant & token) const;
111 
118 
124  const std::string getRegionTypeString() const { return _region_type; }
125 
131  std::vector<std::reference_wrapper<const CSGSurface>> getSurfaces() const;
132 
140  std::map<std::string, std::reference_wrapper<const CSGSurface>> & identical_surface_refs);
141 
143  CSGRegion & operator&=(const CSGRegion & other_region);
144 
146  CSGRegion & operator|=(const CSGRegion & other_region);
147 
149  bool operator==(const CSGRegion & other) const;
150 
152  bool operator!=(const CSGRegion & other) const;
153 
154 protected:
160  const std::vector<PostfixTokenVariant> & getPostfixTokens() const { return _postfix_tokens; }
161 
171  bool nextRegionOpIsIdentical(const RegionType region,
172  const std::size_t postfix_token_index) const;
173 
180  bool checkRegionEquality(const std::vector<PostfixTokenVariant> & other_tokens) const;
181 
183  MooseEnum _region_type{"EMPTY=0 HALFSPACE=1 COMPLEMENT=2 INTERSECTION=3 UNION=4"};
184 
186  std::vector<PostfixTokenVariant> _postfix_tokens;
187 };
188 
190 
192 const CSGRegion operator+(const CSGSurface & surf);
193 
195 const CSGRegion operator-(const CSGSurface & surf);
196 
198 const CSGRegion operator&(const CSGRegion & region_a, const CSGRegion & region_b);
199 
201 const CSGRegion operator|(const CSGRegion & region_a, const CSGRegion & region_b);
202 
204 const CSGRegion operator~(const CSGRegion & region);
205 
206 } // namespace CSG
static char halfspaceSymbol(const CSGSurface::Halfspace halfspace)
Definition: CSGRegion.C:37
std::vector< std::string > toPostfixStringList() const
gets the list of postfix tokens of the region in string representation
Definition: CSGRegion.C:214
CSGRegions creates an internal representation of a CSG region, which can refer to an intersection...
Definition: CSGRegion.h:22
CSGRegion()
Default Constructor.
Definition: CSGRegion.C:90
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
static char regionSymbol(const RegionType region_type)
Definition: CSGRegion.C:16
Halfspace
Enum for the sign of the half-space being represented by a point and surface.
Definition: CSGSurface.h:30
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:317
virtual ~CSGRegion()=default
Destructor.
T getEnum() const
get the current value cast to the enum type T
Definition: MooseEnum.h:172
bool operator!=(const CSGRegion &other) const
Operator overload for checking if two CSGRegion objects are not equal.
Definition: CSGRegion.C:337
std::vector< PostfixTokenVariant > _postfix_tokens
List of tokens representing the region in postfix notation.
Definition: CSGRegion.h:186
std::vector< std::reference_wrapper< const CSGSurface > > getSurfaces() const
Get the list of surfaces associated with the region.
Definition: CSGRegion.C:266
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:242
const CSGRegion operator+(const CSGSurface &surf)
Operation overloads for operation based region construction.
Definition: CSGRegion.C:296
const std::vector< PostfixTokenVariant > & getPostfixTokens() const
Get the list of postfix tokens associated with the region.
Definition: CSGRegion.h:160
CSGRegion & operator|=(const CSGRegion &other_region)
Operator overload for |= which creates a union of the current region with the other_region.
Definition: CSGRegion.C:285
bool operator==(const CSGRegion &other) const
Operator overload for checking if two CSGRegion objects are equal.
Definition: CSGRegion.C:330
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:310
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:252
RegionType getRegionType() const
Get the region type.
Definition: CSGRegion.h:117
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.
Definition: CSGRegion.h:183
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:54
RegionType
Enum for representing region types, defined to match _region_type MooseEnum.
Definition: CSGRegion.h:26
std::string postfixTokenToString(const PostfixTokenVariant &token) const
converts postfix token from PostfixTokenVariant to string representation
Definition: CSGRegion.C:224
CSGSurface creates an internal representation of a Constructive Solid Geometry (CSG) surface...
Definition: CSGSurface.h:26
const CSGRegion operator~(const CSGRegion &region)
Overload for creating a region from the complement (~) of another region.
Definition: CSGRegion.C:324
nlohmann::json toInfixJSON() const
gets the infix JSON representation of the region, which involves converting region representation fro...
Definition: CSGRegion.C:147
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
const std::string getRegionTypeString() const
Get the region type as a string.
Definition: CSGRegion.h:124
const CSGRegion operator-(const CSGSurface &surf)
Overload for creating a region from the negative half-space (-) of a surface.
Definition: CSGRegion.C:303