Geant4  10.00.p01
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 66356 2012-12-18 09:02:32Z 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  if ( sampleNormal.dot(localDirection) <= 0 )
59  {
60  if( sampleNormal.dot(localDirection) == 0 )
61  {
62  // We can't decide yet, let's make sure we're entering the solid.
63  // If by a confusion we entered the next solid we find out now
64  // whether to leave or to enter.
65  // This happens when we're on the surface or edge shared by two
66  // solids
67  //
68  G4double distanceToIn =
69  sampleSolid->DistanceToIn( localPoint, localDirection );
70  if( distanceToIn != kInfinity )
71  {
72  enter = true;
73  }
74  }
75  else
76  {
77  enter = true;
78  }
79  }
80  }
81  else
82  {
83  enter = true;
84  }
85  }
86  return enter;
87 }
88 
89 // --------------------------------------------------------------------
90 
91 inline G4bool
92 G4AuxiliaryNavServices::
93 CheckPointExiting( const G4VSolid* sampleSolid,
94  const G4ThreeVector& localPoint,
95  const G4ThreeVector* globalDirection,
96  const G4AffineTransform& sampleTransform )
97 {
98  if( !globalDirection ) { return false; }
99 
100  G4ThreeVector localDirection, sampleNormal;
101  G4bool exiting = false;
102 
103  EInside insideSolid = sampleSolid->Inside(localPoint);
104  if( insideSolid==kSurface )
105  {
106  localDirection= sampleTransform.TransformAxis(*globalDirection);
107 
108  // Check whether we are exiting the volume
109  //
110  sampleNormal = sampleSolid->SurfaceNormal(localPoint);
111  if ( sampleNormal.dot(localDirection) >= 0 )
112  {
113  if( sampleNormal.dot(localDirection) == 0 )
114  {
115  // We can't decide yet, let's make sure we're entering the solid.
116  // If by a confusion we entered the next solid we find out now
117  // whether to leave or to exiting.
118  // This happens when we're on the surface or edge shared by two
119  // solids
120  //
121  G4double distanceToIn =
122  sampleSolid->DistanceToIn( localPoint, localDirection );
123  if( distanceToIn != kInfinity )
124  {
125  exiting = true;
126  }
127  }
128  else
129  {
130  exiting = true;
131  }
132  }
133  }
134  return exiting;
135 }