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

#include <G4ExtrudedSolid.hh>

Inheritance diagram for G4ExtrudedSolid:
G4TessellatedSolid G4VSolid

Data Structures

struct  ZSection
 

Public Member Functions

 G4ExtrudedSolid (const G4String &pName, std::vector< G4TwoVector > polygon, std::vector< ZSection > zsections)
 
 G4ExtrudedSolid (const G4String &pName, std::vector< G4TwoVector > polygon, G4double halfZ, G4TwoVector off1, G4double scale1, G4TwoVector off2, G4double scale2)
 
virtual ~G4ExtrudedSolid ()
 
G4int GetNofVertices () const
 
G4TwoVector GetVertex (G4int index) const
 
std::vector< G4TwoVector > GetPolygon () const
 
G4int GetNofZSections () const
 
ZSection GetZSection (G4int index) const
 
std::vector< ZSection > GetZSections () const
 
EInside Inside (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
 
G4GeometryType GetEntityType () const
 
G4VSolid * Clone () const
 
std::ostream & StreamInfo (std::ostream &os) const
 
 G4ExtrudedSolid (__void__ &)
 
 G4ExtrudedSolid (const G4ExtrudedSolid &rhs)
 
G4ExtrudedSolid & operator= (const G4ExtrudedSolid &rhs)
 
- Public Member Functions inherited from G4TessellatedSolid
 G4TessellatedSolid ()
 
virtual ~G4TessellatedSolid ()
 
 G4TessellatedSolid (const G4String &name)
 
 G4TessellatedSolid (__void__ &)
 
 G4TessellatedSolid (const G4TessellatedSolid &ts)
 
G4TessellatedSolid & operator= (const G4TessellatedSolid &right)
 
G4TessellatedSolid & operator+= (const G4TessellatedSolid &right)
 
G4bool AddFacet (G4VFacet *aFacet)
 
G4VFacet * GetFacet (G4int i) const
 
G4int GetNumberOfFacets () const
 
virtual G4ThreeVector SurfaceNormal (const G4ThreeVector &p) const
 
virtual G4double DistanceToIn (const G4ThreeVector &p, const G4ThreeVector &v) const
 
virtual G4double DistanceToIn (const G4ThreeVector &p) const
 
virtual G4bool Normal (const G4ThreeVector &p, G4ThreeVector &n) const
 
virtual G4double SafetyFromOutside (const G4ThreeVector &p, G4bool aAccurate=false) const
 
virtual G4double SafetyFromInside (const G4ThreeVector &p, G4bool aAccurate=false) const
 
virtual G4ThreeVector GetPointOnSurface () const
 
virtual G4double GetSurfaceArea ()
 
virtual G4double GetCubicVolume ()
 
void SetSolidClosed (const G4bool t)
 
G4bool GetSolidClosed () const
 
void SetMaxVoxels (G4int max)
 
G4SurfaceVoxelizer & GetVoxels ()
 
virtual G4bool CalculateExtent (const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
 
G4double GetMinXExtent () const
 
G4double GetMaxXExtent () const
 
G4double GetMinYExtent () const
 
G4double GetMaxYExtent () const
 
G4double GetMinZExtent () const
 
G4double GetMaxZExtent () const
 
G4ThreeVectorList * CreateRotatedVertices (const G4AffineTransform &pT) const
 
virtual G4Polyhedron * CreatePolyhedron () const
 
virtual G4Polyhedron * GetPolyhedron () const
 
virtual void DescribeYourselfTo (G4VGraphicsScene &scene) const
 
virtual G4VisExtent GetExtent () const
 
G4int AllocatedMemoryWithoutVoxels ()
 
G4int AllocatedMemory ()
 
void DisplayAllocatedMemory ()
 
- 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 G4VSolid * GetConstituentSolid (G4int no) const
 
virtual G4VSolid * GetConstituentSolid (G4int no)
 
virtual const G4DisplacedSolid * GetDisplacedSolidPtr () const
 
virtual G4DisplacedSolid * GetDisplacedSolidPtr ()
 
 G4VSolid (__void__ &)
 
 G4VSolid (const G4VSolid &rhs)
 
G4VSolid & operator= (const G4VSolid &rhs)
 

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
 
- Protected Attributes inherited from G4VSolid
G4double kCarTolerance
 

Detailed Description

Definition at line 73 of file G4ExtrudedSolid.hh.

Constructor & Destructor Documentation

G4ExtrudedSolid::G4ExtrudedSolid ( const G4String &  pName,
std::vector< G4TwoVector >  polygon,
std::vector< ZSection >  zsections 
)

Definition at line 52 of file G4ExtrudedSolid.cc.

References FatalErrorInArgument, FatalException, G4Exception(), and G4VSolid::kCarTolerance.

Referenced by Clone().

55  : G4TessellatedSolid(pName),
56  fNv(polygon.size()),
57  fNz(zsections.size()),
58  fPolygon(),
59  fZSections(),
60  fTriangles(),
61  fIsConvex(false),
62  fGeometryType("G4ExtrudedSolid")
63 
64 {
65  // General constructor
66 
67  // First check input parameters
68 
69  if ( fNv < 3 )
70  {
71  std::ostringstream message;
72  message << "Number of polygon vertices < 3 - " << pName;
73  G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "GeomSolids0002",
74  FatalErrorInArgument, message);
75  }
76 
77  if ( fNz < 2 )
78  {
79  std::ostringstream message;
80  message << "Number of z-sides < 2 - " << pName;
81  G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "GeomSolids0002",
82  FatalErrorInArgument, message);
83  }
84 
85  for ( G4int i=0; i<fNz-1; ++i )
86  {
87  if ( zsections[i].fZ > zsections[i+1].fZ )
88  {
89  std::ostringstream message;
90  message << "Z-sections have to be ordered by z value (z0 < z1 < z2...) - "
91  << pName;
92  G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "GeomSolids0002",
93  FatalErrorInArgument, message);
94  }
95  if ( std::fabs( zsections[i+1].fZ - zsections[i].fZ ) < kCarTolerance * 0.5 )
96  {
97  std::ostringstream message;
98  message << "Z-sections with the same z position are not supported - "
99  << pName;
100  G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "GeomSolids0001",
101  FatalException, message);
102  }
103  }
104 
105  // Check if polygon vertices are defined clockwise
106  // (the area is positive if polygon vertices are defined anti-clockwise)
107  //
108  G4double area = 0.;
109  for ( G4int i=0; i<fNv; ++i ) {
110  G4int j = i+1;
111  if ( j == fNv ) j = 0;
112  area += 0.5 * ( polygon[i].x()*polygon[j].y() - polygon[j].x()*polygon[i].y());
113  }
114 
115  // Copy polygon
116  //
117  if ( area < 0. ) {
118  // Polygon vertices are defined clockwise, we just copy the polygon
119  for ( G4int i=0; i<fNv; ++i ) { fPolygon.push_back(polygon[i]); }
120  }
121  else {
122  // Polygon vertices are defined anti-clockwise, we revert them
123  //G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "GeomSolids1001",
124  // JustWarning,
125  // "Polygon vertices defined anti-clockwise, reverting polygon");
126  for ( G4int i=0; i<fNv; ++i ) { fPolygon.push_back(polygon[fNv-i-1]); }
127  }
128 
129 
130  // Copy z-sections
131  //
132  for ( G4int i=0; i<fNz; ++i ) { fZSections.push_back(zsections[i]); }
133 
134 
135  G4bool result = MakeFacets();
136  if (!result)
137  {
138  std::ostringstream message;
139  message << "Making facets failed - " << pName;
140  G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "GeomSolids0003",
141  FatalException, message);
142  }
143  fIsConvex = IsConvex();
144 
145 
146  ComputeProjectionParameters();
147 }
int G4int
Definition: G4Types.hh:78
bool G4bool
Definition: G4Types.hh:79
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4double kCarTolerance
Definition: G4VSolid.hh:305
double G4double
Definition: G4Types.hh:76
G4ExtrudedSolid::G4ExtrudedSolid ( const G4String &  pName,
std::vector< G4TwoVector >  polygon,
G4double  halfZ,
G4TwoVector  off1,
G4double  scale1,
G4TwoVector  off2,
G4double  scale2 
)

