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

G4SubtractionSolid is a solid describing the Boolean subtraction of two solids. More...

#include <G4SubtractionSolid.hh>

Inheritance diagram for G4SubtractionSolid:

Public Member Functions

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

Additional Inherited Members

Static Public Member Functions inherited from G4BooleanSolid
static G4VBooleanProcessorGetExternalBooleanProcessor ()
static void SetExternalBooleanProcessor (G4VBooleanProcessor *extProcessor)
Protected Member Functions inherited from G4BooleanSolid
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 inherited from G4BooleanSolid
G4VSolidfPtrSolidA = nullptr
G4VSolidfPtrSolidB = nullptr
G4double fCubicVolume = -1.0
G4double fSurfaceArea = -1.0
Protected Attributes inherited from G4VSolid
G4double kCarTolerance
Static Protected Attributes inherited from G4BooleanSolid
static G4VBooleanProcessorfExternalBoolProcessor = nullptr

Detailed Description

G4SubtractionSolid is a solid describing the Boolean subtraction of two solids.

Definition at line 50 of file G4SubtractionSolid.hh.

Constructor & Destructor Documentation

◆ G4SubtractionSolid() [1/5]

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

Constructor of a Boolean subtraction between two solids with no displacement.

Parameters
[in]pNameThe name of the Boolean composition.
[in]pSolidAPointer to the first reference solid.
[in]pSolidBPointer to the second solid to form the composition.

Definition at line 60 of file G4SubtractionSolid.cc.

63 : G4BooleanSolid(pName,pSolidA,pSolidB)
64{
65}
G4BooleanSolid(const G4String &pName, G4VSolid *pSolidA, G4VSolid *pSolidB)

Referenced by Clone(), G4SubtractionSolid(), and operator=().

◆ G4SubtractionSolid() [2/5]

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

Constructor of a Boolean subtraction between two solids with rotation and translation, used to transform the coordinate system of the second solid to the coordinate system of the first solid.

Parameters
[in]pNameThe name of the Boolean composition.
[in]pSolidAPointer to the first reference solid.
[in]pSolidBPointer to the second solid to form the composition.
[in]rotMatrixPointer to the rotation vector.
[in]transVectorThe translation vector.

Definition at line 71 of file G4SubtractionSolid.cc.

76 : G4BooleanSolid(pName,pSolidA,pSolidB,rotMatrix,transVector)
77{
78}

◆ G4SubtractionSolid() [3/5]

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

Constructor of a Boolean subtraction between two solids with a transformation that moves the second solid from its desired position to its standard position.

Parameters
[in]pNameThe name of the Boolean composition.
[in]pSolidAPointer to the first reference solid.
[in]pSolidBPointer to the second solid to form the composition.
[in]transformThe composed 3D transformation.

Definition at line 84 of file G4SubtractionSolid.cc.

88 : G4BooleanSolid(pName,pSolidA,pSolidB,transform)
89{
90}

◆ ~G4SubtractionSolid()

G4SubtractionSolid::~G4SubtractionSolid ( )
overridedefault

Default destructor.

◆ G4SubtractionSolid() [4/5]

G4SubtractionSolid::G4SubtractionSolid ( __void__ & a)

Fake default constructor for usage restricted to direct object persistency for clients requiring preallocation of memory for persistifiable objects.

Definition at line 97 of file G4SubtractionSolid.cc.

99{
100}

◆ G4SubtractionSolid() [5/5]

G4SubtractionSolid::G4SubtractionSolid ( const G4SubtractionSolid & rhs)
default

Copy constructor and assignment operator.

Member Function Documentation

◆ BoundingLimits()

void G4SubtractionSolid::BoundingLimits ( G4ThreeVector & pMin,
G4ThreeVector & pMax ) const
overridevirtual

Computes the bounding limits of the solid.

Parameters
[out]pMinThe minimum bounding limit point.
[out]pMaxThe maximum bounding limit point.

Reimplemented from G4VSolid.

Definition at line 131 of file G4SubtractionSolid.cc.

