G4BREPSolidSphere.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // ----------------------------------------------------------------------
00030 // GEANT 4 class source file
00031 //
00032 // G4BREPSolidSphere.cc
00033 //
00034 // ----------------------------------------------------------------------
00035 
00036 #include "G4BREPSolidSphere.hh"
00037 #include "G4PhysicalConstants.hh"
00038 #include "G4SphericalSurface.hh"
00039 
00040 G4BREPSolidSphere::G4BREPSolidSphere(const G4String& name,
00041                                      const G4Vector3D& origin,
00042                                      const G4Vector3D& xhat, 
00043                                      const G4Vector3D& zhat,
00044                                      G4double radius)
00045   : G4BREPSolid(name)
00046 {  
00047   constructorParams.origin = origin;
00048   constructorParams.xhat   = xhat;
00049   constructorParams.zhat   = zhat;
00050   constructorParams.radius = radius;
00051   
00052   active=1;
00053   InitializeSphere();
00054 }
00055 
00056 G4BREPSolidSphere::G4BREPSolidSphere( __void__& a )
00057   : G4BREPSolid(a)
00058 {
00059 }
00060 
00061 G4BREPSolidSphere::~G4BREPSolidSphere()
00062 {
00063 }
00064 
00065 G4BREPSolidSphere::G4BREPSolidSphere(const G4BREPSolidSphere& rhs)
00066   : G4BREPSolid(rhs)
00067 {
00068   constructorParams.origin = rhs.constructorParams.origin;
00069   constructorParams.xhat   = rhs.constructorParams.xhat;
00070   constructorParams.zhat   = rhs.constructorParams.zhat;
00071   constructorParams.radius = rhs.constructorParams.radius;
00072   
00073   InitializeSphere();
00074 }
00075 
00076 G4BREPSolidSphere&
00077 G4BREPSolidSphere::operator = (const G4BREPSolidSphere& rhs) 
00078 {
00079   // Check assignment to self
00080   //
00081   if (this == &rhs)  { return *this; }
00082 
00083   // Copy base class data
00084   //
00085   G4BREPSolid::operator=(rhs);
00086 
00087   // Copy data
00088   //
00089   constructorParams.origin = rhs.constructorParams.origin;
00090   constructorParams.xhat   = rhs.constructorParams.xhat;
00091   constructorParams.zhat   = rhs.constructorParams.zhat;
00092   constructorParams.radius = rhs.constructorParams.radius;
00093 
00094   InitializeSphere();
00095 
00096   return *this;
00097 }  
00098 
00099 void G4BREPSolidSphere::InitializeSphere()
00100 {
00101   SurfaceVec    = new G4Surface*[1];
00102   G4double ph1  = 0;
00103   G4double ph2  = 2*pi;
00104   G4double th1  = 0;
00105   G4double th2  = pi;
00106   SurfaceVec[0] = new G4SphericalSurface(constructorParams.origin,
00107                                          constructorParams.xhat,
00108                                          constructorParams.zhat,
00109                                          constructorParams.radius,
00110                                          ph1, ph2, th1, th2);
00111   nb_of_surfaces = 1;
00112   Initialize();
00113 }
00114 
00115 EInside G4BREPSolidSphere::Inside(register const G4ThreeVector& Pt) const
00116 {
00117   G4double Dist = SurfaceVec[0]->HowNear(Pt);
00118   if(Dist > 0+kCarTolerance) return kInside;
00119   if(Dist < 0-kCarTolerance) return kOutside;
00120   return kSurface;
00121 }
00122 
00123 
00124 G4ThreeVector G4BREPSolidSphere::SurfaceNormal(const G4ThreeVector& Pt) const
00125 {
00126   G4Vector3D n =  SurfaceVec[0]->Normal(Pt);
00127   G4ThreeVector norm(n.x(), n.y(), n.z());
00128   return norm;
00129 }
00130 
00131 
00132 G4double G4BREPSolidSphere::DistanceToIn(const G4ThreeVector& Pt) const
00133 {
00134   return  std::fabs(SurfaceVec[0]->HowNear(Pt));
00135 }
00136 
00137 
00138 G4double G4BREPSolidSphere::DistanceToIn(register const G4ThreeVector& Pt, 
00139                                          register const G4ThreeVector& V) const
00140 {
00141   // SphReset();  
00142   G4Vector3D Pttmp(Pt);
00143   G4Vector3D Vtmp(V);   
00144   G4Ray      r(Pttmp, Vtmp);
00145   G4int      Result = SurfaceVec[0]->Intersect( r );
00146 
00147   if(Result>0)
00148   {
00149     ShortestDistance = SurfaceVec[0]->GetDistance();
00150     return std::sqrt(ShortestDistance);
00151   }
00152   return kInfinity; 
00153 }
00154 
00155 
00156 G4double G4BREPSolidSphere::DistanceToOut(register const G4ThreeVector& Pt, 
00157                                           register const G4ThreeVector& V, 
00158                                           const G4bool calcNorm, 
00159                                           G4bool *validNorm, 
00160                                           G4ThreeVector *n) const
00161 {
00162   if(validNorm) *validNorm = false;
00163   // SphReset();  
00164   G4Vector3D Pttmp(Pt);
00165   G4Vector3D Vtmp(V);   
00166   G4Ray      r(Pttmp, Vtmp);
00167 
00168   if(SurfaceVec[0]->Intersect( r ))
00169   {
00170     if(calcNorm)
00171     {
00172       if(validNorm) *validNorm = true;
00173       *n = SurfaceNormal(Pt);
00174     }
00175 
00176     ShortestDistance = SurfaceVec[0]->GetDistance();
00177     return std::sqrt(ShortestDistance);
00178   }
00179   return kInfinity; 
00180 }
00181 
00182 
00183 G4double G4BREPSolidSphere::DistanceToOut(const G4ThreeVector& Pt) const
00184 {
00185   return  std::fabs(SurfaceVec[0]->HowNear(Pt));
00186 }
00187 
00188 G4VSolid* G4BREPSolidSphere::Clone() const
00189 {
00190   return new G4BREPSolidSphere(*this);
00191 }
00192 
00193 std::ostream& G4BREPSolidSphere::StreamInfo(std::ostream& os) const
00194 {
00195   // Streams solid contents to output stream.
00196 
00197   G4BREPSolid::StreamInfo( os )
00198   << "\n origin: " << constructorParams.origin
00199   << "\n xhat:   " << constructorParams.xhat
00200   << "\n zhat:   " << constructorParams.zhat
00201   << "\n radius: " << constructorParams.radius
00202   << "\n-----------------------------------------------------------\n";
00203 
00204   return os;
00205 }
00206 

Generated on Mon May 27 17:47:47 2013 for Geant4 by  doxygen 1.4.7