Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4UMultiUnion.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 of G4UMultiUnion wrapper class
31 // --------------------------------------------------------------------
32 
33 #include "G4UMultiUnion.hh"
34 
35 #if defined(G4GEOM_USE_USOLIDS)
36 
37 #include "G4VoxelLimits.hh"
38 #include "G4BoundingEnvelope.hh"
39 #include "G4Polyhedron.hh"
40 #include "G4DisplacedSolid.hh"
41 #include "G4RotationMatrix.hh"
42 
44 //
45 // Constructor (generic parameters)
46 //
47 G4UMultiUnion::G4UMultiUnion(const G4String& name)
48  : G4USolid(name, new UMultiUnion(name))
49 {
50 }
51 
52 
54 //
55 // Fake default constructor - sets only member data and allocates memory
56 // for usage restricted to object persistency.
57 //
58 G4UMultiUnion::G4UMultiUnion(__void__& a)
59  : G4USolid(a)
60 {
61 }
62 
63 
65 //
66 // Destructor
67 //
68 G4UMultiUnion::~G4UMultiUnion()
69 {
70 }
71 
72 
74 //
75 // Copy constructor
76 //
77 G4UMultiUnion::G4UMultiUnion(const G4UMultiUnion &source)
78  : G4USolid(source)
79 {
80 }
81 
82 
84 //
85 // Assignment operator
86 //
87 G4UMultiUnion& G4UMultiUnion::operator=(const G4UMultiUnion &source)
88 {
89  if (this == &source) return *this;
90 
91  G4USolid::operator=( source );
92 
93  return *this;
94 }
95 
96 
98 //
99 // Accessors & modifiers
100 //
101 void G4UMultiUnion::AddNode(G4VSolid& solid, G4Transform3D& trans)
102 {
103  HepGeom::Rotate3D rot;
104  HepGeom::Translate3D transl ;
105  HepGeom::Scale3D scale;
106 
107  trans.getDecomposition(scale,rot,transl);
108  G4ThreeVector pos = transl.getTranslation();
109 
110  UTransform3D tr;
111  tr.fRot[0] = rot.xx(); tr.fRot[1] = rot.xy(); tr.fRot[2] = rot.xz();
112  tr.fRot[3] = rot.yx(); tr.fRot[4] = rot.yy(); tr.fRot[5] = rot.yz();
113  tr.fRot[6] = rot.zx(); tr.fRot[7] = rot.zy(); tr.fRot[8] = rot.zz();
114  tr.fTr = UVector3(pos.x(), pos.y(), pos.z());
115 
116  GetShape()->AddNode(*(static_cast<G4USolid&>(solid).GetSolid()), tr);
117 }
118 
119 G4Transform3D* G4UMultiUnion::GetTransformation(G4int index) const
120 {
121  UTransform3D tr = GetShape()->GetTransformation(index);
122 
124  rot(CLHEP::HepRep3x3(tr.fRot[0], tr.fRot[1], tr.fRot[2],
125  tr.fRot[3], tr.fRot[4], tr.fRot[5],
126  tr.fRot[6], tr.fRot[7], tr.fRot[8]));
127  G4ThreeVector transl(tr.fTr.x(), tr.fTr.y(), tr.fTr.z());
128 
129  return new G4Transform3D(rot, transl);
130 }
131 
132 G4VSolid* G4UMultiUnion::GetSolid(G4int index) const
133 {
134  VUSolid* solid = GetShape()->GetSolid(index);
135  return new G4USolid(solid->GetName(), solid);
136 }
137 
138 G4int G4UMultiUnion::GetNumberOfSolids()const
139 {
140  return GetShape()->GetNumberOfSolids();
141 }
142 
143 void G4UMultiUnion::Voxelize()
144 {
145  GetShape()->Voxelize();
146 }
147 
149 //
150 // Get bounding box
151 
152 void G4UMultiUnion::Extent(G4ThreeVector& pMin, G4ThreeVector& pMax) const
153 {
154  UVector3 vmin, vmax;
155  GetShape()->Extent(vmin,vmax);
156  pMin.set(vmin.x(),vmin.y(),vmin.z());
157  pMax.set(vmax.x(),vmax.y(),vmax.z());
158 
159  // Check correctness of the bounding box
160  //
161  if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
162  {
163  std::ostringstream message;
164  message << "Bad bounding box (min >= max) for solid: "
165  << GetName() << " !"
166  << "\npMin = " << pMin
167  << "\npMax = " << pMax;
168  G4Exception("G4UMultiUnion::Extent()", "GeomMgt0001", JustWarning, message);
169  DumpInfo();
170  }
171 }
172 
174 //
175 // Calculate extent under transform and specified limit
176 
177 G4bool
178 G4UMultiUnion::CalculateExtent(const EAxis pAxis,
179  const G4VoxelLimits& pVoxelLimit,
180  const G4AffineTransform& pTransform,
181  G4double& pMin, G4double& pMax) const
182 {
183  G4ThreeVector bmin, bmax;
184 
185  // Get bounding box
186  Extent(bmin,bmax);
187 
188  // Find extent
189  G4BoundingEnvelope bbox(bmin,bmax);
190  return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
191 }
192 
194 //
195 // CreatePolyhedron
196 //
197 G4Polyhedron* G4UMultiUnion::CreatePolyhedron() const
198 {
199 
202 
203  G4VSolid* solidA = GetSolid(0);
204  const G4Transform3D* transform0=GetTransformation(0);
205  G4RotationMatrix rot0=(*transform0).getRotation();
206  const G4ThreeVector transl0 = (*transform0).getTranslation();
207  G4DisplacedSolid dispSolidA("placedA",solidA,&rot0,transl0);
208  delete transform0;
209 
210  G4Polyhedron* top = new G4Polyhedron(*dispSolidA.GetPolyhedron());
211 
212  for(G4int i=1; i<GetNumberOfSolids(); ++i)
213  {
214  G4VSolid* solidB = GetSolid(i);
215  const G4Transform3D* transform=GetTransformation(i);
216  G4RotationMatrix rot=(*transform).getRotation();
217  const G4ThreeVector transl = (*transform).getTranslation();
218  G4DisplacedSolid dispSolidB("placedB",solidB,&rot,transl);
219  G4Polyhedron* operand = dispSolidB.GetPolyhedron();
220  processor.push_back (operation, *operand);
221  delete transform;
222  }
223 
224  if (processor.execute(*top)) { return top; }
225  else { return 0; }
226 }
227 
228 #endif // G4GEOM_USE_USOLIDS
void set(double x, double y, double z)
double yy() const
Definition: Transform3D.h:264
const XML_Char * name
Definition: expat.h:151
double x() const
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
double yx() const
Definition: Transform3D.h:261
void getDecomposition(Scale3D &scale, Rotate3D &rotation, Translate3D &translation) const
Definition: Transform3D.cc:174
double zz() const
Definition: Transform3D.h:276
int G4int
Definition: G4Types.hh:78
double z() const
double xz() const
Definition: Transform3D.h:258
static int operand(pchar begin, pchar end, double &result, pchar &endp, const dic_type &dictionary)
Definition: Evaluator.cc:164
void push_back(Operation, const HepPolyhedron &)
CLHEP::HepRotation getRotation() const
bool G4bool
Definition: G4Types.hh:79
HepGeom::Transform3D G4Transform3D
double xy() const
Definition: Transform3D.h:255
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define processor
Definition: xmlparse.cc:617
double yz() const
Definition: Transform3D.h:267
EAxis
Definition: geomdefs.hh:54
double y() const
double xx() const
Definition: Transform3D.h:252
double G4double
Definition: G4Types.hh:76
CLHEP::Hep3Vector getTranslation() const
double zy() const
Definition: Transform3D.h:273
virtual void Extent(G4ThreeVector &pMin, G4ThreeVector &pMax) const
Definition: G4VSolid.cc:626
bool execute(HepPolyhedron &)
static const G4double pos
double zx() const
Definition: Transform3D.h:270