55#ifdef G4DEBUG_NAVIGATION
90 const G4double currentProposedStepLength,
98 G4int& blockedReplicaNo )
104 G4double ourStep=currentProposedStepLength, ourSafety;
106 G4int localNoDaughters, sampleNo;
108 G4bool initialNode, noStep;
110 G4int curNoVolumes, contentNo;
113 motherPhysical =
history.GetTopVolume();
115 motherSolid = motherLogical->
GetSolid();
122 ourSafety = motherSafety;
137 if ( exiting && validExitNormal )
143 blockedExitedVol = *pBlockedPhysical;
151 G4bool motherValidExitNormal =
false;
162 &motherValidExitNormal,
179 for (contentNo=curNoVolumes-1; contentNo>=0; contentNo--)
181 sampleNo = curVoxelNode->
GetVolume(contentNo);
185 samplePhysical = motherLogical->
GetDaughter(sampleNo);
186 if ( samplePhysical!=blockedExitedVol )
198 if ( sampleSafety<ourSafety )
200 ourSafety = sampleSafety;
202 if ( sampleSafety<=ourStep )
206 sampleSolid->
DistanceToIn(samplePoint, sampleDirection);
212 sampleDirection, sampleStep);
215 if ( sampleStep<=ourStep )
217 ourStep = sampleStep;
220 *pBlockedPhysical = samplePhysical;
221 blockedReplicaNo = -1;
228 sampleDirection, localDirection, sampleSafety, sampleStep);
234 && ( sampleStep >= motherStep ) )
239 samplePoint, sampleDirection,
241 localPoint, localDirection,
242 motherStep, sampleStep);
264 if ( voxelSafety<ourSafety )
266 ourSafety = voxelSafety;
268 if ( currentProposedStepLength<ourSafety )
275 *pBlockedPhysical =
nullptr;
283 if ( motherSafety<=ourStep )
286 motherStep = motherSolid->
DistanceToOut(localPoint, localDirection,
287 true, &motherValidExitNormal, &motherExitNormal);
292 motherStep, motherSafety);
293 if( motherValidExitNormal )
296 localPoint, localDirection,
297 motherStep, motherSolid,
298 "From motherSolid::DistanceToOut" );
302 if( (motherStep >=
kInfinity) || (motherStep < 0.0) )
320 validExitNormal=
false;
322 *pBlockedPhysical =
nullptr;
323 blockedReplicaNo = 0;
329 if ( motherStep<=ourStep )
331 ourStep = motherStep;
337 validExitNormal = motherValidExitNormal;
338 exitNormal = motherExitNormal;
340 if ( validExitNormal )
351 "From RotationMatrix" );
358 validExitNormal =
false;
362 newSafety = ourSafety;
387 G4double curNodeOffset, minCurCommonDelta, maxCurCommonDelta;
388 G4int minCurNodeNoDelta, maxCurNodeNoDelta;
389 G4int localVoxelDepth, curNodeNo;
402 curNodeOffset = curNodeNo*curNodeWidth;
405 minCurCommonDelta = localPoint(curHeaderAxis)
407 maxCurCommonDelta = curNodeWidth-minCurCommonDelta;
409 if ( minCurNodeNoDelta<maxCurNodeNoDelta )
411 voxelSafety = minCurNodeNoDelta*curNodeWidth;
412 voxelSafety += minCurCommonDelta;
414 else if (maxCurNodeNoDelta < minCurNodeNoDelta)
416 voxelSafety = maxCurNodeNoDelta*curNodeWidth;
417 voxelSafety += maxCurCommonDelta;
421 voxelSafety = minCurNodeNoDelta*curNodeWidth;
422 voxelSafety +=
std::min(minCurCommonDelta,maxCurCommonDelta);
429 while ( (localVoxelDepth>0) && (voxelSafety>0) )
436 curNodeOffset = curNodeNo*curNodeWidth;
437 minCurCommonDelta = localPoint(curHeaderAxis)
439 maxCurCommonDelta = curNodeWidth-minCurCommonDelta;
441 if ( minCurCommonDelta<voxelSafety )
443 voxelSafety = minCurCommonDelta;
445 if ( maxCurCommonDelta<voxelSafety )
447 voxelSafety = maxCurCommonDelta;
480 G4double workNodeWidth, workMinExtent, workCoord;
481 G4double minVal, maxVal, newDistance=0.;
482 G4double newHeaderMin, newHeaderNodeWidth;
483 G4int depth=0, newDepth=0, workNodeNo=0, newNodeNo=0, newHeaderNoSlices=0;
484 EAxis workHeaderAxis, newHeaderAxis;
485 G4bool isNewVoxel =
false;
487 G4double currentDistance = currentStep;
493 targetPoint = localPoint+localDirection*currentDistance;
494 newDistance = currentDistance;
500 workCoord = targetPoint(workHeaderAxis);
501 minVal = workMinExtent+workNodeNo*workNodeWidth;
505 maxVal = minVal+workNodeWidth;
510 newNodeNo = workNodeNo+1;
511 newHeader = workHeader;
512 newDistance = (maxVal-localPoint(workHeaderAxis))
513 / localDirection(workHeaderAxis);
520 newNodeNo = workNodeNo-1;
521 newHeader = workHeader;
522 newDistance = (minVal-localPoint(workHeaderAxis))
523 / localDirection(workHeaderAxis);
527 currentDistance = newDistance;
529 targetPoint = localPoint+localDirection*currentDistance;
540 workCoord = targetPoint(workHeaderAxis);
550 newHeader = workHeader;
551 newDistance = (maxVal-localPoint(workHeaderAxis))
552 / localDirection(workHeaderAxis);
560 newHeader = workHeader;
561 newDistance = (minVal-localPoint(workHeaderAxis))
562 / localDirection(workHeaderAxis);
566 currentDistance = newDistance;
577 if ( (newNodeNo<0) || (newNodeNo>=
G4int(newHeader->GetNoSlices())))
588 voxelPoint = localPoint+localDirection*newDistance;
592 while ( !newVoxelNode )
594 newProxy = newHeader->GetSlice(newNodeNo);
597 newVoxelNode = newProxy->
GetNode();
603 newHeaderAxis = newHeader->
GetAxis();
604 newHeaderNoSlices = newHeader->GetNoSlices();
605 newHeaderMin = newHeader->GetMinExtent();
606 newHeaderNodeWidth = (newHeader->GetMaxExtent()-newHeaderMin)
608 newNodeNo =
G4int( (voxelPoint(newHeaderAxis)-newHeaderMin)
609 / newHeaderNodeWidth );
616 else if ( newNodeNo>=newHeaderNoSlices )
618 newNodeNo = newHeaderNoSlices-1;
654 G4int curNoVolumes, contentNo;
657 motherPhysical =
history.GetTopVolume();
659 motherSolid = motherLogical->
GetSolid();
671 ourSafety = motherSafety;
673 if( motherSafety == 0.0 )
675#ifdef G4DEBUG_NAVIGATION
682 message <<
"Safety method called for location outside current Volume." <<
G4endl
683 <<
"Location for safety is Outside this volume. " <<
G4endl
684 <<
"The approximate distance to the solid "
685 <<
"(safety from outside) is: "
687 message <<
" Problem occurred with physical volume: "
688 <<
" Name: " << motherPhysical->
GetName()
690 <<
" Local Point = " << localPoint <<
G4endl;
691 message <<
" Description of solid: " <<
G4endl
692 << *motherSolid <<
G4endl;
693 G4Exception(
"G4VoxelNavigation::ComputeSafety()",
"GeomNav0003",
704 messageIn <<
" Point is Inside, but safety is Zero ." <<
G4endl;
705 messageIn <<
" Inexact safety for volume " << motherPhysical->
GetName() <<
G4endl
706 <<
" Solid: Name= " << motherSolid->
GetName()
708 messageIn <<
" Local point= " << localPoint <<
G4endl;
709 messageIn <<
" Solid parameters: " <<
G4endl << *motherSolid <<
G4endl;
710 G4Exception(
"G4VoxelNavigation::ComputeSafety()",
"GeomNav0003",
732 for ( contentNo=curNoVolumes-1; contentNo>=0; contentNo-- )
734 sampleNo = curVoxelNode->
GetVolume(contentNo);
735 samplePhysical = motherLogical->
GetDaughter(sampleNo);
743 if ( sampleSafety<ourSafety )
745 ourSafety = sampleSafety;
751 sampleSafety,
false,
false);
756 if ( voxelSafety<ourSafety )
758 ourSafety = voxelSafety;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
CLHEP::Hep3Vector G4ThreeVector
double dot(const Hep3Vector &) const
HepRotation inverse() const
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
size_t GetNoDaughters() const
G4VPhysicalVolume * GetDaughter(const G4int i) const
void SetVerboseLevel(G4int level)
void PreComputeStepLog(const G4VPhysicalVolume *motherPhysical, G4double motherSafety, const G4ThreeVector &localPoint) const
void CheckDaughterEntryPoint(const G4VSolid *sampleSolid, const G4ThreeVector &samplePoint, const G4ThreeVector &sampleDirection, const G4VSolid *motherSolid, const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, G4double motherStep, G4double sampleStep) const
void PrintDaughterLog(const G4VSolid *sampleSolid, const G4ThreeVector &samplePoint, G4double sampleSafety, G4bool onlySafety, const G4ThreeVector &sampleDirection, G4double sampleStep) const
G4bool CheckAndReportBadNormal(const G4ThreeVector &unitNormal, const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, G4double step, const G4VSolid *solid, const char *msg) const
void ComputeSafetyLog(const G4VSolid *solid, const G4ThreeVector &point, G4double safety, G4bool isMotherVolume, G4int banner=-1) const
void PostComputeStepLog(const G4VSolid *motherSolid, const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, G4double motherStep, G4double motherSafety) const
void ReportOutsideMother(const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, const G4VPhysicalVolume *motherPV, G4double tDist=30.0 *CLHEP::cm) const
void AlongComputeStepLog(const G4VSolid *sampleSolid, const G4ThreeVector &samplePoint, const G4ThreeVector &sampleDirection, const G4ThreeVector &localDirection, G4double sampleSafety, G4double sampleStep) const
G4int GetMaxEquivalentSliceNo() const
G4int GetVolume(G4int pVolumeNo) const
std::size_t GetNoContained() const
G4int GetMinEquivalentSliceNo() const
G4SmartVoxelNode * GetNode() const
G4SmartVoxelHeader * GetHeader() const
const G4RotationMatrix * GetRotation() const
const G4ThreeVector GetTranslation() const
G4LogicalVolume * GetLogicalVolume() const
virtual G4int GetCopyNo() const =0
const G4String & GetName() const
virtual EInside Inside(const G4ThreeVector &p) const =0
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const =0
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
virtual G4GeometryType GetEntityType() const =0
G4NavigationLogger * fLogger
virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4NavigationHistory &history, const G4double pMaxLength=DBL_MAX)
virtual G4double ComputeStep(const G4ThreeVector &globalPoint, const G4ThreeVector &globalDirection, const G4double currentProposedStepLength, G4double &newSafety, G4NavigationHistory &history, G4bool &validExitNormal, G4ThreeVector &exitNormal, G4bool &exiting, G4bool &entering, G4VPhysicalVolume *(*pBlockedPhysical), G4int &blockedReplicaNo)
std::vector< G4double > fVoxelSliceWidthStack
std::vector< EAxis > fVoxelAxisStack
G4VoxelSafety * fpVoxelSafety
G4SmartVoxelNode * fVoxelNode
G4bool LocateNextVoxel(const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, const G4double currentStep)
virtual ~G4VoxelNavigation()
std::vector< G4int > fVoxelNodeNoStack
std::vector< G4SmartVoxelHeader * > fVoxelHeaderStack
std::vector< G4int > fVoxelNoSlicesStack
G4double ComputeVoxelSafety(const G4ThreeVector &localPoint) const
void SetVerboseLevel(G4int level)
void SetVerboseLevel(G4int level)
G4double ComputeSafety(const G4ThreeVector &localPoint, const G4VPhysicalVolume ¤tPhysical, G4double maxLength=DBL_MAX)
static const G4int kNavigatorVoxelStackMax
static const double kMinExitingNormalCosine
static const G4double kInfinity
T min(const T t1, const T t2)
brief Return the smallest of the two arguments