Problem 979 - Optimize boolean solids with "short-circuit" test
Summary: Optimize boolean solids with "short-circuit" test
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: geometry/solids (show other problems)
Version: 9.0
Hardware: All All
: P5 enhancement
Assignee: Vladimir.Grichine
URL:
Depends on:
Blocks:
 
Reported: 2007-10-22 02:43 CEST by Stan Seibert
Modified: 2007-10-23 16:48 CEST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
Description Stan Seibert 2007-10-22 02:43:40 CEST
The Inside() method for boolean solids G4UnionSolid, G4SubtractionSolid, and G4IntersectionSolid can be sped up if a short circuit test is applied after testing solid A, but before testing solid B.  For example, in a subtraction solid, you can do:

 EInside G4SubtractionSolid::Inside( const G4ThreeVector& p ) const
 {
   EInside positionA = fPtrSolidA->Inside(p);
+  
+  if (positionA == kOutside)
+     return kOutside;
+  
   EInside positionB = fPtrSolidB->Inside(p);
   
This avoids calling Inside() on solid B unless necessary.  Similarly, one can do the same thing to G4UnionSolid:

 EInside G4UnionSolid::Inside( const G4ThreeVector& p ) const
 {
   EInside positionA = fPtrSolidA->Inside(p);
+  
+  if (positionA == kInside)
+    return kInside;
+  
   EInside positionB = fPtrSolidB->Inside(p);

A similar patch could be made to G4IntersectionSolid, though I haven't tried it yet.  These changes improve the performance of complex boolean solid geometries quite a bit.
Comment 1 Vladimir.Grichine 2007-10-23 16:48:39 CEST
These modifications were introduced in subtracted and union solids, while 
it already existed in intersection.