Geant4  10.01.p02
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 "UTessellatedSolid.hh"
46 #include "UVector2.hh"
47 
48 class VUFacet;
49 
51 {
52 
53  public:
54 
55  struct ZSection
56  {
57  ZSection(double z, UVector2 offset, double scale)
58  : fZ(z), fOffset(offset), fScale(scale) {}
59 
60  double fZ;
62  double fScale;
63  };
64 
65  public:
66 
67  UExtrudedSolid(const std::string& pName,
68  std::vector<UVector2> polygon,
69  std::vector<ZSection> zsections);
70  // General constructor
71 
72  UExtrudedSolid(const std::string& pName,
73  std::vector<UVector2> polygon,
74  double halfZ,
75  UVector2 off1, double scale1,
76  UVector2 off2, double scale2);
77  // Special constructor for solid with 2 z-sections
78 
79  virtual ~UExtrudedSolid();
80  // Destructor
81 
82  // Accessors
83 
84  inline int GetNofVertices() const;
85  inline UVector2 GetVertex(int index) const;
86  inline std::vector<UVector2> GetPolygon() const;
87 
88  inline int GetNofZSections() const;
89  inline ZSection GetZSection(int index) const;
90  inline std::vector<ZSection> GetZSections() const;
91 
92  // Solid methods
93 
94  EnumInside Inside(const UVector3& aPoint) const;
95  double DistanceToOut(const UVector3& aPoint,
96  const UVector3& aDirection,
97  UVector3& aNormalVector,
98  bool& aConvex,
99  double aPstep = UUtils::kInfinity) const;
100  double SafetyFromInside(const UVector3& aPoint,
101  bool aAccurate = false) const;
102 
104  VUSolid* Clone() const;
105 
106  std::ostream& StreamInfo(std::ostream& os) const;
107 
108  public:
109 
110  UExtrudedSolid();
111  // Fake default constructor for usage restricted to direct object
112  // persistency for clients requiring preallocation of memory for
113  // persistifiable objects.
114 
115  UExtrudedSolid(const UExtrudedSolid& rhs);
117  // Copy constructor and assignment operator.
118 
119  void Initialise(std::vector<UVector2>& polygon,
120  std::vector<ZSection>& zsections);
121  void Initialise(std::vector<UVector2>& polygon, double dz,
122  UVector2 off1, double scale1,
123  UVector2 off2, double scale2);
124  // Initialisation methods for constructors.
125 
126  private:
127 
129 
130  UVector3 GetVertex(int iz, int ind) const;
131  UVector2 ProjectPoint(const UVector3& point) const;
132 
133  bool IsSameLine(UVector2 p,
134  UVector2 l1, UVector2 l2) const;
136  UVector2 l1, UVector2 l2) const;
138  UVector2 l1, UVector2 l2) const;
140  UVector2 p) const;
141  double GetAngle(UVector2 p0, UVector2 pa, UVector2 pb) const;
142 
143  VUFacet* MakeDownFacet(int ind1, int ind2, int ind3) const;
144  VUFacet* MakeUpFacet(int ind1, int ind2, int ind3) const;
145 
147  bool MakeFacets();
148  bool IsConvex() const;
149 
150 
151  private:
152 
153  int fNv;
154  int fNz;
155  std::vector<UVector2> fPolygon;
156  std::vector<ZSection> fZSections;
157  std::vector< std::vector<int> > fTriangles;
158  bool fIsConvex;
160 
161  std::vector<double> fKScales;
162  std::vector<double> fScale0s;
163  std::vector<UVector2> fKOffsets;
164  std::vector<UVector2> fOffset0s;
165 };
166 
167 #include "UExtrudedSolid.icc"
168 
169 #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:54
VUSolid * Clone() const
bool IsConvex() const
std::vector< ZSection > GetZSections() const
G4double iz
Definition: TRTMaterials.hh:39
std::vector< UVector2 > fOffset0s
const G4double p2
const G4double p1
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
const G4double p0
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