Geant4  10.03
G4VoxelNavigation.icc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
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. *
10 // * *
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. *
17 // * *
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 // ********************************************************************
25 //
26 //
27 // $Id: G4VoxelNavigation.icc 80287 2014-04-10 09:49:49Z gcosmo $
28 //
29 //
30 // class G4VoxelNavigation Inline implementation
31 //
32 // --------------------------------------------------------------------
33 
34 // ********************************************************************
35 // VoxelLocate
36 // ********************************************************************
37 //
38 inline
39 G4SmartVoxelNode*
40 G4VoxelNavigation::VoxelLocate( G4SmartVoxelHeader* pHead,
41  const G4ThreeVector& localPoint )
42 {
43  G4SmartVoxelHeader *targetVoxelHeader=pHead;
44  G4SmartVoxelNode *targetVoxelNode=0;
45  G4SmartVoxelProxy *sampleProxy;
46  EAxis targetHeaderAxis;
47  G4double targetHeaderMin, targetHeaderNodeWidth;
48  G4int targetHeaderNoSlices, targetNodeNo;
49 
50  fVoxelDepth = 0;
51 
52  while ( !targetVoxelNode )
53  {
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
62  //
63  if ( targetNodeNo<0 )
64  {
65  targetNodeNo = 0;
66  }
67  else if ( targetNodeNo>=targetHeaderNoSlices )
68  {
69  targetNodeNo = targetHeaderNoSlices-1;
70  }
71  // Stack info for stepping
72  //
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);
79 
80  if ( sampleProxy->IsNode() )
81  {
82  targetVoxelNode = sampleProxy->GetNode();
83  }
84  else
85  {
86  targetVoxelHeader = sampleProxy->GetHeader();
87  fVoxelDepth++;
88  }
89  }
90  fVoxelNode = targetVoxelNode;
91  return targetVoxelNode;
92 }
93 
94 // ********************************************************************
95 // LevelLocate
96 // ********************************************************************
97 //
98 inline
99 G4bool
100 G4VoxelNavigation::LevelLocate( G4NavigationHistory& history,
101  const G4VPhysicalVolume* blockedVol,
102  const G4int,
103  const G4ThreeVector& globalPoint,
104  const G4ThreeVector* globalDirection,
105  const G4bool pLocatedOnEdge,
106  G4ThreeVector& localPoint )
107 {
108  G4SmartVoxelHeader *targetVoxelHeader;
109  G4SmartVoxelNode *targetVoxelNode;
110  G4VPhysicalVolume *targetPhysical, *samplePhysical;
111  G4LogicalVolume *targetLogical;
112  G4VSolid *sampleSolid;
113  G4ThreeVector samplePoint;
114  G4int targetNoDaughters;
115 
116  targetPhysical = history.GetTopVolume();
117  targetLogical = targetPhysical->GetLogicalVolume();
118  targetVoxelHeader = targetLogical->GetVoxelHeader();
119 
120  // Find the voxel containing the point
121  //
122  targetVoxelNode = VoxelLocate(targetVoxelHeader,localPoint);
123 
124  targetNoDaughters=targetVoxelNode->GetNoContained();
125  if ( targetNoDaughters==0 ) return false;
126 
127  //
128  // Search daughters in volume
129  //
130 
131  for ( G4int sampleNo=targetNoDaughters-1; sampleNo>=0; sampleNo-- )
132  {
133  samplePhysical = targetLogical->
134  GetDaughter(targetVoxelNode->GetVolume(sampleNo));
135  if ( samplePhysical!=blockedVol )
136  {
137  // Setup history
138  //
139  history.NewLevel(samplePhysical, kNormal, samplePhysical->GetCopyNo());
140  sampleSolid = samplePhysical->GetLogicalVolume()->GetSolid();
141  samplePoint = history.GetTopTransform().TransformPoint(globalPoint);
142 
143  if( G4AuxiliaryNavServices::CheckPointOnSurface(sampleSolid,
144  samplePoint,
145  globalDirection,
146  history.GetTopTransform(),
147  pLocatedOnEdge) )
148  {
149  // Enter this daughter
150  //
151  localPoint = samplePoint;
152  return true;
153  }
154  else
155  {
156  history.BackLevel();
157  }
158  }
159  }
160  return false;
161 }
162 
163 // ********************************************************************
164 // GetVerboseLevel
165 // ********************************************************************
166 //
167 inline
168 G4int G4VoxelNavigation::GetVerboseLevel() const
169 {
170  return fLogger->GetVerboseLevel();
171 }
172 
173 // ********************************************************************
174 // CheckMode
175 // ********************************************************************
176 //
177 inline
178 void G4VoxelNavigation::CheckMode(G4bool mode)
179 {
180  fCheck = mode;
181 }
182 
183 // ********************************************************************
184 // EnableBestSafety
185 // ********************************************************************
186 //
187 inline
188 void G4VoxelNavigation::EnableBestSafety(G4bool flag)
189 {
190  fBestSafety = flag;
191 }