Geant4  10.02.p02
G4AuxiliaryNavServices.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: G4AuxiliaryNavServices.icc 90009 2015-05-08 07:42:39Z gcosmo $
28 //
29 //
30 // class G4AuxiliaryNavServices Inline implementation
31 //
32 // --------------------------------------------------------------------
33 
34 inline G4bool
35 G4AuxiliaryNavServices::
36 CheckPointOnSurface( const G4VSolid* sampleSolid,
37  const G4ThreeVector& localPoint,
38  const G4ThreeVector* globalDirection,
39  const G4AffineTransform& sampleTransform,
40  const G4bool locatedOnEdge)
41 {
42  G4ThreeVector localDirection, sampleNormal;
43  G4bool enter = false;
44 
45  EInside insideSolid = sampleSolid->Inside(localPoint);
46  if ( insideSolid!=kOutside )
47  {
48  G4bool checkDirection= locatedOnEdge && (globalDirection!=0);
49  if( (insideSolid==kSurface) && checkDirection)
50  {
51  // We are probably located on an edge.
52  //
53  localDirection= sampleTransform.TransformAxis(*globalDirection);
54 
55  // Check whether we enter the volume
56  //
57  sampleNormal = sampleSolid->SurfaceNormal(localPoint);
58 
59  G4double dotProd= sampleNormal.dot(localDirection);
60 
61 #ifdef G4DEBUG_AUX_NAVIGATION
62  G4cout << " dir.norm= " << dotProd // sampleNormal.dot(localDirection)
63  << " localDirection= " << localDirection
64  << " sampleNormal= " << sampleNormal;
65  if( dotProd == 0.0 )
66  {
67  G4cout << " distanceToIn = "
68  << sampleSolid->DistanceToIn( localPoint, localDirection );
69  }
70 #endif
71 
72  if ( dotProd <= 0.0 )
73  {
74  if( dotProd == 0.0 )
75  {
76  // We can't decide yet, let's make sure we're entering the solid.
77  // If by a confusion we entered the next solid we find out now
78  // whether to leave or to enter.
79  // This happens when we're on the surface or edge shared by two
80  // solids
81  //
82  G4double distanceToIn =
83  sampleSolid->DistanceToIn( localPoint, localDirection );
84  if( distanceToIn != kInfinity )
85  {
86  enter = true;
87  }
88  }
89  else
90  {
91  enter = true;
92  }
93  }
94  }
95  else
96  {
97  enter = true;
98  }
99  }
100 #ifdef G4DEBUG_AUX_NAVIGATION
101  G4cout << " enter = " << (enter ? "true" : "false" ) << G4endl;
102 #endif
103 
104  return enter;
105 }
106 
107 // --------------------------------------------------------------------
108 
109 inline G4bool
110 G4AuxiliaryNavServices::
111 CheckPointExiting( const G4VSolid* sampleSolid,
112  const G4ThreeVector& localPoint,
113  const G4ThreeVector* globalDirection,
114  const G4AffineTransform& sampleTransform )
115 {
116  if( !globalDirection ) { return false; }
117 
118  G4ThreeVector localDirection, sampleNormal;
119  G4bool exiting = false;
120 
121  EInside insideSolid = sampleSolid->Inside(localPoint);
122  if( insideSolid==kSurface )
123  {
124  localDirection= sampleTransform.TransformAxis(*globalDirection);
125 
126  // Check whether we are exiting the volume
127  //
128  sampleNormal = sampleSolid->SurfaceNormal(localPoint);
129  if ( sampleNormal.dot(localDirection) >= 0 )
130  {
131  if( sampleNormal.dot(localDirection) == 0 )
132  {
133  // We can't decide yet, let's make sure we're entering the solid.
134  // If by a confusion we entered the next solid we find out now
135  // whether to leave or to exiting.
136  // This happens when we're on the surface or edge shared by two
137  // solids
138  //
139  G4double distanceToIn =
140  sampleSolid->DistanceToIn( localPoint, localDirection );
141  if( distanceToIn != kInfinity )
142  {
143  exiting = true;
144  }
145  }
146  else
147  {
148  exiting = true;
149  }
150  }
151  }
152  return exiting;
153 }