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 // Implementation for G4UTrd wrapper class << 27 // 26 // 28 // 13.09.13 G.Cosmo, CERN/PH << 27 // $Id:$ >> 28 // >> 29 // >> 30 // Implementation for G4UTrd wrapper class 29 // ------------------------------------------- 31 // -------------------------------------------------------------------- 30 32 31 #include "G4Trd.hh" 33 #include "G4Trd.hh" 32 #include "G4UTrd.hh" 34 #include "G4UTrd.hh" 33 << 34 #if ( defined(G4GEOM_USE_USOLIDS) || defined(G << 35 << 36 #include "G4AffineTransform.hh" << 37 #include "G4VPVParameterisation.hh" 35 #include "G4VPVParameterisation.hh" 38 #include "G4BoundingEnvelope.hh" << 39 << 40 using namespace CLHEP; << 41 36 42 ////////////////////////////////////////////// 37 ///////////////////////////////////////////////////////////////////////// 43 // 38 // 44 // Constructor - check & set half widths 39 // Constructor - check & set half widths 45 // 40 // 46 G4UTrd::G4UTrd(const G4String& pName, 41 G4UTrd::G4UTrd(const G4String& pName, 47 G4double pdx1, G4double 42 G4double pdx1, G4double pdx2, 48 G4double pdy1, G4double 43 G4double pdy1, G4double pdy2, 49 G4double pdz) 44 G4double pdz) 50 : Base_t(pName, pdx1, pdx2, pdy1, pdy2, pdz) << 45 : G4USolid(pName, new UTrd(pName, pdx1, pdx2, pdy1, pdy2, pdz)) 51 { 46 { 52 } 47 } 53 48 54 ////////////////////////////////////////////// 49 /////////////////////////////////////////////////////////////////////// 55 // 50 // 56 // Fake default constructor - sets only member 51 // Fake default constructor - sets only member data and allocates memory 57 // for usage restri 52 // for usage restricted to object persistency. 58 // 53 // 59 G4UTrd::G4UTrd( __void__& a ) 54 G4UTrd::G4UTrd( __void__& a ) 60 : Base_t(a) << 55 : G4USolid(a) 61 { 56 { 62 } 57 } 63 58 64 ////////////////////////////////////////////// 59 ////////////////////////////////////////////////////////////////////////// 65 // 60 // 66 // Destructor 61 // Destructor 67 // 62 // 68 G4UTrd::~G4UTrd() = default; << 63 G4UTrd::~G4UTrd() >> 64 { >> 65 } 69 66 70 ////////////////////////////////////////////// 67 ////////////////////////////////////////////////////////////////////////// 71 // 68 // 72 // Copy constructor 69 // Copy constructor 73 // 70 // 74 G4UTrd::G4UTrd(const G4UTrd& rhs) 71 G4UTrd::G4UTrd(const G4UTrd& rhs) 75 : Base_t(rhs) << 72 : G4USolid(rhs) 76 { 73 { 77 } 74 } 78 75 79 ////////////////////////////////////////////// 76 ////////////////////////////////////////////////////////////////////////// 80 // 77 // 81 // Assignment operator 78 // Assignment operator 82 // 79 // 83 G4UTrd& G4UTrd::operator = (const G4UTrd& rhs) 80 G4UTrd& G4UTrd::operator = (const G4UTrd& rhs) 84 { 81 { 85 // Check assignment to self 82 // Check assignment to self 86 // 83 // 87 if (this == &rhs) { return *this; } 84 if (this == &rhs) { return *this; } 88 85 89 // Copy base class data 86 // Copy base class data 90 // 87 // 91 Base_t::operator=(rhs); << 88 G4USolid::operator=(rhs); 92 89 93 return *this; 90 return *this; 94 } 91 } 95 92 96 ////////////////////////////////////////////// << 97 // << 98 // Accessors & modifiers << 99 << 100 G4double G4UTrd::GetXHalfLength1() const << 101 { << 102 return dx1(); << 103 } << 104 G4double G4UTrd::GetXHalfLength2() const << 105 { << 106 return dx2(); << 107 } << 108 G4double G4UTrd::GetYHalfLength1() const << 109 { << 110 return dy1(); << 111 } << 112 G4double G4UTrd::GetYHalfLength2() const << 113 { << 114 return dy2(); << 115 } << 116 G4double G4UTrd::GetZHalfLength() const << 117 { << 118 return dz(); << 119 } << 120 << 121 void G4UTrd::SetXHalfLength1(G4double val) << 122 { << 123 Base_t::SetXHalfLength1(val); << 124 fRebuildPolyhedron = true; << 125 } << 126 void G4UTrd::SetXHalfLength2(G4double val) << 127 { << 128 Base_t::SetXHalfLength2(val); << 129 fRebuildPolyhedron = true; << 130 } << 131 void G4UTrd::SetYHalfLength1(G4double val) << 132 { << 133 Base_t::SetYHalfLength1(val); << 134 fRebuildPolyhedron = true; << 135 } << 136 void G4UTrd::SetYHalfLength2(G4double val) << 137 { << 138 Base_t::SetYHalfLength2(val); << 139 fRebuildPolyhedron = true; << 140 } << 141 void G4UTrd::SetZHalfLength(G4double val) << 142 { << 143 Base_t::SetZHalfLength(val); << 144 fRebuildPolyhedron = true; << 145 } << 146 void G4UTrd::SetAllParameters(G4double pdx1, G << 147 G4double pdy1, G << 148 { << 149 Base_t::SetAllParameters(pdx1, pdx2, pdy1, p << 150 fRebuildPolyhedron = true; << 151 } << 152 << 153 ////////////////////////////////////////////// 93 ///////////////////////////////////////////////////////////////////////// 154 // 94 // 155 // Dispatch to parameterisation for replicatio 95 // Dispatch to parameterisation for replication mechanism dimension 156 // computation & modification. 96 // computation & modification. 157 // 97 // 158 void G4UTrd::ComputeDimensions( G4VPVPara 98 void G4UTrd::ComputeDimensions( G4VPVParameterisation* p, 159 const G4int n, 99 const G4int n, 160 const G4VPhysic 100 const G4VPhysicalVolume* pRep) 161 { 101 { 162 p->ComputeDimensions(*(G4Trd*)this,n,pRep); 102 p->ComputeDimensions(*(G4Trd*)this,n,pRep); 163 } 103 } 164 104 165 ////////////////////////////////////////////// 105 ////////////////////////////////////////////////////////////////////////// 166 // 106 // 167 // Make a clone of the object 107 // Make a clone of the object 168 108 169 G4VSolid* G4UTrd::Clone() const 109 G4VSolid* G4UTrd::Clone() const 170 { 110 { 171 return new G4UTrd(*this); 111 return new G4UTrd(*this); 172 } 112 } 173 << 174 ////////////////////////////////////////////// << 175 // << 176 // Get bounding box << 177 << 178 void G4UTrd::BoundingLimits(G4ThreeVector& pMi << 179 { << 180 static G4bool checkBBox = true; << 181 << 182 G4double dx1 = GetXHalfLength1(); << 183 G4double dx2 = GetXHalfLength2(); << 184 G4double dy1 = GetYHalfLength1(); << 185 G4double dy2 = GetYHalfLength2(); << 186 G4double dz = GetZHalfLength(); << 187 << 188 G4double xmax = std::max(dx1,dx2); << 189 G4double ymax = std::max(dy1,dy2); << 190 pMin.set(-xmax,-ymax,-dz); << 191 pMax.set( xmax, ymax, dz); << 192 << 193 // Check correctness of the bounding box << 194 // << 195 if (pMin.x() >= pMax.x() || pMin.y() >= pMax << 196 { << 197 std::ostringstream message; << 198 message << "Bad bounding box (min >= max) << 199 << GetName() << " !" << 200 << "\npMin = " << pMin << 201 << "\npMax = " << pMax; << 202 G4Exception("G4UTrd::BoundingLimits()", "G << 203 JustWarning, message); << 204 StreamInfo(G4cout); << 205 } << 206 << 207 // Check consistency of bounding boxes << 208 // << 209 if (checkBBox) << 210 { << 211 U3Vector vmin, vmax; << 212 Extent(vmin,vmax); << 213 if (std::abs(pMin.x()-vmin.x()) > kCarTole << 214 std::abs(pMin.y()-vmin.y()) > kCarTole << 215 std::abs(pMin.z()-vmin.z()) > kCarTole << 216 std::abs(pMax.x()-vmax.x()) > kCarTole << 217 std::abs(pMax.y()-vmax.y()) > kCarTole << 218 std::abs(pMax.z()-vmax.z()) > kCarTole << 219 { << 220 std::ostringstream message; << 221 message << "Inconsistency in bounding bo << 222 << GetName() << " !" << 223 << "\nBBox min: wrapper = " << p << 224 << "\nBBox max: wrapper = " << p << 225 G4Exception("G4UTrd::BoundingLimits()", << 226 JustWarning, message); << 227 checkBBox = false; << 228 } << 229 } << 230 } << 231 << 232 ////////////////////////////////////////////// << 233 // << 234 // Calculate extent under transform and specif << 235 << 236 G4bool << 237 G4UTrd::CalculateExtent(const EAxis pAxis, << 238 const G4VoxelLimits& p << 239 const G4AffineTransfor << 240 G4double& pMin, << 241 { << 242 G4ThreeVector bmin, bmax; << 243 G4bool exist; << 244 << 245 // Check bounding box (bbox) << 246 // << 247 BoundingLimits(bmin,bmax); << 248 G4BoundingEnvelope bbox(bmin,bmax); << 249 #ifdef G4BBOX_EXTENT << 250 if (true) return bbox.CalculateExtent(pAxis, << 251 #endif << 252 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVox << 253 { << 254 return exist = pMin < pMax; << 255 } << 256 << 257 // Set bounding envelope (benv) and calculat << 258 // << 259 G4double dx1 = GetXHalfLength1(); << 260 G4double dx2 = GetXHalfLength2(); << 261 G4double dy1 = GetYHalfLength1(); << 262 G4double dy2 = GetYHalfLength2(); << 263 G4double dz = GetZHalfLength(); << 264 << 265 G4ThreeVectorList baseA(4), baseB(4); << 266 baseA[0].set(-dx1,-dy1,-dz); << 267 baseA[1].set( dx1,-dy1,-dz); << 268 baseA[2].set( dx1, dy1,-dz); << 269 baseA[3].set(-dx1, dy1,-dz); << 270 baseB[0].set(-dx2,-dy2, dz); << 271 baseB[1].set( dx2,-dy2, dz); << 272 baseB[2].set( dx2, dy2, dz); << 273 baseB[3].set(-dx2, dy2, dz); << 274 << 275 std::vector<const G4ThreeVectorList *> polyg << 276 polygons[0] = &baseA; << 277 polygons[1] = &baseB; << 278 << 279 G4BoundingEnvelope benv(bmin,bmax,polygons); << 280 exist = benv.CalculateExtent(pAxis,pVoxelLim << 281 return exist; << 282 } << 283 << 284 ////////////////////////////////////////////// << 285 // << 286 // Create polyhedron for visualization << 287 // << 288 G4Polyhedron* G4UTrd::CreatePolyhedron() const << 289 { << 290 return new G4PolyhedronTrd2(GetXHalfLength1( << 291 GetXHalfLength2( << 292 GetYHalfLength1( << 293 GetYHalfLength2( << 294 GetZHalfLength() << 295 } << 296 << 297 #endif // G4GEOM_USE_USOLIDS << 298 113