G4FPlane Class Reference

#include <G4FPlane.hh>

Inheritance diagram for G4FPlane:

G4Surface G4STEPEntity

Public Member Functions

 G4FPlane ()
virtual ~G4FPlane ()
 G4FPlane (const G4Vector3D &direction, const G4Vector3D &axis, const G4Point3D &Pt0, G4int sense=1)
 G4FPlane (const G4Point3DVector *pVec, const G4Point3DVector *iVec=0, G4int sense=1)
G4int Intersect (const G4Ray &G4Rayref)
void CalcBBox ()
void Project ()
G4int GetConvex () const
G4int GetNumberOfPoints () const
G4Point3D GetSrfPoint () const
const G4Point3D & GetPoint (G4int Count) const
void CalcNormal ()
G4Vector3D SurfaceNormal (const G4Point3D &Pt) const
const char * Name () const
G4double ClosestDistanceToPoint (const G4Point3D &Pt)
G4double HowNear (const G4Vector3D &x) const
G4Axis2Placement3D GetPplace () const
G4Plane GetPplane () const
G4int MyType () const
G4int IsConvex () const
void Deactivate ()
G4Ray * Norm ()
const G4Point3D & GetHitPoint () const

Protected Member Functions

void InitBounded ()

Protected Attributes

G4Point3D hitpoint

Detailed Description

Definition at line 67 of file G4FPlane.hh.


Constructor & Destructor Documentation

G4FPlane::G4FPlane (  ) 

G4FPlane::~G4FPlane (  )  [virtual]

Definition at line 124 of file G4FPlane.cc.

00125 {
00126   delete NormalX;
00127 }

G4FPlane::G4FPlane ( const G4Vector3D &  direction,
const G4Vector3D &  axis,
const G4Point3D &  Pt0,
G4int  sense = 1 
)

Definition at line 49 of file G4FPlane.cc.

References G4Surface::active, CalcNormal(), G4Ray::CalcPlane3Pts(), G4Surface::distance, G4Surface::sameSense, and G4Surface::Type.

00052   : pplace(direction, axis, Pt0), Convex(0), projectedBoundary(0)
00053 {
00054   G4Point3D Pt1 = G4Point3D( Pt0 + direction );
00055 
00056   // The plane include direction and axis is the normal,
00057   // so axis^direction is included in the plane
00058   G4Point3D Pt2 = G4Point3D( Pt0 + axis.cross(direction) );
00059 
00060   G4Ray::CalcPlane3Pts( Pl, Pt0, Pt1, Pt2 );
00061 
00062   active   = 1;
00063   sameSense = sense;
00064   CalcNormal();
00065   distance = kInfinity;
00066   Type     = 1;
00067 }

G4FPlane::G4FPlane ( const G4Point3DVector *  pVec,
const G4Point3DVector *  iVec = 0,
G4int  sense = 1 
)

Definition at line 70 of file G4FPlane.cc.

References CalcNormal(), G4Ray::CalcPlane3Pts(), G4Surface::distance, G4CompositeCurve::GetSegments(), IsConvex(), G4Surface::sameSense, G4Surface::SetBoundaries(), G4Surface::SetSameSense(), and G4Surface::Type.

00073   : pplace( (*pVec)[0]-(*pVec)[1],                    // direction
00074             ((*pVec)[pVec->size()-1]-(*pVec)[0])
00075             .cross((*pVec)[0]-(*pVec)[1]),            // axis
00076             (*pVec)[0]                             )  // location
00077 
00078 {
00079   G4Ray::CalcPlane3Pts( Pl, (*pVec)[0], (*pVec)[1], (*pVec)[2] );
00080  
00081   G4CurveVector bounds;
00082   G4CompositeCurve* polygon;
00083 
00084   projectedBoundary = new G4SurfaceBoundary;
00085 
00086   sameSense = sense;
00087 
00088   // Outer boundary
00089 
00090   polygon= new G4CompositeCurve(*pVec);
00091  
00092   for (size_t i=0; i< polygon->GetSegments().size(); i++) 
00093     polygon->GetSegments()[i]->SetSameSense(sameSense);
00094 
00095   bounds.push_back(polygon);
00096   
00097   // Eventual inner boundary
00098   
00099   if (iVec) 
00100   {
00101     polygon= new G4CompositeCurve(*iVec);
00102 
00103     for (size_t i=0; i< polygon->GetSegments().size(); i++) 
00104     polygon->GetSegments()[i]->SetSameSense(sameSense);
00105 
00106     bounds.push_back(polygon);
00107   }
00108   
00109   // Set sense for boundaries  
00110   
00111   for (size_t j=0; j< bounds.size(); j++) 
00112     bounds[j]->SetSameSense(sameSense);
00113   
00114 
00115   SetBoundaries(&bounds);
00116       
00117   CalcNormal();
00118   IsConvex();
00119   distance = kInfinity;
00120   Type=1;
00121 }


