2 // ********************************************************************
3 // * License and Disclaimer *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
27 // $Id: G4VoxelNavigation.icc 80287 2014-04-10 09:49:49Z gcosmo $
30 // class G4VoxelNavigation Inline implementation
32 // --------------------------------------------------------------------
34 // ********************************************************************
36 // ********************************************************************
40 G4VoxelNavigation::VoxelLocate( G4SmartVoxelHeader* pHead,
41 const G4ThreeVector& localPoint )
43 G4SmartVoxelHeader *targetVoxelHeader=pHead;
44 G4SmartVoxelNode *targetVoxelNode=0;
45 G4SmartVoxelProxy *sampleProxy;
46 EAxis targetHeaderAxis;
47 G4double targetHeaderMin, targetHeaderNodeWidth;
48 G4int targetHeaderNoSlices, targetNodeNo;
52 while ( !targetVoxelNode )
54 targetHeaderAxis = targetVoxelHeader->GetAxis();
55 targetHeaderNoSlices = targetVoxelHeader->GetNoSlices();
56 targetHeaderMin = targetVoxelHeader->GetMinExtent();
57 targetHeaderNodeWidth = (targetVoxelHeader->GetMaxExtent()-targetHeaderMin)
58 / targetHeaderNoSlices;
59 targetNodeNo = G4int( (localPoint(targetHeaderAxis)-targetHeaderMin)
60 / targetHeaderNodeWidth);
61 // Rounding protection
67 else if ( targetNodeNo>=targetHeaderNoSlices )
69 targetNodeNo = targetHeaderNoSlices-1;
71 // Stack info for stepping
73 fVoxelAxisStack[fVoxelDepth] = targetHeaderAxis;
74 fVoxelNoSlicesStack[fVoxelDepth] = targetHeaderNoSlices;
75 fVoxelSliceWidthStack[fVoxelDepth] = targetHeaderNodeWidth;
76 fVoxelNodeNoStack[fVoxelDepth] = targetNodeNo;
77 fVoxelHeaderStack[fVoxelDepth] = targetVoxelHeader;
78 sampleProxy = targetVoxelHeader->GetSlice(targetNodeNo);
80 if ( sampleProxy->IsNode() )
82 targetVoxelNode = sampleProxy->GetNode();
86 targetVoxelHeader = sampleProxy->GetHeader();
90 fVoxelNode = targetVoxelNode;
91 return targetVoxelNode;
94 // ********************************************************************
96 // ********************************************************************
100 G4VoxelNavigation::LevelLocate( G4NavigationHistory& history,
101 const G4VPhysicalVolume* blockedVol,
103 const G4ThreeVector& globalPoint,
104 const G4ThreeVector* globalDirection,
105 const G4bool pLocatedOnEdge,
106 G4ThreeVector& localPoint )
108 G4SmartVoxelHeader *targetVoxelHeader;
109 G4SmartVoxelNode *targetVoxelNode;
110 G4VPhysicalVolume *targetPhysical, *samplePhysical;
111 G4LogicalVolume *targetLogical;
112 G4VSolid *sampleSolid;
113 G4ThreeVector samplePoint;
114 G4int targetNoDaughters;
116 targetPhysical = history.GetTopVolume();
117 targetLogical = targetPhysical->GetLogicalVolume();
118 targetVoxelHeader = targetLogical->GetVoxelHeader();
120 // Find the voxel containing the point
122 targetVoxelNode = VoxelLocate(targetVoxelHeader,localPoint);
124 targetNoDaughters=targetVoxelNode->GetNoContained();
125 if ( targetNoDaughters==0 ) return false;
128 // Search daughters in volume
131 for ( G4int sampleNo=targetNoDaughters-1; sampleNo>=0; sampleNo-- )
133 samplePhysical = targetLogical->
134 GetDaughter(targetVoxelNode->GetVolume(sampleNo));
135 if ( samplePhysical!=blockedVol )
139 history.NewLevel(samplePhysical, kNormal, samplePhysical->GetCopyNo());
140 sampleSolid = samplePhysical->GetLogicalVolume()->GetSolid();
141 samplePoint = history.GetTopTransform().TransformPoint(globalPoint);
143 if( G4AuxiliaryNavServices::CheckPointOnSurface(sampleSolid,
146 history.GetTopTransform(),
149 // Enter this daughter
151 localPoint = samplePoint;
163 // ********************************************************************
165 // ********************************************************************
168 G4int G4VoxelNavigation::GetVerboseLevel() const
170 return fLogger->GetVerboseLevel();
173 // ********************************************************************
175 // ********************************************************************
178 void G4VoxelNavigation::CheckMode(G4bool mode)
183 // ********************************************************************
185 // ********************************************************************
188 void G4VoxelNavigation::EnableBestSafety(G4bool flag)