Geant4  10.03
G4UBox.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 //
29 //
30 // Implementation for G4UBox wrapper class
31 // --------------------------------------------------------------------
32 
33 #include "G4Box.hh"
34 #include "G4UBox.hh"
35 
36 #if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
37 
38 #include "G4AffineTransform.hh"
39 #include "G4VPVParameterisation.hh"
40 #include "G4BoundingEnvelope.hh"
41 
42 using namespace CLHEP;
43 
45 //
46 // Constructor - check & set half widths
47 
48 
49 G4UBox::G4UBox(const G4String& pName,
50  G4double pX,
51  G4double pY,
52  G4double pZ)
53  : G4USolid(pName, new UBox(pName, pX, pY, pZ))
54 {
55 }
56 
58 //
59 // Fake default constructor - sets only member data and allocates memory
60 // for usage restricted to object persistency.
61 
62 G4UBox::G4UBox( __void__& a )
63  : G4USolid(a)
64 {
65 }
66 
68 //
69 // Destructor
70 
71 G4UBox::~G4UBox()
72 {
73 }
74 
76 //
77 // Copy constructor
78 
79 G4UBox::G4UBox(const G4UBox& rhs)
80  : G4USolid(rhs)
81 {
82 }
83 
85 //
86 // Assignment operator
87 
88 G4UBox& G4UBox::operator = (const G4UBox& 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 G4UBox::GetXHalfLength() const
106 {
107  return GetShape()->GetXHalfLength();
108 }
109 G4double G4UBox::GetYHalfLength() const
110 {
111  return GetShape()->GetYHalfLength();
112 }
113 G4double G4UBox::GetZHalfLength() const
114 {
115  return GetShape()->GetZHalfLength();
116 }
117 
118 void G4UBox::SetXHalfLength(G4double dx)
119 {
120  GetShape()->SetXHalfLength(dx);
121  fRebuildPolyhedron = true;
122 }
123 void G4UBox::SetYHalfLength(G4double dy)
124 {
125  GetShape()->SetYHalfLength(dy);
126  fRebuildPolyhedron = true;
127 }
128 void G4UBox::SetZHalfLength(G4double dz)
129 {
130  GetShape()->SetZHalfLength(dz);
131  fRebuildPolyhedron = true;
132 }
133 
135 //
136 // Dispatch to parameterisation for replication mechanism dimension
137 // computation & modification.
138 
139 void G4UBox::ComputeDimensions(G4VPVParameterisation* p,
140  const G4int n,
141  const G4VPhysicalVolume* pRep)
142 {
143  p->ComputeDimensions(*(G4Box*)this,n,pRep);
144 }
145 
147 //
148 // Make a clone of the object
149 
150 G4VSolid* G4UBox::Clone() const
151 {
152  return new G4UBox(*this);
153 }
154 
156 //
157 // Get bounding box
158 
159 void G4UBox::Extent(G4ThreeVector& pMin, G4ThreeVector& pMax) const
160 {
161  G4double dx = GetXHalfLength();
162  G4double dy = GetYHalfLength();
163  G4double dz = GetZHalfLength();
164  pMin.set(-dx,-dy,-dz);
165  pMax.set( dx, dy, dz);
166 
167  // Check correctness of the bounding box
168  //
169  if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
170  {
171  std::ostringstream message;
172  message << "Bad bounding box (min >= max) for solid: "
173  << GetName() << " !"
174  << "\npMin = " << pMin
175  << "\npMax = " << pMax;
176  G4Exception("G4UBox::Extent()", "GeomMgt0001", JustWarning, message);
177  StreamInfo(G4cout);
178  }
179 }
180 
182 //
183 // Calculate extent under transform and specified limit
184 
185 G4bool
186 G4UBox::CalculateExtent(const EAxis pAxis,
187  const G4VoxelLimits& pVoxelLimit,
188  const G4AffineTransform& pTransform,
189  G4double& pMin, G4double& pMax) const
190 {
191  G4ThreeVector bmin, bmax;
192 
193  // Get bounding box
194  Extent(bmin,bmax);
195 
196  // Find extent
197  G4BoundingEnvelope bbox(bmin,bmax);
198  return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
199 }
200 
201 
203 //
204 // Create polyhedron for visualization
205 
206 G4Polyhedron* G4UBox::CreatePolyhedron() const
207 {
208  return new G4PolyhedronBox(GetXHalfLength(),
209  GetYHalfLength(),
210  GetZHalfLength());
211 }
212 
213 #endif // G4GEOM_USE_USOLIDS
CLHEP::Hep3Vector G4ThreeVector
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
Definition: G4Box.hh:64
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
const G4int n
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 G4double
Definition: G4Types.hh:76