Member Function Documentation

void G4FPlane::CalcBBox (  )  [virtual]

Reimplemented from G4Surface.

Definition at line 130 of file G4FPlane.cc.

References G4SurfaceBoundary::BBox(), G4Surface::bbox, G4BoundingBox3D::GetBoxMax(), G4BoundingBox3D::GetBoxMin(), and G4Surface::surfaceBoundary.

00131 {
00132   // This is needed since the bounds are used for the Solid
00133   // bbox calculation. The bbox test is NOT performed for
00134   // planar surfaces.
00135 
00136   // Finds the bounds of the G4Plane surface iow
00137   // calculates the bounds for a bounding box
00138   // to the surface. The bounding box is used
00139   // for a preliminary check of intersection.
00140   
00141   bbox= new G4BoundingBox3D(surfaceBoundary.BBox().GetBoxMin(), 
00142                             surfaceBoundary.BBox().GetBoxMax());
00143 
00144 }

void G4FPlane::CalcNormal (  )  [virtual]

Reimplemented from G4Surface.

Definition at line 147 of file G4FPlane.cc.

References G4Ray::CreatePlanes(), G4Axis2Placement3D::GetAxis(), G4Axis2Placement3D::GetLocation(), G4Surface::GetSameSense(), and G4Ray::RayCheck().

Referenced by G4FPlane().

00148 {
00149 /* 
00150   // Calc Normal for surface which is used for the projection
00151   // Make planes
00152   G4Vector3D norm;
00153 
00154   G4Vector3D RefDirection = pplace.GetRefDirection();
00155   G4Vector3D Axis = pplace.GetAxis();
00156 
00157   // L. Broglia : before in G4Placement
00158   if( RefDirection == Axis )
00159     norm = RefDirection;
00160   else
00161   {
00162     // L. Broglia : error on setY, and it`s better to use cross function
00163     // norm.setX( RefDirection.y() * Axis.z() -  RefDirection.z() * Axis.y() );
00164     // norm.setY( RefDirection.x() * Axis.z() -  RefDirection.z() * Axis.x() );
00165     // norm.setZ( RefDirection.x() * Axis.y() -  RefDirection.y() * Axis.x() );
00166        
00167     norm = RefDirection.cross(Axis);
00168   }
00169   
00170   //  const G4Point3D& tmp = pplace.GetSrfPoint();
00171   const G4Point3D tmp = pplace.GetLocation();
00172 */  
00173 
00174   // L. Broglia
00175   // The direction of the normal is the axis of his location
00176   // Its sense depend on the orientation of the bounded curve
00177   const G4Point3D tmp = pplace.GetLocation();
00178   G4Vector3D norm;
00179   G4int sense = GetSameSense();
00180   
00181   if (sense)
00182     norm = pplace.GetAxis();
00183   else
00184     norm = - pplace.GetAxis();
00185 
00186   NormalX =  new G4Ray(tmp, norm);
00187   NormalX->RayCheck();
00188   NormalX->CreatePlanes();
00189 }

G4double G4FPlane::ClosestDistanceToPoint ( const G4Point3D &  Pt  )  [virtual]

Reimplemented from G4Surface.

Definition at line 341 of file G4FPlane.cc.

References G4Plane::a, G4Plane::b, G4Plane::c, and G4Plane::d.

00342 {
00343   // Calculates signed distance of point Pt to G4Plane Pl
00344   // Be careful, the equation of the plane is :
00345   // ax + by + cz = d
00346   G4double dist = Pt.x()*Pl.a + Pt.y()*Pl.b + Pt.z()*Pl.c - Pl.d;
00347 
00348   return dist;
00349 }

void G4FPlane::Deactivate (  )  [inline]

Reimplemented from G4Surface.

Definition at line 44 of file G4FPlane.icc.

References G4Surface::active.

00045 {
00046   active=0;
00047 }

G4int G4FPlane::GetConvex (  )  const [inline, virtual]

Reimplemented from G4Surface.

Definition at line 38 of file G4FPlane.icc.

00039 {
00040   return Convex;
00041 }

const G4Point3D & G4FPlane::GetHitPoint (  )  const [inline]

Definition at line 68 of file G4FPlane.icc.

References hitpoint.

00069 {
00070   return hitpoint;
00071 }

G4int G4FPlane::GetNumberOfPoints (  )  const [inline, virtual]

Reimplemented from G4Surface.

Definition at line 50 of file G4FPlane.icc.

References G4SurfaceBoundary::GetNumberOfPoints(), and G4Surface::surfaceBoundary.

