G4ExtrudedSolid Class Reference

#include <G4ExtrudedSolid.hh>

Inheritance diagram for G4ExtrudedSolid:

G4TessellatedSolid G4VSolid

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< G4TwoVectorGetPolygon () const
G4int GetNofZSections () const
ZSection GetZSection (G4int index) const
std::vector< ZSectionGetZSections () 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
G4VSolidClone () const
std::ostream & StreamInfo (std::ostream &os) const
 G4ExtrudedSolid (__void__ &)
 G4ExtrudedSolid (const G4ExtrudedSolid &rhs)
G4ExtrudedSolidoperator= (const G4ExtrudedSolid &rhs)

Data Structures

struct  ZSection

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().

00055   : G4TessellatedSolid(pName),
00056     fNv(polygon.size()),
00057     fNz(zsections.size()),
00058     fPolygon(),
00059     fZSections(),
00060     fTriangles(),
00061     fIsConvex(false),
00062     fGeometryType("G4ExtrudedSolid")
00063     
00064 {
00065   // General constructor 
00066 
00067   // First check input parameters
00068 
00069   if ( fNv < 3 )
00070   {
00071     std::ostringstream message;
00072     message << "Number of polygon vertices < 3 - " << pName;
00073     G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "GeomSolids0002",
00074                 FatalErrorInArgument, message);
00075   }
00076      
00077   if ( fNz < 2 )
00078   {
00079     std::ostringstream message;
00080     message << "Number of z-sides < 2 - " << pName;
00081     G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "GeomSolids0002",
00082                 FatalErrorInArgument, message);
00083   }
00084      
00085   for ( G4int i=0; i<fNz-1; ++i ) 
00086   {
00087     if ( zsections[i].fZ > zsections[i+1].fZ ) 
00088     {
00089       std::ostringstream message;
00090       message << "Z-sections have to be ordered by z value (z0 < z1 < z2...) - "
00091               << pName;
00092       G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "GeomSolids0002",
00093                   FatalErrorInArgument, message);
00094     }
00095     if ( std::fabs( zsections[i+1].fZ - zsections[i].fZ ) < kCarTolerance * 0.5 ) 
00096     {
00097       std::ostringstream message;
00098       message << "Z-sections with the same z position are not supported - "
00099               << pName;
00100       G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "GeomSolids0001",
00101                   FatalException, message);
00102     }
00103   }  
00104   
00105   // Check if polygon vertices are defined clockwise
00106   // (the area is positive if polygon vertices are defined anti-clockwise)
00107   //
00108   G4double area = 0.;
00109   for ( G4int i=0; i<fNv; ++i ) {
00110     G4int j = i+1;
00111     if ( j == fNv ) j = 0;
00112     area += 0.5 * ( polygon[i].x()*polygon[j].y() - polygon[j].x()*polygon[i].y());
00113   }
00114  
00115   // Copy polygon
00116   //
00117   if  ( area < 0. ) {   
00118     // Polygon vertices are defined clockwise, we just copy the polygon       
00119     for ( G4int i=0; i<fNv; ++i ) { fPolygon.push_back(polygon[i]); }
00120   }
00121   else {
00122     // Polygon vertices are defined anti-clockwise, we revert them
00123     //G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "GeomSolids1001",
00124     //            JustWarning, 
00125     //            "Polygon vertices defined anti-clockwise, reverting polygon");      
00126     for ( G4int i=0; i<fNv; ++i ) { fPolygon.push_back(polygon[fNv-i-1]); }
00127   }
00128     
00129   
00130   // Copy z-sections
00131   //
00132   for ( G4int i=0; i<fNz; ++i ) { fZSections.push_back(zsections[i]); }
00133     
00134 
00135   G4bool result = MakeFacets();
00136   if (!result)
00137   {   
00138     std::ostringstream message;
00139     message << "Making facets failed - " << pName;
00140     G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "GeomSolids0003",
00141                 FatalException, message);
00142   }
00143   fIsConvex = IsConvex();
00144 
00145   
00146   ComputeProjectionParameters();
00147 }

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().

