Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4UOrb.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id:$
27 //
28 //
29 // Implementation for G4UOrb wrapper class
30 // --------------------------------------------------------------------
31 
32 #include "G4Orb.hh"
33 #include "G4UOrb.hh"
34 
35 #if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
36 
37 #include "G4TwoVector.hh"
38 #include "G4AffineTransform.hh"
39 #include "G4GeometryTolerance.hh"
40 #include "G4BoundingEnvelope.hh"
41 
42 #include "G4VPVParameterisation.hh"
43 #include "G4PhysicalConstants.hh"
44 
45 using namespace CLHEP;
46 
48 //
49 // constructor - check positive radius
50 //
51 
52 G4UOrb::G4UOrb( const G4String& pName, G4double pRmax )
53  : G4USolid(pName, new UOrb(pName, pRmax))
54 {
55 }
56 
58 //
59 // Fake default constructor - sets only member data and allocates memory
60 // for usage restricted to object persistency.
61 //
62 G4UOrb::G4UOrb( __void__& a )
63  : G4USolid(a)
64 {
65 }
66 
68 //
69 // Destructor
70 
71 G4UOrb::~G4UOrb()
72 {
73 }
74 
76 //
77 // Copy constructor
78 
79 G4UOrb::G4UOrb(const G4UOrb& rhs)
80  : G4USolid(rhs)
81 {
82 }
83 
85 //
86 // Assignment operator
87 
88 G4UOrb& G4UOrb::operator = (const G4UOrb& rhs)
89 {
90  // Check assignment to self
91  //
92  if (this == &rhs) { return *this; }
93 
94  // Copy base class data
95  //
96  G4USolid::operator=(rhs);
97 
98  return *this;
99 }
100 
102 //
103 // Accessors & modifiers
104 
105 G4double G4UOrb::GetRadius() const
106 {
107  return GetShape()->GetRadius();
108 }
109 
110 void G4UOrb::SetRadius(G4double newRmax)
111 {
112  GetShape()->SetRadius(newRmax);
113  fRebuildPolyhedron = true;
114 }
115 
116 G4double G4UOrb::GetRadialTolerance() const
117 {
118  return GetShape()->GetRadialTolerance();
119 }
120 
122 //
123 // Dispatch to parameterisation for replication mechanism dimension
124 // computation & modification.
125 
126 void G4UOrb::ComputeDimensions( G4VPVParameterisation* p,
127  const G4int n,
128  const G4VPhysicalVolume* pRep )
129 {
130  p->ComputeDimensions(*(G4Orb*)this,n,pRep);
131 }
132 
134 //
135 // Make a clone of the object
136 
137 G4VSolid* G4UOrb::Clone() const
138 {
139  return new G4UOrb(*this);
140 }
141 
143 //
144 // Get bounding box
145 
146 void G4UOrb::Extent(G4ThreeVector& pMin, G4ThreeVector& pMax) const
147 {
148  G4double radius = GetRadius();
149  pMin.set(-radius,-radius,-radius);
150  pMax.set( radius, radius, radius);
151 
152  // Check correctness of the bounding box
153  //
154  if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
155  {
156  std::ostringstream message;
157  message << "Bad bounding box (min >= max) for solid: "
158  << GetName() << " !"
159  << "\npMin = " << pMin
160  << "\npMax = " << pMax;
161  G4Exception("G4UOrb::Extent()", "GeomMgt0001", JustWarning, message);
162  StreamInfo(G4cout);
163  }
164 }
165 
167 //
168 // Calculate extent under transform and specified limit
169 
170 G4bool
171 G4UOrb::CalculateExtent(const EAxis pAxis,
172  const G4VoxelLimits& pVoxelLimit,
173  const G4AffineTransform& pTransform,
174  G4double& pMin, G4double& pMax) const
175 {
176  G4ThreeVector bmin, bmax;
177  G4bool exist;
178 
179  // Get bounding box
180  Extent(bmin,bmax);
181 
182  // Check bounding box
183  G4BoundingEnvelope bbox(bmin,bmax);
184 #ifdef G4BBOX_EXTENT
185  if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
186 #endif
187  if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
188  {
189  return exist = (pMin < pMax) ? true : false;
190  }
191 
192  // Find bounding envelope and calculate extent
193  //
194  static const G4int NTHETA = 8; // number of steps along Theta
195  static const G4int NPHI = 16; // number of steps along Phi
196  static const G4double sinHalfTheta = std::sin(halfpi/NTHETA);
197  static const G4double cosHalfTheta = std::cos(halfpi/NTHETA);
198  static const G4double sinHalfPhi = std::sin(pi/NPHI);
199  static const G4double cosHalfPhi = std::cos(pi/NPHI);
200  static const G4double sinStepTheta = 2.*sinHalfTheta*cosHalfTheta;
201  static const G4double cosStepTheta = 1. - 2.*sinHalfTheta*sinHalfTheta;
202  static const G4double sinStepPhi = 2.*sinHalfPhi*cosHalfPhi;
203  static const G4double cosStepPhi = 1. - 2.*sinHalfPhi*sinHalfPhi;
204 
205  G4double radius = GetRadius();
206  G4double rtheta = radius/cosHalfTheta;
207  G4double rphi = rtheta/cosHalfPhi;
208 
209  // set reference circle
210  G4TwoVector xy[NPHI];
211  G4double sinCurPhi = sinHalfPhi;
212  G4double cosCurPhi = cosHalfPhi;
213  for (G4int k=0; k<NPHI; ++k)
214  {
215  xy[k].set(cosCurPhi,sinCurPhi);
216  G4double sinTmpPhi = sinCurPhi;
217  sinCurPhi = sinCurPhi*cosStepPhi + cosCurPhi*sinStepPhi;
218  cosCurPhi = cosCurPhi*cosStepPhi - sinTmpPhi*sinStepPhi;
219  }
220 
221  // set bounding circles
222  G4ThreeVectorList circles[NTHETA];
223  for (G4int i=0; i<NTHETA; ++i) circles[i].resize(NPHI);
224 
225  G4double sinCurTheta = sinHalfTheta;
226  G4double cosCurTheta = cosHalfTheta;
227  for (G4int i=0; i<NTHETA; ++i)
228  {
229  G4double z = rtheta*cosCurTheta;
230  G4double rho = rphi*sinCurTheta;
231  for (G4int k=0; k<NPHI; ++k)
232  {
233  circles[i][k].set(rho*xy[k].x(),rho*xy[k].y(),z);
234  }
235  G4double sinTmpTheta = sinCurTheta;
236  sinCurTheta = sinCurTheta*cosStepTheta + cosCurTheta*sinStepTheta;
237  cosCurTheta = cosCurTheta*cosStepTheta - sinTmpTheta*sinStepTheta;
238  }
239 
240  // set envelope and calculate extent
241  std::vector<const G4ThreeVectorList *> polygons;
242  polygons.resize(NTHETA);
243  for (G4int i=0; i<NTHETA; ++i) polygons[i] = &circles[i];
244 
245  G4BoundingEnvelope benv(bmin,bmax,polygons);
246  exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
247  return exist;
248 }
249 
251 //
252 // Create polyhedron for visualization
253 
254 G4Polyhedron* G4UOrb::CreatePolyhedron() const
255 {
256  return new G4PolyhedronSphere(0., GetRadius(), 0., twopi, 0., pi);
257 }
258 
259 #endif // G4GEOM_USE_USOLIDS
void set(double x, double y, double z)
double x() const
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
const char * p
Definition: xmltok.h:285
tuple x
Definition: test.py:50
int G4int
Definition: G4Types.hh:78
double z() const
static constexpr double twopi
Definition: G4SIunits.hh:76
G4GLOB_DLL std::ostream G4cout
void set(double x, double y)
bool G4bool
Definition: G4Types.hh:79
const G4int n
std::vector< G4ThreeVector > G4ThreeVectorList
Definition: G4Orb.hh:61
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
EAxis
Definition: geomdefs.hh:54
double y() const
tuple z
Definition: test.py:28
static constexpr double pi
Definition: G4SIunits.hh:75
static constexpr double halfpi
Definition: G4SIunits.hh:77
double G4double
Definition: G4Types.hh:76