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 intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 19 // * Vanderbilt University Free Electron Laser Center * 20 // * By using, copying, modifying or distri << 20 // * Vanderbilt University, Nashville, TN, USA * 21 // * any work based on the software) you ag << 21 // * Development supported by: * 22 // * use in resulting scientific publicati << 22 // * United States MFEL program under grant FA9550-04-1-0045 * 23 // * acceptance of all terms of the Geant4 Sof << 23 // * and NASA under contract number NNG04CT05P * >> 24 // * Written by Marcus H. Mendenhall and Robert A. Weller. * >> 25 // * * >> 26 // * Contributed to the Geant4 Core, January, 2005. * >> 27 // * * 24 // ******************************************* 28 // ******************************************************************** 25 // 29 // 26 // Implementation for G4UTet wrapper class << 30 // $Id:$ 27 // 31 // 28 // 1.11.13 G.Cosmo, CERN << 32 // >> 33 // Implementation for G4UTet wrapper class 29 // ------------------------------------------- 34 // -------------------------------------------------------------------- 30 35 31 #include "G4Tet.hh" 36 #include "G4Tet.hh" >> 37 #if 0 32 #include "G4UTet.hh" 38 #include "G4UTet.hh" 33 39 34 #if ( defined(G4GEOM_USE_USOLIDS) || defined(G 40 #if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) ) 35 41 36 #include "G4AffineTransform.hh" 42 #include "G4AffineTransform.hh" 37 #include "G4VPVParameterisation.hh" 43 #include "G4VPVParameterisation.hh" 38 #include "G4BoundingEnvelope.hh" 44 #include "G4BoundingEnvelope.hh" 39 45 40 using namespace CLHEP; 46 using namespace CLHEP; 41 47 42 ////////////////////////////////////////////// 48 //////////////////////////////////////////////////////////////////////// 43 // 49 // 44 // Constructor - create a tetrahedron 50 // Constructor - create a tetrahedron 45 // This class is implemented separately from g 51 // This class is implemented separately from general polyhedra, 46 // because the simplex geometry can be compute 52 // because the simplex geometry can be computed very quickly, 47 // which may become important in situations im 53 // which may become important in situations imported from mesh generators, 48 // in which a very large number of G4Tets are 54 // in which a very large number of G4Tets are created. 49 // A Tet has all of its geometrical informatio 55 // A Tet has all of its geometrical information precomputed 50 // 56 // 51 G4UTet::G4UTet(const G4String& pName, 57 G4UTet::G4UTet(const G4String& pName, 52 const G4ThreeVector& anchor, << 58 G4ThreeVector anchor, 53 const G4ThreeVector& p1, << 59 G4ThreeVector p2, 54 const G4ThreeVector& p2, << 60 G4ThreeVector p3, 55 const G4ThreeVector& p3, G4bool << 61 G4ThreeVector p4, G4bool* degeneracyFlag) 56 : Base_t(pName, U3Vector(anchor.x(),anchor.y << 62 : G4USolid(pName, new UTet(pName, 57 U3Vector(p1.x(), p1.y(), p1. << 63 UVector3(anchor.x(),anchor.y(),anchor.z()), 58 U3Vector(p2.x(), p2.y(), p2. << 64 UVector3(p2.x(), p2.y(), p2.z()), 59 U3Vector(p3.x(), p3.y(), p3. << 65 UVector3(p3.x(), p3.y(), p3.z()), >> 66 UVector3(p4.x(), p4.y(), p4.z()), >> 67 degeneracyFlag)) 60 { 68 { 61 // Check for degeneracy << 62 G4bool degenerate = CheckDegeneracy(anchor, << 63 if(degeneracyFlag != nullptr) *degeneracyFla << 64 else if (degenerate) << 65 { << 66 G4Exception("G4UTet::G4UTet()", "GeomSolid << 67 "Degenerate tetrahedron not al << 68 } << 69 << 70 // Set bounding box << 71 for (G4int i = 0; i < 3; ++i) << 72 { << 73 fBmin[i] = std::min(std::min(std::min(anch << 74 fBmax[i] = std::max(std::max(std::max(anch << 75 } << 76 } 69 } 77 70 78 ////////////////////////////////////////////// 71 ////////////////////////////////////////////////////////////////////////// 79 // 72 // 80 // Fake default constructor - sets only member 73 // Fake default constructor - sets only member data and allocates memory 81 // for usage restri 74 // for usage restricted to object persistency. 82 // 75 // 83 G4UTet::G4UTet( __void__& a ) 76 G4UTet::G4UTet( __void__& a ) 84 : Base_t(a) << 77 : G4USolid(a) 85 { 78 { 86 } 79 } 87 80 88 ////////////////////////////////////////////// 81 ////////////////////////////////////////////////////////////////////////// 89 // 82 // 90 // Destructor 83 // Destructor 91 // 84 // 92 G4UTet::~G4UTet() = default; << 85 G4UTet::~G4UTet() >> 86 { >> 87 } 93 88 94 ////////////////////////////////////////////// 89 /////////////////////////////////////////////////////////////////////////////// 95 // 90 // 96 // Copy constructor 91 // Copy constructor 97 // 92 // 98 G4UTet::G4UTet(const G4UTet& rhs) 93 G4UTet::G4UTet(const G4UTet& rhs) 99 : Base_t(rhs) << 94 : G4USolid(rhs) 100 { 95 { 101 fBmin = rhs.fBmin; << 102 fBmax = rhs.fBmax; << 103 } 96 } 104 97 105 98 106 ////////////////////////////////////////////// 99 /////////////////////////////////////////////////////////////////////////////// 107 // 100 // 108 // Assignment operator 101 // Assignment operator 109 // 102 // 110 G4UTet& G4UTet::operator = (const G4UTet& rhs) << 103 G4UTet& G4UTet::operator = (const G4UTet& rhs) 111 { 104 { 112 // Check assignment to self << 105 // Check assignment to self 113 if (this == &rhs) { return *this; } << 106 // >> 107 if (this == &rhs) { return *this; } 114 108 115 // Copy base class data << 109 // Copy base class data 116 Base_t::operator=(rhs); << 110 // >> 111 G4USolid::operator=(rhs); 117 112 118 // Copy bounding box << 113 return *this; 119 fBmin = rhs.fBmin; << 120 fBmax = rhs.fBmax; << 121 << 122 return *this; << 123 } << 124 << 125 ////////////////////////////////////////////// << 126 // << 127 // Return true if tetrahedron is degenerate << 128 // Tetrahedron is concidered as degenerate in << 129 // height is less than the degeneracy toleranc << 130 // << 131 G4bool G4UTet::CheckDegeneracy(const G4ThreeVe << 132 const G4ThreeVe << 133 const G4ThreeVe << 134 const G4ThreeVe << 135 { << 136 G4double hmin = 4. * kCarTolerance; // degen << 137 << 138 // Calculate volume << 139 G4double vol = std::abs((p1 - p0).cross(p2 - << 140 << 141 // Calculate face areas squared << 142 G4double ss[4]; << 143 ss[0] = ((p1 - p0).cross(p2 - p0)).mag2(); << 144 ss[1] = ((p2 - p0).cross(p3 - p0)).mag2(); << 145 ss[2] = ((p3 - p0).cross(p1 - p0)).mag2(); << 146 ss[3] = ((p2 - p1).cross(p3 - p1)).mag2(); << 147 << 148 // Find face with max area << 149 G4int k = 0; << 150 for (G4int i = 1; i < 4; ++i) { if (ss[i] > << 151 << 152 // Check: vol^2 / s^2 <= hmin^2 << 153 return (vol*vol <= ss[k]*hmin*hmin); << 154 } << 155 << 156 ////////////////////////////////////////////// << 157 // << 158 // Dispatch to parameterisation for replicatio << 159 // computation & modification. << 160 // << 161 void G4UTet::ComputeDimensions(G4VPVParameteri << 162 const G4int, << 163 const G4VPhysic << 164 { << 165 } << 166 << 167 ////////////////////////////////////////////// << 168 // << 169 // Make a clone of the object << 170 // << 171 G4VSolid* G4UTet::Clone() const << 172 { << 173 return new G4UTet(*this); << 174 } << 175 << 176 ////////////////////////////////////////////// << 177 // << 178 // Modifier << 179 // << 180 void G4UTet::SetVertices(const G4ThreeVector& << 181 const G4ThreeVector& << 182 const G4ThreeVector& << 183 const G4ThreeVector& << 184 G4bool* degeneracyFla << 185 { << 186 // Check for degeneracy << 187 G4bool degenerate = CheckDegeneracy(anchor, << 188 if(degeneracyFlag != nullptr) *degeneracyFla << 189 else if (degenerate) << 190 { << 191 G4Exception("G4UTet::SetVertices()", "Geom << 192 "Degenerate tetrahedron not al << 193 } << 194 << 195 // Change tetrahedron << 196 *this = G4UTet(GetName(), anchor, p1, p2, p3 << 197 } 114 } 198 115 199 ////////////////////////////////////////////// 116 /////////////////////////////////////////////////////////////////////////////// 200 // 117 // 201 // Accessors 118 // Accessors 202 // 119 // 203 void G4UTet::GetVertices(G4ThreeVector& anchor << 204 G4ThreeVector& p1, << 205 G4ThreeVector& p2, << 206 G4ThreeVector& p3) co << 207 { << 208 std::vector<U3Vector> vec(4); << 209 Base_t::GetVertices(vec[0], vec[1], vec[2], << 210 anchor = G4ThreeVector(vec[0].x(), vec[0].y( << 211 p1 = G4ThreeVector(vec[1].x(), vec[1].y(), v << 212 p2 = G4ThreeVector(vec[2].x(), vec[2].y(), v << 213 p3 = G4ThreeVector(vec[3].x(), vec[3].y(), v << 214 } << 215 << 216 std::vector<G4ThreeVector> G4UTet::GetVertices 120 std::vector<G4ThreeVector> G4UTet::GetVertices() const 217 { 121 { 218 std::vector<U3Vector> vec(4); << 122 std::vector<UVector3> vec = GetShape()->GetVertices(); 219 Base_t::GetVertices(vec[0], vec[1], vec[2], << 220 std::vector<G4ThreeVector> vertices; 123 std::vector<G4ThreeVector> vertices; 221 for (unsigned int i=0; i<4; ++i) << 124 for (unsigned int i=0; i<vec.size(); ++i) 222 { 125 { 223 G4ThreeVector v(vec[i].x(), vec[i].y(), ve 126 G4ThreeVector v(vec[i].x(), vec[i].y(), vec[i].z()); 224 vertices.push_back(v); 127 vertices.push_back(v); 225 } 128 } 226 return vertices; 129 return vertices; 227 } 130 } 228 131 229 ////////////////////////////////////////////// << 230 // << 231 // Set bounding box << 232 // << 233 void G4UTet::SetBoundingLimits(const G4ThreeVe << 234 const G4ThreeVe << 235 { << 236 G4ThreeVector fVertex[4]; << 237 GetVertices(fVertex[0], fVertex[1], fVertex[ << 238 << 239 G4int iout[4] = { 0, 0, 0, 0 }; << 240 for (G4int i = 0; i < 4; ++i) << 241 { << 242 iout[i] = (G4int)(fVertex[i].x() < pMin.x( << 243 fVertex[i].y() < pMin.y( << 244 fVertex[i].z() < pMin.z( << 245 fVertex[i].x() > pMax.x( << 246 fVertex[i].y() > pMax.y( << 247 fVertex[i].z() > pMax.z( << 248 } << 249 if (iout[0] + iout[1] + iout[2] + iout[3] != << 250 { << 251 std::ostringstream message; << 252 message << "Attempt to set bounding box th << 253 << GetName() << " !\n" << 254 << " Specified bounding box limit << 255 << " pmin: " << pMin << "\n" << 256 << " pmax: " << pMax << "\n" << 257 << " Tetrahedron vertices:\n" << 258 << " anchor " << fVertex[0] << << 259 << " p1 " << fVertex[1] << << 260 << " p2 " << fVertex[2] << << 261 << " p3 " << fVertex[3] << << 262 G4Exception("G4UTet::SetBoundingLimits()", << 263 FatalException, message); << 264 } << 265 fBmin = pMin; << 266 fBmax = pMax; << 267 } << 268 << 269 ////////////////////////////////////////////// 132 ////////////////////////////////////////////////////////////////////////// 270 // 133 // 271 // Get bounding box 134 // Get bounding box 272 135 273 void G4UTet::BoundingLimits(G4ThreeVector& pMi 136 void G4UTet::BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const 274 { 137 { 275 pMin = fBmin; << 138 UVector3 vmin, vmax; 276 pMax = fBmax; << 139 GetShape()->Extent(vmin,vmax); >> 140 pMin.set(vmin.x(),vmin.y(),vmin.z()); >> 141 pMax.set(vmax.x(),vmax.y(),vmax.z()); >> 142 >> 143 // Check correctness of the bounding box >> 144 // >> 145 if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z()) >> 146 { >> 147 std::ostringstream message; >> 148 message << "Bad bounding box (min >= max) for solid: " >> 149 << GetName() << " !" >> 150 << "\npMin = " << pMin >> 151 << "\npMax = " << pMax; >> 152 G4Exception("G4UTet::BoundingLimits()", "GeomMgt0001", >> 153 JustWarning, message); >> 154 StreamInfo(G4cout); >> 155 } 277 } 156 } 278 157 279 ////////////////////////////////////////////// 158 ////////////////////////////////////////////////////////////////////////// 280 // 159 // 281 // Calculate extent under transform and specif 160 // Calculate extent under transform and specified limit 282 161 283 G4bool 162 G4bool 284 G4UTet::CalculateExtent(const EAxis pAxis, 163 G4UTet::CalculateExtent(const EAxis pAxis, 285 const G4VoxelLimits& p 164 const G4VoxelLimits& pVoxelLimit, 286 const G4AffineTransfor 165 const G4AffineTransform& pTransform, 287 G4double& pMin, 166 G4double& pMin, G4double& pMax) const 288 { 167 { 289 G4ThreeVector bmin, bmax; 168 G4ThreeVector bmin, bmax; >> 169 G4bool exist; 290 170 291 // Check bounding box (bbox) 171 // Check bounding box (bbox) 292 // 172 // 293 BoundingLimits(bmin,bmax); 173 BoundingLimits(bmin,bmax); 294 G4BoundingEnvelope bbox(bmin,bmax); 174 G4BoundingEnvelope bbox(bmin,bmax); 295 << 175 #ifdef G4BBOX_EXTENT 296 // Use simple bounding-box to help in the ca << 176 if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax); 297 // << 177 #endif 298 return bbox.CalculateExtent(pAxis,pVoxelLimi << 299 << 300 #if 0 << 301 // Precise extent computation (disabled by d << 302 // << 303 G4bool exist; << 304 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVox 178 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax)) 305 { 179 { 306 return exist = (pMin < pMax) ? true : fals 180 return exist = (pMin < pMax) ? true : false; 307 } 181 } 308 182 309 // Set bounding envelope (benv) and calculat 183 // Set bounding envelope (benv) and calculate extent 310 // 184 // 311 std::vector<G4ThreeVector> vec = GetVertices << 185 std::vector<UVector3> vec = GetShape()->GetVertices(); 312 186 313 G4ThreeVectorList anchor(1); 187 G4ThreeVectorList anchor(1); 314 anchor[0] = vec[0]; << 188 anchor[0].set(vec[0].x(),vec[0].y(),vec[0].z()); 315 189 316 G4ThreeVectorList base(3); 190 G4ThreeVectorList base(3); 317 base[0] = vec[1]; << 191 base[0].set(vec[1].x(),vec[1].y(),vec[1].z()); 318 base[1] = vec[2]; << 192 base[1].set(vec[2].x(),vec[2].y(),vec[2].z()); 319 base[2] = vec[3]; << 193 base[2].set(vec[3].x(),vec[3].y(),vec[3].z()); 320 194 321 std::vector<const G4ThreeVectorList *> polyg 195 std::vector<const G4ThreeVectorList *> polygons(2); 322 polygons[0] = &anchor; 196 polygons[0] = &anchor; 323 polygons[1] = &base; 197 polygons[1] = &base; 324 198 325 G4BoundingEnvelope benv(bmin,bmax,polygons); 199 G4BoundingEnvelope benv(bmin,bmax,polygons); 326 return exists = benv.CalculateExtent(pAxis,p << 200 exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax); 327 #endif << 201 return exist; 328 } 202 } 329 203 330 ////////////////////////////////////////////// 204 //////////////////////////////////////////////////////////////////////// 331 // 205 // 332 // CreatePolyhedron 206 // CreatePolyhedron 333 // 207 // 334 G4Polyhedron* G4UTet::CreatePolyhedron() const 208 G4Polyhedron* G4UTet::CreatePolyhedron() const 335 { 209 { 336 std::vector<U3Vector> vec(4); << 210 G4int index = 0; 337 Base_t::GetVertices(vec[0], vec[1], vec[2], << 211 G4double array[12]; >> 212 GetShape()->GetParametersList(index, array); 338 213 >> 214 G4Polyhedron *ph=new G4Polyhedron; 339 G4double xyz[4][3]; 215 G4double xyz[4][3]; 340 const G4int faces[4][4] = {{1,3,2,0},{1,4,3, << 216 const G4int faces[4][4]={{1,3,2,0},{1,4,3,0},{1,2,4,0},{2,3,4,0}}; 341 for (unsigned int i=0; i<4; ++i) << 217 xyz[0][0]=array[0]; xyz[0][1]=array[1]; xyz[0][2]=array[2]; // fAnchor 342 { << 218 xyz[1][0]=array[3]; xyz[1][1]=array[4]; xyz[1][2]=array[5]; // fP2 343 xyz[i][0] = vec[i].x(); << 219 xyz[2][0]=array[6]; xyz[2][1]=array[7]; xyz[2][2]=array[8]; // fP3 344 xyz[i][1] = vec[i].y(); << 220 xyz[3][0]=array[9]; xyz[3][1]=array[10]; xyz[3][2]=array[11]; // fP4 345 xyz[i][2] = vec[i].z(); << 346 } << 347 221 348 auto ph = new G4Polyhedron; << 349 ph->createPolyhedron(4,4,xyz,faces); 222 ph->createPolyhedron(4,4,xyz,faces); >> 223 350 return ph; 224 return ph; 351 } 225 } 352 226 353 #endif // G4GEOM_USE_USOLIDS 227 #endif // G4GEOM_USE_USOLIDS >> 228 #endif 354 229