133{
134 // Since it is unclear how the shape of the first solid will be changed
135 // after subtraction, just return its original bounding box.
136 //
137 fPtrSolidA->BoundingLimits(pMin,pMax);
138
139 // Check correctness of the bounding box
140 //
141 if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
142 {
143 std::ostringstream message;
144 message << "Bad bounding box (min >= max) for solid: "
145 << GetName() << " !"
146 << "\npMin = " << pMin
147 << "\npMax = " << pMax;
148 G4Exception("G4SubtractionSolid::BoundingLimits()", "GeomMgt0001",
149 JustWarning, message);
150 DumpInfo();
151 }
152}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
double z() const
double x() const
double y() const
G4VSolid * fPtrSolidA
G4String GetName() const
void DumpInfo() const

◆ CalculateExtent()

G4bool G4SubtractionSolid::CalculateExtent ( const EAxis pAxis,
const G4VoxelLimits & pVoxelLimit,
const G4AffineTransform & pTransform,
G4double & pMin,
G4double & pMax ) const
overridevirtual

Calculates the minimum and maximum extent of the solid, when under the specified transform, and within the specified limits.

Parameters
[in]pAxisThe axis along which compute the extent.
[in]pVoxelLimitThe limiting space dictated by voxels.
[in]pTransformThe internal transformation applied to the solid.
[out]pMinThe minimum extent value.
[out]pMaxThe maximum extent value.
Returns
True if the solid is intersected by the extent region.

Implements G4VSolid.

Definition at line 159 of file G4SubtractionSolid.cc.

164{
165 // Since we cannot be sure how much the second solid subtracts
166 // from the first, we must use the first solid's extent!
167
168 return fPtrSolidA->CalculateExtent( pAxis, pVoxelLimit,
169 pTransform, pMin, pMax );
170}

◆ Clone()

G4VSolid * G4SubtractionSolid::Clone ( ) const
overridevirtual

Makes a clone of the object for use in multi-treading.

Returns
A pointer to the new cloned allocated solid.

Reimplemented from G4VSolid.

Definition at line 529 of file G4SubtractionSolid.cc.

530{
531 return new G4SubtractionSolid(*this);
532}
G4SubtractionSolid(const G4String &pName, G4VSolid *pSolidA, G4VSolid *pSolidB)

◆ ComputeDimensions()

void G4SubtractionSolid::ComputeDimensions ( G4VPVParameterisation * p,
const G4int n,
const G4VPhysicalVolume * pRep )
overridevirtual

Throws an exception as paramterisations are not allowed for these solids.

Reimplemented from G4VSolid.

Definition at line 539 of file G4SubtractionSolid.cc.

542{
543 DumpInfo();
544 G4Exception("G4SubtractionSolid::ComputeDimensions()",
545 "GeomSolids0001", FatalException,
546 "Method not applicable in this context!");
547}
@ FatalException

◆ CreatePolyhedron()

G4Polyhedron * G4SubtractionSolid::CreatePolyhedron ( ) const
overridevirtual

Creates a Polyhedron used for Visualisation. It is the caller's responsibility to delete it. A null pointer means "not created".

Reimplemented from G4VSolid.

Definition at line 563 of file G4SubtractionSolid.cc.

564{
565 if (fExternalBoolProcessor == nullptr)
566 {
567 HepPolyhedronProcessor processor;
568 // Stack components and components of components recursively
569 // See G4BooleanSolid::StackPolyhedron
570 G4Polyhedron* top = StackPolyhedron(processor, this);
571 auto result = new G4Polyhedron(*top);
572 if (processor.execute(*result))
573 {
574 return result;
575 }
576 return nullptr;
577 }
578 else
579 {
580 return fExternalBoolProcessor->Process(this);
581 }
582}
static G4VBooleanProcessor * fExternalBoolProcessor
G4Polyhedron * StackPolyhedron(HepPolyhedronProcessor &, const G4VSolid *) const
bool execute(HepPolyhedron &)

◆ DescribeYourselfTo()

void G4SubtractionSolid::DescribeYourselfTo ( G4VGraphicsScene & scene) const
overridevirtual

Methods for creating graphical representations (i.e. for visualisation).

Implements G4VSolid.

Definition at line 554 of file G4SubtractionSolid.cc.

555{
556 scene.AddSolid (*this);
557}
virtual void AddSolid(const G4Box &)=0

◆ DistanceToIn() [1/2]

G4double G4SubtractionSolid::DistanceToIn ( const G4ThreeVector & p) const
overridevirtual

Calculates the safety distance to the nearest surface of a shape from an outside point. The distance can be an underestimate.

Implements G4VSolid.

Definition at line 401 of file G4SubtractionSolid.cc.

402{
403 G4double dist = 0.0;
404
405#ifdef G4BOOLDEBUG
406 if( Inside(p) == kInside )
407 {
408 G4cout << "WARNING - Invalid call in "
409 << "G4SubtractionSolid::DistanceToIn(p)" << G4endl
410 << " Point p is inside !" << G4endl;
411 G4cout << " p = " << p << G4endl;
412 G4cerr << "WARNING - Invalid call in "
413 << "G4SubtractionSolid::DistanceToIn(p)" << G4endl
414 << " Point p is inside !" << G4endl;
415 G4cerr << " p = " << p << G4endl;
416 }
417#endif
418
419 if( ( fPtrSolidA->Inside(p) != kOutside) && // case 1
420 ( fPtrSolidB->Inside(p) != kOutside) )
421 {
422 dist = fPtrSolidB->DistanceToOut(p);
423 }
424 else
425 {
426 dist = fPtrSolidA->DistanceToIn(p);
427 }
428
429 return dist;
430}
double G4double
Definition G4Types.hh:83
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
G4VSolid * fPtrSolidB
EInside Inside(const G4ThreeVector &p) const override
@ kInside
Definition geomdefs.hh:70
@ kOutside
Definition geomdefs.hh:68

◆ DistanceToIn() [2/2]

G4double G4SubtractionSolid::DistanceToIn ( const G4ThreeVector & p,
const G4ThreeVector & v ) const
overridevirtual

Returns the distance along the normalised vector "v" to the shape, from the point at offset "p". If there is no intersection, return kInfinity. The first intersection resulting from leaving a surface/volume is discarded. Hence, it is tolerant of points on the surface of the shape.

Implements G4VSolid.

Definition at line 263 of file G4SubtractionSolid.cc.

265{
266 G4double dist = 0.0, dist2 = 0.0, disTmp = 0.0;
267
268#ifdef G4BOOLDEBUG
269 if( Inside(p) == kInside )
270 {
271 G4cout << "WARNING - Invalid call in "
272 << "G4SubtractionSolid::DistanceToIn(p,v)" << G4endl
273 << " Point p is inside !" << G4endl;
274 G4cout << " p = " << p << G4endl;
275 G4cout << " v = " << v << G4endl;
276 G4cerr << "WARNING - Invalid call in "
277 << "G4SubtractionSolid::DistanceToIn(p,v)" << G4endl
278 << " Point p is inside !" << G4endl;
279 G4cerr << " p = " << p << G4endl;
280 G4cerr << " v = " << v << G4endl;
281 }
282#endif
283
284 // if( // ( fPtrSolidA->Inside(p) != kOutside) && // case1:p in both A&B
285 if ( fPtrSolidB->Inside(p) != kOutside ) // start: out of B
286 {
287 dist = fPtrSolidB->DistanceToOut(p,v) ; // ,calcNorm,validNorm,n) ;
288
289 if( fPtrSolidA->Inside(p+dist*v) != kInside )
290 {
291 G4int count1=0;
292 do // Loop checking, 13.08.2015, G.Cosmo
293 {
294 disTmp = fPtrSolidA->DistanceToIn(p+dist*v,v) ;
295
296 if(disTmp == kInfinity)
297 {
298 return kInfinity ;
299 }
300 dist += disTmp ;
301
302 if( Inside(p+dist*v) == kOutside )
303 {
304 disTmp = fPtrSolidB->DistanceToOut(p+dist*v,v) ;
305 dist2 = dist+disTmp;
306 if (dist == dist2) { return dist; } // no progress
307 dist = dist2 ;
308 ++count1;
309 if( count1 > 1000 ) // Infinite loop detected
310 {
311 G4String nameB = fPtrSolidB->GetName();
312 if(fPtrSolidB->GetEntityType()=="G4DisplacedSolid")
313 {
314 nameB = (dynamic_cast<G4DisplacedSolid*>(fPtrSolidB))
315 ->GetConstituentMovedSolid()->GetName();
316 }
317 std::ostringstream message;
318 message << "Illegal condition caused by solids: "
319 << fPtrSolidA->GetName() << " and " << nameB << G4endl;
320 message.precision(16);
321 message << "Looping detected in point " << p+dist*v
322 << ", from original point " << p
323 << " and direction " << v << G4endl
324 << "Computed candidate distance: " << dist << "*mm. ";
325 message.precision(6);
326 DumpInfo();
327 G4Exception("G4SubtractionSolid::DistanceToIn(p,v)",
328 "GeomSolids1001", JustWarning, message,
329 "Returning candidate distance.");
330 return dist;
331 }
332 }
333 }
334 while( Inside(p+dist*v) == kOutside ) ;
335 }
336 }
337 else // p outside A, start in A
338 {
339 dist = fPtrSolidA->DistanceToIn(p,v) ;
340
341 if( dist == kInfinity ) // past A, hence past A\B
342 {
343 return kInfinity ;
344 }
345
346 G4int count2=0;
347 while( Inside(p+dist*v) == kOutside ) // pushing loop
348 {
349 disTmp = fPtrSolidB->DistanceToOut(p+dist*v,v) ;
350 dist += disTmp ;
351
352 if( Inside(p+dist*v) == kOutside )
353 {
354 disTmp = fPtrSolidA->DistanceToIn(p+dist*v,v) ;
355
356 if(disTmp == kInfinity) // past A, hence past A\B
357 {
358 return kInfinity ;
359 }
360 dist2 = dist+disTmp;
361 if (dist == dist2) { return dist; } // no progress
362 dist = dist2 ;
363 ++count2;
364 if( count2 > 1000 ) // Infinite loop detected
365 {
366 G4String nameB = fPtrSolidB->GetName();
367 if(fPtrSolidB->GetEntityType()=="G4DisplacedSolid")
368 {
369 nameB = (dynamic_cast<G4DisplacedSolid*>(fPtrSolidB))
370 ->GetConstituentMovedSolid()->GetName();
371 }
372 std::ostringstream message;
373 message << "Illegal condition caused by solids: "
374 << fPtrSolidA->GetName() << " and " << nameB << G4endl;
375 message.precision(16);
376 message << "Looping detected in point " << p+dist*v
377 << ", from original point " << p
378 << " and direction " << v << G4endl
379 << "Computed candidate distance: " << dist << "*mm. ";
380 message.precision(6);
381 DumpInfo();
382 G4Exception("G4SubtractionSolid::DistanceToIn(p,v)",
383 "GeomSolids1001", JustWarning, message,
384 "Returning candidate distance.");
385 return dist;
386 }
387 }
388 } // Loop checking, 13.08.2015, G.Cosmo
389 }
390
391 return dist ;
392}
int G4int
Definition G4Types.hh:85

