LCOV - code coverage report
Current view: top level - include/csg - CSGRegion.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31730 (e8b711) with base e0c998 Lines: 6 6 100.0 %
Date: 2025-10-29 16:49:47 Functions: 5 6 83.3 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      14             : namespace CSG
      15             : {
      16             : 
      17             : /**
      18             :  * CSGRegions creates an internal representation of a CSG region, which can refer to
      19             :  * an intersection, union, complement, or half-space
      20             :  */
      21             : class CSGRegion
      22             : {
      23             : public:
      24             :   /// Enum for representing region types, defined to match _region_type MooseEnum
      25             :   enum class RegionType
      26             :   {
      27             :     EMPTY = 0,
      28             :     HALFSPACE = 1,
      29             :     COMPLEMENT = 2,
      30             :     INTERSECTION = 3,
      31             :     UNION = 4
      32             :   };
      33             : 
      34             :   /**
      35             :    * Default Constructor
      36             :    */
      37             :   CSGRegion();
      38             : 
      39             :   /**
      40             :    * @brief Constructor for half-space of a surface
      41             :    *
      42             :    * @param surf referance to surface used to define the half-space
      43             :    * @param halfspace half-space to apply to surface (POSITIVE or NEGATIVE)
      44             :    */
      45             :   CSGRegion(const CSGSurface & surf, const CSGSurface::Halfspace halfspace);
      46             : 
      47             :   /**
      48             :    * @brief Constructor for union and intersection
      49             :    *
      50             :    * @param region_a reference to first region to union or intersect
      51             :    * @param region_b reference to second region to union or intersect
      52             :    * @param region_type type of region operation (UNION or INTERSECTION)
      53             :    */
      54             :   CSGRegion(const CSGRegion & region_a,
      55             :             const CSGRegion & region_b,
      56             :             const std::string & region_type);
      57             : 
      58             :   /**
      59             :    * @brief Constructor for complement or empty region (clear the region)
      60             :    *
      61             :    * @param region reference to region to apply complement
      62             :    * @param region_type type of region to apply (COMPLEMENT or EMPTY)
      63             :    */
      64             :   CSGRegion(const CSGRegion & region, const std::string & region_type);
      65             : 
      66             :   /**
      67             :    * Destructor
      68             :    */
      69         746 :   virtual ~CSGRegion() = default;
      70             : 
      71             :   /**
      72             :    * @brief gets the string representation of the region
      73             :    *
      74             :    * @return string representation of the region
      75             :    */
      76         591 :   const std::string & toString() const { return _region_str; }
      77             : 
      78             :   /**
      79             :    * @brief Get the region type
      80             :    *
      81             :    * @return region type enum
      82             :    */
      83        1012 :   RegionType getRegionType() const { return _region_type.getEnum<RegionType>(); }
      84             : 
      85             :   /**
      86             :    * @brief Get the region type as a string
      87             :    *
      88             :    * @return region type string
      89             :    */
      90          16 :   const std::string getRegionTypeString() const { return _region_type; }
      91             : 
      92             :   /**
      93             :    * @brief Get the list of surfaces associated with the region
      94             :    *
      95             :    * @return list of pointers to surfaces that define the region
      96             :    */
      97         558 :   const std::vector<std::reference_wrapper<const CSGSurface>> & getSurfaces() const
      98             :   {
      99         558 :     return _surfaces;
     100             :   }
     101             : 
     102             :   /// Operator overload for &= which creates an intersection between the current region and the other_region
     103             :   CSGRegion & operator&=(const CSGRegion & other_region);
     104             : 
     105             :   /// Operator overload for |= which creates a union of the current region with the other_region
     106             :   CSGRegion & operator|=(const CSGRegion & other_region);
     107             : 
     108             :   /// Operator overload for checking if two CSGRegion objects are equal
     109             :   bool operator==(const CSGRegion & other) const;
     110             : 
     111             :   /// Operator overload for checking if two CSGRegion objects are not equal
     112             :   bool operator!=(const CSGRegion & other) const;
     113             : 
     114             : protected:
     115             :   /// String representation of region - defaults to empty string
     116             :   std::string _region_str;
     117             : 
     118             :   /// An enum for type of type of operation that defines region
     119             :   MooseEnum _region_type{"EMPTY=0 HALFSPACE=1 COMPLEMENT=2 INTERSECTION=3 UNION=4"};
     120             : 
     121             :   /// Surface list associated with the region
     122             :   std::vector<std::reference_wrapper<const CSGSurface>> _surfaces;
     123             : };
     124             : 
     125             : /**
     126             :  * @brief strip the leading and trailing parentheses from the string
     127             :  * if only the specified operator is present in the string
     128             :  *
     129             :  * @param region_str region string representation to simplify
     130             :  * @param op operator to consider
     131             :  * @return region string with () removed if applicable
     132             :  */
     133             : const std::string stripRegionString(std::string region_str, std::string op);
     134             : 
     135             : /// Operation overloads for operation based region construction
     136             : 
     137             : /// Overload for creating a region from the positive half-space (+) of a surface
     138             : const CSGRegion operator+(const CSGSurface & surf);
     139             : 
     140             : /// Overload for creating a region from the negative half-space (-) of a surface
     141             : const CSGRegion operator-(const CSGSurface & surf);
     142             : 
     143             : /// Overload for creating a region from the the intersection (&) of two regions
     144             : const CSGRegion operator&(const CSGRegion & region_a, const CSGRegion & region_b);
     145             : 
     146             : /// Overload for creating a region from the union (|) of two regions
     147             : const CSGRegion operator|(const CSGRegion & region_a, const CSGRegion & region_b);
     148             : 
     149             : /// Overload for creating a region from the complement (~) of another region
     150             : const CSGRegion operator~(const CSGRegion & region);
     151             : 
     152             : } // namespace CSG

Generated by: LCOV version 1.14