Geant4 11.1.1
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)
 
virtual ~G4BooleanSolid ()
 
virtual const G4VSolidGetConstituentSolid (G4int no) const
 
virtual G4VSolidGetConstituentSolid (G4int no)
 
virtual G4double GetCubicVolume ()
 
G4double GetSurfaceArea ()
 
virtual G4GeometryType GetEntityType () const
 
virtual G4PolyhedronGetPolyhedron () const
 
std::ostream & StreamInfo (std::ostream &os) const
 
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
 
 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 G4double GetCubicVolume ()
 
virtual G4double GetSurfaceArea ()
 
virtual G4GeometryType GetEntityType () const =0
 
virtual G4ThreeVector GetPointOnSurface () const
 
virtual G4VSolidClone () const
 
virtual std::ostream & StreamInfo (std::ostream &os) const =0
 
void DumpInfo () const
 
virtual void DescribeYourselfTo (G4VGraphicsScene &scene) const =0
 
virtual G4VisExtent GetExtent () const
 
virtual G4PolyhedronCreatePolyhedron () const
 
virtual G4PolyhedronGetPolyhedron () const
 
virtual const G4VSolidGetConstituentSolid (G4int no) const
 
virtual G4VSolidGetConstituentSolid (G4int no)
 
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
 

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
 
- Protected Attributes inherited from G4VSolid
G4double kCarTolerance
 

Detailed Description

Definition at line 46 of file G4BooleanSolid.hh.

Constructor & Destructor Documentation

◆ G4BooleanSolid() [1/5]

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

Definition at line 52 of file G4BooleanSolid.cc.

55 : G4VSolid(pName), fPtrSolidA(pSolidA), fPtrSolidB(pSolidB)
56{
57}
G4VSolid * fPtrSolidA
G4VSolid * fPtrSolidB

◆ G4BooleanSolid() [2/5]

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

Definition at line 63 of file G4BooleanSolid.cc.

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

◆ G4BooleanSolid() [3/5]

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

Definition at line 78 of file G4BooleanSolid.cc.

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

◆ ~G4BooleanSolid()

G4BooleanSolid::~G4BooleanSolid ( )
virtual

Definition at line 102 of file G4BooleanSolid.cc.

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

◆ G4BooleanSolid() [4/5]

G4BooleanSolid::G4BooleanSolid ( __void__ &  a)

Definition at line 93 of file G4BooleanSolid.cc.

94 : G4VSolid(a)
95{
96}

◆ G4BooleanSolid() [5/5]

G4BooleanSolid::G4BooleanSolid ( const G4BooleanSolid rhs)

Definition at line 115 of file G4BooleanSolid.cc.

117 fCubicVolume(rhs.fCubicVolume), fStatistics(rhs.fStatistics),
118 fCubVolEpsilon(rhs.fCubVolEpsilon), fAreaAccuracy(rhs.fAreaAccuracy),
119 fSurfaceArea(rhs.fSurfaceArea), fRebuildPolyhedron(false),
120 fpPolyhedron(nullptr), createdDisplacedSolid(rhs.createdDisplacedSolid)
121{
122 fPrimitives.resize(0); fPrimitivesSurfaceArea = 0.;
123}
G4double fCubicVolume

Member Function Documentation

◆ GetAreaAccuracy()

G4double G4BooleanSolid::GetAreaAccuracy ( ) const
inline

◆ GetAreaStatistics()

G4int G4BooleanSolid::GetAreaStatistics ( ) const
inline

◆ GetConstituentSolid() [1/2]

G4VSolid * G4BooleanSolid::GetConstituentSolid ( G4int  no)
virtual

Reimplemented from G4VSolid.

Definition at line 181 of file G4BooleanSolid.cc.

182{
183 G4VSolid* subSolid = nullptr;
184 if( no == 0 )
185 subSolid = fPtrSolidA;
186 else if( no == 1 )
187 subSolid = fPtrSolidB;
188 else
189 {
190 DumpInfo();
191 G4Exception("G4BooleanSolid::GetConstituentSolid()",
192 "GeomSolids0002", FatalException, "Invalid solid index.");
193 }
194 return subSolid;
195}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
void DumpInfo() const

◆ GetConstituentSolid() [2/2]

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

Reimplemented from G4VSolid.

Definition at line 159 of file G4BooleanSolid.cc.

160{
161 const G4VSolid* subSolid = nullptr;
162 if( no == 0 )
163 subSolid = fPtrSolidA;
164 else if( no == 1 )
165 subSolid = fPtrSolidB;
166 else
167 {
168 DumpInfo();
169 G4Exception("G4BooleanSolid::GetConstituentSolid()",
170 "GeomSolids0002", FatalException, "Invalid solid index.");
171 }
172 return subSolid;
173}

