Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4SolidExtentList implementation; a list of << 27 // 26 // 28 // Author: David C. Williams (davidw@scipp.ucs << 27 // $Id: G4SolidExtentList.cc,v 1.5 2007/05/11 13:54:29 gcosmo Exp $ >> 28 // GEANT4 tag $Name: geant4-09-02 $ >> 29 // >> 30 // >> 31 // -------------------------------------------------------------------- >> 32 // GEANT 4 class source file >> 33 // >> 34 // >> 35 // G4SolidExtentList.cc >> 36 // >> 37 // Implementation of a list of (voxel) extents along one axis >> 38 // 29 // ------------------------------------------- 39 // -------------------------------------------------------------------- 30 40 31 #include "G4SolidExtentList.hh" 41 #include "G4SolidExtentList.hh" 32 #include "G4VoxelLimits.hh" 42 #include "G4VoxelLimits.hh" 33 #include "G4GeometryTolerance.hh" 43 #include "G4GeometryTolerance.hh" 34 44 >> 45 >> 46 // 35 // Constructor (default) 47 // Constructor (default) 36 // 48 // 37 G4SolidExtentList::G4SolidExtentList() 49 G4SolidExtentList::G4SolidExtentList() 38 { 50 { 39 axis = kZAxis; 51 axis = kZAxis; 40 minLimit = -INT_MAX/2; << 52 limited = false; 41 maxLimit = INT_MAX/2; << 53 minLimit = -DBL_MAX; >> 54 maxLimit = +DBL_MAX; 42 } 55 } 43 56 >> 57 >> 58 // 44 // Constructor (limited case) 59 // Constructor (limited case) 45 // 60 // 46 G4SolidExtentList::G4SolidExtentList( const EA 61 G4SolidExtentList::G4SolidExtentList( const EAxis targetAxis, 47 const G4 62 const G4VoxelLimits &voxelLimits ) 48 { 63 { 49 axis = targetAxis; 64 axis = targetAxis; 50 65 51 limited = voxelLimits.IsLimited( axis ); 66 limited = voxelLimits.IsLimited( axis ); 52 if (limited) 67 if (limited) 53 { 68 { 54 minLimit = voxelLimits.GetMinExtent( axis 69 minLimit = voxelLimits.GetMinExtent( axis ); 55 maxLimit = voxelLimits.GetMaxExtent( axis 70 maxLimit = voxelLimits.GetMaxExtent( axis ); 56 } 71 } 57 else 72 else 58 { 73 { 59 minLimit = -INT_MAX/2; << 74 minLimit = -DBL_MAX; 60 maxLimit = INT_MAX/2; << 75 maxLimit = +DBL_MAX; 61 } 76 } 62 } 77 } 63 78 >> 79 >> 80 // 64 // Destructor 81 // Destructor 65 // 82 // 66 G4SolidExtentList::~G4SolidExtentList() = defa << 83 G4SolidExtentList::~G4SolidExtentList() >> 84 { >> 85 } >> 86 67 87 >> 88 // 68 // AddSurface 89 // AddSurface 69 // 90 // 70 // 91 // 71 void G4SolidExtentList::AddSurface( const G4Cl << 92 void G4SolidExtentList::AddSurface( const G4ClippablePolygon &surface ) 72 { 93 { 73 // 94 // 74 // Keep track of four surfaces 95 // Keep track of four surfaces 75 // 96 // 76 G4double smin=.0, smax=0.; << 97 G4double min, max; 77 98 78 surface.GetExtent( axis, smin, smax ); << 99 surface.GetExtent( axis, min, max ); 79 100 80 if (smin > maxLimit) << 101 if (min > maxLimit) 81 { 102 { 82 // 103 // 83 // Nearest surface beyond maximum limit 104 // Nearest surface beyond maximum limit 84 // 105 // 85 if (surface.InFrontOf(minAbove,axis)) minA 106 if (surface.InFrontOf(minAbove,axis)) minAbove = surface; 86 } 107 } 87 else if (smax < minLimit) << 108 else if (max < minLimit) 88 { 109 { 89 // 110 // 90 // Nearest surface below minimum limit 111 // Nearest surface below minimum limit 91 // 112 // 92 if (surface.BehindOf(maxBelow,axis)) maxBe 113 if (surface.BehindOf(maxBelow,axis)) maxBelow = surface; 93 } 114 } 94 else 115 else 95 { 116 { 96 // 117 // 97 // Max and min surfaces inside 118 // Max and min surfaces inside 98 // 119 // 99 if (surface.BehindOf(maxSurface,axis)) max 120 if (surface.BehindOf(maxSurface,axis)) maxSurface = surface; 100 if (surface.InFrontOf(minSurface,axis)) mi 121 if (surface.InFrontOf(minSurface,axis)) minSurface = surface; 101 } 122 } 102 } 123 } 103 124 >> 125 >> 126 >> 127 // 104 // GetExtent 128 // GetExtent 105 // 129 // 106 // Return extent after processing all surfaces 130 // Return extent after processing all surfaces 107 // 131 // 108 G4bool G4SolidExtentList::GetExtent( G4double& << 132 G4bool G4SolidExtentList::GetExtent( G4double &min, G4double &max ) const 109 { 133 { 110 G4double kCarTolerance = G4GeometryTolerance 134 G4double kCarTolerance = G4GeometryTolerance::GetInstance() 111 ->GetSurfaceToleran 135 ->GetSurfaceTolerance(); 112 // 136 // 113 // Did we have any surfaces within the limit 137 // Did we have any surfaces within the limits? 114 // 138 // 115 if (minSurface.Empty()) 139 if (minSurface.Empty()) 116 { 140 { 117 // 141 // 118 // Nothing! Do we have anything above? 142 // Nothing! Do we have anything above? 119 // 143 // 120 if (minAbove.Empty()) return false; 144 if (minAbove.Empty()) return false; 121 145 122 // 146 // 123 // Yup. Is it facing inwards? 147 // Yup. Is it facing inwards? 124 // 148 // 125 if (minAbove.GetNormal().operator()(axis) 149 if (minAbove.GetNormal().operator()(axis) < 0) return false; 126 150 127 // 151 // 128 // No. We must be entirely within the soli 152 // No. We must be entirely within the solid 129 // 153 // 130 emax = maxLimit + kCarTolerance; << 154 max = maxLimit + kCarTolerance; 131 emin = minLimit - kCarTolerance; << 155 min = minLimit - kCarTolerance; 132 return true; 156 return true; 133 } 157 } 134 158 135 // 159 // 136 // Check max surface 160 // Check max surface 137 // 161 // 138 if (maxSurface.GetNormal().operator()(axis) 162 if (maxSurface.GetNormal().operator()(axis) < 0) 139 { 163 { 140 // 164 // 141 // Inward facing: max limit must be embedd 165 // Inward facing: max limit must be embedded within solid 142 // 166 // 143 emax = maxLimit + kCarTolerance; << 167 max = maxLimit + kCarTolerance; 144 } 168 } 145 else 169 else 146 { 170 { 147 G4double sMin=0., sMax=0.; << 171 G4double sMin, sMax; 148 maxSurface.GetExtent( axis, sMin, sMax ); 172 maxSurface.GetExtent( axis, sMin, sMax ); 149 emax = ( (sMax > maxLimit) ? maxLimit : sM << 173 max = ( (sMax > maxLimit) ? maxLimit : sMax ) + kCarTolerance; 150 } 174 } 151 175 152 // 176 // 153 // Check min surface 177 // Check min surface 154 // 178 // 155 if (minSurface.GetNormal().operator()(axis) 179 if (minSurface.GetNormal().operator()(axis) > 0) 156 { 180 { 157 // 181 // 158 // Inward facing: max limit must be embedd 182 // Inward facing: max limit must be embedded within solid 159 // 183 // 160 emin = minLimit - kCarTolerance; << 184 min = minLimit - kCarTolerance; 161 } 185 } 162 else 186 else 163 { 187 { 164 G4double sMin=0., sMax=0.; << 188 G4double sMin, sMax; 165 minSurface.GetExtent( axis, sMin, sMax ); 189 minSurface.GetExtent( axis, sMin, sMax ); 166 emin = ( (sMin < minLimit) ? minLimit : sM << 190 min = ( (sMin < minLimit) ? minLimit : sMin ) - kCarTolerance; 167 } 191 } 168 192 169 return true; 193 return true; 170 } 194 } 171 195 172 196