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 G4UBox wrapper class << 27 // 26 // 28 // 13.09.13 G.Cosmo, CERN/PH << 27 // $Id:$ >> 28 // >> 29 // >> 30 // Implementation for G4UBox wrapper class 29 // ------------------------------------------- 31 // -------------------------------------------------------------------- 30 32 31 #include "G4Box.hh" 33 #include "G4Box.hh" 32 #include "G4UBox.hh" 34 #include "G4UBox.hh" 33 35 34 #if ( defined(G4GEOM_USE_USOLIDS) || defined(G 36 #if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) ) 35 37 36 #include "G4AffineTransform.hh" 38 #include "G4AffineTransform.hh" 37 #include "G4VPVParameterisation.hh" 39 #include "G4VPVParameterisation.hh" 38 #include "G4BoundingEnvelope.hh" 40 #include "G4BoundingEnvelope.hh" 39 41 40 using namespace CLHEP; 42 using namespace CLHEP; 41 43 42 ////////////////////////////////////////////// 44 //////////////////////////////////////////////////////////////////////// 43 // 45 // 44 // Constructor - check & set half widths 46 // Constructor - check & set half widths 45 47 46 48 47 G4UBox::G4UBox(const G4String& pName, 49 G4UBox::G4UBox(const G4String& pName, 48 G4double pX, 50 G4double pX, 49 G4double pY, 51 G4double pY, 50 G4double pZ) 52 G4double pZ) 51 : Base_t(pName, pX, pY, pZ) 53 : Base_t(pName, pX, pY, pZ) 52 { 54 { 53 } 55 } 54 56 55 ////////////////////////////////////////////// 57 ////////////////////////////////////////////////////////////////////////// 56 // 58 // 57 // Fake default constructor - sets only member 59 // Fake default constructor - sets only member data and allocates memory 58 // for usage restri 60 // for usage restricted to object persistency. 59 61 60 G4UBox::G4UBox( __void__& a ) 62 G4UBox::G4UBox( __void__& a ) 61 : Base_t(a) 63 : Base_t(a) 62 { 64 { 63 } 65 } 64 66 65 ////////////////////////////////////////////// 67 ////////////////////////////////////////////////////////////////////////// 66 // 68 // 67 // Destructor 69 // Destructor 68 70 69 G4UBox::~G4UBox() = default; << 71 G4UBox::~G4UBox() >> 72 { >> 73 } 70 74 71 ////////////////////////////////////////////// 75 ////////////////////////////////////////////////////////////////////////// 72 // 76 // 73 // Copy constructor 77 // Copy constructor 74 78 75 G4UBox::G4UBox(const G4UBox& rhs) 79 G4UBox::G4UBox(const G4UBox& rhs) 76 : Base_t(rhs) 80 : Base_t(rhs) 77 { 81 { 78 } 82 } 79 83 80 ////////////////////////////////////////////// 84 ////////////////////////////////////////////////////////////////////////// 81 // 85 // 82 // Assignment operator 86 // Assignment operator 83 87 84 G4UBox& G4UBox::operator = (const G4UBox& rhs) 88 G4UBox& G4UBox::operator = (const G4UBox& rhs) 85 { 89 { 86 // Check assignment to self 90 // Check assignment to self 87 // 91 // 88 if (this == &rhs) { return *this; } 92 if (this == &rhs) { return *this; } 89 93 90 // Copy base class data 94 // Copy base class data 91 // 95 // 92 Base_t::operator=(rhs); 96 Base_t::operator=(rhs); 93 97 94 return *this; 98 return *this; 95 } 99 } 96 100 97 ////////////////////////////////////////////// 101 //////////////////////////////////////////////////////////////////////// 98 // 102 // 99 // Accessors & modifiers 103 // Accessors & modifiers 100 104 101 G4double G4UBox::GetXHalfLength() const 105 G4double G4UBox::GetXHalfLength() const 102 { 106 { 103 return x(); 107 return x(); 104 } 108 } 105 G4double G4UBox::GetYHalfLength() const 109 G4double G4UBox::GetYHalfLength() const 106 { 110 { 107 return y(); 111 return y(); 108 } 112 } 109 G4double G4UBox::GetZHalfLength() const 113 G4double G4UBox::GetZHalfLength() const 110 { 114 { 111 return z(); 115 return z(); 112 } 116 } 113 117 114 void G4UBox::SetXHalfLength(G4double dx) 118 void G4UBox::SetXHalfLength(G4double dx) 115 { 119 { 116 SetX(dx); 120 SetX(dx); 117 fRebuildPolyhedron = true; 121 fRebuildPolyhedron = true; 118 } 122 } 119 void G4UBox::SetYHalfLength(G4double dy) 123 void G4UBox::SetYHalfLength(G4double dy) 120 { 124 { 121 SetY(dy); 125 SetY(dy); 122 fRebuildPolyhedron = true; 126 fRebuildPolyhedron = true; 123 } 127 } 124 void G4UBox::SetZHalfLength(G4double dz) 128 void G4UBox::SetZHalfLength(G4double dz) 125 { 129 { 126 SetZ(dz); 130 SetZ(dz); 127 fRebuildPolyhedron = true; 131 fRebuildPolyhedron = true; 128 } 132 } 129 133 130 ////////////////////////////////////////////// 134 //////////////////////////////////////////////////////////////////////// 131 // 135 // 132 // Dispatch to parameterisation for replicatio 136 // Dispatch to parameterisation for replication mechanism dimension 133 // computation & modification. 137 // computation & modification. 134 138 135 void G4UBox::ComputeDimensions(G4VPVParameteri 139 void G4UBox::ComputeDimensions(G4VPVParameterisation* p, 136 const G4int n, 140 const G4int n, 137 const G4VPhysic 141 const G4VPhysicalVolume* pRep) 138 { 142 { 139 p->ComputeDimensions(*(G4Box*)this,n,pRep); 143 p->ComputeDimensions(*(G4Box*)this,n,pRep); 140 } 144 } 141 145 142 ////////////////////////////////////////////// 146 ////////////////////////////////////////////////////////////////////////// 143 // 147 // 144 // Make a clone of the object 148 // Make a clone of the object 145 149 146 G4VSolid* G4UBox::Clone() const 150 G4VSolid* G4UBox::Clone() const 147 { 151 { 148 return new G4UBox(*this); 152 return new G4UBox(*this); 149 } 153 } 150 154 151 ////////////////////////////////////////////// 155 ////////////////////////////////////////////////////////////////////////// 152 // 156 // 153 // Get bounding box 157 // Get bounding box 154 158 155 void G4UBox::BoundingLimits(G4ThreeVector& pMi 159 void G4UBox::BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const 156 { 160 { 157 G4double dx = GetXHalfLength(); 161 G4double dx = GetXHalfLength(); 158 G4double dy = GetYHalfLength(); 162 G4double dy = GetYHalfLength(); 159 G4double dz = GetZHalfLength(); 163 G4double dz = GetZHalfLength(); 160 pMin.set(-dx,-dy,-dz); 164 pMin.set(-dx,-dy,-dz); 161 pMax.set( dx, dy, dz); 165 pMax.set( dx, dy, dz); 162 166 163 // Check correctness of the bounding box 167 // Check correctness of the bounding box 164 // 168 // 165 if (pMin.x() >= pMax.x() || pMin.y() >= pMax 169 if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z()) 166 { 170 { 167 std::ostringstream message; 171 std::ostringstream message; 168 message << "Bad bounding box (min >= max) 172 message << "Bad bounding box (min >= max) for solid: " 169 << GetName() << " !" 173 << GetName() << " !" 170 << "\npMin = " << pMin 174 << "\npMin = " << pMin 171 << "\npMax = " << pMax; 175 << "\npMax = " << pMax; 172 G4Exception("G4UBox::BoundingLimits()", "G 176 G4Exception("G4UBox::BoundingLimits()", "GeomMgt0001", 173 JustWarning, message); 177 JustWarning, message); 174 StreamInfo(G4cout); 178 StreamInfo(G4cout); 175 } 179 } 176 } 180 } 177 181 178 ////////////////////////////////////////////// 182 ////////////////////////////////////////////////////////////////////////// 179 // 183 // 180 // Calculate extent under transform and specif 184 // Calculate extent under transform and specified limit 181 185 182 G4bool 186 G4bool 183 G4UBox::CalculateExtent(const EAxis pAxis, 187 G4UBox::CalculateExtent(const EAxis pAxis, 184 const G4VoxelLimits& p 188 const G4VoxelLimits& pVoxelLimit, 185 const G4AffineTransfor 189 const G4AffineTransform& pTransform, 186 G4double& pMin, 190 G4double& pMin, G4double& pMax) const 187 { 191 { 188 G4ThreeVector bmin, bmax; 192 G4ThreeVector bmin, bmax; 189 193 190 // Get bounding box limits 194 // Get bounding box limits 191 BoundingLimits(bmin,bmax); 195 BoundingLimits(bmin,bmax); 192 196 193 // Find extent 197 // Find extent 194 G4BoundingEnvelope bbox(bmin,bmax); 198 G4BoundingEnvelope bbox(bmin,bmax); 195 return bbox.CalculateExtent(pAxis,pVoxelLimi 199 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax); 196 } 200 } 197 201 198 202 199 ////////////////////////////////////////////// 203 ////////////////////////////////////////////////////////////////////////// 200 // 204 // 201 // Create polyhedron for visualization 205 // Create polyhedron for visualization 202 206 203 G4Polyhedron* G4UBox::CreatePolyhedron() const 207 G4Polyhedron* G4UBox::CreatePolyhedron() const 204 { 208 { 205 return new G4PolyhedronBox(GetXHalfLength(), 209 return new G4PolyhedronBox(GetXHalfLength(), 206 GetYHalfLength(), 210 GetYHalfLength(), 207 GetZHalfLength()) 211 GetZHalfLength()); 208 } 212 } 209 213 210 #endif // G4GEOM_USE_USOLIDS 214 #endif // G4GEOM_USE_USOLIDS 211 215