◆ DistanceToOut() [1/2]

G4double G4SubtractionSolid::DistanceToOut ( const G4ThreeVector & p) const
overridevirtual

Calculates the safety distance to the nearest surface of a shape from an inside point "p". The distance can be an underestimate.

Implements G4VSolid.

Definition at line 491 of file G4SubtractionSolid.cc.

492{
493 G4double dist=0.0;
494
495 if( Inside(p) == kOutside )
496 {
497#ifdef G4BOOLDEBUG
498 G4cout << "WARNING - Invalid call in "
499 << "G4SubtractionSolid::DistanceToOut(p)" << G4endl
500 << " Point p is outside" << G4endl;
501 G4cout << " p = " << p << G4endl;
502 G4cerr << "WARNING - Invalid call in "
503 << "G4SubtractionSolid::DistanceToOut(p)" << G4endl
504 << " Point p is outside" << G4endl;
505 G4cerr << " p = " << p << G4endl;
506#endif
507 }
508 else
509 {
510 dist= std::min(fPtrSolidA->DistanceToOut(p),
511 fPtrSolidB->DistanceToIn(p) ) ;
512 }
513 return dist;
514}

◆ DistanceToOut() [2/2]

G4double G4SubtractionSolid::DistanceToOut ( const G4ThreeVector & p,
const G4ThreeVector & v,
const G4bool calcNorm = false,
G4bool * validNorm = nullptr,
G4ThreeVector * n = nullptr ) const
overridevirtual

Returns the distance along the normalised vector "v" to the shape, from a point at an offset "p" inside or on the surface of the shape. Intersections with surfaces, when the point is < Tolerance/2 from a surface must be ignored. Must be called as solid.DistanceToOut(p,v) or by specifying all the parameters.

Parameters
[in]pThe reference point in space.
[in]vThe normalised direction.
[in]calcNormFlag to enable the normal computation or not.
[out]validNormSet to true if the solid lies entirely behind or on the exiting surface (calcNorm must be true, otherwise it is unused).
[out]nThe exiting outwards normal vector (undefined Magnitude). (calcNorm must be true, otherwise it is unused).
Returns
The distance value to exit the volume.

