Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4USolid.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 //
27 // $Id:$
28 // GEANT4 tag $Name:$
29 //
30 //
31 // G4USolid implementation
32 //
33 // --------------------------------------------------------------------
34 
35 #include "G4USolid.hh"
36 
37 #if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
38 
39 #include "G4AffineTransform.hh"
40 #include "G4VoxelLimits.hh"
41 #include "G4VGraphicsScene.hh"
42 #include "G4Polyhedron.hh"
43 #include "G4VisExtent.hh"
44 #include "G4PhysicalConstants.hh"
45 #include "G4GeometryTolerance.hh"
46 #include "G4BoundingEnvelope.hh"
47 
48 #include "G4AutoLock.hh"
49 
50 namespace
51 {
52  G4Mutex polyhedronMutex = G4MUTEX_INITIALIZER;
53 }
54 
55 G4USolid::G4USolid(const G4String& name, VUSolid* s) :
56  G4VSolid(name), fShape(s), fRebuildPolyhedron(false), fPolyhedron(0)
57 {
58 }
59 
60 G4USolid::G4USolid(__void__& a)
61  : G4VSolid(a), fShape(0), fRebuildPolyhedron(false), fPolyhedron(0)
62 {
63 }
64 
65 G4USolid::~G4USolid()
66 {
67  delete fPolyhedron; fPolyhedron = 0;
68 }
69 
70 G4bool G4USolid::operator==(const G4USolid& s) const
71 {
72  return (this == &s) ? true : false;
73 }
74 
75 EInside G4USolid::Inside(const G4ThreeVector& p) const
76 {
77  UVector3 pt;
78  VUSolid::EnumInside in_temp;
79  EInside in = kOutside;
80  pt.x() = p.x();
81  pt.y() = p.y();
82  pt.z() = p.z(); // better assign at construction
83 
84  in_temp = fShape->Inside(pt);
85 
86  if (in_temp == VUSolid::EnumInside::eSurface) return kSurface;
87  if (in_temp == VUSolid::EnumInside::eInside) return kInside;
88 
89  return in;
90 }
91 
92 G4ThreeVector G4USolid::SurfaceNormal(const G4ThreeVector& pt) const
93 {
94  UVector3 p;
95  p.x() = pt.x();
96  p.y() = pt.y();
97  p.z() = pt.z();
98  UVector3 n;
99  fShape->Normal(p, n);
100  return G4ThreeVector(n.x(), n.y(), n.z());
101 }
102 
103 G4double G4USolid::DistanceToIn(const G4ThreeVector& pt,
104  const G4ThreeVector& d) const
105 {
106  UVector3 p;
107  p.x() = pt.x();
108  p.y() = pt.y();
109  p.z() = pt.z(); // better assign at construction
110  UVector3 v;
111  v.x() = d.x();
112  v.y() = d.y();
113  v.z() = d.z(); // better assign at construction
114  G4double dist = fShape->DistanceToIn(p, v);
115  if (dist > kInfinity) return kInfinity;
116 // return (dist > halfTolerance) ? dist : 0.0;
117  return dist;
118 }
119 
120 G4double G4USolid::DistanceToIn(const G4ThreeVector& pt) const
121 {
122  UVector3 p;
123  p.x() = pt.x();
124  p.y() = pt.y();
125  p.z() = pt.z(); // better assign at construction
126  G4double dist = fShape->SafetyFromOutside(p); // true?
127  if (dist > kInfinity) return kInfinity;
128 // return (dist > halfTolerance) ? dist : 0.0;
129  return dist;
130 }
131 
132 G4double G4USolid::DistanceToOut(const G4ThreeVector& pt,
133  const G4ThreeVector& d,
134  const G4bool calcNorm,
135  G4bool* validNorm,
136  G4ThreeVector* norm) const
137 {
138  UVector3 p;
139  p.x() = pt.x();
140  p.y() = pt.y();
141  p.z() = pt.z(); // better assign at construction
142  UVector3 v;
143  v.x() = d.x();
144  v.y() = d.y();
145  v.z() = d.z(); // better assign at construction
146  UVector3 n;
147  G4bool valid;
148  G4double dist = fShape->DistanceToOut(p, v, n, valid); // should use local variable
149  if(calcNorm)
150  {
151  if(valid){ *validNorm = true; }
152  else { *validNorm = false; }
153  if(*validNorm) // *norm = n, but only after calcNorm check
154  {
155  norm->setX(n.x());
156  norm->setY(n.y());
157  norm->setZ(n.z());
158  }
159  }
160  if (dist > kInfinity) return kInfinity;
161 // return (dist > halfTolerance) ? dist : 0.0;
162  return dist;
163 }
164 
165 G4double G4USolid::DistanceToOut(const G4ThreeVector& pt) const
166 {
167  UVector3 p;
168  p.x() = pt.x();
169  p.y() = pt.y();
170  p.z() = pt.z(); // better assign at construction
171  G4double dist = fShape->SafetyFromInside(p); // true?
172 // return (dist > halfTolerance) ? dist : 0.0;
173  return dist;
174 }
175 
176 G4double G4USolid::GetCubicVolume()
177 {
178  return fShape->Capacity();
179 }
180 
181 G4double G4USolid::GetSurfaceArea()
182 {
183  return fShape->SurfaceArea();
184 }
185 
186 G4ThreeVector G4USolid::GetPointOnSurface() const
187 {
188  UVector3 p;
189  p = fShape->GetPointOnSurface();
190  return G4ThreeVector(p.x(), p.y(), p.z());
191 }
192 
193 G4bool G4USolid::CalculateExtent(const EAxis pAxis,
194  const G4VoxelLimits& pVoxelLimit,
195  const G4AffineTransform& pTransform,
196  G4double& pMin, G4double& pMax) const
197 {
198  UVector3 vmin, vmax;
199  fShape->Extent(vmin,vmax);
200  G4ThreeVector bmin(vmin.x(),vmin.y(),vmin.z());
201  G4ThreeVector bmax(vmax.x(),vmax.y(),vmax.z());
202 
203  // Check correctness of the bounding box
204  //
205  if (bmin.x() >= bmax.x() || bmin.y() >= bmax.y() || bmin.z() >= bmax.z())
206  {
207  std::ostringstream message;
208  message << "Bad bounding box (min >= max) for solid: "
209  << GetName() << " - " << GetEntityType() << " !"
210  << "\nmin = " << bmin
211  << "\nmax = " << bmax;
212  G4Exception("G4USolid::CalculateExtent()", "GeomMgt0001",
213  JustWarning, message);
214  StreamInfo(G4cout);
215  }
216 
217  G4BoundingEnvelope bbox(bmin,bmax);
218  return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
219 }
220 
221 void G4USolid::ComputeDimensions(G4VPVParameterisation*,
222  const G4int,
223  const G4VPhysicalVolume*)
224 {
225  std::ostringstream message;
226  message << "Illegal call to G4USolid::ComputeDimensions()" << G4endl
227  << "Method not overloaded by derived class !";
228  G4Exception("G4USolid::ComputeDimensions()", "GeomSolids0003",
229  FatalException, message);
230 }
231 
232 void G4USolid::DescribeYourselfTo(G4VGraphicsScene& scene) const
233 {
234  scene.AddSolid(*this);
235 }
236 
237 G4GeometryType G4USolid::GetEntityType() const
238 {
239 
240  G4String string = fShape->GetEntityType();
241  return "G4" + string;
242 }
243 
244 std::ostream& G4USolid::StreamInfo(std::ostream& os) const
245 {
246  return fShape->StreamInfo(os);
247 }
248 
249 G4USolid::G4USolid(const G4USolid& rhs)
250  : G4VSolid(rhs), fRebuildPolyhedron(false), fPolyhedron(0)
251 {
252  fShape = rhs.fShape->Clone();
253 }
254 
255 G4USolid& G4USolid::operator=(const G4USolid& rhs)
256 {
257  // Check assignment to self
258  //
259  if (this == &rhs)
260  {
261  return *this;
262  }
263 
264  // Copy base class data
265  //
266  G4VSolid::operator=(rhs);
267 
268  // Copy data
269  //
270  fShape = rhs.fShape->Clone();
271  fRebuildPolyhedron = false;
272  delete fPolyhedron; fPolyhedron = 0;
273 
274  return *this;
275 }
276 
277 G4VSolid* G4USolid::Clone() const
278 {
279  std::ostringstream message;
280  message << "Clone() method not implemented for type: "
281  << GetEntityType() << "!" << G4endl
282  << "Returning NULL pointer!";
283  G4Exception("G4USolid::Clone()", "GeomSolids1001", JustWarning, message);
284  return 0;
285 }
286 
287 G4Polyhedron* G4USolid::CreatePolyhedron() const
288 {
289  // Must be implemented in concrete wrappers...
290 
291  std::ostringstream message;
292  message << "Visualization not supported for USolid shape "
293  << GetEntityType() << "... Sorry!" << G4endl;
294  G4Exception("G4USolid::CreatePolyhedron()", "GeomSolids0003",
295  FatalException, message);
296  return 0;
297 }
298 
299 G4Polyhedron* G4USolid::GetPolyhedron() const
300 {
301  if (!fPolyhedron ||
302  fRebuildPolyhedron ||
303  fPolyhedron->GetNumberOfRotationStepsAtTimeOfCreation() !=
304  fPolyhedron->GetNumberOfRotationSteps())
305  {
306  G4AutoLock l(&polyhedronMutex);
307  delete fPolyhedron;
308  fPolyhedron = CreatePolyhedron();
309  fRebuildPolyhedron = false;
310  l.unlock();
311  }
312  return fPolyhedron;
313 }
314 
315 G4VisExtent G4USolid::GetExtent() const
316 {
317  UVector3 vmin, vmax;
318  fShape->Extent(vmin,vmax);
319  return G4VisExtent(vmin.x(),vmax.x(),
320  vmin.y(),vmax.y(),
321  vmin.z(),vmax.z());
322 }
323 
324 #endif // G4GEOM_USE_USOLIDS
const XML_Char * name
Definition: expat.h:151
bool operator==(const HepRotation &r, const HepLorentzRotation &lt)
static const G4double kInfinity
Definition: geomdefs.hh:42
CLHEP::Hep3Vector G4ThreeVector
double x() const
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
const char * p
Definition: xmltok.h:285
virtual void AddSolid(const G4Box &)=0
int G4int
Definition: G4Types.hh:78
void setY(double)
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:175
double z() const
void setZ(double)
void setX(double)
const XML_Char * s
Definition: expat.h:262
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
const G4int n
tuple v
Definition: test.py:18
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4int G4Mutex
Definition: G4Threading.hh:173
EInside
Definition: geomdefs.hh:58
EAxis
Definition: geomdefs.hh:54
double y() const
#define G4endl
Definition: G4ios.hh:61
G4VSolid & operator=(const G4VSolid &rhs)
Definition: G4VSolid.cc:111
virtual G4VSolid * Clone() const
Definition: G4VSolid.cc:325
double G4double
Definition: G4Types.hh:76