ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4UBox.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4UBox.cc
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 // Implementation for G4UBox wrapper class
27 //
28 // 13.09.13 G.Cosmo, CERN/PH
29 // --------------------------------------------------------------------
30 
31 #include "G4Box.hh"
32 #include "G4UBox.hh"
33 
34 #if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
35 
36 #include "G4AffineTransform.hh"
37 #include "G4VPVParameterisation.hh"
38 #include "G4BoundingEnvelope.hh"
39 
40 using namespace CLHEP;
41 
43 //
44 // Constructor - check & set half widths
45 
46 
47 G4UBox::G4UBox(const G4String& pName,
48  G4double pX,
49  G4double pY,
50  G4double pZ)
51  : Base_t(pName, pX, pY, pZ)
52 {
53 }
54 
56 //
57 // Fake default constructor - sets only member data and allocates memory
58 // for usage restricted to object persistency.
59 
60 G4UBox::G4UBox( __void__& a )
61  : Base_t(a)
62 {
63 }
64 
66 //
67 // Destructor
68 
69 G4UBox::~G4UBox()
70 {
71 }
72 
74 //
75 // Copy constructor
76 
77 G4UBox::G4UBox(const G4UBox& rhs)
78  : Base_t(rhs)
79 {
80 }
81 
83 //
84 // Assignment operator
85 
86 G4UBox& G4UBox::operator = (const G4UBox& rhs)
87 {
88  // Check assignment to self
89  //
90  if (this == &rhs) { return *this; }
91 
92  // Copy base class data
93  //
94  Base_t::operator=(rhs);
95 
96  return *this;
97 }
98 
100 //
101 // Accessors & modifiers
102 
103 G4double G4UBox::GetXHalfLength() const
104 {
105  return x();
106 }
107 G4double G4UBox::GetYHalfLength() const
108 {
109  return y();
110 }
111 G4double G4UBox::GetZHalfLength() const
112 {
113  return z();
114 }
115 
116 void G4UBox::SetXHalfLength(G4double dx)
117 {
118  SetX(dx);
119  fRebuildPolyhedron = true;
120 }
121 void G4UBox::SetYHalfLength(G4double dy)
122 {
123  SetY(dy);
124  fRebuildPolyhedron = true;
125 }
126 void G4UBox::SetZHalfLength(G4double dz)
127 {
128  SetZ(dz);
129  fRebuildPolyhedron = true;
130 }
131 
133 //
134 // Dispatch to parameterisation for replication mechanism dimension
135 // computation & modification.
136 
137 void G4UBox::ComputeDimensions(G4VPVParameterisation* p,
138  const G4int n,
139  const G4VPhysicalVolume* pRep)
140 {
141  p->ComputeDimensions(*(G4Box*)this,n,pRep);
142 }
143 
145 //
146 // Make a clone of the object
147 
148 G4VSolid* G4UBox::Clone() const
149 {
150  return new G4UBox(*this);
151 }
152 
154 //
155 // Get bounding box
156 
157 void G4UBox::BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const
158 {
159  G4double dx = GetXHalfLength();
160  G4double dy = GetYHalfLength();
161  G4double dz = GetZHalfLength();
162  pMin.set(-dx,-dy,-dz);
163  pMax.set( dx, dy, dz);
164 
165  // Check correctness of the bounding box
166  //
167  if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
168  {
169  std::ostringstream message;
170  message << "Bad bounding box (min >= max) for solid: "
171  << GetName() << " !"
172  << "\npMin = " << pMin
173  << "\npMax = " << pMax;
174  G4Exception("G4UBox::BoundingLimits()", "GeomMgt0001",
175  JustWarning, message);
176  StreamInfo(G4cout);
177  }
178 }
179 
181 //
182 // Calculate extent under transform and specified limit
183 
184 G4bool
185 G4UBox::CalculateExtent(const EAxis pAxis,
186  const G4VoxelLimits& pVoxelLimit,
187  const G4AffineTransform& pTransform,
188  G4double& pMin, G4double& pMax) const
189 {
190  G4ThreeVector bmin, bmax;
191 
192  // Get bounding box limits
193  BoundingLimits(bmin,bmax);
194 
195  // Find extent
196  G4BoundingEnvelope bbox(bmin,bmax);
197  return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
198 }
199 
200 
202 //
203 // Create polyhedron for visualization
204 
205 G4Polyhedron* G4UBox::CreatePolyhedron() const
206 {
207  return new G4PolyhedronBox(GetXHalfLength(),
208  GetYHalfLength(),
209  GetZHalfLength());
210 }
211 
212 #endif // G4GEOM_USE_USOLIDS