86 G4int localNoDaughters;
91 motherSolid = motherLogical->
GetSolid();
97 G4cout <<
"*** G4VoxelSafety::ComputeSafety(): ***" <<
G4endl;
106 #ifdef G4DEBUG_NAVIGATION
109 std::ostringstream message;
110 message <<
"Safety method called for location outside current Volume."
112 <<
"Location for safety is Outside this volume. " <<
G4endl
113 <<
"The approximate distance to the solid "
114 <<
"(safety from outside) is: "
116 message <<
" Problem occurred with physical volume: "
117 <<
" Name: " << currentPhysical.
GetName()
119 <<
" Local Point = " << localPoint <<
G4endl;
120 message <<
" Description of solid: " << G4endl
121 << *motherSolid <<
G4endl;
122 G4Exception(
"G4VoxelSafety::ComputeSafety()",
"GeomNav0003",
132 ourSafety = motherSafety;
137 G4cout <<
" Invoked DistanceToOut(p) for mother solid: "
139 <<
". Solid replied: " << motherSafety <<
G4endl
140 <<
" For local point p: " << localPoint
141 <<
", to be considered as 'mother safety'." <<
G4endl;
151 currentPhysical, 0, ourSafety);
152 ourSafety=
std::min( motherSafety, daughterSafety );
169 G4int curNoVolumes, contentNo, sampleNo;
178 for ( contentNo=curNoVolumes-1; contentNo>=0; contentNo-- )
180 sampleNo = curVoxelNode->
GetVolume(contentNo);
193 ourSafety =
std::min( sampleSafety, ourSafety );
198 G4cout <<
"*** G4VoxelSafety::SafetyForVoxelNode(): ***" <<
G4endl
199 <<
" Invoked DistanceToIn(p) for daughter solid: "
201 <<
". Solid replied: " << sampleSafety <<
G4endl
202 <<
" For local point p: " << samplePoint
203 <<
", to be considered as 'daughter safety'." <<
G4endl;
232 EAxis targetHeaderAxis;
233 G4double targetHeaderMin, targetHeaderMax, targetHeaderNodeWidth;
234 G4int targetHeaderNoSlices;
239 unsigned int checkedNum= 0;
244 targetHeaderAxis = targetVoxelHeader->
GetAxis();
245 targetHeaderNoSlices = targetVoxelHeader->
GetNoSlices();
249 targetHeaderNodeWidth = (targetHeaderMax-targetHeaderMin)
250 / targetHeaderNoSlices;
252 G4double localCrd= localPoint(targetHeaderAxis);
254 const G4int candNodeNo=
G4int( (localCrd-targetHeaderMin)
255 / targetHeaderNodeWidth );
258 #ifdef G4DEBUG_VOXELISATION
259 if( candNodeNo < 0 || candNodeNo > targetHeaderNoSlices-1 )
262 ed <<
" Potential ERROR."
263 <<
" Point is outside range of Voxel in current coordinate" <<
G4endl;
264 ed <<
" Node number of point " << localPoint
265 <<
"is outside the range. " <<
G4endl;
266 ed <<
" Voxel node Num= " << candNodeNo <<
" versus minimum= " << 0
267 <<
" and maximum= " << targetHeaderNoSlices-1 <<
G4endl;
268 ed <<
" Axis = " << targetHeaderAxis
269 <<
" No of slices = " << targetHeaderNoSlices <<
G4endl;
270 ed <<
" Local coord = " << localCrd
271 <<
" Voxel Min = " << targetHeaderMin
272 <<
" Max = " << targetHeaderMax <<
G4endl;
274 ed <<
" Current volume (physical) = " << currentPhysical.
GetName()
279 G4Exception(
"G4VoxelSafety::SafetyForVoxelHeader()",
"GeomNav1003",
281 "Point is outside range of Voxel in current coordinate");
285 const G4int pointNodeNo =
292 G4cout <<
"**** G4VoxelSafety::SafetyForVoxelHeader " <<
G4endl;
294 G4cout <<
" Calculated pointNodeNo= " << pointNodeNo
295 <<
" from position= " << localPoint(targetHeaderAxis)
296 <<
" min= " << targetHeaderMin
297 <<
" max= " << targetHeaderMax
298 <<
" width= " << targetHeaderNodeWidth
299 <<
" no-slices= " << targetHeaderNoSlices
300 <<
" axis= " << targetHeaderAxis <<
G4endl;
305 <<
" Number of Slices = " << targetHeaderNoSlices
306 <<
" Header (address) = " << targetVoxelHeader <<
G4endl;
318 G4int trialUp= -1, trialDown= -1;
323 G4int nextUp= pointNodeNo+1;
324 G4int nextDown= pointNodeNo-1;
326 G4int nextNodeNo= pointNodeNo;
330 G4bool nextIsInside=
false;
337 targetNodeNo= pointNodeNo;
345 sampleProxy = targetVoxelHeader->
GetSlice(targetNodeNo);
347 #ifdef G4DEBUG_NAVIGATION
348 assert( sampleProxy != 0);
351 G4cout <<
" -Checking node " << targetNodeNo
352 <<
" is proxy with address " << sampleProxy <<
G4endl;
356 if ( sampleProxy == 0 )
359 ed <<
" Problem for node number= " << targetNodeNo
360 <<
" Number of slides = " << targetHeaderNoSlices
362 G4Exception(
"G4VoxelSafety::SafetyForVoxelHeader()",
"GeomNav0003",
364 "Problem sampleProxy is Zero. Failure in loop.");
366 else if ( sampleProxy->
IsNode() )
368 targetVoxelNode = sampleProxy->
GetNode();
373 #ifdef G4DEBUG_NAVIGATION
376 G4cout <<
" -- It is a Node ";
377 G4cout <<
" its safety= " << nodeSafety
378 <<
" our level Saf = " << ourSafety
379 <<
" MinSaf= " << minSafety <<
G4endl;
382 ourSafety=
std::min( ourSafety, nodeSafety );
392 distCombined_Sq = distUpperDepth_Sq + distAxis*distAxis;
394 #ifdef G4DEBUG_NAVIGATION
397 G4double distCombined= std::sqrt( distCombined_Sq );
398 G4double distUpperDepth= std::sqrt ( distUpperDepth_Sq );
400 G4cout <<
" Recurse to deal with next level, fVoxelDepth= "
402 G4cout <<
" Distances: Upper= " << distUpperDepth
403 <<
" Axis= " << distAxis
404 <<
" Combined= " << distCombined <<
G4endl;
411 maxLength, currentPhysical,
412 distCombined_Sq, minSafety);
413 ourSafety=
std::min( ourSafety, headerSafety );
415 #ifdef G4DEBUG_NAVIGATION
418 G4cout <<
" >> Header safety = " << headerSafety
419 <<
" our level Saf = " << ourSafety <<
G4endl;
425 minSafety=
std::min( minSafety, ourSafety );
431 if( targetNodeNo >= pointNodeNo )
435 G4double lowerEdgeOfNext = targetHeaderMin
436 + nextUp * targetHeaderNodeWidth;
437 distUp = lowerEdgeOfNext-localCrd ;
442 #ifdef G4DEBUG_NAVIGATION
450 if( targetNodeNo <= pointNodeNo )
452 nextDown = trialDown;
454 G4double upperEdgeOfNext = targetHeaderMin
455 + (nextDown+1) * targetHeaderNodeWidth;
456 distDown = localCrd-upperEdgeOfNext;
461 #ifdef G4DEBUG_NAVIGATION
464 G4cout <<
" > Updated nextDown= " << nextDown <<
G4endl;
469 #ifdef G4DEBUG_NAVIGATION
472 G4cout <<
" Node= " << pointNodeNo
473 <<
" Up: next= " << nextUp <<
" d# "
474 << nextUp - pointNodeNo
475 <<
" trialUp= " << trialUp <<
" d# "
476 << trialUp - pointNodeNo
477 <<
" Down: next= " << nextDown <<
" d# "
478 << targetNodeNo - nextDown
479 <<
" trialDwn= " << trialDown <<
" d# "
480 << targetNodeNo - trialDown
481 <<
" condition (next is Inside)= " << nextIsInside
487 UpIsClosest= distUp < distDown;
489 if( (nextUp < targetHeaderNoSlices)
490 && (UpIsClosest || (nextDown < 0)) )
499 <<
" Nodes: next= " << nextNodeNo
500 <<
" new nextUp= " << nextUp
501 <<
" Dist = " << distAxis <<
G4endl;
514 <<
" Nodes: next= " << nextNodeNo
515 <<
" new nextDown= " << nextDown
516 <<
" Dist = " << distAxis <<
G4endl;
521 nextIsInside = (nextNodeNo >= 0) && (nextNodeNo < targetHeaderNoSlices);
524 targetNodeNo= nextNodeNo;
526 #ifdef G4DEBUG_NAVIGATION
527 assert( targetVoxelHeader->
GetSlice(nextNodeNo) != 0 );
533 G4cout <<
" Can skip remaining at depth " << targetHeaderAxis
534 <<
" >> distAxis= " << distAxis
535 <<
" minSafety= " << minSafety <<
G4endl;
542 #ifdef G4DEBUG_NAVIGATION
546 G4cout <<
" VoxSaf> No more candidates: nodeDown= " << nextDown
547 <<
" nodeUp= " << nextUp
548 <<
" lastSlice= " << targetHeaderNoSlices <<
G4endl;
555 distMaxInterest =
std::min( minSafety, maxLength );
557 }
while ( nextIsInside && ( distAxis*distAxis + distUpperDepth_Sq
558 < distMaxInterest*distMaxInterest ) );
563 G4cout <<
" Ended for targetNodeNo -- checked " << checkedNum <<
" out of "
564 << targetHeaderNoSlices <<
" slices." <<
G4endl;
565 G4cout <<
" ===== Returning from SafetyForVoxelHeader "
G4LogicalVolume * fpMotherLogical
G4SmartVoxelHeader * GetVoxelHeader() const
G4SmartVoxelHeader * GetHeader() const
G4int GetMinEquivalentSliceNo() const
G4double SafetyForVoxelNode(const G4SmartVoxelNode *curVoxelNode, const G4ThreeVector &localPoint)
G4double SafetyForVoxelHeader(const G4SmartVoxelHeader *pHead, const G4ThreeVector &localPoint, G4double maxLength, const G4VPhysicalVolume ¤tPhysical, G4double distUpperDepth=0.0, G4double previousMinSafety=DBL_MAX)
const G4ThreeVector & GetTranslation() const
std::ostringstream G4ExceptionDescription
CLHEP::Hep3Vector G4ThreeVector
G4int GetVolume(G4int pVolumeNo) const
std::vector< G4int > fVoxelNodeNoStack
G4double GetSurfaceTolerance() const
G4VPhysicalVolume * GetDaughter(const G4int i) const
G4double ComputeSafety(const G4ThreeVector &localPoint, const G4VPhysicalVolume ¤tPhysical, G4double maxLength=DBL_MAX)
virtual G4GeometryType GetEntityType() const =0
G4int GetNoContained() const
G4int GetMaxEquivalentSliceNo() const
G4GLOB_DLL std::ostream G4cout
std::vector< G4double > fVoxelSliceWidthStack
const G4String & GetName() const
virtual EInside Inside(const G4ThreeVector &p) const =0
void BlockVolume(const G4int v)
G4bool IsBlocked(const G4int v) const
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
std::vector< const G4SmartVoxelHeader * > fVoxelHeaderStack
G4int GetNoDaughters() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
static const G4double minSafety
std::vector< G4int > fVoxelNoSlicesStack
G4LogicalVolume * GetLogicalVolume() const
G4SmartVoxelNode * GetNode() const
T max(const T t1, const T t2)
brief Return the largest of the two arguments
G4BlockingList fBlockList
virtual G4int GetCopyNo() const =0
const G4RotationMatrix * GetRotation() const
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
static const G4int kNavigatorVoxelStackMax
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const =0
static G4GeometryTolerance * GetInstance()
G4VSolid * GetSolid() const
void Enlarge(const G4int nv)
std::vector< EAxis > fVoxelAxisStack