Definition at line 151 of file G4ExtrudedSolid.cc.

References FatalErrorInArgument, FatalException, and G4Exception().

156  : G4TessellatedSolid(pName),
157  fNv(polygon.size()),
158  fNz(2),
159  fPolygon(),
160  fZSections(),
161  fTriangles(),
162  fIsConvex(false),
163  fGeometryType("G4ExtrudedSolid")
164 
165 {
166  // Special constructor for solid with 2 z-sections
167 
168  // First check input parameters
169  //
170  if ( fNv < 3 )
171  {
172  std::ostringstream message;
173  message << "Number of polygon vertices < 3 - " << pName;
174  G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "GeomSolids0002",
175  FatalErrorInArgument, message);
176  }
177 
178  // Check if polygon vertices are defined clockwise
179  // (the area is positive if polygon vertices are defined anti-clockwise)
180 
181  G4double area = 0.;
182  for ( G4int i=0; i<fNv; ++i )
183  {
184  G4int j = i+1;
185  if ( j == fNv ) { j = 0; }
186  area += 0.5 * ( polygon[i].x()*polygon[j].y()
187  - polygon[j].x()*polygon[i].y());
188  }
189 
190  // Copy polygon
191  //
192  if ( area < 0. )
193  {
194  // Polygon vertices are defined clockwise, we just copy the polygon
195  for ( G4int i=0; i<fNv; ++i ) { fPolygon.push_back(polygon[i]); }
196  }
197  else
198  {
199  // Polygon vertices are defined anti-clockwise, we revert them
200  //G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "GeomSolids1001",
201  // JustWarning,
202  // "Polygon vertices defined anti-clockwise, reverting polygon");
203  for ( G4int i=0; i<fNv; ++i ) { fPolygon.push_back(polygon[fNv-i-1]); }
204  }
205 
206  // Copy z-sections
207  //
208  fZSections.push_back(ZSection(-dz, off1, scale1));
209  fZSections.push_back(ZSection( dz, off2, scale2));
210 
211  G4bool result = MakeFacets();
212  if (!result)
213  {
214  std::ostringstream message;
215  message << "Making facets failed - " << pName;
216  G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "GeomSolids0003",
217  FatalException, message);
218  }
219  fIsConvex = IsConvex();
220 
221  ComputeProjectionParameters();
222 }
int G4int
Definition: G4Types.hh:78
bool G4bool
Definition: G4Types.hh:79
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double G4double
Definition: G4Types.hh:76
G4ExtrudedSolid::~G4ExtrudedSolid ( )
virtual

Definition at line 272 of file G4ExtrudedSolid.cc.

273 {
274  // Destructor
275 }
G4ExtrudedSolid::G4ExtrudedSolid ( __void__ &  a)

Definition at line 226 of file G4ExtrudedSolid.cc.

227  : G4TessellatedSolid(a), fNv(0), fNz(0), fPolygon(), fZSections(),
228  fTriangles(), fIsConvex(false), fGeometryType("G4ExtrudedSolid")
229 {
230  // Fake default constructor - sets only member data and allocates memory
231  // for usage restricted to object persistency.
232 }
G4ExtrudedSolid::G4ExtrudedSolid ( const G4ExtrudedSolid &  rhs)

Definition at line 236 of file G4ExtrudedSolid.cc.

237  : G4TessellatedSolid(rhs), fNv(rhs.fNv), fNz(rhs.fNz),
238  fPolygon(rhs.fPolygon), fZSections(rhs.fZSections),
239  fTriangles(rhs.fTriangles), fIsConvex(rhs.fIsConvex),
240  fGeometryType(rhs.fGeometryType), fKScales(rhs.fKScales),
241  fScale0s(rhs.fScale0s), fKOffsets(rhs.fKOffsets), fOffset0s(rhs.fOffset0s)
242 {
243 }

Member Function Documentation

G4VSolid * G4ExtrudedSolid::Clone ( ) const
virtual

Reimplemented from G4TessellatedSolid.

Definition at line 753 of file G4ExtrudedSolid.cc.

References G4ExtrudedSolid().

754 {
755  return new G4ExtrudedSolid(*this);
756 }
G4ExtrudedSolid(const G4String &pName, std::vector< G4TwoVector > polygon, std::vector< ZSection > zsections)
G4double G4ExtrudedSolid::DistanceToOut ( const G4ThreeVector &  p,
const G4ThreeVector &  v,
const G4bool  calcNorm = false,
G4bool *  validNorm = 0,
G4ThreeVector *  n = 0 
) const
virtual

Reimplemented from G4TessellatedSolid.

Definition at line 833 of file G4ExtrudedSolid.cc.