00051 {
00052   return (surfaceBoundary.GetNumberOfPoints());
00053 }

const G4Point3D & G4FPlane::GetPoint ( G4int  Count  )  const [inline, virtual]

Reimplemented from G4Surface.

Definition at line 62 of file G4FPlane.icc.

References G4SurfaceBoundary::GetPoint(), and G4Surface::surfaceBoundary.

00063 {
00064   return surfaceBoundary.GetPoint(Count);
00065 }  

G4Axis2Placement3D G4FPlane::GetPplace (  )  const [inline]

Definition at line 92 of file G4FPlane.icc.

00093 {
00094   return  pplace;
00095 }

G4Plane G4FPlane::GetPplane (  )  const [inline]

Definition at line 98 of file G4FPlane.icc.

00099 {
00100   return  Pl;
00101 }

G4Point3D G4FPlane::GetSrfPoint (  )  const [inline]

Definition at line 56 of file G4FPlane.icc.

References G4Axis2Placement3D::GetLocation().

Referenced by G4BREPSolidPolyhedra::SurfaceNormal().

00057 {
00058   return pplace.GetLocation();
00059 }

G4double G4FPlane::HowNear ( const G4Vector3D &  x  )  const [virtual]

Reimplemented from G4Surface.

Definition at line 360 of file G4FPlane.cc.

References G4Plane::a, G4Plane::b, G4Plane::c, and G4Plane::d.

00361 {
00362   G4double hownear = Pt.x()*Pl.a + Pt.y()*Pl.b + Pt.z()*Pl.c - Pl.d;
00363 
00364   return hownear;
00365 }

void G4FPlane::InitBounded (  )  [protected, virtual]

Reimplemented from G4Surface.

Definition at line 352 of file G4FPlane.cc.

References G4Axis2Placement3D::GetToPlacementCoordinates(), G4SurfaceBoundary::Project(), and G4Surface::surfaceBoundary.

00353 {
00354   // L. Broglia
00355 
00356   projectedBoundary =
00357     surfaceBoundary.Project( pplace.GetToPlacementCoordinates() );
00358 }

G4int G4FPlane::Intersect ( const G4Ray &  G4Rayref  )  [virtual]

Reimplemented from G4Surface.

Definition at line 210 of file G4FPlane.cc.

References G4Surface::active, G4Surface::closest_hit, G4Surface::distance, G4Ray::GetDir(), G4Axis2Placement3D::GetLocation(), G4Ray::GetStart(), G4Axis2Placement3D::GetToPlacementCoordinates(), hitpoint, G4Surface::Intersected, G4SurfaceBoundary::IntersectRay2D(), G4Surface::kCarTolerance, PINFINITY(), and G4Surface::SetDistance().

