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 // Implementation of the base class for solids << 26 // >> 27 // $Id: G4BooleanSolid.cc 83572 2014-09-01 15:23:27Z gcosmo $ >> 28 // >> 29 // Implementation for the abstract base class for solids created by boolean 27 // operations between other solids 30 // operations between other solids 28 // 31 // 29 // 1998.09.10 V.Grichine - created << 32 // History: >> 33 // >> 34 // 10.09.98 V.Grichine, created >> 35 // 30 // ------------------------------------------- 36 // -------------------------------------------------------------------- 31 37 32 #include "G4BooleanSolid.hh" 38 #include "G4BooleanSolid.hh" 33 #include "G4VSolid.hh" 39 #include "G4VSolid.hh" 34 #include "G4DisplacedSolid.hh" << 35 #include "G4ReflectedSolid.hh" << 36 #include "G4ScaledSolid.hh" << 37 #include "G4Polyhedron.hh" 40 #include "G4Polyhedron.hh" 38 #include "HepPolyhedronProcessor.h" 41 #include "HepPolyhedronProcessor.h" 39 #include "G4QuickRand.hh" << 42 #include "Randomize.hh" 40 43 41 #include "G4AutoLock.hh" 44 #include "G4AutoLock.hh" 42 45 43 namespace 46 namespace 44 { 47 { 45 G4RecursiveMutex polyhedronMutex = G4MUTEX_I << 48 G4Mutex polyhedronMutex = G4MUTEX_INITIALIZER; 46 } 49 } 47 50 48 G4VBooleanProcessor* G4BooleanSolid::fExternal << 49 << 50 ////////////////////////////////////////////// 51 ////////////////////////////////////////////////////////////////// 51 // 52 // 52 // Constructor 53 // Constructor 53 54 54 G4BooleanSolid::G4BooleanSolid( const G4String 55 G4BooleanSolid::G4BooleanSolid( const G4String& pName, 55 G4VSolid* pSol 56 G4VSolid* pSolidA , 56 G4VSolid* pSol << 57 G4VSolid* pSolidB ) : 57 : G4VSolid(pName), fPtrSolidA(pSolidA), fPtr << 58 G4VSolid(pName), fAreaRatio(0.), fStatistics(1000000), fCubVolEpsilon(0.001), >> 59 fAreaAccuracy(-1.), fCubicVolume(0.), fSurfaceArea(0.), >> 60 fRebuildPolyhedron(false), fpPolyhedron(0), createdDisplacedSolid(false) 58 { 61 { >> 62 fPtrSolidA = pSolidA ; >> 63 fPtrSolidB = pSolidB ; 59 } 64 } 60 65 61 ////////////////////////////////////////////// 66 ////////////////////////////////////////////////////////////////// 62 // 67 // 63 // Constructor 68 // Constructor 64 69 65 G4BooleanSolid::G4BooleanSolid( const G4String 70 G4BooleanSolid::G4BooleanSolid( const G4String& pName, 66 G4VSolid 71 G4VSolid* pSolidA , 67 G4VSolid 72 G4VSolid* pSolidB , 68 G4Rotati 73 G4RotationMatrix* rotMatrix, 69 const G4ThreeV << 74 const G4ThreeVector& transVector ) : 70 : G4VSolid(pName), createdDisplacedSolid(tru << 75 G4VSolid(pName), fAreaRatio(0.), fStatistics(1000000), fCubVolEpsilon(0.001), >> 76 fAreaAccuracy(-1.), fCubicVolume(0.), fSurfaceArea(0.), >> 77 fRebuildPolyhedron(false), fpPolyhedron(0), createdDisplacedSolid(true) 71 { 78 { 72 fPtrSolidA = pSolidA ; 79 fPtrSolidA = pSolidA ; 73 fPtrSolidB = new G4DisplacedSolid("placedB", 80 fPtrSolidB = new G4DisplacedSolid("placedB",pSolidB,rotMatrix,transVector) ; 74 } 81 } 75 82 76 ////////////////////////////////////////////// 83 ////////////////////////////////////////////////////////////////// 77 // 84 // 78 // Constructor 85 // Constructor 79 86 80 G4BooleanSolid::G4BooleanSolid( const G4String 87 G4BooleanSolid::G4BooleanSolid( const G4String& pName, 81 G4VSolid 88 G4VSolid* pSolidA , 82 G4VSolid 89 G4VSolid* pSolidB , 83 const G4Transf << 90 const G4Transform3D& transform ) : 84 : G4VSolid(pName), createdDisplacedSolid(tru << 91 G4VSolid(pName), fAreaRatio(0.), fStatistics(1000000), fCubVolEpsilon(0.001), >> 92 fAreaAccuracy(-1.), fCubicVolume(0.), fSurfaceArea(0.), >> 93 fRebuildPolyhedron(false), fpPolyhedron(0), createdDisplacedSolid(true) 85 { 94 { 86 fPtrSolidA = pSolidA ; 95 fPtrSolidA = pSolidA ; 87 fPtrSolidB = new G4DisplacedSolid("placedB", 96 fPtrSolidB = new G4DisplacedSolid("placedB",pSolidB,transform) ; 88 } 97 } 89 98 90 ////////////////////////////////////////////// 99 /////////////////////////////////////////////////////////////// 91 // 100 // 92 // Fake default constructor - sets only member 101 // Fake default constructor - sets only member data and allocates memory 93 // for usage restri 102 // for usage restricted to object persistency. 94 103 95 G4BooleanSolid::G4BooleanSolid( __void__& a ) 104 G4BooleanSolid::G4BooleanSolid( __void__& a ) 96 : G4VSolid(a) << 105 : G4VSolid(a), fPtrSolidA(0), fPtrSolidB(0), fAreaRatio(0.), >> 106 fStatistics(1000000), fCubVolEpsilon(0.001), >> 107 fAreaAccuracy(-1.), fCubicVolume(0.), fSurfaceArea(0.), >> 108 fRebuildPolyhedron(false), fpPolyhedron(0), createdDisplacedSolid(false) 97 { 109 { 98 } 110 } 99 111 100 ////////////////////////////////////////////// 112 /////////////////////////////////////////////////////////////// 101 // 113 // 102 // Destructor deletes transformation contents 114 // Destructor deletes transformation contents of the created displaced solid 103 115 104 G4BooleanSolid::~G4BooleanSolid() 116 G4BooleanSolid::~G4BooleanSolid() 105 { 117 { 106 if(createdDisplacedSolid) 118 if(createdDisplacedSolid) 107 { 119 { 108 ((G4DisplacedSolid*)fPtrSolidB)->CleanTran 120 ((G4DisplacedSolid*)fPtrSolidB)->CleanTransformations(); 109 } 121 } 110 delete fpPolyhedron; fpPolyhedron = nullptr; << 122 delete fpPolyhedron; fpPolyhedron = 0; 111 } 123 } 112 124 113 ////////////////////////////////////////////// 125 /////////////////////////////////////////////////////////////// 114 // 126 // 115 // Copy constructor 127 // Copy constructor 116 128 117 G4BooleanSolid::G4BooleanSolid(const G4Boolean 129 G4BooleanSolid::G4BooleanSolid(const G4BooleanSolid& rhs) 118 : G4VSolid (rhs), fPtrSolidA(rhs.fPtrSolidA) 130 : G4VSolid (rhs), fPtrSolidA(rhs.fPtrSolidA), fPtrSolidB(rhs.fPtrSolidB), 119 fCubicVolume(rhs.fCubicVolume), fSurfaceAr << 131 fAreaRatio(rhs.fAreaRatio), 120 fCubVolStatistics(rhs.fCubVolStatistics), << 132 fStatistics(rhs.fStatistics), fCubVolEpsilon(rhs.fCubVolEpsilon), 121 fAreaStatistics(rhs.fAreaStatistics), << 133 fAreaAccuracy(rhs.fAreaAccuracy), fCubicVolume(rhs.fCubicVolume), 122 fCubVolEpsilon(rhs.fCubVolEpsilon), << 134 fSurfaceArea(rhs.fSurfaceArea), fRebuildPolyhedron(false), fpPolyhedron(0), 123 fAreaAccuracy(rhs.fAreaAccuracy), << 124 createdDisplacedSolid(rhs.createdDisplaced 135 createdDisplacedSolid(rhs.createdDisplacedSolid) 125 { 136 { 126 fPrimitives.resize(0); fPrimitivesSurfaceAre << 127 } 137 } 128 138 129 ////////////////////////////////////////////// 139 /////////////////////////////////////////////////////////////// 130 // 140 // 131 // Assignment operator 141 // Assignment operator 132 142 133 G4BooleanSolid& G4BooleanSolid::operator = (co 143 G4BooleanSolid& G4BooleanSolid::operator = (const G4BooleanSolid& rhs) 134 { 144 { 135 // Check assignment to self 145 // Check assignment to self 136 // 146 // 137 if (this == &rhs) { return *this; } 147 if (this == &rhs) { return *this; } 138 148 139 // Copy base class data 149 // Copy base class data 140 // 150 // 141 G4VSolid::operator=(rhs); 151 G4VSolid::operator=(rhs); 142 152 143 // Copy data 153 // Copy data 144 // 154 // 145 fPtrSolidA= rhs.fPtrSolidA; fPtrSolidB= rhs. 155 fPtrSolidA= rhs.fPtrSolidA; fPtrSolidB= rhs.fPtrSolidB; 146 fCubicVolume= rhs.fCubicVolume; fSurfaceArea << 156 fAreaRatio= rhs.fAreaRatio; 147 fCubVolStatistics = rhs.fCubVolStatistics; f << 157 fStatistics= rhs.fStatistics; fCubVolEpsilon= rhs.fCubVolEpsilon; 148 fAreaStatistics = rhs.fAreaStatistics; fArea << 158 fAreaAccuracy= rhs.fAreaAccuracy; fCubicVolume= rhs.fCubicVolume; >> 159 fSurfaceArea= rhs.fSurfaceArea; fpPolyhedron= 0; 149 createdDisplacedSolid= rhs.createdDisplacedS 160 createdDisplacedSolid= rhs.createdDisplacedSolid; 150 << 151 fRebuildPolyhedron = false; 161 fRebuildPolyhedron = false; 152 delete fpPolyhedron; fpPolyhedron = nullptr; << 162 delete fpPolyhedron; fpPolyhedron = 0; 153 fPrimitives.resize(0); fPrimitivesSurfaceAre << 154 163 155 return *this; 164 return *this; 156 } 165 } 157 166 158 ////////////////////////////////////////////// 167 /////////////////////////////////////////////////////////////// 159 // 168 // 160 // If solid is made up from a Boolean operatio << 169 // If Solid is made up from a Boolean operation of two solids, 161 // return the corresponding solid (for no=0 an << 170 // return the corresponding solid (for no=0 and 1) 162 // If the solid is not a "Boolean", return 0 171 // If the solid is not a "Boolean", return 0 163 172 164 const G4VSolid* G4BooleanSolid::GetConstituent 173 const G4VSolid* G4BooleanSolid::GetConstituentSolid(G4int no) const 165 { 174 { 166 const G4VSolid* subSolid = nullptr; << 175 const G4VSolid* subSolid=0; 167 if( no == 0 ) 176 if( no == 0 ) 168 subSolid = fPtrSolidA; 177 subSolid = fPtrSolidA; 169 else if( no == 1 ) 178 else if( no == 1 ) 170 subSolid = fPtrSolidB; 179 subSolid = fPtrSolidB; 171 else 180 else 172 { 181 { 173 DumpInfo(); 182 DumpInfo(); 174 G4Exception("G4BooleanSolid::GetConstituen 183 G4Exception("G4BooleanSolid::GetConstituentSolid()", 175 "GeomSolids0002", FatalExcepti 184 "GeomSolids0002", FatalException, "Invalid solid index."); 176 } 185 } >> 186 177 return subSolid; 187 return subSolid; 178 } 188 } 179 189 180 ////////////////////////////////////////////// 190 /////////////////////////////////////////////////////////////// 181 // 191 // 182 // If solid is made up from a Boolean operatio << 192 // If Solid is made up from a Boolean operation of two solids, 183 // return the corresponding solid (for no=0 an << 193 // return the corresponding solid (for no=0 and 1) 184 // If the solid is not a "Boolean", return 0 194 // If the solid is not a "Boolean", return 0 185 195 186 G4VSolid* G4BooleanSolid::GetConstituentSolid( 196 G4VSolid* G4BooleanSolid::GetConstituentSolid(G4int no) 187 { 197 { 188 G4VSolid* subSolid = nullptr; << 198 G4VSolid* subSolid=0; 189 if( no == 0 ) 199 if( no == 0 ) 190 subSolid = fPtrSolidA; 200 subSolid = fPtrSolidA; 191 else if( no == 1 ) 201 else if( no == 1 ) 192 subSolid = fPtrSolidB; 202 subSolid = fPtrSolidB; 193 else 203 else 194 { 204 { 195 DumpInfo(); 205 DumpInfo(); 196 G4Exception("G4BooleanSolid::GetConstituen 206 G4Exception("G4BooleanSolid::GetConstituentSolid()", 197 "GeomSolids0002", FatalExcepti 207 "GeomSolids0002", FatalException, "Invalid solid index."); 198 } 208 } >> 209 199 return subSolid; 210 return subSolid; 200 } 211 } 201 212 202 ////////////////////////////////////////////// 213 ////////////////////////////////////////////////////////////////////////// 203 // 214 // 204 // Returns entity type 215 // Returns entity type 205 216 206 G4GeometryType G4BooleanSolid::GetEntityType() 217 G4GeometryType G4BooleanSolid::GetEntityType() const 207 { 218 { 208 return {"G4BooleanSolid"}; << 219 return G4String("G4BooleanSolid"); 209 } << 210 << 211 ////////////////////////////////////////////// << 212 // << 213 // Set number of random points to be used for << 214 << 215 void G4BooleanSolid::SetCubVolStatistics(G4int << 216 { << 217 if (st != fCubVolStatistics) { fCubicVolume << 218 fCubVolStatistics = st; << 219 << 220 // Propagate st to all components of the 1st << 221 if (fPtrSolidA->GetNumOfConstituents() > 1) << 222 { << 223 G4VSolid* ptr = fPtrSolidA; << 224 while(true) << 225 { << 226 G4String type = ptr->GetEntityType(); << 227 if (type == "G4DisplacedSolid") << 228 { << 229 ptr = ((G4DisplacedSolid*)ptr)->GetCon << 230 continue; << 231 } << 232 if (type == "G4ReflectedSolid") << 233 { << 234 ptr = ((G4ReflectedSolid*)ptr)->GetCon << 235 continue; << 236 } << 237 if (type == "G4ScaledSolid") << 238 { << 239 ptr = ((G4ScaledSolid*)ptr)->GetUnscal << 240 continue; << 241 } << 242 if (type != "G4MultiUnion") // G4MultiUn << 243 { << 244 ((G4BooleanSolid*)ptr)->SetCubVolStatistics( << 245 } << 246 break; << 247 } << 248 } << 249 << 250 // Propagate st to all components of the 2nd << 251 if (fPtrSolidB->GetNumOfConstituents() > 1) << 252 { << 253 G4VSolid* ptr = fPtrSolidB; << 254 while(true) << 255 { << 256 G4String type = ptr->GetEntityType(); << 257 if (type == "G4DisplacedSolid") << 258 { << 259 ptr = ((G4DisplacedSolid*)ptr)->GetCon << 260 continue; << 261 } << 262 if (type == "G4ReflectedSolid") << 263 { << 264 ptr = ((G4ReflectedSolid*)ptr)->GetCon << 265 continue; << 266 } << 267 if (type == "G4ScaledSolid") << 268 { << 269 ptr = ((G4ScaledSolid*)ptr)->GetUnscal << 270 continue; << 271 } << 272 if (type != "G4MultiUnion") // G4MultiUn << 273 { << 274 ((G4BooleanSolid*)ptr)->SetCubVolStatistics( << 275 } << 276 break; << 277 } << 278 } << 279 } << 280 << 281 ////////////////////////////////////////////// << 282 // << 283 // Set epsilon for computing cubic volume << 284 << 285 void G4BooleanSolid::SetCubVolEpsilon(G4double << 286 { << 287 if (ep != fCubVolEpsilon) { fCubicVolume = - << 288 fCubVolEpsilon = ep; << 289 << 290 // Propagate ep to all components of the 1st << 291 if (fPtrSolidA->GetNumOfConstituents() > 1) << 292 { << 293 G4VSolid* ptr = fPtrSolidA; << 294 while(true) << 295 { << 296 G4String type = ptr->GetEntityType(); << 297 if (type == "G4DisplacedSolid") << 298 { << 299 ptr = ((G4DisplacedSolid*)ptr)->GetCon << 300 continue; << 301 } << 302 if (type == "G4ReflectedSolid") << 303 { << 304 ptr = ((G4ReflectedSolid*)ptr)->GetCon << 305 continue; << 306 } << 307 if (type == "G4ScaledSolid") << 308 { << 309 ptr = ((G4ScaledSolid*)ptr)->GetUnscal << 310 continue; << 311 } << 312 if (type != "G4MultiUnion") // G4MultiUn << 313 { << 314 ((G4BooleanSolid*)ptr)->SetCubVolEpsilon(ep) << 315 } << 316 break; << 317 } << 318 } << 319 << 320 // Propagate ep to all components of the 2nd << 321 if (fPtrSolidB->GetNumOfConstituents() > 1) << 322 { << 323 G4VSolid* ptr = fPtrSolidB; << 324 while(true) << 325 { << 326 G4String type = ptr->GetEntityType(); << 327 if (type == "G4DisplacedSolid") << 328 { << 329 ptr = ((G4DisplacedSolid*)ptr)->GetCon << 330 continue; << 331 } << 332 if (type == "G4ReflectedSolid") << 333 { << 334 ptr = ((G4ReflectedSolid*)ptr)->GetCon << 335 continue; << 336 } << 337 if (type == "G4ScaledSolid") << 338 { << 339 ptr = ((G4ScaledSolid*)ptr)->GetUnscal << 340 continue; << 341 } << 342 if (type != "G4MultiUnion") // G4MultiUn << 343 { << 344 ((G4BooleanSolid*)ptr)->SetCubVolEpsilon(ep) << 345 } << 346 break; << 347 } << 348 } << 349 } 220 } 350 221 351 ////////////////////////////////////////////// 222 ////////////////////////////////////////////////////////////////////////// 352 // 223 // 353 // Stream object contents to an output stream 224 // Stream object contents to an output stream 354 225 355 std::ostream& G4BooleanSolid::StreamInfo(std:: 226 std::ostream& G4BooleanSolid::StreamInfo(std::ostream& os) const 356 { 227 { 357 os << "------------------------------------- 228 os << "-----------------------------------------------------------\n" 358 << " *** Dump for Boolean solid - " << 229 << " *** Dump for Boolean solid - " << GetName() << " ***\n" 359 << " ================================= 230 << " ===================================================\n" 360 << " Solid type: " << GetEntityType() << 231 << " Solid type: " << GetEntityType() << "\n" 361 << " Parameters of constituent solids: \n 232 << " Parameters of constituent solids: \n" 362 << "===================================== 233 << "===========================================================\n"; 363 fPtrSolidA->StreamInfo(os); 234 fPtrSolidA->StreamInfo(os); 364 fPtrSolidB->StreamInfo(os); 235 fPtrSolidB->StreamInfo(os); 365 os << "===================================== 236 os << "===========================================================\n"; 366 237 367 return os; 238 return os; 368 } 239 } 369 240 370 ////////////////////////////////////////////// 241 ////////////////////////////////////////////////////////////////////////// 371 // 242 // 372 // Creates list of constituent primitives of a << 373 << 374 void G4BooleanSolid::GetListOfPrimitives( << 375 std::vector<std::pair<G4VSolid*,G4Trans << 376 const G4Transform3D& curPlacement) cons << 377 { << 378 G4Transform3D transform; << 379 G4VSolid* solid; << 380 G4String type; << 381 << 382 // Repeat two times, first time for fPtrSoli << 383 // << 384 for (auto i=0; i<2; ++i) << 385 { << 386 transform = curPlacement; << 387 solid = (i == 0) ? fPtrSolidA : fPtrSo << 388 type = solid->GetEntityType(); << 389 << 390 // While current solid is a trasformed sol << 391 // << 392 while (type == "G4DisplacedSolid" || << 393 type == "G4ReflectedSolid" || << 394 type == "G4ScaledSolid") << 395 { << 396 if (type == "G4DisplacedSolid") << 397 { << 398 transform = transform * G4Transform3D( << 399 ((G4DisplacedSolid*)solid) << 400 ((G4DisplacedSolid*)solid) << 401 solid = ((G4DisplacedSolid*)solid) << 402 } << 403 else if (type == "G4ReflectedSolid") << 404 { << 405 transform= transform*((G4ReflectedSoli << 406 solid = ((G4ReflectedSolid*)solid)- << 407 } << 408 else if (type == "G4ScaledSolid") << 409 { << 410 transform = transform * ((G4ScaledSoli << 411 solid = ((G4ScaledSolid*)solid)->G << 412 } << 413 type = solid->GetEntityType(); << 414 } << 415 << 416 // If current solid is a Boolean solid the << 417 // otherwise add it to the list of primiti << 418 // << 419 if (type == "G4UnionSolid" || << 420 type == "G4SubtractionSolid" || << 421 type == "G4IntersectionSolid" || << 422 type == "G4BooleanSolid") << 423 { << 424 ((G4BooleanSolid *)solid)->GetListOfPrim << 425 } << 426 else << 427 { << 428 primitives.emplace_back(solid,transform) << 429 } << 430 } << 431 } << 432 << 433 ////////////////////////////////////////////// << 434 // << 435 // Returns a point (G4ThreeVector) randomly an 243 // Returns a point (G4ThreeVector) randomly and uniformly selected 436 // on the surface of the solid << 244 // on the solid surface >> 245 // 437 246 438 G4ThreeVector G4BooleanSolid::GetPointOnSurfac 247 G4ThreeVector G4BooleanSolid::GetPointOnSurface() const 439 { 248 { 440 std::size_t nprims = fPrimitives.size(); << 249 G4double rand; 441 std::pair<G4VSolid *, G4Transform3D> prim; << 442 << 443 // Get list of primitives and find the total << 444 // << 445 if (nprims == 0) << 446 { << 447 GetListOfPrimitives(fPrimitives, G4Transfo << 448 nprims = fPrimitives.size(); << 449 fPrimitivesSurfaceArea = 0.; << 450 for (std::size_t i=0; i<nprims; ++i) << 451 { << 452 fPrimitivesSurfaceArea += fPrimitives[i] << 453 } << 454 } << 455 << 456 // Select random primitive, get random point << 457 // check that the point belongs to the surfa << 458 // << 459 G4ThreeVector p; 250 G4ThreeVector p; 460 for (std::size_t k=0; k<100000; ++k) // try << 461 { << 462 G4double rand = fPrimitivesSurfaceArea * << 463 G4double area = 0.; << 464 for (std::size_t i=0; i<nprims; ++i) << 465 { << 466 prim = fPrimitives[i]; << 467 area += prim.first->GetSurfaceArea(); << 468 if (rand < area) break; << 469 } << 470 p = prim.first->GetPointOnSurface(); << 471 p = prim.second * G4Point3D(p); << 472 if (Inside(p) == kSurface) return p; << 473 } << 474 std::ostringstream message; << 475 message << "Solid - " << GetName() << "\n" << 476 << "All 100k attempts to generate a << 477 << "The solid created may be an inva << 478 G4Exception("G4BooleanSolid::GetPointOnSurfa << 479 "GeomSolids1001", JustWarning, m << 480 return p; << 481 } << 482 251 483 ////////////////////////////////////////////// << 252 do 484 // << 253 { 485 // Return total number of constituents used fo << 254 rand = G4UniformRand(); 486 << 487 G4int G4BooleanSolid::GetNumOfConstituents() c << 488 { << 489 return (fPtrSolidA->GetNumOfConstituents() + << 490 } << 491 255 492 ////////////////////////////////////////////// << 256 if (rand < GetAreaRatio()) { p = fPtrSolidA->GetPointOnSurface(); } 493 // << 257 else { p = fPtrSolidB->GetPointOnSurface(); } 494 // Return true if the resulting solid has only << 258 } while (Inside(p) != kSurface); 495 259 496 G4bool G4BooleanSolid::IsFaceted() const << 260 return p; 497 { << 498 return (fPtrSolidA->IsFaceted() && fPtrSolid << 499 } 261 } 500 262 501 ////////////////////////////////////////////// 263 ////////////////////////////////////////////////////////////////////////// 502 // 264 // 503 // Returns polyhedron for visualization 265 // Returns polyhedron for visualization 504 266 505 G4Polyhedron* G4BooleanSolid::GetPolyhedron () 267 G4Polyhedron* G4BooleanSolid::GetPolyhedron () const 506 { 268 { 507 if (fpPolyhedron == nullptr || << 269 if (!fpPolyhedron || 508 fRebuildPolyhedron || 270 fRebuildPolyhedron || 509 fpPolyhedron->GetNumberOfRotationStepsAt 271 fpPolyhedron->GetNumberOfRotationStepsAtTimeOfCreation() != 510 fpPolyhedron->GetNumberOfRotationSteps() 272 fpPolyhedron->GetNumberOfRotationSteps()) 511 { 273 { 512 G4RecursiveAutoLock l(&polyhedronMutex); << 274 G4AutoLock l(&polyhedronMutex); 513 delete fpPolyhedron; 275 delete fpPolyhedron; 514 fpPolyhedron = CreatePolyhedron(); 276 fpPolyhedron = CreatePolyhedron(); 515 fRebuildPolyhedron = false; 277 fRebuildPolyhedron = false; 516 l.unlock(); 278 l.unlock(); 517 } 279 } 518 return fpPolyhedron; 280 return fpPolyhedron; 519 } 281 } 520 282 521 ////////////////////////////////////////////// 283 ////////////////////////////////////////////////////////////////////////// 522 // 284 // 523 // Stacks polyhedra for processing. Returns to 285 // Stacks polyhedra for processing. Returns top polyhedron. 524 286 525 G4Polyhedron* 287 G4Polyhedron* 526 G4BooleanSolid::StackPolyhedron(HepPolyhedronP 288 G4BooleanSolid::StackPolyhedron(HepPolyhedronProcessor& processor, 527 const G4VSolid 289 const G4VSolid* solid) const 528 { 290 { 529 HepPolyhedronProcessor::Operation operation; 291 HepPolyhedronProcessor::Operation operation; 530 const G4String& type = solid->GetEntityType( 292 const G4String& type = solid->GetEntityType(); 531 if (type == "G4UnionSolid") 293 if (type == "G4UnionSolid") 532 { operation = HepPolyhedronProcessor::UNIO 294 { operation = HepPolyhedronProcessor::UNION; } 533 else if (type == "G4IntersectionSolid") 295 else if (type == "G4IntersectionSolid") 534 { operation = HepPolyhedronProcessor::INTE 296 { operation = HepPolyhedronProcessor::INTERSECTION; } 535 else if (type == "G4SubtractionSolid") 297 else if (type == "G4SubtractionSolid") 536 { operation = HepPolyhedronProcessor::SUBT 298 { operation = HepPolyhedronProcessor::SUBTRACTION; } 537 else 299 else 538 { 300 { 539 std::ostringstream message; 301 std::ostringstream message; 540 message << "Solid - " << solid->GetName() 302 message << "Solid - " << solid->GetName() 541 << " - Unrecognised composite soli 303 << " - Unrecognised composite solid" << G4endl 542 << " Returning NULL !"; 304 << " Returning NULL !"; 543 G4Exception("StackPolyhedron()", "GeomSoli 305 G4Exception("StackPolyhedron()", "GeomSolids1001", JustWarning, message); 544 return nullptr; << 306 return 0; 545 } 307 } 546 308 547 G4Polyhedron* top = nullptr; << 309 G4Polyhedron* top = 0; 548 const G4VSolid* solidA = solid->GetConstitue 310 const G4VSolid* solidA = solid->GetConstituentSolid(0); 549 const G4VSolid* solidB = solid->GetConstitue 311 const G4VSolid* solidB = solid->GetConstituentSolid(1); 550 312 551 if (solidA->GetConstituentSolid(0) != nullpt << 313 if (solidA->GetConstituentSolid(0)) 552 { 314 { 553 top = StackPolyhedron(processor, solidA); 315 top = StackPolyhedron(processor, solidA); 554 } 316 } 555 else 317 else 556 { 318 { 557 top = solidA->GetPolyhedron(); 319 top = solidA->GetPolyhedron(); 558 } 320 } 559 G4Polyhedron* operand = solidB->GetPolyhedro 321 G4Polyhedron* operand = solidB->GetPolyhedron(); 560 if (operand != nullptr) << 322 processor.push_back (operation, *operand); 561 { << 562 processor.push_back (operation, *operand); << 563 } << 564 else << 565 { << 566 std::ostringstream message; << 567 message << "Solid - " << solid->GetName() << 568 << " - No G4Polyhedron for Boolean << 569 G4Exception("G4BooleanSolid::StackPolyhedr << 570 "GeomSolids2001", JustWarning, << 571 } << 572 323 573 return top; 324 return top; 574 } << 575 << 576 << 577 ////////////////////////////////////////////// << 578 // << 579 // Estimate Cubic Volume (capacity) and cache << 580 << 581 G4double G4BooleanSolid::GetCubicVolume() << 582 { << 583 if(fCubicVolume < 0.) << 584 { << 585 fCubicVolume = EstimateCubicVolume(fCubVol << 586 } << 587 return fCubicVolume; << 588 } << 589 << 590 ////////////////////////////////////////////// << 591 // << 592 // Set external Boolean processor. << 593 << 594 void << 595 G4BooleanSolid::SetExternalBooleanProcessor(G4 << 596 { << 597 fExternalBoolProcessor = extProcessor; << 598 } << 599 << 600 ////////////////////////////////////////////// << 601 // << 602 // Get external Boolean processor. << 603 << 604 G4VBooleanProcessor* G4BooleanSolid::GetExtern << 605 { << 606 return fExternalBoolProcessor; << 607 } 325 } 608 326