Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4BooleanSolid Class Reference

#include <G4BooleanSolid.hh>

+ Inheritance diagram for G4BooleanSolid:

Public Member Functions

 G4BooleanSolid (const G4String &pName, G4VSolid *pSolidA, G4VSolid *pSolidB)
 
 G4BooleanSolid (const G4String &pName, G4VSolid *pSolidA, G4VSolid *pSolidB, G4RotationMatrix *rotMatrix, const G4ThreeVector &transVector)
 
 G4BooleanSolid (const G4String &pName, G4VSolid *pSolidA, G4VSolid *pSolidB, const G4Transform3D &transform)
 
 ~G4BooleanSolid () override
 
const G4VSolidGetConstituentSolid (G4int no) const override
 
G4VSolidGetConstituentSolid (G4int no) override
 
G4double GetCubicVolume () override
 
G4double GetSurfaceArea () override
 
G4GeometryType GetEntityType () const override
 
G4PolyhedronGetPolyhedron () const override
 
std::ostream & StreamInfo (std::ostream &os) const override
 
G4int GetCubVolStatistics () const
 
G4double GetCubVolEpsilon () const
 
void SetCubVolStatistics (G4int st)
 
void SetCubVolEpsilon (G4double ep)
 
G4int GetAreaStatistics () const
 
G4double GetAreaAccuracy () const
 
void SetAreaStatistics (G4int st)
 
void SetAreaAccuracy (G4double ep)
 
G4ThreeVector GetPointOnSurface () const override
 
 G4BooleanSolid (__void__ &)
 
 G4BooleanSolid (const G4BooleanSolid &rhs)
 
G4BooleanSolidoperator= (const G4BooleanSolid &rhs)
 
- Public Member Functions inherited from G4VSolid
 G4VSolid (const G4String &name)
 
virtual ~G4VSolid ()
 
G4bool operator== (const G4VSolid &s) const
 
G4String GetName () const
 
void SetName (const G4String &name)
 
G4double GetTolerance () const
 
virtual void BoundingLimits (G4ThreeVector &pMin, G4ThreeVector &pMax) const
 