References G4TessellatedSolid::DistanceToOut().

838 {
839  // Override the base class function to redefine validNorm
840  // (the solid can be concave)
841 
842  G4double distOut =
843  G4TessellatedSolid::DistanceToOut(p, v, calcNorm, validNorm, n);
844  if (validNorm) { *validNorm = fIsConvex; }
845 
846  return distOut;
847 }
virtual G4double DistanceToOut(const G4ThreeVector &p) const
double G4double
Definition: G4Types.hh:76
G4double G4ExtrudedSolid::DistanceToOut ( const G4ThreeVector &  p) const
virtual

Reimplemented from G4TessellatedSolid.

Definition at line 852 of file G4ExtrudedSolid.cc.

References G4TessellatedSolid::DistanceToOut().

853 {
854  // Override the overloaded base class function
855 
857 }
virtual G4double DistanceToOut(const G4ThreeVector &p) const
G4GeometryType G4ExtrudedSolid::GetEntityType ( ) const
virtual

Reimplemented from G4TessellatedSolid.

Definition at line 744 of file G4ExtrudedSolid.cc.

745 {
746  // Return entity type
747 
748  return fGeometryType;
749 }
G4int G4ExtrudedSolid::GetNofVertices ( ) const
inline
G4int G4ExtrudedSolid::GetNofZSections ( ) const
inline
std::vector<G4TwoVector> G4ExtrudedSolid::GetPolygon ( ) const
inline
G4TwoVector G4ExtrudedSolid::GetVertex ( G4int  index) const
inline
ZSection G4ExtrudedSolid::GetZSection ( G4int  index) const
inline
std::vector<ZSection> G4ExtrudedSolid::GetZSections ( ) const
inline
EInside G4ExtrudedSolid::Inside ( const G4ThreeVector &  p) const
virtual

Reimplemented from G4TessellatedSolid.

Definition at line 760 of file G4ExtrudedSolid.cc.

References G4TessellatedSolid::GetMaxXExtent(), G4TessellatedSolid::GetMaxYExtent(), G4TessellatedSolid::GetMaxZExtent(), G4TessellatedSolid::GetMinXExtent(), G4TessellatedSolid::GetMinYExtent(), G4TessellatedSolid::GetMinZExtent(), G4VSolid::kCarTolerance, kInside, kOutside, kSurface, CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

761 {
762  // Override the base class function as it fails in case of concave polygon.
763  // Project the point in the original polygon scale and check if it is inside
764  // for each triangle.
765 
766  // Check first if outside extent
767  //
768  if ( p.x() < GetMinXExtent() - kCarTolerance * 0.5 ||
769  p.x() > GetMaxXExtent() + kCarTolerance * 0.5 ||
770  p.y() < GetMinYExtent() - kCarTolerance * 0.5 ||
771  p.y() > GetMaxYExtent() + kCarTolerance * 0.5 ||
772  p.z() < GetMinZExtent() - kCarTolerance * 0.5 ||
773  p.z() > GetMaxZExtent() + kCarTolerance * 0.5 )
774  {
775  // G4cout << "G4ExtrudedSolid::Outside extent: " << p << G4endl;
776  return kOutside;
777  }
778 
779  // Project point p(z) to the polygon scale p0
780  //
781  G4TwoVector pscaled = ProjectPoint(p);
782 
783  // Check if on surface of polygon
784  //
785  for ( G4int i=0; i<fNv; ++i )
786  {
787  G4int j = (i+1) % fNv;
788  if ( IsSameLineSegment(pscaled, fPolygon[i], fPolygon[j]) )
789  {
790  // G4cout << "G4ExtrudedSolid::Inside return Surface (on polygon) "
791  // << G4endl;
792 
793  return kSurface;
794  }
795  }
796 
797  // Now check if inside triangles
798  //
799  std::vector< std::vector<G4int> >::const_iterator it = fTriangles.begin();
800  G4bool inside = false;
801  do
802  {
803  if ( IsPointInside(fPolygon[(*it)[0]], fPolygon[(*it)[1]],
804  fPolygon[(*it)[2]], pscaled) ) { inside = true; }
805  ++it;
806  } while ( (inside == false) && (it != fTriangles.end()) );
807 
808  if ( inside )
809  {
810  // Check if on surface of z sides
811  //
812  if ( std::fabs( p.z() - fZSections[0].fZ ) < kCarTolerance * 0.5 ||
813  std::fabs( p.z() - fZSections[fNz-1].fZ ) < kCarTolerance * 0.5 )
814  {
815  // G4cout << "G4ExtrudedSolid::Inside return Surface (on z side)"
816  // << G4endl;
817 
818  return kSurface;
819  }
820 
821  // G4cout << "G4ExtrudedSolid::Inside return Inside" << G4endl;
822 
823  return kInside;
824  }
825 
826  // G4cout << "G4ExtrudedSolid::Inside return Outside " << G4endl;
827 
828  return kOutside;
829 }
double x() const
G4double GetMaxXExtent() const
G4double GetMinXExtent() const
G4double GetMaxZExtent() const
int G4int
Definition: G4Types.hh:78
double z() const
G4double GetMinZExtent() const
bool G4bool
Definition: G4Types.hh:79
double y() const
G4double kCarTolerance
Definition: G4VSolid.hh:305
G4double GetMaxYExtent() const
G4double GetMinYExtent() const
G4ExtrudedSolid & G4ExtrudedSolid::operator= ( const G4ExtrudedSolid &  rhs)

