Geant4  10.03
G4UTet.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 intellectual property of the *
19 // * Vanderbilt University Free Electron Laser Center *
20 // * Vanderbilt University, Nashville, TN, USA *
21 // * Development supported by: *
22 // * United States MFEL program under grant FA9550-04-1-0045 *
23 // * and NASA under contract number NNG04CT05P *
24 // * Written by Marcus H. Mendenhall and Robert A. Weller. *
25 // * *
26 // * Contributed to the Geant4 Core, January, 2005. *
27 // * *
28 // ********************************************************************
29 //
30 // $Id:$
31 //
32 //
33 // Implementation for G4UTet wrapper class
34 // --------------------------------------------------------------------
35 
36 #include "G4Tet.hh"
37 #include "G4UTet.hh"
38 
39 #if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
40 
41 #include "G4AffineTransform.hh"
42 #include "G4VPVParameterisation.hh"
43 #include "G4BoundingEnvelope.hh"
44 
45 using namespace CLHEP;
46 
48 //
49 // Constructor - create a tetrahedron
50 // This class is implemented separately from general polyhedra,
51 // because the simplex geometry can be computed very quickly,
52 // which may become important in situations imported from mesh generators,
53 // in which a very large number of G4Tets are created.
54 // A Tet has all of its geometrical information precomputed
55 //
56 G4UTet::G4UTet(const G4String& pName,
57  G4ThreeVector anchor,
58  G4ThreeVector p2,
59  G4ThreeVector p3,
60  G4ThreeVector p4, G4bool* degeneracyFlag)
61  : G4USolid(pName, new UTet(pName,
62  UVector3(anchor.x(),anchor.y(),anchor.z()),
63  UVector3(p2.x(), p2.y(), p2.z()),
64  UVector3(p3.x(), p3.y(), p3.z()),
65  UVector3(p4.x(), p4.y(), p4.z()),
66  degeneracyFlag))
67 {
68 }
69 
71 //
72 // Fake default constructor - sets only member data and allocates memory
73 // for usage restricted to object persistency.
74 //
75 G4UTet::G4UTet( __void__& a )
76  : G4USolid(a)
77 {
78 }
79 
81 //
82 // Destructor
83 //
84 G4UTet::~G4UTet()
85 {
86 }
87 
89 //
90 // Copy constructor
91 //
92 G4UTet::G4UTet(const G4UTet& rhs)
93  : G4USolid(rhs)
94 {
95 }
96 
97 
99 //
100 // Assignment operator
101 //
102 G4UTet& G4UTet::operator = (const G4UTet& rhs)
103 {
104  // Check assignment to self
105  //
106  if (this == &rhs) { return *this; }
107 
108  // Copy base class data
109  //
110  G4USolid::operator=(rhs);
111 
112  return *this;
113 }
114 
116 //
117 // Accessors
118 //
119 std::vector<G4ThreeVector> G4UTet::GetVertices() const
120 {
121  std::vector<UVector3> vec = GetShape()->GetVertices();
122  std::vector<G4ThreeVector> vertices;
123  for (unsigned int i=0; i<vec.size(); ++i)
124  {
125  G4ThreeVector v(vec[i].x(), vec[i].y(), vec[i].z());
126  vertices.push_back(v);
127  }
128  return vertices;
129 }
130 
132 //
133 // Get bounding box
134 
135 void G4UTet::Extent(G4ThreeVector& pMin, G4ThreeVector& pMax) const
136 {
137  UVector3 vmin, vmax;
138  GetShape()->Extent(vmin,vmax);
139  pMin.set(vmin.x(),vmin.y(),vmin.z());
140  pMax.set(vmax.x(),vmax.y(),vmax.z());
141 
142  // Check correctness of the bounding box
143  //
144  if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
145  {
146  std::ostringstream message;
147  message << "Bad bounding box (min >= max) for solid: "
148  << GetName() << " !"
149  << "\npMin = " << pMin
150  << "\npMax = " << pMax;
151  G4Exception("G4UTet::Extent()", "GeomMgt0001", JustWarning, message);
152  StreamInfo(G4cout);
153  }
154 }
155 
157 //
158 // Calculate extent under transform and specified limit
159 
160 G4bool
161 G4UTet::CalculateExtent(const EAxis pAxis,
162  const G4VoxelLimits& pVoxelLimit,
163  const G4AffineTransform& pTransform,
164  G4double& pMin, G4double& pMax) const
165 {
166  G4ThreeVector bmin, bmax;
167  G4bool exist;
168 
169  // Check bounding box (bbox)
170  //
171  Extent(bmin,bmax);
172  G4BoundingEnvelope bbox(bmin,bmax);
173 #ifdef G4BBOX_EXTENT
174  if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
175 #endif
176  if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
177  {
178  return exist = (pMin < pMax) ? true : false;
179  }
180 
181  // Set bounding envelope (benv) and calculate extent
182  //
183  std::vector<UVector3> vec = GetShape()->GetVertices();
184 
185  G4ThreeVectorList anchor(1);
186  anchor[0].set(vec[0].x(),vec[0].y(),vec[0].z());
187 
188  G4ThreeVectorList base(3);
189  base[0].set(vec[1].x(),vec[1].y(),vec[1].z());
190  base[1].set(vec[2].x(),vec[2].y(),vec[2].z());
191  base[2].set(vec[3].x(),vec[3].y(),vec[3].z());
192 
193  std::vector<const G4ThreeVectorList *> polygons(2);
194  polygons[0] = &anchor;
195  polygons[1] = &base;
196 
197  G4BoundingEnvelope benv(bmin,bmax,polygons);
198  exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
199  return exist;
200 }
201 
203 //
204 // CreatePolyhedron
205 //
206 G4Polyhedron* G4UTet::CreatePolyhedron() const
207 {
208  G4int index = 0;
209  G4double array[12];
210  GetShape()->GetParametersList(index, array);
211 
212  G4Polyhedron *ph=new G4Polyhedron;
213  G4double xyz[4][3];
214  const G4int faces[4][4]={{1,3,2,0},{1,4,3,0},{1,2,4,0},{2,3,4,0}};
215  xyz[0][0]=array[0]; xyz[0][1]=array[1]; xyz[0][2]=array[2]; // fAnchor
216  xyz[1][0]=array[3]; xyz[1][1]=array[4]; xyz[1][2]=array[5]; // fP2
217  xyz[2][0]=array[6]; xyz[2][1]=array[7]; xyz[2][2]=array[8]; // fP3
218  xyz[3][0]=array[9]; xyz[3][1]=array[10]; xyz[3][2]=array[11]; // fP4
219 
220  ph->createPolyhedron(4,4,xyz,faces);
221 
222  return ph;
223 }
224 
225 #endif // G4GEOM_USE_USOLIDS
CLHEP::Hep3Vector G4ThreeVector
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
std::vector< G4ThreeVector > G4ThreeVectorList
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
EAxis
Definition: geomdefs.hh:54
double G4double
Definition: G4Types.hh:76