https://mooseframework.inl.gov
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CSG::CSGPlane Class Reference

CSGPlane creates an internal representation of a Constructive Solid Geometry (CSG) plane, represented in the form aX + bY + cZ = d. More...

#include <CSGPlane.h>

Inheritance diagram for CSG::CSGPlane:
[legend]

Public Types

enum  Halfspace { Halfspace::POSITIVE, Halfspace::NEGATIVE }
 Enum for the sign of the half-space being represented by a point and surface. More...
 

Public Member Functions

 CSGPlane (const std::string &name, const Point &p1, const Point &p2, const Point &p3)
 Construct a new CSGPlane surface from three non co-linear points. More...
 
 CSGPlane (const std::string &name, const Real a, const Real b, const Real c, const Real d)
 Construct a new CSGPlane surface from coefficients (a, b, c, d) for the equation of a plane: aX + bY + cZ = d. More...
 
virtual ~CSGPlane ()=default
 Destructor. More...
 
virtual std::unordered_map< std::string, RealgetCoeffs () const override
 get coefficients (a, b, c, d) of the Plane aX + bY + cZ = d More...
 
virtual Real evaluateSurfaceEquationAtPoint (const Point &p) const override
 given a point, determine its evaluation based on the equation of the plane More...
 
const std::string & getSurfaceType () const
 Get the Surface Type. More...
 
CSGSurface::Halfspace getHalfspaceFromPoint (const Point &p) const
 given a point, determine if it is in the positive or negative half-space for the surface More...
 
const std::string & getName () const
 Get the name of surface. More...
 
bool operator== (const CSGSurface &other) const
 Operator overload for checking if two CSGSurface objects are equal. More...
 
bool operator!= (const CSGSurface &other) const
 Operator overload for checking if two CSGSurface objects are not equal. More...
 

Protected Member Functions

virtual std::unique_ptr< CSGSurfaceclone () const override
 create clone of CSGPlane object More...
 
void coeffsFromPoints (const Point &p1, const Point &p2, const Point &p3)
 
void normalizePlaneCoefficients ()
 Normalize plane coefficients so that a^2 + b^2 + c^2 = 1. More...
 
void setName (const std::string &name)
 
 FRIEND_TEST (CSGSurfaceTest, testSetName)
 Friends for unit testing. More...
 

Protected Attributes

Real _a
 Value of a in equation of plane. More...
 
Real _b
 Value of b in equation of plane. More...
 
Real _c
 Value of c in equation of plane. More...
 
Real _d
 Value of d in equation of plane. More...
 
std::string _name
 Name of surface. More...
 
const std::string _surface_type
 Type of surface that is being represented string is taken directly from the surface class name. More...
 

Detailed Description

CSGPlane creates an internal representation of a Constructive Solid Geometry (CSG) plane, represented in the form aX + bY + cZ = d.

Definition at line 23 of file CSGPlane.h.

Member Enumeration Documentation

◆ Halfspace

enum CSG::CSGSurface::Halfspace
stronginherited

Enum for the sign of the half-space being represented by a point and surface.

Enumerator
POSITIVE 
NEGATIVE 

Definition at line 30 of file CSGSurface.h.

31  {
32  POSITIVE,
33  NEGATIVE
34  };

Constructor & Destructor Documentation

◆ CSGPlane() [1/2]

CSG::CSGPlane::CSGPlane ( const std::string &  name,
const Point &  p1,
const Point &  p2,
const Point &  p3 
)

Construct a new CSGPlane surface from three non co-linear points.

Parameters
nameunique name of plane
p1point 1
p2point 2
p3point 3

Definition at line 15 of file CSGPlane.C.

16  : CSGSurface(name, MooseUtils::prettyCppType<CSGPlane>())
17 {
18  coeffsFromPoints(p1, p2, p3);
20 }
void normalizePlaneCoefficients()
Normalize plane coefficients so that a^2 + b^2 + c^2 = 1.
Definition: CSGPlane.C:55
CSGSurface(const std::string &name)
Default constructor.
void coeffsFromPoints(const Point &p1, const Point &p2, const Point &p3)
Definition: CSGPlane.C:36

◆ CSGPlane() [2/2]

CSG::CSGPlane::CSGPlane ( const std::string &  name,
const Real  a,
const Real  b,
const Real  c,
const Real  d 
)

Construct a new CSGPlane surface from coefficients (a, b, c, d) for the equation of a plane: aX + bY + cZ = d.

Parameters
nameunique name of plane
acoefficient a
bcoefficient b
ccoefficient c
dcoefficient d

Definition at line 22 of file CSGPlane.C.

23  : CSGSurface(name, MooseUtils::prettyCppType<CSGPlane>()), _a(a), _b(b), _c(c), _d(d)
24 {
26 }
Real _a
Value of a in equation of plane.
Definition: CSGPlane.h:87
void normalizePlaneCoefficients()
Normalize plane coefficients so that a^2 + b^2 + c^2 = 1.
Definition: CSGPlane.C:55
Real _b
Value of b in equation of plane.
Definition: CSGPlane.h:90
Real _d
Value of d in equation of plane.
Definition: CSGPlane.h:96
CSGSurface(const std::string &name)
Default constructor.
Real _c
Value of c in equation of plane.
Definition: CSGPlane.h:93