virtual G4bool CalculateExtent (const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const =0
 
virtual EInside Inside (const G4ThreeVector &p) const =0
 
virtual G4ThreeVector SurfaceNormal (const G4ThreeVector &p) const =0
 
virtual G4double DistanceToIn (const G4ThreeVector &p, const G4ThreeVector &v) const =0
 
virtual G4double DistanceToIn (const G4ThreeVector &p) const =0
 
virtual G4double DistanceToOut (const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const =0
 
virtual G4double DistanceToOut (const G4ThreeVector &p) const =0
 
virtual void ComputeDimensions (G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
 
virtual G4VSolidClone () const
 
void DumpInfo () const
 
virtual void DescribeYourselfTo (G4VGraphicsScene &scene) const =0
 
virtual G4VisExtent GetExtent () const
 
virtual G4PolyhedronCreatePolyhedron () const
 
virtual const G4DisplacedSolidGetDisplacedSolidPtr () const
 
virtual G4DisplacedSolidGetDisplacedSolidPtr ()
 
 G4VSolid (__void__ &)
 
 G4VSolid (const G4VSolid &rhs)
 
G4VSolidoperator= (const G4VSolid &rhs)
 
G4double EstimateCubicVolume (G4int nStat, G4double epsilon) const
 
G4double EstimateSurfaceArea (G4int nStat, G4double ell) const
 

Static Public Member Functions

static void SetExternalBooleanProcessor (G4VBooleanProcessor *extProcessor)
 
static G4VBooleanProcessorGetExternalBooleanProcessor ()
 

Protected Member Functions

void GetListOfPrimitives (std::vector< std::pair< G4VSolid *, G4Transform3D > > &, const G4Transform3D &) const
 
G4PolyhedronStackPolyhedron (HepPolyhedronProcessor &, const G4VSolid *) const
 
- Protected Member Functions inherited from G4VSolid
void CalculateClippedPolygonExtent (G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
 
void ClipCrossSection (G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
 
void ClipBetweenSections (G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
 
void ClipPolygon (G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis) const
 

Protected Attributes

G4VSolidfPtrSolidA = nullptr
 
G4VSolidfPtrSolidB = nullptr
 
G4double fCubicVolume = -1.0
 
G4double fSurfaceArea = -1.0
 
- Protected Attributes inherited from G4VSolid
G4double kCarTolerance
 

Static Protected Attributes

static G4VBooleanProcessorfExternalBoolProcessor = nullptr
 

Detailed Description

Definition at line 49 of file G4BooleanSolid.hh.

Constructor & Destructor Documentation

◆ G4BooleanSolid() [1/5]

G4BooleanSolid::G4BooleanSolid ( const G4String & pName,
G4VSolid * pSolidA,
G4VSolid * pSolidB )

Definition at line 54 of file G4BooleanSolid.cc.

57 : G4VSolid(pName), fPtrSolidA(pSolidA), fPtrSolidB(pSolidB)
58{
59}
G4VSolid * fPtrSolidA
G4VSolid * fPtrSolidB
G4VSolid(const G4String &name)
Definition G4VSolid.cc:57

◆ G4BooleanSolid() [2/5]

G4BooleanSolid::G4BooleanSolid ( const G4String & pName,
G4VSolid * pSolidA,
G4VSolid * pSolidB,
G4RotationMatrix * rotMatrix,
const G4ThreeVector & transVector )

Definition at line 65 of file G4BooleanSolid.cc.

70 : G4VSolid(pName), createdDisplacedSolid(true)
71{
72 fPtrSolidA = pSolidA ;
73 fPtrSolidB = new G4DisplacedSolid("placedB",pSolidB,rotMatrix,transVector) ;
74}

◆ G4BooleanSolid() [3/5]

G4BooleanSolid::G4BooleanSolid ( const G4String & pName,
G4VSolid * pSolidA,
G4VSolid * pSolidB,
const G4Transform3D & transform )

Definition at line 80 of file G4BooleanSolid.cc.

84 : G4VSolid(pName), createdDisplacedSolid(true)
85{
86 fPtrSolidA = pSolidA ;
87 fPtrSolidB = new G4DisplacedSolid("placedB",pSolidB,transform) ;
88}

◆ ~G4BooleanSolid()

G4BooleanSolid::~G4BooleanSolid ( )
override

Definition at line 104 of file G4BooleanSolid.cc.

105{
106 if(createdDisplacedSolid)
107 {
108 ((G4DisplacedSolid*)fPtrSolidB)->CleanTransformations();
109 }
110 delete fpPolyhedron; fpPolyhedron = nullptr;
111}

◆ G4BooleanSolid() [4/5]

G4BooleanSolid::G4BooleanSolid ( __void__ & a)

Definition at line 95 of file G4BooleanSolid.cc.

96 : G4VSolid(a)
97{
98}

◆ G4BooleanSolid() [5/5]

G4BooleanSolid::G4BooleanSolid ( const G4BooleanSolid & rhs)

Definition at line 117 of file G4BooleanSolid.cc.

120 fCubVolStatistics(rhs.fCubVolStatistics),
121 fAreaStatistics(rhs.fAreaStatistics),
122 fCubVolEpsilon(rhs.fCubVolEpsilon),
123 fAreaAccuracy(rhs.fAreaAccuracy),
124 createdDisplacedSolid(rhs.createdDisplacedSolid)
125{
126 fPrimitives.resize(0); fPrimitivesSurfaceArea = 0.;
127}

Member Function Documentation

◆ GetAreaAccuracy()

G4double G4BooleanSolid::GetAreaAccuracy ( ) const
inline

◆ GetAreaStatistics()

G4int G4BooleanSolid::GetAreaStatistics ( ) const
inline

◆ GetConstituentSolid() [1/2]

const G4VSolid * G4BooleanSolid::GetConstituentSolid ( G4int no) const
overridevirtual

Reimplemented from G4VSolid.

Definition at line 164 of file G4BooleanSolid.cc.

165{
166 const G4VSolid* subSolid = nullptr;
167 if( no == 0 )
168 subSolid = fPtrSolidA;
169 else if( no == 1 )
170 subSolid = fPtrSolidB;
171 else
172 {
173 DumpInfo();
174 G4Exception("G4BooleanSolid::GetConstituentSolid()",
175 "GeomSolids0002", FatalException, "Invalid solid index.");
176 }
177 return subSolid;
178}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
void DumpInfo() const

Referenced by G4IntersectionSolid::CreatePolyhedron(), G4SubtractionSolid::CreatePolyhedron(), G4UnionSolid::CreatePolyhedron(), and G4tgbGeometryDumper::DumpBooleanVolume().

◆ GetConstituentSolid() [2/2]

G4VSolid * G4BooleanSolid::GetConstituentSolid ( G4int no)
overridevirtual

Reimplemented from G4VSolid.

Definition at line 186 of file G4BooleanSolid.cc.

187{
188 G4VSolid* subSolid = nullptr;
189 if( no == 0 )
190 subSolid = fPtrSolidA;
191 else if( no == 1 )
192 subSolid = fPtrSolidB;
193 else
194 {
195 DumpInfo();
196 G4Exception("G4BooleanSolid::GetConstituentSolid()",
197 "GeomSolids0002", FatalException, "Invalid solid index.");
198 }
199 return subSolid;
200}

◆ GetCubicVolume()

G4double G4BooleanSolid::GetCubicVolume ( )
overridevirtual

Reimplemented from G4VSolid.

Reimplemented in G4SubtractionSolid, and G4UnionSolid.

Definition at line 423 of file G4BooleanSolid.cc.

424{
425 if(fCubicVolume < 0.)
426 {
427 fCubicVolume = EstimateCubicVolume(fCubVolStatistics, fCubVolEpsilon);
428 }
429 return fCubicVolume;
430}
G4double EstimateCubicVolume(G4int nStat, G4double epsilon) const
Definition G4VSolid.cc:203

Referenced by G4SubtractionSolid::GetCubicVolume(), and G4UnionSolid::GetCubicVolume().

◆ GetCubVolEpsilon()

G4double G4BooleanSolid::GetCubVolEpsilon ( ) const
inline

◆ GetCubVolStatistics()

G4int G4BooleanSolid::GetCubVolStatistics ( ) const
inline

◆ GetEntityType()

G4GeometryType G4BooleanSolid::GetEntityType ( ) const
overridevirtual

Implements G4VSolid.

Reimplemented in G4IntersectionSolid, G4SubtractionSolid, and G4UnionSolid.

Definition at line 206 of file G4BooleanSolid.cc.

207{
208 return {"G4BooleanSolid"};
209}

Referenced by StreamInfo().

◆ GetExternalBooleanProcessor()

G4VBooleanProcessor * G4BooleanSolid::GetExternalBooleanProcessor ( )
static

Definition at line 446 of file G4BooleanSolid.cc.

447{
449}
static G4VBooleanProcessor * fExternalBoolProcessor

Referenced by G4MultiUnion::CreatePolyhedron().

◆ GetListOfPrimitives()

void G4BooleanSolid::GetListOfPrimitives ( std::vector< std::pair< G4VSolid *, G4Transform3D > > & primitives,
const G4Transform3D & curPlacement ) const
protected

Definition at line 234 of file G4BooleanSolid.cc.

237{
238 G4Transform3D transform;
239 G4VSolid* solid;
240 G4String type;
241
242 // Repeat two times, first time for fPtrSolidA and then for fPtrSolidB
243 //
244 for (auto i=0; i<2; ++i)
245 {
246 transform = curPlacement;
247 solid = (i == 0) ? fPtrSolidA : fPtrSolidB;
248 type = solid->GetEntityType();
249
250 // While current solid is a trasformed solid just modify transform
251 //
252 while (type == "G4DisplacedSolid" ||
253 type == "G4ReflectedSolid" ||
254 type == "G4ScaledSolid")
255 {
256 if (type == "G4DisplacedSolid")
257 {
258 transform = transform * G4Transform3D(
259 ((G4DisplacedSolid*)solid)->GetObjectRotation(),
260 ((G4DisplacedSolid*)solid)->GetObjectTranslation());
261 solid = ((G4DisplacedSolid*)solid)->GetConstituentMovedSolid();
262 }
263 else if (type == "G4ReflectedSolid")
264 {
265 transform= transform*((G4ReflectedSolid*)solid)->GetDirectTransform3D();
266 solid = ((G4ReflectedSolid*)solid)->GetConstituentMovedSolid();
267 }
268 else if (type == "G4ScaledSolid")
269 {
270 transform = transform * ((G4ScaledSolid*)solid)->GetScaleTransform();
271 solid = ((G4ScaledSolid*)solid)->GetUnscaledSolid();
272 }
273 type = solid->GetEntityType();
274 }
275
276 // If current solid is a Boolean solid then continue recursion,
277 // otherwise add it to the list of primitives
278 //
279 if (type == "G4UnionSolid" ||
280 type == "G4SubtractionSolid" ||
281 type == "G4IntersectionSolid" ||
282 type == "G4BooleanSolid")
283 {
284 ((G4BooleanSolid *)solid)->GetListOfPrimitives(primitives,transform);
285 }
286 else
287 {
288 primitives.emplace_back(solid,transform);
289 }
290 }
291}
HepGeom::Transform3D G4Transform3D
G4VSolid * GetConstituentMovedSolid() const
G4GeometryType GetEntityType() const override
virtual G4GeometryType GetEntityType() const =0

Referenced by GetPointOnSurface().

◆ GetPointOnSurface()

G4ThreeVector G4BooleanSolid::GetPointOnSurface ( ) const
overridevirtual

Reimplemented from G4VSolid.

Definition at line 298 of file G4BooleanSolid.cc.

299{
300 std::size_t nprims = fPrimitives.size();
301 std::pair<G4VSolid *, G4Transform3D> prim;
302
303 // Get list of primitives and find the total area of their surfaces
304 //
305 if (nprims == 0)
306 {
307 GetListOfPrimitives(fPrimitives, G4Transform3D());
308 nprims = fPrimitives.size();
309 fPrimitivesSurfaceArea = 0.;
310 for (std::size_t i=0; i<nprims; ++i)
311 {
312 fPrimitivesSurfaceArea += fPrimitives[i].first->GetSurfaceArea();
313 }
314 }
315
316 // Select random primitive, get random point on its surface and
317 // check that the point belongs to the surface of the solid
318 //
320 for (std::size_t k=0; k<100000; ++k) // try 100k times
321 {
322 G4double rand = fPrimitivesSurfaceArea * G4QuickRand();
323 G4double area = 0.;
324 for (std::size_t i=0; i<nprims; ++i)
325 {
326 prim = fPrimitives[i];
327 area += prim.first->GetSurfaceArea();
328 if (rand < area) break;
329 }
330 p = prim.first->GetPointOnSurface();
331 p = prim.second * G4Point3D(p);
332 if (Inside(p) == kSurface) return p;
333 }
334 std::ostringstream message;
335 message << "Solid - " << GetName() << "\n"
336 << "All 100k attempts to generate a point on the surface have failed!\n"
337 << "The solid created may be an invalid Boolean construct!";
338 G4Exception("G4BooleanSolid::GetPointOnSurface()",
339 "GeomSolids1001", JustWarning, message);
340 return p;
341}
@ JustWarning
HepGeom::Point3D< G4double > G4Point3D
Definition G4Point3D.hh:34
G4double G4QuickRand()
double G4double
Definition G4Types.hh:83
void GetListOfPrimitives(std::vector< std::pair< G4VSolid *, G4Transform3D > > &, const G4Transform3D &) const
G4String GetName() const
virtual EInside Inside(const G4ThreeVector &p) const =0
@ kSurface
Definition geomdefs.hh:69

◆ GetPolyhedron()

G4Polyhedron * G4BooleanSolid::GetPolyhedron ( ) const
overridevirtual

Reimplemented from G4VSolid.

Definition at line 347 of file G4BooleanSolid.cc.

348{
349 if (fpPolyhedron == nullptr ||
350 fRebuildPolyhedron ||
352 fpPolyhedron->GetNumberOfRotationSteps())
353 {
354 G4RecursiveAutoLock l(&polyhedronMutex);
355 delete fpPolyhedron;
356 fpPolyhedron = CreatePolyhedron();
357 fRebuildPolyhedron = false;
358 l.unlock();
359 }
360 return fpPolyhedron;
361}
G4int GetNumberOfRotationStepsAtTimeOfCreation() const
virtual G4Polyhedron * CreatePolyhedron() const
Definition G4VSolid.cc:700
static G4int GetNumberOfRotationSteps()

Referenced by G4IntersectionSolid::CreatePolyhedron(), G4SubtractionSolid::CreatePolyhedron(), and G4UnionSolid::CreatePolyhedron().

◆ GetSurfaceArea()

G4double G4BooleanSolid::GetSurfaceArea ( )
inlineoverridevirtual

Reimplemented from G4VSolid.

◆ operator=()

G4BooleanSolid & G4BooleanSolid::operator= ( const G4BooleanSolid & rhs)

Definition at line 133 of file G4BooleanSolid.cc.

134{
135 // Check assignment to self
136 //
137 if (this == &rhs) { return *this; }
138
139 // Copy base class data
140 //
142
143 // Copy data
144 //
147 fCubVolStatistics = rhs.fCubVolStatistics; fCubVolEpsilon = rhs.fCubVolEpsilon;
148 fAreaStatistics = rhs.fAreaStatistics; fAreaAccuracy = rhs.fAreaAccuracy;
149 createdDisplacedSolid= rhs.createdDisplacedSolid;
150
151 fRebuildPolyhedron = false;
152 delete fpPolyhedron; fpPolyhedron = nullptr;
153 fPrimitives.resize(0); fPrimitivesSurfaceArea = 0.;
154
155 return *this;
156}
G4VSolid & operator=(const G4VSolid &rhs)
Definition G4VSolid.cc:107

Referenced by G4IntersectionSolid::operator=(), G4SubtractionSolid::operator=(), and G4UnionSolid::operator=().

◆ SetAreaAccuracy()

void G4BooleanSolid::SetAreaAccuracy ( G4double ep)
inline

◆ SetAreaStatistics()

void G4BooleanSolid::SetAreaStatistics ( G4int st)
inline

◆ SetCubVolEpsilon()

void G4BooleanSolid::SetCubVolEpsilon ( G4double ep)
inline

◆ SetCubVolStatistics()

void G4BooleanSolid::SetCubVolStatistics ( G4int st)
inline

◆ SetExternalBooleanProcessor()

void G4BooleanSolid::SetExternalBooleanProcessor ( G4VBooleanProcessor * extProcessor)
static

Definition at line 437 of file G4BooleanSolid.cc.

438{
439 fExternalBoolProcessor = extProcessor;
440}

◆ StackPolyhedron()

G4Polyhedron * G4BooleanSolid::StackPolyhedron ( HepPolyhedronProcessor & processor,
const G4VSolid * solid ) const
protected

Definition at line 368 of file G4BooleanSolid.cc.

370{
372 const G4String& type = solid->GetEntityType();
373 if (type == "G4UnionSolid")
374 { operation = HepPolyhedronProcessor::UNION; }
375 else if (type == "G4IntersectionSolid")
377 else if (type == "G4SubtractionSolid")
379 else
380 {
381 std::ostringstream message;
382 message << "Solid - " << solid->GetName()
383 << " - Unrecognised composite solid" << G4endl
384 << " Returning NULL !";
385 G4Exception("StackPolyhedron()", "GeomSolids1001", JustWarning, message);
386 return nullptr;
387 }
388
389 G4Polyhedron* top = nullptr;
390 const G4VSolid* solidA = solid->GetConstituentSolid(0);
391 const G4VSolid* solidB = solid->GetConstituentSolid(1);
392
393 if (solidA->GetConstituentSolid(0) != nullptr)
394 {
395 top = StackPolyhedron(processor, solidA);
396 }
397 else
398 {
399 top = solidA->GetPolyhedron();
400 }
401 G4Polyhedron* operand = solidB->GetPolyhedron();
402 if (operand != nullptr)
403 {
404 processor.push_back (operation, *operand);
405 }
406 else
407 {
408 std::ostringstream message;
409 message << "Solid - " << solid->GetName()
410 << " - No G4Polyhedron for Boolean component";
411 G4Exception("G4BooleanSolid::StackPolyhedron()",
412 "GeomSolids2001", JustWarning, message);
413 }
414
415 return top;
416}
#define G4endl
Definition G4ios.hh:67
G4Polyhedron * StackPolyhedron(HepPolyhedronProcessor &, const G4VSolid *) const
virtual const G4VSolid * GetConstituentSolid(G4int no) const
Definition G4VSolid.cc:167
virtual G4Polyhedron * GetPolyhedron() const
Definition G4VSolid.cc:705
void push_back(Operation, const HepPolyhedron &)

Referenced by G4IntersectionSolid::CreatePolyhedron(), G4SubtractionSolid::CreatePolyhedron(), G4UnionSolid::CreatePolyhedron(), and StackPolyhedron().

◆ StreamInfo()

std::ostream & G4BooleanSolid::StreamInfo ( std::ostream & os) const
overridevirtual

Implements G4VSolid.

Definition at line 215 of file G4BooleanSolid.cc.

216{
217 os << "-----------------------------------------------------------\n"
218 << " *** Dump for Boolean solid - " << GetName() << " ***\n"
219 << " ===================================================\n"
220 << " Solid type: " << GetEntityType() << "\n"
221 << " Parameters of constituent solids: \n"
222 << "===========================================================\n";
225 os << "===========================================================\n";
226
227 return os;
228}
G4GeometryType GetEntityType() const override
virtual std::ostream & StreamInfo(std::ostream &os) const =0

Member Data Documentation

◆ fCubicVolume

G4double G4BooleanSolid::fCubicVolume = -1.0
protected

◆ fExternalBoolProcessor

◆ fPtrSolidA

◆ fPtrSolidB

◆ fSurfaceArea

G4double G4BooleanSolid::fSurfaceArea = -1.0
protected

Definition at line 127 of file G4BooleanSolid.hh.

Referenced by operator=().


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