Geant4  10.01.p03
UGenericTrap.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * This Software is part of the AIDA Unified Solids Library package *
4 // * See: https://aidasoft.web.cern.ch/USolids *
5 // ********************************************************************
6 //
7 // $Id:$
8 //
9 // --------------------------------------------------------------------
10 //
11 // UGenericTrap
12 //
13 // Class description:
14 //
15 // UGenericTrap is a solid which represents an arbitrary trapezoid with
16 // up to 8 vertices standing on two parallel planes perpendicular to Z axis.
17 //
18 // Parameters in the constructor:
19 // - name - solid name
20 // - halfZ - the solid half length in Z
21 // - vertices - the (x,y) coordinates of vertices:
22 // o first four points: vertices[i], i<4
23 // are the vertices sitting on the -halfZ plane;
24 // o last four points: vertices[i], i>=4
25 // are the vertices sitting on the +halfZ plane.
26 //
27 // The order of defining the vertices of the solid is the following:
28 // - point 0 is connected with points 1,3,4
29 // - point 1 is connected with points 0,2,5
30 // - point 2 is connected with points 1,3,6
31 // - point 3 is connected with points 0,2,7
32 // - point 4 is connected with points 0,5,7
33 // - point 5 is connected with points 1,4,6
34 // - point 6 is connected with points 2,5,7
35 // - point 7 is connected with points 3,4,6
36 // Points can be identical in order to create shapes with less than
37 // 8 vertices.
38 //
39 // 21.10.13 Tatiana Nikitina, CERN; Ivana Hrivnacova, IPN Orsay
40 // Adapted from Root Arb8 implementation
41 // --------------------------------------------------------------------
42 
43 #ifndef USOLIDS_UGenericTrap_HH
44 #define USOLIDS_UGenericTrap_HH
45 
46 #ifndef USOLIDS_VUSolid
47 #include "VUSolid.hh"
48 #endif
49 
50 #ifndef USOLIDS_UUtils
51 #include "UUtils.hh"
52 #endif
53 
54 #include <vector>
55 
56 #include "UVector2.hh"
57 
58 class VUFacet;
59 class UTessellatedSolid;
60 class UBox;
61 
62 class UGenericTrap : public VUSolid
63 {
64  public: // with description
65 
66  UGenericTrap(const std::string& name, double halfZ,
67  const std::vector<UVector2>& vertices);
68  // Constructor
69 
70  ~UGenericTrap();
71  // Destructor
72 
73  // Accessors
74 
75  inline double GetZHalfLength() const;
76  inline void SetZHalfLength(double);
77  inline int GetNofVertices() const;
78  inline UVector2 GetVertex(int index) const;
79  inline const std::vector<UVector2>& GetVertices() const;
80  inline double GetTwistAngle(int index) const;
81  inline bool IsTwisted() const;
82  inline int GetVisSubdivisions() const;
83  inline void SetVisSubdivisions(int subdiv);
84 
85  // Solid methods
86 
87  EnumInside Inside(const UVector3& aPoint) const;
88  bool Normal(const UVector3& aPoint, UVector3& aNormal) const;
89  double SafetyFromInside(const UVector3& aPoint,
90  bool aAccurate = false) const;
91  double SafetyFromOutside(const UVector3& aPoint,
92  bool aAccurate = false) const;
93  double DistanceToIn(const UVector3& aPoint,
94  const UVector3& aDirection,
95  double aPstep = UUtils::kInfinity) const;
96 
97  double DistanceToOut(const UVector3& aPoint,
98  const UVector3& aDirection,
99  UVector3& aNormalVector,
100  bool& aConvex,
101  double aPstep = UUtils::kInfinity) const;
102  void Extent(UVector3& aMin, UVector3& aMax) const;
103  double Capacity() ;
104  double SurfaceArea() ;
105  VUSolid* Clone() const ;
106 
107  inline UGeometryType GetEntityType() const { return "GenericTrap"; }
108  inline void ComputeBBox(UBBox* /*aBox*/, bool /*aStore = false*/) {}
109  inline void GetParametersList(int /*aNumber*/, double* /*aArray*/) const {}
110 
111  UVector3 GetPointOnSurface() const;
112 
113  std::ostream& StreamInfo(std::ostream& os) const;
114 
115  public:
116 
117  UGenericTrap();
118  // Fake default constructor for usage restricted to direct object
119  // persistency for clients requiring preallocation of memory for
120  // persistifiable objects.
121 
122  UGenericTrap(const UGenericTrap& rhs);
123  UGenericTrap& operator=(const UGenericTrap& rhs);
124  // Copy constructor and assignment operator.
125 
126  void Initialise(const std::vector<UVector2>& vertices);
127  inline UVector3 GetMinimumBBox() const;
128  inline UVector3 GetMaximumBBox() const;
129 
130  private:
131 
132  // Internal methods
133 
134  inline void SetTwistAngle(int index, double twist);
135  bool ComputeIsTwisted() ;
136  bool CheckOrder(const std::vector<UVector2>& vertices) const;
137  bool IsSegCrossing(const UVector2& a, const UVector2& b,
138  const UVector2& c, const UVector2& d) const;
139  bool IsSegCrossingZ(const UVector2& a, const UVector2& b,
140  const UVector2& c, const UVector2& d) const;
141  bool IsSameLineSegment(const UVector2& p,
142  const UVector2& l1, const UVector2& l2) const;
143  bool IsSameLine(const UVector2& p,
144  const UVector2& l1, const UVector2& l2) const;
145 
146  void ReorderVertices(std::vector<UVector3>& vertices) const;
147  void ComputeBBox();
148 
149  VUFacet* MakeDownFacet(const std::vector<UVector3>& fromVertices,
150  int ind1, int ind2, int ind3) const;
151  VUFacet* MakeUpFacet(const std::vector<UVector3>& fromVertices,
152  int ind1, int ind2, int ind3) const;
153  VUFacet* MakeSideFacet(const UVector3& downVertex0,
154  const UVector3& downVertex1,
155  const UVector3& upVertex1,
156  const UVector3& upVertex0) const;
158 
160  const UVector2* poly)const;
161  double DistToPlane(const UVector3& p,
162  const UVector3& v, const int ipl) const ;
163  double DistToTriangle(const UVector3& p,
164  const UVector3& v, const int ipl) const;
166  const int ipl) const;
167  double SafetyToFace(const UVector3& p, const int iseg) const;
168  double GetFaceSurfaceArea(const UVector3& p0,
169  const UVector3& p1,
170  const UVector3& p2,
171  const UVector3& p3) const;
172  private:
173 
174  // static data members
175 
176  static const int fgkNofVertices;
177  static const double fgkTolerance;
178 
179  // data members
180 
181  double fDz;
182  std::vector<UVector2> fVertices;
184  double fTwist[4];
190 
192  // Codes for faces (kXY[num]=num of lateral face,kMZ= minus z face etc)
193 
194  double fSurfaceArea;
195  double fCubicVolume;
196  // Surface and Volume
197 };
198 
199 #include "UGenericTrap.icc"
200 
201 #endif
VUFacet * MakeDownFacet(const std::vector< UVector3 > &fromVertices, int ind1, int ind2, int ind3) const
void ComputeBBox(UBBox *, bool)
bool IsSameLineSegment(const UVector2 &p, const UVector2 &l1, const UVector2 &l2) const
UVector3 fMaxBBoxVector
double DistanceToOut(const UVector3 &aPoint, const UVector3 &aDirection, UVector3 &aNormalVector, bool &aConvex, double aPstep=UUtils::kInfinity) const
void SetZHalfLength(double)
UBox * fBoundBox
std::ostream & StreamInfo(std::ostream &os) const
double fTwist[4]
double fSurfaceArea
double SafetyFromInside(const UVector3 &aPoint, bool aAccurate=false) const
double Capacity()
UVector3 fMinBBoxVector
double DistToPlane(const UVector3 &p, const UVector3 &v, const int ipl) const
G4String name
Definition: TRTMaterials.hh:40
void SetVisSubdivisions(int subdiv)
void Extent(UVector3 &aMin, UVector3 &aMax) const
bool CheckOrder(const std::vector< UVector2 > &vertices) const
G4double a
Definition: TRTMaterials.hh:39
static const int fgkNofVertices
EnumInside InsidePolygone(const UVector3 &p, const UVector2 *poly) const
void SetTwistAngle(int index, double twist)
bool Normal(const UVector3 &aPoint, UVector3 &aNormal) const
Definition: UBox.hh:33
void Initialise(const std::vector< UVector2 > &vertices)
UTessellatedSolid * fTessellatedSolid
double DistToTriangle(const UVector3 &p, const UVector3 &v, const int ipl) const
double SurfaceArea()
double SafetyToFace(const UVector3 &p, const int iseg) const
UGenericTrap & operator=(const UGenericTrap &rhs)
int GetNofVertices() const
std::vector< UVector2 > fVertices
static const double kInfinity
Definition: UUtils.hh:54
double fCubicVolume
double SafetyFromOutside(const UVector3 &aPoint, bool aAccurate=false) const
int GetVisSubdivisions() const
bool IsTwisted() const
const G4double p2
void ReorderVertices(std::vector< UVector3 > &vertices) const
const G4double p1
bool IsSegCrossing(const UVector2 &a, const UVector2 &b, const UVector2 &c, const UVector2 &d) const
double DistanceToIn(const UVector3 &aPoint, const UVector3 &aDirection, double aPstep=UUtils::kInfinity) const
EnumInside
Definition: VUSolid.hh:23
UVector3 NormalToPlane(const UVector3 &p, const int ipl) const
VUFacet * MakeUpFacet(const std::vector< UVector3 > &fromVertices, int ind1, int ind2, int ind3) const
bool IsSameLine(const UVector2 &p, const UVector2 &l1, const UVector2 &l2) const
static const double fgkTolerance
const G4double p0
const std::vector< UVector2 > & GetVertices() const
UGeometryType GetEntityType() const
EnumInside Inside(const UVector3 &aPoint) const
UVector3 GetMaximumBBox() const
VUSolid * Clone() const
void GetParametersList(int, double *) const
double GetTwistAngle(int index) const
void ComputeBBox()
std::string UGeometryType
Definition: UTypes.hh:39
bool ComputeIsTwisted()
UTessellatedSolid * CreateTessellatedSolid() const
VUFacet * MakeSideFacet(const UVector3 &downVertex0, const UVector3 &downVertex1, const UVector3 &upVertex1, const UVector3 &upVertex0) const
UVector2 GetVertex(int index) const
double GetFaceSurfaceArea(const UVector3 &p0, const UVector3 &p1, const UVector3 &p2, const UVector3 &p3) const
UVector3 GetPointOnSurface() const
UVector3 GetMinimumBBox() const
bool IsSegCrossingZ(const UVector2 &a, const UVector2 &b, const UVector2 &c, const UVector2 &d) const
double GetZHalfLength() const