Geant4  10.02.p02
G4UExtrudedSolid.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 G4UExtrudedSolid wrapper class
31 // --------------------------------------------------------------------
32 
33 #include "G4ExtrudedSolid.hh"
34 #include "G4UExtrudedSolid.hh"
35 
36 #if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
37 
38 #include "G4PolyhedronArbitrary.hh"
39 
41 //
42 // Constructors
43 //
44 G4UExtrudedSolid::G4UExtrudedSolid(const G4String& name,
45  std::vector<G4TwoVector> polygon,
46  std::vector<ZSection> zsections)
47  : G4USolid(name, new UExtrudedSolid())
48 {
49  GetShape()->SetName(name);
50  std::vector<UVector2> pvec;
51  for (unsigned int i=0; i<polygon.size(); ++i)
52  {
53  pvec.push_back(UVector2(polygon[i].x(), polygon[i].y()));
54  }
55  std::vector<UExtrudedSolid::ZSection> svec;
56  for (unsigned int i=0; i<zsections.size(); ++i)
57  {
58  ZSection sec = zsections[i];
59  svec.push_back(UExtrudedSolid::ZSection(sec.fZ,
60  UVector2(sec.fOffset.x(), sec.fOffset.y()), sec.fScale));
61  }
62  GetShape()->Initialise(pvec, svec);
63 }
64 
65 
66 G4UExtrudedSolid::G4UExtrudedSolid(const G4String& name,
67  std::vector<G4TwoVector> polygon,
68  G4double halfZ,
69  G4TwoVector off1, G4double scale1,
70  G4TwoVector off2, G4double scale2)
71  : G4USolid(name, new UExtrudedSolid())
72 {
73  GetShape()->SetName(name);
74  std::vector<UVector2> pvec;
75  for (unsigned int i=0; i<polygon.size(); ++i)
76  {
77  pvec.push_back(UVector2(polygon[i].x(), polygon[i].y()));
78  }
79  GetShape()->Initialise(pvec, halfZ, UVector2(off1.x(), off1.y()), scale1,
80  UVector2(off2.x(), off2.y()), scale2);
81 }
82 
84 //
85 // Fake default constructor - sets only member data and allocates memory
86 // for usage restricted to object persistency.
87 //
88 G4UExtrudedSolid::G4UExtrudedSolid(__void__& a)
89  : G4USolid(a)
90 {
91 }
92 
93 
95 //
96 // Destructor
97 //
98 G4UExtrudedSolid::~G4UExtrudedSolid()
99 {
100 }
101 
102 
104 //
105 // Copy constructor
106 //
107 G4UExtrudedSolid::G4UExtrudedSolid(const G4UExtrudedSolid &source)
108  : G4USolid(source)
109 {
110 }
111 
112 
114 //
115 // Assignment operator
116 //
117 G4UExtrudedSolid&
118 G4UExtrudedSolid::operator=(const G4UExtrudedSolid &source)
119 {
120  if (this == &source) return *this;
121 
122  G4USolid::operator=( source );
123 
124  return *this;
125 }
126 
127 
129 //
130 // Accessors
131 
132 G4int G4UExtrudedSolid::GetNofVertices() const
133 {
134  return GetShape()->GetNofVertices();
135 }
136 G4TwoVector G4UExtrudedSolid::GetVertex(G4int i) const
137 {
138  UVector2 v = GetShape()->GetVertex(i);
139  return G4TwoVector(v.x, v.y);
140 }
141 std::vector<G4TwoVector> G4UExtrudedSolid::GetPolygon() const
142 {
143  std::vector<UVector2> pol = GetShape()->GetPolygon();
144  std::vector<G4TwoVector> v;
145  for (unsigned int i=0; i<pol.size(); ++i)
146  {
147  v.push_back(G4TwoVector(pol[i].x, pol[i].y));
148  }
149  return v;
150 }
151 G4int G4UExtrudedSolid::GetNofZSections() const
152 {
153  return GetShape()->GetNofZSections();
154 }
155 G4UExtrudedSolid::ZSection G4UExtrudedSolid::GetZSection(G4int i) const
156 {
157  return ZSection(GetShape()->GetZSection(i));
158 }
159 std::vector<G4UExtrudedSolid::ZSection> G4UExtrudedSolid::GetZSections() const
160 {
161  std::vector<UExtrudedSolid::ZSection> sv = GetShape()->GetZSections();
162  std::vector<G4UExtrudedSolid::ZSection> vec;
163  for (unsigned int i=0; i<sv.size(); ++i)
164  {
165  vec.push_back(ZSection(sv[i]));
166  }
167  return vec;
168 }
169 
170 
172 //
173 // CreatePolyhedron()
174 //
175 G4Polyhedron* G4UExtrudedSolid::CreatePolyhedron () const
176 {
177  G4int nFacets = GetShape()->GetNumberOfFacets();
178  G4int nVertices = 0;
179  for (G4int l = 0; l<nFacets; ++l) // compute total number of vertices first
180  {
181  VUFacet* facet = GetShape()->GetFacet(l);
182  G4int n = facet->GetNumberOfVertices();
183  nVertices += n;
184  }
185 
186  G4PolyhedronArbitrary *polyhedron =
187  new G4PolyhedronArbitrary (nVertices,nFacets);
188 
189  for (G4int i = 0; i<nFacets; ++i)
190  {
191  VUFacet* facet = GetShape()->GetFacet(i);
192  G4int v[4];
193  G4int n = facet->GetNumberOfVertices();
194  for (G4int m = 0; m<n; ++m)
195  {
196  UVector3 vtx = facet->GetVertex(m);
197  polyhedron->AddVertex(G4ThreeVector(vtx.x(), vtx.y(), vtx.z()));
198  }
199  if (n > 4) n = 4;
200  else if (n == 3) v[3] = 0;
201  for (G4int j=0; j<n; ++j)
202  {
203  G4int k = facet->GetVertexIndex(j);
204  v[j] = k+1;
205  }
206  polyhedron->AddFacet(v[0],v[1],v[2],v[3]);
207  }
208  polyhedron->SetReferences();
209 
210  return (G4Polyhedron*) polyhedron;
211 }
212 
213 #endif // G4GEOM_USE_USOLIDS
CLHEP::Hep3Vector G4ThreeVector
G4String name
Definition: TRTMaterials.hh:40
G4double a
Definition: TRTMaterials.hh:39
int G4int
Definition: G4Types.hh:78
const G4int n
void AddVertex(const G4ThreeVector &v)
const G4double x[NPOINTSGL]
void AddFacet(const G4int iv1, const G4int iv2, const G4int iv3, const G4int iv4=0)
CLHEP::Hep2Vector G4TwoVector
Definition: G4TwoVector.hh:42
static const double m
Definition: G4SIunits.hh:128
double G4double
Definition: G4Types.hh:76