00156   : G4TessellatedSolid(pName),
00157     fNv(polygon.size()),
00158     fNz(2),
00159     fPolygon(),
00160     fZSections(),
00161     fTriangles(),
00162     fIsConvex(false),
00163     fGeometryType("G4ExtrudedSolid")
00164     
00165 {
00166   // Special constructor for solid with 2 z-sections
00167 
00168   // First check input parameters
00169   //
00170   if ( fNv < 3 )
00171   {
00172     std::ostringstream message;
00173     message << "Number of polygon vertices < 3 - " << pName;
00174     G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "GeomSolids0002",
00175                 FatalErrorInArgument, message);
00176   }
00177      
00178   // Check if polygon vertices are defined clockwise
00179   // (the area is positive if polygon vertices are defined anti-clockwise)
00180   
00181   G4double area = 0.;
00182   for ( G4int i=0; i<fNv; ++i )
00183   {
00184     G4int j = i+1;
00185     if ( j == fNv )  { j = 0; }
00186     area += 0.5 * ( polygon[i].x()*polygon[j].y()
00187                   - polygon[j].x()*polygon[i].y());
00188   }
00189  
00190   // Copy polygon
00191   //
00192   if  ( area < 0. )
00193   {   
00194     // Polygon vertices are defined clockwise, we just copy the polygon       
00195     for ( G4int i=0; i<fNv; ++i ) { fPolygon.push_back(polygon[i]); }
00196   }
00197   else
00198   {
00199     // Polygon vertices are defined anti-clockwise, we revert them
00200     //G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "GeomSolids1001",
00201     //            JustWarning, 
00202     //            "Polygon vertices defined anti-clockwise, reverting polygon");      
00203     for ( G4int i=0; i<fNv; ++i ) { fPolygon.push_back(polygon[fNv-i-1]); }
00204   }
00205   
00206   // Copy z-sections
00207   //
00208   fZSections.push_back(ZSection(-dz, off1, scale1));
00209   fZSections.push_back(ZSection( dz, off2, scale2));
00210     
00211   G4bool result = MakeFacets();
00212   if (!result)
00213   {   
00214     std::ostringstream message;
00215     message << "Making facets failed - " << pName;
00216     G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "GeomSolids0003",
00217                 FatalException, message);
00218   }
00219   fIsConvex = IsConvex();
00220 
00221   ComputeProjectionParameters();
00222 }

G4ExtrudedSolid::~G4ExtrudedSolid (  )  [virtual]

Definition at line 272 of file G4ExtrudedSolid.cc.

00273 {
00274   // Destructor
00275 }

G4ExtrudedSolid::G4ExtrudedSolid ( __void__ &   ) 

Definition at line 226 of file G4ExtrudedSolid.cc.

00227   : G4TessellatedSolid(a), fNv(0), fNz(0), fPolygon(), fZSections(),
00228     fTriangles(), fIsConvex(false), fGeometryType("G4ExtrudedSolid")
00229 {
00230   // Fake default constructor - sets only member data and allocates memory
00231   //                            for usage restricted to object persistency.
00232 }

G4ExtrudedSolid::G4ExtrudedSolid ( const G4ExtrudedSolid rhs  ) 

Definition at line 236 of file G4ExtrudedSolid.cc.

00237   : G4TessellatedSolid(rhs), fNv(rhs.fNv), fNz(rhs.fNz),
00238     fPolygon(rhs.fPolygon), fZSections(rhs.fZSections),
00239     fTriangles(rhs.fTriangles), fIsConvex(rhs.fIsConvex),
00240     fGeometryType(rhs.fGeometryType), fKScales(rhs.fKScales),
00241     fScale0s(rhs.fScale0s), fKOffsets(rhs.fKOffsets), fOffset0s(rhs.fOffset0s)
00242 {
00243 }


Member Function Documentation

G4VSolid * G4ExtrudedSolid::Clone (  )  const [virtual]

Reimplemented from G4TessellatedSolid.

Definition at line 753 of file G4ExtrudedSolid.cc.

References G4ExtrudedSolid().

00754 {
00755   return new G4ExtrudedSolid(*this);
00756 }

G4double G4ExtrudedSolid::DistanceToOut ( const G4ThreeVector p  )  const [virtual]

Reimplemented from G4TessellatedSolid.

Definition at line 852 of file G4ExtrudedSolid.cc.

References G4TessellatedSolid::DistanceToOut().

00853 {
00854   // Override the overloaded base class function
00855 
00856   return G4TessellatedSolid::DistanceToOut(p);
00857 }

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().

00838 {
00839   // Override the base class function to redefine validNorm
00840   // (the solid can be concave) 
00841 
00842   G4double distOut =
00843     G4TessellatedSolid::DistanceToOut(p, v, calcNorm, validNorm, n);
00844   if (validNorm) { *validNorm = fIsConvex; }
00845 
00846   return distOut;
00847 }