Definition at line 248 of file G4ExtrudedSolid.cc.

References G4TessellatedSolid::operator=().

249 {
250  // Check assignment to self
251  //
252  if (this == &rhs) { return *this; }
253 
254  // Copy base class data
255  //
257 
258  // Copy data
259  //
260  fNv = rhs.fNv; fNz = rhs.fNz;
261  fPolygon = rhs.fPolygon; fZSections = rhs.fZSections;
262  fTriangles = rhs.fTriangles; fIsConvex = rhs.fIsConvex;
263  fGeometryType = rhs.fGeometryType; fKScales = rhs.fKScales;
264  fScale0s = rhs.fScale0s; fKOffsets = rhs.fKOffsets;
265  fOffset0s = rhs.fOffset0s;
266 
267  return *this;
268 }
G4TessellatedSolid & operator=(const G4TessellatedSolid &right)
std::ostream & G4ExtrudedSolid::StreamInfo ( std::ostream &  os) const
virtual

Reimplemented from G4TessellatedSolid.

Definition at line 861 of file G4ExtrudedSolid.cc.

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

862 {
863  G4int oldprc = os.precision(16);
864  os << "-----------------------------------------------------------\n"
865  << " *** Dump for solid - " << GetName() << " ***\n"
866  << " ===================================================\n"
867  << " Solid geometry type: " << fGeometryType << G4endl;
868 
869  if ( fIsConvex)
870  { os << " Convex polygon; list of vertices:" << G4endl; }
871  else
872  { os << " Concave polygon; list of vertices:" << G4endl; }
873 
874  for ( G4int i=0; i<fNv; ++i )
875  {
876  os << std::setw(5) << "#" << i
877  << " vx = " << fPolygon[i].x()/mm << " mm"
878  << " vy = " << fPolygon[i].y()/mm << " mm" << G4endl;
879  }
880 
881  os << " Sections:" << G4endl;
882  for ( G4int iz=0; iz<fNz; ++iz )
883  {
884  os << " z = " << fZSections[iz].fZ/mm << " mm "
885  << " x0= " << fZSections[iz].fOffset.x()/mm << " mm "
886  << " y0= " << fZSections[iz].fOffset.y()/mm << " mm "
887  << " scale= " << fZSections[iz].fScale << G4endl;
888  }
889 
890 /*
891  // Triangles (for debugging)
892  os << G4endl;
893  os << " Triangles:" << G4endl;
894  os << " Triangle # vertex1 vertex2 vertex3" << G4endl;
895 
896  G4int counter = 0;
897  std::vector< std::vector<G4int> >::const_iterator it;
898  for ( it = fTriangles.begin(); it != fTriangles.end(); it++ ) {
899  std::vector<G4int> triangle = *it;
900  os << std::setw(10) << counter++
901  << std::setw(10) << triangle[0] << std::setw(10) << triangle[1] << std::setw(10) << triangle[2]
902  << G4endl;
903  }
904 */
905  os.precision(oldprc);
906 
907  return os;
908 }
G4String GetName() const
int G4int
Definition: G4Types.hh:78
G4double iz
Definition: TRTMaterials.hh:39
#define G4endl
Definition: G4ios.hh:61

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