Implements G4VSolid.

Definition at line 437 of file G4SubtractionSolid.cc.

442{
443#ifdef G4BOOLDEBUG
444 if( Inside(p) == kOutside )
445 {
446 G4cout << "Position:" << G4endl << G4endl;
447 G4cout << "p.x() = " << p.x()/mm << " mm" << G4endl;
448 G4cout << "p.y() = " << p.y()/mm << " mm" << G4endl;
449 G4cout << "p.z() = " << p.z()/mm << " mm" << G4endl << G4endl;
450 G4cout << "Direction:" << G4endl << G4endl;
451 G4cout << "v.x() = " << v.x() << G4endl;
452 G4cout << "v.y() = " << v.y() << G4endl;
453 G4cout << "v.z() = " << v.z() << G4endl << G4endl;
454 G4cout << "WARNING - Invalid call in "
455 << "G4SubtractionSolid::DistanceToOut(p,v)" << G4endl
456 << " Point p is outside !" << G4endl;
457 G4cout << " p = " << p << G4endl;
458 G4cout << " v = " << v << G4endl;
459 G4cerr << "WARNING - Invalid call in "
460 << "G4SubtractionSolid::DistanceToOut(p,v)" << G4endl
461 << " Point p is outside !" << G4endl;
462 G4cerr << " p = " << p << G4endl;
463 G4cerr << " v = " << v << G4endl;
464 }
465#endif
466
467 G4double distout;
468 G4double distA = fPtrSolidA->DistanceToOut(p,v,calcNorm,validNorm,n) ;
469 G4double distB = fPtrSolidB->DistanceToIn(p,v) ;
470 if(distB < distA)
471 {
472 if(calcNorm)
473 {
474 *n = -(fPtrSolidB->SurfaceNormal(p+distB*v)) ;
475 *validNorm = false ;
476 }
477 distout= distB ;
478 }
479 else
480 {
481 distout= distA ;
482 }
483 return distout;
484}

◆ GetCubicVolume()

G4double G4SubtractionSolid::GetCubicVolume ( )
finalvirtual

Returns an estimate of the capacity of the Boolean composition.

Reimplemented from G4BooleanSolid.

Definition at line 589 of file G4SubtractionSolid.cc.