Referenced by G4tgbGeometryDumper::DumpBooleanVolume().

◆ GetCubicVolume()

G4double G4BooleanSolid::GetCubicVolume ( )
virtual

Reimplemented from G4VSolid.

Reimplemented in G4SubtractionSolid, and G4UnionSolid.

Definition at line 418 of file G4BooleanSolid.cc.

419{
420 if(fCubicVolume < 0.)
421 {
422 fCubicVolume = EstimateCubicVolume(fStatistics,fCubVolEpsilon);
423 }
424 return fCubicVolume;
425}
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
virtual

Implements G4VSolid.

Reimplemented in G4IntersectionSolid, G4SubtractionSolid, and G4UnionSolid.

Definition at line 201 of file G4BooleanSolid.cc.

202{
203 return G4String("G4BooleanSolid");
204}

Referenced by StreamInfo().

◆ GetListOfPrimitives()

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

Definition at line 229 of file G4BooleanSolid.cc.

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

Referenced by GetPointOnSurface().

◆ GetPointOnSurface()

G4ThreeVector G4BooleanSolid::GetPointOnSurface ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 293 of file G4BooleanSolid.cc.

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

Reimplemented from G4VSolid.

Definition at line 342 of file G4BooleanSolid.cc.

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

◆ GetSurfaceArea()

G4double G4BooleanSolid::GetSurfaceArea ( )
inlinevirtual

Reimplemented from G4VSolid.

◆ operator=()

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

Definition at line 129 of file G4BooleanSolid.cc.

130{
131 // Check assignment to self
132 //
133 if (this == &rhs) { return *this; }
134
135 // Copy base class data
136 //
138
139 // Copy data
140 //
142 fStatistics= rhs.fStatistics; fCubVolEpsilon= rhs.fCubVolEpsilon;
143 fAreaAccuracy= rhs.fAreaAccuracy; fCubicVolume= rhs.fCubicVolume;
144 fSurfaceArea= rhs.fSurfaceArea;
145 createdDisplacedSolid= rhs.createdDisplacedSolid;
146 fRebuildPolyhedron = false;
147 delete fpPolyhedron; fpPolyhedron = nullptr;
148 fPrimitives.resize(0); fPrimitivesSurfaceArea = 0.;
149
150 return *this;
151}
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

◆ StackPolyhedron()

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

Definition at line 363 of file G4BooleanSolid.cc.

365{
367 const G4String& type = solid->GetEntityType();
368 if (type == "G4UnionSolid")
369 { operation = HepPolyhedronProcessor::UNION; }
370 else if (type == "G4IntersectionSolid")
372 else if (type == "G4SubtractionSolid")
374 else
375 {
376 std::ostringstream message;
377 message << "Solid - " << solid->GetName()
378 << " - Unrecognised composite solid" << G4endl
379 << " Returning NULL !";
380 G4Exception("StackPolyhedron()", "GeomSolids1001", JustWarning, message);
381 return nullptr;
382 }
383
384 G4Polyhedron* top = nullptr;
385 const G4VSolid* solidA = solid->GetConstituentSolid(0);
386 const G4VSolid* solidB = solid->GetConstituentSolid(1);
387
388 if (solidA->GetConstituentSolid(0) != nullptr)
389 {
390 top = StackPolyhedron(processor, solidA);
391 }
392 else
393 {
394 top = solidA->GetPolyhedron();
395 }
396 G4Polyhedron* operand = solidB->GetPolyhedron();
397 if (operand != nullptr)
398 {
399 processor.push_back (operation, *operand);
400 }
401 else
402 {
403 std::ostringstream message;
404 message << "Solid - " << solid->GetName()
405 << " - No G4Polyhedron for Boolean component";
406 G4Exception("G4BooleanSolid::StackPolyhedron()",
407 "GeomSolids2001", JustWarning, message);
408 }
409
410 return top;
411}
#define G4endl
Definition: G4ios.hh:57
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
virtual

Implements G4VSolid.

Definition at line 210 of file G4BooleanSolid.cc.

211{
212 os << "-----------------------------------------------------------\n"
213 << " *** Dump for Boolean solid - " << GetName() << " ***\n"
214 << " ===================================================\n"
215 << " Solid type: " << GetEntityType() << "\n"
216 << " Parameters of constituent solids: \n"
217 << "===========================================================\n";
220 os << "===========================================================\n";
221
222 return os;
223}
virtual G4GeometryType GetEntityType() const
virtual std::ostream & StreamInfo(std::ostream &os) const =0

Member Data Documentation

◆ fCubicVolume

G4double G4BooleanSolid::fCubicVolume = -1.0
protected

◆ fPtrSolidA

◆ fPtrSolidB


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