Geant4  10.01.p01
UExtrudedSolid.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 // UExtrudedSolid
12 //
13 // Class description:
14 //
15 // UExtrudedSolid is a solid which represents the extrusion of an arbitrary
16 // polygon with fixed outline in the defined Z sections.
17 // The z-sides of the solid are the scaled versions of the same polygon.
18 // The solid is implemented as a specification of UTessellatedSolid.
19 //
20 // Parameters in the constructor:
21 // const std::tring& pName - solid name
22 // std::vector<UVector2> polygon - the vertices of the outlined polygon
23 // defined in clockwise or anti-clockwise
24 // order
25 // std::vector<ZSection> - the z-sections defined by
26 // z position, offset and scale
27 // in increasing z-position order
28 //
29 // Parameters in the special constructor (for solid with 2 z-sections:
30 // double halfZ - the solid half length in Z
31 // UVector2 off1 - offset of the side in -halfZ
32 // double scale1 - scale of the side in -halfZ
33 // UVector2 off2 - offset of the side in +halfZ
34 // double scale2 - scale of the side in -halfZ
35 //
36 // 13.08.13 Tatiana Nikitina
37 // Created from original implementation in Geant4
38 // --------------------------------------------------------------------
39 
40 #ifndef USOLIDS_UExtrudedSolid_HH
41 #define USOLIDS_UExtrudedSolid_HH
42 
43 //#include <vector>
44 
45 //#include "VUSolid.hh"
46 //#include "UUtils.hh"
47 #include "UTessellatedSolid.hh"
48 #include "UVector2.hh"
49 
50 class VUFacet;
51 
53 {
54 
55  public:
56 
57  struct ZSection
58  {
59  ZSection(double z, UVector2 offset, double scale)
60  : fZ(z), fOffset(offset), fScale(scale) {}
61 
62  double fZ;
64  double fScale;
65  };
66 
67  public:
68 
69  UExtrudedSolid(const std::string& pName,
70  std::vector<UVector2> polygon,
71  std::vector<ZSection> zsections);
72  // General constructor
73 
74  UExtrudedSolid(const std::string& pName,
75  std::vector<UVector2> polygon,
76  double halfZ,
77  UVector2 off1, double scale1,
78  UVector2 off2, double scale2);
79  // Special constructor for solid with 2 z-sections
80 
81  virtual ~UExtrudedSolid();
82  // Destructor
83 
84  // Accessors
85 
86  inline int GetNofVertices() const;
87  inline UVector2 GetVertex(int index) const;
88  inline std::vector<UVector2> GetPolygon() const;
89 
90  inline int GetNofZSections() const;
91  inline ZSection GetZSection(int index) const;
92  inline std::vector<ZSection> GetZSections() const;
93 
94  // Solid methods
95 
96  EnumInside Inside(const UVector3& aPoint) const;
97  double DistanceToOut(const UVector3& aPoint,
98  const UVector3& aDirection,
99  UVector3& aNormalVector,
100  bool& aConvex,
101  double aPstep = UUtils::kInfinity) const;
102  double SafetyFromInside(const UVector3& aPoint,
103  bool aAccurate = false) const;
105  {
106  return "ExtrudedSolid";
107  }
108  VUSolid* Clone() const;
109 
110  std::ostream& StreamInfo(std::ostream& os) const;
111 
112  public:
113 
114  UExtrudedSolid();
115  // Fake default constructor for usage restricted to direct object
116  // persistency for clients requiring preallocation of memory for
117  // persistifiable objects.
118 
119  UExtrudedSolid(const UExtrudedSolid& rhs);
121  // Copy constructor and assignment operator.
122 
123  void Initialise(std::vector<UVector2>& polygon,
124  std::vector<ZSection>& zsections);
125  void Initialise(std::vector<UVector2>& polygon, double dz,
126  UVector2 off1, double scale1,
127  UVector2 off2, double scale2);
128  // Initialisation methods for constructors.
129 
130  private:
131 
133 
134  UVector3 GetVertex(int iz, int ind) const;
135  UVector2 ProjectPoint(const UVector3& point) const;
136 
137  bool IsSameLine(UVector2 p,
138  UVector2 l1, UVector2 l2) const;
140  UVector2 l1, UVector2 l2) const;
141  bool IsSameSide(UVector2 p1, UVector2 p2,
142  UVector2 l1, UVector2 l2) const;
144  UVector2 p) const;
145  double GetAngle(UVector2 p0, UVector2 pa, UVector2 pb) const;
146 
147  VUFacet* MakeDownFacet(int ind1, int ind2, int ind3) const;
148  VUFacet* MakeUpFacet(int ind1, int ind2, int ind3) const;
149 
151  bool MakeFacets();
152  bool IsConvex() const;
153 
154 
155  private:
156 
157  int fNv;
158  int fNz;
159  std::vector<UVector2> fPolygon;
160  std::vector<ZSection> fZSections;
161  std::vector< std::vector<int> > fTriangles;
162  bool fIsConvex;
164 
165  std::vector<double> fKScales;
166  std::vector<double> fScale0s;
167  std::vector<UVector2> fKOffsets;
168  std::vector<UVector2> fOffset0s;
169 };
170 
171 #include "UExtrudedSolid.icc"
172 
173 #endif
void Initialise(std::vector< UVector2 > &polygon, std::vector< ZSection > &zsections)
std::ostream & StreamInfo(std::ostream &os) const
std::vector< double > fKScales
virtual ~UExtrudedSolid()
bool IsPointInside(UVector2 a, UVector2 b, UVector2 c, UVector2 p) const
double SafetyFromInside(const UVector3 &aPoint, bool aAccurate=false) const
ZSection GetZSection(int index) const
UVector2 ProjectPoint(const UVector3 &point) const
G4double z
Definition: TRTMaterials.hh:39
std::vector< std::vector< int > > fTriangles
bool IsSameLineSegment(UVector2 p, UVector2 l1, UVector2 l2) const
VUFacet * MakeUpFacet(int ind1, int ind2, int ind3) const
std::vector< UVector2 > fKOffsets
std::vector< double > fScale0s
UGeometryType fGeometryType
G4double a
Definition: TRTMaterials.hh:39
EnumInside Inside(const UVector3 &aPoint) const
UGeometryType GetEntityType() const
std::vector< UVector2 > fPolygon
bool AddGeneralPolygonFacets()
std::vector< UVector2 > GetPolygon() const
double GetAngle(UVector2 p0, UVector2 pa, UVector2 pb) const
std::vector< ZSection > fZSections
static const double kInfinity
Definition: UUtils.hh:53
VUSolid * Clone() const
bool IsConvex() const
std::vector< ZSection > GetZSections() const
G4double iz
Definition: TRTMaterials.hh:39
std::vector< UVector2 > fOffset0s
VUFacet * MakeDownFacet(int ind1, int ind2, int ind3) const
EnumInside
Definition: VUSolid.hh:23
UVector2 GetVertex(int index) const
ZSection(double z, UVector2 offset, double scale)
int GetNofZSections() const
bool IsSameSide(UVector2 p1, UVector2 p2, UVector2 l1, UVector2 l2) const
std::string UGeometryType
Definition: UTypes.hh:39
UExtrudedSolid & operator=(const UExtrudedSolid &rhs)
int GetNofVertices() const
bool IsSameLine(UVector2 p, UVector2 l1, UVector2 l2) const
void ComputeProjectionParameters()
double DistanceToOut(const UVector3 &aPoint, const UVector3 &aDirection, UVector3 &aNormalVector, bool &aConvex, double aPstep=UUtils::kInfinity) const