00211 {
00212   // This function count the number of intersections of a 
00213   // bounded surface by a ray.
00214   
00215 
00216   // Find the intersection with the infinite plane
00217   Intersected =1;
00218 
00219   // s is solution, line is p + tq, n is G4Plane Normal, r is point on G4Plane 
00220   // all parameters are pointers to arrays of three elements
00221  
00222   hitpoint = PINFINITY;
00223   register G4double a, b, t;
00224 
00225   register const G4Vector3D& RayDir   = rayref.GetDir();
00226   register const G4Point3D&  RayStart = rayref.GetStart();
00227 
00228   G4double dirx =  RayDir.x();
00229   G4double diry =  RayDir.y();
00230   G4double dirz =  RayDir.z();
00231 
00232   G4Vector3D norm = (*NormalX).GetDir();
00233   G4Point3D  srf_point = pplace.GetLocation();
00234 
00235   b = norm.x() * dirx + norm.y() * diry + norm.z() * dirz;
00236 
00237   if ( std::fabs(b) < perMillion )    
00238   {
00239     // G4cout << "\nLine is parallel to G4Plane.No Hit.";
00240   }  
00241   else
00242   {
00243     G4double startx =  RayStart.x();
00244     G4double starty =  RayStart.y();
00245     G4double startz =  RayStart.z();    
00246     
00247     a = norm.x() * (srf_point.x() - startx) + 
00248         norm.y() * (srf_point.y() - starty) + 
00249         norm.z() * (srf_point.z() - startz)   ;
00250     
00251     t = a/b;
00252     
00253     // substitute t into line equation
00254     // to calculate final solution     
00255     G4double solx,soly,solz;
00256     solx = startx + t * dirx;
00257     soly = starty + t * diry;
00258     solz = startz + t * dirz;
00259 
00260     // solve tolerance problem
00261     if( (t*dirx >= -kCarTolerance/2) && (t*dirx <= kCarTolerance/2) )
00262       solx = startx;
00263 
00264     if( (t*diry >= -kCarTolerance/2) && (t*diry <= kCarTolerance/2) )
00265       soly = starty;
00266 
00267     if( (t*dirz >= -kCarTolerance/2) && (t*dirz <= kCarTolerance/2) )
00268       solz = startz;
00269     
00270     G4bool xhit = (dirx < 0 && solx <= startx) || (dirx >= 0 && solx >= startx);
00271     G4bool yhit = (diry < 0 && soly <= starty) || (diry >= 0 && soly >= starty);
00272     G4bool zhit = (dirz < 0 && solz <= startz) || (dirz >= 0 && solz >= startz);
00273     
00274     if( xhit && yhit && zhit ) {
00275       hitpoint= G4Point3D(solx, soly, solz);
00276     }
00277   }
00278    
00279   // closest_hit is a public Point3D in G4Surface
00280   closest_hit = hitpoint;
00281   
00282   if(closest_hit.x() == kInfinity)
00283   {
00284     // no hit
00285     active=0;
00286     SetDistance(kInfinity);
00287     return 0;
00288   }
00289   else
00290   {
00291     // calculate the squared distance from the point to the intersection
00292     // and set it in the distance data member (all clients know they have
00293     // to take the sqrt)
00294     SetDistance( RayStart.distance2(closest_hit) );   
00295 
00296     // now, we have to verify that the hit point founded
00297     // is included into the G4FPlane boundaries
00298 
00299     // project the hit to the xy plane,
00300     // with the same projection that took the boundary
00301     // into projectedBoundary
00302     G4Point3D projectedHit= pplace.GetToPlacementCoordinates() * closest_hit;
00303     
00304     // test ray from the hit on the xy plane
00305     G4Ray testRay( projectedHit, G4Vector3D(1, 0.01, 0) );
00306 
00307     // check if it intersects the boundary
00308     G4int nbinter = projectedBoundary->IntersectRay2D(testRay);
00309 
00310     // If this number is par, it`s signify that the projected point  
00311     // is outside the projected surface, so the hit point is outside
00312     // the bounded surface
00313     if(nbinter&1)
00314     {
00315       // the intersection point is into the boundaries
00316       // check if the intersection point is on the surface
00317       if(distance <= kCarTolerance*0.5*kCarTolerance*0.5)
00318       {
00319         // the point is on the surface, set the distance to 0            
00320         SetDistance(0);         
00321       }
00322       else
00323       {
00324         // the point is outside the surface
00325       }
00326       
00327       return 1 ;      
00328     }
00329     else
00330     {
00331       // the intersection point is out the boundaries
00332       // it is not a real intersection
00333       active=0;
00334       SetDistance(kInfinity);
00335       return 0;
00336     }
00337   }
00338 }

G4int G4FPlane::IsConvex (  )  const [virtual]

Reimplemented from G4Surface.

Definition at line 204 of file G4FPlane.cc.

Referenced by G4FPlane().

00205 {
00206   return -1;  
00207 }

G4int G4FPlane::MyType (  )  const [inline, virtual]

Reimplemented from G4Surface.

Definition at line 104 of file G4FPlane.icc.

00105 {
00106   return 1;
00107 }

const char * G4FPlane::Name (  )  const [inline, virtual]

Reimplemented from G4Surface.

Definition at line 86 of file G4FPlane.icc.

00087 {
00088   return "G4FPlane";
00089 }

G4Ray * G4FPlane::Norm (  )  [inline, virtual]

Reimplemented from G4Surface.

Definition at line 74 of file G4FPlane.icc.

00075 {
00076   return NormalX;
00077 }

void G4FPlane::Project (  )  [virtual]

Reimplemented from G4Surface.

Definition at line 192 of file G4FPlane.cc.

00193 {
00194     // Project
00195     // const G4Plane& Plane1 = NormalX->GetPlane(1);
00196     // const G4Plane& Plane2 = NormalX->GetPlane(2);
00197 
00198     // probably not necessary
00199     // projections of the boundary should be handled by the intersection
00200     //    OuterBoundary->ProjectBoundaryTo2D(Plane1, Plane2, 0);
00201 }

G4Vector3D G4FPlane::SurfaceNormal ( const G4Point3D &  Pt  )  const [inline, virtual]

Implements G4Surface.

Definition at line 80 of file G4FPlane.icc.

References G4Ray::GetDir().

Referenced by G4BREPSolidPolyhedra::SurfaceNormal().

00081 {
00082   return NormalX->GetDir();
00083 }


Field Documentation

G4Point3D G4FPlane::hitpoint [protected]

Definition at line 151 of file G4FPlane.hh.

Referenced by GetHitPoint(), and Intersect().


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