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.3 1999/12/15 16:40:07 gcosmo Exp $ >> 9 // GEANT4 tag $Name: geant4-01-01 $ 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 // G4std::ostream& operator << (G4std::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" >> 103 #include "g4std/iostream" 49 104 50 #include <assert.h> 105 #include <assert.h> 51 106 52 class G4VoxelLimits 107 class G4VoxelLimits 53 { 108 { 54 public: << 109 public: 55 << 110 // Constructor - initialise to be unlimited 56 G4VoxelLimits() = default; << 111 G4VoxelLimits() : fxAxisMin(-kInfinity),fxAxisMax(kInfinity), 57 // Constructor - initialise to be unlimi << 112 fyAxisMin(-kInfinity),fyAxisMax(kInfinity), 58 << 113 fzAxisMin(-kInfinity),fzAxisMax(kInfinity) 59 ~G4VoxelLimits() = default; << 114 {;} 60 // Destructor. No actions. << 115 61 << 116 // G4VoxelLimits(const G4VoxelLimits& v); 62 void AddLimit(const EAxis pAxis, const G4d << 117 63 // Restrict the volume to between specif << 118 // Destructor 64 // given axis. Cartesian axes only, pMin << 119 ~G4VoxelLimits() {;} 65 << 120 66 G4double GetMaxXExtent() const; << 121 // Further restict limits 67 // Return maximum x extent. << 122 void AddLimit(const EAxis pAxis, const G4double pMin,const G4double pMax); 68 G4double GetMaxYExtent() const; << 123 69 // Return maximum y extent. << 124 // Return appropriate max limit 70 G4double GetMaxZExtent() const; << 125 G4double GetMaxXExtent() const 71 // Return maximum z extent. << 126 { 72 << 127 return fxAxisMax; 73 G4double GetMinXExtent() const; << 128 } 74 // Return minimum x extent. << 129 G4double GetMaxYExtent() const 75 G4double GetMinYExtent() const; << 130 { 76 // Return minimum y extent. << 131 return fyAxisMax; 77 G4double GetMinZExtent() const; << 132 } 78 // Return minimum z extent. << 133 G4double GetMaxZExtent() const 79 << 134 { 80 G4double GetMaxExtent(const EAxis pAxis) c << 135 return fzAxisMax; 81 // Return maximum extent of volume along << 136 } 82 G4double GetMinExtent(const EAxis pAxis) c << 137 83 // Return minimum extent of volume along << 138 // Return appropriate min limit 84 << 139 G4double GetMinXExtent() const 85 G4bool IsXLimited() const; << 140 { 86 // Return true if the x axis is limited. << 141 return fxAxisMin; 87 G4bool IsYLimited() const; << 142 } 88 // Return true if the y axis is limited. << 143 G4double GetMinYExtent() const 89 G4bool IsZLimited() const; << 144 { 90 // Return true if the z axis is limited. << 145 return fyAxisMin; 91 << 146 } 92 G4bool IsLimited() const; << 147 G4double GetMinZExtent() const 93 // Return true if limited along any axis << 148 { 94 G4bool IsLimited(const EAxis pAxis) const; << 149 return fzAxisMin; 95 // Return true if the specified axis is << 150 } 96 << 151 97 G4bool ClipToLimits(G4ThreeVector& pStart, << 152 // Return specified max limit 98 // Clip the line segment pStart->pEnd to << 153 G4double GetMaxExtent(const EAxis pAxis) const 99 // current limits. Return true if the li << 154 { 100 // else false, and leave the vectors in << 155 if (pAxis==kXAxis) 101 << 156 { 102 G4bool Inside(const G4ThreeVector& pVec) c << 157 return GetMaxXExtent(); 103 // Return true if the specified vector i << 158 } >> 159 else if (pAxis==kYAxis) >> 160 { >> 161 return GetMaxYExtent(); >> 162 } >> 163 else >> 164 { >> 165 assert(pAxis==kZAxis); >> 166 return GetMaxZExtent(); >> 167 } >> 168 } >> 169 >> 170 //Return min limit >> 171 G4double GetMinExtent(const EAxis pAxis) const >> 172 { >> 173 if (pAxis==kXAxis) >> 174 { >> 175 return GetMinXExtent(); >> 176 } >> 177 else if (pAxis==kYAxis) >> 178 { >> 179 return GetMinYExtent(); >> 180 } >> 181 else >> 182 { >> 183 assert(pAxis==kZAxis); >> 184 return GetMinZExtent(); >> 185 } >> 186 } >> 187 >> 188 // Return true if x axis is limited >> 189 G4bool IsXLimited() const >> 190 { >> 191 return (fxAxisMin==-kInfinity&&fxAxisMax==kInfinity) ? false : true; >> 192 } >> 193 // Return true if y axis is limited >> 194 G4bool IsYLimited() const >> 195 { >> 196 return (fyAxisMin==-kInfinity&&fyAxisMax==kInfinity) ? false : true; >> 197 } >> 198 // Return true if z axis is limited >> 199 G4bool IsZLimited() const >> 200 { >> 201 return (fzAxisMin==-kInfinity&&fzAxisMax==kInfinity) ? false : true; >> 202 } >> 203 >> 204 // Return true if limited along any axis >> 205 G4bool IsLimited() const >> 206 { >> 207 return (IsXLimited()||IsYLimited()||IsZLimited()); >> 208 } >> 209 >> 210 // Return true if specified axis is limited >> 211 G4bool IsLimited(const EAxis pAxis) const >> 212 { >> 213 if (pAxis==kXAxis) >> 214 { >> 215 return IsXLimited(); >> 216 } >> 217 else if (pAxis==kYAxis) >> 218 { >> 219 return IsYLimited(); >> 220 } >> 221 else >> 222 { >> 223 assert(pAxis==kZAxis); >> 224 return IsZLimited(); >> 225 } >> 226 } >> 227 >> 228 G4bool ClipToLimits(G4ThreeVector& pStart,G4ThreeVector& pEnd) const; >> 229 >> 230 // Return true if specified vector is inside/on boundaries of limits >> 231 G4bool Inside(const G4ThreeVector& pVec) const >> 232 { >> 233 return ((GetMinXExtent()<=pVec.x()) && >> 234 (GetMaxXExtent()>=pVec.x()) && >> 235 (GetMinYExtent()<=pVec.y()) && >> 236 (GetMaxYExtent()>=pVec.y()) && >> 237 (GetMinZExtent()<=pVec.z()) && >> 238 (GetMaxZExtent()>=pVec.z()) ) ? true : false; >> 239 } 104 240 105 G4int OutCode(const G4ThreeVector& pVec) c 241 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 242 123 #include "G4VoxelLimits.icc" << 243 private: >> 244 G4double fxAxisMin,fxAxisMax; >> 245 G4double fyAxisMin,fyAxisMax; >> 246 G4double fzAxisMin,fzAxisMax; >> 247 }; 124 248 125 std::ostream& operator << (std::ostream& os, c << 249 G4std::ostream& operator << (G4std::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 250 130 #endif 251 #endif 131 252