◆ ~CSGPlane()

virtual CSG::CSGPlane::~CSGPlane ( )
virtualdefault

Destructor.

Member Function Documentation

◆ clone()

virtual std::unique_ptr<CSGSurface> CSG::CSGPlane::clone ( ) const
inlineoverrideprotectedvirtual

create clone of CSGPlane object

Returns
std::unordered_map<CSGSurface> unique_ptr to cloned plane

Implements CSG::CSGSurface.

Definition at line 75 of file CSGPlane.h.

76  {
77  return std::make_unique<CSGPlane>(_name, _a, _b, _c, _d);
78  }
Real _a
Value of a in equation of plane.
Definition: CSGPlane.h:87
Real _b
Value of b in equation of plane.
Definition: CSGPlane.h:90
std::string _name
Name of surface.
Definition: CSGSurface.h:116
Real _d
Value of d in equation of plane.
Definition: CSGPlane.h:96
Real _c
Value of c in equation of plane.
Definition: CSGPlane.h:93

◆ coeffsFromPoints()

void CSG::CSGPlane::coeffsFromPoints ( const Point &  p1,
const Point &  p2,
const Point &  p3 
)
protected

Definition at line 36 of file CSGPlane.C.

Referenced by CSGPlane().

37 {
38  // Use three points on plane to solve for the plane equation in form aX + bY +cZ = d,
39  // where we are solving for a, b, c, and d.
40  RealVectorValue v1 = p2 - p1;
41  RealVectorValue v2 = p3 - p1;
42  RealVectorValue cross = v2.cross(v1);
43 
44  // Check that provided points aren't collinear
45  if (MooseUtils::absoluteFuzzyEqual(cross.norm(), 0))
46  mooseError("Provided points to define a CSGPlane are collinear");
47 
48  _a = cross(0);
49  _b = cross(1);
50  _c = cross(2);
51  _d = cross * (RealVectorValue)p1;
52 }
auto norm() const -> decltype(std::norm(Real()))
Real _a
Value of a in equation of plane.
Definition: CSGPlane.h:87
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
TypeVector< typename CompareTypes< Real, T2 >::supertype > cross(const TypeVector< T2 > &v) const
Real _b
Value of b in equation of plane.
Definition: CSGPlane.h:90
Real _d
Value of d in equation of plane.
Definition: CSGPlane.h:96
Real _c
Value of c in equation of plane.
Definition: CSGPlane.h:93

◆ evaluateSurfaceEquationAtPoint()

Real CSG::CSGPlane::evaluateSurfaceEquationAtPoint ( const Point &  p) const
overridevirtual

given a point, determine its evaluation based on the equation of the plane

Parameters
ppoint
Returns
evaluation of point based on surface equation

Implements CSG::CSGSurface.

Definition at line 65 of file CSGPlane.C.

66 {
67  // Compute dot product of <a, b, c> and p to determine if p lies
68  // in the positive or negative halfspace of the plane
69  const Real dot_prod = _a * p(0) + _b * p(1) + _c * p(2);
70 
71  return dot_prod - _d;
72 }
Real _a
Value of a in equation of plane.
Definition: CSGPlane.h:87
Real _b
Value of b in equation of plane.
Definition: CSGPlane.h:90
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real _d
Value of d in equation of plane.
Definition: CSGPlane.h:96
Real _c
Value of c in equation of plane.
Definition: CSGPlane.h:93

◆ FRIEND_TEST()

CSG::CSGSurface::FRIEND_TEST ( CSGSurfaceTest  ,
testSetName   
)
protectedinherited

Friends for unit testing.

◆ getCoeffs()

std::unordered_map< std::string, Real > CSG::CSGPlane::getCoeffs ( ) const
overridevirtual

get coefficients (a, b, c, d) of the Plane aX + bY + cZ = d

Returns
std::unordered_map<std::string, Real> map of coefficients (a, b, c, and d) and their values

Implements CSG::CSGSurface.

Definition at line 29 of file CSGPlane.C.

30 {
31  std::unordered_map<std::string, Real> coeffs = {{"a", _a}, {"b", _b}, {"c", _c}, {"d", _d}};
32  return coeffs;
33 }
Real _a
Value of a in equation of plane.
Definition: CSGPlane.h:87
Real _b
Value of b in equation of plane.
Definition: CSGPlane.h:90
Real _d
Value of d in equation of plane.
Definition: CSGPlane.h:96
Real _c
Value of c in equation of plane.
Definition: CSGPlane.h:93

◆ getHalfspaceFromPoint()

CSGSurface::Halfspace CSG::CSGSurface::getHalfspaceFromPoint ( const Point &  p) const
inherited

given a point, determine if it is in the positive or negative half-space for the surface

Parameters
ppoint
Returns
sign of the half-space

Definition at line 21 of file CSGSurface.C.