G4GeometryType G4ExtrudedSolid::GetEntityType (  )  const [virtual]

Reimplemented from G4TessellatedSolid.

Definition at line 744 of file G4ExtrudedSolid.cc.

00745 {
00746   // Return entity type
00747 
00748   return fGeometryType;
00749 }

G4int G4ExtrudedSolid::GetNofVertices (  )  const [inline]

Definition at line 38 of file G4ExtrudedSolid.icc.

Referenced by G4GDMLWriteSolids::XtruWrite().

00039 {
00040   return fNv;
00041 }

G4int G4ExtrudedSolid::GetNofZSections (  )  const [inline]

Definition at line 61 of file G4ExtrudedSolid.icc.

Referenced by G4GDMLWriteSolids::XtruWrite().

00062 {
00063   return fNz;
00064 }

std::vector< G4TwoVector > G4ExtrudedSolid::GetPolygon (  )  const [inline]

Definition at line 55 of file G4ExtrudedSolid.icc.

00056 {
00057   return fPolygon;
00058 }  

G4TwoVector G4ExtrudedSolid::GetVertex ( G4int  index  )  const [inline]

Definition at line 43 of file G4ExtrudedSolid.icc.

References FatalException, and G4Exception().

Referenced by G4GDMLWriteSolids::XtruWrite().

00044 {
00045   if ( index<0 || index >= fNv )
00046   {
00047     G4Exception ("G4ExtrudedSolid::GetVertex()", "GeomSolids0003",
00048                  FatalException, "Index outside range.");
00049     return G4TwoVector();
00050   }
00051   return fPolygon[index];
00052 }  

G4ExtrudedSolid::ZSection G4ExtrudedSolid::GetZSection ( G4int  index  )  const [inline]

Definition at line 67 of file G4ExtrudedSolid.icc.

References FatalException, and G4Exception().

Referenced by G4GDMLWriteSolids::XtruWrite().

00068 {
00069   if ( index<0 || index >= fNz )
00070   {
00071     G4Exception ("G4ExtrudedSolid::GetZSection()", "GeomSolids0003",
00072                  FatalException, "Index outside range.");
00073     return ZSection(0.0, G4TwoVector(), 0.0);
00074   }
00075   return fZSections[index];
00076 }

std::vector< G4ExtrudedSolid::ZSection > G4ExtrudedSolid::GetZSections (  )  const [inline]

Definition at line 79 of file G4ExtrudedSolid.icc.

00080 {
00081   return fZSections;
00082 }  

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, and kSurface.

00761 {
00762   // Override the base class function  as it fails in case of concave polygon.
00763   // Project the point in the original polygon scale and check if it is inside
00764   // for each triangle.
00765 
00766   // Check first if outside extent
00767   //
00768   if ( p.x() < GetMinXExtent() - kCarTolerance * 0.5 ||
00769        p.x() > GetMaxXExtent() + kCarTolerance * 0.5 ||
00770        p.y() < GetMinYExtent() - kCarTolerance * 0.5 ||
00771        p.y() > GetMaxYExtent() + kCarTolerance * 0.5 ||
00772        p.z() < GetMinZExtent() - kCarTolerance * 0.5 ||
00773        p.z() > GetMaxZExtent() + kCarTolerance * 0.5 )
00774   {
00775     // G4cout << "G4ExtrudedSolid::Outside extent: " << p << G4endl;
00776     return kOutside;
00777   }  
00778 
00779   // Project point p(z) to the polygon scale p0
00780   //
00781   G4TwoVector pscaled = ProjectPoint(p);
00782   
00783   // Check if on surface of polygon
00784   //
00785   for ( G4int i=0; i<fNv; ++i )
00786   {
00787     G4int j = (i+1) % fNv;
00788     if ( IsSameLineSegment(pscaled, fPolygon[i], fPolygon[j]) )
00789     {
00790       // G4cout << "G4ExtrudedSolid::Inside return Surface (on polygon) "
00791       //        << G4endl;
00792 
00793       return kSurface;
00794     }  
00795   }   
00796 
00797   // Now check if inside triangles
00798   //
00799   std::vector< std::vector<G4int> >::const_iterator it = fTriangles.begin();
00800   G4bool inside = false;
00801   do
00802   {
00803     if ( IsPointInside(fPolygon[(*it)[0]], fPolygon[(*it)[1]],
00804                        fPolygon[(*it)[2]], pscaled) )  { inside = true; }
00805     ++it;
00806   } while ( (inside == false) && (it != fTriangles.end()) );
00807   
00808   if ( inside )
00809   {
00810     // Check if on surface of z sides
00811     //
00812     if ( std::fabs( p.z() - fZSections[0].fZ ) < kCarTolerance * 0.5 ||
00813          std::fabs( p.z() - fZSections[fNz-1].fZ ) < kCarTolerance * 0.5 )
00814     {
00815       // G4cout << "G4ExtrudedSolid::Inside return Surface (on z side)"
00816       //        << G4endl;
00817 
00818       return kSurface;
00819     }  
00820   
00821     // G4cout << "G4ExtrudedSolid::Inside return Inside" << G4endl;
00822 
00823     return kInside;
00824   }  
00825                             
00826   // G4cout << "G4ExtrudedSolid::Inside return Outside " << G4endl;
00827 
00828   return kOutside; 
00829 }  

