Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/geometry/navigation/src/G4VoxelNavigation.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /geometry/navigation/src/G4VoxelNavigation.cc (Version 11.3.0) and /geometry/navigation/src/G4VoxelNavigation.cc (Version 6.1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
 25 //                                                 22 //
                                                   >>  23 //
                                                   >>  24 // $Id: G4VoxelNavigation.cc,v 1.3 2004/03/10 18:21:20 gcosmo Exp $
                                                   >>  25 // GEANT4 tag $Name: geant4-06-01 $
                                                   >>  26 //
                                                   >>  27 //
 26 // class G4VoxelNavigation Implementation          28 // class G4VoxelNavigation Implementation
 27 //                                                 29 //
 28 // Author: P.Kent, 1996                            30 // Author: P.Kent, 1996
 29 //                                                 31 //
 30 // -------------------------------------------     32 // --------------------------------------------------------------------
 31 #include "G4VoxelNavigation.hh"                << 
 32 #include "G4GeometryTolerance.hh"              << 
 33 #include "G4VoxelSafety.hh"                    << 
 34                                                    33 
 35 #include "G4AuxiliaryNavServices.hh"           <<  34 #include "G4VoxelNavigation.hh"
 36                                                << 
 37 #include <cassert>                             << 
 38 #include <ostream>                             << 
 39                                                    35 
 40 // *******************************************     36 // ********************************************************************
 41 // Constructor                                     37 // Constructor
 42 // *******************************************     38 // ********************************************************************
 43 //                                                 39 //
 44 G4VoxelNavigation::G4VoxelNavigation()             40 G4VoxelNavigation::G4VoxelNavigation()
 45   : fVoxelAxisStack(kNavigatorVoxelStackMax,kX <<  41   : fVoxelDepth(-1),
                                                   >>  42     fVoxelAxisStack(kNavigatorVoxelStackMax,kXAxis),
 46     fVoxelNoSlicesStack(kNavigatorVoxelStackMa     43     fVoxelNoSlicesStack(kNavigatorVoxelStackMax,0),
 47     fVoxelSliceWidthStack(kNavigatorVoxelStack     44     fVoxelSliceWidthStack(kNavigatorVoxelStackMax,0.),
 48     fVoxelNodeNoStack(kNavigatorVoxelStackMax,     45     fVoxelNodeNoStack(kNavigatorVoxelStackMax,0),
 49     fVoxelHeaderStack(kNavigatorVoxelStackMax, <<  46     fVoxelHeaderStack(kNavigatorVoxelStackMax,(G4SmartVoxelHeader*)0),
                                                   >>  47     fVoxelNode(0),
                                                   >>  48     fCheck(false),
                                                   >>  49     fVerbose(0)
 50 {                                                  50 {
 51   fLogger= new G4NavigationLogger("G4VoxelNavi << 
 52   fpVoxelSafety= new G4VoxelSafety();          << 
 53   fHalfTolerance= 0.5*G4GeometryTolerance::Get << 
 54                                                << 
 55 #ifdef G4DEBUG_NAVIGATION                      << 
 56   SetVerboseLevel(5);   // Reports most about  << 
 57 #endif                                         << 
 58 }                                                  51 }
 59                                                    52 
 60 // *******************************************     53 // ********************************************************************
 61 // Destructor                                      54 // Destructor
 62 // *******************************************     55 // ********************************************************************
 63 //                                                 56 //
 64 G4VoxelNavigation::~G4VoxelNavigation()            57 G4VoxelNavigation::~G4VoxelNavigation()
 65 {                                                  58 {
 66   delete fpVoxelSafety;                        <<  59 #ifdef G4DEBUG_NAVIGATION
 67   delete fLogger;                              <<  60   G4cout << "G4VoxelNavigation::~G4VoxelNavigation() called." << G4endl;
                                                   >>  61 #endif
 68 }                                                  62 }
 69                                                    63 
 70 // ------------------------------------------- << 
 71 // Input:                                      << 
 72 //    exiting:         : last step exited      << 
 73 //    blockedPhysical  : phys volume last exit << 
 74 //    blockedReplicaNo : copy/replica number o << 
 75 // Output:                                     << 
 76 //    entering         : if true, found candid << 
 77 //    blockedPhysical  : candidate phys volume << 
 78 //    blockedReplicaNo : copy/replica number   << 
 79 //    exiting:         : will exit current (mo << 
 80 // In/Out                                      << 
 81 // ------------------------------------------- << 
 82                                                << 
 83 // *******************************************     64 // ********************************************************************
 84 // ComputeStep                                     65 // ComputeStep
 85 // *******************************************     66 // ********************************************************************
 86 //                                                 67 //
 87 G4double                                           68 G4double
 88 G4VoxelNavigation::ComputeStep( const G4ThreeV     69 G4VoxelNavigation::ComputeStep( const G4ThreeVector& localPoint,
 89                                 const G4ThreeV     70                                 const G4ThreeVector& localDirection,
 90                                 const G4double     71                                 const G4double currentProposedStepLength,
 91                                       G4double     72                                       G4double& newSafety,
 92                           /* const */ G4Naviga <<  73                                       G4NavigationHistory& history,
 93                                       G4bool&      74                                       G4bool& validExitNormal,
 94                                       G4ThreeV     75                                       G4ThreeVector& exitNormal,
 95                                       G4bool&      76                                       G4bool& exiting,
 96                                       G4bool&      77                                       G4bool& entering,
 97                                       G4VPhysi <<  78                                       G4VPhysicalVolume *(*pBlockedPhysical),
 98                                       G4int& b     79                                       G4int& blockedReplicaNo )
 99 {                                                  80 {
100   G4VPhysicalVolume *motherPhysical, *samplePh <<  81   G4VPhysicalVolume *motherPhysical, *samplePhysical, *blockedExitedVol=0;
101   G4LogicalVolume *motherLogical;                  82   G4LogicalVolume *motherLogical;
102   G4VSolid *motherSolid;                           83   G4VSolid *motherSolid;
103   G4ThreeVector sampleDirection;                   84   G4ThreeVector sampleDirection;
104   G4double ourStep=currentProposedStepLength,  <<  85   G4double ourStep=currentProposedStepLength, motherSafety, ourSafety;
105   G4double motherSafety, motherStep = DBL_MAX; << 
106   G4int localNoDaughters, sampleNo;                86   G4int localNoDaughters, sampleNo;
107                                                    87 
108   G4bool initialNode, noStep;                      88   G4bool initialNode, noStep;
109   G4SmartVoxelNode *curVoxelNode;                  89   G4SmartVoxelNode *curVoxelNode;
110   G4long curNoVolumes, contentNo;              <<  90   G4int curNoVolumes, contentNo;
111   G4double voxelSafety;                            91   G4double voxelSafety;
112                                                    92 
113   motherPhysical = history.GetTopVolume();         93   motherPhysical = history.GetTopVolume();
114   motherLogical = motherPhysical->GetLogicalVo     94   motherLogical = motherPhysical->GetLogicalVolume();
115   motherSolid = motherLogical->GetSolid();         95   motherSolid = motherLogical->GetSolid();
116                                                    96 
117   //                                               97   //
118   // Compute mother safety                         98   // Compute mother safety
119   //                                               99   //
120                                                   100 
121   motherSafety = motherSolid->DistanceToOut(lo    101   motherSafety = motherSolid->DistanceToOut(localPoint);
122   ourSafety = motherSafety;                 //    102   ourSafety = motherSafety;                 // Working isotropic safety
123                                                   103   
124 #ifdef G4VERBOSE                                  104 #ifdef G4VERBOSE
125   if ( fCheck )                                   105   if ( fCheck )
126   {                                               106   {
127     fLogger->PreComputeStepLog (motherPhysical << 107     if( motherSafety < 0.0 )
                                                   >> 108     {
                                                   >> 109       G4cout << "ERROR - G4VoxelNavigation::ComputeStep()" << G4endl
                                                   >> 110              << "        Current solid " << motherSolid->GetName()
                                                   >> 111              << " gave negative safety: " << motherSafety << G4endl
                                                   >> 112              << "        for the current (local) point " << localPoint
                                                   >> 113              << G4endl;
                                                   >> 114       G4Exception("G4VoxelNavigation::ComputeStep()",
                                                   >> 115                   "NegativeSafetyMotherVol", FatalException,
                                                   >> 116                   "Negative Safety In Voxel Navigation !" ); 
                                                   >> 117     }
                                                   >> 118     if( motherSolid->Inside(localPoint)==kOutside )
                                                   >> 119     { 
                                                   >> 120       G4cout << "WARNING - G4VoxelNavigation::ComputeStep()" << G4endl
                                                   >> 121              << "          Point " << localPoint
                                                   >> 122              << " is outside current volume " << motherPhysical->GetName()
                                                   >> 123              << G4endl;
                                                   >> 124       G4double  estDistToSolid= motherSolid->DistanceToIn(localPoint); 
                                                   >> 125       G4cout << "          Estimated isotropic distance to solid (distToIn)= " 
                                                   >> 126              << estDistToSolid << G4endl;
                                                   >> 127       if( estDistToSolid > 100.0 * kCarTolerance ) 
                                                   >> 128         G4Exception("G4VoxelNavigation::ComputeStep()",
                                                   >> 129                     "FarOutsideCurrentVolume", FatalException,
                                                   >> 130                     "Point is far outside Current Volume !"); 
                                                   >> 131       else
                                                   >> 132         G4Exception("G4VoxelNavigation::ComputeStep()", "OutsideCurrentVolume", 
                                                   >> 133                     JustWarning, "Point is a little outside Current Volume."); 
                                                   >> 134     }
128   }                                               135   }
129 #endif                                            136 #endif
130                                                   137 
131   //                                              138   //
132   // Compute daughter safeties & intersections    139   // Compute daughter safeties & intersections
133   //                                              140   //
134                                                   141 
135   // Exiting normal optimisation                  142   // Exiting normal optimisation
136   //                                              143   //
137   if ( exiting && validExitNormal )               144   if ( exiting && validExitNormal )
138   {                                               145   {
139     if ( localDirection.dot(exitNormal)>=kMinE    146     if ( localDirection.dot(exitNormal)>=kMinExitingNormalCosine )
140     {                                             147     {
141       // Block exited daughter volume             148       // Block exited daughter volume
142       //                                          149       //
143       blockedExitedVol = *pBlockedPhysical;       150       blockedExitedVol = *pBlockedPhysical;
144       ourSafety = 0;                              151       ourSafety = 0;
145     }                                             152     }
146   }                                               153   }
147   exiting = false;                                154   exiting = false;
148   entering = false;                               155   entering = false;
149                                                   156 
150   // For extra checking,  get the distance to  << 157   localNoDaughters = motherLogical->GetNoDaughters();
151   G4bool motherValidExitNormal = false;        << 
152   G4ThreeVector motherExitNormal(0.0, 0.0, 0.0 << 
153                                                << 
154 #ifdef G4VERBOSE                               << 
155   if ( fCheck )                                << 
156   {                                            << 
157     // Compute early -- a) for validity        << 
158     //                  b) to check against an << 
159     motherStep = motherSolid->DistanceToOut(lo << 
160                                             lo << 
161                                             tr << 
162                                            &mo << 
163                                            &mo << 
164   }                                            << 
165 #endif                                         << 
166                                                << 
167   localNoDaughters = (G4int)motherLogical->Get << 
168                                                   158 
169   fBList.Enlarge(localNoDaughters);               159   fBList.Enlarge(localNoDaughters);
170   fBList.Reset();                                 160   fBList.Reset();
171                                                   161 
172   initialNode = true;                             162   initialNode = true;
173   noStep = true;                                  163   noStep = true;
174                                                   164 
175   while (noStep)                                  165   while (noStep)
176   {                                               166   {
177     curVoxelNode = fVoxelNode;                    167     curVoxelNode = fVoxelNode;
178     curNoVolumes = curVoxelNode->GetNoContaine    168     curNoVolumes = curVoxelNode->GetNoContained();
179     for (contentNo=curNoVolumes-1; contentNo>=    169     for (contentNo=curNoVolumes-1; contentNo>=0; contentNo--)
180     {                                             170     {
181       sampleNo = curVoxelNode->GetVolume((G4in << 171       sampleNo = curVoxelNode->GetVolume(contentNo);
182       if ( !fBList.IsBlocked(sampleNo) )          172       if ( !fBList.IsBlocked(sampleNo) )
183       {                                           173       {
184         fBList.BlockVolume(sampleNo);             174         fBList.BlockVolume(sampleNo);
185         samplePhysical = motherLogical->GetDau    175         samplePhysical = motherLogical->GetDaughter(sampleNo);
186         if ( samplePhysical!=blockedExitedVol     176         if ( samplePhysical!=blockedExitedVol )
187         {                                         177         {
188           G4AffineTransform sampleTf(samplePhy    178           G4AffineTransform sampleTf(samplePhysical->GetRotation(),
189                                      samplePhy    179                                      samplePhysical->GetTranslation());
190           sampleTf.Invert();                      180           sampleTf.Invert();
191           const G4ThreeVector samplePoint =       181           const G4ThreeVector samplePoint =
192                      sampleTf.TransformPoint(l    182                      sampleTf.TransformPoint(localPoint);
193           const G4VSolid *sampleSolid     =       183           const G4VSolid *sampleSolid     =
194                      samplePhysical->GetLogica    184                      samplePhysical->GetLogicalVolume()->GetSolid();
195           const G4double sampleSafety     =       185           const G4double sampleSafety     =
196                      sampleSolid->DistanceToIn    186                      sampleSolid->DistanceToIn(samplePoint);
197                                                << 
198           if ( sampleSafety<ourSafety )           187           if ( sampleSafety<ourSafety )
199           {                                       188           {
200             ourSafety = sampleSafety;             189             ourSafety = sampleSafety;
201           }                                       190           }
202           if ( sampleSafety<=ourStep )            191           if ( sampleSafety<=ourStep )
203           {                                       192           {
204             sampleDirection = sampleTf.Transfo    193             sampleDirection = sampleTf.TransformAxis(localDirection);
205             G4double sampleStep =                 194             G4double sampleStep =
206                      sampleSolid->DistanceToIn    195                      sampleSolid->DistanceToIn(samplePoint, sampleDirection);
207 #ifdef G4VERBOSE                               << 
208             if( fCheck )                       << 
209             {                                  << 
210               fLogger->PrintDaughterLog(sample << 
211                                         sample << 
212                                         sample << 
213             }                                  << 
214 #endif                                         << 
215             if ( sampleStep<=ourStep )            196             if ( sampleStep<=ourStep )
216             {                                     197             {
217               ourStep = sampleStep;               198               ourStep = sampleStep;
218               entering = true;                    199               entering = true;
219               exiting = false;                    200               exiting = false;
220               *pBlockedPhysical = samplePhysic    201               *pBlockedPhysical = samplePhysical;
221               blockedReplicaNo = -1;              202               blockedReplicaNo = -1;
222 #ifdef G4VERBOSE                                  203 #ifdef G4VERBOSE
223               // Check to see that the resulti    204               // Check to see that the resulting point is indeed in/on volume.
224               // This could be done only for s << 205               // This check could eventually be made only for successful
225               if ( fCheck )                    << 206               // candidate.
                                                   >> 207 
                                                   >> 208               if ( ( fCheck ) && ( sampleStep < kInfinity ) )
226               {                                   209               {
227                 fLogger->AlongComputeStepLog ( << 210                 G4ThreeVector intersectionPoint;
228                   sampleDirection, localDirect << 211                 intersectionPoint= samplePoint + sampleStep * sampleDirection;
                                                   >> 212                 EInside insideIntPt= sampleSolid->Inside(intersectionPoint); 
                                                   >> 213                 if( insideIntPt != kSurface )
                                                   >> 214                 {
                                                   >> 215                   G4int oldcoutPrec = G4cout.precision(16); 
                                                   >> 216                   G4cout << "WARNING - G4VoxelNavigation::ComputeStep()"
                                                   >> 217                          << G4endl
                                                   >> 218                          << "          Inaccurate solid DistanceToIn"
                                                   >> 219                          << " for solid " << sampleSolid->GetName() << G4endl;
                                                   >> 220                   G4cout << "          Solid gave DistanceToIn = "
                                                   >> 221                          << sampleStep << " yet returns " ;
                                                   >> 222                   if( insideIntPt == kInside )
                                                   >> 223                     G4cout << "-kInside-"; 
                                                   >> 224                   else if( insideIntPt == kOutside )
                                                   >> 225                     G4cout << "-kOutside-";
                                                   >> 226                   else
                                                   >> 227                     G4cout << "-kSurface-"; 
                                                   >> 228                   G4cout << " for this point !" << G4endl; 
                                                   >> 229                   G4cout << "          Point = " << intersectionPoint << G4endl;
                                                   >> 230                   if ( insideIntPt != kInside )
                                                   >> 231                     G4cout << "        DistanceToIn(p) = " 
                                                   >> 232                            << sampleSolid->DistanceToIn(intersectionPoint)
                                                   >> 233                            << G4endl;
                                                   >> 234                   if ( insideIntPt != kOutside ) 
                                                   >> 235                     G4cout << "        DistanceToOut(p) = " 
                                                   >> 236                            << sampleSolid->DistanceToOut(intersectionPoint)
                                                   >> 237                            << G4endl;
                                                   >> 238                   G4Exception("G4VoxelNavigation::ComputeStep()", 
                                                   >> 239                               "InaccurateDistanceToIn", JustWarning,
                                                   >> 240                               "Navigator gets conflicting response from Solid.");
                                                   >> 241                   G4cout.precision(oldcoutPrec);
                                                   >> 242                 }
229               }                                   243               }
230 #endif                                            244 #endif
231             }                                     245             }
232 #ifdef G4VERBOSE                               << 
233             if ( fCheck && ( sampleStep < kInf << 
234                         && ( sampleStep >= mot << 
235             {                                  << 
236                // The intersection point with  << 
237                // point from the mother volume << 
238                fLogger->CheckDaughterEntryPoin << 
239                                                << 
240                                                << 
241                                                << 
242                                                << 
243             }                                  << 
244 #endif                                         << 
245           }                                    << 
246 #ifdef G4VERBOSE                               << 
247           else // ie if sampleSafety > outStep << 
248           {                                    << 
249             if( fCheck )                       << 
250             {                                  << 
251               fLogger->PrintDaughterLog(sample << 
252                                         sample << 
253                                         G4Thre << 
254             }                                  << 
255           }                                       246           }
256 #endif                                         << 
257         }                                         247         }
258       }                                           248       }
259     }                                             249     }
260     if (initialNode)                              250     if (initialNode)
261     {                                             251     {
262       initialNode = false;                        252       initialNode = false;
263       voxelSafety = ComputeVoxelSafety(localPo    253       voxelSafety = ComputeVoxelSafety(localPoint);
264       if ( voxelSafety<ourSafety )                254       if ( voxelSafety<ourSafety )
265       {                                           255       {
266         ourSafety = voxelSafety;                  256         ourSafety = voxelSafety;
267       }                                           257       }
268       if ( currentProposedStepLength<ourSafety    258       if ( currentProposedStepLength<ourSafety )
269       {                                           259       {
270         // Guaranteed physics limited             260         // Guaranteed physics limited
271         //                                        261         //      
272         noStep = false;                           262         noStep = false;
273         entering = false;                         263         entering = false;
274         exiting = false;                          264         exiting = false;
275         *pBlockedPhysical = nullptr;           << 265         *pBlockedPhysical = 0;
276         ourStep = kInfinity;                      266         ourStep = kInfinity;
277       }                                           267       }
278       else                                        268       else
279       {                                           269       {
280         //                                        270         //
281         // Compute mother intersection if requ    271         // Compute mother intersection if required
282         //                                        272         //
283         if ( motherSafety<=ourStep )              273         if ( motherSafety<=ourStep )
284         {                                         274         {
285           // In case of check mode this is a d << 275           G4double motherStep =
286           motherStep = motherSolid->DistanceTo << 276               motherSolid->DistanceToOut(localPoint,
287                               true, &motherVal << 277                                          localDirection,
288 #ifdef G4VERBOSE                               << 278                                          true, &validExitNormal, &exitNormal);
289           if ( fCheck )                        << 
290           {                                    << 
291             fLogger->PostComputeStepLog(mother << 
292                                         mother << 
293             if( motherValidExitNormal )        << 
294             {                                  << 
295               fLogger->CheckAndReportBadNormal << 
296                                                << 
297                                                << 
298                                         "From  << 
299             }                                  << 
300           }                                    << 
301 #endif                                         << 
302           if( (motherStep >= kInfinity) || (mo << 
303           {                                    << 
304 #ifdef G4VERBOSE                                  279 #ifdef G4VERBOSE
305             if( fCheck ) // Error - indication << 280           if ( fCheck ) 
                                                   >> 281             if( ( motherStep < 0.0 ) || ( motherStep >= kInfinity) )
306             {                                     282             {
307               fLogger->ReportOutsideMother(loc << 283               G4int oldPrOut= G4cout.precision(16); 
308                                            mot << 284               G4int oldPrErr= G4cerr.precision(16);
                                                   >> 285               G4cerr << "ERROR - G4VoxelNavigation::ComputeStep()" << G4endl
                                                   >> 286                      << "        Problem in Navigation"  << G4endl
                                                   >> 287                      << "        Point (local coordinates): "
                                                   >> 288                      << localPoint << G4endl
                                                   >> 289                      << "        Local Direction: " << localDirection << G4endl
                                                   >> 290                      << "        Solid: " << motherSolid->GetName() << G4endl; 
                                                   >> 291               G4Exception("G4VoxelNavigation::ComputeStep()",
                                                   >> 292                           "PointOutsideCurrentVolume", FatalException,
                                                   >> 293                           "Current point is outside the current solid !");
                                                   >> 294               G4cout.precision(oldPrOut);
                                                   >> 295               G4cerr.precision(oldPrErr);
309             }                                     296             }
310 #endif                                            297 #endif
311             motherStep = 0.0;                  << 
312             ourStep = 0.0;                     << 
313             exiting = true;                    << 
314             entering = false;                  << 
315                                                << 
316             // validExitNormal= motherValidExi << 
317             // exitNormal= motherExitNormal;   << 
318             // Useful only if the point is ver << 
319             // => but it would need to be rota << 
320             validExitNormal= false;            << 
321                                                << 
322             *pBlockedPhysical = nullptr; // or << 
323             blockedReplicaNo = 0;  // or mothe << 
324                                                << 
325             newSafety = 0.0;                   << 
326             return ourStep;                    << 
327           }                                    << 
328                                                << 
329           if ( motherStep<=ourStep )              298           if ( motherStep<=ourStep )
330           {                                       299           {
331             ourStep = motherStep;                 300             ourStep = motherStep;
332             exiting = true;                       301             exiting = true;
333             entering = false;                     302             entering = false;
334                                                << 
335             // Exit normal: Natural location t << 
336             //                                 << 
337             validExitNormal = motherValidExitN << 
338             exitNormal = motherExitNormal;     << 
339                                                << 
340             if ( validExitNormal )                303             if ( validExitNormal )
341             {                                     304             {
342               const G4RotationMatrix *rot = mo    305               const G4RotationMatrix *rot = motherPhysical->GetRotation();
343               if (rot != nullptr)              << 306               if (rot)
344               {                                   307               {
345                 exitNormal *= rot->inverse();     308                 exitNormal *= rot->inverse();
346 #ifdef G4VERBOSE                               << 
347                 if( fCheck )                   << 
348                 {                              << 
349                   fLogger->CheckAndReportBadNo << 
350                                                << 
351                                                << 
352                                                << 
353                 }                              << 
354 #endif                                         << 
355               }                                   309               }
356             }                                  << 310             }  
357           }                                       311           }
358           else                                    312           else
359           {                                       313           {
360             validExitNormal = false;              314             validExitNormal = false;
361           }                                       315           }
362         }                                         316         }
363       }                                           317       }
364       newSafety = ourSafety;                      318       newSafety = ourSafety;
365     }                                             319     }
366     if (noStep)                                   320     if (noStep)
367     {                                             321     {
368       noStep = LocateNextVoxel(localPoint, loc    322       noStep = LocateNextVoxel(localPoint, localDirection, ourStep);
369     }                                             323     }
370   }  // end -while (noStep)- loop                 324   }  // end -while (noStep)- loop
371                                                   325 
372   return ourStep;                                 326   return ourStep;
373 }                                                 327 }
374                                                   328 
375 // *******************************************    329 // ********************************************************************
376 // ComputeVoxelSafety                             330 // ComputeVoxelSafety
377 //                                                331 //
378 // Computes safety from specified point to vox    332 // Computes safety from specified point to voxel boundaries
379 // using already located point                    333 // using already located point
380 // o collected boundaries for most derived lev    334 // o collected boundaries for most derived level
381 // o adjacent boundaries for previous levels      335 // o adjacent boundaries for previous levels
382 // *******************************************    336 // ********************************************************************
383 //                                                337 //
384 G4double                                          338 G4double
385 G4VoxelNavigation::ComputeVoxelSafety(const G4    339 G4VoxelNavigation::ComputeVoxelSafety(const G4ThreeVector& localPoint) const
386 {                                                 340 {
387   G4SmartVoxelHeader *curHeader;                  341   G4SmartVoxelHeader *curHeader;
388   G4double voxelSafety, curNodeWidth;             342   G4double voxelSafety, curNodeWidth;
389   G4double curNodeOffset, minCurCommonDelta, m    343   G4double curNodeOffset, minCurCommonDelta, maxCurCommonDelta;
390   G4int minCurNodeNoDelta, maxCurNodeNoDelta;     344   G4int minCurNodeNoDelta, maxCurNodeNoDelta;
391   G4int localVoxelDepth, curNodeNo;               345   G4int localVoxelDepth, curNodeNo;
392   EAxis curHeaderAxis;                            346   EAxis curHeaderAxis;
393                                                   347 
394   localVoxelDepth = fVoxelDepth;                  348   localVoxelDepth = fVoxelDepth;
395                                                   349 
396   curHeader = fVoxelHeaderStack[localVoxelDept    350   curHeader = fVoxelHeaderStack[localVoxelDepth];
397   curHeaderAxis = fVoxelAxisStack[localVoxelDe    351   curHeaderAxis = fVoxelAxisStack[localVoxelDepth];
398   curNodeNo = fVoxelNodeNoStack[localVoxelDept    352   curNodeNo = fVoxelNodeNoStack[localVoxelDepth];
399   curNodeWidth = fVoxelSliceWidthStack[localVo    353   curNodeWidth = fVoxelSliceWidthStack[localVoxelDepth];
400                                                   354   
401   // Compute linear intersection distance to b    355   // Compute linear intersection distance to boundaries of max/min
402   // to collected nodes at current level          356   // to collected nodes at current level
403   //                                              357   //
404   curNodeOffset = curNodeNo*curNodeWidth;         358   curNodeOffset = curNodeNo*curNodeWidth;
405   maxCurNodeNoDelta = fVoxelNode->GetMaxEquiva    359   maxCurNodeNoDelta = fVoxelNode->GetMaxEquivalentSliceNo()-curNodeNo;
406   minCurNodeNoDelta = curNodeNo-fVoxelNode->Ge    360   minCurNodeNoDelta = curNodeNo-fVoxelNode->GetMinEquivalentSliceNo();
407   minCurCommonDelta = localPoint(curHeaderAxis    361   minCurCommonDelta = localPoint(curHeaderAxis)
408                       - curHeader->GetMinExten    362                       - curHeader->GetMinExtent() - curNodeOffset;
409   maxCurCommonDelta = curNodeWidth-minCurCommo    363   maxCurCommonDelta = curNodeWidth-minCurCommonDelta;
410                                                   364 
411   if ( minCurNodeNoDelta<maxCurNodeNoDelta )      365   if ( minCurNodeNoDelta<maxCurNodeNoDelta )
412   {                                               366   {
413     voxelSafety = minCurNodeNoDelta*curNodeWid    367     voxelSafety = minCurNodeNoDelta*curNodeWidth;
414     voxelSafety += minCurCommonDelta;             368     voxelSafety += minCurCommonDelta;
415   }                                               369   }
416   else if (maxCurNodeNoDelta < minCurNodeNoDel    370   else if (maxCurNodeNoDelta < minCurNodeNoDelta)
417   {                                            << 371        {
418     voxelSafety = maxCurNodeNoDelta*curNodeWid << 372          voxelSafety = maxCurNodeNoDelta*curNodeWidth;
419     voxelSafety += maxCurCommonDelta;          << 373          voxelSafety += maxCurCommonDelta;
420   }                                            << 374         }
421   else    // (maxCurNodeNoDelta == minCurNodeN << 375         else    // (maxCurNodeNoDelta == minCurNodeNoDelta)
422   {                                            << 376         {
423     voxelSafety = minCurNodeNoDelta*curNodeWid << 377           voxelSafety = minCurNodeNoDelta*curNodeWidth;
424     voxelSafety += std::min(minCurCommonDelta, << 378           voxelSafety += std::min(minCurCommonDelta,maxCurCommonDelta);
425   }                                            << 379         }
426                                                   380 
427   // Compute isotropic safety to boundaries of    381   // Compute isotropic safety to boundaries of previous levels
428   // [NOT to collected boundaries]                382   // [NOT to collected boundaries]
429                                                << 383   //
430   // Loop checking, 07.10.2016, JA             << 
431   while ( (localVoxelDepth>0) && (voxelSafety>    384   while ( (localVoxelDepth>0) && (voxelSafety>0) )
432   {                                               385   {
433     localVoxelDepth--;                            386     localVoxelDepth--;
434     curHeader = fVoxelHeaderStack[localVoxelDe    387     curHeader = fVoxelHeaderStack[localVoxelDepth];
435     curHeaderAxis = fVoxelAxisStack[localVoxel    388     curHeaderAxis = fVoxelAxisStack[localVoxelDepth];
436     curNodeNo = fVoxelNodeNoStack[localVoxelDe    389     curNodeNo = fVoxelNodeNoStack[localVoxelDepth];
437     curNodeWidth = fVoxelSliceWidthStack[local    390     curNodeWidth = fVoxelSliceWidthStack[localVoxelDepth];
438     curNodeOffset = curNodeNo*curNodeWidth;       391     curNodeOffset = curNodeNo*curNodeWidth;
439     minCurCommonDelta = localPoint(curHeaderAx    392     minCurCommonDelta = localPoint(curHeaderAxis)
440                         - curHeader->GetMinExt    393                         - curHeader->GetMinExtent() - curNodeOffset;
441     maxCurCommonDelta = curNodeWidth-minCurCom    394     maxCurCommonDelta = curNodeWidth-minCurCommonDelta;
442                                                   395     
443     if ( minCurCommonDelta<voxelSafety )          396     if ( minCurCommonDelta<voxelSafety )
444     {                                             397     {
445       voxelSafety = minCurCommonDelta;            398       voxelSafety = minCurCommonDelta;
446     }                                             399     }
447     if ( maxCurCommonDelta<voxelSafety )          400     if ( maxCurCommonDelta<voxelSafety )
448     {                                             401     {
449       voxelSafety = maxCurCommonDelta;            402       voxelSafety = maxCurCommonDelta;
450     }                                             403     }
451   }                                               404   }
452   if ( voxelSafety<0 )                            405   if ( voxelSafety<0 )
453   {                                               406   {
454     voxelSafety = 0;                              407     voxelSafety = 0;
455   }                                               408   }
456                                                   409 
457   return voxelSafety;                             410   return voxelSafety;
458 }                                                 411 }
459                                                   412 
460 // *******************************************    413 // ********************************************************************
461 // LocateNextVoxel                                414 // LocateNextVoxel
462 //                                                415 //
463 // Finds the next voxel from the current voxel    416 // Finds the next voxel from the current voxel and point
464 // in the specified direction                     417 // in the specified direction
465 //                                                418 //
466 // Returns false if all voxels considered         419 // Returns false if all voxels considered
467 //              [current Step ends inside same    420 //              [current Step ends inside same voxel or leaves all voxels]
468 //         true  otherwise                        421 //         true  otherwise
469 //              [the information on the next v    422 //              [the information on the next voxel is put into the set of
470 //               fVoxel* variables & "stacks"]    423 //               fVoxel* variables & "stacks"] 
471 // *******************************************    424 // ********************************************************************
472 //                                                425 // 
473 G4bool                                            426 G4bool
474 G4VoxelNavigation::LocateNextVoxel(const G4Thr    427 G4VoxelNavigation::LocateNextVoxel(const G4ThreeVector& localPoint,
475                                    const G4Thr    428                                    const G4ThreeVector& localDirection,
476                                    const G4dou    429                                    const G4double currentStep)
477 {                                                 430 {
478   G4SmartVoxelHeader *workHeader=nullptr, *new << 431   G4SmartVoxelHeader *workHeader=0, *newHeader=0;
479   G4SmartVoxelProxy *newProxy=nullptr;         << 432   G4SmartVoxelProxy *newProxy=0;
480   G4SmartVoxelNode *newVoxelNode=nullptr;      << 433   G4SmartVoxelNode *newVoxelNode=0;
481   G4ThreeVector targetPoint, voxelPoint;          434   G4ThreeVector targetPoint, voxelPoint;
482   G4double workNodeWidth, workMinExtent, workC    435   G4double workNodeWidth, workMinExtent, workCoord;
483   G4double minVal, maxVal, newDistance=0.;        436   G4double minVal, maxVal, newDistance=0.;
484   G4double newHeaderMin, newHeaderNodeWidth;      437   G4double newHeaderMin, newHeaderNodeWidth;
485   G4int depth=0, newDepth=0, workNodeNo=0, new    438   G4int depth=0, newDepth=0, workNodeNo=0, newNodeNo=0, newHeaderNoSlices=0;
486   EAxis workHeaderAxis, newHeaderAxis;            439   EAxis workHeaderAxis, newHeaderAxis;
487   G4bool isNewVoxel = false;                   << 440   G4bool isNewVoxel=false;
488                                                   441   
489   G4double currentDistance = currentStep;         442   G4double currentDistance = currentStep;
490                                                   443 
491   // Determine if end of Step within current v    444   // Determine if end of Step within current voxel
492   //                                              445   //
493   for (depth=0; depth<fVoxelDepth; ++depth)    << 446   for (depth=0; depth<fVoxelDepth; depth++)
494   {                                               447   {
495     targetPoint = localPoint+localDirection*cu    448     targetPoint = localPoint+localDirection*currentDistance;
496     newDistance = currentDistance;                449     newDistance = currentDistance;
497     workHeader = fVoxelHeaderStack[depth];        450     workHeader = fVoxelHeaderStack[depth];
498     workHeaderAxis = fVoxelAxisStack[depth];      451     workHeaderAxis = fVoxelAxisStack[depth];
499     workNodeNo = fVoxelNodeNoStack[depth];        452     workNodeNo = fVoxelNodeNoStack[depth];
500     workNodeWidth = fVoxelSliceWidthStack[dept    453     workNodeWidth = fVoxelSliceWidthStack[depth];
501     workMinExtent = workHeader->GetMinExtent()    454     workMinExtent = workHeader->GetMinExtent();
502     workCoord = targetPoint(workHeaderAxis);      455     workCoord = targetPoint(workHeaderAxis);
503     minVal = workMinExtent+workNodeNo*workNode    456     minVal = workMinExtent+workNodeNo*workNodeWidth;
504                                                   457 
505     if ( minVal<=workCoord+fHalfTolerance )    << 458     if ( minVal<=workCoord+kCarTolerance*0.5 )
506     {                                             459     {
507       maxVal = minVal+workNodeWidth;              460       maxVal = minVal+workNodeWidth;
508       if ( maxVal<=workCoord-fHalfTolerance )  << 461       if ( maxVal<=workCoord-kCarTolerance*0.5 )
509       {                                           462       {
510         // Must consider next voxel               463         // Must consider next voxel
511         //                                        464         //
512         newNodeNo = workNodeNo+1;                 465         newNodeNo = workNodeNo+1;
513         newHeader = workHeader;                   466         newHeader = workHeader;
514         newDistance = (maxVal-localPoint(workH    467         newDistance = (maxVal-localPoint(workHeaderAxis))
515                     / localDirection(workHeade    468                     / localDirection(workHeaderAxis);
516         isNewVoxel = true;                        469         isNewVoxel = true;
517         newDepth = depth;                         470         newDepth = depth;
518       }                                           471       }
519     }                                             472     }
520     else                                          473     else
521     {                                             474     {
522       newNodeNo = workNodeNo-1;                   475       newNodeNo = workNodeNo-1;
523       newHeader = workHeader;                     476       newHeader = workHeader;
524       newDistance = (minVal-localPoint(workHea    477       newDistance = (minVal-localPoint(workHeaderAxis))
525                   / localDirection(workHeaderA    478                   / localDirection(workHeaderAxis);
526       isNewVoxel = true;                          479       isNewVoxel = true;
527       newDepth = depth;                           480       newDepth = depth;
528     }                                             481     }
529     currentDistance = newDistance;                482     currentDistance = newDistance;
530   }                                               483   }
531   targetPoint = localPoint+localDirection*curr    484   targetPoint = localPoint+localDirection*currentDistance;
532                                                   485 
533   // Check if end of Step within collected bou    486   // Check if end of Step within collected boundaries of current voxel
534   //                                              487   //
535   depth = fVoxelDepth;                            488   depth = fVoxelDepth;
536   {                                               489   {
537     workHeader = fVoxelHeaderStack[depth];        490     workHeader = fVoxelHeaderStack[depth];
538     workHeaderAxis = fVoxelAxisStack[depth];      491     workHeaderAxis = fVoxelAxisStack[depth];
539     workNodeNo = fVoxelNodeNoStack[depth];        492     workNodeNo = fVoxelNodeNoStack[depth];
540     workNodeWidth = fVoxelSliceWidthStack[dept    493     workNodeWidth = fVoxelSliceWidthStack[depth];
541     workMinExtent = workHeader->GetMinExtent()    494     workMinExtent = workHeader->GetMinExtent();
542     workCoord = targetPoint(workHeaderAxis);      495     workCoord = targetPoint(workHeaderAxis);
543     minVal = workMinExtent+fVoxelNode->GetMinE    496     minVal = workMinExtent+fVoxelNode->GetMinEquivalentSliceNo()*workNodeWidth;
544                                                   497 
545     if ( minVal<=workCoord+fHalfTolerance )    << 498     if ( minVal<=workCoord+kCarTolerance*0.5 )
546     {                                             499     {
547       maxVal = workMinExtent+(fVoxelNode->GetM    500       maxVal = workMinExtent+(fVoxelNode->GetMaxEquivalentSliceNo()+1)
548                             *workNodeWidth;       501                             *workNodeWidth;
549       if ( maxVal<=workCoord-fHalfTolerance )  << 502       if ( maxVal<=workCoord-kCarTolerance*0.5 )
550       {                                           503       {
551         newNodeNo = fVoxelNode->GetMaxEquivale    504         newNodeNo = fVoxelNode->GetMaxEquivalentSliceNo()+1;
552         newHeader = workHeader;                   505         newHeader = workHeader;
553         newDistance = (maxVal-localPoint(workH    506         newDistance = (maxVal-localPoint(workHeaderAxis))
554                     / localDirection(workHeade    507                     / localDirection(workHeaderAxis);
555         isNewVoxel = true;                        508         isNewVoxel = true;
556         newDepth = depth;                         509         newDepth = depth;
557       }                                           510       }
558     }                                             511     }
559     else                                          512     else
560     {                                             513     {
561       newNodeNo = fVoxelNode->GetMinEquivalent    514       newNodeNo = fVoxelNode->GetMinEquivalentSliceNo()-1;
562       newHeader = workHeader;                     515       newHeader = workHeader;
563       newDistance = (minVal-localPoint(workHea    516       newDistance = (minVal-localPoint(workHeaderAxis))
564                   / localDirection(workHeaderA    517                   / localDirection(workHeaderAxis);
565       isNewVoxel = true;                          518       isNewVoxel = true;
566       newDepth = depth;                           519       newDepth = depth;
567     }                                             520     }
568     currentDistance = newDistance;                521     currentDistance = newDistance;
569   }                                               522   }
570   if (isNewVoxel)                                 523   if (isNewVoxel)
571   {                                               524   {
572     // Compute new voxel & adjust voxel stack     525     // Compute new voxel & adjust voxel stack
573     //                                            526     //
574     // newNodeNo=Candidate node no at             527     // newNodeNo=Candidate node no at 
575     // newDepth =refinement depth of crossed v    528     // newDepth =refinement depth of crossed voxel boundary
576     // newHeader=Header for crossed voxel         529     // newHeader=Header for crossed voxel
577     // newDistance=distance to crossed voxel b    530     // newDistance=distance to crossed voxel boundary (along the track)
578     //                                            531     //
579     if ( (newNodeNo<0) || (newNodeNo>=G4int(ne << 532     if ( (newNodeNo<0) || (newNodeNo>=newHeader->GetNoSlices()))
580     {                                             533     {
581       // Leaving mother volume                    534       // Leaving mother volume
582       //                                          535       //
583       isNewVoxel = false;                         536       isNewVoxel = false;
584     }                                             537     }
585     else                                          538     else
586     {                                             539     {
587       // Compute intersection point on the lea    540       // Compute intersection point on the least refined
588       // voxel boundary that is hit               541       // voxel boundary that is hit
589       //                                          542       //
590       voxelPoint = localPoint+localDirection*n    543       voxelPoint = localPoint+localDirection*newDistance;
591       fVoxelNodeNoStack[newDepth] = newNodeNo;    544       fVoxelNodeNoStack[newDepth] = newNodeNo;
592       fVoxelDepth = newDepth;                     545       fVoxelDepth = newDepth;
593       newVoxelNode = nullptr;                  << 546       newVoxelNode = 0;
594       while ( newVoxelNode == nullptr )        << 547       while ( !newVoxelNode )
595       {                                           548       {
596         newProxy = newHeader->GetSlice(newNode    549         newProxy = newHeader->GetSlice(newNodeNo);
597         if (newProxy->IsNode())                   550         if (newProxy->IsNode())
598         {                                         551         {
599           newVoxelNode = newProxy->GetNode();     552           newVoxelNode = newProxy->GetNode();
600         }                                         553         }
601         else                                      554         else
602         {                                         555         {
603           ++fVoxelDepth;                       << 556           fVoxelDepth++;
604           newHeader = newProxy->GetHeader();      557           newHeader = newProxy->GetHeader();
605           newHeaderAxis = newHeader->GetAxis()    558           newHeaderAxis = newHeader->GetAxis();
606           newHeaderNoSlices = (G4int)newHeader << 559           newHeaderNoSlices = newHeader->GetNoSlices();
607           newHeaderMin = newHeader->GetMinExte    560           newHeaderMin = newHeader->GetMinExtent();
608           newHeaderNodeWidth = (newHeader->Get    561           newHeaderNodeWidth = (newHeader->GetMaxExtent()-newHeaderMin)
609                              / newHeaderNoSlic    562                              / newHeaderNoSlices;
610           newNodeNo = G4int( (voxelPoint(newHe    563           newNodeNo = G4int( (voxelPoint(newHeaderAxis)-newHeaderMin)
611                              / newHeaderNodeWi    564                              / newHeaderNodeWidth );
612           // Rounding protection                  565           // Rounding protection
613           //                                      566           //
614           if ( newNodeNo<0 )                      567           if ( newNodeNo<0 )
615           {                                       568           {
616             newNodeNo=0;                          569             newNodeNo=0;
617           }                                       570           }
618           else if ( newNodeNo>=newHeaderNoSlic    571           else if ( newNodeNo>=newHeaderNoSlices )
619           {                                    << 572                {
620             newNodeNo = newHeaderNoSlices-1;   << 573                  newNodeNo = newHeaderNoSlices-1;
621           }                                    << 574                }
622           // Stack info for stepping              575           // Stack info for stepping
623           //                                      576           //
624           fVoxelAxisStack[fVoxelDepth] = newHe    577           fVoxelAxisStack[fVoxelDepth] = newHeaderAxis;
625           fVoxelNoSlicesStack[fVoxelDepth] = n    578           fVoxelNoSlicesStack[fVoxelDepth] = newHeaderNoSlices;
626           fVoxelSliceWidthStack[fVoxelDepth] =    579           fVoxelSliceWidthStack[fVoxelDepth] = newHeaderNodeWidth;
627           fVoxelNodeNoStack[fVoxelDepth] = new    580           fVoxelNodeNoStack[fVoxelDepth] = newNodeNo;
628           fVoxelHeaderStack[fVoxelDepth] = new    581           fVoxelHeaderStack[fVoxelDepth] = newHeader;
629         }                                         582         }
630       }                                           583       }
631       fVoxelNode = newVoxelNode;                  584       fVoxelNode = newVoxelNode;
632     }                                             585     }
633   }                                               586   }
634   return isNewVoxel;                              587   return isNewVoxel;        
635 }                                                 588 }
636                                                   589 
637 // *******************************************    590 // ********************************************************************
638 // ComputeSafety                                  591 // ComputeSafety
639 //                                                592 //
640 // Calculates the isotropic distance to the ne    593 // Calculates the isotropic distance to the nearest boundary from the
641 // specified point in the local coordinate sys    594 // specified point in the local coordinate system. 
642 // The localpoint utilised must be within the     595 // The localpoint utilised must be within the current volume.
643 // *******************************************    596 // ********************************************************************
644 //                                                597 //
645 G4double                                          598 G4double
646 G4VoxelNavigation::ComputeSafety(const G4Three    599 G4VoxelNavigation::ComputeSafety(const G4ThreeVector& localPoint,
647                                  const G4Navig    600                                  const G4NavigationHistory& history,
648                                  const G4doubl << 601                                  const G4double )
649 {                                                 602 {
650   G4VPhysicalVolume *motherPhysical, *samplePh    603   G4VPhysicalVolume *motherPhysical, *samplePhysical;
651   G4LogicalVolume *motherLogical;                 604   G4LogicalVolume *motherLogical;
652   G4VSolid *motherSolid;                          605   G4VSolid *motherSolid;
653   G4double motherSafety, ourSafety;               606   G4double motherSafety, ourSafety;
654   G4int sampleNo;                              << 607   G4int localNoDaughters, sampleNo;
655   G4SmartVoxelNode *curVoxelNode;                 608   G4SmartVoxelNode *curVoxelNode;
656   G4long curNoVolumes, contentNo;              << 609   G4int curNoVolumes, contentNo;
657   G4double voxelSafety;                           610   G4double voxelSafety;
658                                                   611 
659   motherPhysical = history.GetTopVolume();        612   motherPhysical = history.GetTopVolume();
660   motherLogical = motherPhysical->GetLogicalVo    613   motherLogical = motherPhysical->GetLogicalVolume();
661   motherSolid = motherLogical->GetSolid();        614   motherSolid = motherLogical->GetSolid();
662                                                   615 
663   if( fBestSafety )                            << 
664   {                                            << 
665     return fpVoxelSafety->ComputeSafety( local << 
666   }                                            << 
667                                                << 
668   //                                              616   //
669   // Compute mother safety                        617   // Compute mother safety
670   //                                              618   //
671                                                   619 
672   motherSafety = motherSolid->DistanceToOut(lo    620   motherSafety = motherSolid->DistanceToOut(localPoint);
673   ourSafety = motherSafety;                 //    621   ourSafety = motherSafety;                 // Working isotropic safety
674                                                   622 
675   if( motherSafety == 0.0 )                    << 
676   {                                            << 
677 #ifdef G4DEBUG_NAVIGATION                      << 
678     // Check that point is inside mother volum << 
679     EInside  insideMother = motherSolid->Insid << 
680                                                << 
681     if( insideMother == kOutside )             << 
682     {                                          << 
683       G4ExceptionDescription message;          << 
684       message << "Safety method called for loc << 
685          << "Location for safety is Outside th << 
686          << "The approximate distance to the s << 
687          << "(safety from outside) is: "       << 
688          << motherSolid->DistanceToIn( localPo << 
689       message << "  Problem occurred with phys << 
690          << " Name: " << motherPhysical->GetNa << 
691          << " Copy No: " << motherPhysical->Ge << 
692          << "    Local Point = " << localPoint << 
693       message << "  Description of solid: " << << 
694             << *motherSolid << G4endl;         << 
695       G4Exception("G4VoxelNavigation::ComputeS << 
696                   JustWarning, message);       << 
697     }                                          << 
698                                                << 
699     // Following check is NOT for an issue - i << 
700     //  It is allowed that a solid gives appro << 
701     //                                         << 
702     if( insideMother == kInside ) // && fVerbo << 
703     {                                          << 
704       G4ExceptionDescription messageIn;        << 
705                                                << 
706       messageIn << " Point is Inside, but safe << 
707       messageIn << " Inexact safety for volume << 
708              << "  Solid: Name= " << motherSol << 
709              << "   Type= " << motherSolid->Ge << 
710       messageIn << "  Local point= " << localP << 
711       messageIn << "  Solid parameters: " << G << 
712       G4Exception("G4VoxelNavigation::ComputeS << 
713                   JustWarning, messageIn);     << 
714     }                                          << 
715 #endif                                         << 
716     // if( insideMother != kInside )           << 
717     return 0.0;                                << 
718   }                                            << 
719                                                << 
720 #ifdef G4VERBOSE                               << 
721   if( fCheck )                                 << 
722   {                                            << 
723     fLogger->ComputeSafetyLog (motherSolid,loc << 
724   }                                            << 
725 #endif                                         << 
726   //                                              623   //
727   // Compute daughter safeties                 << 624   // Compute daughter safeties 
728   //                                              625   //
729   // Look only inside the current Voxel only ( << 626 
                                                   >> 627   localNoDaughters = motherLogical->GetNoDaughters();
                                                   >> 628 
                                                   >> 629   //  Look only inside the current Voxel only (in the first version).
730   //                                              630   //
731   curVoxelNode = fVoxelNode;                      631   curVoxelNode = fVoxelNode;
732   curNoVolumes = curVoxelNode->GetNoContained(    632   curNoVolumes = curVoxelNode->GetNoContained();
733                                                   633 
734   for ( contentNo=curNoVolumes-1; contentNo>=0    634   for ( contentNo=curNoVolumes-1; contentNo>=0; contentNo-- )
735   {                                               635   {
736     sampleNo = curVoxelNode->GetVolume((G4int) << 636     sampleNo = curVoxelNode->GetVolume(contentNo);
737     samplePhysical = motherLogical->GetDaughte    637     samplePhysical = motherLogical->GetDaughter(sampleNo);
738                                                   638 
739     G4AffineTransform sampleTf(samplePhysical-    639     G4AffineTransform sampleTf(samplePhysical->GetRotation(),
740                                samplePhysical-    640                                samplePhysical->GetTranslation());
741     sampleTf.Invert();                            641     sampleTf.Invert();
742     const G4ThreeVector samplePoint = sampleTf << 642     const G4ThreeVector samplePoint =
743     const G4VSolid* sampleSolid= samplePhysica << 643                           sampleTf.TransformPoint(localPoint);
                                                   >> 644     const G4VSolid *sampleSolid     =
                                                   >> 645                           samplePhysical->GetLogicalVolume()->GetSolid();
744     G4double sampleSafety = sampleSolid->Dista    646     G4double sampleSafety = sampleSolid->DistanceToIn(samplePoint);
745     if ( sampleSafety<ourSafety )                 647     if ( sampleSafety<ourSafety )
746     {                                             648     {
747       ourSafety = sampleSafety;                   649       ourSafety = sampleSafety;
748     }                                             650     }
749 #ifdef G4VERBOSE                               << 
750     if( fCheck )                               << 
751     {                                          << 
752       fLogger->ComputeSafetyLog(sampleSolid, s << 
753                                 sampleSafety,  << 
754     }                                          << 
755 #endif                                         << 
756   }                                               651   }
757   voxelSafety = ComputeVoxelSafety(localPoint)    652   voxelSafety = ComputeVoxelSafety(localPoint);
758   if ( voxelSafety<ourSafety )                    653   if ( voxelSafety<ourSafety )
759   {                                               654   {
760     ourSafety = voxelSafety;                      655     ourSafety = voxelSafety;
761   }                                               656   }
762   return ourSafety;                               657   return ourSafety;
763 }                                              << 
764                                                << 
765 void G4VoxelNavigation::RelocateWithinVolume(  << 
766                                                << 
767 {                                              << 
768   auto motherLogical = motherPhysical->GetLogi << 
769                                                << 
770   assert(motherLogical != nullptr);            << 
771                                                << 
772   if ( auto pVoxelHeader = motherLogical->GetV << 
773     VoxelLocate( pVoxelHeader, localPoint );   << 
774 }                                              << 
775                                                << 
776 // ******************************************* << 
777 // SetVerboseLevel                             << 
778 // ******************************************* << 
779 //                                             << 
780 void  G4VoxelNavigation::SetVerboseLevel(G4int << 
781 {                                              << 
782   if( fLogger != nullptr ) { fLogger->SetVerbo << 
783   if( fpVoxelSafety != nullptr) { fpVoxelSafet << 
784 }                                                 658 }
785                                                   659