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 // G4VCSGfaceted implementation; a virtual cla 26 // G4VCSGfaceted implementation; a virtual class of a CSG type shape 27 // that is built entirely out of G4VCSGface fa 27 // that is built entirely out of G4VCSGface faces. 28 // 28 // 29 // Author: David C. Williams (davidw@scipp.ucs 29 // Author: David C. Williams (davidw@scipp.ucsc.edu) 30 // ------------------------------------------- 30 // -------------------------------------------------------------------- 31 31 32 #include "G4VCSGfaceted.hh" 32 #include "G4VCSGfaceted.hh" 33 #include "G4VCSGface.hh" 33 #include "G4VCSGface.hh" 34 #include "G4SolidExtentList.hh" 34 #include "G4SolidExtentList.hh" 35 35 36 #include "G4VoxelLimits.hh" 36 #include "G4VoxelLimits.hh" 37 #include "G4AffineTransform.hh" 37 #include "G4AffineTransform.hh" 38 38 39 #include "Randomize.hh" 39 #include "Randomize.hh" 40 40 41 #include "G4Polyhedron.hh" 41 #include "G4Polyhedron.hh" 42 #include "G4VGraphicsScene.hh" 42 #include "G4VGraphicsScene.hh" 43 #include "G4VisExtent.hh" 43 #include "G4VisExtent.hh" 44 44 45 #include "G4AutoLock.hh" 45 #include "G4AutoLock.hh" 46 46 47 namespace 47 namespace 48 { 48 { 49 G4Mutex polyhedronMutex = G4MUTEX_INITIALIZE 49 G4Mutex polyhedronMutex = G4MUTEX_INITIALIZER; 50 } 50 } 51 51 52 // 52 // 53 // Constructor 53 // Constructor 54 // 54 // 55 G4VCSGfaceted::G4VCSGfaceted( const G4String& 55 G4VCSGfaceted::G4VCSGfaceted( const G4String& name ) 56 : G4VSolid(name), 56 : G4VSolid(name), 57 fStatistics(1000000), fCubVolEpsilon(0.001 57 fStatistics(1000000), fCubVolEpsilon(0.001), fAreaAccuracy(-1.) 58 { 58 { 59 } 59 } 60 60 61 61 62 // 62 // 63 // Fake default constructor - sets only member 63 // Fake default constructor - sets only member data and allocates memory 64 // for usage restri 64 // for usage restricted to object persistency. 65 // 65 // 66 G4VCSGfaceted::G4VCSGfaceted( __void__& a ) 66 G4VCSGfaceted::G4VCSGfaceted( __void__& a ) 67 : G4VSolid(a), 67 : G4VSolid(a), 68 fStatistics(1000000), fCubVolEpsilon(0.001 68 fStatistics(1000000), fCubVolEpsilon(0.001), fAreaAccuracy(-1.) 69 { 69 { 70 } 70 } 71 71 72 // 72 // 73 // Destructor 73 // Destructor 74 // 74 // 75 G4VCSGfaceted::~G4VCSGfaceted() 75 G4VCSGfaceted::~G4VCSGfaceted() 76 { 76 { 77 DeleteStuff(); 77 DeleteStuff(); 78 delete fpPolyhedron; fpPolyhedron = nullptr; 78 delete fpPolyhedron; fpPolyhedron = nullptr; 79 } 79 } 80 80 81 81 82 // 82 // 83 // Copy constructor 83 // Copy constructor 84 // 84 // 85 G4VCSGfaceted::G4VCSGfaceted( const G4VCSGface 85 G4VCSGfaceted::G4VCSGfaceted( const G4VCSGfaceted& source ) 86 : G4VSolid( source ) 86 : G4VSolid( source ) 87 { 87 { 88 fStatistics = source.fStatistics; 88 fStatistics = source.fStatistics; 89 fCubVolEpsilon = source.fCubVolEpsilon; 89 fCubVolEpsilon = source.fCubVolEpsilon; 90 fAreaAccuracy = source.fAreaAccuracy; 90 fAreaAccuracy = source.fAreaAccuracy; 91 91 92 CopyStuff( source ); 92 CopyStuff( source ); 93 } 93 } 94 94 95 95 96 // 96 // 97 // Assignment operator 97 // Assignment operator 98 // 98 // 99 G4VCSGfaceted& G4VCSGfaceted::operator=( const 99 G4VCSGfaceted& G4VCSGfaceted::operator=( const G4VCSGfaceted& source ) 100 { 100 { 101 if (&source == this) { return *this; } 101 if (&source == this) { return *this; } 102 102 103 // Copy base class data 103 // Copy base class data 104 // 104 // 105 G4VSolid::operator=(source); 105 G4VSolid::operator=(source); 106 106 107 // Copy data 107 // Copy data 108 // 108 // 109 fStatistics = source.fStatistics; 109 fStatistics = source.fStatistics; 110 fCubVolEpsilon = source.fCubVolEpsilon; 110 fCubVolEpsilon = source.fCubVolEpsilon; 111 fAreaAccuracy = source.fAreaAccuracy; 111 fAreaAccuracy = source.fAreaAccuracy; 112 112 113 DeleteStuff(); 113 DeleteStuff(); 114 CopyStuff( source ); 114 CopyStuff( source ); 115 115 116 return *this; 116 return *this; 117 } 117 } 118 118 119 119 120 // 120 // 121 // CopyStuff (protected) 121 // CopyStuff (protected) 122 // 122 // 123 // Copy the contents of source 123 // Copy the contents of source 124 // 124 // 125 void G4VCSGfaceted::CopyStuff( const G4VCSGfac 125 void G4VCSGfaceted::CopyStuff( const G4VCSGfaceted& source ) 126 { 126 { 127 numFace = source.numFace; 127 numFace = source.numFace; 128 if (numFace == 0) { return; } // odd, but 128 if (numFace == 0) { return; } // odd, but permissable? 129 129 130 faces = new G4VCSGface*[numFace]; 130 faces = new G4VCSGface*[numFace]; 131 131 132 G4VCSGface **face = faces, 132 G4VCSGface **face = faces, 133 **sourceFace = source.faces; 133 **sourceFace = source.faces; 134 do // Loop checking, 13.08.2015, G.Cosmo 134 do // Loop checking, 13.08.2015, G.Cosmo 135 { 135 { 136 *face = (*sourceFace)->Clone(); 136 *face = (*sourceFace)->Clone(); 137 } while( ++sourceFace, ++face < faces+numFac 137 } while( ++sourceFace, ++face < faces+numFace ); 138 fCubicVolume = source.fCubicVolume; 138 fCubicVolume = source.fCubicVolume; 139 fSurfaceArea = source.fSurfaceArea; 139 fSurfaceArea = source.fSurfaceArea; 140 fRebuildPolyhedron = false; 140 fRebuildPolyhedron = false; 141 fpPolyhedron = nullptr; 141 fpPolyhedron = nullptr; 142 } 142 } 143 143 144 144 145 // 145 // 146 // DeleteStuff (protected) 146 // DeleteStuff (protected) 147 // 147 // 148 // Delete all allocated objects 148 // Delete all allocated objects 149 // 149 // 150 void G4VCSGfaceted::DeleteStuff() 150 void G4VCSGfaceted::DeleteStuff() 151 { 151 { 152 if (numFace != 0) << 152 if (numFace) 153 { 153 { 154 G4VCSGface **face = faces; 154 G4VCSGface **face = faces; 155 do // Loop checking, 13.08.2015, G.Cosm 155 do // Loop checking, 13.08.2015, G.Cosmo 156 { 156 { 157 delete *face; 157 delete *face; 158 } while( ++face < faces + numFace ); 158 } while( ++face < faces + numFace ); 159 159 160 delete [] faces; 160 delete [] faces; 161 } 161 } 162 delete fpPolyhedron; fpPolyhedron = nullptr; 162 delete fpPolyhedron; fpPolyhedron = nullptr; 163 } 163 } 164 164 165 165 166 // 166 // 167 // CalculateExtent 167 // CalculateExtent 168 // 168 // 169 G4bool G4VCSGfaceted::CalculateExtent( const E 169 G4bool G4VCSGfaceted::CalculateExtent( const EAxis axis, 170 const G 170 const G4VoxelLimits& voxelLimit, 171 const G 171 const G4AffineTransform& transform, 172 G 172 G4double& min, 173 G 173 G4double& max ) const 174 { 174 { 175 G4SolidExtentList extentList( axis, voxelLi 175 G4SolidExtentList extentList( axis, voxelLimit ); 176 176 177 // 177 // 178 // Loop over all faces, checking min/max ext 178 // Loop over all faces, checking min/max extent as we go. 179 // 179 // 180 G4VCSGface **face = faces; 180 G4VCSGface **face = faces; 181 do // Loop checking, 13.08.2015, G.Cosmo 181 do // Loop checking, 13.08.2015, G.Cosmo 182 { 182 { 183 (*face)->CalculateExtent( axis, voxelLimit 183 (*face)->CalculateExtent( axis, voxelLimit, transform, extentList ); 184 } while( ++face < faces + numFace ); 184 } while( ++face < faces + numFace ); 185 185 186 // 186 // 187 // Return min/max value 187 // Return min/max value 188 // 188 // 189 return extentList.GetExtent( min, max ); 189 return extentList.GetExtent( min, max ); 190 } 190 } 191 191 192 192 193 // 193 // 194 // Inside 194 // Inside 195 // 195 // 196 // It could be a good idea to override this vi 196 // It could be a good idea to override this virtual 197 // member to add first a simple test (such as 197 // member to add first a simple test (such as spherical 198 // test or whatnot) and to call this version o 198 // test or whatnot) and to call this version only if 199 // the simplier test fails. 199 // the simplier test fails. 200 // 200 // 201 EInside G4VCSGfaceted::Inside( const G4ThreeVe 201 EInside G4VCSGfaceted::Inside( const G4ThreeVector& p ) const 202 { 202 { 203 EInside answer=kOutside; 203 EInside answer=kOutside; 204 G4VCSGface **face = faces; 204 G4VCSGface **face = faces; 205 G4double best = kInfinity; 205 G4double best = kInfinity; 206 do // Loop checking, 13.08.2015, G.Cosmo 206 do // Loop checking, 13.08.2015, G.Cosmo 207 { 207 { 208 G4double distance; 208 G4double distance; 209 EInside result = (*face)->Inside( p, kCarT 209 EInside result = (*face)->Inside( p, kCarTolerance/2, &distance ); 210 if (result == kSurface) { return kSurface; 210 if (result == kSurface) { return kSurface; } 211 if (distance < best) 211 if (distance < best) 212 { 212 { 213 best = distance; 213 best = distance; 214 answer = result; 214 answer = result; 215 } 215 } 216 } while( ++face < faces + numFace ); 216 } while( ++face < faces + numFace ); 217 217 218 return answer; 218 return answer; 219 } 219 } 220 220 221 221 222 // 222 // 223 // SurfaceNormal 223 // SurfaceNormal 224 // 224 // 225 G4ThreeVector G4VCSGfaceted::SurfaceNormal( co 225 G4ThreeVector G4VCSGfaceted::SurfaceNormal( const G4ThreeVector& p ) const 226 { 226 { 227 G4ThreeVector answer; 227 G4ThreeVector answer; 228 G4VCSGface **face = faces; 228 G4VCSGface **face = faces; 229 G4double best = kInfinity; 229 G4double best = kInfinity; 230 do // Loop checking, 13.08.2015, G.Cosmo 230 do // Loop checking, 13.08.2015, G.Cosmo 231 { 231 { 232 G4double distance = kInfinity; << 232 G4double distance; 233 G4ThreeVector normal = (*face)->Normal( p, 233 G4ThreeVector normal = (*face)->Normal( p, &distance ); 234 if (distance < best) 234 if (distance < best) 235 { 235 { 236 best = distance; 236 best = distance; 237 answer = normal; 237 answer = normal; 238 } 238 } 239 } while( ++face < faces + numFace ); 239 } while( ++face < faces + numFace ); 240 240 241 return answer; 241 return answer; 242 } 242 } 243 243 244 244 245 // 245 // 246 // DistanceToIn(p,v) 246 // DistanceToIn(p,v) 247 // 247 // 248 G4double G4VCSGfaceted::DistanceToIn( const G4 248 G4double G4VCSGfaceted::DistanceToIn( const G4ThreeVector& p, 249 const G4 249 const G4ThreeVector& v ) const 250 { 250 { 251 G4double distance = kInfinity; 251 G4double distance = kInfinity; 252 G4double distFromSurface = kInfinity; 252 G4double distFromSurface = kInfinity; 253 G4VCSGface **face = faces; 253 G4VCSGface **face = faces; 254 G4VCSGface *bestFace = *face; 254 G4VCSGface *bestFace = *face; 255 do // Loop checking, 13.08.2015, G.Cosmo 255 do // Loop checking, 13.08.2015, G.Cosmo 256 { 256 { 257 G4double faceDistance, 257 G4double faceDistance, 258 faceDistFromSurface; 258 faceDistFromSurface; 259 G4ThreeVector faceNormal; 259 G4ThreeVector faceNormal; 260 G4bool faceAllBehind; 260 G4bool faceAllBehind; 261 if ((*face)->Intersect( p, v, false, kCarT 261 if ((*face)->Intersect( p, v, false, kCarTolerance/2, 262 faceDistance, faceDistFromSurf 262 faceDistance, faceDistFromSurface, 263 faceNormal, faceAllBehind ) ) 263 faceNormal, faceAllBehind ) ) 264 { 264 { 265 // 265 // 266 // Intersecting face 266 // Intersecting face 267 // 267 // 268 if (faceDistance < distance) 268 if (faceDistance < distance) 269 { 269 { 270 distance = faceDistance; 270 distance = faceDistance; 271 distFromSurface = faceDistFromSurface; 271 distFromSurface = faceDistFromSurface; 272 bestFace = *face; 272 bestFace = *face; 273 if (distFromSurface <= 0) { return 0; 273 if (distFromSurface <= 0) { return 0; } 274 } 274 } 275 } 275 } 276 } while( ++face < faces + numFace ); 276 } while( ++face < faces + numFace ); 277 277 278 if (distance < kInfinity && distFromSurface< 278 if (distance < kInfinity && distFromSurface<kCarTolerance/2) 279 { 279 { 280 if (bestFace->Distance(p,false) < kCarTole 280 if (bestFace->Distance(p,false) < kCarTolerance/2) { distance = 0; } 281 } 281 } 282 282 283 return distance; 283 return distance; 284 } 284 } 285 285 286 286 287 // 287 // 288 // DistanceToIn(p) 288 // DistanceToIn(p) 289 // 289 // 290 G4double G4VCSGfaceted::DistanceToIn( const G4 290 G4double G4VCSGfaceted::DistanceToIn( const G4ThreeVector& p ) const 291 { 291 { 292 return DistanceTo( p, false ); 292 return DistanceTo( p, false ); 293 } 293 } 294 294 295 295 296 // 296 // 297 // DistanceToOut(p,v) 297 // DistanceToOut(p,v) 298 // 298 // 299 G4double G4VCSGfaceted::DistanceToOut( const G 299 G4double G4VCSGfaceted::DistanceToOut( const G4ThreeVector& p, 300 const G 300 const G4ThreeVector& v, 301 const G 301 const G4bool calcNorm, 302 G 302 G4bool* validNorm, 303 G 303 G4ThreeVector* n ) const 304 { 304 { 305 G4bool allBehind = true; 305 G4bool allBehind = true; 306 G4double distance = kInfinity; 306 G4double distance = kInfinity; 307 G4double distFromSurface = kInfinity; 307 G4double distFromSurface = kInfinity; 308 G4ThreeVector normal; 308 G4ThreeVector normal; 309 309 310 G4VCSGface **face = faces; 310 G4VCSGface **face = faces; 311 G4VCSGface *bestFace = *face; 311 G4VCSGface *bestFace = *face; 312 do // Loop checking, 13.08.2015, G.Cosmo 312 do // Loop checking, 13.08.2015, G.Cosmo 313 { 313 { 314 G4double faceDistance, 314 G4double faceDistance, 315 faceDistFromSurface; 315 faceDistFromSurface; 316 G4ThreeVector faceNormal; 316 G4ThreeVector faceNormal; 317 G4bool faceAllBehind; 317 G4bool faceAllBehind; 318 if ((*face)->Intersect( p, v, true, kCarTo 318 if ((*face)->Intersect( p, v, true, kCarTolerance/2, 319 faceDistance, faceDistFromSurf 319 faceDistance, faceDistFromSurface, 320 faceNormal, faceAllBehind ) ) 320 faceNormal, faceAllBehind ) ) 321 { 321 { 322 // 322 // 323 // Intersecting face 323 // Intersecting face 324 // 324 // 325 if ( (distance < kInfinity) || (!faceAll 325 if ( (distance < kInfinity) || (!faceAllBehind) ) { allBehind = false; } 326 if (faceDistance < distance) 326 if (faceDistance < distance) 327 { 327 { 328 distance = faceDistance; 328 distance = faceDistance; 329 distFromSurface = faceDistFromSurface; 329 distFromSurface = faceDistFromSurface; 330 normal = faceNormal; 330 normal = faceNormal; 331 bestFace = *face; 331 bestFace = *face; 332 if (distFromSurface <= 0.) { break; } 332 if (distFromSurface <= 0.) { break; } 333 } 333 } 334 } 334 } 335 } while( ++face < faces + numFace ); 335 } while( ++face < faces + numFace ); 336 336 337 if (distance < kInfinity) 337 if (distance < kInfinity) 338 { 338 { 339 if (distFromSurface <= 0.) 339 if (distFromSurface <= 0.) 340 { 340 { 341 distance = 0.; 341 distance = 0.; 342 } 342 } 343 else if (distFromSurface<kCarTolerance/2) 343 else if (distFromSurface<kCarTolerance/2) 344 { 344 { 345 if (bestFace->Distance(p,true) < kCarTol 345 if (bestFace->Distance(p,true) < kCarTolerance/2) { distance = 0.; } 346 } 346 } 347 347 348 if (calcNorm) 348 if (calcNorm) 349 { 349 { 350 *validNorm = allBehind; 350 *validNorm = allBehind; 351 *n = normal; 351 *n = normal; 352 } 352 } 353 } 353 } 354 else 354 else 355 { 355 { 356 if (Inside(p) == kSurface) { distance = 0 356 if (Inside(p) == kSurface) { distance = 0.; } 357 if (calcNorm) { *validNorm = false; } 357 if (calcNorm) { *validNorm = false; } 358 } 358 } 359 359 360 return distance; 360 return distance; 361 } 361 } 362 362 363 363 364 // 364 // 365 // DistanceToOut(p) 365 // DistanceToOut(p) 366 // 366 // 367 G4double G4VCSGfaceted::DistanceToOut( const G 367 G4double G4VCSGfaceted::DistanceToOut( const G4ThreeVector& p ) const 368 { 368 { 369 return DistanceTo( p, true ); 369 return DistanceTo( p, true ); 370 } 370 } 371 371 372 372 373 // 373 // 374 // DistanceTo 374 // DistanceTo 375 // 375 // 376 // Protected routine called by DistanceToIn an 376 // Protected routine called by DistanceToIn and DistanceToOut 377 // 377 // 378 G4double G4VCSGfaceted::DistanceTo( const G4Th 378 G4double G4VCSGfaceted::DistanceTo( const G4ThreeVector& p, 379 const G4bo 379 const G4bool outgoing ) const 380 { 380 { 381 G4VCSGface **face = faces; 381 G4VCSGface **face = faces; 382 G4double best = kInfinity; 382 G4double best = kInfinity; 383 do // Loop checking, 13.08.2015, G.Cosmo 383 do // Loop checking, 13.08.2015, G.Cosmo 384 { 384 { 385 G4double distance = (*face)->Distance( p, 385 G4double distance = (*face)->Distance( p, outgoing ); 386 if (distance < best) { best = distance; } 386 if (distance < best) { best = distance; } 387 } while( ++face < faces + numFace ); 387 } while( ++face < faces + numFace ); 388 388 389 return (best < 0.5*kCarTolerance) ? 0. : bes 389 return (best < 0.5*kCarTolerance) ? 0. : best; 390 } 390 } 391 391 392 392 393 // 393 // 394 // DescribeYourselfTo 394 // DescribeYourselfTo 395 // 395 // 396 void G4VCSGfaceted::DescribeYourselfTo( G4VGra 396 void G4VCSGfaceted::DescribeYourselfTo( G4VGraphicsScene& scene ) const 397 { 397 { 398 scene.AddSolid( *this ); 398 scene.AddSolid( *this ); 399 } 399 } 400 400 401 401 402 // 402 // 403 // GetExtent 403 // GetExtent 404 // 404 // 405 // Define the sides of the box into which our 405 // Define the sides of the box into which our solid instance would fit. 406 // 406 // 407 G4VisExtent G4VCSGfaceted::GetExtent() const 407 G4VisExtent G4VCSGfaceted::GetExtent() const 408 { 408 { 409 static const G4ThreeVector xMax(1,0,0), xMin 409 static const G4ThreeVector xMax(1,0,0), xMin(-1,0,0), 410 yMax(0,1,0), yMin 410 yMax(0,1,0), yMin(0,-1,0), 411 zMax(0,0,1), zMin 411 zMax(0,0,1), zMin(0,0,-1); 412 static const G4ThreeVector *axes[6] = 412 static const G4ThreeVector *axes[6] = 413 { &xMin, &xMax, &yMin, &yMax, &zMin, &zMa 413 { &xMin, &xMax, &yMin, &yMax, &zMin, &zMax }; 414 414 415 G4double answers[6] = 415 G4double answers[6] = 416 {-kInfinity, -kInfinity, -kInfinity, -kIn 416 {-kInfinity, -kInfinity, -kInfinity, -kInfinity, -kInfinity, -kInfinity}; 417 417 418 G4VCSGface **face = faces; 418 G4VCSGface **face = faces; 419 do // Loop checking, 13.08.2015, G.Cosmo 419 do // Loop checking, 13.08.2015, G.Cosmo 420 { 420 { 421 const G4ThreeVector **axis = axes+5 ; 421 const G4ThreeVector **axis = axes+5 ; 422 G4double* answer = answers+5; 422 G4double* answer = answers+5; 423 do // Loop checking, 13.08.2015, G.Cosm 423 do // Loop checking, 13.08.2015, G.Cosmo 424 { 424 { 425 G4double testFace = (*face)->Extent( **a 425 G4double testFace = (*face)->Extent( **axis ); 426 if (testFace > *answer) { *answer = tes 426 if (testFace > *answer) { *answer = testFace; } 427 } 427 } 428 while( --axis, --answer >= answers ); 428 while( --axis, --answer >= answers ); 429 429 430 } while( ++face < faces + numFace ); 430 } while( ++face < faces + numFace ); 431 431 432 return { -answers[0], answers[1], << 432 return G4VisExtent( -answers[0], answers[1], 433 -answers[2], answers[3], << 433 -answers[2], answers[3], 434 -answers[4], answers[5] }; << 434 -answers[4], answers[5] ); 435 } 435 } 436 436 437 437 438 // 438 // 439 // GetEntityType 439 // GetEntityType 440 // 440 // 441 G4GeometryType G4VCSGfaceted::GetEntityType() 441 G4GeometryType G4VCSGfaceted::GetEntityType() const 442 { 442 { 443 return {"G4CSGfaceted"}; << 443 return G4String("G4CSGfaceted"); 444 } 444 } 445 445 446 446 447 // 447 // 448 // Stream object contents to an output stream 448 // Stream object contents to an output stream 449 // 449 // 450 std::ostream& G4VCSGfaceted::StreamInfo( std:: 450 std::ostream& G4VCSGfaceted::StreamInfo( std::ostream& os ) const 451 { 451 { 452 os << "------------------------------------- 452 os << "-----------------------------------------------------------\n" 453 << " *** Dump for solid - " << GetName 453 << " *** Dump for solid - " << GetName() << " ***\n" 454 << " ================================= 454 << " ===================================================\n" 455 << " Solid type: G4VCSGfaceted\n" 455 << " Solid type: G4VCSGfaceted\n" 456 << " Parameters: \n" 456 << " Parameters: \n" 457 << " number of faces: " << numFace << 457 << " number of faces: " << numFace << "\n" 458 << "------------------------------------- 458 << "-----------------------------------------------------------\n"; 459 459 460 return os; 460 return os; 461 } 461 } 462 462 463 463 464 // 464 // 465 // GetCubVolStatistics 465 // GetCubVolStatistics 466 // 466 // 467 G4int G4VCSGfaceted::GetCubVolStatistics() con 467 G4int G4VCSGfaceted::GetCubVolStatistics() const 468 { 468 { 469 return fStatistics; 469 return fStatistics; 470 } 470 } 471 471 472 472 473 // 473 // 474 // GetCubVolEpsilon 474 // GetCubVolEpsilon 475 // 475 // 476 G4double G4VCSGfaceted::GetCubVolEpsilon() con 476 G4double G4VCSGfaceted::GetCubVolEpsilon() const 477 { 477 { 478 return fCubVolEpsilon; 478 return fCubVolEpsilon; 479 } 479 } 480 480 481 481 482 // 482 // 483 // SetCubVolStatistics 483 // SetCubVolStatistics 484 // 484 // 485 void G4VCSGfaceted::SetCubVolStatistics(G4int 485 void G4VCSGfaceted::SetCubVolStatistics(G4int st) 486 { 486 { 487 fCubicVolume=0.; 487 fCubicVolume=0.; 488 fStatistics=st; 488 fStatistics=st; 489 } 489 } 490 490 491 491 492 // 492 // 493 // SetCubVolEpsilon 493 // SetCubVolEpsilon 494 // 494 // 495 void G4VCSGfaceted::SetCubVolEpsilon(G4double 495 void G4VCSGfaceted::SetCubVolEpsilon(G4double ep) 496 { 496 { 497 fCubicVolume=0.; 497 fCubicVolume=0.; 498 fCubVolEpsilon=ep; 498 fCubVolEpsilon=ep; 499 } 499 } 500 500 501 501 502 // 502 // 503 // GetAreaStatistics 503 // GetAreaStatistics 504 // 504 // 505 G4int G4VCSGfaceted::GetAreaStatistics() const 505 G4int G4VCSGfaceted::GetAreaStatistics() const 506 { 506 { 507 return fStatistics; 507 return fStatistics; 508 } 508 } 509 509 510 510 511 // 511 // 512 // GetAreaAccuracy 512 // GetAreaAccuracy 513 // 513 // 514 G4double G4VCSGfaceted::GetAreaAccuracy() cons 514 G4double G4VCSGfaceted::GetAreaAccuracy() const 515 { 515 { 516 return fAreaAccuracy; 516 return fAreaAccuracy; 517 } 517 } 518 518 519 519 520 // 520 // 521 // SetAreaStatistics 521 // SetAreaStatistics 522 // 522 // 523 void G4VCSGfaceted::SetAreaStatistics(G4int st 523 void G4VCSGfaceted::SetAreaStatistics(G4int st) 524 { 524 { 525 fSurfaceArea=0.; 525 fSurfaceArea=0.; 526 fStatistics=st; 526 fStatistics=st; 527 } 527 } 528 528 529 529 530 // 530 // 531 // SetAreaAccuracy 531 // SetAreaAccuracy 532 // 532 // 533 void G4VCSGfaceted::SetAreaAccuracy(G4double e 533 void G4VCSGfaceted::SetAreaAccuracy(G4double ep) 534 { 534 { 535 fSurfaceArea=0.; 535 fSurfaceArea=0.; 536 fAreaAccuracy=ep; 536 fAreaAccuracy=ep; 537 } 537 } 538 538 539 539 540 // 540 // 541 // GetCubicVolume 541 // GetCubicVolume 542 // 542 // 543 G4double G4VCSGfaceted::GetCubicVolume() 543 G4double G4VCSGfaceted::GetCubicVolume() 544 { 544 { 545 if(fCubicVolume != 0.) {;} 545 if(fCubicVolume != 0.) {;} 546 else { fCubicVolume = EstimateCubicVolume( 546 else { fCubicVolume = EstimateCubicVolume(fStatistics,fCubVolEpsilon); } 547 return fCubicVolume; 547 return fCubicVolume; 548 } 548 } 549 549 550 550 551 // 551 // 552 // GetSurfaceArea 552 // GetSurfaceArea 553 // 553 // 554 G4double G4VCSGfaceted::GetSurfaceArea() 554 G4double G4VCSGfaceted::GetSurfaceArea() 555 { 555 { 556 if(fSurfaceArea != 0.) {;} 556 if(fSurfaceArea != 0.) {;} 557 else { fSurfaceArea = EstimateSurfaceArea( 557 else { fSurfaceArea = EstimateSurfaceArea(fStatistics,fAreaAccuracy); } 558 return fSurfaceArea; 558 return fSurfaceArea; 559 } 559 } 560 560 561 561 562 // 562 // 563 // GetPolyhedron 563 // GetPolyhedron 564 // 564 // 565 G4Polyhedron* G4VCSGfaceted::GetPolyhedron () 565 G4Polyhedron* G4VCSGfaceted::GetPolyhedron () const 566 { 566 { 567 if (fpPolyhedron == nullptr || 567 if (fpPolyhedron == nullptr || 568 fRebuildPolyhedron || 568 fRebuildPolyhedron || 569 fpPolyhedron->GetNumberOfRotationStepsAt 569 fpPolyhedron->GetNumberOfRotationStepsAtTimeOfCreation() != 570 fpPolyhedron->GetNumberOfRotationSteps() 570 fpPolyhedron->GetNumberOfRotationSteps()) 571 { 571 { 572 G4AutoLock l(&polyhedronMutex); 572 G4AutoLock l(&polyhedronMutex); 573 delete fpPolyhedron; 573 delete fpPolyhedron; 574 fpPolyhedron = CreatePolyhedron(); 574 fpPolyhedron = CreatePolyhedron(); 575 fRebuildPolyhedron = false; 575 fRebuildPolyhedron = false; 576 l.unlock(); 576 l.unlock(); 577 } 577 } 578 return fpPolyhedron; 578 return fpPolyhedron; 579 } 579 } 580 580 581 581 582 // 582 // 583 // GetPointOnSurfaceGeneric proportional to Ar 583 // GetPointOnSurfaceGeneric proportional to Areas of faces 584 // in case of GenericPolycone or GenericPolyhe 584 // in case of GenericPolycone or GenericPolyhedra 585 // 585 // 586 G4ThreeVector G4VCSGfaceted::GetPointOnSurface 586 G4ThreeVector G4VCSGfaceted::GetPointOnSurfaceGeneric( ) const 587 { 587 { 588 // Preparing variables 588 // Preparing variables 589 // 589 // 590 G4ThreeVector answer=G4ThreeVector(0.,0.,0.) 590 G4ThreeVector answer=G4ThreeVector(0.,0.,0.); 591 G4VCSGface **face = faces; 591 G4VCSGface **face = faces; 592 G4double area = 0.; 592 G4double area = 0.; 593 G4int i; 593 G4int i; 594 std::vector<G4double> areas; 594 std::vector<G4double> areas; 595 595 596 // First step: calculate surface areas 596 // First step: calculate surface areas 597 // 597 // 598 do // Loop checking, 13.08.2015, G.Cosmo 598 do // Loop checking, 13.08.2015, G.Cosmo 599 { 599 { 600 G4double result = (*face)->SurfaceArea( ); 600 G4double result = (*face)->SurfaceArea( ); 601 areas.push_back(result); 601 areas.push_back(result); 602 area=area+result; 602 area=area+result; 603 } while( ++face < faces + numFace ); 603 } while( ++face < faces + numFace ); 604 604 605 // Second Step: choose randomly one surface 605 // Second Step: choose randomly one surface 606 // 606 // 607 G4VCSGface **face1 = faces; 607 G4VCSGface **face1 = faces; 608 G4double chose = area*G4UniformRand(); 608 G4double chose = area*G4UniformRand(); 609 G4double Achose1, Achose2; 609 G4double Achose1, Achose2; 610 Achose1=0.; Achose2=0.; 610 Achose1=0.; Achose2=0.; 611 i=0; 611 i=0; 612 612 613 do 613 do 614 { 614 { 615 Achose2+=areas[i]; 615 Achose2+=areas[i]; 616 if(chose>=Achose1 && chose<Achose2) 616 if(chose>=Achose1 && chose<Achose2) 617 { 617 { 618 G4ThreeVector point; 618 G4ThreeVector point; 619 point= (*face1)->GetPointOnFace(); 619 point= (*face1)->GetPointOnFace(); 620 return point; 620 return point; 621 } 621 } 622 ++i; 622 ++i; 623 Achose1=Achose2; 623 Achose1=Achose2; 624 } while( ++face1 < faces + numFace ); 624 } while( ++face1 < faces + numFace ); 625 625 626 return answer; 626 return answer; 627 } 627 } 628 628