Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Attributes
G4GenericTrap Class Reference

#include <G4GenericTrap.hh>

Inheritance diagram for G4GenericTrap:
G4VSolid

Public Member Functions

 G4GenericTrap (const G4String &name, G4double halfZ, const std::vector< G4TwoVector > &vertices)
 
 ~G4GenericTrap ()
 
G4double GetZHalfLength () const
 
G4int GetNofVertices () const
 
G4TwoVector GetVertex (G4int index) const
 
const std::vector< G4TwoVector > & GetVertices () const
 
G4double GetTwistAngle (G4int index) const
 
G4bool IsTwisted () const
 
G4int GetVisSubdivisions () const
 
void SetVisSubdivisions (G4int subdiv)
 
EInside Inside (const G4ThreeVector &p) const
 
G4ThreeVector SurfaceNormal (const G4ThreeVector &p) const
 
G4double DistanceToIn (const G4ThreeVector &p, const G4ThreeVector &v) const
 
G4double DistanceToIn (const G4ThreeVector &p) const
 
G4double DistanceToOut (const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const
 
G4double DistanceToOut (const G4ThreeVector &p) const
 
G4bool CalculateExtent (const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pmin, G4double &pmax) const
 
G4GeometryType GetEntityType () const
 
G4VSolidClone () const
 
std::ostream & StreamInfo (std::ostream &os) const
 
G4ThreeVector GetPointOnSurface () const
 
G4double GetCubicVolume ()
 
G4double GetSurfaceArea ()
 
G4PolyhedronGetPolyhedron () const
 
void DescribeYourselfTo (G4VGraphicsScene &scene) const
 
G4VisExtent GetExtent () const
 
G4PolyhedronCreatePolyhedron () const
 
 G4GenericTrap (__void__ &)
 
 G4GenericTrap (const G4GenericTrap &rhs)
 
G4GenericTrapoperator= (const G4GenericTrap &rhs)
 
- Public Member Functions inherited from G4VSolid
 G4VSolid (const G4String &name)
 
virtual ~G4VSolid ()
 
G4bool operator== (const G4VSolid &s) const
 
G4String GetName () const
 
void SetName (const G4String &name)
 
G4double GetTolerance () const
 
virtual void ComputeDimensions (G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
 
void DumpInfo () const
 
virtual const G4VSolidGetConstituentSolid (G4int no) const
 
virtual G4VSolidGetConstituentSolid (G4int no)
 
virtual const G4DisplacedSolidGetDisplacedSolidPtr () const
 
virtual G4DisplacedSolidGetDisplacedSolidPtr ()
 
 G4VSolid (__void__ &)
 
 G4VSolid (const G4VSolid &rhs)
 
G4VSolidoperator= (const G4VSolid &rhs)
 

Protected Attributes

G4PolyhedronfpPolyhedron
 
- Protected Attributes inherited from G4VSolid
G4double kCarTolerance
 

Additional Inherited Members

- Protected Member Functions inherited from G4VSolid
void CalculateClippedPolygonExtent (G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
 
void ClipCrossSection (G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
 
void ClipBetweenSections (G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
 
void ClipPolygon (G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis) const
 
G4double EstimateCubicVolume (G4int nStat, G4double epsilon) const
 
G4double EstimateSurfaceArea (G4int nStat, G4double ell) const
 

Detailed Description

Definition at line 79 of file G4GenericTrap.hh.

Constructor & Destructor Documentation

G4GenericTrap::G4GenericTrap ( const G4String name,
G4double  halfZ,
const std::vector< G4TwoVector > &  vertices 
)

Definition at line 66 of file G4GenericTrap.cc.

References FatalErrorInArgument, G4endl, G4Exception(), JustWarning, and G4VSolid::kCarTolerance.

Referenced by Clone().

68  : G4VSolid(name),
69  fpPolyhedron(0),
70  fDz(halfZ),
71  fVertices(),
72  fIsTwisted(false),
73  fTessellatedSolid(0),
74  fMinBBoxVector(G4ThreeVector(0,0,0)),
75  fMaxBBoxVector(G4ThreeVector(0,0,0)),
76  fVisSubdivisions(0),
77  fSurfaceArea(0.),
78  fCubicVolume(0.)
79 
80 {
81  // General constructor
82  const G4double min_length=5*1.e-6;
83  G4double length = 0.;
84  G4int k=0;
85  G4String errorDescription = "InvalidSetup in \" ";
86  errorDescription += name;
87  errorDescription += "\"";
88 
89  halfCarTolerance = kCarTolerance*0.5;
90 
91  // Check vertices size
92 
93  if ( G4int(vertices.size()) != fgkNofVertices )
94  {
95  G4Exception("G4GenericTrap::G4GenericTrap()", "GeomSolids0002",
96  FatalErrorInArgument, "Number of vertices != 8");
97  }
98 
99  // Check dZ
100  //
101  if (halfZ < kCarTolerance)
102  {
103  G4Exception("G4GenericTrap::G4GenericTrap()", "GeomSolids0002",
104  FatalErrorInArgument, "dZ is too small or negative");
105  }
106 
107  // Check Ordering and Copy vertices
108  //
109  if(CheckOrder(vertices))
110  {
111  for (G4int i=0; i<fgkNofVertices; ++i) {fVertices.push_back(vertices[i]);}
112  }
113  else
114  {
115  for (G4int i=0; i <4; ++i) {fVertices.push_back(vertices[3-i]);}
116  for (G4int i=0; i <4; ++i) {fVertices.push_back(vertices[7-i]);}
117  }
118 
119  // Check length of segments and Adjust
120  //
121  for (G4int j=0; j < 2; j++)
122  {
123  for (G4int i=1; i<4; ++i)
124  {
125  k = j*4+i;
126  length = (fVertices[k]-fVertices[k-1]).mag();
127  if ( ( length < min_length) && ( length > kCarTolerance ) )
128  {
129  std::ostringstream message;
130  message << "Length segment is too small." << G4endl
131  << "Distance between " << fVertices[k-1] << " and "
132  << fVertices[k] << " is only " << length << " mm !";
133  G4Exception("G4GenericTrap::G4GenericTrap()", "GeomSolids1001",
134  JustWarning, message, "Vertices will be collapsed.");
135  fVertices[k]=fVertices[k-1];
136  }
137  }
138  }
139 
140  // Compute Twist
141  //
142  for( G4int i=0; i<4; i++) { fTwist[i]=0.; }
143  fIsTwisted = ComputeIsTwisted();
144 
145  // Compute Bounding Box
146  //
147  ComputeBBox();
148 
149  // If not twisted - create tessellated solid
150  // (an alternative implementation for testing)
151  //
152 #ifdef G4TESS_TEST
153  if ( !fIsTwisted ) { fTessellatedSolid = CreateTessellatedSolid(); }
154 #endif
155 }
CLHEP::Hep3Vector G4ThreeVector
G4Polyhedron * fpPolyhedron
const XML_Char * name
int G4int
Definition: G4Types.hh:78
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define G4endl
Definition: G4ios.hh:61
G4VSolid(const G4String &name)
Definition: G4VSolid.cc:60
G4double kCarTolerance
Definition: G4VSolid.hh:305
double G4double
Definition: G4Types.hh:76
G4GenericTrap::~G4GenericTrap ( )

Definition at line 181 of file G4GenericTrap.cc.

182 {
183  // Destructor
184  delete fTessellatedSolid;
185 }
G4GenericTrap::G4GenericTrap ( __void__ &  a)

Definition at line 159 of file G4GenericTrap.cc.

160  : G4VSolid(a),
161  fpPolyhedron(0),
162  halfCarTolerance(0.),
163  fDz(0.),
164  fVertices(),
165  fIsTwisted(false),
166  fTessellatedSolid(0),
167  fMinBBoxVector(G4ThreeVector(0,0,0)),
168  fMaxBBoxVector(G4ThreeVector(0,0,0)),
169  fVisSubdivisions(0),
170  fSurfaceArea(0.),
171  fCubicVolume(0.)
172 {
173  // Fake default constructor - sets only member data and allocates memory
174  // for usage restricted to object persistency.
175 
176  for (size_t i=0; i<4; ++i) { fTwist[i]=0.; }
177 }
CLHEP::Hep3Vector G4ThreeVector
G4Polyhedron * fpPolyhedron
G4VSolid(const G4String &name)
Definition: G4VSolid.cc:60
G4GenericTrap::G4GenericTrap ( const G4GenericTrap rhs)

Definition at line 189 of file G4GenericTrap.cc.

190  : G4VSolid(rhs),
191  fpPolyhedron(0), halfCarTolerance(rhs.halfCarTolerance),
192  fDz(rhs.fDz), fVertices(rhs.fVertices),
193  fIsTwisted(rhs.fIsTwisted), fTessellatedSolid(0),
194  fMinBBoxVector(rhs.fMinBBoxVector), fMaxBBoxVector(rhs.fMaxBBoxVector),
195  fVisSubdivisions(rhs.fVisSubdivisions),
196  fSurfaceArea(rhs.fSurfaceArea), fCubicVolume(rhs.fCubicVolume)
197 {
198  for (size_t i=0; i<4; ++i) { fTwist[i] = rhs.fTwist[i]; }
199 #ifdef G4TESS_TEST
200  if (rhs.fTessellatedSolid && !fIsTwisted )
201  { fTessellatedSolid = CreateTessellatedSolid(); }
202 #endif
203 }
G4Polyhedron * fpPolyhedron
G4VSolid(const G4String &name)
Definition: G4VSolid.cc:60

Member Function Documentation

G4bool G4GenericTrap::CalculateExtent ( const EAxis  pAxis,
const G4VoxelLimits pVoxelLimit,
const G4AffineTransform pTransform,
G4double pmin,
G4double pmax 
) const
virtual

Implements G4VSolid.

Definition at line 1193 of file G4GenericTrap.cc.

References G4TessellatedSolid::CalculateExtent(), G4VSolid::ClipBetweenSections(), G4VSolid::ClipCrossSection(), G4VoxelLimits::GetMaxExtent(), G4VoxelLimits::GetMaxXExtent(), G4VoxelLimits::GetMaxYExtent(), G4VoxelLimits::GetMaxZExtent(), G4VoxelLimits::GetMinExtent(), G4VoxelLimits::GetMinXExtent(), G4VoxelLimits::GetMinYExtent(), G4VoxelLimits::GetMinZExtent(), Inside(), G4AffineTransform::Inverse(), G4AffineTransform::IsRotated(), G4VoxelLimits::IsXLimited(), G4VoxelLimits::IsYLimited(), G4VoxelLimits::IsZLimited(), G4VSolid::kCarTolerance, kOutside, kXAxis, kYAxis, kZAxis, G4AffineTransform::NetTranslation(), G4AffineTransform::TransformPoint(), CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

1197 {
1198 #ifdef G4TESS_TEST
1199  if ( fTessellatedSolid )
1200  {
1201  return fTessellatedSolid->CalculateExtent(pAxis, pVoxelLimit,
1202  pTransform, pMin, pMax);
1203  }
1204 #endif
1205 
1206  // Computes bounding vectors for a shape
1207  //
1208  G4double Dx,Dy;
1209  G4ThreeVector minVec = GetMinimumBBox();
1210  G4ThreeVector maxVec = GetMaximumBBox();
1211  Dx = 0.5*(maxVec.x()- minVec.x());
1212  Dy = 0.5*(maxVec.y()- minVec.y());
1213 
1214  if (!pTransform.IsRotated())
1215  {
1216  // Special case handling for unrotated shapes
1217  // Compute x/y/z mins and maxs respecting limits, with early returns
1218  // if outside limits. Then switch() on pAxis
1219  //
1220  G4double xoffset,xMin,xMax;
1221  G4double yoffset,yMin,yMax;
1222  G4double zoffset,zMin,zMax;
1223 
1224  xoffset=pTransform.NetTranslation().x();
1225  xMin=xoffset-Dx;
1226  xMax=xoffset+Dx;
1227  if (pVoxelLimit.IsXLimited())
1228  {
1229  if ( (xMin>pVoxelLimit.GetMaxXExtent()+kCarTolerance)
1230  || (xMax<pVoxelLimit.GetMinXExtent()-kCarTolerance) )
1231  {
1232  return false;
1233  }
1234  else
1235  {
1236  if (xMin<pVoxelLimit.GetMinXExtent())
1237  {
1238  xMin=pVoxelLimit.GetMinXExtent();
1239  }
1240  if (xMax>pVoxelLimit.GetMaxXExtent())
1241  {
1242  xMax=pVoxelLimit.GetMaxXExtent();
1243  }
1244  }
1245  }
1246 
1247  yoffset=pTransform.NetTranslation().y();
1248  yMin=yoffset-Dy;
1249  yMax=yoffset+Dy;
1250  if (pVoxelLimit.IsYLimited())
1251  {
1252  if ( (yMin>pVoxelLimit.GetMaxYExtent()+kCarTolerance)
1253  || (yMax<pVoxelLimit.GetMinYExtent()-kCarTolerance) )
1254  {
1255  return false;
1256  }
1257  else
1258  {
1259  if (yMin<pVoxelLimit.GetMinYExtent())
1260  {
1261  yMin=pVoxelLimit.GetMinYExtent();
1262  }
1263  if (yMax>pVoxelLimit.GetMaxYExtent())
1264  {
1265  yMax=pVoxelLimit.GetMaxYExtent();
1266  }
1267  }
1268  }
1269 
1270  zoffset=pTransform.NetTranslation().z();
1271  zMin=zoffset-fDz;
1272  zMax=zoffset+fDz;
1273  if (pVoxelLimit.IsZLimited())
1274  {
1275  if ( (zMin>pVoxelLimit.GetMaxZExtent()+kCarTolerance)
1276  || (zMax<pVoxelLimit.GetMinZExtent()-kCarTolerance) )
1277  {
1278  return false;
1279  }
1280  else
1281  {
1282  if (zMin<pVoxelLimit.GetMinZExtent())
1283  {
1284  zMin=pVoxelLimit.GetMinZExtent();
1285  }
1286  if (zMax>pVoxelLimit.GetMaxZExtent())
1287  {
1288  zMax=pVoxelLimit.GetMaxZExtent();
1289  }
1290  }
1291  }
1292 
1293  switch (pAxis)
1294  {
1295  case kXAxis:
1296  pMin = xMin;
1297  pMax = xMax;
1298  break;
1299  case kYAxis:
1300  pMin = yMin;
1301  pMax = yMax;
1302  break;
1303  case kZAxis:
1304  pMin = zMin;
1305  pMax = zMax;
1306  break;
1307  default:
1308  break;
1309  }
1310  pMin-=kCarTolerance;
1311  pMax+=kCarTolerance;
1312 
1313  return true;
1314  }
1315  else
1316  {
1317  // General rotated case - create and clip mesh to boundaries
1318 
1319  G4bool existsAfterClip=false;
1320  G4ThreeVectorList *vertices;
1321 
1322  pMin=+kInfinity;
1323  pMax=-kInfinity;
1324 
1325  // Calculate rotated vertex coordinates
1326  //
1327  vertices=CreateRotatedVertices(pTransform);
1328  ClipCrossSection(vertices,0,pVoxelLimit,pAxis,pMin,pMax);
1329  ClipCrossSection(vertices,4,pVoxelLimit,pAxis,pMin,pMax);
1330  ClipBetweenSections(vertices,0,pVoxelLimit,pAxis,pMin,pMax);
1331 
1332  if ( (pMin!=kInfinity) || (pMax!=-kInfinity) )
1333  {
1334  existsAfterClip=true;
1335 
1336  // Add 2*tolerance to avoid precision troubles
1337  //
1338  pMin-=kCarTolerance;
1339  pMax+=kCarTolerance;
1340  }
1341  else
1342  {
1343  // Check for case where completely enveloping clipping volume.
1344  // If point inside then we are confident that the solid completely
1345  // envelopes the clipping volume. Hence set min/max extents according
1346  // to clipping volume extents along the specified axis.
1347  //
1348  G4ThreeVector clipCentre(
1349  (pVoxelLimit.GetMinXExtent()+pVoxelLimit.GetMaxXExtent())*0.5,
1350  (pVoxelLimit.GetMinYExtent()+pVoxelLimit.GetMaxYExtent())*0.5,
1351  (pVoxelLimit.GetMinZExtent()+pVoxelLimit.GetMaxZExtent())*0.5);
1352 
1353  if (Inside(pTransform.Inverse().TransformPoint(clipCentre))!=kOutside)
1354  {
1355  existsAfterClip=true;
1356  pMin=pVoxelLimit.GetMinExtent(pAxis);
1357  pMax=pVoxelLimit.GetMaxExtent(pAxis);
1358  }
1359  }
1360  delete vertices;
1361  return existsAfterClip;
1362  }
1363 }
void ClipCrossSection(G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
Definition: G4VSolid.cc:347
G4double GetMinYExtent() const
double x() const
G4AffineTransform Inverse() const
G4bool IsYLimited() const
G4bool IsRotated() const
G4ThreeVector NetTranslation() const
G4bool IsXLimited() const
double z() const
G4double GetMaxXExtent() const
G4double GetMinZExtent() const
bool G4bool
Definition: G4Types.hh:79
std::vector< G4ThreeVector > G4ThreeVectorList
Definition: G4VSolid.hh:79
EInside Inside(const G4ThreeVector &p) const
G4double GetMinXExtent() const
G4ThreeVector TransformPoint(const G4ThreeVector &vec) const
G4double GetMaxZExtent() const
double y() const
G4double GetMaxYExtent() const
G4double kCarTolerance
Definition: G4VSolid.hh:305
double G4double
Definition: G4Types.hh:76
G4double GetMaxExtent(const EAxis pAxis) const
virtual G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
G4bool IsZLimited() const
void ClipBetweenSections(G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
Definition: G4VSolid.cc:378
G4double GetMinExtent(const EAxis pAxis) const
G4VSolid * G4GenericTrap::Clone ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 1420 of file G4GenericTrap.cc.

References G4GenericTrap().

1421 {
1422  return new G4GenericTrap(*this);
1423 }
G4GenericTrap(const G4String &name, G4double halfZ, const std::vector< G4TwoVector > &vertices)
G4Polyhedron * G4GenericTrap::CreatePolyhedron ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 2147 of file G4GenericTrap.cc.

References G4PolyhedronArbitrary::AddFacet(), G4PolyhedronArbitrary::AddVertex(), G4TessellatedSolid::CreatePolyhedron(), GetTwistAngle(), GetVisSubdivisions(), G4PolyhedronArbitrary::InvertFacets(), G4PolyhedronArbitrary::SetReferences(), test::x, CLHEP::Hep2Vector::x(), CLHEP::Hep3Vector::x(), CLHEP::Hep2Vector::y(), and CLHEP::Hep3Vector::y().

Referenced by GetPolyhedron().

2148 {
2149 
2150 #ifdef G4TESS_TEST
2151  if ( fTessellatedSolid )
2152  {
2153  return fTessellatedSolid->CreatePolyhedron();
2154  }
2155 #endif
2156 
2157  // Approximation of Twisted Side
2158  // Construct extra Points, if Twisted Side
2159  //
2160  G4PolyhedronArbitrary* polyhedron;
2161  size_t nVertices, nFacets;
2162 
2163  G4int subdivisions=0;
2164  G4int i;
2165  if(fIsTwisted)
2166  {
2167  if ( GetVisSubdivisions()!= 0 )
2168  {
2169  subdivisions=GetVisSubdivisions();
2170  }
2171  else
2172  {
2173  // Estimation of Number of Subdivisions for smooth visualisation
2174  //
2175  G4double maxTwist=0.;
2176  for(i=0; i<4; i++)
2177  {
2178  if(GetTwistAngle(i)>maxTwist) { maxTwist=GetTwistAngle(i); }
2179  }
2180 
2181  // Computes bounding vectors for the shape
2182  //
2183  G4double Dx,Dy;
2184  G4ThreeVector minVec = GetMinimumBBox();
2185  G4ThreeVector maxVec = GetMaximumBBox();
2186  Dx = 0.5*(maxVec.x()- minVec.y());
2187  Dy = 0.5*(maxVec.y()- minVec.y());
2188  if (Dy > Dx) { Dx=Dy; }
2189 
2190  subdivisions=8*G4int(maxTwist/(Dx*Dx*Dx)*fDz);
2191  if (subdivisions<4) { subdivisions=4; }
2192  if (subdivisions>30) { subdivisions=30; }
2193  }
2194  }
2195  G4int sub4=4*subdivisions;
2196  nVertices = 8+subdivisions*4;
2197  nFacets = 6+subdivisions*4;
2198  G4double cf=1./(subdivisions+1);
2199  polyhedron = new G4PolyhedronArbitrary (nVertices, nFacets);
2200 
2201  // Add Vertex
2202  //
2203  for (i=0;i<4;i++)
2204  {
2205  polyhedron->AddVertex(G4ThreeVector(fVertices[i].x(),
2206  fVertices[i].y(),-fDz));
2207  }
2208  for( i=0;i<subdivisions;i++)
2209  {
2210  for(G4int j=0;j<4;j++)
2211  {
2212  G4TwoVector u=fVertices[j]+cf*(i+1)*( fVertices[j+4]-fVertices[j]);
2213  polyhedron->AddVertex(G4ThreeVector(u.x(),u.y(),-fDz+cf*2*fDz*(i+1)));
2214  }
2215  }
2216  for (i=4;i<8;i++)
2217  {
2218  polyhedron->AddVertex(G4ThreeVector(fVertices[i].x(),
2219  fVertices[i].y(),fDz));
2220  }
2221 
2222  // Add Facets
2223  //
2224  polyhedron->AddFacet(1,4,3,2); //Z-plane
2225  for (i=0;i<subdivisions+1;i++)
2226  {
2227  G4int is=i*4;
2228  polyhedron->AddFacet(5+is,8+is,4+is,1+is);
2229  polyhedron->AddFacet(8+is,7+is,3+is,4+is);
2230  polyhedron->AddFacet(7+is,6+is,2+is,3+is);
2231  polyhedron->AddFacet(6+is,5+is,1+is,2+is);
2232  }
2233  polyhedron->AddFacet(5+sub4,6+sub4,7+sub4,8+sub4); //Z-plane
2234 
2235  polyhedron->SetReferences();
2236  polyhedron->InvertFacets();
2237 
2238  return (G4Polyhedron*) polyhedron;
2239 }
double y() const
G4int GetVisSubdivisions() const
double x() const
CLHEP::Hep3Vector G4ThreeVector
double x() const
int G4int
Definition: G4Types.hh:78
virtual G4Polyhedron * CreatePolyhedron() const
G4double GetTwistAngle(G4int index) const
void AddVertex(const G4ThreeVector &v)
double y() const
void AddFacet(const G4int iv1, const G4int iv2, const G4int iv3, const G4int iv4=0)
double G4double
Definition: G4Types.hh:76
void G4GenericTrap::DescribeYourselfTo ( G4VGraphicsScene scene) const
virtual

Implements G4VSolid.

Definition at line 2110 of file G4GenericTrap.cc.

References G4VGraphicsScene::AddSolid(), and G4TessellatedSolid::DescribeYourselfTo().

2111 {
2112 
2113 #ifdef G4TESS_TEST
2114  if ( fTessellatedSolid )
2115  {
2116  return fTessellatedSolid->DescribeYourselfTo(scene);
2117  }
2118 #endif
2119 
2120  scene.AddSolid(*this);
2121 }
virtual void DescribeYourselfTo(G4VGraphicsScene &scene) const
virtual void AddSolid(const G4Box &)=0
G4double G4GenericTrap::DistanceToIn ( const G4ThreeVector p,
const G4ThreeVector v 
) const
virtual

Implements G4VSolid.

Definition at line 749 of file G4GenericTrap.cc.

References G4TessellatedSolid::DistanceToIn(), CLHEP::Hep3Vector::dot(), Inside(), kOutside, n, test::v, and CLHEP::Hep3Vector::z().

751 {
752 #ifdef G4TESS_TEST
753  if ( fTessellatedSolid )
754  {
755  return fTessellatedSolid->DistanceToIn(p, v);
756  }
757 #endif
758 
759  G4double dist[5];
761 
762  // Check lateral faces
763  //
764  G4int i;
765  for (i=0; i<4; i++)
766  {
767  dist[i]=DistToPlane(p, v, i);
768  }
769 
770  // Check Z planes
771  //
772  dist[4]=kInfinity;
773  if (std::fabs(p.z())>fDz-halfCarTolerance)
774  {
775  if (v.z())
776  {
777  G4ThreeVector pt;
778  if (p.z()>0)
779  {
780  dist[4] = (fDz-p.z())/v.z();
781  }
782  else
783  {
784  dist[4] = (-fDz-p.z())/v.z();
785  }
786  if (dist[4]<-halfCarTolerance)
787  {
788  dist[4]=kInfinity;
789  }
790  else
791  {
792  if(dist[4]<halfCarTolerance)
793  {
794  if(p.z()>0) { n=G4ThreeVector(0,0,1); }
795  else { n=G4ThreeVector(0,0,-1); }
796  if (n.dot(v)<0) { dist[4]=0.; }
797  else { dist[4]=kInfinity; }
798  }
799  pt=p+dist[4]*v;
800  if (Inside(pt)==kOutside) { dist[4]=kInfinity; }
801  }
802  }
803  }
804  G4double distmin = dist[0];
805  for (i=1;i<5;i++)
806  {
807  if (dist[i] < distmin) { distmin = dist[i]; }
808  }
809 
810  if (distmin<halfCarTolerance) { distmin=0.; }
811 
812  return distmin;
813 }
CLHEP::Hep3Vector G4ThreeVector
double dot(const Hep3Vector &) const
int G4int
Definition: G4Types.hh:78
double z() const
const G4int n
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
EInside Inside(const G4ThreeVector &p) const
double G4double
Definition: G4Types.hh:76
G4double G4GenericTrap::DistanceToIn ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Definition at line 817 of file G4GenericTrap.cc.

References G4TessellatedSolid::DistanceToIn(), and CLHEP::Hep3Vector::z().

818 {
819  // Computes the closest distance from given point to this shape
820 
821 #ifdef G4TESS_TEST
822  if ( fTessellatedSolid )
823  {
824  return fTessellatedSolid->DistanceToIn(p);
825  }
826 #endif
827 
828  G4double safz = std::fabs(p.z())-fDz;
829  if(safz<0) { safz=0; }
830 
831  G4int iseg;
832  G4double safe = safz;
833  G4double safxy = safz;
834 
835  for (iseg=0; iseg<4; iseg++)
836  {
837  safxy = SafetyToFace(p,iseg);
838  if (safxy>safe) { safe=safxy; }
839  }
840 
841  return safe;
842 }
int G4int
Definition: G4Types.hh:78
double z() const
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
double G4double
Definition: G4Types.hh:76
G4double G4GenericTrap::DistanceToOut ( const G4ThreeVector p,
const G4ThreeVector v,
const G4bool  calcNorm = false,
G4bool validNorm = 0,
G4ThreeVector n = 0 
) const
virtual

Implements G4VSolid.

Definition at line 921 of file G4GenericTrap.cc.

References test::b, test::c, G4TessellatedSolid::DistanceToOut(), CLHEP::Hep3Vector::dot(), G4VSolid::DumpInfo(), G4endl, G4Exception(), JustWarning, G4VSolid::kCarTolerance, kOutside, python.hepunit::mm, test::v, CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

926 {
927 #ifdef G4TESS_TEST
928  if ( fTessellatedSolid )
929  {
930  return fTessellatedSolid->DistanceToOut(p, v, calcNorm, validNorm, n);
931  }
932 #endif
933 
934  G4double distmin;
935  G4bool lateral_cross = false;
936  ESide side = kUndefined;
937 
938  if (calcNorm) { *validNorm=true; } // All normals are valid
939 
940  if (v.z() < 0)
941  {
942  distmin=(-fDz-p.z())/v.z();
943  if (calcNorm) { side=kMZ; *n=G4ThreeVector(0,0,-1); }
944  }
945  else
946  {
947  if (v.z() > 0)
948  {
949  distmin = (fDz-p.z())/v.z();
950  if (calcNorm) { side=kPZ; *n=G4ThreeVector(0,0,1); }
951  }
952  else { distmin = kInfinity; }
953  }
954 
955  G4double dz2 =0.5/fDz;
956  G4double xa,xb,xc,xd;
957  G4double ya,yb,yc,yd;
958 
959  for (G4int ipl=0; ipl<4; ipl++)
960  {
961  G4int j = (ipl+1)%4;
962  xa=fVertices[ipl].x();
963  ya=fVertices[ipl].y();
964  xb=fVertices[ipl+4].x();
965  yb=fVertices[ipl+4].y();
966  xc=fVertices[j].x();
967  yc=fVertices[j].y();
968  xd=fVertices[4+j].x();
969  yd=fVertices[4+j].y();
970 
971  if ( ((std::fabs(xb-xd)+std::fabs(yb-yd))<halfCarTolerance)
972  || ((std::fabs(xa-xc)+std::fabs(ya-yc))<halfCarTolerance) )
973  {
974  G4double q=DistToTriangle(p,v,ipl) ;
975  if ( (q>=0) && (q<distmin) )
976  {
977  distmin=q;
978  lateral_cross=true;
979  side=ESide(ipl+1);
980  }
981  continue;
982  }
983  G4double tx1 =dz2*(xb-xa);
984  G4double ty1 =dz2*(yb-ya);
985  G4double tx2 =dz2*(xd-xc);
986  G4double ty2 =dz2*(yd-yc);
987  G4double dzp =fDz+p.z();
988  G4double xs1 =xa+tx1*dzp;
989  G4double ys1 =ya+ty1*dzp;
990  G4double xs2 =xc+tx2*dzp;
991  G4double ys2 =yc+ty2*dzp;
992  G4double dxs =xs2-xs1;
993  G4double dys =ys2-ys1;
994  G4double dtx =tx2-tx1;
995  G4double dty =ty2-ty1;
996  G4double a = (dtx*v.y()-dty*v.x()+(tx1*ty2-tx2*ty1)*v.z())*v.z();
997  G4double b = dxs*v.y()-dys*v.x()+(dtx*p.y()-dty*p.x()+ty2*xs1-ty1*xs2
998  + tx1*ys2-tx2*ys1)*v.z();
999  G4double c=dxs*p.y()-dys*p.x()+xs1*ys2-xs2*ys1;
1000  G4double q=kInfinity;
1001 
1002  if (std::fabs(a) < kCarTolerance)
1003  {
1004  if (std::fabs(b) < kCarTolerance) { continue; }
1005  q=-c/b;
1006 
1007  // Check for Point on the Surface
1008  //
1009  if ((q > -halfCarTolerance) && (q < distmin))
1010  {
1011  if (q < halfCarTolerance)
1012  {
1013  if (NormalToPlane(p,ipl).dot(v)<0.) { continue; }
1014  }
1015  distmin =q;
1016  lateral_cross=true;
1017  side=ESide(ipl+1);
1018  }
1019  continue;
1020  }
1021  G4double d=b*b-4*a*c;
1022  if (d >= 0.)
1023  {
1024  if (a > 0) { q=0.5*(-b-std::sqrt(d))/a; }
1025  else { q=0.5*(-b+std::sqrt(d))/a; }
1026 
1027  // Check for Point on the Surface
1028  //
1029  if (q > -halfCarTolerance )
1030  {
1031  if (q < distmin)
1032  {
1033  if(q < halfCarTolerance)
1034  {
1035  if (NormalToPlane(p,ipl).dot(v)<0.) // Check second root
1036  {
1037  if (a > 0) { q=0.5*(-b+std::sqrt(d))/a; }
1038  else { q=0.5*(-b-std::sqrt(d))/a; }
1039  if (( q > halfCarTolerance) && (q < distmin))
1040  {
1041  distmin=q;
1042  lateral_cross = true;
1043  side=ESide(ipl+1);
1044  }
1045  continue;
1046  }
1047  }
1048  distmin = q;
1049  lateral_cross = true;
1050  side=ESide(ipl+1);
1051  }
1052  }
1053  else
1054  {
1055  if (a > 0) { q=0.5*(-b+std::sqrt(d))/a; }
1056  else { q=0.5*(-b-std::sqrt(d))/a; }
1057 
1058  // Check for Point on the Surface
1059  //
1060  if ((q > -halfCarTolerance) && (q < distmin))
1061  {
1062  if (q < halfCarTolerance)
1063  {
1064  if (NormalToPlane(p,ipl).dot(v)<0.) // Check second root
1065  {
1066  if (a > 0) { q=0.5*(-b-std::sqrt(d))/a; }
1067  else { q=0.5*(-b+std::sqrt(d))/a; }
1068  if ( ( q > halfCarTolerance) && (q < distmin) )
1069  {
1070  distmin=q;
1071  lateral_cross = true;
1072  side=ESide(ipl+1);
1073  }
1074  continue;
1075  }
1076  }
1077  distmin =q;
1078  lateral_cross = true;
1079  side=ESide(ipl+1);
1080  }
1081  }
1082  }
1083  }
1084  if (!lateral_cross) // Make sure that track crosses the top or bottom
1085  {
1086  if (distmin >= kInfinity) { distmin=kCarTolerance; }
1087  G4ThreeVector pt=p+distmin*v;
1088 
1089  // Check if propagated point is in the polygon
1090  //
1091  G4int i=0;
1092  if (v.z()>0.) { i=4; }
1093  std::vector<G4TwoVector> xy;
1094  for ( G4int j=0; j<4; j++) { xy.push_back(fVertices[i+j]); }
1095 
1096  // Check Inside
1097  //
1098  if (InsidePolygone(pt,xy)==kOutside)
1099  {
1100  if(calcNorm)
1101  {
1102  if (v.z()>0) {side= kPZ; *n = G4ThreeVector(0,0,1);}
1103  else { side=kMZ; *n = G4ThreeVector(0,0,-1);}
1104  }
1105  return 0.;
1106  }
1107  else
1108  {
1109  if(v.z()>0) {side=kPZ;}
1110  else {side=kMZ;}
1111  }
1112  }
1113 
1114  if (calcNorm)
1115  {
1116  G4ThreeVector pt=p+v*distmin;
1117  switch (side)
1118  {
1119  case kXY0:
1120  *n=NormalToPlane(pt,0);
1121  break;
1122  case kXY1:
1123  *n=NormalToPlane(pt,1);
1124  break;
1125  case kXY2:
1126  *n=NormalToPlane(pt,2);
1127  break;
1128  case kXY3:
1129  *n=NormalToPlane(pt,3);
1130  break;
1131  case kPZ:
1132  *n=G4ThreeVector(0,0,1);
1133  break;
1134  case kMZ:
1135  *n=G4ThreeVector(0,0,-1);
1136  break;
1137  default:
1138  DumpInfo();
1139  std::ostringstream message;
1140  G4int oldprc = message.precision(16);
1141  message << "Undefined side for valid surface normal to solid." << G4endl
1142  << "Position:" << G4endl
1143  << " p.x() = " << p.x()/mm << " mm" << G4endl
1144  << " p.y() = " << p.y()/mm << " mm" << G4endl
1145  << " p.z() = " << p.z()/mm << " mm" << G4endl
1146  << "Direction:" << G4endl
1147  << " v.x() = " << v.x() << G4endl
1148  << " v.y() = " << v.y() << G4endl
1149  << " v.z() = " << v.z() << G4endl
1150  << "Proposed distance :" << G4endl
1151  << " distmin = " << distmin/mm << " mm";
1152  message.precision(oldprc);
1153  G4Exception("G4GenericTrap::DistanceToOut(p,v,..)",
1154  "GeomSolids1002", JustWarning, message);
1155  break;
1156  }
1157  }
1158 
1159  if (distmin<halfCarTolerance) { distmin=0.; }
1160 
1161  return distmin;
1162 }
Definition: G4Cons.cc:68
CLHEP::Hep3Vector G4ThreeVector
double x() const
double dot(const Hep3Vector &) const
int G4int
Definition: G4Types.hh:78
double z() const
void DumpInfo() const
virtual G4double DistanceToOut(const G4ThreeVector &p) const
bool G4bool
Definition: G4Types.hh:79
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double y() const
Definition: G4Cons.cc:68
#define G4endl
Definition: G4ios.hh:61
G4double kCarTolerance
Definition: G4VSolid.hh:305
ESide
Definition: G4Cons.cc:68
double G4double
Definition: G4Types.hh:76
G4double G4GenericTrap::DistanceToOut ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Definition at line 1166 of file G4GenericTrap.cc.

References G4TessellatedSolid::DistanceToOut(), and CLHEP::Hep3Vector::z().

1167 {
1168 
1169 #ifdef G4TESS_TEST
1170  if ( fTessellatedSolid )
1171  {
1172  return fTessellatedSolid->DistanceToOut(p);
1173  }
1174 #endif
1175 
1176  G4double safz = fDz-std::fabs(p.z());
1177  if (safz<0) { safz = 0; }
1178 
1179  G4double safe = safz;
1180  G4double safxy = safz;
1181 
1182  for (G4int iseg=0; iseg<4; iseg++)
1183  {
1184  safxy = std::fabs(SafetyToFace(p,iseg));
1185  if (safxy < safe) { safe = safxy; }
1186  }
1187 
1188  return safe;
1189 }
int G4int
Definition: G4Types.hh:78
double z() const
virtual G4double DistanceToOut(const G4ThreeVector &p) const
double G4double
Definition: G4Types.hh:76
G4double G4GenericTrap::GetCubicVolume ( )
virtual

Reimplemented from G4VSolid.

Definition at line 1538 of file G4GenericTrap.cc.

References G4VSolid::GetCubicVolume().

1539 {
1540  if(fCubicVolume != 0.) {;}
1541  else { fCubicVolume = G4VSolid::GetCubicVolume(); }
1542  return fCubicVolume;
1543 }
virtual G4double GetCubicVolume()
Definition: G4VSolid.cc:188
G4GeometryType G4GenericTrap::GetEntityType ( ) const
virtual

Implements G4VSolid.

Definition at line 1413 of file G4GenericTrap.cc.

Referenced by StreamInfo().

1414 {
1415  return G4String("G4GenericTrap");
1416 }
G4VisExtent G4GenericTrap::GetExtent ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 2125 of file G4GenericTrap.cc.

References G4TessellatedSolid::GetExtent(), CLHEP::Hep3Vector::x(), and CLHEP::Hep3Vector::y().

2126 {
2127  // Computes bounding vectors for the shape
2128 
2129 #ifdef G4TESS_TEST
2130  if ( fTessellatedSolid )
2131  {
2132  return fTessellatedSolid->GetExtent();
2133  }
2134 #endif
2135 
2136  G4double Dx,Dy;
2137  G4ThreeVector minVec = GetMinimumBBox();
2138  G4ThreeVector maxVec = GetMaximumBBox();
2139  Dx = 0.5*(maxVec.x()- minVec.x());
2140  Dy = 0.5*(maxVec.y()- minVec.y());
2141 
2142  return G4VisExtent (-Dx, Dx, -Dy, Dy, -fDz, fDz);
2143 }
double x() const
virtual G4VisExtent GetExtent() const
double y() const
double G4double
Definition: G4Types.hh:76
G4int G4GenericTrap::GetNofVertices ( ) const
inline
G4ThreeVector G4GenericTrap::GetPointOnSurface ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 1450 of file G4GenericTrap.cc.

References G4UniformRand, G4TessellatedSolid::GetPointOnSurface(), test::v, test::x, CLHEP::Hep2Vector::x(), and CLHEP::Hep2Vector::y().

1451 {
1452 
1453 #ifdef G4TESS_TEST
1454  if ( fTessellatedSolid )
1455  {
1456  return fTessellatedSolid->GetPointOnSurface();
1457  }
1458 #endif
1459 
1460  G4ThreeVector point;
1461  G4TwoVector u,v,w;
1462  G4double rand,area,chose,cf,lambda0,lambda1,alfa,beta,zp;
1463  G4int ipl,j;
1464 
1465  std::vector<G4ThreeVector> vertices;
1466  for (G4int i=0; i<4;i++)
1467  {
1468  vertices.push_back(G4ThreeVector(fVertices[i].x(),fVertices[i].y(),-fDz));
1469  }
1470  for (G4int i=4; i<8;i++)
1471  {
1472  vertices.push_back(G4ThreeVector(fVertices[i].x(),fVertices[i].y(),fDz));
1473  }
1474 
1475  // Surface Area of Planes(only estimation for twisted)
1476  //
1477  G4double Surface0=GetFaceSurfaceArea(vertices[0],vertices[1],
1478  vertices[2],vertices[3]);//-fDz plane
1479  G4double Surface1=GetFaceSurfaceArea(vertices[0],vertices[1],
1480  vertices[5],vertices[4]);// Lat plane
1481  G4double Surface2=GetFaceSurfaceArea(vertices[3],vertices[0],
1482  vertices[4],vertices[7]);// Lat plane
1483  G4double Surface3=GetFaceSurfaceArea(vertices[2],vertices[3],
1484  vertices[7],vertices[6]);// Lat plane
1485  G4double Surface4=GetFaceSurfaceArea(vertices[2],vertices[1],
1486  vertices[5],vertices[6]);// Lat plane
1487  G4double Surface5=GetFaceSurfaceArea(vertices[4],vertices[5],
1488  vertices[6],vertices[7]);// fDz plane
1489  rand = G4UniformRand();
1490  area = Surface0+Surface1+Surface2+Surface3+Surface4+Surface5;
1491  chose = rand*area;
1492 
1493  if ( ( chose < Surface0)
1494  || ( chose > (Surface0+Surface1+Surface2+Surface3+Surface4)) )
1495  { // fDz or -fDz Plane
1496  ipl = G4int(G4UniformRand()*4);
1497  j = (ipl+1)%4;
1498  if(chose < Surface0)
1499  {
1500  zp = -fDz;
1501  u = fVertices[ipl]; v = fVertices[j];
1502  w = fVertices[(ipl+3)%4];
1503  }
1504  else
1505  {
1506  zp = fDz;
1507  u = fVertices[ipl+4]; v = fVertices[j+4];
1508  w = fVertices[(ipl+3)%4+4];
1509  }
1510  alfa = G4UniformRand();
1511  beta = G4UniformRand();
1512  lambda1=alfa*beta;
1513  lambda0=alfa-lambda1;
1514  v = v-u;
1515  w = w-u;
1516  v = u+lambda0*v+lambda1*w;
1517  }
1518  else // Lateral Plane Twisted or Not
1519  {
1520  if (chose < Surface0+Surface1) { ipl=0; }
1521  else if (chose < Surface0+Surface1+Surface2) { ipl=1; }
1522  else if (chose < Surface0+Surface1+Surface2+Surface3) { ipl=2; }
1523  else { ipl=3; }
1524  j = (ipl+1)%4;
1525  zp = -fDz+G4UniformRand()*2*fDz;
1526  cf = 0.5*(fDz-zp)/fDz;
1527  u = fVertices[ipl+4]+cf*( fVertices[ipl]-fVertices[ipl+4]);
1528  v = fVertices[j+4]+cf*(fVertices[j]-fVertices[j+4]);
1529  v = u+(v-u)*G4UniformRand();
1530  }
1531  point=G4ThreeVector(v.x(),v.y(),zp);
1532 
1533  return point;
1534 }
double y() const
double x() const
CLHEP::Hep3Vector G4ThreeVector
int G4int
Definition: G4Types.hh:78
#define G4UniformRand()
Definition: Randomize.hh:87
double G4double
Definition: G4Types.hh:76
virtual G4ThreeVector GetPointOnSurface() const
G4Polyhedron * G4GenericTrap::GetPolyhedron ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 2088 of file G4GenericTrap.cc.

References CreatePolyhedron(), fpPolyhedron, HepPolyhedron::GetNumberOfRotationSteps(), G4Polyhedron::GetNumberOfRotationStepsAtTimeOfCreation(), and G4TessellatedSolid::GetPolyhedron().

2089 {
2090 
2091 #ifdef G4TESS_TEST
2092  if ( fTessellatedSolid )
2093  {
2094  return fTessellatedSolid->GetPolyhedron();
2095  }
2096 #endif
2097 
2098  if ( (!fpPolyhedron)
2101  {
2102  delete fpPolyhedron;
2104  }
2105  return fpPolyhedron;
2106 }
G4Polyhedron * fpPolyhedron
virtual G4Polyhedron * GetPolyhedron() const
G4Polyhedron * CreatePolyhedron() const
static G4int GetNumberOfRotationSteps()
G4int GetNumberOfRotationStepsAtTimeOfCreation() const
G4double G4GenericTrap::GetSurfaceArea ( )
virtual

Reimplemented from G4VSolid.

Definition at line 1547 of file G4GenericTrap.cc.

References G4VSolid::GetSurfaceArea(), and test::x.

1548 {
1549  if(fSurfaceArea != 0.) {;}
1550  else
1551  {
1552  std::vector<G4ThreeVector> vertices;
1553  for (G4int i=0; i<4;i++)
1554  {
1555  vertices.push_back(G4ThreeVector(fVertices[i].x(),fVertices[i].y(),-fDz));
1556  }
1557  for (G4int i=4; i<8;i++)
1558  {
1559  vertices.push_back(G4ThreeVector(fVertices[i].x(),fVertices[i].y(),fDz));
1560  }
1561 
1562  // Surface Area of Planes(only estimation for twisted)
1563  //
1564  G4double fSurface0=GetFaceSurfaceArea(vertices[0],vertices[1],
1565  vertices[2],vertices[3]);//-fDz plane
1566  G4double fSurface1=GetFaceSurfaceArea(vertices[0],vertices[1],
1567  vertices[5],vertices[4]);// Lat plane
1568  G4double fSurface2=GetFaceSurfaceArea(vertices[3],vertices[0],
1569  vertices[4],vertices[7]);// Lat plane
1570  G4double fSurface3=GetFaceSurfaceArea(vertices[2],vertices[3],
1571  vertices[7],vertices[6]);// Lat plane
1572  G4double fSurface4=GetFaceSurfaceArea(vertices[2],vertices[1],
1573  vertices[5],vertices[6]);// Lat plane
1574  G4double fSurface5=GetFaceSurfaceArea(vertices[4],vertices[5],
1575  vertices[6],vertices[7]);// fDz plane
1576 
1577  // Total Surface Area
1578  //
1579  if(!fIsTwisted)
1580  {
1581  fSurfaceArea = fSurface0+fSurface1+fSurface2
1582  + fSurface3+fSurface4+fSurface5;
1583  }
1584  else
1585  {
1586  fSurfaceArea = G4VSolid::GetSurfaceArea();
1587  }
1588  }
1589  return fSurfaceArea;
1590 }
CLHEP::Hep3Vector G4ThreeVector
int G4int
Definition: G4Types.hh:78
double G4double
Definition: G4Types.hh:76
virtual G4double GetSurfaceArea()
Definition: G4VSolid.cc:250
G4double G4GenericTrap::GetTwistAngle ( G4int  index) const
inline

Referenced by CreatePolyhedron(), and SurfaceNormal().

G4TwoVector G4GenericTrap::GetVertex ( G4int  index) const
inline
const std::vector<G4TwoVector>& G4GenericTrap::GetVertices ( ) const
inline
G4int G4GenericTrap::GetVisSubdivisions ( ) const
inline

Referenced by CreatePolyhedron().

G4double G4GenericTrap::GetZHalfLength ( ) const
inline
EInside G4GenericTrap::Inside ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Definition at line 339 of file G4GenericTrap.cc.

References G4TessellatedSolid::Inside(), kInside, kOutside, kSurface, and CLHEP::Hep3Vector::z().

Referenced by CalculateExtent(), and DistanceToIn().

340 {
341  // Test if point is inside this shape
342 
343 #ifdef G4TESS_TEST
344  if ( fTessellatedSolid )
345  {
346  return fTessellatedSolid->Inside(p);
347  }
348 #endif
349 
350  EInside innew=kOutside;
351  std::vector<G4TwoVector> xy;
352 
353  if (std::fabs(p.z()) <= fDz+halfCarTolerance) // First check Z range
354  {
355  // Compute intersection between Z plane containing point and the shape
356  //
357  G4double cf = 0.5*(fDz-p.z())/fDz;
358  for (G4int i=0; i<4; i++)
359  {
360  xy.push_back(fVertices[i+4]+cf*( fVertices[i]-fVertices[i+4]));
361  }
362 
363  innew=InsidePolygone(p,xy);
364 
365  if( (innew==kInside) || (innew==kSurface) )
366  {
367  if(std::fabs(p.z()) > fDz-halfCarTolerance) { innew=kSurface; }
368  }
369  }
370  return innew;
371 }
int G4int
Definition: G4Types.hh:78
double z() const
virtual EInside Inside(const G4ThreeVector &p) const
EInside
Definition: geomdefs.hh:58
double G4double
Definition: G4Types.hh:76
G4bool G4GenericTrap::IsTwisted ( ) const
inline
G4GenericTrap & G4GenericTrap::operator= ( const G4GenericTrap rhs)

Definition at line 207 of file G4GenericTrap.cc.

References fpPolyhedron, and G4VSolid::operator=().

208 {
209  // Check assignment to self
210  //
211  if (this == &rhs) { return *this; }
212 
213  // Copy base class data
214  //
215  G4VSolid::operator=(rhs);
216 
217  // Copy data
218  //
219  fpPolyhedron = 0; halfCarTolerance = rhs.halfCarTolerance;
220  fDz = rhs.fDz; fVertices = rhs.fVertices;
221  fIsTwisted = rhs.fIsTwisted; fTessellatedSolid = 0;
222  fMinBBoxVector = rhs.fMinBBoxVector; fMaxBBoxVector = rhs.fMaxBBoxVector;
223  fVisSubdivisions = rhs.fVisSubdivisions;
224  fSurfaceArea = rhs.fSurfaceArea; fCubicVolume = rhs.fCubicVolume;
225 
226  for (size_t i=0; i<4; ++i) { fTwist[i] = rhs.fTwist[i]; }
227 #ifdef G4TESS_TEST
228  if (rhs.fTessellatedSolid && !fIsTwisted )
229  { delete fTessellatedSolid; fTessellatedSolid = CreateTessellatedSolid(); }
230 #endif
231 
232  return *this;
233 }
G4Polyhedron * fpPolyhedron
G4VSolid & operator=(const G4VSolid &rhs)
Definition: G4VSolid.cc:110
void G4GenericTrap::SetVisSubdivisions ( G4int  subdiv)
inline
std::ostream & G4GenericTrap::StreamInfo ( std::ostream &  os) const
virtual

Implements G4VSolid.

Definition at line 1427 of file G4GenericTrap.cc.

References G4endl, GetEntityType(), G4VSolid::GetName(), and python.hepunit::mm.

1428 {
1429  G4int oldprc = os.precision(16);
1430  os << "-----------------------------------------------------------\n"
1431  << " *** Dump for solid - " << GetName() << " *** \n"
1432  << " =================================================== \n"
1433  << " Solid geometry type: " << GetEntityType() << G4endl
1434  << " half length Z: " << fDz/mm << " mm \n"
1435  << " list of vertices:\n";
1436 
1437  for ( G4int i=0; i<fgkNofVertices; ++i )
1438  {
1439  os << std::setw(5) << "#" << i
1440  << " vx = " << fVertices[i].x()/mm << " mm"
1441  << " vy = " << fVertices[i].y()/mm << " mm" << G4endl;
1442  }
1443  os.precision(oldprc);
1444 
1445  return os;
1446 }
G4String GetName() const
G4GeometryType GetEntityType() const
int G4int
Definition: G4Types.hh:78
#define G4endl
Definition: G4ios.hh:61
G4ThreeVector G4GenericTrap::SurfaceNormal ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Definition at line 375 of file G4GenericTrap.cc.

References CLHEP::Hep3Vector::cross(), G4Exception(), GetTwistAngle(), JustWarning, G4VSolid::kCarTolerance, G4TessellatedSolid::SurfaceNormal(), CLHEP::Hep3Vector::unit(), test::x, and CLHEP::Hep3Vector::z().

376 {
377  // Calculate side nearest to p, and return normal
378  // If two sides are equidistant, sum of the Normal is returned
379 
380 #ifdef G4TESS_TEST
381  if ( fTessellatedSolid )
382  {
383  return fTessellatedSolid->SurfaceNormal(p);
384  }
385 #endif
386 
387  G4ThreeVector lnorm, sumnorm(0.,0.,0.), apprnorm(0.,0.,1.),
388  p0, p1, p2, r1, r2, r3, r4;
389  G4int noSurfaces = 0;
390  G4double distxy,distz;
391  G4bool zPlusSide=false;
392 
393  distz = fDz-std::fabs(p.z());
394  if (distz < halfCarTolerance)
395  {
396  if(p.z()>0)
397  {
398  zPlusSide=true;
399  sumnorm=G4ThreeVector(0,0,1);
400  }
401  else
402  {
403  sumnorm=G4ThreeVector(0,0,-1);
404  }
405  noSurfaces ++;
406  }
407 
408  // Check lateral planes
409  //
410  std:: vector<G4TwoVector> vertices;
411  G4double cf = 0.5*(fDz-p.z())/fDz;
412  for (G4int i=0; i<4; i++)
413  {
414  vertices.push_back(fVertices[i+4]+cf*(fVertices[i]-fVertices[i+4]));
415  }
416 
417  // Compute distance for lateral planes
418  //
419  for (G4int q=0; q<4; q++)
420  {
421  p0=G4ThreeVector(vertices[q].x(),vertices[q].y(),p.z());
422  if(zPlusSide)
423  {
424  p1=G4ThreeVector(fVertices[q].x(),fVertices[q].y(),-fDz);
425  }
426  else
427  {
428  p1=G4ThreeVector(fVertices[q+4].x(),fVertices[q+4].y(),fDz);
429  }
430  p2=G4ThreeVector(vertices[(q+1)%4].x(),vertices[(q+1)%4].y(),p.z());
431 
432  // Collapsed vertices
433  //
434  if ( (p2-p0).mag2() < kCarTolerance )
435  {
436  if ( std::fabs(p.z()+fDz) > kCarTolerance )
437  {
438  p2=G4ThreeVector(fVertices[(q+1)%4].x(),fVertices[(q+1)%4].y(),-fDz);
439  }
440  else
441  {
442  p2=G4ThreeVector(fVertices[(q+1)%4+4].x(),fVertices[(q+1)%4+4].y(),fDz);
443  }
444  }
445  lnorm = (p1-p0).cross(p2-p0);
446  lnorm = lnorm.unit();
447  if(zPlusSide) { lnorm=-lnorm; }
448 
449  // Adjust Normal for Twisted Surface
450  //
451  if ( (fIsTwisted) && (GetTwistAngle(q)!=0) )
452  {
453  G4double normP=(p2-p0).mag();
454  if(normP)
455  {
456  G4double proj=(p-p0).dot(p2-p0)/normP;
457  if(proj<0) { proj=0; }
458  if(proj>normP) { proj=normP; }
459  G4int j=(q+1)%4;
460  r1=G4ThreeVector(fVertices[q+4].x(),fVertices[q+4].y(),fDz);
461  r2=G4ThreeVector(fVertices[j+4].x(),fVertices[j+4].y(),fDz);
462  r3=G4ThreeVector(fVertices[q].x(),fVertices[q].y(),-fDz);
463  r4=G4ThreeVector(fVertices[j].x(),fVertices[j].y(),-fDz);
464  r1=r1+proj*(r2-r1)/normP;
465  r3=r3+proj*(r4-r3)/normP;
466  r2=r1-r3;
467  r4=r2.cross(p2-p0); r4=r4.unit();
468  lnorm=r4;
469  }
470  } // End if fIsTwisted
471 
472  distxy=std::fabs((p0-p).dot(lnorm));
473  if ( distxy<halfCarTolerance )
474  {
475  noSurfaces ++;
476 
477  // Negative sign for Normal is taken for Outside Normal
478  //
479  sumnorm=sumnorm+lnorm;
480  }
481 
482  // For ApproxSurfaceNormal
483  //
484  if (distxy<distz)
485  {
486  distz=distxy;
487  apprnorm=lnorm;
488  }
489  } // End for loop
490 
491  // Calculate final Normal, add Normal in the Corners and Touching Sides
492  //
493  if ( noSurfaces == 0 )
494  {
495  G4Exception("G4GenericTrap::SurfaceNormal(p)", "GeomSolids1002",
496  JustWarning, "Point p is not on surface !?" );
497  sumnorm=apprnorm;
498  // Add Approximative Surface Normal Calculation?
499  }
500  else if ( noSurfaces == 1 ) { sumnorm = sumnorm; }
501  else { sumnorm = sumnorm.unit(); }
502 
503  return sumnorm ;
504 }
CLHEP::Hep3Vector G4ThreeVector
int G4int
Definition: G4Types.hh:78
double z() const
bool G4bool
Definition: G4Types.hh:79
G4double GetTwistAngle(G4int index) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
Hep3Vector unit() const
G4double kCarTolerance
Definition: G4VSolid.hh:305
Hep3Vector cross(const Hep3Vector &) const
double G4double
Definition: G4Types.hh:76
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const

Field Documentation

G4Polyhedron* G4GenericTrap::fpPolyhedron
mutableprotected

Definition at line 191 of file G4GenericTrap.hh.

Referenced by GetPolyhedron(), and operator=().


The documentation for this class was generated from the following files: