Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Types | Protected Member Functions
G4Box Class Reference

#include <G4Box.hh>

Inheritance diagram for G4Box:
G4CSGSolid G4VSolid

Public Member Functions

 G4Box (const G4String &pName, G4double pX, G4double pY, G4double pZ)
 
virtual ~G4Box ()
 
void ComputeDimensions (G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
 
G4bool CalculateExtent (const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pmin, G4double &pmax) const
 
G4double GetXHalfLength () const
 
G4double GetYHalfLength () const
 
G4double GetZHalfLength () const
 
void SetXHalfLength (G4double dx)
 
void SetYHalfLength (G4double dy)
 
void SetZHalfLength (G4double dz)
 
G4double GetCubicVolume ()
 
G4double GetSurfaceArea ()
 
EInside Inside (const G4ThreeVector &p) const
 
G4ThreeVector SurfaceNormal (const G4ThreeVector &p) const
 
G4double DistanceToIn (const G4ThreeVector &p, const G4ThreeVector &v) const
 
G4double DistanceToIn (const G4ThreeVector &p) const
 
G4double DistanceToOut (const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const
 
G4double DistanceToOut (const G4ThreeVector &p) const
 
G4GeometryType GetEntityType () const
 
G4ThreeVector GetPointOnSurface () const
 
G4VSolidClone () const
 
std::ostream & StreamInfo (std::ostream &os) const
 
void DescribeYourselfTo (G4VGraphicsScene &scene) const
 
G4VisExtent GetExtent () const
 
G4PolyhedronCreatePolyhedron () const
 
 G4Box (__void__ &)
 
 G4Box (const G4Box &rhs)
 
G4Boxoperator= (const G4Box &rhs)
 
- Public Member Functions inherited from G4CSGSolid
 G4CSGSolid (const G4String &pName)
 
virtual ~G4CSGSolid ()
 
virtual G4PolyhedronGetPolyhedron () const
 
 G4CSGSolid (__void__ &)
 
 G4CSGSolid (const G4CSGSolid &rhs)
 
G4CSGSolidoperator= (const G4CSGSolid &rhs)
 
- Public Member Functions inherited from G4VSolid
 G4VSolid (const G4String &name)
 
virtual ~G4VSolid ()
 
G4bool operator== (const G4VSolid &s) const
 
G4String GetName () const
 
void SetName (const G4String &name)
 
G4double GetTolerance () const
 
void DumpInfo () const
 
virtual const G4VSolidGetConstituentSolid (G4int no) const
 
virtual G4VSolidGetConstituentSolid (G4int no)
 
virtual const G4DisplacedSolidGetDisplacedSolidPtr () const
 
virtual G4DisplacedSolidGetDisplacedSolidPtr ()
 
 G4VSolid (__void__ &)
 
 G4VSolid (const G4VSolid &rhs)
 
G4VSolidoperator= (const G4VSolid &rhs)
 

Protected Types

enum  ESide {
  kUndefined, kPX, kMX, kPY,
  kMY, kPZ, kMZ
}
 

Protected Member Functions

G4ThreeVectorListCreateRotatedVertices (const G4AffineTransform &pTransform) const
 
- Protected Member Functions inherited from G4CSGSolid
G4double GetRadiusInRing (G4double rmin, G4double rmax) const
 
- Protected Member Functions inherited from G4VSolid
void CalculateClippedPolygonExtent (G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
 
void ClipCrossSection (G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
 
void ClipBetweenSections (G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
 
void ClipPolygon (G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis) const
 
G4double EstimateCubicVolume (G4int nStat, G4double epsilon) const
 
G4double EstimateSurfaceArea (G4int nStat, G4double ell) const
 

Additional Inherited Members

- Protected Attributes inherited from G4CSGSolid
G4double fCubicVolume
 
G4double fSurfaceArea
 
G4PolyhedronfpPolyhedron
 
- Protected Attributes inherited from G4VSolid
G4double kCarTolerance
 

Detailed Description

Definition at line 63 of file G4Box.hh.

Member Enumeration Documentation

enum G4Box::ESide
protected
Enumerator
kUndefined 
kPX 
kMX 
kPY 
kMY 
kPZ 
kMZ 

Definition at line 139 of file G4Box.hh.

Constructor & Destructor Documentation

G4Box::G4Box ( const G4String pName,
G4double  pX,
G4double  pY,
G4double  pZ 
)

Definition at line 61 of file G4Box.cc.

References FatalException, G4endl, G4Exception(), G4VSolid::GetName(), and G4VSolid::kCarTolerance.

Referenced by Clone().

65  : G4CSGSolid(pName), fDx(pX), fDy(pY), fDz(pZ)
66 {
67  delta = 0.5*kCarTolerance;
68  if ( (pX < 2*kCarTolerance)
69  || (pY < 2*kCarTolerance)
70  || (pZ < 2*kCarTolerance) ) // limit to thickness of surfaces
71  {
72  std::ostringstream message;
73  message << "Dimensions too small for Solid: " << GetName() << "!" << G4endl
74  << " hX, hY, hZ = " << pX << ", " << pY << ", " << pZ;
75  G4Exception("G4Box::G4Box()", "GeomSolids0002", FatalException, message);
76  }
77 }
G4String GetName() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4CSGSolid(const G4String &pName)
Definition: G4CSGSolid.cc:42
#define G4endl
Definition: G4ios.hh:61
G4double kCarTolerance
Definition: G4VSolid.hh:305
G4Box::~G4Box ( )
virtual

Definition at line 93 of file G4Box.cc.

94 {
95 }
G4Box::G4Box ( __void__ &  a)

Definition at line 84 of file G4Box.cc.

85  : G4CSGSolid(a), fDx(0.), fDy(0.), fDz(0.), delta(0.)
86 {
87 }
G4CSGSolid(const G4String &pName)
Definition: G4CSGSolid.cc:42
G4Box::G4Box ( const G4Box rhs)

Definition at line 101 of file G4Box.cc.

102  : G4CSGSolid(rhs), fDx(rhs.fDx), fDy(rhs.fDy), fDz(rhs.fDz), delta(rhs.delta)
103 {
104 }
G4CSGSolid(const G4String &pName)
Definition: G4CSGSolid.cc:42

Member Function Documentation

G4bool G4Box::CalculateExtent ( const EAxis  pAxis,
const G4VoxelLimits pVoxelLimit,
const G4AffineTransform pTransform,
G4double pmin,
G4double pmax 
) const
virtual

Implements G4VSolid.

Definition at line 208 of file G4Box.cc.

References G4VSolid::ClipBetweenSections(), G4VSolid::ClipCrossSection(), CreateRotatedVertices(), G4VoxelLimits::GetMaxExtent(), G4VoxelLimits::GetMaxXExtent(), G4VoxelLimits::GetMaxYExtent(), G4VoxelLimits::GetMaxZExtent(), G4VoxelLimits::GetMinExtent(), G4VoxelLimits::GetMinXExtent(), G4VoxelLimits::GetMinYExtent(), G4VoxelLimits::GetMinZExtent(), Inside(), G4AffineTransform::Inverse(), G4VoxelLimits::IsLimited(), G4AffineTransform::IsRotated(), G4VoxelLimits::IsXLimited(), G4VoxelLimits::IsYLimited(), G4VoxelLimits::IsZLimited(), G4VSolid::kCarTolerance, kOutside, kXAxis, kYAxis, kZAxis, G4INCL::Math::max(), G4INCL::Math::min(), G4AffineTransform::NetTranslation(), G4AffineTransform::TransformPoint(), CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

212 {
213  if (!pTransform.IsRotated())
214  {
215  // Special case handling for unrotated boxes
216  // Compute x/y/z mins and maxs respecting limits, with early returns
217  // if outside limits. Then switch() on pAxis
218 
219  G4double xoffset,xMin,xMax;
220  G4double yoffset,yMin,yMax;
221  G4double zoffset,zMin,zMax;
222 
223  xoffset = pTransform.NetTranslation().x() ;
224  xMin = xoffset - fDx ;
225  xMax = xoffset + fDx ;
226 
227  if (pVoxelLimit.IsXLimited())
228  {
229  if ((xMin > pVoxelLimit.GetMaxXExtent()+kCarTolerance) ||
230  (xMax < pVoxelLimit.GetMinXExtent()-kCarTolerance)) { return false ; }
231  else
232  {
233  xMin = std::max(xMin, pVoxelLimit.GetMinXExtent());
234  xMax = std::min(xMax, pVoxelLimit.GetMaxXExtent());
235  }
236  }
237  yoffset = pTransform.NetTranslation().y() ;
238  yMin = yoffset - fDy ;
239  yMax = yoffset + fDy ;
240 
241  if (pVoxelLimit.IsYLimited())
242  {
243  if ((yMin > pVoxelLimit.GetMaxYExtent()+kCarTolerance) ||
244  (yMax < pVoxelLimit.GetMinYExtent()-kCarTolerance)) { return false ; }
245  else
246  {
247  yMin = std::max(yMin, pVoxelLimit.GetMinYExtent());
248  yMax = std::min(yMax, pVoxelLimit.GetMaxYExtent());
249  }
250  }
251  zoffset = pTransform.NetTranslation().z() ;
252  zMin = zoffset - fDz ;
253  zMax = zoffset + fDz ;
254 
255  if (pVoxelLimit.IsZLimited())
256  {
257  if ((zMin > pVoxelLimit.GetMaxZExtent()+kCarTolerance) ||
258  (zMax < pVoxelLimit.GetMinZExtent()-kCarTolerance)) { return false ; }
259  else
260  {
261  zMin = std::max(zMin, pVoxelLimit.GetMinZExtent());
262  zMax = std::min(zMax, pVoxelLimit.GetMaxZExtent());
263  }
264  }
265  switch (pAxis)
266  {
267  case kXAxis:
268  pMin = xMin ;
269  pMax = xMax ;
270  break ;
271  case kYAxis:
272  pMin=yMin;
273  pMax=yMax;
274  break;
275  case kZAxis:
276  pMin=zMin;
277  pMax=zMax;
278  break;
279  default:
280  break;
281  }
282  pMin -= kCarTolerance ;
283  pMax += kCarTolerance ;
284 
285  return true;
286  }
287  else // General rotated case - create and clip mesh to boundaries
288  {
289  G4bool existsAfterClip = false ;
290  G4ThreeVectorList* vertices ;
291 
292  pMin = +kInfinity ;
293  pMax = -kInfinity ;
294 
295  // Calculate rotated vertex coordinates
296 
297  vertices = CreateRotatedVertices(pTransform) ;
298  ClipCrossSection(vertices,0,pVoxelLimit,pAxis,pMin,pMax) ;
299  ClipCrossSection(vertices,4,pVoxelLimit,pAxis,pMin,pMax) ;
300  ClipBetweenSections(vertices,0,pVoxelLimit,pAxis,pMin,pMax) ;
301 
302  if (pVoxelLimit.IsLimited(pAxis) == false)
303  {
304  if ( (pMin != kInfinity) || (pMax != -kInfinity) )
305  {
306  existsAfterClip = true ;
307 
308  // Add 2*tolerance to avoid precision troubles
309 
310  pMin -= kCarTolerance;
311  pMax += kCarTolerance;
312  }
313  }
314  else
315  {
316  G4ThreeVector clipCentre(
317  ( pVoxelLimit.GetMinXExtent()+pVoxelLimit.GetMaxXExtent())*0.5,
318  ( pVoxelLimit.GetMinYExtent()+pVoxelLimit.GetMaxYExtent())*0.5,
319  ( pVoxelLimit.GetMinZExtent()+pVoxelLimit.GetMaxZExtent())*0.5);
320 
321  if ( (pMin != kInfinity) || (pMax != -kInfinity) )
322  {
323  existsAfterClip = true ;
324 
325 
326  // Check to see if endpoints are in the solid
327 
328  clipCentre(pAxis) = pVoxelLimit.GetMinExtent(pAxis);
329 
330  if (Inside(pTransform.Inverse().TransformPoint(clipCentre)) != kOutside)
331  {
332  pMin = pVoxelLimit.GetMinExtent(pAxis);
333  }
334  else
335  {
336  pMin -= kCarTolerance;
337  }
338  clipCentre(pAxis) = pVoxelLimit.GetMaxExtent(pAxis);
339 
340  if (Inside(pTransform.Inverse().TransformPoint(clipCentre)) != kOutside)
341  {
342  pMax = pVoxelLimit.GetMaxExtent(pAxis);
343  }
344  else
345  {
346  pMax += kCarTolerance;
347  }
348  }
349 
350  // Check for case where completely enveloping clipping volume
351  // If point inside then we are confident that the solid completely
352  // envelopes the clipping volume. Hence set min/max extents according
353  // to clipping volume extents along the specified axis.
354 
355  else if (Inside(pTransform.Inverse().TransformPoint(clipCentre))
356  != kOutside)
357  {
358  existsAfterClip = true ;
359  pMin = pVoxelLimit.GetMinExtent(pAxis) ;
360  pMax = pVoxelLimit.GetMaxExtent(pAxis) ;
361  }
362  }
363  delete vertices;
364  return existsAfterClip;
365  }
366 }
void ClipCrossSection(G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
Definition: G4VSolid.cc:347
G4double GetMinYExtent() const
double x() const
G4AffineTransform Inverse() const
G4bool IsYLimited() const
G4bool IsRotated() const
G4ThreeVector NetTranslation() const
G4bool IsXLimited() const
double z() const
G4double GetMaxXExtent() const
G4double GetMinZExtent() const
G4bool IsLimited() const
bool G4bool
Definition: G4Types.hh:79
std::vector< G4ThreeVector > G4ThreeVectorList
Definition: G4VSolid.hh:79
G4ThreeVectorList * CreateRotatedVertices(const G4AffineTransform &pTransform) const
Definition: G4Box.cc:918
G4double GetMinXExtent() const
G4ThreeVector TransformPoint(const G4ThreeVector &vec) const
EInside Inside(const G4ThreeVector &p) const
Definition: G4Box.cc:372
G4double GetMaxZExtent() const
T max(const T t1, const T t2)
brief Return the largest of the two arguments
double y() const
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4double GetMaxYExtent() const
G4double kCarTolerance
Definition: G4VSolid.hh:305
double G4double
Definition: G4Types.hh:76
G4double GetMaxExtent(const EAxis pAxis) const
G4bool IsZLimited() const
void ClipBetweenSections(G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
Definition: G4VSolid.cc:378
G4double GetMinExtent(const EAxis pAxis) const
G4VSolid * G4Box::Clone ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 1029 of file G4Box.cc.

References G4Box().

1030 {
1031  return new G4Box(*this);
1032 }
G4Box(const G4String &pName, G4double pX, G4double pY, G4double pZ)
Definition: G4Box.cc:61
void G4Box::ComputeDimensions ( G4VPVParameterisation p,
const G4int  n,
const G4VPhysicalVolume pRep 
)
virtual

Reimplemented from G4VSolid.

Definition at line 197 of file G4Box.cc.

References G4VPVParameterisation::ComputeDimensions().

200 {
201  p->ComputeDimensions(*this,n,pRep);
202 }
const G4int n
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
G4Polyhedron * G4Box::CreatePolyhedron ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 1048 of file G4Box.cc.

Referenced by G4GMocrenFileSceneHandler::AddSolid().

1049 {
1050  return new G4PolyhedronBox (fDx, fDy, fDz);
1051 }
G4ThreeVectorList * G4Box::CreateRotatedVertices ( const G4AffineTransform pTransform) const
protected

Definition at line 918 of file G4Box.cc.

References G4VSolid::DumpInfo(), FatalException, G4Exception(), and G4AffineTransform::TransformPoint().

Referenced by CalculateExtent().

919 {
920  G4ThreeVectorList* vertices = new G4ThreeVectorList();
921 
922  if (vertices)
923  {
924  vertices->reserve(8);
925  G4ThreeVector vertex0(-fDx,-fDy,-fDz) ;
926  G4ThreeVector vertex1(fDx,-fDy,-fDz) ;
927  G4ThreeVector vertex2(fDx,fDy,-fDz) ;
928  G4ThreeVector vertex3(-fDx,fDy,-fDz) ;
929  G4ThreeVector vertex4(-fDx,-fDy,fDz) ;
930  G4ThreeVector vertex5(fDx,-fDy,fDz) ;
931  G4ThreeVector vertex6(fDx,fDy,fDz) ;
932  G4ThreeVector vertex7(-fDx,fDy,fDz) ;
933 
934  vertices->push_back(pTransform.TransformPoint(vertex0));
935  vertices->push_back(pTransform.TransformPoint(vertex1));
936  vertices->push_back(pTransform.TransformPoint(vertex2));
937  vertices->push_back(pTransform.TransformPoint(vertex3));
938  vertices->push_back(pTransform.TransformPoint(vertex4));
939  vertices->push_back(pTransform.TransformPoint(vertex5));
940  vertices->push_back(pTransform.TransformPoint(vertex6));
941  vertices->push_back(pTransform.TransformPoint(vertex7));
942  }
943  else
944  {
945  DumpInfo();
946  G4Exception("G4Box::CreateRotatedVertices()",
947  "GeomSolids0003", FatalException,
948  "Error in allocation of vertices. Out of memory !");
949  }
950  return vertices;
951 }
void DumpInfo() const
std::vector< G4ThreeVector > G4ThreeVectorList
Definition: G4VSolid.hh:79
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4ThreeVector TransformPoint(const G4ThreeVector &vec) const
void G4Box::DescribeYourselfTo ( G4VGraphicsScene scene) const
virtual

Implements G4VSolid.

Definition at line 1038 of file G4Box.cc.

References G4VGraphicsScene::AddSolid().

1039 {
1040  scene.AddSolid (*this);
1041 }
virtual void AddSolid(const G4Box &)=0
G4double G4Box::DistanceToIn ( const G4ThreeVector p,
const G4ThreeVector v 
) const
virtual

Implements G4VSolid.

Definition at line 556 of file G4Box.cc.

References smax, CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

Referenced by G4SurfaceVoxelizer::DistanceToFirst().

558 {
559  G4double safx, safy, safz ;
560  G4double smin=0.0, sminy, sminz ; // , sminx ;
561  G4double smax=kInfinity, smaxy, smaxz ; // , smaxx ; // they always > 0
562  G4double stmp ;
563  G4double sOut=kInfinity, sOuty=kInfinity, sOutz=kInfinity ;
564 
565  safx = std::fabs(p.x()) - fDx ; // minimum distance to x surface of shape
566  safy = std::fabs(p.y()) - fDy ;
567  safz = std::fabs(p.z()) - fDz ;
568 
569  // Will we intersect?
570  // If safx/y/z is >-tol/2 the point is outside/on the box's x/y/z extent.
571  // If both p.x/y/z and v.x/y/z repectively are both positive/negative,
572  // travel is in a direction away from the shape.
573 
574  if ( ((p.x()*v.x() >= 0.0) && (safx > -delta))
575  || ((p.y()*v.y() >= 0.0) && (safy > -delta))
576  || ((p.z()*v.z() >= 0.0) && (safz > -delta)) )
577  {
578  return kInfinity ; // travel away or parallel within tolerance
579  }
580 
581  // Compute min / max distances for x/y/z travel:
582  // X Planes
583 
584  if ( v.x() ) // != 0
585  {
586  stmp = 1.0/std::fabs(v.x()) ;
587 
588  if (safx >= 0.0)
589  {
590  smin = safx*stmp ;
591  smax = (fDx+std::fabs(p.x()))*stmp ;
592  }
593  else
594  {
595  if (v.x() < 0) { sOut = (fDx + p.x())*stmp ; }
596  else { sOut = (fDx - p.x())*stmp ; }
597  }
598  }
599 
600  // Y Planes
601 
602  if ( v.y() ) // != 0
603  {
604  stmp = 1.0/std::fabs(v.y()) ;
605 
606  if (safy >= 0.0)
607  {
608  sminy = safy*stmp ;
609  smaxy = (fDy+std::fabs(p.y()))*stmp ;
610 
611  if (sminy > smin) { smin=sminy ; }
612  if (smaxy < smax) { smax=smaxy ; }
613 
614  if (smin >= (smax-delta))
615  {
616  return kInfinity ; // touch XY corner
617  }
618  }
619  else
620  {
621  if (v.y() < 0) { sOuty = (fDy + p.y())*stmp ; }
622  else { sOuty = (fDy - p.y())*stmp ; }
623  if( sOuty < sOut ) { sOut = sOuty ; }
624  }
625  }
626 
627  // Z planes
628 
629  if ( v.z() ) // != 0
630  {
631  stmp = 1.0/std::fabs(v.z()) ;
632 
633  if ( safz >= 0.0 )
634  {
635  sminz = safz*stmp ;
636  smaxz = (fDz+std::fabs(p.z()))*stmp ;
637 
638  if (sminz > smin) { smin = sminz ; }
639  if (smaxz < smax) { smax = smaxz ; }
640 
641  if (smin >= (smax-delta))
642  {
643  return kInfinity ; // touch ZX or ZY corners
644  }
645  }
646  else
647  {
648  if (v.z() < 0) { sOutz = (fDz + p.z())*stmp ; }
649  else { sOutz = (fDz - p.z())*stmp ; }
650  if( sOutz < sOut ) { sOut = sOutz ; }
651  }
652  }
653 
654  if (sOut <= (smin + delta)) // travel over edge
655  {
656  return kInfinity ;
657  }
658  if (smin < delta) { smin = 0.0 ; }
659 
660  return smin ;
661 }
double x() const
const G4int smax
double z() const
double y() const
double G4double
Definition: G4Types.hh:76
G4double G4Box::DistanceToIn ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Definition at line 670 of file G4Box.cc.

References CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

671 {
672  G4double safex, safey, safez, safe = 0.0 ;
673 
674  safex = std::fabs(p.x()) - fDx ;
675  safey = std::fabs(p.y()) - fDy ;
676  safez = std::fabs(p.z()) - fDz ;
677 
678  if (safex > safe) { safe = safex ; }
679  if (safey > safe) { safe = safey ; }
680  if (safez > safe) { safe = safez ; }
681 
682  return safe ;
683 }
double x() const
double z() const
double y() const
double G4double
Definition: G4Types.hh:76
G4double G4Box::DistanceToOut ( const G4ThreeVector p,
const G4ThreeVector v,
const G4bool  calcNorm = false,
G4bool validNorm = 0,
G4ThreeVector n = 0 
) const
virtual

Implements G4VSolid.

Definition at line 693 of file G4Box.cc.

References G4VSolid::DumpInfo(), G4cout, G4endl, G4Exception(), JustWarning, kMX, kMY, kMZ, kPX, kPY, kPZ, kUndefined, python.hepunit::mm, CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

696 {
697  ESide side = kUndefined ;
698  G4double pdist,stmp,snxt=kInfinity;
699 
700  if (calcNorm) { *validNorm = true ; } // All normals are valid
701 
702  if (v.x() > 0) // X planes
703  {
704  pdist = fDx - p.x() ;
705 
706  if (pdist > delta)
707  {
708  snxt = pdist/v.x() ;
709  side = kPX ;
710  }
711  else
712  {
713  if (calcNorm) { *n = G4ThreeVector(1,0,0) ; }
714  return snxt = 0 ;
715  }
716  }
717  else if (v.x() < 0)
718  {
719  pdist = fDx + p.x() ;
720 
721  if (pdist > delta)
722  {
723  snxt = -pdist/v.x() ;
724  side = kMX ;
725  }
726  else
727  {
728  if (calcNorm) { *n = G4ThreeVector(-1,0,0) ; }
729  return snxt = 0 ;
730  }
731  }
732 
733  if (v.y() > 0) // Y planes
734  {
735  pdist = fDy-p.y();
736 
737  if (pdist > delta)
738  {
739  stmp = pdist/v.y();
740 
741  if (stmp < snxt)
742  {
743  snxt = stmp;
744  side = kPY;
745  }
746  }
747  else
748  {
749  if (calcNorm) { *n = G4ThreeVector(0,1,0) ; }
750  return snxt = 0 ;
751  }
752  }
753  else if (v.y() < 0)
754  {
755  pdist = fDy + p.y() ;
756 
757  if (pdist > delta)
758  {
759  stmp = -pdist/v.y();
760 
761  if ( stmp < snxt )
762  {
763  snxt = stmp;
764  side = kMY;
765  }
766  }
767  else
768  {
769  if (calcNorm) { *n = G4ThreeVector(0,-1,0) ; }
770  return snxt = 0 ;
771  }
772  }
773 
774  if (v.z() > 0) // Z planes
775  {
776  pdist = fDz-p.z();
777 
778  if ( pdist > delta )
779  {
780  stmp = pdist/v.z();
781 
782  if ( stmp < snxt )
783  {
784  snxt = stmp;
785  side = kPZ;
786  }
787  }
788  else
789  {
790  if (calcNorm) { *n = G4ThreeVector(0,0,1) ; }
791  return snxt = 0 ;
792  }
793  }
794  else if (v.z() < 0)
795  {
796  pdist = fDz + p.z();
797 
798  if ( pdist > delta )
799  {
800  stmp = -pdist/v.z();
801 
802  if ( stmp < snxt )
803  {
804  snxt = stmp;
805  side = kMZ;
806  }
807  }
808  else
809  {
810  if (calcNorm) { *n = G4ThreeVector(0,0,-1) ; }
811  return snxt = 0 ;
812  }
813  }
814 
815  if (calcNorm)
816  {
817  switch (side)
818  {
819  case kPX:
820  *n=G4ThreeVector(1,0,0);
821  break;
822  case kMX:
823  *n=G4ThreeVector(-1,0,0);
824  break;
825  case kPY:
826  *n=G4ThreeVector(0,1,0);
827  break;
828  case kMY:
829  *n=G4ThreeVector(0,-1,0);
830  break;
831  case kPZ:
832  *n=G4ThreeVector(0,0,1);
833  break;
834  case kMZ:
835  *n=G4ThreeVector(0,0,-1);
836  break;
837  default:
838  G4cout << G4endl;
839  DumpInfo();
840  std::ostringstream message;
841  G4int oldprc = message.precision(16);
842  message << "Undefined side for valid surface normal to solid."
843  << G4endl
844  << "Position:" << G4endl << G4endl
845  << "p.x() = " << p.x()/mm << " mm" << G4endl
846  << "p.y() = " << p.y()/mm << " mm" << G4endl
847  << "p.z() = " << p.z()/mm << " mm" << G4endl << G4endl
848  << "Direction:" << G4endl << G4endl
849  << "v.x() = " << v.x() << G4endl
850  << "v.y() = " << v.y() << G4endl
851  << "v.z() = " << v.z() << G4endl << G4endl
852  << "Proposed distance :" << G4endl << G4endl
853  << "snxt = " << snxt/mm << " mm" << G4endl;
854  message.precision(oldprc);
855  G4Exception("G4Box::DistanceToOut(p,v,..)", "GeomSolids1002",
856  JustWarning, message);
857  break;
858  }
859  }
860  return snxt;
861 }
CLHEP::Hep3Vector G4ThreeVector
double x() const
int G4int
Definition: G4Types.hh:78
double z() const
void DumpInfo() const
G4GLOB_DLL std::ostream G4cout
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double y() const
#define G4endl
Definition: G4ios.hh:61
ESide
Definition: G4Cons.cc:68
double G4double
Definition: G4Types.hh:76
G4double G4Box::DistanceToOut ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Definition at line 868 of file G4Box.cc.

References G4VSolid::DumpInfo(), G4cout, G4endl, G4Exception(), Inside(), JustWarning, kOutside, python.hepunit::mm, CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

869 {
870  G4double safx1,safx2,safy1,safy2,safz1,safz2,safe=0.0;
871 
872 #ifdef G4CSGDEBUG
873  if( Inside(p) == kOutside )
874  {
875  G4int oldprc = G4cout.precision(16) ;
876  G4cout << G4endl ;
877  DumpInfo();
878  G4cout << "Position:" << G4endl << G4endl ;
879  G4cout << "p.x() = " << p.x()/mm << " mm" << G4endl ;
880  G4cout << "p.y() = " << p.y()/mm << " mm" << G4endl ;
881  G4cout << "p.z() = " << p.z()/mm << " mm" << G4endl << G4endl ;
882  G4cout.precision(oldprc) ;
883  G4Exception("G4Box::DistanceToOut(p)", "GeomSolids1002",
884  JustWarning, "Point p is outside !?" );
885  }
886 #endif
887 
888  safx1 = fDx - p.x() ;
889  safx2 = fDx + p.x() ;
890  safy1 = fDy - p.y() ;
891  safy2 = fDy + p.y() ;
892  safz1 = fDz - p.z() ;
893  safz2 = fDz + p.z() ;
894 
895  // shortest Dist to any boundary now MIN(safx1,safx2,safy1..)
896 
897  if (safx2 < safx1) { safe = safx2; }
898  else { safe = safx1; }
899  if (safy1 < safe) { safe = safy1; }
900  if (safy2 < safe) { safe = safy2; }
901  if (safz1 < safe) { safe = safz1; }
902  if (safz2 < safe) { safe = safz2; }
903 
904  if (safe < 0) { safe = 0 ; }
905  return safe ;
906 }
double x() const
int G4int
Definition: G4Types.hh:78
double z() const
void DumpInfo() const
G4GLOB_DLL std::ostream G4cout
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
EInside Inside(const G4ThreeVector &p) const
Definition: G4Box.cc:372
double y() const
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4double G4Box::GetCubicVolume ( )
inlinevirtual

Reimplemented from G4VSolid.

G4GeometryType G4Box::GetEntityType ( ) const
virtual

Implements G4VSolid.

Definition at line 957 of file G4Box.cc.

G4VisExtent G4Box::GetExtent ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 1043 of file G4Box.cc.

1044 {
1045  return G4VisExtent (-fDx, fDx, -fDy, fDy, -fDz, fDz);
1046 }
G4ThreeVector G4Box::GetPointOnSurface ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 990 of file G4Box.cc.

References G4UniformRand.

991 {
992  G4double px, py, pz, select, sumS;
993  G4double Sxy = fDx*fDy, Sxz = fDx*fDz, Syz = fDy*fDz;
994 
995  sumS = Sxy + Sxz + Syz;
996  select = sumS*G4UniformRand();
997 
998  if( select < Sxy )
999  {
1000  px = -fDx +2*fDx*G4UniformRand();
1001  py = -fDy +2*fDy*G4UniformRand();
1002 
1003  if(G4UniformRand() > 0.5) { pz = fDz; }
1004  else { pz = -fDz; }
1005  }
1006  else if ( ( select - Sxy ) < Sxz )
1007  {
1008  px = -fDx +2*fDx*G4UniformRand();
1009  pz = -fDz +2*fDz*G4UniformRand();
1010 
1011  if(G4UniformRand() > 0.5) { py = fDy; }
1012  else { py = -fDy; }
1013  }
1014  else
1015  {
1016  py = -fDy +2*fDy*G4UniformRand();
1017  pz = -fDz +2*fDz*G4UniformRand();
1018 
1019  if(G4UniformRand() > 0.5) { px = fDx; }
1020  else { px = -fDx; }
1021  }
1022  return G4ThreeVector(px,py,pz);
1023 }
CLHEP::Hep3Vector G4ThreeVector
#define G4UniformRand()
Definition: Randomize.hh:87
double G4double
Definition: G4Types.hh:76
G4double G4Box::GetSurfaceArea ( )
inlinevirtual

Reimplemented from G4VSolid.

G4double G4Box::GetXHalfLength ( ) const
inline
G4double G4Box::GetYHalfLength ( ) const
inline
G4double G4Box::GetZHalfLength ( ) const
inline
EInside G4Box::Inside ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Definition at line 372 of file G4Box.cc.

References kInside, kOutside, kSurface, CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

Referenced by CalculateExtent(), and DistanceToOut().

373 {
374  EInside in = kOutside ;
375  G4ThreeVector q(std::fabs(p.x()), std::fabs(p.y()), std::fabs(p.z()));
376 
377  if ( q.x() <= (fDx - delta) )
378  {
379  if (q.y() <= (fDy - delta) )
380  {
381  if ( q.z() <= (fDz - delta) ) { in = kInside ; }
382  else if ( q.z() <= (fDz + delta) ) { in = kSurface ; }
383  }
384  else if ( q.y() <= (fDy + delta) )
385  {
386  if ( q.z() <= (fDz + delta) ) { in = kSurface ; }
387  }
388  }
389  else if ( q.x() <= (fDx + delta) )
390  {
391  if ( q.y() <= (fDy + delta) )
392  {
393  if ( q.z() <= (fDz + delta) ) { in = kSurface ; }
394  }
395  }
396  return in ;
397 }
double x() const
double z() const
EInside
Definition: geomdefs.hh:58
double y() const
G4Box & G4Box::operator= ( const G4Box rhs)

Definition at line 110 of file G4Box.cc.

References G4CSGSolid::operator=().

111 {
112  // Check assignment to self
113  //
114  if (this == &rhs) { return *this; }
115 
116  // Copy base class data
117  //
119 
120  // Copy data
121  //
122  fDx = rhs.fDx;
123  fDy = rhs.fDy;
124  fDz = rhs.fDz;
125  delta = rhs.delta;
126 
127  return *this;
128 }
G4CSGSolid & operator=(const G4CSGSolid &rhs)
Definition: G4CSGSolid.cc:82
void G4Box::SetXHalfLength ( G4double  dx)

Definition at line 132 of file G4Box.cc.

References FatalException, G4CSGSolid::fCubicVolume, G4CSGSolid::fpPolyhedron, G4CSGSolid::fSurfaceArea, G4endl, G4Exception(), G4VSolid::GetName(), and G4VSolid::kCarTolerance.

Referenced by VoxelParam::ComputeDimensions(), ExN02ChamberParameterisation::ComputeDimensions(), ExP01ChamberParameterisation::ComputeDimensions(), G02ChamberParameterisation::ComputeDimensions(), G4ParameterisationBoxX::ComputeDimensions(), DicomNestedPhantomParameterisation::ComputeDimensions(), RE02NestedPhantomParameterisation::ComputeDimensions(), G4ParameterisationBoxY::ComputeDimensions(), G4ParameterisationBoxZ::ComputeDimensions(), export_G4Box(), G4STRead::Read(), and HadrontherapyDetectorROGeometry::UpdateROGeometry().

133 {
134  if(dx > 2*kCarTolerance) // limit to thickness of surfaces
135  {
136  fDx = dx;
137  }
138  else
139  {
140  std::ostringstream message;
141  message << "Dimension X too small for solid: " << GetName() << "!"
142  << G4endl
143  << " hX = " << dx;
144  G4Exception("G4Box::SetXHalfLength()", "GeomSolids0002",
145  FatalException, message);
146  }
147  fCubicVolume= 0.;
148  fSurfaceArea= 0.;
149  fpPolyhedron = 0;
150 }
G4String GetName() const
G4double fCubicVolume
Definition: G4CSGSolid.hh:78
G4double fSurfaceArea
Definition: G4CSGSolid.hh:79
G4Polyhedron * fpPolyhedron
Definition: G4CSGSolid.hh:80
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define G4endl
Definition: G4ios.hh:61
G4double kCarTolerance
Definition: G4VSolid.hh:305
void G4Box::SetYHalfLength ( G4double  dy)

Definition at line 152 of file G4Box.cc.

References FatalException, G4CSGSolid::fCubicVolume, G4CSGSolid::fpPolyhedron, G4CSGSolid::fSurfaceArea, G4endl, G4Exception(), G4VSolid::GetName(), and G4VSolid::kCarTolerance.

Referenced by VoxelParam::ComputeDimensions(), ExN02ChamberParameterisation::ComputeDimensions(), ExP01ChamberParameterisation::ComputeDimensions(), G02ChamberParameterisation::ComputeDimensions(), G4ParameterisationBoxX::ComputeDimensions(), DicomNestedPhantomParameterisation::ComputeDimensions(), RE02NestedPhantomParameterisation::ComputeDimensions(), G4ParameterisationBoxY::ComputeDimensions(), G4ParameterisationBoxZ::ComputeDimensions(), export_G4Box(), G4STRead::Read(), and HadrontherapyDetectorROGeometry::UpdateROGeometry().

153 {
154  if(dy > 2*kCarTolerance) // limit to thickness of surfaces
155  {
156  fDy = dy;
157  }
158  else
159  {
160  std::ostringstream message;
161  message << "Dimension Y too small for solid: " << GetName() << "!"
162  << G4endl
163  << " hY = " << dy;
164  G4Exception("G4Box::SetYHalfLength()", "GeomSolids0002",
165  FatalException, message);
166  }
167  fCubicVolume= 0.;
168  fSurfaceArea= 0.;
169  fpPolyhedron = 0;
170 }
G4String GetName() const
G4double fCubicVolume
Definition: G4CSGSolid.hh:78
G4double fSurfaceArea
Definition: G4CSGSolid.hh:79
G4Polyhedron * fpPolyhedron
Definition: G4CSGSolid.hh:80
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define G4endl
Definition: G4ios.hh:61
G4double kCarTolerance
Definition: G4VSolid.hh:305
void G4Box::SetZHalfLength ( G4double  dz)

Definition at line 172 of file G4Box.cc.

References FatalException, G4CSGSolid::fCubicVolume, G4CSGSolid::fpPolyhedron, G4CSGSolid::fSurfaceArea, G4endl, G4Exception(), G4VSolid::GetName(), and G4VSolid::kCarTolerance.

Referenced by VoxelParam::ComputeDimensions(), ExN02ChamberParameterisation::ComputeDimensions(), ExP01ChamberParameterisation::ComputeDimensions(), G02ChamberParameterisation::ComputeDimensions(), G4ParameterisationBoxX::ComputeDimensions(), DicomNestedPhantomParameterisation::ComputeDimensions(), RE02NestedPhantomParameterisation::ComputeDimensions(), G4ParameterisationBoxY::ComputeDimensions(), G4ParameterisationBoxZ::ComputeDimensions(), export_G4Box(), G4STRead::Read(), RE06DetectorConstruction::SetNumberOfLayers(), and HadrontherapyDetectorROGeometry::UpdateROGeometry().

173 {
174  if(dz > 2*kCarTolerance) // limit to thickness of surfaces
175  {
176  fDz = dz;
177  }
178  else
179  {
180  std::ostringstream message;
181  message << "Dimension Z too small for solid: " << GetName() << "!"
182  << G4endl
183  << " hZ = " << dz;
184  G4Exception("G4Box::SetZHalfLength()", "GeomSolids0002",
185  FatalException, message);
186  }
187  fCubicVolume= 0.;
188  fSurfaceArea= 0.;
189  fpPolyhedron = 0;
190 }
G4String GetName() const
G4double fCubicVolume
Definition: G4CSGSolid.hh:78
G4double fSurfaceArea
Definition: G4CSGSolid.hh:79
G4Polyhedron * fpPolyhedron
Definition: G4CSGSolid.hh:80
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define G4endl
Definition: G4ios.hh:61
G4double kCarTolerance
Definition: G4VSolid.hh:305
std::ostream & G4Box::StreamInfo ( std::ostream &  os) const
virtual

Reimplemented from G4CSGSolid.

Definition at line 966 of file G4Box.cc.

References G4VSolid::GetName(), and python.hepunit::mm.

967 {
968  G4int oldprc = os.precision(16);
969  os << "-----------------------------------------------------------\n"
970  << " *** Dump for solid - " << GetName() << " ***\n"
971  << " ===================================================\n"
972  << " Solid type: G4Box\n"
973  << " Parameters: \n"
974  << " half length X: " << fDx/mm << " mm \n"
975  << " half length Y: " << fDy/mm << " mm \n"
976  << " half length Z: " << fDz/mm << " mm \n"
977  << "-----------------------------------------------------------\n";
978  os.precision(oldprc);
979 
980  return os;
981 }
G4String GetName() const
int G4int
Definition: G4Types.hh:78
G4ThreeVector G4Box::SurfaceNormal ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Definition at line 405 of file G4Box.cc.

References G4Exception(), JustWarning, CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

406 {
407  G4double distx, disty, distz ;
408  G4ThreeVector norm(0.,0.,0.);
409 
410  // Calculate distances as if in 1st octant
411 
412  distx = std::fabs(std::fabs(p.x()) - fDx) ;
413  disty = std::fabs(std::fabs(p.y()) - fDy) ;
414  distz = std::fabs(std::fabs(p.z()) - fDz) ;
415 
416  // New code for particle on surface including edges and corners with specific
417  // normals
418 
419  const G4ThreeVector nX = G4ThreeVector( 1.0, 0,0 );
420  const G4ThreeVector nmX = G4ThreeVector(-1.0, 0,0 );
421  const G4ThreeVector nY = G4ThreeVector( 0, 1.0,0 );
422  const G4ThreeVector nmY = G4ThreeVector( 0,-1.0,0 );
423  const G4ThreeVector nZ = G4ThreeVector( 0, 0, 1.0);
424  const G4ThreeVector nmZ = G4ThreeVector( 0, 0,- 1.0);
425 
426  G4ThreeVector normX(0.,0.,0.), normY(0.,0.,0.), normZ(0.,0.,0.);
427  G4ThreeVector sumnorm(0., 0., 0.);
428  G4int noSurfaces=0;
429 
430  if (distx <= delta) // on X/mX surface and around
431  {
432  noSurfaces ++;
433  if ( p.x() >= 0. ) { normX= nX ; } // on +X surface : (1,0,0)
434  else { normX= nmX; } // (-1,0,0)
435  sumnorm= normX;
436  }
437 
438  if (disty <= delta) // on one of the +Y or -Y surfaces
439  {
440  noSurfaces ++;
441  if ( p.y() >= 0. ) { normY= nY; } // on +Y surface
442  else { normY= nmY; }
443  sumnorm += normY;
444  }
445 
446  if (distz <= delta) // on one of the +Z or -Z surfaces
447  {
448  noSurfaces ++;
449  if ( p.z() >= 0. ) { normZ= nZ; } // on +Z surface
450  else { normZ= nmZ; }
451  sumnorm += normZ;
452  }
453 
454  static const G4double invSqrt2 = 1.0 / std::sqrt(2.0);
455  static const G4double invSqrt3 = 1.0 / std::sqrt(3.0);
456 
457  if( noSurfaces > 0 )
458  {
459  if( noSurfaces == 1 )
460  {
461  norm= sumnorm;
462  }
463  else
464  {
465  // norm = sumnorm . unit();
466  if( noSurfaces == 2 )
467  {
468  // 2 surfaces -> on edge
469  norm = invSqrt2 * sumnorm;
470  }
471  else
472  {
473  // 3 surfaces (on corner)
474  norm = invSqrt3 * sumnorm;
475  }
476  }
477  }
478  else
479  {
480 #ifdef G4CSGDEBUG
481  G4Exception("G4Box::SurfaceNormal(p)", "Notification", JustWarning,
482  "Point p is not on surface !?" );
483 #endif
484  norm = ApproxSurfaceNormal(p);
485  }
486 
487  return norm;
488 }
CLHEP::Hep3Vector G4ThreeVector
double x() const
int G4int
Definition: G4Types.hh:78
double z() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double y() const
double G4double
Definition: G4Types.hh:76

The documentation for this class was generated from the following files: