49 fVoxelAxisStack(kNavigatorVoxelStackMax,
kXAxis),
50 fVoxelNoSlicesStack(kNavigatorVoxelStackMax,0),
51 fVoxelSliceWidthStack(kNavigatorVoxelStackMax,0.),
52 fVoxelNodeNoStack(kNavigatorVoxelStackMax,0),
86 G4int localNoDaughters;
90 fpMotherLogical= motherLogical;
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;
146 fBlockList.
Enlarge(localNoDaughters);
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);
185 samplePhysical = fpMotherLogical->
GetDaughter(sampleNo);
193 ourSafety = std::min( sampleSafety, ourSafety );
195 if(( fCheck ) && ( fVerbose == 1 ))
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;
237 G4double minSafety= previousMinSafety;
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 =
286 std::max( 0, std::min( candNodeNo, targetHeaderNoSlices-1 ) );
292 G4cout <<
"**** G4VoxelSafety::SafetyForVoxelHeader " <<
G4endl;
293 G4cout <<
" Called at Depth = " << fVoxelDepth;
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;
302 else if (fVerbose == 1)
304 G4cout <<
" VoxelSafety: Depth = " << fVoxelDepth
305 <<
" Number of Slices = " << targetHeaderNoSlices
306 <<
" Header (address) = " << targetVoxelHeader <<
G4endl;
312 fVoxelAxisStack[fVoxelDepth] = targetHeaderAxis;
313 fVoxelNoSlicesStack[fVoxelDepth] = targetHeaderNoSlices;
314 fVoxelSliceWidthStack[fVoxelDepth] = targetHeaderNodeWidth;
316 fVoxelHeaderStack[fVoxelDepth] = pHeader;
318 G4int trialUp= -1, trialDown= -1;
323 G4int nextUp= pointNodeNo+1;
324 G4int nextDown= pointNodeNo-1;
326 G4int nextNodeNo= pointNodeNo;
330 G4bool nextIsInside=
false;
332 G4double distMaxInterest= std::min( previousMinSafety, maxLength);
337 targetNodeNo= pointNodeNo;
341 fVoxelNodeNoStack[fVoxelDepth] = targetNodeNo;
345 sampleProxy = targetVoxelHeader->
GetSlice(targetNodeNo);
347#ifdef G4DEBUG_NAVIGATION
350 G4cout <<
" -Checking node " << targetNodeNo
351 <<
" is proxy with address " << sampleProxy <<
G4endl;
355 if ( sampleProxy == 0 )
358 ed <<
" Problem for node number= " << targetNodeNo
359 <<
" Number of slides = " << targetHeaderNoSlices
361 G4Exception(
"G4VoxelSafety::SafetyForVoxelHeader()",
"GeomNav0003",
363 "Problem sampleProxy is Zero. Failure in loop.");
365 else if ( sampleProxy->
IsNode() )
367 targetVoxelNode = sampleProxy->
GetNode();
372#ifdef G4DEBUG_NAVIGATION
375 G4cout <<
" -- It is a Node ";
376 G4cout <<
" its safety= " << nodeSafety
377 <<
" our level Saf = " << ourSafety
378 <<
" MinSaf= " << minSafety <<
G4endl;
381 ourSafety= std::min( ourSafety, nodeSafety );
391 distCombined_Sq = distUpperDepth_Sq + distAxis*distAxis;
393#ifdef G4DEBUG_NAVIGATION
396 G4double distCombined= std::sqrt( distCombined_Sq );
397 G4double distUpperDepth= std::sqrt ( distUpperDepth_Sq );
399 G4cout <<
" Recurse to deal with next level, fVoxelDepth= "
400 << fVoxelDepth+1 <<
G4endl;
401 G4cout <<
" Distances: Upper= " << distUpperDepth
402 <<
" Axis= " << distAxis
403 <<
" Combined= " << distCombined <<
G4endl;
410 maxLength, currentPhysical,
411 distCombined_Sq, minSafety);
412 ourSafety= std::min( ourSafety, headerSafety );
414#ifdef G4DEBUG_NAVIGATION
417 G4cout <<
" >> Header safety = " << headerSafety
418 <<
" our level Saf = " << ourSafety <<
G4endl;
424 minSafety= std::min( minSafety, ourSafety );
430 if( targetNodeNo >= pointNodeNo )
433 distUp = targetHeaderMax-localCrd ;
438#ifdef G4DEBUG_NAVIGATION
446 if( targetNodeNo <= pointNodeNo )
448 nextDown = trialDown;
449 distDown = localCrd-targetHeaderMin;
454#ifdef G4DEBUG_NAVIGATION
457 G4cout <<
" > Updated nextDown= " << nextDown <<
G4endl;
462#ifdef G4DEBUG_NAVIGATION
465 G4cout <<
" Node= " << pointNodeNo
466 <<
" Up: next= " << nextUp <<
" d# "
467 << nextUp - pointNodeNo
468 <<
" trialUp= " << trialUp <<
" d# "
469 << trialUp - pointNodeNo
470 <<
" Down: next= " << nextDown <<
" d# "
471 << targetNodeNo - nextDown
472 <<
" trialDwn= " << trialDown <<
" d# "
473 << targetNodeNo - trialDown
474 <<
" condition (next is Inside)= " << nextIsInside
480 UpIsClosest= distUp < distDown;
482 if( UpIsClosest || (nextDown < 0) )
490 G4cout <<
" > Chose Up. Depth= " << fVoxelDepth
491 <<
" Nodes: next= " << nextNodeNo
492 <<
" new nextUp= " << nextUp
493 <<
" Dist = " << distAxis <<
G4endl;
505 G4cout <<
" > Chose Down. Depth= " << fVoxelDepth
506 <<
" Nodes: next= " << nextNodeNo
507 <<
" new nextDown= " << nextDown
508 <<
" Dist = " << distAxis <<
G4endl;
513 nextIsInside = (nextNodeNo >= 0) && (nextNodeNo < targetHeaderNoSlices);
516 targetNodeNo= nextNodeNo;
518#ifdef G4DEBUG_NAVIGATION
519 G4bool bContinue= (distAxis<minSafety);
524 G4cout <<
" Can skip remaining at depth " << targetHeaderAxis
525 <<
" >> distAxis= " << distAxis
526 <<
" minSafety= " << minSafety <<
G4endl;
533#ifdef G4DEBUG_NAVIGATION
537 G4cout <<
" VoxSaf> No more candidates: nodeDown= " << nextDown
538 <<
" nodeUp= " << nextUp
539 <<
" lastSlice= " << targetHeaderNoSlices <<
G4endl;
546 distMaxInterest = std::min( minSafety, maxLength );
548 }
while ( nextIsInside && ( distAxis*distAxis + distUpperDepth_Sq
549 < distMaxInterest*distMaxInterest ) );
554 G4cout <<
" Ended for targetNodeNo -- checked " << checkedNum <<
" out of "
555 << targetHeaderNoSlices <<
" slices." <<
G4endl;
556 G4cout <<
" ===== Returning from SafetyForVoxelHeader "
557 <<
" Depth= " << fVoxelDepth <<
G4endl
G4DLLIMPORT std::ostream G4cout
void BlockVolume(const G4int v)
void Enlarge(const G4int nv)
G4bool IsBlocked(const G4int v) const
G4double GetSurfaceTolerance() const
static G4GeometryTolerance * GetInstance()
G4VSolid * GetSolid() const
G4int GetNoDaughters() const
G4VPhysicalVolume * GetDaughter(const G4int i) const
G4SmartVoxelHeader * GetVoxelHeader() const
G4int GetMaxEquivalentSliceNo() const
G4int GetNoContained() const
G4int GetVolume(G4int pVolumeNo) const
G4int GetMinEquivalentSliceNo() const
G4SmartVoxelNode * GetNode() const
G4SmartVoxelHeader * GetHeader() const
const G4RotationMatrix * GetRotation() const
G4LogicalVolume * GetLogicalVolume() const
virtual G4int GetCopyNo() const =0
const G4String & GetName() const
const G4ThreeVector & GetTranslation() const
virtual EInside Inside(const G4ThreeVector &p) const =0
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const =0
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
virtual G4GeometryType GetEntityType() const =0
G4double ComputeSafety(const G4ThreeVector &localPoint, const G4VPhysicalVolume ¤tPhysical, G4double maxLength=DBL_MAX)
G4double SafetyForVoxelHeader(const G4SmartVoxelHeader *pHead, const G4ThreeVector &localPoint, G4double maxLength, const G4VPhysicalVolume ¤tPhysical, G4double distUpperDepth=0.0, G4double previousMinSafety=DBL_MAX)
G4double SafetyForVoxelNode(const G4SmartVoxelNode *curVoxelNode, const G4ThreeVector &localPoint)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
std::ostringstream G4ExceptionDescription