G4ExtrudedSolid & G4ExtrudedSolid::operator= ( const G4ExtrudedSolid rhs  ) 

Definition at line 248 of file G4ExtrudedSolid.cc.

References fGeometryType, fIsConvex, fKOffsets, fKScales, fNv, fNz, fOffset0s, fPolygon, fScale0s, fTriangles, fZSections, and G4TessellatedSolid::operator=().

00249 {
00250    // Check assignment to self
00251    //
00252    if (this == &rhs)  { return *this; }
00253 
00254    // Copy base class data
00255    //
00256    G4TessellatedSolid::operator=(rhs);
00257 
00258    // Copy data
00259    //
00260    fNv = rhs.fNv; fNz = rhs.fNz;
00261    fPolygon = rhs.fPolygon; fZSections = rhs.fZSections;
00262    fTriangles = rhs.fTriangles; fIsConvex = rhs.fIsConvex;
00263    fGeometryType = rhs.fGeometryType; fKScales = rhs.fKScales;
00264    fScale0s = rhs.fScale0s; fKOffsets = rhs.fKOffsets;
00265    fOffset0s = rhs.fOffset0s;
00266 
00267    return *this;
00268 }

std::ostream & G4ExtrudedSolid::StreamInfo ( std::ostream &  os  )  const [virtual]

Reimplemented from G4TessellatedSolid.

Definition at line 861 of file G4ExtrudedSolid.cc.

References G4endl, and G4VSolid::GetName().

00862 {
00863   G4int oldprc = os.precision(16);
00864   os << "-----------------------------------------------------------\n"
00865      << "    *** Dump for solid - " << GetName() << " ***\n"
00866      << "    ===================================================\n"
00867      << " Solid geometry type: " << fGeometryType  << G4endl;
00868 
00869   if ( fIsConvex) 
00870     { os << " Convex polygon; list of vertices:" << G4endl; }
00871   else  
00872     { os << " Concave polygon; list of vertices:" << G4endl; }
00873   
00874   for ( G4int i=0; i<fNv; ++i )
00875   {
00876     os << std::setw(5) << "#" << i 
00877        << "   vx = " << fPolygon[i].x()/mm << " mm" 
00878        << "   vy = " << fPolygon[i].y()/mm << " mm" << G4endl;
00879   }
00880   
00881   os << " Sections:" << G4endl;
00882   for ( G4int iz=0; iz<fNz; ++iz ) 
00883   {
00884     os << "   z = "   << fZSections[iz].fZ/mm          << " mm  "
00885        << "  x0= "    << fZSections[iz].fOffset.x()/mm << " mm  "
00886        << "  y0= "    << fZSections[iz].fOffset.y()/mm << " mm  " 
00887        << "  scale= " << fZSections[iz].fScale << G4endl;
00888   }     
00889 
00890 /*
00891   // Triangles (for debugging)
00892   os << G4endl; 
00893   os << " Triangles:" << G4endl;
00894   os << " Triangle #   vertex1   vertex2   vertex3" << G4endl;
00895 
00896   G4int counter = 0;
00897   std::vector< std::vector<G4int> >::const_iterator it;
00898   for ( it = fTriangles.begin(); it != fTriangles.end(); it++ ) {
00899      std::vector<G4int> triangle = *it;
00900      os << std::setw(10) << counter++ 
00901         << std::setw(10) << triangle[0] << std::setw(10)  << triangle[1]  << std::setw(10)  << triangle[2] 
00902         << G4endl;
00903   }          
00904 */
00905   os.precision(oldprc);
00906 
00907   return os;
00908 }  


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:51:57 2013 for Geant4 by  doxygen 1.4.7