Geant4  10.00.p03
VUSolid.hh
Go to the documentation of this file.
1 #ifndef USOLIDS_VUSolid
2 #define USOLIDS_VUSolid
3 // "Universal" Solid Interface
5 // Authors: J. Apostolakis, G. Cosmo, M. Gayer, A. Gheata, A. Munnich, T. Nikitina (CERN)
6 //
7 // Created: 25 May 2011
8 //
10 
11 #include "UTypes.hh"
12 #include "UVector3.hh"
13 
14 #include "UUtils.hh"
15 
16 #define USOLIDS
17 #define USOLIDSONLY
18 
19 class VUSolid
20 {
21 public:
22 
23 enum EnumInside { eInside=0, eSurface=1, eOutside=2 };
24  // Use eInside < eSurface < eOutside: allows "max(,)" to combine Inside of surfaces
25  // Potentially replace eSurface with eInSurface, eOutSurface
26 
27 enum EAxisType { eXaxis=0, eYaxis=1, eZaxis=2};
28 
29 protected:
30 static double fgTolerance;
31 static double frTolerance;
32 static double faTolerance;
33 
34 // =>10 degrees/wedge for complete tube
35 
36 public:
37  VUSolid();
38  VUSolid(const std::string &name);
39  virtual ~VUSolid();
40 
41  // Accessors and modifiers for Tolerance
42  inline double GetCarTolerance() const;
43  inline double GetRadTolerance() const;
44  inline double GetAngTolerance() const;
45  void SetCarTolerance(double eps);
46  void SetRadTolerance(double eps);
47  void SetAngTolerance(double eps);
48 
49  // Navigation methods
50  virtual EnumInside Inside (const UVector3 &aPoint) const = 0;
51  //
52  // Evaluate if point is inside, outside or on the surface within the tolerance
53  virtual double SafetyFromInside ( const UVector3 &aPoint,
54  bool aAccurate=false) const = 0;
55  virtual double SafetyFromOutside( const UVector3 &aPoint,
56  bool aAccurate=false) const = 0;
57  //
58  // Estimates isotropic distance to the surface of the solid. This must
59  // be either accurate or an underestimate.
60  // Two modes: - default/fast mode, sacrificing accuracy for speed
61  // - "precise" mode, requests accurate value if available.
62  // For both modes, if at a large distance from solid ( > ? )
63  // it is expected that a simplified calculation will be made if available.
64 
65  virtual double DistanceToIn( const UVector3 &aPoint,
66  const UVector3 &aDirection,
67  double aPstep = UUtils::kInfinity) const = 0;
68  virtual double DistanceToOut( const UVector3 &aPoint,
69  const UVector3 &aDirection,
70  UVector3 &aNormalVector,
71  bool &aConvex,
72  double aPstep = UUtils::kInfinity) const = 0;
73  //
74  // o return the exact distance (double) from a surface, given a direction
75  // o compute the normal on the surface, returned as argument, calculated
76  // within the method to verify if it is close to the surface or not
77  // o for DistanceToOut(), normal-vector and convexity flag could be optional (to decide).
78  // If normal cannot be computed (or shape is not convex), set 'convex' to 'false'.
79  // o for DistanceToIn(), the normal-vector could be added as optional
80 
81  virtual bool Normal( const UVector3& aPoint, UVector3 &aNormal ) const = 0;
82  // Computes the normal on a surface and returns it as a unit vector
83  // In case a point is further than tolerance_normal from a surface, set validNormal=false
84  // Must return a valid vector. (even if the point is not on the surface.)
85  //
86  // On an edge or corner, provide an average normal of all facets within tolerance
87 
88  // Decision: provide or not the Boolean 'validNormal' argument for returning validity
89 
90  virtual void ExtentAxis(EAxisType aAxis, double &aMin, double &aMax) const;
91 
92  virtual void Extent( UVector3 &aMin, UVector3 &aMax ) const = 0;
93  // Return the minimum and maximum extent along all Cartesian axes
94  // For both the Extent methods
95  // o Expect mostly to use a GetBBox()/CalculateBBox() method internally to compute the extent
96  // o Decision: whether to store the computed BBox (containing or representing 6 double values),
97  // and whether to compute it at construction time.
98  // Methods are *not* const to allow caching of the Bounding Box
99  virtual UGeometryType GetEntityType() const = 0;
100  // Provide identification of the class of an object.
101  // (required for persistency and STEP interface)
102 
103  const std::string &GetName() const {return fName;}
104  void SetName(const std::string &aName) {fName = aName;}
105 
106  // Auxiliary methods
107  virtual double Capacity() = 0 ; // like CubicVolume()
108  virtual double SurfaceArea() = 0 ;
109  // Expect the solids to cache the values of Capacity and Surface Area
110 
111  // Sampling
112  virtual void SamplePointsInside(int /*aNpoints*/, UVector3 * /*aArray*/) const {}
113  virtual void SamplePointsOnSurface(int /*aNpoints*/, UVector3 * /*aArray*/) const {}
114  virtual void SamplePointsOnEdge(int /*aNpoints*/, UVector3 * /*aArray*/) const {}
115  // o generates points on the edges of a solid - primarily for testing purposes
116  // o for solids composed only of curved surfaces(like full spheres or toruses) or
117  // where an implementation is not available, it defaults to PointOnSurface.
118 
119  // Visualisation
120  virtual void GetParametersList(int aNumber,double *aArray) const =0;
121 
122  virtual VUSolid* Clone() const =0;
123  // o provide a new object which is a clone of the solid
124 
125  // Visualization
126 
127  static double Tolerance() {return fgTolerance;}
128 
129  inline virtual std::ostream& StreamInfo( std::ostream& os ) const = 0;
130 
131  virtual UVector3 GetPointOnSurface() const = 0;
132 
133  double EstimateCubicVolume(int nStat, double epsilon) const;
134  // Calculate cubic volume based on Inside() method.
135  // Accuracy is limited by the second argument or the statistics
136  // expressed by the first argument.
137 
138  double EstimateSurfaceArea(int nStat, double ell) const;
139  // Calculate surface area only based on Inside() method.
140  // Accuracy is limited by the second argument or the statistics
141  // expressed by the first argument.
142 
143 protected:
144  virtual void ComputeBBox(UBBox *aBox, bool aStore = false) = 0;
145  // o Compute the bounding box for the solid. Called automatically and stored ?
146  // o Can throw an exception if the solid is invalid
147 private:
148  std::string fName; // Name of the solid
149  //UBBox *fBBox; // Bounding box
150 };
151 inline double VUSolid::GetCarTolerance() const { return fgTolerance;}
152 inline double VUSolid::GetRadTolerance() const { return frTolerance;}
153 inline double VUSolid::GetAngTolerance() const { return faTolerance;}
154 
155 #endif
156 
virtual UVector3 GetPointOnSurface() const =0
VUSolid()
Definition: VUSolid.cc:18
virtual UGeometryType GetEntityType() const =0
void SetRadTolerance(double eps)
Definition: VUSolid.cc:338
static double frTolerance
Definition: VUSolid.hh:31
virtual double SurfaceArea()=0
Definition: VUSolid.cc:255
virtual void SamplePointsOnEdge(int, UVector3 *) const
Definition: VUSolid.hh:114
void SetCarTolerance(double eps)
Definition: VUSolid.cc:334
virtual ~VUSolid()
Definition: VUSolid.cc:32
const std::string & GetName() const
Definition: VUSolid.hh:103
static double fgTolerance
Definition: VUSolid.hh:30
G4String name
Definition: TRTMaterials.hh:40
void SetAngTolerance(double eps)
Definition: VUSolid.cc:342
double EstimateCubicVolume(int nStat, double epsilon) const
Definition: VUSolid.cc:214
virtual void ComputeBBox(UBBox *aBox, bool aStore=false)=0
static const G4double eps
virtual bool Normal(const UVector3 &aPoint, UVector3 &aNormal) const =0
virtual EnumInside Inside(const UVector3 &aPoint) const =0
double EstimateSurfaceArea(int nStat, double ell) const
Definition: VUSolid.cc:268
static double Tolerance()
Definition: VUSolid.hh:127
virtual std::ostream & StreamInfo(std::ostream &os) const =0
static const double kInfinity
Definition: UUtils.hh:53
std::string fName
Definition: VUSolid.hh:148
virtual double DistanceToIn(const UVector3 &aPoint, const UVector3 &aDirection, double aPstep=UUtils::kInfinity) const =0
void SetName(const std::string &aName)
Definition: VUSolid.hh:104
static double faTolerance
Definition: VUSolid.hh:32
EAxisType
Definition: VUSolid.hh:27
EnumInside
Definition: VUSolid.hh:23
virtual void SamplePointsInside(int, UVector3 *) const
Definition: VUSolid.hh:112
virtual double SafetyFromInside(const UVector3 &aPoint, bool aAccurate=false) const =0
double GetRadTolerance() const
Definition: VUSolid.hh:152
virtual void ExtentAxis(EAxisType aAxis, double &aMin, double &aMax) const
Definition: VUSolid.cc:318
virtual double SafetyFromOutside(const UVector3 &aPoint, bool aAccurate=false) const =0
double GetCarTolerance() const
Definition: VUSolid.hh:151
virtual void SamplePointsOnSurface(int, UVector3 *) const
Definition: VUSolid.hh:113
std::string UGeometryType
Definition: UTypes.hh:39
virtual double DistanceToOut(const UVector3 &aPoint, const UVector3 &aDirection, UVector3 &aNormalVector, bool &aConvex, double aPstep=UUtils::kInfinity) const =0
virtual void Extent(UVector3 &aMin, UVector3 &aMax) const =0
virtual VUSolid * Clone() const =0
virtual double Capacity()=0
Definition: VUSolid.cc:199
virtual void GetParametersList(int aNumber, double *aArray) const =0
double GetAngTolerance() const
Definition: VUSolid.hh:153