Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UPolycone.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 // UPolycone
12 //
13 // Class description:
14 //
15 // Class implementing a CSG-like type "PCON".
16 //
17 // UPolycone( const G4String& name,
18 // G4double phiStart, // initial phi starting angle
19 // G4double phiTotal, // total phi angle
20 // G4int numZPlanes, // number of z planes
21 // const G4double zPlane[], // position of z planes
22 // const G4double rInner[], // tangent distance to inner surface
23 // const G4double rOuter[]) // tangent distance to outer surface
24 //
25 // Alternative constructor, but limited to increasing-only Z sections:
26 //
27 // UPolycone( const G4String& name,
28 // G4double phiStart, // initial phi starting angle
29 // G4double phiTotal, // total phi angle
30 // G4int numRZ, // number corners in r,z space
31 // const G4double r[], // r coordinate of these corners
32 // const G4double z[]) // z coordinate of these corners
33 //
34 // 19.04.13 Marek Gayer
35 // Created from original implementation in Geant4
36 // --------------------------------------------------------------------
37 
38 #ifndef UPolycone_hh
39 #define UPolycone_hh
40 
41 #include "VUSolid.hh"
42 
43 #include "UPolyconeSide.hh"
44 #include "UVCSGfaceted.hh"
45 #include "UVoxelizer.hh"
46 
47 #include "UCons.hh"
48 #include "UTubs.hh"
49 #include "UBox.hh"
50 
51 class UEnclosingCylinder;
52 class UReduciblePolygon;
54 {
55  public:
60 
61  double fStartAngle;
62  double fOpeningAngle;
64  std::vector<double> fZValues;
65  std::vector<double> Rmin;
66  std::vector<double> Rmax;
67 };
68 
69 class UPolycone : public VUSolid
70 {
71 
72  public: // with description
73 
74  void Init(
75  double phiStart, // initial phi starting angle
76  double phiTotal, // total phi angle
77  int numZPlanes, // number of z planes
78  const double zPlane[], // position of z planes
79  const double rInner[], // tangent distance to inner surface
80  const double rOuter[]);
81 
82  UPolycone(const std::string& name) : VUSolid(name)
83  {
84  }
85 
86  UPolycone(const std::string& name,
87  double phiStart, // initial phi starting angle
88  double phiTotal, // total phi angle
89  int numZPlanes, // number of z planes
90  const double zPlane[], // position of z planes
91  const double rInner[], // tangent distance to inner surface
92  const double rOuter[]); // tangent distance to outer surface
93 
94 
95  UPolycone(const std::string& name,
96  double phiStart, // initial phi starting angle
97  double phiTotal, // total phi angle
98  int numRZ, // number corners in r,z space
99  const double r[], // r coordinate of these corners
100  const double z[]); // z coordinate of these corners
101 
102 
103  virtual ~UPolycone();
104 
105  void Reset();
106 
107 // inline void SetOriginalParameters(UPolyconeHistorical* pars);
108 
109 // inline void SetOriginalParameters();
110 
111  std::ostream& StreamInfo(std::ostream& os) const;
112 
113  VUSolid::EnumInside Inside(const UVector3& p) const;
114 
115  double DistanceToIn(const UVector3& p, const UVector3& v, double aPstep = UUtils::kInfinity) const;
116 
117  double SafetyFromInside(const UVector3& aPoint,
118  bool aAccurate = false) const;
119  double SafetyFromOutside(const UVector3& aPoint,
120  bool aAccurate = false) const;
121 
122  double DistanceToOut(const UVector3& aPoint,
123  const UVector3& aDirection,
124  UVector3& aNormalVector,
125  bool& aConvex,
126  double aPstep = UUtils::kInfinity) const;
127 
128  bool Normal(const UVector3& aPoint, UVector3& aNormal) const;
129  // virtual void Extent ( EAxisType aAxis, double &aMin, double &aMax ) const;
130  void Extent(UVector3& aMin, UVector3& aMax) const;
131  double Capacity();
132  double SurfaceArea();
134 
135  void ComputeBBox(UBBox* /*aBox*/, bool /*aStore = false*/) {}
136 
137  //G4Visualisation
138  void GetParametersList(int /*aNumber*/, double* /*aArray*/) const {}
139  VUSolid* Clone() const;
140 
141  UPolycone(const UPolycone& source);
142  UPolycone& operator=(const UPolycone& source);
143  // Copy constructor and assignment operator.
144  void CopyStuff(const UPolycone& source);
145  UVector3 GetPointOnSurface() const;
146 
147 // Methods for random point generation
148 
149  UVector3 GetPointOnCone(double fRmin1, double fRmax1,
150  double fRmin2, double fRmax2,
151  double zOne, double zTwo,
152  double& totArea) const;
153 
154  UVector3 GetPointOnTubs(double fRMin, double fRMax,
155  double zOne, double zTwo,
156  double& totArea) const;
157 
158  UVector3 GetPointOnCut(double fRMin1, double fRMax1,
159  double fRMin2, double fRMax2,
160  double zOne, double zTwo,
161  double& totArea) const;
162 
163  UVector3 GetPointOnRing(double fRMin, double fRMax,
164  double fRMin2, double fRMax2,
165  double zOne) const;
166 
167  inline double GetStartPhi() const
168  {
169  return startPhi;
170  }
171 
172  inline double GetEndPhi() const
173  {
174  return endPhi;
175  }
176 
177  inline bool IsOpen() const
178  {
179  return phiIsOpen;
180  }
181 
182  inline bool IsGeneric() const
183  {
184  return false;
185  }
186 
187  inline int GetNumRZCorner() const
188  {
189  return numCorner;
190  }
191 
192  inline UPolyconeSideRZ GetCorner(int index) const
193  {
194  return corners[index];
195  }
196 
198  {
199  return fOriginalParameters;
200  }
201 
203  {
204  if (!pars)
205  // UException("UPolycone3::SetOriginalParameters()", "GeomSolids0002",
206  // FatalException, "NULL pointer to parameters!");
207  *fOriginalParameters = *pars;
208  }
209 
210  protected: // without description
211 
212 // int fNumSides;
214  // Here are our parameters
215 
216  double startPhi; // Starting phi value (0 < phiStart < 2pi)
217  double endPhi; // end phi value (0 < endPhi-phiStart < 2pi)
218  bool phiIsOpen; // true if there is a phi segment
219  int numCorner; // number RZ points
220  UPolyconeSideRZ* corners; // corner r,z points
221  UPolyconeHistorical* fOriginalParameters; // original input parameters
222  double fCubicVolume; // Cubic Volume
223  double fSurfaceArea; // Surface Area
224  mutable UBox fBox; // Bounding box for Polycone
225 
226  inline void SetOriginalParameters()
227  {
228  int numPlanes = (int)numCorner / 2;
229 
231 
232  fOriginalParameters->fZValues.resize(numPlanes);
233  fOriginalParameters->Rmin.resize(numPlanes);
234  fOriginalParameters->Rmax.resize(numPlanes);
235 
236  for (int j = 0; j < numPlanes; j++)
237  {
238  fOriginalParameters->fZValues[j] = corners[numPlanes + j].z;
239  fOriginalParameters->Rmax[j] = corners[numPlanes + j].r;
240  fOriginalParameters->Rmin[j] = corners[numPlanes - 1 - j].r;
241  }
242 
245  fOriginalParameters->fNumZPlanes = numPlanes;
246  }
247 
249 
251  {
252  VUSolid* solid;// true if all points in section are concave in regards to whole polycone, will be determined
253  double shift;
254  bool tubular;
255 // double left, right;
256  bool convex; // TURE if all points in section are concave in regards to whole polycone, will be determined, currently not implemented
257  };
258 
259  std::vector<double> fZs; // z coordinates of given sections
260  std::vector<UPolyconeSection> fSections;
262 
263  inline VUSolid::EnumInside InsideSection(int index, const UVector3& p) const;
264 
265  inline double SafetyFromInsideSection(int index, const UVector3& p) const
266  {
267  const UPolyconeSection& section = fSections[index];
268  UVector3 ps(p.x, p.y, p.z - section.shift);
269  double res = section.solid->SafetyFromInside(ps, true);
270  return res;
271  }
272 
273  inline double SafetyFromOutsideSection(int index, const UVector3& p) const
274  {
275  const UPolyconeSection& section = fSections[index];
276  UVector3 ps(p.x, p.y, p.z - section.shift);
277  double res = section.solid->SafetyFromOutside(ps, true);
278  return res;
279  }
280 
281  bool NormalSection(int index, const UVector3& p, UVector3& n) const
282  {
283  const UPolyconeSection& section = fSections[index];
284  UVector3 ps(p.x, p.y, p.z - section.shift);
285  bool res = section.solid->Normal(ps, n);
286  return res;
287  }
288 
289  inline int GetSection(double z) const
290  {
291  int section = UVoxelizer::BinarySearch(fZs, z);
292  if (section < 0) section = 0;
293  else if (section > fMaxSection) section = fMaxSection;
294  return section;
295  }
296 };
297 
298 #endif
double DistanceToIn(const UVector3 &p, const UVector3 &v, double aPstep=UUtils::kInfinity) const
Definition: UPolycone.cc:519
std::vector< double > Rmin
Definition: UPolycone.hh:65
UPolyconeSideRZ GetCorner(int index) const
Definition: UPolycone.hh:192
std::vector< double > fZValues
Definition: UPolycone.hh:64
double GetEndPhi() const
Definition: UPolycone.hh:172
UVector3 GetPointOnTubs(double fRMin, double fRMax, double zOne, double zTwo, double &totArea) const
Definition: UPolycone.cc:960
double SafetyFromInsideSection(int index, const UVector3 &p) const
Definition: UPolycone.hh:265
void SetOriginalParameters(UPolyconeHistorical *pars)
Definition: UPolycone.hh:202
bool NormalSection(int index, const UVector3 &p, UVector3 &n) const
Definition: UPolycone.hh:281
int GetSection(double z) const
Definition: UPolycone.hh:289
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
G4double z
Definition: TRTMaterials.hh:39
double fCubicVolume
Definition: UPolycone.hh:222
UPolyconeHistorical * GetOriginalParameters() const
Definition: UPolycone.hh:197
const char * p
Definition: xmltok.h:285
void CopyStuff(const UPolycone &source)
Definition: UPolycone.cc:1263
std::vector< UPolyconeSection > fSections
Definition: UPolycone.hh:260
UVector3 GetPointOnCut(double fRMin1, double fRMax1, double fRMin2, double fRMax2, double zOne, double zTwo, double &totArea) const
Definition: UPolycone.cc:1067
const XML_Char * name
std::ostream & StreamInfo(std::ostream &os) const
Definition: UPolycone.cc:361
UPolyconeHistorical & operator=(const UPolyconeHistorical &right)
Definition: UPolycone.cc:1206
virtual bool Normal(const UVector3 &aPoint, UVector3 &aNormal) const =0
bool IsOpen() const
Definition: UPolycone.hh:177
double x
Definition: UVector3.hh:136
Definition: UBox.hh:33
int numCorner
Definition: UPolycone.hh:219
VUSolid::EnumInside Inside(const UVector3 &p) const
Definition: UPolycone.cc:470
void GetParametersList(int, double *) const
Definition: UPolycone.hh:138
std::vector< double > Rmax
Definition: UPolycone.hh:66
int fMaxSection
Definition: UPolycone.hh:261
bool Normal(const UVector3 &aPoint, UVector3 &aNormal) const
Definition: UPolycone.cc:680
static int BinarySearch(const std::vector< T > &vec, T value)
Definition: UVoxelizer.hh:58
double SafetyFromOutsideSection(int index, const UVector3 &p) const
Definition: UPolycone.hh:273
bool phiIsOpen
Definition: UPolycone.hh:218
UVector3 GetPointOnSurface() const
Definition: UPolycone.cc:1087
void Init(double phiStart, double phiTotal, int numZPlanes, const double zPlane[], const double rInner[], const double rOuter[])
Definition: UPolycone.cc:105
double endPhi
Definition: UPolycone.hh:217
UPolyconeHistorical * fOriginalParameters
Definition: UPolycone.hh:221
UPolyconeSideRZ * corners
Definition: UPolycone.hh:220
UGeometryType GetEntityType() const
Definition: UPolycone.cc:1287
void Reset()
Definition: UPolycone.cc:1505
EnumInside
Definition: VUSolid.hh:23
const G4int n
double SurfaceArea()
Definition: UPolycone.cc:789
virtual double SafetyFromInside(const UVector3 &aPoint, bool aAccurate=false) const =0
double Capacity()
Definition: UPolycone.cc:772
void SetOriginalParameters()
Definition: UPolycone.hh:226
VUSolid::EnumInside InsideSection(int index, const UVector3 &p) const
Definition: UPolycone.cc:399
virtual double SafetyFromOutside(const UVector3 &aPoint, bool aAccurate=false) const =0
double SafetyFromOutside(const UVector3 &aPoint, bool aAccurate=false) const
Definition: UPolycone.cc:651
double fSurfaceArea
Definition: UPolycone.hh:223
double GetStartPhi() const
Definition: UPolycone.hh:167
VUSolid * Clone() const
Definition: UPolycone.cc:1230
double SafetyFromInside(const UVector3 &aPoint, bool aAccurate=false) const
Definition: UPolycone.cc:618
std::string UGeometryType
Definition: UTypes.hh:70
UVector3 GetPointOnRing(double fRMin, double fRMax, double fRMin2, double fRMax2, double zOne) const
Definition: UPolycone.cc:1019
UVector3 GetPointOnCone(double fRmin1, double fRmax1, double fRmin2, double fRmax2, double zOne, double zTwo, double &totArea) const
Definition: UPolycone.cc:856
virtual ~UPolycone()
Definition: UPolycone.cc:350
UPolycone & operator=(const UPolycone &source)
Definition: UPolycone.cc:1246
int GetNumRZCorner() const
Definition: UPolycone.hh:187
double z
Definition: UVector3.hh:138
double startPhi
Definition: UPolycone.hh:216
std::vector< double > fZs
Definition: UPolycone.hh:259
UEnclosingCylinder * enclosingCylinder
Definition: UPolycone.hh:248
void Extent(UVector3 &aMin, UVector3 &aMax) const
Definition: UPolycone.cc:765
double DistanceToOut(const UVector3 &aPoint, const UVector3 &aDirection, UVector3 &aNormalVector, bool &aConvex, double aPstep=UUtils::kInfinity) const
Definition: UPolycone.cc:563
double y
Definition: UVector3.hh:137
UPolycone(const std::string &name)
Definition: UPolycone.hh:82
void ComputeBBox(UBBox *, bool)
Definition: UPolycone.hh:135
UBox fBox
Definition: UPolycone.hh:224
bool IsGeneric() const
Definition: UPolycone.hh:182