22 {
23  auto eval = evaluateSurfaceEquationAtPoint(p);
24  if (MooseUtils::absoluteFuzzyGreaterThan(eval, 0))
25  return Halfspace::POSITIVE;
26  else if (MooseUtils::absoluteFuzzyLessThan(eval, 0))
27  return Halfspace::NEGATIVE;
28  else
29  mooseError("Point ",
30  p,
31  " used to determine halfspace evaluation lies on the surface ",
32  _name,
33  ", leading to an ambiguously defined halfspace.");
34 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
virtual Real evaluateSurfaceEquationAtPoint(const Point &p) const =0
given a point, determine its evaluation based on the surface equation.
std::string _name
Name of surface.
Definition: CSGSurface.h:116

◆ getName()

const std::string& CSG::CSGSurface::getName ( ) const
inlineinherited

Get the name of surface.

Returns
std::string name of surface

Definition at line 95 of file CSGSurface.h.

Referenced by CSG::CSGSurfaceList::addSurface(), CSG::CSGRegion::CSGRegion(), CSG::CSGSurface::operator==(), and CSG::CSGSurfaceList::renameSurface().

95 { return _name; }
std::string _name
Name of surface.
Definition: CSGSurface.h:116

◆ getSurfaceType()

const std::string& CSG::CSGSurface::getSurfaceType ( ) const
inlineinherited

Get the Surface Type.

Returns
type of surface

Definition at line 61 of file CSGSurface.h.

Referenced by CSG::CSGSurface::operator==().

61 { return _surface_type; }
const std::string _surface_type
Type of surface that is being represented string is taken directly from the surface class name...
Definition: CSGSurface.h:120

◆ normalizePlaneCoefficients()

void CSG::CSGPlane::normalizePlaneCoefficients ( )
protected

Normalize plane coefficients so that a^2 + b^2 + c^2 = 1.

Definition at line 55 of file CSGPlane.C.

Referenced by CSGPlane().

56 {
57  const auto k = 1. / std::sqrt(_a * _a + _b * _b + _c * _c);
58  _a *= k;
59  _b *= k;
60  _c *= k;
61  _d *= k;
62 }
Real _a
Value of a in equation of plane.
Definition: CSGPlane.h:87
Real _b
Value of b in equation of plane.
Definition: CSGPlane.h:90
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh
Real _d
Value of d in equation of plane.
Definition: CSGPlane.h:96
Real _c
Value of c in equation of plane.
Definition: CSGPlane.h:93

◆ operator!=()

bool CSG::CSGSurface::operator!= ( const CSGSurface other) const
inherited

Operator overload for checking if two CSGSurface objects are not equal.

Definition at line 45 of file CSGSurface.C.

46 {
47  return !(*this == other);
48 }

◆ operator==()

bool CSG::CSGSurface::operator== ( const CSGSurface other) const
inherited

Operator overload for checking if two CSGSurface objects are equal.

Definition at line 37 of file CSGSurface.C.

38 {
39  return (this->getName() == other.getName()) &&
40  (this->getSurfaceType() == other.getSurfaceType()) &&
41  (this->getCoeffs() == other.getCoeffs());
42 }
const std::string & getName() const
Get the name of surface.
Definition: CSGSurface.h:95
virtual std::unordered_map< std::string, Real > getCoeffs() const =0
Get the coefficients that define the surface.
const std::string & getSurfaceType() const
Get the Surface Type.
Definition: CSGSurface.h:61

◆ setName()

void CSG::CSGSurface::setName ( const std::string &  name)
inlineprotectedinherited

Definition at line 113 of file CSGSurface.h.

113 { _name = name; }
std::string name(const ElemQuality q)
std::string _name
Name of surface.
Definition: CSGSurface.h:116

Member Data Documentation

◆ _a

Real CSG::CSGPlane::_a
protected

Value of a in equation of plane.

Definition at line 87 of file CSGPlane.h.

Referenced by clone(), coeffsFromPoints(), evaluateSurfaceEquationAtPoint(), getCoeffs(), and normalizePlaneCoefficients().

◆ _b

Real CSG::CSGPlane::_b
protected

Value of b in equation of plane.

Definition at line 90 of file CSGPlane.h.

Referenced by clone(), coeffsFromPoints(), evaluateSurfaceEquationAtPoint(), getCoeffs(), and normalizePlaneCoefficients().

◆ _c

Real CSG::CSGPlane::_c
protected

Value of c in equation of plane.

Definition at line 93 of file CSGPlane.h.

Referenced by clone(), coeffsFromPoints(), evaluateSurfaceEquationAtPoint(), getCoeffs(), and normalizePlaneCoefficients().

◆ _d

Real CSG::CSGPlane::_d
protected

Value of d in equation of plane.

Definition at line 96 of file CSGPlane.h.

Referenced by clone(), coeffsFromPoints(), evaluateSurfaceEquationAtPoint(), getCoeffs(), and normalizePlaneCoefficients().

◆ _name

std::string CSG::CSGSurface::_name
protectedinherited

◆ _surface_type

const std::string CSG::CSGSurface::_surface_type
protectedinherited

Type of surface that is being represented string is taken directly from the surface class name.

Definition at line 120 of file CSGSurface.h.

Referenced by CSG::CSGSurface::getSurfaceType().


The documentation for this class was generated from the following files: