Geant4  10.02.p02
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 "G4Polyhedron.hh"
38 #include "G4DisplacedSolid.hh"
39 #include "G4RotationMatrix.hh"
40 
42 //
43 // Constructor (generic parameters)
44 //
45 G4UMultiUnion::G4UMultiUnion(const G4String& name)
46  : G4USolid(name, new UMultiUnion(name))
47 {
48 }
49 
50 
52 //
53 // Fake default constructor - sets only member data and allocates memory
54 // for usage restricted to object persistency.
55 //
56 G4UMultiUnion::G4UMultiUnion(__void__& a)
57  : G4USolid(a)
58 {
59 }
60 
61 
63 //
64 // Destructor
65 //
66 G4UMultiUnion::~G4UMultiUnion()
67 {
68 }
69 
70 
72 //
73 // Copy constructor
74 //
75 G4UMultiUnion::G4UMultiUnion(const G4UMultiUnion &source)
76  : G4USolid(source)
77 {
78 }
79 
80 
82 //
83 // Assignment operator
84 //
85 G4UMultiUnion& G4UMultiUnion::operator=(const G4UMultiUnion &source)
86 {
87  if (this == &source) return *this;
88 
89  G4USolid::operator=( source );
90 
91  return *this;
92 }
93 
94 
96 //
97 // Accessors & modifiers
98 //
99 void G4UMultiUnion::AddNode(G4VSolid& solid, G4Transform3D& trans)
100 {
101  HepGeom::Rotate3D rot;
102  HepGeom::Translate3D transl ;
103  HepGeom::Scale3D scale;
104 
105  trans.getDecomposition(scale,rot,transl);
106  G4ThreeVector pos = transl.getTranslation();
107 
108  UTransform3D tr;
109  tr.fRot[0] = rot.xx(); tr.fRot[1] = rot.xy(); tr.fRot[2] = rot.xz();
110  tr.fRot[3] = rot.yx(); tr.fRot[4] = rot.yy(); tr.fRot[5] = rot.yz();
111  tr.fRot[6] = rot.zx(); tr.fRot[7] = rot.zy(); tr.fRot[8] = rot.zz();
112  tr.fTr = UVector3(pos.x(), pos.y(), pos.z());
113 
114  GetShape()->AddNode(*(static_cast<G4USolid&>(solid).GetSolid()), tr);
115 }
116 
117 G4Transform3D* G4UMultiUnion::GetTransformation(G4int index) const
118 {
119  UTransform3D tr = GetShape()->GetTransformation(index);
120 
122  rot(CLHEP::HepRep3x3(tr.fRot[0], tr.fRot[1], tr.fRot[2],
123  tr.fRot[3], tr.fRot[4], tr.fRot[5],
124  tr.fRot[6], tr.fRot[7], tr.fRot[8]));
125  G4ThreeVector transl(tr.fTr.x(), tr.fTr.y(), tr.fTr.z());
126 
127  return new G4Transform3D(rot, transl);
128 }
129 
130 G4VSolid* G4UMultiUnion::GetSolid(G4int index) const
131 {
132  VUSolid* solid = GetShape()->GetSolid(index);
133  return new G4USolid(solid->GetName(), solid);
134 }
135 
136 G4int G4UMultiUnion::GetNumberOfSolids()const
137 {
138  return GetShape()->GetNumberOfSolids();
139 }
140 
141 void G4UMultiUnion::Voxelize()
142 {
143  GetShape()->Voxelize();
144 }
145 
146 
148 //
149 // CreatePolyhedron
150 //
151 G4Polyhedron* G4UMultiUnion::CreatePolyhedron() const
152 {
153 
154  HepPolyhedronProcessor processor;
155  HepPolyhedronProcessor::Operation operation = HepPolyhedronProcessor::UNION;
156 
157  G4VSolid* solidA = GetSolid(0);
158  const G4Transform3D* transform0=GetTransformation(0);
159  G4RotationMatrix rot0=(*transform0).getRotation();
160  const G4ThreeVector transl0 = (*transform0).getTranslation();
161  G4DisplacedSolid dispSolidA("placedA",solidA,&rot0,transl0);
162  delete transform0;
163 
164  G4Polyhedron* top = new G4Polyhedron(*dispSolidA.GetPolyhedron());
165 
166  for(G4int i=1; i<GetNumberOfSolids(); ++i)
167  {
168  G4VSolid* solidB = GetSolid(i);
169  const G4Transform3D* transform=GetTransformation(i);
170  G4RotationMatrix rot=(*transform).getRotation();
171  const G4ThreeVector transl = (*transform).getTranslation();
172  G4DisplacedSolid dispSolidB("placedB",solidB,&rot,transl);
173  G4Polyhedron* operand = dispSolidB.GetPolyhedron();
174  processor.push_back (operation, *operand);
175  delete transform;
176  }
177 
178  if (processor.execute(*top)) { return top; }
179  else { return 0; }
180 }
181 
182 #endif // G4GEOM_USE_USOLIDS
CLHEP::Hep3Vector G4ThreeVector
CLHEP::HepRotation G4RotationMatrix
G4String name
Definition: TRTMaterials.hh:40
G4double a
Definition: TRTMaterials.hh:39
int G4int
Definition: G4Types.hh:78
static int operand(pchar begin, pchar end, double &result, pchar &endp, const dic_type &dictionary)
Definition: Evaluator.cc:162
HepGeom::Transform3D G4Transform3D
#define processor
Definition: xmlparse.cc:617
static const G4double pos