Geant4 Cross Reference |
>> 1 // This code implementation is the intellectual property of >> 2 // the GEANT4 collaboration. 1 // 3 // 2 // ******************************************* << 4 // By copying, distributing or modifying the Program (or any work 3 // * License and Disclaimer << 5 // based on the Program) you indicate your acceptance of this statement, 4 // * << 6 // and all its terms. 5 // * The Geant4 software is copyright of th << 6 // * the Geant4 Collaboration. It is provided << 7 // * conditions of the Geant4 Software License << 8 // * LICENSE and available at http://cern.ch/ << 9 // * include a list of copyright holders. << 10 // * << 11 // * Neither the authors of this software syst << 12 // * institutes,nor the agencies providing fin << 13 // * work make any representation or warran << 14 // * regarding this software system or assum << 15 // * use. Please see the license in the file << 16 // * for the full disclaimer and the limitatio << 17 // * << 18 // * This code implementation is the result << 19 // * technical work of the GEANT4 collaboratio << 20 // * By using, copying, modifying or distri << 21 // * any work based on the software) you ag << 22 // * use in resulting scientific publicati << 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* << 25 // 7 // 26 // G4VoxelLimits << 8 // $Id: G4VoxelLimits.hh,v 1.1.12.1 1999/12/07 20:48:12 gunter Exp $ >> 9 // GEANT4 tag $Name: geant4-01-00 $ 27 // 10 // 28 // Class description: << 11 // class G4VoxelLimits 29 // 12 // 30 // Represents limitation/restrictions of space << 13 // Represents limitation/restrictions of space , where restrictions 31 // are only made perpendicular to the cartesia 14 // are only made perpendicular to the cartesian axes. 32 // 15 // >> 16 // >> 17 // Member functions: >> 18 // >> 19 // G4VoxelLimits() >> 20 // Construct, with volume unrestricted >> 21 // ~G4VoxelLimits() >> 22 // No actions. >> 23 // AddLimit(const EAxis pAxis, const G4double pMin,const G4double pMax) >> 24 // Restict the volume to between specified min and max along the given axis. >> 25 // Cartesian axes only, pMin<=pMax. >> 26 // G4double GetMaxXExtent() const >> 27 // Return maximum x extent >> 28 // G4double GetMaxYExtent() const >> 29 // Return maximum y extent >> 30 // G4double GetMaxZExtent() const >> 31 // Return maximum z extent >> 32 // G4double GetMinXExtent() const >> 33 // Return minimum x extent >> 34 // G4double GetMinYExtent() const >> 35 // Return minimum y extent >> 36 // G4double GetMinZExtent() const >> 37 // Return minimum z extent >> 38 // G4double GetMaxExtent(const EAxis pAxis) const >> 39 // Return maximum extent of volume along specified axis. >> 40 // G4double GetMinExtent(const EAxis pAxis) const >> 41 // Return maximum extent of volume along specified axis. >> 42 // G4bool IsLimited() const >> 43 // Return true if limited along any axis >> 44 // G4bool IsLimited(const EAxis pAxis) const >> 45 // Return true if the specified axis is resticted/limited. >> 46 // G4bool IsXLimited() const >> 47 // Return true if the x axis is limited >> 48 // G4bool IsYLimited() const >> 49 // Return true if the y axis is limited >> 50 // G4bool IsZLimited() const >> 51 // Return true if the z axis is limited >> 52 // >> 53 // G4bool ClipToLimits(G4ThreeVector& pStart,G4ThreeVector& pEnd) >> 54 // Clip the line segment pStart->pEnd to the volume described by the >> 55 // current limits. Return true if the line remains after clipping, >> 56 // else false, and leave the vectors in an undefined state. >> 57 // >> 58 // G4bool Inside(const G4ThreeVector& pVec) const >> 59 // Return true if the specified vector is inside/on boundaries >> 60 // of limits >> 61 // >> 62 // G4int OutCode(const G4ThreeVector& pVec) const >> 63 // Calculate the `outcode' for the specified vector. >> 64 // Intended for use during clipping against the limits >> 65 // The bits are set given following conditions: >> 66 // 0 pVec.x()<fxAxisMin && IsXLimited() >> 67 // 1 pVec.x()>fxAxisMax && IsXLimited() >> 68 // 2 pVec.y()<fyAxisMin && IsYLimited() >> 69 // 3 pVec.y()>fyAxisMax && IsYLimited() >> 70 // 4 pVec.z()<fzAxisMin && IsZLimited() >> 71 // 5 pVec.z()>fzAxisMax && IsZLimited() >> 72 // 33 // Member data: 73 // Member data: 34 // 74 // 35 // G4double fxAxisMin,fxAxisMax 75 // G4double fxAxisMin,fxAxisMax 36 // G4double fyAxisMin,fyAxisMax 76 // G4double fyAxisMin,fyAxisMax 37 // G4double fzAxisMin,fzAxisMax 77 // G4double fzAxisMin,fzAxisMax 38 // - The min and max values along each axis. + << 78 // The min and max values along each axis. +-kInfinity if not restricted >> 79 // >> 80 // >> 81 // operators: >> 82 // >> 83 // ostream& operator << (ostream& os, const G4VoxelLimits& pLim); >> 84 // >> 85 // Print the limits to the stream in the form: >> 86 // "{(xmin,xmax) (ymin,ymax) (zmin,zmax)}" Replace (xmin,xmax) by (-,-) >> 87 // when not limited. >> 88 // >> 89 // Notes: >> 90 // >> 91 // Beware no break statements after returns in switch(pAxis)s >> 92 // >> 93 // History: >> 94 // 13.07.95 P.Kent Initial version. 39 95 40 // 13.07.95, P.Kent - Initial version. << 41 // ------------------------------------------- << 42 #ifndef G4VOXELLIMITS_HH 96 #ifndef G4VOXELLIMITS_HH 43 #define G4VOXELLIMITS_HH 1 << 97 #define G4VOXELLIMITS_HH 44 98 45 #include "G4Types.hh" << 99 #include "globals.hh" 46 #include "geomdefs.hh" 100 #include "geomdefs.hh" 47 101 48 #include "G4ThreeVector.hh" 102 #include "G4ThreeVector.hh" 49 103 50 #include <assert.h> 104 #include <assert.h> 51 105 >> 106 class ostream; >> 107 52 class G4VoxelLimits 108 class G4VoxelLimits 53 { 109 { 54 public: << 110 public: 55 << 111 // Constructor - initialise to be unlimited 56 G4VoxelLimits() = default; << 112 G4VoxelLimits() : fxAxisMin(-kInfinity),fxAxisMax(kInfinity), 57 // Constructor - initialise to be unlimi << 113 fyAxisMin(-kInfinity),fyAxisMax(kInfinity), 58 << 114 fzAxisMin(-kInfinity),fzAxisMax(kInfinity) 59 ~G4VoxelLimits() = default; << 115 {;} 60 // Destructor. No actions. << 116 61 << 117 // G4VoxelLimits(const G4VoxelLimits& v); 62 void AddLimit(const EAxis pAxis, const G4d << 118 63 // Restrict the volume to between specif << 119 // Destructor 64 // given axis. Cartesian axes only, pMin << 120 ~G4VoxelLimits() {;} 65 << 121 66 G4double GetMaxXExtent() const; << 122 // Further restict limits 67 // Return maximum x extent. << 123 void AddLimit(const EAxis pAxis, const G4double pMin,const G4double pMax); 68 G4double GetMaxYExtent() const; << 124 69 // Return maximum y extent. << 125 // Return appropriate max limit 70 G4double GetMaxZExtent() const; << 126 G4double GetMaxXExtent() const 71 // Return maximum z extent. << 127 { 72 << 128 return fxAxisMax; 73 G4double GetMinXExtent() const; << 129 } 74 // Return minimum x extent. << 130 G4double GetMaxYExtent() const 75 G4double GetMinYExtent() const; << 131 { 76 // Return minimum y extent. << 132 return fyAxisMax; 77 G4double GetMinZExtent() const; << 133 } 78 // Return minimum z extent. << 134 G4double GetMaxZExtent() const 79 << 135 { 80 G4double GetMaxExtent(const EAxis pAxis) c << 136 return fzAxisMax; 81 // Return maximum extent of volume along << 137 } 82 G4double GetMinExtent(const EAxis pAxis) c << 138 83 // Return minimum extent of volume along << 139 // Return appropriate min limit 84 << 140 G4double GetMinXExtent() const 85 G4bool IsXLimited() const; << 141 { 86 // Return true if the x axis is limited. << 142 return fxAxisMin; 87 G4bool IsYLimited() const; << 143 } 88 // Return true if the y axis is limited. << 144 G4double GetMinYExtent() const 89 G4bool IsZLimited() const; << 145 { 90 // Return true if the z axis is limited. << 146 return fyAxisMin; 91 << 147 } 92 G4bool IsLimited() const; << 148 G4double GetMinZExtent() const 93 // Return true if limited along any axis << 149 { 94 G4bool IsLimited(const EAxis pAxis) const; << 150 return fzAxisMin; 95 // Return true if the specified axis is << 151 } 96 << 152 97 G4bool ClipToLimits(G4ThreeVector& pStart, << 153 // Return specified max limit 98 // Clip the line segment pStart->pEnd to << 154 G4double GetMaxExtent(const EAxis pAxis) const 99 // current limits. Return true if the li << 155 { 100 // else false, and leave the vectors in << 156 if (pAxis==kXAxis) 101 << 157 { 102 G4bool Inside(const G4ThreeVector& pVec) c << 158 return GetMaxXExtent(); 103 // Return true if the specified vector i << 159 } >> 160 else if (pAxis==kYAxis) >> 161 { >> 162 return GetMaxYExtent(); >> 163 } >> 164 else >> 165 { >> 166 assert(pAxis==kZAxis); >> 167 return GetMaxZExtent(); >> 168 } >> 169 } >> 170 >> 171 //Return min limit >> 172 G4double GetMinExtent(const EAxis pAxis) const >> 173 { >> 174 if (pAxis==kXAxis) >> 175 { >> 176 return GetMinXExtent(); >> 177 } >> 178 else if (pAxis==kYAxis) >> 179 { >> 180 return GetMinYExtent(); >> 181 } >> 182 else >> 183 { >> 184 assert(pAxis==kZAxis); >> 185 return GetMinZExtent(); >> 186 } >> 187 } >> 188 >> 189 // Return true if x axis is limited >> 190 G4bool IsXLimited() const >> 191 { >> 192 return (fxAxisMin==-kInfinity&&fxAxisMax==kInfinity) ? false : true; >> 193 } >> 194 // Return true if y axis is limited >> 195 G4bool IsYLimited() const >> 196 { >> 197 return (fyAxisMin==-kInfinity&&fyAxisMax==kInfinity) ? false : true; >> 198 } >> 199 // Return true if z axis is limited >> 200 G4bool IsZLimited() const >> 201 { >> 202 return (fzAxisMin==-kInfinity&&fzAxisMax==kInfinity) ? false : true; >> 203 } >> 204 >> 205 // Return true if limited along any axis >> 206 G4bool IsLimited() const >> 207 { >> 208 return (IsXLimited()||IsYLimited()||IsZLimited()); >> 209 } >> 210 >> 211 // Return true if specified axis is limited >> 212 G4bool IsLimited(const EAxis pAxis) const >> 213 { >> 214 if (pAxis==kXAxis) >> 215 { >> 216 return IsXLimited(); >> 217 } >> 218 else if (pAxis==kYAxis) >> 219 { >> 220 return IsYLimited(); >> 221 } >> 222 else >> 223 { >> 224 assert(pAxis==kZAxis); >> 225 return IsZLimited(); >> 226 } >> 227 } >> 228 >> 229 G4bool ClipToLimits(G4ThreeVector& pStart,G4ThreeVector& pEnd) const; >> 230 >> 231 // Return true if specified vector is inside/on boundaries of limits >> 232 G4bool Inside(const G4ThreeVector& pVec) const >> 233 { >> 234 return ((GetMinXExtent()<=pVec.x()) && >> 235 (GetMaxXExtent()>=pVec.x()) && >> 236 (GetMinYExtent()<=pVec.y()) && >> 237 (GetMaxYExtent()>=pVec.y()) && >> 238 (GetMinZExtent()<=pVec.z()) && >> 239 (GetMaxZExtent()>=pVec.z()) ) ? true : false; >> 240 } 104 241 105 G4int OutCode(const G4ThreeVector& pVec) c 242 G4int OutCode(const G4ThreeVector& pVec) const; 106 // Calculate the `outcode' for the speci << 107 // Intended for use during clipping agai << 108 // The bits are set given the following << 109 // 0 pVec.x()<fxAxisMin && IsXLim << 110 // 1 pVec.x()>fxAxisMax && IsXLim << 111 // 2 pVec.y()<fyAxisMin && IsYLim << 112 // 3 pVec.y()>fyAxisMax && IsYLim << 113 // 4 pVec.z()<fzAxisMin && IsZLim << 114 // 5 pVec.z()>fzAxisMax && IsZLim << 115 << 116 private: << 117 << 118 G4double fxAxisMin = -kInfinity, fxAxisMax << 119 G4double fyAxisMin = -kInfinity, fyAxisMax << 120 G4double fzAxisMin = -kInfinity, fzAxisMax << 121 }; << 122 243 123 #include "G4VoxelLimits.icc" << 244 private: >> 245 G4double fxAxisMin,fxAxisMax; >> 246 G4double fyAxisMin,fyAxisMax; >> 247 G4double fzAxisMin,fzAxisMax; >> 248 }; 124 249 125 std::ostream& operator << (std::ostream& os, c << 250 ostream& operator << (ostream& os, const G4VoxelLimits& pLim); 126 // Print the limits to the stream in the for << 127 // "{(xmin,xmax) (ymin,ymax) (zmin,zmax)}" << 128 // Replace (xmin,xmax) by (-,-) when not li << 129 251 130 #endif 252 #endif 131 253