590{
591 if( fCubicVolume >= 0. )
592 {
593 return fCubicVolume;
594 }
595 G4RecursiveAutoLock l(&subMutex);
596 G4ThreeVector bminA, bmaxA, bminB, bmaxB;
597 fPtrSolidA->BoundingLimits(bminA, bmaxA);
598 fPtrSolidB->BoundingLimits(bminB, bmaxB);
599 G4bool noIntersection =
600 bminA.x() >= bmaxB.x() || bminA.y() >= bmaxB.y() || bminA.z() >= bmaxB.z() ||
601 bminB.x() >= bmaxA.x() || bminB.y() >= bmaxA.y() || bminB.z() >= bmaxA.z();
602
603 if (noIntersection)
604 {
605 fCubicVolume = fPtrSolidA->GetCubicVolume();
606 }
607 else
608 {
609 if (GetNumOfConstituents() > 10)
610 {
612 }
613 else
614 {
615 G4IntersectionSolid intersectVol("Temporary-Intersection-for-Subtraction",
617 intersectVol.SetCubVolStatistics(GetCubVolStatistics());
618 intersectVol.SetCubVolEpsilon(GetCubVolEpsilon());
619
620 G4double cubVolumeA = fPtrSolidA->GetCubicVolume();
621 fCubicVolume = cubVolumeA - intersectVol.GetCubicVolume();
622 if (fCubicVolume < 0.01*cubVolumeA)
623 {
625 }
626 }
627 }
628 l.unlock();
629 return fCubicVolume;
630}
G4TemplateAutoLock< G4RecursiveMutex > G4RecursiveAutoLock
CLHEP::Hep3Vector G4ThreeVector
bool G4bool
Definition G4Types.hh:86
G4double GetCubVolEpsilon() const
G4double GetCubicVolume() override
G4int GetCubVolStatistics() const
G4int GetNumOfConstituents() const override

◆ GetEntityType()

G4GeometryType G4SubtractionSolid::GetEntityType ( ) const
overridevirtual

Returns the type ID, "G4SubtractionSolid" of the solid.

Reimplemented from G4BooleanSolid.

Definition at line 520 of file G4SubtractionSolid.cc.

521{
522 return {"G4SubtractionSolid"};
523}

◆ Inside()

EInside G4SubtractionSolid::Inside ( const G4ThreeVector & p) const
overridevirtual

Returns if the given point "p" is inside or not the solid.

Implements G4VSolid.

Definition at line 176 of file G4SubtractionSolid.cc.

177{
178 EInside positionA = fPtrSolidA->Inside(p);
179 if (positionA == kOutside) { return positionA; } // outside A
180
181 EInside positionB = fPtrSolidB->Inside(p);
182 if (positionB == kOutside) { return positionA; }
183
184 if (positionB == kInside) { return kOutside; }
185 if (positionA == kInside) { return kSurface; } // surface B
186
187 // Point is on both surfaces
188 //
189 static const G4double rtol = 1000*kCarTolerance;
190
191 return ((fPtrSolidA->SurfaceNormal(p) -
192 fPtrSolidB->SurfaceNormal(p)).mag2() > rtol) ? kSurface : kOutside;
193}
G4double kCarTolerance
Definition G4VSolid.hh:418
EInside
Definition geomdefs.hh:67
@ kSurface
Definition geomdefs.hh:69

Referenced by DistanceToIn(), DistanceToIn(), DistanceToOut(), DistanceToOut(), and SurfaceNormal().

◆ operator=()

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

Definition at line 113 of file G4SubtractionSolid.cc.

114{
115 // Check assignment to self
116 //
117 if (this == &rhs) { return *this; }
118
119 // Copy base class data
120 //
122
123 return *this;
124}
G4BooleanSolid & operator=(const G4BooleanSolid &rhs)

◆ SurfaceNormal()

G4ThreeVector G4SubtractionSolid::SurfaceNormal ( const G4ThreeVector & p) const
overridevirtual

Returns the outwards pointing unit normal of the shape for the surface closest to the point at offset "p".

Implements G4VSolid.

Definition at line 200 of file G4SubtractionSolid.cc.

201{
202 G4ThreeVector normal;
203
204 EInside InsideA = fPtrSolidA->Inside(p);
205 EInside InsideB = fPtrSolidB->Inside(p);
206
207 if( InsideA == kOutside )
208 {
209#ifdef G4BOOLDEBUG
210 G4cout << "WARNING - Invalid call [1] in "
211 << "G4SubtractionSolid::SurfaceNormal(p)" << G4endl
212 << " Point p is outside !" << G4endl;
213 G4cout << " p = " << p << G4endl;
214 G4cerr << "WARNING - Invalid call [1] in "
215 << "G4SubtractionSolid::SurfaceNormal(p)" << G4endl
216 << " Point p is outside !" << G4endl;
217 G4cerr << " p = " << p << G4endl;
218#endif
219 normal = fPtrSolidA->SurfaceNormal(p) ;
220 }
221 else if( InsideA == kSurface &&
222 InsideB != kInside )
223 {
224 normal = fPtrSolidA->SurfaceNormal(p) ;
225 }
226 else if( InsideA == kInside &&
227 InsideB != kOutside )
228 {
229 normal = -fPtrSolidB->SurfaceNormal(p) ;
230 }
231 else
232 {
233 if ( fPtrSolidA->DistanceToOut(p) <= fPtrSolidB->DistanceToIn(p) )
234 {
235 normal = fPtrSolidA->SurfaceNormal(p) ;
236 }
237 else
238 {
239 normal = -fPtrSolidB->SurfaceNormal(p) ;
240 }
241#ifdef G4BOOLDEBUG
242 if(Inside(p) == kInside)
243 {
244 G4cout << "WARNING - Invalid call [2] in "
245 << "G4SubtractionSolid::SurfaceNormal(p)" << G4endl
246 << " Point p is inside !" << G4endl;
247 G4cout << " p = " << p << G4endl;
248 G4cerr << "WARNING - Invalid call [2] in "
249 << "G4SubtractionSolid::SurfaceNormal(p)" << G4endl
250 << " Point p is inside !" << G4endl;
251 G4cerr << " p = " << p << G4endl;
252 }
253#endif
254 }
255 return normal;
256}

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