G4BREPSolid.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // ----------------------------------------------------------------------
00030 // Class G4BREPSolid
00031 //
00032 // Class description:
00033 //
00034 // Base class for generic Boundary REPresentation solid.
00035 
00036 // Authors: J.Sulkimo, P.Urban.
00037 // Revisions by: L.Broglia, G.Cosmo.
00038 // ----------------------------------------------------------------------
00039 #ifndef __SOLID_H
00040 #define __SOLID_H
00041 
00042 #include "G4VSolid.hh"        
00043 #include "G4Surface.hh"
00044 #include "G4Axis2Placement3D.hh"
00045 #include "G4PointRat.hh"         
00046 #include "G4BoundingBox3D.hh"    
00047 
00048 class G4Ray;
00049 
00050 class G4BREPSolid : public G4VSolid
00051 {
00052 
00053 public: // with description
00054 
00055   G4BREPSolid(const G4String& name);
00056   G4BREPSolid(const G4String&, G4Surface**, G4int);
00057   virtual ~G4BREPSolid();
00058     // Constructors & destructor
00059 
00060   virtual void Initialize();
00061     // Calculates the bounding box for solids and surfaces.
00062     // Converts concave planes to convex.
00063 
00064   G4bool CalculateExtent(const EAxis              pAxis      ,
00065                          const G4VoxelLimits&     pVoxelLimit,
00066                          const G4AffineTransform& pTransform ,
00067                          G4double&                pMin       , 
00068                          G4double&                pMax        ) const;
00069     // Calculate the minimum and maximum extent of the solid, when under the
00070     // specified transform, and within the specified limits. If the solid
00071     // is not intersected by the region, return false, else return true.
00072 
00073   virtual EInside Inside(register const G4ThreeVector& Pt) const;
00074     // Determines if the point Pt is inside, outside or on the surface
00075     // of the solid.
00076 
00077   virtual G4ThreeVector SurfaceNormal(const G4ThreeVector&) const;
00078     // Calculates the normal of the surface at a point on the surface
00079     // The sense of the normal depends on the sense of the surface.
00080 
00081   virtual G4double DistanceToIn(const G4ThreeVector&) const;
00082     // Calculates the shortest distance ("safety") from a point
00083     // outside the solid to any boundary of this solid.
00084     // Return 0 if the point is already inside.
00085 
00086   virtual G4double DistanceToIn(register const G4ThreeVector& Pt,
00087                                 register const G4ThreeVector& V) const;
00088     // Calculates the distance from a point Pt outside the solid
00089     // to the solid's boundary along a specified direction vector V.
00090     // Note: Intersections with boundaries less than the tolerance must
00091     //       be ignored if the direction is away from the boundary.
00092 
00093   virtual G4double DistanceToOut(const G4ThreeVector&) const;
00094     // Calculates the shortest distance ("safety") from a point inside the
00095     // solid to any boundary of this solid.
00096     // Return 0 if the point is already outside.        
00097 
00098   virtual G4double DistanceToOut(register const G4ThreeVector& Pt,
00099                                  register const G4ThreeVector& V,
00100                                  const G4bool  calcNorm=false , 
00101                                  G4bool        *validNorm=0   , 
00102                                  G4ThreeVector *n=0             ) const;
00103     // Calculates the distance from a point inside the solid to the solid`s
00104     // boundary along a specified direction vector.
00105     // Return 0 if the point is already outside.
00106     // Note: If the shortest distance to a boundary is less than the
00107     //       tolerance, it is ignored. This allows for a point within a
00108     //       tolerant boundary to leave immediately.
00109 
00110   G4Point3D Scope() const;
00111     // Utility function to determine the maximum scope of the solid
00112     // in the coordinates X, Y, Z. Returned as a G4Point3D.
00113 
00114   virtual G4String GetEntityType() const;
00115     // Returns identifier for solid type entity.
00116     // A generic BREP solid is considered a "Closed_Shell".
00117 
00118   virtual G4VSolid* Clone() const;
00119     // Returns a pointer of a dynamically allocated copy of the solid.
00120     // The caller has responsibility for ownership.
00121 
00122   virtual std::ostream& StreamInfo(std::ostream& os) const;
00123     // Streams solid contents to output stream.
00124 
00125   void DescribeYourselfTo (G4VGraphicsScene& scene) const;
00126     // Dispatch function which identifies the solid to the graphics scene.
00127 
00128   G4Polyhedron* CreatePolyhedron () const;
00129   G4NURBS*      CreateNURBS      () const;
00130     // Create a G4Polyhedron/G4NURBS/...  (It is the caller's responsibility
00131     // to delete it).  A null pointer means "not created".
00132   virtual G4Polyhedron* GetPolyhedron () const;
00133     // Smart access function - creates on request and stores for future
00134     // access.  A null pointer means "not available".
00135 
00136   G4int Intersect(register const G4Ray&) const;
00137     // Gets the roughly calculated closest intersection point for
00138     // a b_spline and the accurate point for others.
00139 
00140   inline G4Surface* GetSurface(G4int) const;
00141   inline void Active(G4int) const;  
00142   inline G4int Active() const;
00143   inline G4double GetShortestDistance() const;
00144   inline G4int GetId() const;
00145   inline void SetId(G4int);
00146   inline const G4String& GetName() const;
00147   inline void SetName(const G4String& name);
00148   inline G4int GetNumberOfFaces() const;
00149   inline G4int GetNumberOfSolids() const;
00150   inline const G4Axis2Placement3D* GetPlace() const;
00151   inline const G4BoundingBox3D*    GetBBox()  const;
00152     // Accessors methods.
00153 
00154   inline G4int GetCubVolStatistics() const;
00155   inline G4double GetCubVolEpsilon() const;
00156   inline void SetCubVolStatistics(G4int st);
00157   inline void SetCubVolEpsilon(G4double ep);
00158   inline G4int GetAreaStatistics() const;
00159   inline G4double GetAreaAccuracy() const;
00160   inline void SetAreaStatistics(G4int st);
00161   inline void SetAreaAccuracy(G4double ep);
00162     // Accessors methods.
00163 
00164 public:
00165 
00166   inline G4double GetCubicVolume();
00167     // Returns an estimation of the geometrical cubic volume of the
00168     // solid. Caches the computed value once computed the first time.
00169   inline G4double GetSurfaceArea();
00170     // Returns an estimation of the geometrical surface area of the
00171     // solid. Caches the computed value once computed the first time.
00172 
00173   inline G4double IntersectionDistance() const;
00174   inline void IntersectionDistance(G4double) const;
00175     // Gets and sets intersection distance.
00176 
00177   virtual void Reset() const;
00178     // Resets all distance attributes.
00179 
00180 public:  // without description
00181 
00182   G4BREPSolid(__void__&);
00183     // Fake default constructor for usage restricted to direct object
00184     // persistency for clients requiring preallocation of memory for
00185     // persistifiable objects.
00186 
00187   G4BREPSolid(const G4BREPSolid& rhs);
00188   G4BREPSolid& operator=(const G4BREPSolid& rhs); 
00189     // Copy constructor and assignment operator.
00190 
00191 protected:
00192  
00193   G4ThreeVectorList* CreateRotatedVertices(const G4AffineTransform&) const;
00194   G4bool  IsConvex();
00195 
00196   virtual void CalcBBoxes();
00197     // Calculates the bounding boxes for the surfaces and for the solid.
00198 
00199   void    CheckSurfaceNormals();
00200   void    RemoveHiddenFaces(register const G4Ray& G4Rayref, G4int) const;   
00201     // Deactivates the planar faces that are on the "back" side of a solid.
00202     // B-splines are not handled by this function. Also cases where the ray
00203     // starting point is Inside the bbox of the solid are ignored as we don't
00204     // know if the starting point is Inside the actual solid except for
00205     // axis-oriented box-like solids.
00206 
00207   void    TestSurfaceBBoxes(register const G4Ray&) const;
00208     // Tests the bounding-box to all surfaces in List.
00209     // For planar faces the intersection is instead evaluated.
00210 
00211   inline G4int StartInside() const;  
00212   inline void StartInside(G4int si) const;
00213 
00214   inline void QuickSort( register G4Surface** SrfVec, 
00215                          register G4int left, register G4int right) const;
00216 
00217 protected:
00218 
00219   static G4int        NumberOfSolids;
00220   static G4Ray        Track;
00221   static G4double     ShortestDistance;
00222 
00223   G4int               Box, Convex, AxisBox, PlaneSolid;
00224   G4Axis2Placement3D* place;
00225   G4BoundingBox3D*    bbox;   
00226   G4double            intersectionDistance;
00227   G4int               active;
00228   G4int               startInside;
00229   G4int               nb_of_surfaces;
00230   G4Point3D           intersection_point;
00231   G4Surface**         SurfaceVec;
00232   G4double            RealDist;
00233   G4String            solidname; 
00234   G4int               Id;
00235    
00236 
00237 private:
00238 
00239   G4int IsBox();
00240   G4int FinalEvaluation(register const G4Ray&, G4int =0) const;
00241 
00242 private:
00243 
00244   G4int    fStatistics;
00245   G4double fCubVolEpsilon;
00246   G4double fAreaAccuracy;
00247   G4double fCubicVolume;
00248   G4double fSurfaceArea;
00249     // Statistics, error accuracy and cached value for volume and area.
00250 
00251   mutable G4Polyhedron* fpPolyhedron;
00252 
00253 };
00254 
00255 #include "G4BREPSolid.icc"
00256 
00257 #endif

Generated on Mon May 27 17:47:47 2013 for Geant4 by  doxygen 1.4.7