Changeset 1315 for trunk/source/geometry/solids
- Timestamp:
- Jun 18, 2010, 11:42:07 AM (15 years ago)
- Location:
- trunk/source/geometry/solids
- Files:
-
- 20 edited
-
Boolean/History (modified) (2 diffs)
-
Boolean/include/G4BooleanSolid.hh (modified) (3 diffs)
-
Boolean/src/G4BooleanSolid.cc (modified) (3 diffs)
-
Boolean/src/G4IntersectionSolid.cc (modified) (3 diffs)
-
Boolean/src/G4SubtractionSolid.cc (modified) (3 diffs)
-
Boolean/src/G4UnionSolid.cc (modified) (3 diffs)
-
CSG/History (modified) (2 diffs)
-
CSG/include/G4Box.hh (modified) (3 diffs)
-
CSG/src/G4Box.cc (modified) (41 diffs)
-
CSG/src/G4Orb.cc (modified) (9 diffs)
-
specific/History (modified) (2 diffs)
-
specific/include/G4ExtrudedSolid.hh (modified) (2 diffs)
-
specific/include/G4PolyconeSide.hh (modified) (3 diffs)
-
specific/include/G4PolyhedraSide.hh (modified) (3 diffs)
-
specific/src/G4ExtrudedSolid.cc (modified) (9 diffs)
-
specific/src/G4PolyconeSide.cc (modified) (6 diffs)
-
specific/src/G4PolyhedraSide.cc (modified) (7 diffs)
-
specific/src/G4SolidExtentList.cc (modified) (3 diffs)
-
specific/src/G4TessellatedSolid.cc (modified) (3 diffs)
-
specific/src/G4TriangularFacet.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/geometry/solids/Boolean/History
r831 r1315 1 1 2 $Id: History,v 1.6 2 2007/10/24 08:19:11 gcosmo Exp $2 $Id: History,v 1.64 2010/05/11 15:04:01 gcosmo Exp $ 3 3 ------------------------------------------------------------------- 4 4 … … 20 20 * Reverse chronological order (last date on top), please * 21 21 ---------------------------------------------------------- 22 23 May 11, 2010 J.Allison geom-bool-V09-03-00 24 - Introduced recursive algorithm in CreatePolyhedron(): it uses 25 HepPolyhedronProcessor from 'graphics_reps', which tries small shifts 26 in an attempt to avoid numerical problems in the calculation of the 27 polyhedron in BooleanProcessor. Recursion allows HepPolyhedronProcessor 28 to try all permutations, also for Booleans of Booleans. 29 Helps in reducing the number of cases of "Error in Boolean processor" for 30 visualization, but still some stubborn cases are left. 22 31 23 32 Oct 24, 2007 V.Grichine geom-bool-V09-00-00 -
trunk/source/geometry/solids/Boolean/include/G4BooleanSolid.hh
r1228 r1315 25 25 // 26 26 // 27 // $Id: G4BooleanSolid.hh,v 1.1 5 2006/10/19 15:34:49gcosmo Exp $28 // GEANT4 tag $Name: geant4-09-0 3$27 // $Id: G4BooleanSolid.hh,v 1.17 2010/05/11 15:03:45 gcosmo Exp $ 28 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 29 29 // 30 30 // … … 50 50 #include "G4Transform3D.hh" 51 51 52 class G4VSolid;52 class HepPolyhedronProcessor; 53 53 54 54 class G4BooleanSolid : public G4VSolid … … 111 111 G4VSolid* fPtrSolidB; 112 112 113 G4Polyhedron* StackPolyhedron(HepPolyhedronProcessor&, 114 const G4VSolid*) const; 115 // Stack polyhedra for processing. Return top polyhedron. 116 113 117 private: 114 118 -
trunk/source/geometry/solids/Boolean/src/G4BooleanSolid.cc
r1228 r1315 25 25 // 26 26 // 27 // $Id: G4BooleanSolid.cc,v 1.2 1 2006/10/19 15:34:49gcosmo Exp $28 // GEANT4 tag $Name: geant4-09-0 3$27 // $Id: G4BooleanSolid.cc,v 1.23 2010/05/11 15:03:45 gcosmo Exp $ 28 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 29 29 // 30 30 // Implementation for the abstract base class for solids created by boolean … … 40 40 #include "G4VSolid.hh" 41 41 #include "G4Polyhedron.hh" 42 #include "HepPolyhedronProcessor.h" 42 43 #include "Randomize.hh" 43 44 … … 231 232 return fpPolyhedron; 232 233 } 234 235 ////////////////////////////////////////////////////////////////////////// 236 // 237 // Stacks polyhedra for processing. Returns top polyhedron. 238 239 G4Polyhedron* 240 G4BooleanSolid::StackPolyhedron(HepPolyhedronProcessor& processor, 241 const G4VSolid* solid) const 242 { 243 HepPolyhedronProcessor::Operation operation; 244 const G4String& type = solid->GetEntityType(); 245 if (type == "G4UnionSolid") 246 { operation = HepPolyhedronProcessor::UNION; } 247 else if (type == "G4IntersectionSolid") 248 { operation = HepPolyhedronProcessor::INTERSECTION; } 249 else if (type == "G4SubtractionSolid") 250 { operation = HepPolyhedronProcessor::SUBTRACTION; } 251 else 252 { 253 std::ostringstream oss; 254 oss << "Solid - " << solid->GetName() 255 << " - Unrecognised composite solid" 256 << "\n Returning NULL !"; 257 G4Exception("StackPolyhedron()", "InvalidSetup", 258 JustWarning, oss.str().c_str()); 259 return 0; 260 } 261 262 G4Polyhedron* top = 0; 263 const G4VSolid* solidA = solid->GetConstituentSolid(0); 264 const G4VSolid* solidB = solid->GetConstituentSolid(1); 265 266 if (solidA->GetConstituentSolid(0)) 267 { 268 top = StackPolyhedron(processor, solidA); 269 } 270 else 271 { 272 top = solidA->GetPolyhedron(); 273 } 274 G4Polyhedron* operand = solidB->GetPolyhedron(); 275 processor.push_back (operation, *operand); 276 277 return top; 278 } -
trunk/source/geometry/solids/Boolean/src/G4IntersectionSolid.cc
r1228 r1315 25 25 // 26 26 // 27 // $Id: G4IntersectionSolid.cc,v 1.3 0 2006/11/08 09:37:41gcosmo Exp $28 // GEANT4 tag $Name: geant4-09-0 3$27 // $Id: G4IntersectionSolid.cc,v 1.32 2010/05/11 15:03:45 gcosmo Exp $ 28 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 29 29 // 30 30 // Implementation of methods for the class G4IntersectionSolid … … 50 50 #include "G4VGraphicsScene.hh" 51 51 #include "G4Polyhedron.hh" 52 #include "HepPolyhedronProcessor.h" 52 53 #include "G4NURBS.hh" 53 54 // #include "G4NURBSbox.hh" … … 502 503 G4IntersectionSolid::CreatePolyhedron () const 503 504 { 504 G4Polyhedron* pA = fPtrSolidA->GetPolyhedron(); 505 G4Polyhedron* pB = fPtrSolidB->GetPolyhedron(); 506 if (pA && pB) 507 { 508 G4Polyhedron* resultant = new G4Polyhedron (pA->intersect(*pB)); 509 return resultant; 510 } 511 else 512 { 513 std::ostringstream oss; 514 oss << "Solid - " << GetName() 515 << " - one of the Boolean components has no" << G4endl 516 << " corresponding polyhedron. Returning NULL !"; 517 G4Exception("G4IntersectionSolid::CreatePolyhedron()", "InvalidSetup", 518 JustWarning, oss.str().c_str()); 519 return 0; 520 } 505 HepPolyhedronProcessor processor; 506 // Stack components and components of components recursively 507 // See G4BooleanSolid::StackPolyhedron 508 G4Polyhedron* top = StackPolyhedron(processor, this); 509 G4Polyhedron* result = new G4Polyhedron(*top); 510 if (processor.execute(*result)) { return result; } 511 else { return 0; } 521 512 } 522 513 -
trunk/source/geometry/solids/Boolean/src/G4SubtractionSolid.cc
r1228 r1315 25 25 // 26 26 // 27 // $Id: G4SubtractionSolid.cc,v 1.3 1 2007/10/23 14:42:31 grichineExp $28 // GEANT4 tag $Name: geant4-09-0 3$27 // $Id: G4SubtractionSolid.cc,v 1.33 2010/05/11 15:03:45 gcosmo Exp $ 28 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 29 29 // 30 30 // Implementation of methods for the class G4IntersectionSolid … … 48 48 #include "G4VGraphicsScene.hh" 49 49 #include "G4Polyhedron.hh" 50 #include "HepPolyhedronProcessor.h" 50 51 #include "G4NURBS.hh" 51 52 // #include "G4NURBSbox.hh" … … 463 464 G4SubtractionSolid::CreatePolyhedron () const 464 465 { 465 G4Polyhedron* pA = fPtrSolidA->GetPolyhedron(); 466 G4Polyhedron* pB = fPtrSolidB->GetPolyhedron(); 467 if (pA && pB) 468 { 469 G4Polyhedron* resultant = new G4Polyhedron (pA->subtract(*pB)); 470 return resultant; 471 } 472 else 473 { 474 std::ostringstream oss; 475 oss << "Solid - " << GetName() 476 << " - one of the Boolean components has no" << G4endl 477 << " corresponding polyhedron. Returning NULL !"; 478 G4Exception("G4SubtractionSolid::CreatePolyhedron()", "InvalidSetup", 479 JustWarning, oss.str().c_str()); 480 return 0; 481 } 466 HepPolyhedronProcessor processor; 467 // Stack components and components of components recursively 468 // See G4BooleanSolid::StackPolyhedron 469 G4Polyhedron* top = StackPolyhedron(processor, this); 470 G4Polyhedron* result = new G4Polyhedron(*top); 471 if (processor.execute(*result)) { return result; } 472 else { return 0; } 482 473 } 483 474 -
trunk/source/geometry/solids/Boolean/src/G4UnionSolid.cc
r1228 r1315 25 25 // 26 26 // 27 // $Id: G4UnionSolid.cc,v 1.3 5 2007/10/23 14:42:31 grichineExp $28 // GEANT4 tag $Name: geant4-09-0 3$27 // $Id: G4UnionSolid.cc,v 1.37 2010/05/11 15:03:45 gcosmo Exp $ 28 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 29 29 // 30 30 // Implementation of methods for the class G4IntersectionSolid … … 49 49 #include "G4VGraphicsScene.hh" 50 50 #include "G4Polyhedron.hh" 51 #include "HepPolyhedronProcessor.h" 51 52 #include "G4NURBS.hh" 52 53 // #include "G4NURBSbox.hh" … … 454 455 G4UnionSolid::CreatePolyhedron () const 455 456 { 456 G4Polyhedron* pA = fPtrSolidA->GetPolyhedron(); 457 G4Polyhedron* pB = fPtrSolidB->GetPolyhedron(); 458 if (pA && pB) { 459 G4Polyhedron* resultant = new G4Polyhedron (pA->add(*pB)); 460 return resultant; 461 } else { 462 std::ostringstream oss; 463 oss << GetName() << 464 ": one of the Boolean components has no corresponding polyhedron."; 465 G4Exception("G4UnionSolid::CreatePolyhedron", 466 "", JustWarning, oss.str().c_str()); 467 return 0; 468 } 457 HepPolyhedronProcessor processor; 458 // Stack components and components of components recursively 459 // See G4BooleanSolid::StackPolyhedron 460 G4Polyhedron* top = StackPolyhedron(processor, this); 461 G4Polyhedron* result = new G4Polyhedron(*top); 462 if (processor.execute(*result)) { return result; } 463 else { return 0; } 469 464 } 470 465 -
trunk/source/geometry/solids/CSG/History
r1228 r1315 1 $Id: History,v 1.1 19 2009/11/30 10:20:53gcosmo Exp $1 $Id: History,v 1.121 2010/05/25 09:19:02 gcosmo Exp $ 2 2 ------------------------------------------------------------------- 3 3 … … 17 17 * Reverse chronological order (last date on top), please * 18 18 ---------------------------------------------------------- 19 20 May 25, 2010 G.Cosmo geom-csg-V09-03-01 21 - G4Box: more minor fixes in coding style, following code review discussion. 22 23 May 18, 2010 G.Cosmo geom-csg-V09-03-00 24 - G4Box: first implementation of speed improvements and corrections from joint 25 code review of G4Box class: introduced half-tolerance constants and better 26 logic in some conditional statements. 27 - Some code cleanup. 28 29 Dec 04, 2009 V.Grichine 30 - G4Orb: modified DistanceToIn(p,v) to be more consistent with Inside(p). 19 31 20 32 Nov 30, 2009 V.Grichine geom-csg-V09-02-08 -
trunk/source/geometry/solids/CSG/include/G4Box.hh
r1228 r1315 25 25 // 26 26 // 27 // $Id: G4Box.hh,v 1.1 7 2006/10/19 15:33:37gcosmo Exp $28 // GEANT4 tag $Name: geant4-09-0 3$27 // $Id: G4Box.hh,v 1.18 2010/05/18 10:07:52 gcosmo Exp $ 28 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 29 29 // 30 30 // -------------------------------------------------------------------- … … 101 101 std::ostream& StreamInfo(std::ostream& os) const; 102 102 103 // Functions for visualization103 // Utilities for visualization 104 104 105 105 void DescribeYourselfTo (G4VGraphicsScene& scene) const; … … 125 125 126 126 enum ESide {kUndefined,kPX,kMX,kPY,kMY,kPZ,kMZ}; 127 // Codes for faces (kPX= plus x face,kMY= minus y face etc)127 // Codes for faces (kPX= +x face, kMY= -y face, etc...) 128 128 129 129 private: -
trunk/source/geometry/solids/CSG/src/G4Box.cc
r1228 r1315 25 25 // 26 26 // 27 // $Id: G4Box.cc,v 1.4 4 2006/10/19 15:33:37gcosmo Exp $28 // GEANT4 tag $Name: geant4-09-0 3$27 // $Id: G4Box.cc,v 1.49 2010/05/25 10:14:41 gcosmo Exp $ 28 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 29 29 // 30 30 // … … 32 32 // Implementation for G4Box class 33 33 // 34 // 24.06.98 - V. Grichine: insideEdge in DistanceToIn(p,v)34 // 24.06.98 - V.Grichine: insideEdge in DistanceToIn(p,v) 35 35 // 20.09.98 - V.Grichine: new algorithm of DistanceToIn(p,v) 36 36 // 07.05.00 - V.Grichine: d= DistanceToIn(p,v), if d<e/2, d=0 … … 67 67 if ( (pX > 2*kCarTolerance) 68 68 && (pY > 2*kCarTolerance) 69 && (pZ > 2*kCarTolerance) ) 69 && (pZ > 2*kCarTolerance) ) // limit to thickness of surfaces 70 70 { 71 71 fDx = pX ; … … 105 105 void G4Box::SetXHalfLength(G4double dx) 106 106 { 107 if(dx > 2*kCarTolerance) 107 if(dx > 2*kCarTolerance) // limit to thickness of surfaces 108 { 108 109 fDx = dx; 110 } 109 111 else 110 112 { … … 122 124 void G4Box::SetYHalfLength(G4double dy) 123 125 { 124 if(dy > 2*kCarTolerance) 126 if(dy > 2*kCarTolerance) // limit to thickness of surfaces 127 { 125 128 fDy = dy; 129 } 126 130 else 127 131 { … … 139 143 void G4Box::SetZHalfLength(G4double dz) 140 144 { 141 if(dz > 2*kCarTolerance) 145 if(dz > 2*kCarTolerance) // limit to thickness of surfaces 146 { 142 147 fDz = dz; 148 } 143 149 else 144 150 { … … 153 159 fpPolyhedron = 0; 154 160 } 155 156 157 161 158 162 //////////////////////////////////////////////////////////////////////// … … 193 197 if (pVoxelLimit.IsXLimited()) 194 198 { 195 if ( xMin > pVoxelLimit.GetMaxXExtent()+kCarTolerance||196 xMax < pVoxelLimit.GetMinXExtent()-kCarTolerance ) return false ;199 if ((xMin > pVoxelLimit.GetMaxXExtent()+kCarTolerance) || 200 (xMax < pVoxelLimit.GetMinXExtent()-kCarTolerance)) { return false ; } 197 201 else 198 202 { 199 if (xMin < pVoxelLimit.GetMinXExtent()) 200 { 201 xMin = pVoxelLimit.GetMinXExtent() ; 202 } 203 if (xMax > pVoxelLimit.GetMaxXExtent()) 204 { 205 xMax = pVoxelLimit.GetMaxXExtent() ; 206 } 203 xMin = std::max(xMin, pVoxelLimit.GetMinXExtent()); 204 xMax = std::min(xMax, pVoxelLimit.GetMaxXExtent()); 207 205 } 208 206 } … … 213 211 if (pVoxelLimit.IsYLimited()) 214 212 { 215 if ( yMin > pVoxelLimit.GetMaxYExtent()+kCarTolerance||216 yMax < pVoxelLimit.GetMinYExtent()-kCarTolerance ) return false ;213 if ((yMin > pVoxelLimit.GetMaxYExtent()+kCarTolerance) || 214 (yMax < pVoxelLimit.GetMinYExtent()-kCarTolerance)) { return false ; } 217 215 else 218 216 { 219 if (yMin < pVoxelLimit.GetMinYExtent()) 220 { 221 yMin = pVoxelLimit.GetMinYExtent() ; 222 } 223 if (yMax > pVoxelLimit.GetMaxYExtent()) 224 { 225 yMax = pVoxelLimit.GetMaxYExtent() ; 226 } 217 yMin = std::max(yMin, pVoxelLimit.GetMinYExtent()); 218 yMax = std::min(yMax, pVoxelLimit.GetMaxYExtent()); 227 219 } 228 220 } … … 233 225 if (pVoxelLimit.IsZLimited()) 234 226 { 235 if ( zMin > pVoxelLimit.GetMaxZExtent()+kCarTolerance||236 zMax < pVoxelLimit.GetMinZExtent()-kCarTolerance ) return false ;227 if ((zMin > pVoxelLimit.GetMaxZExtent()+kCarTolerance) || 228 (zMax < pVoxelLimit.GetMinZExtent()-kCarTolerance)) { return false ; } 237 229 else 238 230 { 239 if (zMin < pVoxelLimit.GetMinZExtent()) 240 { 241 zMin = pVoxelLimit.GetMinZExtent() ; 242 } 243 if (zMax > pVoxelLimit.GetMaxZExtent()) 244 { 245 zMax = pVoxelLimit.GetMaxZExtent() ; 246 } 231 zMin = std::max(zMin, pVoxelLimit.GetMinZExtent()); 232 zMax = std::min(zMax, pVoxelLimit.GetMaxZExtent()); 247 233 } 248 234 } … … 286 272 if (pVoxelLimit.IsLimited(pAxis) == false) 287 273 { 288 if ( pMin != kInfinity || pMax != -kInfinity)274 if ( (pMin != kInfinity) || (pMax != -kInfinity) ) 289 275 { 290 276 existsAfterClip = true ; … … 292 278 // Add 2*tolerance to avoid precision troubles 293 279 294 pMin -= kCarTolerance;295 pMax += kCarTolerance;280 pMin -= kCarTolerance; 281 pMax += kCarTolerance; 296 282 } 297 283 } … … 303 289 ( pVoxelLimit.GetMinZExtent()+pVoxelLimit.GetMaxZExtent())*0.5); 304 290 305 if ( pMin != kInfinity || pMax != -kInfinity)291 if ( (pMin != kInfinity) || (pMax != -kInfinity) ) 306 292 { 307 293 existsAfterClip = true ; … … 356 342 EInside G4Box::Inside(const G4ThreeVector& p) const 357 343 { 344 static const G4double delta=0.5*kCarTolerance; 358 345 EInside in = kOutside ; 359 360 if ( std::fabs(p.x()) <= fDx - kCarTolerance*0.5 ) 361 { 362 if (std::fabs(p.y()) <= fDy - kCarTolerance*0.5 ) 363 { 364 if (std::fabs(p.z()) <= fDz - kCarTolerance*0.5 ) in = kInside ; 365 else if (std::fabs(p.z()) <= fDz + kCarTolerance*0.5 ) in = kSurface ; 366 } 367 else if (std::fabs(p.y()) <= fDy + kCarTolerance*0.5 ) 368 { 369 if (std::fabs(p.z()) <= fDz + kCarTolerance*0.5 ) in = kSurface ; 370 } 371 } 372 else if (std::fabs(p.x()) <= fDx + kCarTolerance*0.5 ) 373 { 374 if (std::fabs(p.y()) <= fDy + kCarTolerance*0.5 ) 375 { 376 if (std::fabs(p.z()) <= fDz + kCarTolerance*0.5) in = kSurface ; 346 G4ThreeVector q(std::fabs(p.x()), std::fabs(p.y()), std::fabs(p.z())); 347 348 if ( q.x() <= (fDx - delta) ) 349 { 350 if (q.y() <= (fDy - delta) ) 351 { 352 if ( q.z() <= (fDz - delta) ) { in = kInside ; } 353 else if ( q.z() <= (fDz + delta) ) { in = kSurface ; } 354 } 355 else if ( q.y() <= (fDy + delta) ) 356 { 357 if ( q.z() <= (fDz + delta) ) { in = kSurface ; } 358 } 359 } 360 else if ( q.x() <= (fDx + delta) ) 361 { 362 if ( q.y() <= (fDy + delta) ) 363 { 364 if ( q.z() <= (fDz + delta) ) { in = kSurface ; } 377 365 } 378 366 } … … 389 377 { 390 378 G4double distx, disty, distz ; 391 G4ThreeVector norm ;379 G4ThreeVector norm(0.,0.,0.); 392 380 393 381 // Calculate distances as if in 1st octant … … 400 388 // normals 401 389 402 const G4double delta = 0.5*kCarTolerance;390 static const G4double delta = 0.5*kCarTolerance; 403 391 const G4ThreeVector nX = G4ThreeVector( 1.0, 0,0 ); 404 392 const G4ThreeVector nmX = G4ThreeVector(-1.0, 0,0 ); … … 415 403 { 416 404 noSurfaces ++; 417 if ( p.x() >= 0.){ // on +X surface 418 normX= nX ; // G4ThreeVector( 1.0, 0., 0. ); 419 }else{ 420 normX= nmX; // G4ThreeVector(-1.0, 0., 0. ); 421 } 405 if ( p.x() >= 0. ) { normX= nX ; } // on +X surface : (1,0,0) 406 else { normX= nmX; } // (-1,0,0) 422 407 sumnorm= normX; 423 408 } … … 426 411 { 427 412 noSurfaces ++; 428 if ( p.y() >= 0.){ // on +Y surface 429 normY= nY; 430 }else{ 431 normY = nmY; 432 } 413 if ( p.y() >= 0. ) { normY= nY; } // on +Y surface 414 else { normY= nmY; } 433 415 sumnorm += normY; 434 416 } … … 437 419 { 438 420 noSurfaces ++; 439 if ( p.z() >= 0.){ // on +Z surface 440 normZ= nZ; 441 }else{ 442 normZ = nmZ; 443 } 444 sumnorm += normZ; 445 } 446 447 // sumnorm= normX + normY + normZ; 448 const G4double invSqrt2 = 1.0 / std::sqrt( 2.0); 449 const G4double invSqrt3 = 1.0 / std::sqrt( 3.0); 450 451 norm= G4ThreeVector( 0., 0., 0.); 421 if ( p.z() >= 0. ) { normZ= nZ; } // on +Z surface 422 else { normZ= nmZ; } 423 sumnorm += normZ; 424 } 425 426 static const G4double invSqrt2 = 1.0 / std::sqrt(2.0); 427 static const G4double invSqrt3 = 1.0 / std::sqrt(3.0); 428 452 429 if( noSurfaces > 0 ) 453 430 { 454 if( noSurfaces == 1 ){ 431 if( noSurfaces == 1 ) 432 { 455 433 norm= sumnorm; 456 }else{ 434 } 435 else 436 { 457 437 // norm = sumnorm . unit(); 458 if( noSurfaces == 2 ) { 438 if( noSurfaces == 2 ) 439 { 459 440 // 2 surfaces -> on edge 460 441 norm = invSqrt2 * sumnorm; 461 } else { 442 } 443 else 444 { 462 445 // 3 surfaces (on corner) 463 446 norm = invSqrt3 * sumnorm; 464 447 } 465 448 } 466 }else{ 449 } 450 else 451 { 467 452 #ifdef G4CSGDEBUG 468 453 G4Exception("G4Box::SurfaceNormal(p)", "Notification", JustWarning, … … 483 468 { 484 469 G4double distx, disty, distz ; 485 G4ThreeVector norm ;470 G4ThreeVector norm(0.,0.,0.); 486 471 487 472 // Calculate distances as if in 1st octant … … 495 480 if ( distx <= distz ) // Closest to X 496 481 { 497 if ( p.x() < 0 ) norm = G4ThreeVector(-1.0,0,0) ;498 else norm = G4ThreeVector( 1.0,0,0) ;482 if ( p.x() < 0 ) { norm = G4ThreeVector(-1.0,0,0) ; } 483 else { norm = G4ThreeVector( 1.0,0,0) ; } 499 484 } 500 485 else // Closest to Z 501 486 { 502 if ( p.z() < 0 ) norm = G4ThreeVector(0,0,-1.0) ;503 else norm = G4ThreeVector(0,0, 1.0) ;487 if ( p.z() < 0 ) { norm = G4ThreeVector(0,0,-1.0) ; } 488 else { norm = G4ThreeVector(0,0, 1.0) ; } 504 489 } 505 490 } … … 508 493 if ( disty <= distz ) // Closest to Y 509 494 { 510 if ( p.y() < 0 ) norm = G4ThreeVector(0,-1.0,0) ;511 else norm = G4ThreeVector(0, 1.0,0) ;495 if ( p.y() < 0 ) { norm = G4ThreeVector(0,-1.0,0) ; } 496 else { norm = G4ThreeVector(0, 1.0,0) ; } 512 497 } 513 498 else // Closest to Z 514 499 { 515 if ( p.z() < 0 ) norm = G4ThreeVector(0,0,-1.0) ;516 else norm = G4ThreeVector(0,0, 1.0) ;500 if ( p.z() < 0 ) { norm = G4ThreeVector(0,0,-1.0) ; } 501 else { norm = G4ThreeVector(0,0, 1.0) ; } 517 502 } 518 503 } … … 541 526 // shape. 542 527 543 G4double G4Box::DistanceToIn(const G4ThreeVector& p,const G4ThreeVector& v) const 528 G4double G4Box::DistanceToIn(const G4ThreeVector& p, 529 const G4ThreeVector& v) const 544 530 { 545 531 G4double safx, safy, safz ; … … 549 535 G4double sOut=kInfinity, sOuty=kInfinity, sOutz=kInfinity ; 550 536 537 static const G4double delta = 0.5*kCarTolerance; 538 551 539 safx = std::fabs(p.x()) - fDx ; // minimum distance to x surface of shape 552 540 safy = std::fabs(p.y()) - fDy ; … … 558 546 // travel is in a direction away from the shape. 559 547 560 if ( ((p.x()*v.x() >= 0.0) && safx > -kCarTolerance*0.5)561 || ((p.y()*v.y() >= 0.0) && safy > -kCarTolerance*0.5)562 || ((p.z()*v.z() >= 0.0) && safz > -kCarTolerance*0.5) )548 if ( ((p.x()*v.x() >= 0.0) && (safx > -delta)) 549 || ((p.y()*v.y() >= 0.0) && (safy > -delta)) 550 || ((p.z()*v.z() >= 0.0) && (safz > -delta)) ) 563 551 { 564 552 return kInfinity ; // travel away or parallel within tolerance … … 568 556 // X Planes 569 557 570 if ( v.x() )558 if ( v.x() ) // != 0 571 559 { 572 560 stmp = 1.0/std::fabs(v.x()) ; … … 579 567 else 580 568 { 581 if (v.x() > 0) sOut = (fDx - p.x())*stmp ;582 if (v.x() < 0) sOut = (fDx + p.x())*stmp ;569 if (v.x() < 0) { sOut = (fDx + p.x())*stmp ; } 570 else { sOut = (fDx - p.x())*stmp ; } 583 571 } 584 572 } … … 586 574 // Y Planes 587 575 588 if ( v.y() )576 if ( v.y() ) // != 0 589 577 { 590 578 stmp = 1.0/std::fabs(v.y()) ; … … 595 583 smaxy = (fDy+std::fabs(p.y()))*stmp ; 596 584 597 if (sminy > smin) smin=sminy ;598 if (smaxy < smax) smax=smaxy ;599 600 if (smin >= smax-kCarTolerance*0.5)585 if (sminy > smin) { smin=sminy ; } 586 if (smaxy < smax) { smax=smaxy ; } 587 588 if (smin >= (smax-delta)) 601 589 { 602 590 return kInfinity ; // touch XY corner … … 605 593 else 606 594 { 607 if (v.y() > 0) sOuty = (fDy - p.y())*stmp ;608 if (v.y() < 0) sOuty = (fDy + p.y())*stmp ;609 if( sOuty < sOut ) sOut = sOuty ;595 if (v.y() < 0) { sOuty = (fDy + p.y())*stmp ; } 596 else { sOuty = (fDy - p.y())*stmp ; } 597 if( sOuty < sOut ) { sOut = sOuty ; } 610 598 } 611 599 } … … 613 601 // Z planes 614 602 615 if ( v.z() ) 603 if ( v.z() ) // != 0 616 604 { 617 605 stmp = 1.0/std::fabs(v.z()) ; 618 606 619 if ( safz >= 0.0 )607 if ( safz >= 0.0 ) 620 608 { 621 609 sminz = safz*stmp ; 622 610 smaxz = (fDz+std::fabs(p.z()))*stmp ; 623 611 624 if (sminz > smin) smin = sminz ;625 if (smaxz < smax) smax = smaxz ;626 627 if (smin >= smax-kCarTolerance*0.5)612 if (sminz > smin) { smin = sminz ; } 613 if (smaxz < smax) { smax = smaxz ; } 614 615 if (smin >= (smax-delta)) 628 616 { 629 617 return kInfinity ; // touch ZX or ZY corners … … 632 620 else 633 621 { 634 if (v.z() > 0) sOutz = (fDz - p.z())*stmp ;635 if (v.z() < 0) sOutz = (fDz + p.z())*stmp ;636 if( sOutz < sOut ) sOut = sOutz ;637 } 638 } 639 640 if ( sOut <= smin + 0.5*kCarTolerance) // travel over edge622 if (v.z() < 0) { sOutz = (fDz + p.z())*stmp ; } 623 else { sOutz = (fDz - p.z())*stmp ; } 624 if( sOutz < sOut ) { sOut = sOutz ; } 625 } 626 } 627 628 if (sOut <= (smin + delta)) // travel over edge 641 629 { 642 630 return kInfinity ; 643 631 } 644 if (smin < 0.5*kCarTolerance) smin = 0.0 ;632 if (smin < delta) { smin = 0.0 ; } 645 633 646 634 return smin ; … … 662 650 safez = std::fabs(p.z()) - fDz ; 663 651 664 if (safex > safe) safe = safex ;665 if (safey > safe) safe = safey ;666 if (safez > safe) safe = safez ;652 if (safex > safe) { safe = safex ; } 653 if (safey > safe) { safe = safey ; } 654 if (safez > safe) { safe = safez ; } 667 655 668 656 return safe ; … … 671 659 ///////////////////////////////////////////////////////////////////////// 672 660 // 673 // Calc luate distance to surface of box from inside661 // Calculate distance to surface of box from inside 674 662 // by calculating distances to box's x/y/z planes. 675 663 // Smallest distance is exact distance to exiting. … … 682 670 { 683 671 ESide side = kUndefined ; 684 G4double pdist,stmp,snxt; 685 686 if (calcNorm) *validNorm = true ; // All normals are valid 687 688 if (v.x() > 0) // X planes 672 G4double pdist,stmp,snxt=kInfinity; 673 674 static const G4double delta = 0.5*kCarTolerance; 675 676 if (calcNorm) { *validNorm = true ; } // All normals are valid 677 678 if (v.x() > 0) // X planes 689 679 { 690 680 pdist = fDx - p.x() ; 691 681 692 if (pdist > kCarTolerance*0.5)682 if (pdist > delta) 693 683 { 694 684 snxt = pdist/v.x() ; … … 697 687 else 698 688 { 699 if (calcNorm) *n = G4ThreeVector(1,0,0) ;700 return snxt = 0 ;701 } 702 } 703 else if (v.x() < 0) 689 if (calcNorm) { *n = G4ThreeVector(1,0,0) ; } 690 return snxt = 0 ; 691 } 692 } 693 else if (v.x() < 0) 704 694 { 705 695 pdist = fDx + p.x() ; 706 696 707 if (pdist > kCarTolerance*0.5)697 if (pdist > delta) 708 698 { 709 699 snxt = -pdist/v.x() ; … … 712 702 else 713 703 { 714 if (calcNorm) *n = G4ThreeVector(-1,0,0) ;704 if (calcNorm) { *n = G4ThreeVector(-1,0,0) ; } 715 705 return snxt = 0 ; 716 706 } 717 707 } 718 else snxt = kInfinity ; 719 720 if ( v.y() > 0 ) // Y planes 721 { 722 pdist=fDy-p.y(); 723 724 if (pdist>kCarTolerance*0.5) 725 { 726 stmp=pdist/v.y(); 727 728 if (stmp<snxt) 729 { 730 snxt=stmp; 731 side=kPY; 732 } 733 } 734 else 735 { 736 if (calcNorm) *n = G4ThreeVector(0,1,0) ; 737 return snxt = 0 ; 738 } 739 } 740 else if ( v.y() < 0 ) 741 { 742 pdist = fDy + p.y() ; 743 744 if (pdist > kCarTolerance*0.5) 745 { 746 stmp=-pdist/v.y(); 747 748 if (stmp<snxt) 749 { 750 snxt=stmp; 751 side=kMY; 752 } 753 } 754 else 755 { 756 if (calcNorm) *n = G4ThreeVector(0,-1,0) ; 757 return snxt = 0 ; 758 } 759 } 760 if (v.z()>0) // Z planes 761 { 762 pdist=fDz-p.z(); 763 764 if (pdist > kCarTolerance*0.5) 765 { 766 stmp=pdist/v.z(); 708 709 if (v.y() > 0) // Y planes 710 { 711 pdist = fDy-p.y(); 712 713 if (pdist > delta) 714 { 715 stmp = pdist/v.y(); 767 716 768 717 if (stmp < snxt) 769 718 { 770 snxt =stmp;771 side =kPZ;719 snxt = stmp; 720 side = kPY; 772 721 } 773 722 } 774 723 else 775 724 { 776 if (calcNorm) *n = G4ThreeVector(0,0,1) ;777 return snxt = 0 ;778 } 779 } 780 else if (v. z()<0)781 { 782 pdist = fD z + p.z() ;783 784 if (pdist > kCarTolerance*0.5)785 { 786 stmp =-pdist/v.z();787 788 if ( stmp < snxt)725 if (calcNorm) { *n = G4ThreeVector(0,1,0) ; } 726 return snxt = 0 ; 727 } 728 } 729 else if (v.y() < 0) 730 { 731 pdist = fDy + p.y() ; 732 733 if (pdist > delta) 734 { 735 stmp = -pdist/v.y(); 736 737 if ( stmp < snxt ) 789 738 { 790 snxt =stmp;791 side =kMZ;739 snxt = stmp; 740 side = kMY; 792 741 } 793 742 } 794 743 else 795 744 { 796 if (calcNorm) *n = G4ThreeVector(0,0,-1) ; 797 return snxt = 0 ; 798 } 799 } 745 if (calcNorm) { *n = G4ThreeVector(0,-1,0) ; } 746 return snxt = 0 ; 747 } 748 } 749 750 if (v.z() > 0) // Z planes 751 { 752 pdist = fDz-p.z(); 753 754 if ( pdist > delta ) 755 { 756 stmp = pdist/v.z(); 757 758 if ( stmp < snxt ) 759 { 760 snxt = stmp; 761 side = kPZ; 762 } 763 } 764 else 765 { 766 if (calcNorm) { *n = G4ThreeVector(0,0,1) ; } 767 return snxt = 0 ; 768 } 769 } 770 else if (v.z() < 0) 771 { 772 pdist = fDz + p.z(); 773 774 if ( pdist > delta ) 775 { 776 stmp = -pdist/v.z(); 777 778 if ( stmp < snxt ) 779 { 780 snxt = stmp; 781 side = kMZ; 782 } 783 } 784 else 785 { 786 if (calcNorm) { *n = G4ThreeVector(0,0,-1) ; } 787 return snxt = 0 ; 788 } 789 } 790 800 791 if (calcNorm) 801 792 { … … 875 866 // shortest Dist to any boundary now MIN(safx1,safx2,safy1..) 876 867 877 if (safx2 < safx1) safe = safx2 ;878 else safe = safx1 ;879 if (safy1 < safe) safe = safy1 ;880 if (safy2 < safe) safe = safy2 ;881 if (safz1 < safe) safe = safz1 ;882 if (safz2 < safe) safe = safz2 ;883 884 if (safe < 0) safe = 0 ;868 if (safx2 < safx1) { safe = safx2; } 869 else { safe = safx1; } 870 if (safy1 < safe) { safe = safy1; } 871 if (safy2 < safe) { safe = safy2; } 872 if (safz1 < safe) { safe = safz1; } 873 if (safz2 < safe) { safe = safz2; } 874 875 if (safe < 0) { safe = 0 ; } 885 876 return safe ; 886 877 } … … 979 970 py = -fDy +2*fDy*G4UniformRand(); 980 971 981 if(G4UniformRand() > 0.5) pz = fDz;982 else pz = -fDz;972 if(G4UniformRand() > 0.5) { pz = fDz; } 973 else { pz = -fDz; } 983 974 } 984 975 else if ( ( select - Sxy ) < Sxz ) … … 987 978 pz = -fDz +2*fDz*G4UniformRand(); 988 979 989 if(G4UniformRand() > 0.5) py = fDy;990 else py = -fDy;980 if(G4UniformRand() > 0.5) { py = fDy; } 981 else { py = -fDy; } 991 982 } 992 983 else … … 995 986 pz = -fDz +2*fDz*G4UniformRand(); 996 987 997 if(G4UniformRand() > 0.5) px = fDx;998 else px = -fDx;988 if(G4UniformRand() > 0.5) { px = fDx; } 989 else { px = -fDx; } 999 990 } 1000 991 return G4ThreeVector(px,py,pz); -
trunk/source/geometry/solids/CSG/src/G4Orb.cc
r1228 r1315 24 24 // ******************************************************************** 25 25 // 26 // $Id: G4Orb.cc,v 1.3 0 2009/11/30 10:20:38 gcosmoExp $27 // GEANT4 tag $Name: geant4-09-0 3$26 // $Id: G4Orb.cc,v 1.31 2009/12/04 15:39:56 grichine Exp $ 27 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 28 28 // 29 29 // class G4Orb … … 296 296 297 297 298 rad2 = p.x()*p.x()+p.y()*p.y()+p.z()*p.z() ;298 rad2 = p.x()*p.x()+p.y()*p.y()+p.z()*p.z(); 299 299 300 300 G4double rad = std::sqrt(rad2); … … 304 304 // sets `in' 305 305 306 tolRMax = fRmax - fRmaxTolerance*0.5 ;306 tolRMax = fRmax - fRmaxTolerance*0.5; 307 307 308 if ( rad <= tolRMax ) { in = kInside ; }308 if ( rad <= tolRMax ) { in = kInside; } 309 309 else 310 310 { 311 tolRMax = fRmax + fRmaxTolerance*0.5 ;312 if ( rad <= tolRMax ) { in = kSurface ; }313 else { in = kOutside ; }311 tolRMax = fRmax + fRmaxTolerance*0.5; 312 if ( rad <= tolRMax ) { in = kSurface; } 313 else { in = kOutside; } 314 314 } 315 315 return in; … … 357 357 const G4ThreeVector& v ) const 358 358 { 359 G4double snxt = kInfinity ; // snxt = default return value360 361 G4double rad 2, pDotV3d, tolORMax2, tolIRMax2;362 G4double c, d2, s = kInfinity ;359 G4double snxt = kInfinity; // snxt = default return value 360 361 G4double rad, pDotV3d; // , tolORMax2, tolIRMax2; 362 G4double c, d2, s = kInfinity; 363 363 364 364 const G4double dRmax = 100.*fRmax; … … 366 366 // General Precalcs 367 367 368 rad 2 = p.x()*p.x() + p.y()*p.y() + p.z()*p.z();369 pDotV3d = p.x()*v.x() + p.y()*v.y() + p.z()*v.z() ;368 rad = std::sqrt(p.x()*p.x() + p.y()*p.y() + p.z()*p.z()); 369 pDotV3d = p.x()*v.x() + p.y()*v.y() + p.z()*v.z(); 370 370 371 371 // Radial Precalcs 372 372 373 tolORMax2 = (fRmax+fRmaxTolerance*0.5)*(fRmax+fRmaxTolerance*0.5);374 tolIRMax2 = (fRmax-fRmaxTolerance*0.5)*(fRmax-fRmaxTolerance*0.5);373 // tolORMax2 = (fRmax+fRmaxTolerance*0.5)*(fRmax+fRmaxTolerance*0.5); 374 // tolIRMax2 = (fRmax-fRmaxTolerance*0.5)*(fRmax-fRmaxTolerance*0.5); 375 375 376 376 // Outer spherical shell intersection … … 388 388 // => s=-pDotV3d+-std::sqrt(pDotV3d^2-(rad2-R^2)) 389 389 390 391 G4double rad = std::sqrt(rad2);392 390 c = (rad - fRmax)*(rad + fRmax); 393 391 394 if ( c > fRmaxTolerance*fRmax ) 395 { 396 // If outside tolerant boundary of outer G4Orb 397 // [ should be std::sqrt(rad2) - fRmax > fRmaxTolerance*0.5 ] 398 399 d2 = pDotV3d*pDotV3d - c ; 400 401 if ( d2 >= 0 ) 402 { 403 s = -pDotV3d - std::sqrt(d2) ; 404 if ( s >= 0 ) 405 { 406 if ( s>dRmax ) // Avoid rounding errors due to precision issues seen on 407 { // 64 bits systems. Split long distances and recompute 408 G4double fTerm = s-std::fmod(s,dRmax); 409 s = fTerm + DistanceToIn(p+fTerm*v,v); 410 } 411 return snxt = s; 412 } 413 } 414 else // No intersection with G4Orb 415 { 416 return snxt = kInfinity; 417 } 418 } 419 else 420 { 421 if ( c > -fRmaxTolerance*fRmax ) // on surface 422 { 423 d2 = pDotV3d*pDotV3d - c ; 424 if ( (d2 < fRmaxTolerance*fRmax) || (pDotV3d >= 0) ) 392 if( rad > fRmax-fRmaxTolerance*0.5 ) // not inside in terms of Inside(p) 393 { 394 if ( c > fRmaxTolerance*fRmax ) 395 { 396 // If outside tolerant boundary of outer G4Orb in terms of c 397 // [ should be std::sqrt(rad2) - fRmax > fRmaxTolerance*0.5 ] 398 399 d2 = pDotV3d*pDotV3d - c; 400 401 if ( d2 >= 0 ) 402 { 403 s = -pDotV3d - std::sqrt(d2); 404 if ( s >= 0 ) 405 { 406 if ( s > dRmax ) // Avoid rounding errors due to precision issues seen on 407 { // 64 bits systems. Split long distances and recompute 408 G4double fTerm = s - std::fmod(s,dRmax); 409 s = fTerm + DistanceToIn(p+fTerm*v,v); 410 } 411 return snxt = s; 412 } 413 } 414 else // No intersection with G4Orb 425 415 { 426 416 return snxt = kInfinity; 427 417 } 428 else 429 { 430 return snxt = 0.; 431 } 432 } 418 } 419 else // not outside in terms of c 420 { 421 if ( c > -fRmaxTolerance*fRmax ) // on surface 422 { 423 d2 = pDotV3d*pDotV3d - c; 424 if ( (d2 < fRmaxTolerance*fRmax) || (pDotV3d >= 0) ) 425 { 426 return snxt = kInfinity; 427 } 428 else 429 { 430 return snxt = 0.; 431 } 432 } 433 } 434 } 433 435 #ifdef G4CSGDEBUG 434 else // inside ???435 {436 else // inside ??? 437 { 436 438 G4Exception("G4Orb::DistanceToIn(p,v)", "Notification", 437 439 JustWarning, "Point p is inside !?"); 438 }440 } 439 441 #endif 440 } 442 441 443 return snxt; 442 444 } … … 520 522 if(calcNorm) 521 523 { 522 *validNorm = true ;523 *n = G4ThreeVector(p.x()/fRmax,p.y()/fRmax,p.z()/fRmax) ;524 *validNorm = true; 525 *n = G4ThreeVector(p.x()/fRmax,p.y()/fRmax,p.z()/fRmax); 524 526 } 525 527 return snxt = 0; … … 528 530 { 529 531 snxt = -pDotV3d + std::sqrt(d2); // second root since inside Rmax 530 side = kRMax ;532 side = kRMax; 531 533 } 532 534 } … … 596 598 if( Inside(p) == kOutside ) 597 599 { 598 G4cout.precision(16) ;599 G4cout << G4endl ;600 G4cout.precision(16); 601 G4cout << G4endl; 600 602 DumpInfo(); 601 G4cout << "Position:" << G4endl << G4endl ;602 G4cout << "p.x() = " << p.x()/mm << " mm" << G4endl ;603 G4cout << "p.y() = " << p.y()/mm << " mm" << G4endl ;604 G4cout << "p.z() = " << p.z()/mm << " mm" << G4endl << G4endl ;603 G4cout << "Position:" << G4endl << G4endl; 604 G4cout << "p.x() = " << p.x()/mm << " mm" << G4endl; 605 G4cout << "p.y() = " << p.y()/mm << " mm" << G4endl; 606 G4cout << "p.z() = " << p.z()/mm << " mm" << G4endl << G4endl; 605 607 G4Exception("G4Orb::DistanceToOut(p)", "Notification", JustWarning, 606 608 "Point p is outside !?" ); -
trunk/source/geometry/solids/specific/History
r1228 r1315 1 $Id: History,v 1.1 60 2009/11/11 12:25:46gcosmo Exp $1 $Id: History,v 1.170 2010/06/11 09:42:59 gcosmo Exp $ 2 2 ------------------------------------------------------------------- 3 3 … … 17 17 * Reverse chronological order (last date on top), please * 18 18 ---------------------------------------------------------- 19 20 11-Jun-2010 T.Nikitina (geom-specific-V09-03-07) 21 - G4GenericTrap: fixed cases of zero dToIn/sToOut when vertices are collapsed 22 to triangle, line or point. Added new methods handling those specific cases. 23 - Added unit test for G4GenericTrap. 24 25 10-Jun-2010 I.Hrivnacova 26 - G4GenericTrap: fixed parameter names in CalculateExtent() for the test 27 case construction through tessellated facets. 28 29 09-Jun-2010 G.Cosmo 30 - G4GenericTrap: moved internal methods to private section and reordered 31 in source file. Added missing implementation for IsTwisted() method. 32 33 03-Jun-2010 T.Nikitina, G.Cosmo (geom-specific-V09-03-06) 34 - G4GenericTrap: 35 o Fixed initialization of fSurfaceArea and fCubicVolume and 36 calculation of surface area. 37 o Fixed error in Inside(p) function, and corrected use std::fabs() instead 38 of std::abs() for floating point values. 39 o Added missing initialisation of fpPolyhedron pointer. 40 o More corrected signatures for use of non-const references for vectors 41 passed as arguments to functions. 42 43 02-Jun-2010 G.Cosmo (geom-specific-V09-03-05) 44 - G4GenericTrap: use const reference for vector of vertices passed as argument 45 in constructor and accessor. 46 47 27-May-2010 T.Nikitina (geom-specific-V09-03-04) 48 - First implementation of G4GenericTrap shape, a new solid representing an 49 arbitrary trapezoid with up to 8 vertices standing on two parallel planes 50 perpendicular to the Z axis. 51 52 28-Apr-2010 P.R.Truscott (geom-specific-V09-03-03) 53 - Fix in G4TriangularFacet and G4TessellatedSolid to correct treatment of 54 optical photon transport related to internal reflection at surface. 55 Addresses problem report #1103. 56 57 15-Apr-2010 I.Hrivnacova (geom-specific-V09-03-02) 58 - G4ExtrudedSolid: eliminated requirement for clockwise ordering of polygon 59 vertices. Added a check for vertices ordering; if vertices are defined 60 anti-clockwise their ordering is reverted. 61 Fix in polygon facet triangularization for consequent concave vertices. 62 63 24-Feb-2010 G.Cosmo (geom-specific-V09-03-01) 64 - Adopt caching of Phi in G4PolyconeSide and G4PolyhedraSide to avoid 65 unnecessary consecutive computations on the same point. 66 67 10-Feb-2010 G.Cosmo (geom-specific-V09-03-00) 68 - Use kInfinity for initialising minimum and maximum allowed extent for 69 G4SolidExtentList of faceted solids. 19 70 20 71 11-Nov-2009 G.Cosmo (geom-specific-V09-02-08) -
trunk/source/geometry/solids/specific/include/G4ExtrudedSolid.hh
r1228 r1315 25 25 // 26 26 // 27 // $Id: G4ExtrudedSolid.hh,v 1. 7 2008/02/27 12:32:48ivana Exp $28 // GEANT4 tag $Name: geant4-09-0 3$27 // $Id: G4ExtrudedSolid.hh,v 1.8 2010/04/15 10:23:34 ivana Exp $ 28 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 29 29 // 30 30 // … … 45 45 // const G4String& pName - solid name 46 46 // std::vector<G4TwoVector> polygon - the vertices of the outlined polygon 47 // defined in clock -wise order47 // defined in clockwise or anti-clockwise order 48 48 // std::vector<ZSection> - the z-sections defined by 49 49 // z position, offset and scale -
trunk/source/geometry/solids/specific/include/G4PolyconeSide.hh
r1228 r1315 25 25 // 26 26 // 27 // $Id: G4PolyconeSide.hh,v 1.1 2 2008/05/15 11:41:58gcosmo Exp $28 // GEANT4 tag $Name: geant4-09-0 3$27 // $Id: G4PolyconeSide.hh,v 1.13 2010/02/24 11:18:25 gcosmo Exp $ 28 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 29 29 // 30 30 // … … 114 114 protected: 115 115 116 G4double DistanceAway( const G4ThreeVector &p, G4bool opposite, 117 G4double &distOutside2, G4double *rzNorm=0 ); 118 119 G4bool PointOnCone( const G4ThreeVector &hit, G4double normSign, 120 const G4ThreeVector &p, 121 const G4ThreeVector &v, G4ThreeVector &normal ); 122 123 void CopyStuff( const G4PolyconeSide &source ); 124 125 static void FindLineIntersect( G4double x1, G4double y1, 126 G4double tx1, G4double ty1, 127 G4double x2, G4double y2, 128 G4double tx2, G4double ty2, 129 G4double &x, G4double &y ); 130 131 G4double GetPhi( const G4ThreeVector& p ); 132 133 protected: 134 116 135 G4double r[2], z[2]; // r, z parameters, in specified order 117 136 G4double startPhi, // Start phi (0 to 2pi), if phiIsOpen … … 136 155 G4ThreeVector *corners; // The coordinates of the corners (if phiIsOpen) 137 156 138 G4double DistanceAway( const G4ThreeVector &p, G4bool opposite,139 G4double &distOutside2, G4double *rzNorm=0 );140 141 G4bool PointOnCone( const G4ThreeVector &hit, G4double normSign,142 const G4ThreeVector &p,143 const G4ThreeVector &v, G4ThreeVector &normal );144 145 void CopyStuff( const G4PolyconeSide &source );146 147 static void FindLineIntersect( G4double x1, G4double y1,148 G4double tx1, G4double ty1,149 G4double x2, G4double y2,150 G4double tx2, G4double ty2,151 G4double &x, G4double &y );152 157 private: 153 158 159 std::pair<G4ThreeVector, G4double> fPhi; // Cached value for phi 154 160 G4double kCarTolerance; // Geometrical surface thickness 155 161 G4double fSurfaceArea; // Used for surface calculation -
trunk/source/geometry/solids/specific/include/G4PolyhedraSide.hh
r1228 r1315 25 25 // 26 26 // 27 // $Id: G4PolyhedraSide.hh,v 1.1 1 2008/05/15 11:41:59gcosmo Exp $28 // GEANT4 tag $Name: geant4-09-0 3$27 // $Id: G4PolyhedraSide.hh,v 1.12 2010/02/24 11:18:25 gcosmo Exp $ 28 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 29 29 // 30 30 // … … 166 166 167 167 G4int PhiSegment( G4double phi ); 168 168 169 G4double GetPhi( const G4ThreeVector& p ); 170 169 171 G4double DistanceToOneSide( const G4ThreeVector &p, 170 172 const G4PolyhedraSideVec &vec, … … 197 199 private: 198 200 201 std::pair<G4ThreeVector, G4double> fPhi; // Cached value for phi 199 202 G4double kCarTolerance; // Geometrical surface thickness 200 203 G4double fSurfaceArea; // Surface Area -
trunk/source/geometry/solids/specific/src/G4ExtrudedSolid.cc
r1228 r1315 25 25 // 26 26 // 27 // $Id: G4ExtrudedSolid.cc,v 1.1 8 2008/10/30 11:47:45ivana Exp $28 // GEANT4 tag $Name: geant4-09-0 3$27 // $Id: G4ExtrudedSolid.cc,v 1.19 2010/04/15 10:23:34 ivana Exp $ 28 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 29 29 // 30 30 // … … 40 40 #include <algorithm> 41 41 #include <cmath> 42 #include <iomanip> 42 43 43 44 #include "G4ExtrudedSolid.hh" … … 94 95 "Z-sections with the same z position are not supported."); 95 96 } 96 } 97 97 } 98 99 // Check if polygon vertices are defined clockwise 100 // (the area is positive if polygon vertices are defined anti-clockwise) 101 // 102 G4double area = 0.; 103 for ( G4int i=0; i<fNv; ++i ) { 104 G4int j = i+1; 105 if ( j == fNv ) j = 0; 106 area += 0.5 * ( polygon[i].x()*polygon[j].y() - polygon[j].x()*polygon[i].y()); 107 } 108 98 109 // Copy polygon 99 110 // 100 for ( G4int i=0; i<fNv; ++i ) { fPolygon.push_back(polygon[i]); } 111 if ( area < 0. ) { 112 // Polygon vertices are defined clockwise, we just copy the polygon 113 for ( G4int i=0; i<fNv; ++i ) { fPolygon.push_back(polygon[i]); } 114 } 115 else { 116 // Polygon vertices are defined anti-clockwise, we revert them 117 //G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", errorDescription, 118 // JustWarning, 119 // "Polygon vertices defined anti-clockwise, reverting polygon"); 120 for ( G4int i=0; i<fNv; ++i ) { fPolygon.push_back(polygon[fNv-i-1]); } 121 } 122 101 123 102 124 // Copy z-sections … … 148 170 } 149 171 172 // Check if polygon vertices are defined clockwise 173 // (the area is positive if polygon vertices are defined anti-clockwise) 174 175 G4double area = 0.; 176 for ( G4int i=0; i<fNv; ++i ) { 177 G4int j = i+1; 178 if ( j == fNv ) j = 0; 179 area += 0.5 * ( polygon[i].x()*polygon[j].y() - polygon[j].x()*polygon[i].y()); 180 } 181 150 182 // Copy polygon 151 183 // 152 for ( G4int i=0; i<fNv; ++i ) { fPolygon.push_back(polygon[i]); } 184 if ( area < 0. ) { 185 // Polygon vertices are defined clockwise, we just copy the polygon 186 for ( G4int i=0; i<fNv; ++i ) { fPolygon.push_back(polygon[i]); } 187 } 188 else { 189 // Polygon vertices are defined anti-clockwise, we revert them 190 //G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", errorDescription, 191 // JustWarning, 192 // "Polygon vertices defined anti-clockwise, reverting polygon"); 193 for ( G4int i=0; i<fNv; ++i ) { fPolygon.push_back(polygon[fNv-i-1]); } 194 } 153 195 154 196 // Copy z-sections … … 453 495 // 454 496 G4double angle = GetAngle(c2->first, c3->first, c1->first); 455 456 if ( angle > pi ) 497 //G4cout << "angle " << angle << G4endl; 498 499 G4int counter = 0; 500 while ( angle > pi ) 457 501 { 458 502 // G4cout << "Skipping concave vertex " << c2->second << G4endl; … … 467 511 // G4cout << "Looking at triangle : " 468 512 // << c1->second << " " << c2->second 469 // << " " << c3->second << G4endl; 470 513 // << " " << c3->second << G4endl; 514 515 angle = GetAngle(c2->first, c3->first, c1->first); 516 //G4cout << "angle " << angle << G4endl; 517 518 counter++; 519 520 if ( counter > fNv) { 521 G4Exception("G4ExtrudedSolid::AddGeneralPolygonFacets", "InvalidSetup" , 522 FatalException, "Triangularisation has failed."); 523 break; 524 } 471 525 } 472 526 … … 734 788 } 735 789 736 737 790 //_____________________________________________________________________________ 738 791 … … 751 804 for ( G4int i=0; i<fNv; ++i ) 752 805 { 753 os << " vx = " << fPolygon[i].x()/mm << " mm" 806 os << std::setw(5) << "#" << i 807 << " vx = " << fPolygon[i].x()/mm << " mm" 754 808 << " vy = " << fPolygon[i].y()/mm << " mm" << G4endl; 755 809 } … … 764 818 } 765 819 820 /* 821 // Triangles (for debogging) 822 os << G4endl; 823 os << " Triangles:" << G4endl; 824 os << " Triangle # vertex1 vertex2 vertex3" << G4endl; 825 826 G4int counter = 0; 827 std::vector< std::vector<G4int> >::const_iterator it; 828 for ( it = fTriangles.begin(); it != fTriangles.end(); it++ ) { 829 std::vector<G4int> triangle = *it; 830 os << std::setw(10) << counter++ 831 << std::setw(10) << triangle[0] << std::setw(10) << triangle[1] << std::setw(10) << triangle[2] 832 << G4endl; 833 } 834 */ 766 835 return os; 767 836 } -
trunk/source/geometry/solids/specific/src/G4PolyconeSide.cc
r1228 r1315 25 25 // 26 26 // 27 // $Id: G4PolyconeSide.cc,v 1.2 2 2009/11/11 12:23:37gcosmo Exp $28 // GEANT4 tag $Name: geant4-09-0 3$27 // $Id: G4PolyconeSide.cc,v 1.24 2010/02/24 11:31:49 gcosmo Exp $ 28 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 29 29 // 30 30 // … … 67 67 kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance(); 68 68 fSurfaceArea = 0.0; 69 fPhi.first = G4ThreeVector(0,0,0); 70 fPhi.second= 0.0; 69 71 70 72 // … … 492 494 if (phiIsOpen) 493 495 { 494 G4double phi = axis.phi();496 G4double phi = GetPhi(axis); 495 497 while( phi < startPhi ) phi += twopi; 496 498 … … 853 855 } 854 856 857 // 858 // GetPhi 859 // 860 // Calculate Phi for a given 3-vector (point), if not already cached for the 861 // same point, in the attempt to avoid consecutive computation of the same 862 // quantity 863 // 864 G4double G4PolyconeSide::GetPhi( const G4ThreeVector& p ) 865 { 866 G4double val=0.; 867 868 if (fPhi.first != p) 869 { 870 val = p.phi(); 871 fPhi.first = p; 872 fPhi.second = val; 873 } 874 else 875 { 876 val = fPhi.second; 877 } 878 return val; 879 } 855 880 856 881 // … … 922 947 // Finally, check phi 923 948 // 924 G4double phi = p.phi();949 G4double phi = GetPhi(p); 925 950 while( phi < startPhi ) phi += twopi; 926 951 … … 978 1003 // PolyPhiFace. See PolyPhiFace::InsideEdgesExact 979 1004 // 980 G4double phi = hit.phi();1005 G4double phi = GetPhi(hit); 981 1006 while( phi < startPhi-phiTolerant ) phi += twopi; 982 1007 -
trunk/source/geometry/solids/specific/src/G4PolyhedraSide.cc
r1228 r1315 25 25 // 26 26 // 27 // $Id: G4PolyhedraSide.cc,v 1.1 5 2008/05/15 11:41:59 gcosmo Exp $28 // GEANT4 tag $Name: geant4-09-0 3$27 // $Id: G4PolyhedraSide.cc,v 1.17 2010/02/24 11:31:49 gcosmo Exp $ 28 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 29 29 // 30 30 // … … 64 64 G4bool isAllBehind ) 65 65 { 66 67 66 kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance(); 68 67 fSurfaceArea=0.; 68 fPhi.first = G4ThreeVector(0,0,0); 69 fPhi.second= 0.0; 70 69 71 // 70 72 // Record values … … 561 563 // Try the closest phi segment first 562 564 // 563 G4int iPhi = ClosestPhiSegment( p.phi() );565 G4int iPhi = ClosestPhiSegment( GetPhi(p) ); 564 566 565 567 G4ThreeVector pdotc = p - vecs[iPhi].center; … … 594 596 // Which phi segment is closest to this point? 595 597 // 596 G4int iPhi = ClosestPhiSegment( p.phi() );598 G4int iPhi = ClosestPhiSegment( GetPhi(p) ); 597 599 598 600 G4double norm; … … 624 626 // Which phi segment is closest to this point? 625 627 // 626 G4int iPhi = ClosestPhiSegment( p.phi() );628 G4int iPhi = ClosestPhiSegment( GetPhi(p) ); 627 629 628 630 // … … 656 658 // Which phi segment, if any, does the axis belong to 657 659 // 658 iPhi = PhiSegment( axis.phi() );660 iPhi = PhiSegment( GetPhi(axis) ); 659 661 660 662 if (iPhi < 0) … … 971 973 972 974 // 975 // GetPhi 976 // 977 // Calculate Phi for a given 3-vector (point), if not already cached for the 978 // same point, in the attempt to avoid consecutive computation of the same 979 // quantity 980 // 981 G4double G4PolyhedraSide::GetPhi( const G4ThreeVector& p ) 982 { 983 G4double val=0.; 984 985 if (fPhi.first != p) 986 { 987 val = p.phi(); 988 fPhi.first = p; 989 fPhi.second = val; 990 } 991 else 992 { 993 val = fPhi.second; 994 } 995 return val; 996 } 997 998 999 // 973 1000 // DistanceToOneSide 974 1001 // -
trunk/source/geometry/solids/specific/src/G4SolidExtentList.cc
r1228 r1315 25 25 // 26 26 // 27 // $Id: G4SolidExtentList.cc,v 1. 5 2007/05/11 13:54:29gcosmo Exp $28 // GEANT4 tag $Name: geant4-09-0 3$27 // $Id: G4SolidExtentList.cc,v 1.6 2010/02/10 16:38:37 gcosmo Exp $ 28 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 29 29 // 30 30 // … … 51 51 axis = kZAxis; 52 52 limited = false; 53 minLimit = - DBL_MAX;54 maxLimit = + DBL_MAX;53 minLimit = -kInfinity; 54 maxLimit = +kInfinity; 55 55 } 56 56 … … 72 72 else 73 73 { 74 minLimit = - DBL_MAX;75 maxLimit = + DBL_MAX;74 minLimit = -kInfinity; 75 maxLimit = +kInfinity; 76 76 } 77 77 } -
trunk/source/geometry/solids/specific/src/G4TessellatedSolid.cc
r1228 r1315 25 25 // ******************************************************************** 26 26 // 27 // $Id: G4TessellatedSolid.cc,v 1. 19 2009/04/27 08:06:27 gcosmoExp $28 // GEANT4 tag $Name: geant4-09-0 3$27 // $Id: G4TessellatedSolid.cc,v 1.20 2010/04/28 16:21:21 flei Exp $ 28 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 29 29 // 30 30 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% … … 42 42 // CHANGE HISTORY 43 43 // -------------- 44 // 45 // 12 April 2010 P R Truscott, QinetiQ, bug fixes to treat optical 46 // photon transport, in particular internal reflection 47 // at surface. 44 48 // 45 49 // 14 November 2007 P R Truscott, QinetiQ & Stan Seibert, U Texas … … 670 674 if ((*f)->Intersect(p,v,false,dist,distFromSurface,normal)) 671 675 { 676 // 677 // 678 // Set minDist to the new distance to current facet if distFromSurface is in 679 // positive direction and point is not at surface. If the point is within 680 // 0.5*kCarTolerance of the surface, then force distance to be zero and 681 // leave member function immediately (for efficiency), as proposed by & credit 682 // to Akira Okumura. 683 // 672 684 if (distFromSurface > 0.5*kCarTolerance && dist >= 0.0 && dist < minDist) 673 685 { 674 686 minDist = dist; 687 } 688 else if (-0.5*kCarTolerance <= dist && dist <= 0.5*kCarTolerance) 689 { 690 return 0.0; 675 691 } 676 692 } -
trunk/source/geometry/solids/specific/src/G4TriangularFacet.cc
r1228 r1315 25 25 // ******************************************************************** 26 26 // 27 // $Id: G4TriangularFacet.cc,v 1.1 2 2008/11/13 08:25:07 gcosmoExp $28 // GEANT4 tag $Name: geant4-09-0 3$27 // $Id: G4TriangularFacet.cc,v 1.13 2010/04/28 16:21:21 flei Exp $ 28 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 29 29 // 30 30 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% … … 56 56 // plane of the triangle. 57 57 // 58 // 12 April 2010 P R Truscott, QinetiQ, bug fixes to treat optical 59 // photon transport, in particular internal reflection 60 // at surface. 58 61 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 59 62 … … 350 353 // 351 354 // 352 // Do a heck for rounding errors in the distance-squared. 355 // Do a check for rounding errors in the distance-squared. It appears that 356 // the conventional methods for calculating sqrDist breaks down when very near 357 // to or at the surface (as required by transport). We'll therefore also use 358 // the magnitude-squared of the vector displacement. (Note that I've also 359 // tried to get around this problem by using the existing equations for 360 // 361 // sqrDist = function(a,b,c,d,s,t) 362 // 363 // and use a more accurate addition process which minimises errors and 364 // breakdown of cummutitivity [where (A+B)+C != A+(B+C)] but this still 365 // doesn't work. 366 // Calculation from u = D + s*E[0] + t*E[1] is less efficient, but appears 367 // more robust. 353 368 // 354 369 if (sqrDist < 0.0) { sqrDist = 0.0; } 355 356 return D + s*E[0] + t*E[1]; 370 G4ThreeVector u = D + s*E[0] + t*E[1]; 371 G4double u2 = u.mag2(); 372 // 373 // 374 // The following (part of the roundoff error check) is from Oliver Merle's 375 // updates. 376 // 377 if ( sqrDist > u2 ) sqrDist = u2; 378 379 return u; 357 380 } 358 381 … … 542 565 // we intersect. 543 566 // 544 distance = -0.5*kCarTolerance; 567 // distance = -0.5*kCarTolerance; 568 distance = 0.0; 545 569 normal = surfaceNormal; 546 570 return true; … … 728 752 return area; 729 753 } 754 //////////////////////////////////////////////////////////////////////// 755 //
Note:
See TracChangeset
for help on using the changeset viewer.
