Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4SolidExtentList.cc
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: G4SolidExtentList.cc 66356 2012-12-18 09:02:32Z gcosmo $
28 //
29 //
30 // --------------------------------------------------------------------
31 // GEANT 4 class source file
32 //
33 //
34 // G4SolidExtentList.cc
35 //
36 // Implementation of a list of (voxel) extents along one axis
37 //
38 // --------------------------------------------------------------------
39 
40 #include "G4SolidExtentList.hh"
41 #include "G4VoxelLimits.hh"
42 #include "G4GeometryTolerance.hh"
43 
44 
45 //
46 // Constructor (default)
47 //
49 {
50  axis = kZAxis;
51  limited = false;
52  minLimit = -INT_MAX/2;
53  maxLimit = INT_MAX/2;
54 }
55 
56 
57 //
58 // Constructor (limited case)
59 //
61  const G4VoxelLimits &voxelLimits )
62 {
63  axis = targetAxis;
64 
65  limited = voxelLimits.IsLimited( axis );
66  if (limited)
67  {
68  minLimit = voxelLimits.GetMinExtent( axis );
69  maxLimit = voxelLimits.GetMaxExtent( axis );
70  }
71  else
72  {
73  minLimit = -INT_MAX/2;
74  maxLimit = INT_MAX/2;
75  }
76 }
77 
78 
79 //
80 // Destructor
81 //
83 {
84 }
85 
86 
87 //
88 // AddSurface
89 //
90 //
92 {
93  //
94  // Keep track of four surfaces
95  //
96  G4double min, max;
97 
98  surface.GetExtent( axis, min, max );
99 
100  if (min > maxLimit)
101  {
102  //
103  // Nearest surface beyond maximum limit
104  //
105  if (surface.InFrontOf(minAbove,axis)) minAbove = surface;
106  }
107  else if (max < minLimit)
108  {
109  //
110  // Nearest surface below minimum limit
111  //
112  if (surface.BehindOf(maxBelow,axis)) maxBelow = surface;
113  }
114  else
115  {
116  //
117  // Max and min surfaces inside
118  //
119  if (surface.BehindOf(maxSurface,axis)) maxSurface = surface;
120  if (surface.InFrontOf(minSurface,axis)) minSurface = surface;
121  }
122 }
123 
124 
125 
126 //
127 // GetExtent
128 //
129 // Return extent after processing all surfaces
130 //
132 {
135  //
136  // Did we have any surfaces within the limits?
137  //
138  if (minSurface.Empty())
139  {
140  //
141  // Nothing! Do we have anything above?
142  //
143  if (minAbove.Empty()) return false;
144 
145  //
146  // Yup. Is it facing inwards?
147  //
148  if (minAbove.GetNormal().operator()(axis) < 0) return false;
149 
150  //
151  // No. We must be entirely within the solid
152  //
153  max = maxLimit + kCarTolerance;
154  min = minLimit - kCarTolerance;
155  return true;
156  }
157 
158  //
159  // Check max surface
160  //
161  if (maxSurface.GetNormal().operator()(axis) < 0)
162  {
163  //
164  // Inward facing: max limit must be embedded within solid
165  //
166  max = maxLimit + kCarTolerance;
167  }
168  else
169  {
170  G4double sMin, sMax;
171  maxSurface.GetExtent( axis, sMin, sMax );
172  max = ( (sMax > maxLimit) ? maxLimit : sMax ) + kCarTolerance;
173  }
174 
175  //
176  // Check min surface
177  //
178  if (minSurface.GetNormal().operator()(axis) > 0)
179  {
180  //
181  // Inward facing: max limit must be embedded within solid
182  //
183  min = minLimit - kCarTolerance;
184  }
185  else
186  {
187  G4double sMin, sMax;
188  minSurface.GetExtent( axis, sMin, sMax );
189  min = ( (sMin < minLimit) ? minLimit : sMin ) - kCarTolerance;
190  }
191 
192  return true;
193 }
194 
virtual G4bool InFrontOf(const G4ClippablePolygon &other, EAxis axis) const
G4ClippablePolygon maxBelow
G4bool GetExtent(G4double &min, G4double &max) const
G4double GetSurfaceTolerance() const
virtual G4bool BehindOf(const G4ClippablePolygon &other, EAxis axis) const
const G4ThreeVector GetNormal() const
virtual G4bool GetExtent(const EAxis axis, G4double &min, G4double &max) const
G4bool IsLimited() const
bool G4bool
Definition: G4Types.hh:79
void AddSurface(const G4ClippablePolygon &surface)
#define INT_MAX
Definition: templates.hh:111
T max(const T t1, const T t2)
brief Return the largest of the two arguments
EAxis
Definition: geomdefs.hh:54
G4ClippablePolygon minSurface
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4bool Empty() const
G4ClippablePolygon maxSurface
double G4double
Definition: G4Types.hh:76
G4double GetMaxExtent(const EAxis pAxis) const
G4ClippablePolygon minAbove
G4double GetMinExtent(const EAxis pAxis) const
static G4GeometryTolerance * GetInstance()