Geant4  10.01
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 std::string& name,
18 // double phiStart, // initial phi starting angle
19 // double phiTotal, // total phi angle
20 // int numZPlanes, // number of z planes
21 // const double zPlane[], // position of z planes
22 // const double rInner[], // tangent distance to inner surface
23 // const double rOuter[]) // tangent distance to outer surface
24 //
25 // Alternative constructor, but limited to increasing-only Z sections:
26 //
27 // UPolycone( const std::string& name,
28 // double phiStart, // initial phi starting angle
29 // double phiTotal, // total phi angle
30 // int numRZ, // number corners in r,z space
31 // const double r[], // r coordinate of these corners
32 // const double 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  // Visualisation
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 
230  fOriginalParameters = new UPolyconeHistorical;
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 
243  fOriginalParameters->fStartAngle = startPhi;
244  fOriginalParameters->fOpeningAngle = endPhi - startPhi;
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 double rho,
266  const UVector3& p) const
267  {
268  const UPolyconeSection& section = fSections[index];
269  UVector3 ps(p.x, p.y, p.z - section.shift);
270  double res=0;
271  if (section.tubular)
272  {
273  UTubs* tubs = (UTubs*) section.solid;
274  res = tubs->SafetyFromInsideR(ps,rho, true);
275  }
276  else
277  {
278  UCons* cons = (UCons*) section.solid;
279  res = cons->SafetyFromInsideR(ps,rho, true);
280  }
281  return res;
282  }
283 
284  // Auxiliary method used in SafetyFromInside for finding safety
285  // from section in R and Phi
286  //
287  inline double SafetyFromOutsideSection(int index, const double rho,
288  const UVector3& p) const
289  {
290  const UPolyconeSection& section = fSections[index];
291  UVector3 ps(p.x, p.y, p.z);
292  double res=0;
293  if (section.tubular)
294  {
295  UTubs* tubs = (UTubs*) section.solid;
296  res = tubs->SafetyFromOutsideR(ps,rho, true);
297  }
298  else
299  {
300  UCons* cons = (UCons*) section.solid;
301  res = cons->SafetyFromOutsideR(ps,rho, true);
302  }
303  return res;
304  }
305 
306  // Auxiliary method used in SafetyFromOutside for finding safety
307  // from section
308  //
309  inline double SafetyFromOutsideSection(int index, const UVector3& p) const
310  {
311  const UPolyconeSection& section = fSections[index];
312  UVector3 ps(p.x, p.y,p.z - section.shift);
313  double res=0;
314 
315  res = section.solid->SafetyFromOutside(ps, true);
316  return res;
317  }
318 
319  bool NormalSection(int index, const UVector3& p, UVector3& n) const
320  {
321  const UPolyconeSection& section = fSections[index];
322  UVector3 ps(p.x, p.y, p.z - section.shift);
323  bool res = section.solid->Normal(ps, n);
324  return res;
325  }
326 
327  inline int GetSection(double z) const
328  {
329  int section = UVoxelizer::BinarySearch(fZs, z);
330  if (section < 0) section = 0;
331  else if (section > fMaxSection) section = fMaxSection;
332  return section;
333  }
334 };
335 
336 #endif
Definition: UTubs.hh:47
double DistanceToIn(const UVector3 &p, const UVector3 &v, double aPstep=UUtils::kInfinity) const
Definition: UPolycone.cc:614
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:1130
void SetOriginalParameters(UPolyconeHistorical *pars)
Definition: UPolycone.hh:202
bool NormalSection(int index, const UVector3 &p, UVector3 &n) const
Definition: UPolycone.hh:319
int GetSection(double z) const
Definition: UPolycone.hh:327
G4double z
Definition: TRTMaterials.hh:39
double fCubicVolume
Definition: UPolycone.hh:222
UPolyconeHistorical * GetOriginalParameters() const
Definition: UPolycone.hh:197
G4String name
Definition: TRTMaterials.hh:40
void CopyStuff(const UPolycone &source)
Definition: UPolycone.cc:1433
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:1237
double SafetyFromOutsideSection(int index, const double rho, const UVector3 &p) const
Definition: UPolycone.hh:287
std::ostream & StreamInfo(std::ostream &os) const
Definition: UPolycone.cc:351
UPolyconeHistorical & operator=(const UPolyconeHistorical &right)
Definition: UPolycone.cc:1376
double SafetyFromInsideR(const UVector3 &p, const double rho, bool) const
virtual bool Normal(const UVector3 &aPoint, UVector3 &aNormal) const =0
bool IsOpen() const
Definition: UPolycone.hh:177
double SafetyFromOutsideR(const UVector3 &p, const double rho, bool) const
double x
Definition: UVector3.hh:136
Definition: UBox.hh:33
Definition: UCons.hh:49
int numCorner
Definition: UPolycone.hh:219
VUSolid::EnumInside Inside(const UVector3 &p) const
Definition: UPolycone.cc:563
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:843
static int BinarySearch(const std::vector< T > &vec, T value)
Definition: UVoxelizer.hh:57
static const double kInfinity
Definition: UUtils.hh:53
double SafetyFromOutsideSection(int index, const UVector3 &p) const
Definition: UPolycone.hh:309
bool phiIsOpen
Definition: UPolycone.hh:218
UVector3 GetPointOnSurface() const
Definition: UPolycone.cc:1257
void Init(double phiStart, double phiTotal, int numZPlanes, const double zPlane[], const double rInner[], const double rOuter[])
Definition: UPolycone.cc:103
double SafetyFromOutsideR(const UVector3 &p, const double rho, bool precise=false) const
double endPhi
Definition: UPolycone.hh:217
UPolyconeHistorical * fOriginalParameters
Definition: UPolycone.hh:221
UPolyconeSideRZ * corners
Definition: UPolycone.hh:220
UGeometryType GetEntityType() const
Definition: UPolycone.cc:1457
void Reset()
Definition: UPolycone.cc:1675
EnumInside
Definition: VUSolid.hh:23
const G4int n
double SurfaceArea()
Definition: UPolycone.cc:959
double Capacity()
Definition: UPolycone.cc:942
void SetOriginalParameters()
Definition: UPolycone.hh:226
VUSolid::EnumInside InsideSection(int index, const UVector3 &p) const
Definition: UPolycone.cc:470
virtual double SafetyFromOutside(const UVector3 &aPoint, bool aAccurate=false) const =0
double SafetyFromOutside(const UVector3 &aPoint, bool aAccurate=false) const
Definition: UPolycone.cc:814
double fSurfaceArea
Definition: UPolycone.hh:223
double GetStartPhi() const
Definition: UPolycone.hh:167
VUSolid * Clone() const
Definition: UPolycone.cc:1400
double SafetyFromInside(const UVector3 &aPoint, bool aAccurate=false) const
Definition: UPolycone.cc:765
std::string UGeometryType
Definition: UTypes.hh:39
UVector3 GetPointOnRing(double fRMin, double fRMax, double fRMin2, double fRMax2, double zOne) const
Definition: UPolycone.cc:1189
UVector3 GetPointOnCone(double fRmin1, double fRmax1, double fRmin2, double fRmax2, double zOne, double zTwo, double &totArea) const
Definition: UPolycone.cc:1026
virtual ~UPolycone()
Definition: UPolycone.cc:340
UPolycone & operator=(const UPolycone &source)
Definition: UPolycone.cc:1416
int GetNumRZCorner() const
Definition: UPolycone.hh:187
double z
Definition: UVector3.hh:138
double startPhi
Definition: UPolycone.hh:216
double SafetyFromInsideSection(int index, const double rho, const UVector3 &p) const
Definition: UPolycone.hh:265
std::vector< double > fZs
Definition: UPolycone.hh:259
UEnclosingCylinder * enclosingCylinder
Definition: UPolycone.hh:248
void Extent(UVector3 &aMin, UVector3 &aMax) const
Definition: UPolycone.cc:934
double SafetyFromInsideR(const UVector3 &p, const double rho, bool precise=false) const
double DistanceToOut(const UVector3 &aPoint, const UVector3 &aDirection, UVector3 &aNormalVector, bool &aConvex, double aPstep=UUtils::kInfinity) const
Definition: UPolycone.cc:659
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