Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // >> 26 // >> 27 // $Id: G4SubtractionSolid.cc 104316 2017-05-24 13:04:23Z gcosmo $ >> 28 // 26 // Implementation of methods for the class G4I 29 // Implementation of methods for the class G4IntersectionSolid 27 // 30 // 28 // 22.07.11 T.Nikitina: added detection of inf << 31 // History: 29 // 19.10.98 V.Grichine: new algorithm of Dista << 32 // 30 // 14.10.98 V.Grichine: implementation of the 33 // 14.10.98 V.Grichine: implementation of the first version >> 34 // 19.10.98 V.Grichine: new algorithm of DistanceToIn(p,v) >> 35 // 02.08.99 V.Grichine: bugs fixed in DistanceToOut(p,v,...) >> 36 // while -> do-while & surfaceA limitations >> 37 // 13.09.00 V.Grichine: bug fixed in SurfaceNormal(p), p can be inside >> 38 // 22.07.11 T.Nikitina: add detection of Infinite Loop in DistanceToIn(p,v) >> 39 // 31 // ------------------------------------------- 40 // -------------------------------------------------------------------- 32 41 33 #include "G4SubtractionSolid.hh" 42 #include "G4SubtractionSolid.hh" 34 43 35 #include "G4SystemOfUnits.hh" 44 #include "G4SystemOfUnits.hh" 36 #include "G4VoxelLimits.hh" 45 #include "G4VoxelLimits.hh" 37 #include "G4VPVParameterisation.hh" 46 #include "G4VPVParameterisation.hh" 38 #include "G4GeometryTolerance.hh" 47 #include "G4GeometryTolerance.hh" 39 48 40 #include "G4VGraphicsScene.hh" 49 #include "G4VGraphicsScene.hh" 41 #include "G4Polyhedron.hh" 50 #include "G4Polyhedron.hh" 42 #include "G4PolyhedronArbitrary.hh" << 43 #include "HepPolyhedronProcessor.h" 51 #include "HepPolyhedronProcessor.h" 44 52 45 #include "G4IntersectionSolid.hh" << 46 << 47 #include <sstream> 53 #include <sstream> 48 54 49 ////////////////////////////////////////////// << 55 /////////////////////////////////////////////////////////////////// 50 // 56 // 51 // Transfer all data members to G4BooleanSolid 57 // Transfer all data members to G4BooleanSolid which is responsible 52 // for them. pName will be in turn sent to G4V 58 // for them. pName will be in turn sent to G4VSolid 53 59 54 G4SubtractionSolid::G4SubtractionSolid( const 60 G4SubtractionSolid::G4SubtractionSolid( const G4String& pName, 55 61 G4VSolid* pSolidA , 56 62 G4VSolid* pSolidB ) 57 : G4BooleanSolid(pName,pSolidA,pSolidB) 63 : G4BooleanSolid(pName,pSolidA,pSolidB) 58 { 64 { 59 } 65 } 60 66 61 ////////////////////////////////////////////// << 67 /////////////////////////////////////////////////////////////// 62 // 68 // 63 // Constructor 69 // Constructor 64 70 65 G4SubtractionSolid::G4SubtractionSolid( const 71 G4SubtractionSolid::G4SubtractionSolid( const G4String& pName, 66 72 G4VSolid* pSolidA , 67 73 G4VSolid* pSolidB , 68 74 G4RotationMatrix* rotMatrix, 69 const 75 const G4ThreeVector& transVector ) 70 : G4BooleanSolid(pName,pSolidA,pSolidB,rotMa 76 : G4BooleanSolid(pName,pSolidA,pSolidB,rotMatrix,transVector) 71 { 77 { 72 } 78 } 73 79 74 ////////////////////////////////////////////// << 80 /////////////////////////////////////////////////////////////// 75 // 81 // 76 // Constructor 82 // Constructor 77 83 78 G4SubtractionSolid::G4SubtractionSolid( const 84 G4SubtractionSolid::G4SubtractionSolid( const G4String& pName, 79 85 G4VSolid* pSolidA , 80 86 G4VSolid* pSolidB , 81 const 87 const G4Transform3D& transform ) 82 : G4BooleanSolid(pName,pSolidA,pSolidB,trans 88 : G4BooleanSolid(pName,pSolidA,pSolidB,transform) 83 { 89 { 84 } 90 } 85 91 86 ////////////////////////////////////////////// << 92 ////////////////////////////////////////////////////////////////// 87 // 93 // 88 // Fake default constructor - sets only member 94 // Fake default constructor - sets only member data and allocates memory 89 // for usage restri 95 // for usage restricted to object persistency. 90 96 91 G4SubtractionSolid::G4SubtractionSolid( __void 97 G4SubtractionSolid::G4SubtractionSolid( __void__& a ) 92 : G4BooleanSolid(a) 98 : G4BooleanSolid(a) 93 { 99 { 94 } 100 } 95 101 96 ////////////////////////////////////////////// << 102 /////////////////////////////////////////////////////////////// 97 // 103 // 98 // Destructor 104 // Destructor 99 105 100 G4SubtractionSolid::~G4SubtractionSolid() = de << 106 G4SubtractionSolid::~G4SubtractionSolid() >> 107 { >> 108 } 101 109 102 ////////////////////////////////////////////// << 110 /////////////////////////////////////////////////////////////// 103 // 111 // 104 // Copy constructor 112 // Copy constructor 105 113 106 G4SubtractionSolid::G4SubtractionSolid(const G << 114 G4SubtractionSolid::G4SubtractionSolid(const G4SubtractionSolid& rhs) >> 115 : G4BooleanSolid (rhs) >> 116 { >> 117 } 107 118 108 ////////////////////////////////////////////// << 119 /////////////////////////////////////////////////////////////// 109 // 120 // 110 // Assignment operator 121 // Assignment operator 111 122 112 G4SubtractionSolid& 123 G4SubtractionSolid& 113 G4SubtractionSolid::operator = (const G4Subtra 124 G4SubtractionSolid::operator = (const G4SubtractionSolid& rhs) 114 { 125 { 115 // Check assignment to self 126 // Check assignment to self 116 // 127 // 117 if (this == &rhs) { return *this; } 128 if (this == &rhs) { return *this; } 118 129 119 // Copy base class data 130 // Copy base class data 120 // 131 // 121 G4BooleanSolid::operator=(rhs); 132 G4BooleanSolid::operator=(rhs); 122 133 123 return *this; 134 return *this; 124 } 135 } 125 136 126 ////////////////////////////////////////////// 137 ////////////////////////////////////////////////////////////////////////// 127 // 138 // 128 // Get bounding box 139 // Get bounding box 129 140 130 void 141 void 131 G4SubtractionSolid::BoundingLimits(G4ThreeVect 142 G4SubtractionSolid::BoundingLimits(G4ThreeVector& pMin, 132 G4ThreeVect 143 G4ThreeVector& pMax) const 133 { 144 { 134 // Since it is unclear how the shape of the 145 // Since it is unclear how the shape of the first solid will be changed 135 // after subtraction, just return its origin 146 // after subtraction, just return its original bounding box. 136 // 147 // 137 fPtrSolidA->BoundingLimits(pMin,pMax); 148 fPtrSolidA->BoundingLimits(pMin,pMax); 138 149 139 // Check correctness of the bounding box 150 // Check correctness of the bounding box 140 // 151 // 141 if (pMin.x() >= pMax.x() || pMin.y() >= pMax 152 if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z()) 142 { 153 { 143 std::ostringstream message; 154 std::ostringstream message; 144 message << "Bad bounding box (min >= max) 155 message << "Bad bounding box (min >= max) for solid: " 145 << GetName() << " !" 156 << GetName() << " !" 146 << "\npMin = " << pMin 157 << "\npMin = " << pMin 147 << "\npMax = " << pMax; 158 << "\npMax = " << pMax; 148 G4Exception("G4SubtractionSolid::BoundingL 159 G4Exception("G4SubtractionSolid::BoundingLimits()", "GeomMgt0001", 149 JustWarning, message); 160 JustWarning, message); 150 DumpInfo(); 161 DumpInfo(); 151 } 162 } 152 } 163 } 153 164 154 ////////////////////////////////////////////// 165 ////////////////////////////////////////////////////////////////////////// 155 // 166 // 156 // Calculate extent under transform and specif 167 // Calculate extent under transform and specified limit 157 168 158 G4bool 169 G4bool 159 G4SubtractionSolid::CalculateExtent( const EAx 170 G4SubtractionSolid::CalculateExtent( const EAxis pAxis, 160 const G4V 171 const G4VoxelLimits& pVoxelLimit, 161 const G4A 172 const G4AffineTransform& pTransform, 162 G4d 173 G4double& pMin, 163 G4d 174 G4double& pMax ) const 164 { 175 { 165 // Since we cannot be sure how much the seco 176 // Since we cannot be sure how much the second solid subtracts 166 // from the first, we must use the first sol 177 // from the first, we must use the first solid's extent! 167 178 168 return fPtrSolidA->CalculateExtent( pAxis, p 179 return fPtrSolidA->CalculateExtent( pAxis, pVoxelLimit, 169 pTransfo 180 pTransform, pMin, pMax ); 170 } 181 } 171 182 172 ////////////////////////////////////////////// << 183 ///////////////////////////////////////////////////// 173 // 184 // 174 // Touching ? Empty subtraction ? 185 // Touching ? Empty subtraction ? 175 186 176 EInside G4SubtractionSolid::Inside( const G4Th 187 EInside G4SubtractionSolid::Inside( const G4ThreeVector& p ) const 177 { 188 { 178 EInside positionA = fPtrSolidA->Inside(p); 189 EInside positionA = fPtrSolidA->Inside(p); 179 if (positionA == kOutside) return positionA; << 190 if (positionA == kOutside) return kOutside; 180 191 181 EInside positionB = fPtrSolidB->Inside(p); 192 EInside positionB = fPtrSolidB->Inside(p); 182 if (positionB == kOutside) return positionA; << 193 183 << 194 if(positionA == kInside && positionB == kOutside) 184 if (positionB == kInside) return kOutside; << 195 { 185 if (positionA == kInside) return kSurface; / << 196 return kInside ; 186 << 197 } 187 // Point is on both surfaces << 198 else 188 // << 199 { 189 static const G4double rtol = 1000*kCarTolera << 200 static const G4double rtol 190 << 201 = 1000.0*G4GeometryTolerance::GetInstance()->GetRadialTolerance(); 191 return ((fPtrSolidA->SurfaceNormal(p) - << 202 if(( positionA == kInside && positionB == kSurface) || 192 fPtrSolidB->SurfaceNormal(p)).mag2( << 203 ( positionB == kOutside && positionA == kSurface) || >> 204 ( positionA == kSurface && positionB == kSurface && >> 205 ( fPtrSolidA->SurfaceNormal(p) - >> 206 fPtrSolidB->SurfaceNormal(p) ).mag2() > rtol ) ) >> 207 { >> 208 return kSurface; >> 209 } >> 210 else >> 211 { >> 212 return kOutside; >> 213 } >> 214 } 193 } 215 } 194 216 195 ////////////////////////////////////////////// << 217 ////////////////////////////////////////////////////////////// 196 // 218 // 197 // SurfaceNormal 219 // SurfaceNormal 198 220 199 G4ThreeVector 221 G4ThreeVector 200 G4SubtractionSolid::SurfaceNormal( const G4Thr 222 G4SubtractionSolid::SurfaceNormal( const G4ThreeVector& p ) const 201 { 223 { 202 G4ThreeVector normal; 224 G4ThreeVector normal; 203 225 204 EInside InsideA = fPtrSolidA->Inside(p); 226 EInside InsideA = fPtrSolidA->Inside(p); 205 EInside InsideB = fPtrSolidB->Inside(p); 227 EInside InsideB = fPtrSolidB->Inside(p); 206 228 207 if( InsideA == kOutside ) 229 if( InsideA == kOutside ) 208 { 230 { 209 #ifdef G4BOOLDEBUG 231 #ifdef G4BOOLDEBUG 210 G4cout << "WARNING - Invalid call [1] in " 232 G4cout << "WARNING - Invalid call [1] in " 211 << "G4SubtractionSolid::SurfaceNorm 233 << "G4SubtractionSolid::SurfaceNormal(p)" << G4endl 212 << " Point p is outside !" << G4en 234 << " Point p is outside !" << G4endl; 213 G4cout << " p = " << p << G4endl; 235 G4cout << " p = " << p << G4endl; 214 G4cerr << "WARNING - Invalid call [1] in " 236 G4cerr << "WARNING - Invalid call [1] in " 215 << "G4SubtractionSolid::SurfaceNorm 237 << "G4SubtractionSolid::SurfaceNormal(p)" << G4endl 216 << " Point p is outside !" << G4en 238 << " Point p is outside !" << G4endl; 217 G4cerr << " p = " << p << G4endl; 239 G4cerr << " p = " << p << G4endl; 218 #endif 240 #endif 219 normal = fPtrSolidA->SurfaceNormal(p) ; 241 normal = fPtrSolidA->SurfaceNormal(p) ; 220 } 242 } 221 else if( InsideA == kSurface && 243 else if( InsideA == kSurface && 222 InsideB != kInside ) 244 InsideB != kInside ) 223 { 245 { 224 normal = fPtrSolidA->SurfaceNormal(p) ; 246 normal = fPtrSolidA->SurfaceNormal(p) ; 225 } 247 } 226 else if( InsideA == kInside && 248 else if( InsideA == kInside && 227 InsideB != kOutside ) 249 InsideB != kOutside ) 228 { 250 { 229 normal = -fPtrSolidB->SurfaceNormal(p) ; 251 normal = -fPtrSolidB->SurfaceNormal(p) ; 230 } 252 } 231 else 253 else 232 { 254 { 233 if ( fPtrSolidA->DistanceToOut(p) <= fPtrS 255 if ( fPtrSolidA->DistanceToOut(p) <= fPtrSolidB->DistanceToIn(p) ) 234 { 256 { 235 normal = fPtrSolidA->SurfaceNormal(p) ; 257 normal = fPtrSolidA->SurfaceNormal(p) ; 236 } 258 } 237 else 259 else 238 { 260 { 239 normal = -fPtrSolidB->SurfaceNormal(p) ; 261 normal = -fPtrSolidB->SurfaceNormal(p) ; 240 } 262 } 241 #ifdef G4BOOLDEBUG 263 #ifdef G4BOOLDEBUG 242 if(Inside(p) == kInside) 264 if(Inside(p) == kInside) 243 { 265 { 244 G4cout << "WARNING - Invalid call [2] in 266 G4cout << "WARNING - Invalid call [2] in " 245 << "G4SubtractionSolid::SurfaceNo 267 << "G4SubtractionSolid::SurfaceNormal(p)" << G4endl 246 << " Point p is inside !" << G4e 268 << " Point p is inside !" << G4endl; 247 G4cout << " p = " << p << G4end 269 G4cout << " p = " << p << G4endl; 248 G4cerr << "WARNING - Invalid call [2] in 270 G4cerr << "WARNING - Invalid call [2] in " 249 << "G4SubtractionSolid::SurfaceNo 271 << "G4SubtractionSolid::SurfaceNormal(p)" << G4endl 250 << " Point p is inside !" << G4e 272 << " Point p is inside !" << G4endl; 251 G4cerr << " p = " << p << G4end 273 G4cerr << " p = " << p << G4endl; 252 } 274 } 253 #endif 275 #endif 254 } 276 } 255 return normal; 277 return normal; 256 } 278 } 257 279 258 ////////////////////////////////////////////// << 280 ///////////////////////////////////////////////////////////// 259 // 281 // 260 // The same algorithm as in DistanceToIn(p) 282 // The same algorithm as in DistanceToIn(p) 261 283 262 G4double 284 G4double 263 G4SubtractionSolid::DistanceToIn( const G4Thre << 285 G4SubtractionSolid::DistanceToIn( const G4ThreeVector& p, 264 const G4Thre << 286 const G4ThreeVector& v ) const 265 { 287 { 266 G4double dist = 0.0, dist2 = 0.0, disTmp = 0 288 G4double dist = 0.0, dist2 = 0.0, disTmp = 0.0; 267 289 268 #ifdef G4BOOLDEBUG 290 #ifdef G4BOOLDEBUG 269 if( Inside(p) == kInside ) 291 if( Inside(p) == kInside ) 270 { 292 { 271 G4cout << "WARNING - Invalid call in " 293 G4cout << "WARNING - Invalid call in " 272 << "G4SubtractionSolid::DistanceToI 294 << "G4SubtractionSolid::DistanceToIn(p,v)" << G4endl 273 << " Point p is inside !" << G4end 295 << " Point p is inside !" << G4endl; 274 G4cout << " p = " << p << G4endl; 296 G4cout << " p = " << p << G4endl; 275 G4cout << " v = " << v << G4endl; 297 G4cout << " v = " << v << G4endl; 276 G4cerr << "WARNING - Invalid call in " 298 G4cerr << "WARNING - Invalid call in " 277 << "G4SubtractionSolid::DistanceToI 299 << "G4SubtractionSolid::DistanceToIn(p,v)" << G4endl 278 << " Point p is inside !" << G4end 300 << " Point p is inside !" << G4endl; 279 G4cerr << " p = " << p << G4endl; 301 G4cerr << " p = " << p << G4endl; 280 G4cerr << " v = " << v << G4endl; 302 G4cerr << " v = " << v << G4endl; 281 } 303 } 282 #endif 304 #endif 283 305 284 // if( // ( fPtrSolidA->Inside(p) != kOuts 306 // if( // ( fPtrSolidA->Inside(p) != kOutside) && // case1:p in both A&B 285 if ( fPtrSolidB->Inside(p) != kOutside ) 307 if ( fPtrSolidB->Inside(p) != kOutside ) // start: out of B 286 { 308 { 287 dist = fPtrSolidB->DistanceToOut(p,v) ; 309 dist = fPtrSolidB->DistanceToOut(p,v) ; // ,calcNorm,validNorm,n) ; 288 310 289 if( fPtrSolidA->Inside(p+dist*v) != kIns 311 if( fPtrSolidA->Inside(p+dist*v) != kInside ) 290 { 312 { 291 G4int count1=0; 313 G4int count1=0; 292 do // Loop checking, 13.08.2015, G.C 314 do // Loop checking, 13.08.2015, G.Cosmo 293 { 315 { 294 disTmp = fPtrSolidA->DistanceToIn(p+ 316 disTmp = fPtrSolidA->DistanceToIn(p+dist*v,v) ; 295 317 296 if(disTmp == kInfinity) 318 if(disTmp == kInfinity) 297 { 319 { 298 return kInfinity ; 320 return kInfinity ; 299 } 321 } 300 dist += disTmp ; 322 dist += disTmp ; 301 323 302 if( Inside(p+dist*v) == kOutside ) 324 if( Inside(p+dist*v) == kOutside ) 303 { 325 { 304 disTmp = fPtrSolidB->DistanceToOut 326 disTmp = fPtrSolidB->DistanceToOut(p+dist*v,v) ; 305 dist2 = dist+disTmp; 327 dist2 = dist+disTmp; 306 if (dist == dist2) { return dist; 328 if (dist == dist2) { return dist; } // no progress 307 dist = dist2 ; 329 dist = dist2 ; 308 ++count1; << 330 count1++; 309 if( count1 > 1000 ) // Infinite l 331 if( count1 > 1000 ) // Infinite loop detected 310 { 332 { 311 G4String nameB = fPtrSolidB->Get 333 G4String nameB = fPtrSolidB->GetName(); 312 if(fPtrSolidB->GetEntityType()== 334 if(fPtrSolidB->GetEntityType()=="G4DisplacedSolid") 313 { 335 { 314 nameB = (dynamic_cast<G4Displa 336 nameB = (dynamic_cast<G4DisplacedSolid*>(fPtrSolidB)) 315 ->GetConstituentMovedS 337 ->GetConstituentMovedSolid()->GetName(); 316 } 338 } 317 std::ostringstream message; 339 std::ostringstream message; 318 message << "Illegal condition ca 340 message << "Illegal condition caused by solids: " 319 << fPtrSolidA->GetName() 341 << fPtrSolidA->GetName() << " and " << nameB << G4endl; 320 message.precision(16); 342 message.precision(16); 321 message << "Looping detected in 343 message << "Looping detected in point " << p+dist*v 322 << ", from original poin 344 << ", from original point " << p 323 << " and direction " << 345 << " and direction " << v << G4endl 324 << "Computed candidate d 346 << "Computed candidate distance: " << dist << "*mm. "; 325 message.precision(6); 347 message.precision(6); 326 DumpInfo(); 348 DumpInfo(); 327 G4Exception("G4SubtractionSolid: 349 G4Exception("G4SubtractionSolid::DistanceToIn(p,v)", 328 "GeomSolids1001", Ju 350 "GeomSolids1001", JustWarning, message, 329 "Returning candidate 351 "Returning candidate distance."); 330 return dist; 352 return dist; 331 } 353 } 332 } 354 } 333 } 355 } 334 while( Inside(p+dist*v) == kOutside ) 356 while( Inside(p+dist*v) == kOutside ) ; 335 } 357 } 336 } 358 } 337 else // p outside A, start in A 359 else // p outside A, start in A 338 { 360 { 339 dist = fPtrSolidA->DistanceToIn(p,v) ; 361 dist = fPtrSolidA->DistanceToIn(p,v) ; 340 362 341 if( dist == kInfinity ) // past A, hence 363 if( dist == kInfinity ) // past A, hence past A\B 342 { 364 { 343 return kInfinity ; 365 return kInfinity ; 344 } 366 } 345 else 367 else 346 { 368 { 347 G4int count2=0; 369 G4int count2=0; 348 while( Inside(p+dist*v) == kOutside ) 370 while( Inside(p+dist*v) == kOutside ) // pushing loop 349 { 371 { 350 disTmp = fPtrSolidB->DistanceToOut(p 372 disTmp = fPtrSolidB->DistanceToOut(p+dist*v,v) ; 351 dist += disTmp ; 373 dist += disTmp ; 352 374 353 if( Inside(p+dist*v) == kOutside ) 375 if( Inside(p+dist*v) == kOutside ) 354 { 376 { 355 disTmp = fPtrSolidA->DistanceToIn( 377 disTmp = fPtrSolidA->DistanceToIn(p+dist*v,v) ; 356 378 357 if(disTmp == kInfinity) // past A, 379 if(disTmp == kInfinity) // past A, hence past A\B 358 { 380 { 359 return kInfinity ; 381 return kInfinity ; 360 } 382 } 361 dist2 = dist+disTmp; 383 dist2 = dist+disTmp; 362 if (dist == dist2) { return dist; 384 if (dist == dist2) { return dist; } // no progress 363 dist = dist2 ; 385 dist = dist2 ; 364 ++count2; << 386 count2++; 365 if( count2 > 1000 ) // Infinite l 387 if( count2 > 1000 ) // Infinite loop detected 366 { 388 { 367 G4String nameB = fPtrSolidB->Get 389 G4String nameB = fPtrSolidB->GetName(); 368 if(fPtrSolidB->GetEntityType()== 390 if(fPtrSolidB->GetEntityType()=="G4DisplacedSolid") 369 { 391 { 370 nameB = (dynamic_cast<G4Displa 392 nameB = (dynamic_cast<G4DisplacedSolid*>(fPtrSolidB)) 371 ->GetConstituentMovedS 393 ->GetConstituentMovedSolid()->GetName(); 372 } 394 } 373 std::ostringstream message; 395 std::ostringstream message; 374 message << "Illegal condition ca 396 message << "Illegal condition caused by solids: " 375 << fPtrSolidA->GetName() 397 << fPtrSolidA->GetName() << " and " << nameB << G4endl; 376 message.precision(16); 398 message.precision(16); 377 message << "Looping detected in 399 message << "Looping detected in point " << p+dist*v 378 << ", from original poin 400 << ", from original point " << p 379 << " and direction " << 401 << " and direction " << v << G4endl 380 << "Computed candidate d 402 << "Computed candidate distance: " << dist << "*mm. "; 381 message.precision(6); 403 message.precision(6); 382 DumpInfo(); 404 DumpInfo(); 383 G4Exception("G4SubtractionSolid: 405 G4Exception("G4SubtractionSolid::DistanceToIn(p,v)", 384 "GeomSolids1001", Ju 406 "GeomSolids1001", JustWarning, message, 385 "Returning candidate 407 "Returning candidate distance."); 386 return dist; 408 return dist; 387 } 409 } 388 } 410 } 389 } // Loop checking, 13.08.2015, G.C 411 } // Loop checking, 13.08.2015, G.Cosmo 390 } 412 } 391 } 413 } 392 414 393 return dist ; 415 return dist ; 394 } 416 } 395 417 396 ////////////////////////////////////////////// << 418 //////////////////////////////////////////////////////// 397 // 419 // 398 // Approximate nearest distance from the point 420 // Approximate nearest distance from the point p to the intersection of 399 // two solids. It is usually underestimated fr 421 // two solids. It is usually underestimated from the point of view of 400 // isotropic safety 422 // isotropic safety 401 423 402 G4double 424 G4double 403 G4SubtractionSolid::DistanceToIn( const G4Thre 425 G4SubtractionSolid::DistanceToIn( const G4ThreeVector& p ) const 404 { 426 { 405 G4double dist = 0.0; << 427 G4double dist=0.0; 406 428 407 #ifdef G4BOOLDEBUG 429 #ifdef G4BOOLDEBUG 408 if( Inside(p) == kInside ) 430 if( Inside(p) == kInside ) 409 { 431 { 410 G4cout << "WARNING - Invalid call in " 432 G4cout << "WARNING - Invalid call in " 411 << "G4SubtractionSolid::DistanceToI 433 << "G4SubtractionSolid::DistanceToIn(p)" << G4endl 412 << " Point p is inside !" << G4end 434 << " Point p is inside !" << G4endl; 413 G4cout << " p = " << p << G4endl; 435 G4cout << " p = " << p << G4endl; 414 G4cerr << "WARNING - Invalid call in " 436 G4cerr << "WARNING - Invalid call in " 415 << "G4SubtractionSolid::DistanceToI 437 << "G4SubtractionSolid::DistanceToIn(p)" << G4endl 416 << " Point p is inside !" << G4end 438 << " Point p is inside !" << G4endl; 417 G4cerr << " p = " << p << G4endl; 439 G4cerr << " p = " << p << G4endl; 418 } 440 } 419 #endif 441 #endif 420 442 421 if( ( fPtrSolidA->Inside(p) != kOutside) && 443 if( ( fPtrSolidA->Inside(p) != kOutside) && // case 1 422 ( fPtrSolidB->Inside(p) != kOutside) 444 ( fPtrSolidB->Inside(p) != kOutside) ) 423 { 445 { 424 dist = fPtrSolidB->DistanceToOut(p); << 446 dist= fPtrSolidB->DistanceToOut(p) ; 425 } 447 } 426 else 448 else 427 { 449 { 428 dist = fPtrSolidA->DistanceToIn(p); << 450 dist= fPtrSolidA->DistanceToIn(p) ; 429 } 451 } 430 452 431 return dist; 453 return dist; 432 } 454 } 433 455 434 ////////////////////////////////////////////// << 456 ////////////////////////////////////////////////////////// 435 // 457 // 436 // The same algorithm as DistanceToOut(p) 458 // The same algorithm as DistanceToOut(p) 437 459 438 G4double 460 G4double 439 G4SubtractionSolid::DistanceToOut( const G4Thr 461 G4SubtractionSolid::DistanceToOut( const G4ThreeVector& p, 440 const G4Thr << 462 const G4ThreeVector& v, 441 const G4boo << 463 const G4bool calcNorm, 442 G4boo << 464 G4bool *validNorm, 443 G4Thr << 465 G4ThreeVector *n ) const 444 { 466 { 445 #ifdef G4BOOLDEBUG 467 #ifdef G4BOOLDEBUG 446 if( Inside(p) == kOutside ) 468 if( Inside(p) == kOutside ) 447 { 469 { 448 G4cout << "Position:" << G4endl << G4en 470 G4cout << "Position:" << G4endl << G4endl; 449 G4cout << "p.x() = " << p.x()/mm << " 471 G4cout << "p.x() = " << p.x()/mm << " mm" << G4endl; 450 G4cout << "p.y() = " << p.y()/mm << " 472 G4cout << "p.y() = " << p.y()/mm << " mm" << G4endl; 451 G4cout << "p.z() = " << p.z()/mm << " 473 G4cout << "p.z() = " << p.z()/mm << " mm" << G4endl << G4endl; 452 G4cout << "Direction:" << G4endl << G4en 474 G4cout << "Direction:" << G4endl << G4endl; 453 G4cout << "v.x() = " << v.x() << G4end 475 G4cout << "v.x() = " << v.x() << G4endl; 454 G4cout << "v.y() = " << v.y() << G4end 476 G4cout << "v.y() = " << v.y() << G4endl; 455 G4cout << "v.z() = " << v.z() << G4end 477 G4cout << "v.z() = " << v.z() << G4endl << G4endl; 456 G4cout << "WARNING - Invalid call in " 478 G4cout << "WARNING - Invalid call in " 457 << "G4SubtractionSolid::DistanceT 479 << "G4SubtractionSolid::DistanceToOut(p,v)" << G4endl 458 << " Point p is outside !" << G4 480 << " Point p is outside !" << G4endl; 459 G4cout << " p = " << p << G4end 481 G4cout << " p = " << p << G4endl; 460 G4cout << " v = " << v << G4end 482 G4cout << " v = " << v << G4endl; 461 G4cerr << "WARNING - Invalid call in " 483 G4cerr << "WARNING - Invalid call in " 462 << "G4SubtractionSolid::DistanceT 484 << "G4SubtractionSolid::DistanceToOut(p,v)" << G4endl 463 << " Point p is outside !" << G4 485 << " Point p is outside !" << G4endl; 464 G4cerr << " p = " << p << G4end 486 G4cerr << " p = " << p << G4endl; 465 G4cerr << " v = " << v << G4end 487 G4cerr << " v = " << v << G4endl; 466 } 488 } 467 #endif 489 #endif 468 490 469 G4double distout; 491 G4double distout; 470 G4double distA = fPtrSolidA->DistanceToOut 492 G4double distA = fPtrSolidA->DistanceToOut(p,v,calcNorm,validNorm,n) ; 471 G4double distB = fPtrSolidB->DistanceToIn( 493 G4double distB = fPtrSolidB->DistanceToIn(p,v) ; 472 if(distB < distA) 494 if(distB < distA) 473 { 495 { 474 if(calcNorm) 496 if(calcNorm) 475 { 497 { 476 *n = -(fPtrSolidB->SurfaceNormal(p+dis 498 *n = -(fPtrSolidB->SurfaceNormal(p+distB*v)) ; 477 *validNorm = false ; 499 *validNorm = false ; 478 } 500 } 479 distout= distB ; 501 distout= distB ; 480 } 502 } 481 else 503 else 482 { 504 { 483 distout= distA ; 505 distout= distA ; 484 } 506 } 485 return distout; 507 return distout; 486 } 508 } 487 509 488 ////////////////////////////////////////////// << 510 ////////////////////////////////////////////////////////////// 489 // 511 // 490 // Inverted algorithm of DistanceToIn(p) 512 // Inverted algorithm of DistanceToIn(p) 491 513 492 G4double 514 G4double 493 G4SubtractionSolid::DistanceToOut( const G4Thr 515 G4SubtractionSolid::DistanceToOut( const G4ThreeVector& p ) const 494 { 516 { 495 G4double dist=0.0; 517 G4double dist=0.0; 496 518 497 if( Inside(p) == kOutside ) 519 if( Inside(p) == kOutside ) 498 { 520 { 499 #ifdef G4BOOLDEBUG 521 #ifdef G4BOOLDEBUG 500 G4cout << "WARNING - Invalid call in " 522 G4cout << "WARNING - Invalid call in " 501 << "G4SubtractionSolid::DistanceToO 523 << "G4SubtractionSolid::DistanceToOut(p)" << G4endl 502 << " Point p is outside" << G4endl 524 << " Point p is outside" << G4endl; 503 G4cout << " p = " << p << G4endl; 525 G4cout << " p = " << p << G4endl; 504 G4cerr << "WARNING - Invalid call in " 526 G4cerr << "WARNING - Invalid call in " 505 << "G4SubtractionSolid::DistanceToO 527 << "G4SubtractionSolid::DistanceToOut(p)" << G4endl 506 << " Point p is outside" << G4endl 528 << " Point p is outside" << G4endl; 507 G4cerr << " p = " << p << G4endl; 529 G4cerr << " p = " << p << G4endl; 508 #endif 530 #endif 509 } 531 } 510 else 532 else 511 { 533 { 512 dist= std::min(fPtrSolidA->DistanceToOut( 534 dist= std::min(fPtrSolidA->DistanceToOut(p), 513 fPtrSolidB->DistanceToIn 535 fPtrSolidB->DistanceToIn(p) ) ; 514 } 536 } 515 return dist; 537 return dist; 516 } 538 } 517 539 518 ////////////////////////////////////////////// << 540 ////////////////////////////////////////////////////////////// 519 // 541 // 520 // 542 // 521 543 522 G4GeometryType G4SubtractionSolid::GetEntityTy 544 G4GeometryType G4SubtractionSolid::GetEntityType() const 523 { 545 { 524 return {"G4SubtractionSolid"}; << 546 return G4String("G4SubtractionSolid"); 525 } 547 } 526 548 527 ////////////////////////////////////////////// 549 ////////////////////////////////////////////////////////////////////////// 528 // 550 // 529 // Make a clone of the object 551 // Make a clone of the object 530 552 531 G4VSolid* G4SubtractionSolid::Clone() const 553 G4VSolid* G4SubtractionSolid::Clone() const 532 { 554 { 533 return new G4SubtractionSolid(*this); 555 return new G4SubtractionSolid(*this); 534 } 556 } 535 557 536 ////////////////////////////////////////////// << 558 ////////////////////////////////////////////////////////////// >> 559 // 537 // 560 // 538 // ComputeDimensions << 539 561 540 void 562 void 541 G4SubtractionSolid::ComputeDimensions( G 563 G4SubtractionSolid::ComputeDimensions( G4VPVParameterisation*, 542 const G 564 const G4int, 543 const G 565 const G4VPhysicalVolume* ) 544 { 566 { 545 } 567 } 546 568 547 ////////////////////////////////////////////// << 569 ///////////////////////////////////////////////// 548 // 570 // 549 // DescribeYourselfTo << 571 // 550 572 551 void 573 void 552 G4SubtractionSolid::DescribeYourselfTo ( G4VGr 574 G4SubtractionSolid::DescribeYourselfTo ( G4VGraphicsScene& scene ) const 553 { 575 { 554 scene.AddSolid (*this); 576 scene.AddSolid (*this); 555 } 577 } 556 578 557 ////////////////////////////////////////////// << 579 //////////////////////////////////////////////////// 558 // 580 // 559 // CreatePolyhedron << 560 << 561 G4Polyhedron* G4SubtractionSolid::CreatePolyhe << 562 { << 563 if (fExternalBoolProcessor == nullptr) << 564 { << 565 HepPolyhedronProcessor processor; << 566 // Stack components and components of comp << 567 // See G4BooleanSolid::StackPolyhedron << 568 G4Polyhedron* top = StackPolyhedron(proces << 569 auto result = new G4Polyhedron(*top); << 570 if (processor.execute(*result)) << 571 { << 572 return result; << 573 } << 574 else << 575 { << 576 return nullptr; << 577 } << 578 } << 579 else << 580 { << 581 return fExternalBoolProcessor->Process(thi << 582 } << 583 } << 584 << 585 ////////////////////////////////////////////// << 586 // << 587 // GetCubicVolume << 588 // 581 // 589 582 590 G4double G4SubtractionSolid::GetCubicVolume() << 583 G4Polyhedron* >> 584 G4SubtractionSolid::CreatePolyhedron () const 591 { 585 { 592 if( fCubicVolume >= 0. ) << 586 HepPolyhedronProcessor processor; 593 { << 587 // Stack components and components of components recursively 594 return fCubicVolume; << 588 // See G4BooleanSolid::StackPolyhedron 595 } << 589 G4Polyhedron* top = StackPolyhedron(processor, this); 596 G4ThreeVector bminA, bmaxA, bminB, bmaxB; << 590 G4Polyhedron* result = new G4Polyhedron(*top); 597 fPtrSolidA->BoundingLimits(bminA, bmaxA); << 591 if (processor.execute(*result)) { return result; } 598 fPtrSolidB->BoundingLimits(bminB, bmaxB); << 592 else { return 0; } 599 G4bool noIntersection = << 600 bminA.x() >= bmaxB.x() || bminA.y() >= bm << 601 bminB.x() >= bmaxA.x() || bminB.y() >= bm << 602 << 603 if (noIntersection) << 604 { << 605 fCubicVolume = fPtrSolidA->GetCubicVolume( << 606 } << 607 else << 608 { << 609 if (GetNumOfConstituents() > 10) << 610 { << 611 fCubicVolume = G4BooleanSolid::GetCubicV << 612 } << 613 else << 614 { << 615 G4IntersectionSolid intersectVol("Tempor << 616 fPtrSo << 617 intersectVol.SetCubVolStatistics(GetCubV << 618 intersectVol.SetCubVolEpsilon(GetCubVolE << 619 << 620 G4double cubVolumeA = fPtrSolidA->GetCub << 621 fCubicVolume = cubVolumeA - intersectVol << 622 if (fCubicVolume < 0.01*cubVolumeA) fCub << 623 } << 624 } << 625 return fCubicVolume; << 626 } 593 } 627 594