G4VSolid.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 G4VSolid
00031 //
00032 // Class description:
00033 //
00034 // Abstract base class for solids, physical shapes that can be tracked through.
00035 // Each solid has a name, and the constructors and destructors automatically
00036 // add and subtract them from the G4SolidStore, a singleton `master' List
00037 // of available solids.
00038 //
00039 // This class defines, but does not implement, functions to compute
00040 // distances to/from the shape. Functions are also defined
00041 // to check whether a point is inside the shape, to return the
00042 // surface normal of the shape at a given point, and to compute
00043 // the extent of the shape. [see descriptions below]
00044 //
00045 // Some protected/private utility functions are implemented for the 
00046 // clipping of regions for the computation of a solid's extent. Note that
00047 // the clipping mechanism is presently inefficient.
00048 // 
00049 // Some visualization/graphics functions are also defined.
00050 //
00051 // Member Data:
00052 //
00053 // G4String fshapeName
00054 //   - Name for this solid.
00055 
00056 // History:
00057 // 12.04.00 J.Allison     Implemented GetExtent() in terms of CalculateExtent()
00058 // 17.06.98 J.Apostolakis Added pure virtual function GetEntityType()
00059 // 26.07.96 P.Kent        Added ComputeDimensions for replication mechanism
00060 // 27.03.96 J.Allison     Methods for visualisation 
00061 // 30.06.95 P.Kent        Initial version, no scoping or visualisation functions
00062 // --------------------------------------------------------------------
00063 #ifndef G4VSOLID_HH
00064 #define G4VSOLID_HH
00065 
00066 #include "G4Types.hh"
00067 #include "G4String.hh"
00068 #include "geomdefs.hh"
00069 
00070 class G4AffineTransform;
00071 class G4VoxelLimits;
00072 
00073 class G4VPVParameterisation;
00074 class G4VPhysicalVolume;
00075 
00076 class G4VGraphicsScene;
00077 class G4Polyhedron;
00078 class G4NURBS;
00079 class G4VisExtent;
00080 class G4DisplacedSolid;
00081 
00082 #include "G4ThreeVector.hh"
00083 #include <vector>
00084 
00085 typedef std::vector<G4ThreeVector> G4ThreeVectorList;
00086 typedef G4String   G4GeometryType;
00087 
00088 class G4VSolid
00089 {
00090   public:  // with description 
00091 
00092     G4VSolid(const G4String& name);
00093       // Creates a new shape, with the supplied name. No provision is made
00094       // for sharing a common name amongst multiple classes.
00095     virtual ~G4VSolid();
00096       // Default destructor.
00097 
00098     inline G4bool operator==( const G4VSolid& s ) const;
00099       // Return true only if addresses are the same.
00100 
00101     friend std::ostream& operator<< ( std::ostream& os, const G4VSolid& e );
00102       // Streaming operator, using DumpInfo().
00103 
00104     inline G4String GetName() const;
00105       // Returns the current shape's name.
00106     inline void SetName(const G4String& name);
00107       // Sets the current shape's name.
00108 
00109     inline G4double GetTolerance() const;
00110       // Returns the cached geometrical tolerance.
00111 
00112     virtual G4bool CalculateExtent(const EAxis pAxis,
00113                                    const G4VoxelLimits& pVoxelLimit,
00114                                    const G4AffineTransform& pTransform,
00115                                    G4double& pMin, G4double& pMax) const = 0;
00116       // Calculate the minimum and maximum extent of the solid, when under the
00117       // specified transform, and within the specified limits. If the solid
00118       // is not intersected by the region, return false, else return true.
00119 
00120     virtual EInside Inside(const G4ThreeVector& p) const = 0;
00121       // Returns kOutside if the point at offset p is outside the shapes
00122       // boundaries plus Tolerance/2, kSurface if the point is <= Tolerance/2
00123       // from a surface, otherwise kInside.
00124 
00125     virtual G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const = 0;
00126       // Returns the outwards pointing unit normal of the shape for the
00127       // surface closest to the point at offset p.
00128 
00129     virtual G4double DistanceToIn(const G4ThreeVector& p,
00130                                   const G4ThreeVector& v) const = 0;
00131       // Return the distance along the normalised vector v to the shape,
00132       // from the point at offset p. If there is no intersection, return
00133       // kInfinity. The first intersection resulting from `leaving' a
00134       // surface/volume is discarded. Hence, it is tolerant of points on
00135       // the surface of the shape.
00136 
00137     virtual G4double DistanceToIn(const G4ThreeVector& p) const = 0;
00138       // Calculate the distance to the nearest surface of a shape from an
00139       // outside point. The distance can be an underestimate.
00140 
00141     virtual G4double DistanceToOut(const G4ThreeVector& p,
00142                                    const G4ThreeVector& v,
00143                                    const G4bool calcNorm=false,
00144                                    G4bool *validNorm=0,
00145                                    G4ThreeVector *n=0) const = 0;
00146       // Return the distance along the normalised vector v to the shape,
00147       // from a point at an offset p inside or on the surface of the shape.
00148       // Intersections with surfaces, when the point is < Tolerance/2 from a
00149       // surface must be ignored.
00150       // If calcNorm==true:
00151       //    validNorm set true if the solid lies entirely behind or on the
00152       //              exiting surface.
00153       //    n set to exiting outwards normal vector (undefined Magnitude).
00154       //    validNorm set to false if the solid does not lie entirely behind
00155       //              or on the exiting surface
00156       // If calcNorm==false:
00157       //    validNorm and n are unused.
00158       //
00159       // Must be called as solid.DistanceToOut(p,v) or by specifying all
00160       // the parameters.
00161 
00162     virtual G4double DistanceToOut(const G4ThreeVector& p) const = 0;
00163       // Calculate the distance to the nearest surface of a shape from an
00164       // inside point. The distance can be an underestimate.
00165 
00166 
00167     virtual void ComputeDimensions(G4VPVParameterisation* p,
00168                                    const G4int n,
00169                                    const G4VPhysicalVolume* pRep);
00170       // Throw exception if ComputeDimensions called frrom an illegal
00171       // derived class.
00172 
00173     virtual G4double GetCubicVolume();
00174       // Returns an estimation of the solid volume in internal units.
00175       // This method may be overloaded by derived classes to compute the
00176       // exact geometrical quantity for solids where this is possible,
00177       // or anyway to cache the computed value.
00178       // Note: the computed value is NOT cached.
00179 
00180     virtual G4double GetSurfaceArea();
00181       // Return an estimation of the solid surface area in internal units.
00182       // This method may be overloaded by derived classes to compute the
00183       // exact geometrical quantity for solids where this is possible,
00184       // or anyway to cache the computed value.
00185       // Note: the computed value is NOT cached.
00186 
00187     virtual G4GeometryType  GetEntityType() const = 0;
00188       // Provide identification of the class of an object.
00189       // (required for persistency and STEP interface)
00190 
00191     virtual G4ThreeVector GetPointOnSurface() const;
00192       // Returns a random point located on the surface of the solid.
00193       // Points returned are not necessarily uniformly distributed.
00194 
00195     virtual G4VSolid* Clone() const;
00196       // Returns a pointer of a dynamically allocated copy of the solid.
00197       // Returns NULL pointer with warning in case the concrete solid does not
00198       // implement this method. The caller has responsibility for ownership.
00199 
00200     virtual std::ostream& StreamInfo(std::ostream& os) const = 0;
00201       // Dumps contents of the solid to a stream.
00202     inline void DumpInfo() const;
00203       // Dumps contents of the solid to the standard output.
00204 
00205     // Visualization functions
00206 
00207     virtual void DescribeYourselfTo (G4VGraphicsScene& scene) const = 0;
00208       // A "double dispatch" function which identifies the solid
00209       // to the graphics scene.
00210     virtual G4VisExtent   GetExtent        () const;
00211       // Provide extent (bounding box) as possible hint to the graphics view.
00212     virtual G4Polyhedron* CreatePolyhedron () const;
00213     virtual G4NURBS*      CreateNURBS      () const;
00214       // Create a G4Polyhedron/G4NURBS/...  (It is the caller's responsibility
00215       // to delete it).  A null pointer means "not created".
00216     virtual G4Polyhedron* GetPolyhedron () const;
00217       // Smart access function - creates on request and stores for future
00218       // access.  A null pointer means "not available".
00219 
00220     virtual const G4VSolid* GetConstituentSolid(G4int no) const;
00221     virtual       G4VSolid* GetConstituentSolid(G4int no);
00222       // If the solid is made up from a Boolean operation of two solids,
00223       // return the "no" solid. If the solid is not a "Boolean", return 0.
00224 
00225     virtual const G4DisplacedSolid* GetDisplacedSolidPtr() const; 
00226     virtual       G4DisplacedSolid* GetDisplacedSolidPtr(); 
00227       // If the solid is a "G4DisplacedSolid", return a self pointer
00228       // else return 0.
00229 
00230   public:  // without description
00231 
00232     G4VSolid(__void__&);
00233       // Fake default constructor for usage restricted to direct object
00234       // persistency for clients requiring preallocation of memory for
00235       // persistifiable objects.
00236 
00237     G4VSolid(const G4VSolid& rhs);
00238     G4VSolid& operator=(const G4VSolid& rhs); 
00239       // Copy constructor and assignment operator.
00240 
00241   protected:  // with description
00242 
00243     void CalculateClippedPolygonExtent(G4ThreeVectorList& pPolygon,
00244                                        const G4VoxelLimits& pVoxelLimit,
00245                                        const EAxis pAxis, 
00246                                        G4double& pMin, G4double& pMax) const;
00247       // Calculate the maximum and minimum extents of the convex polygon
00248       // pPolygon along the axis pAxis, within the limits pVoxelLimit.
00249       //
00250       // If the minimum is <pMin pMin is set to the new minimum.
00251       // If the maximum is >pMax pMax is set to the new maximum.
00252       //
00253       // Modifications to pPolygon are made - it is left in an undefined state.
00254 
00255     void ClipCrossSection(G4ThreeVectorList* pVertices,
00256                           const G4int pSectionIndex,
00257                           const G4VoxelLimits& pVoxelLimit,
00258                           const EAxis pAxis, 
00259                           G4double& pMin, G4double& pMax) const;
00260       // Calculate the maximum and minimum extents of the polygon described
00261       // by the vertices: pSectionIndex->pSectionIndex+1->
00262       //                  pSectionIndex+2->pSectionIndex+3->pSectionIndex
00263       // in the List pVertices.
00264       //
00265       // If the minimum is <pMin pMin is set to the new minimum.
00266       // If the maximum is >pMax pMax is set to the new maximum.
00267       //
00268       // No modifications are made to pVertices.
00269 
00270     void ClipBetweenSections(G4ThreeVectorList* pVertices,
00271                              const G4int pSectionIndex,
00272                              const G4VoxelLimits& pVoxelLimit,
00273                              const EAxis pAxis, 
00274                              G4double& pMin, G4double& pMax) const;
00275       // Calculate the maximum and minimum extents of the polygons
00276       // joining the CrossSections at pSectionIndex->pSectionIndex+3 and
00277       //                              pSectionIndex+4->pSectionIndex7
00278       // in the List pVertices, within the boundaries of the voxel limits
00279       // pVoxelLimit.
00280       //
00281       // If the minimum is <pMin pMin is set to the new minimum.
00282       // If the maximum is >pMax pMax is set to the new maximum.
00283       //
00284       // No modifications are made to pVertices.
00285 
00286     void ClipPolygon(      G4ThreeVectorList& pPolygon,
00287                      const G4VoxelLimits& pVoxelLimit,
00288                      const EAxis              pAxis      ) const;
00289       // Clip the specified convex polygon to the given limits, where
00290       // the polygon is described by the vertices at (0),(1),...,(n),(0) in
00291       // pPolygon. 
00292       // If the polygon is completely clipped away, the polygon is cleared.
00293 
00294 
00295     G4double EstimateCubicVolume(G4int nStat, G4double epsilon) const;
00296       // Calculate cubic volume based on Inside() method.
00297       // Accuracy is limited by the second argument or the statistics
00298       // expressed by the first argument.
00299 
00300     G4double EstimateSurfaceArea(G4int nStat, G4double ell) const;
00301       // Calculate surface area only based on Inside() method.
00302       // Accuracy is limited by the second argument or the statistics
00303       // expressed by the first argument.
00304 
00305   protected:
00306 
00307     G4double kCarTolerance;      // Cached geometrical tolerance
00308 
00309   private:
00310 
00311     void ClipPolygonToSimpleLimits(G4ThreeVectorList& pPolygon,
00312                                    G4ThreeVectorList& outputPolygon,
00313                              const G4VoxelLimits&     pVoxelLimit   ) const;
00314       // Clip the specified convex polygon to the given limits, storing the
00315       // result in outputPolygon. The voxel limits must be limited in one
00316       // *plane* only: This is achieved by having only x or y or z limits,
00317       // and either the minimum or maximum limit set to -+kInfinity
00318       // respectively.
00319 
00320     G4String fshapeName;         // Name
00321 };
00322 
00323 #include "G4VSolid.icc"
00324 
00325 #endif

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