34#if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
47G4UPolycone::G4UPolycone(
const G4String& name,
54 : Base_t(
name, phiStart, phiTotal, numZPlanes, zPlane, rInner, rOuter)
57 SetOriginalParameters();
64 if (wrDelta <= 0 || wrDelta >= twopi*(1-
DBL_EPSILON))
70 for (
G4int i=0; i<numZPlanes; ++i)
74 rzcorners.emplace_back(r,z);
76 for (
G4int i=numZPlanes-1; i>=0; --i)
80 rzcorners.emplace_back(r,z);
82 std::vector<G4int> iout;
91G4UPolycone::G4UPolycone(
const G4String& name,
97 : Base_t(
name, phiStart, phiTotal, numRZ, r, z)
100 SetOriginalParameters();
101 wrStart = phiStart;
while (wrStart < 0) wrStart += twopi;
103 if (wrDelta <= 0 || wrDelta >= twopi*(1-
DBL_EPSILON))
109 for (
G4int i=0; i<numRZ; ++i)
111 rzcorners.emplace_back(r[i],z[i]);
113 std::vector<G4int> iout;
123G4UPolycone::G4UPolycone( __void__& a )
133G4UPolycone::~G4UPolycone() =
default;
140G4UPolycone::G4UPolycone(
const G4UPolycone& source )
143 fGenericPcon = source.fGenericPcon;
144 fOriginalParameters = source.fOriginalParameters;
145 wrStart = source.wrStart;
146 wrDelta = source.wrDelta;
147 rzcorners = source.rzcorners;
155G4UPolycone& G4UPolycone::operator=(
const G4UPolycone& source )
157 if (
this == &source)
return *
this;
159 Base_t::operator=( source );
160 fGenericPcon = source.fGenericPcon;
161 fOriginalParameters = source.fOriginalParameters;
162 wrStart = source.wrStart;
163 wrDelta = source.wrDelta;
164 rzcorners = source.rzcorners;
174G4double G4UPolycone::GetStartPhi()
const
178G4double G4UPolycone::GetDeltaPhi()
const
182G4double G4UPolycone::GetEndPhi()
const
184 return (wrStart + wrDelta);
186G4double G4UPolycone::GetSinStartPhi()
const
188 if (!IsOpen())
return 0.;
190 return std::sin(phi);
192G4double G4UPolycone::GetCosStartPhi()
const
194 if (!IsOpen())
return 1.;
196 return std::cos(phi);
198G4double G4UPolycone::GetSinEndPhi()
const
200 if (!IsOpen())
return 0.;
202 return std::sin(phi);
204G4double G4UPolycone::GetCosEndPhi()
const
206 if (!IsOpen())
return 1.;
208 return std::cos(phi);
210G4bool G4UPolycone::IsOpen()
const
212 return (wrDelta < twopi);
214G4int G4UPolycone::GetNumRZCorner()
const
216 return rzcorners.size();
229void G4UPolycone::SetOriginalParameters()
231 vecgeom::PolyconeHistorical* original_parameters = Base_t::GetOriginalParameters();
233 fOriginalParameters.Start_angle = original_parameters->fHStart_angle;
234 fOriginalParameters.Opening_angle = original_parameters->fHOpening_angle;
235 fOriginalParameters.Num_z_planes = original_parameters->fHNum_z_planes;
237 delete [] fOriginalParameters.Z_values;
238 delete [] fOriginalParameters.Rmin;
239 delete [] fOriginalParameters.Rmax;
241 G4int numPlanes = fOriginalParameters.Num_z_planes;
242 fOriginalParameters.Z_values =
new G4double[numPlanes];
243 fOriginalParameters.Rmin =
new G4double[numPlanes];
244 fOriginalParameters.Rmax =
new G4double[numPlanes];
245 for (
G4int i=0; i<numPlanes; ++i)
247 fOriginalParameters.Z_values[i] = original_parameters->fHZ_values[i];
248 fOriginalParameters.Rmin[i] = original_parameters->fHRmin[i];
249 fOriginalParameters.Rmax[i] = original_parameters->fHRmax[i];
254 fOriginalParameters = *pars;
255 fRebuildPolyhedron =
true;
259G4bool G4UPolycone::Reset()
263 std::ostringstream message;
264 message <<
"Solid " << GetName() <<
" built using generic construct."
265 <<
G4endl <<
"Not applicable to the generic construct !";
266 G4Exception(
"G4UPolycone::Reset()",
"GeomSolids1001",
274 wrStart = fOriginalParameters.Start_angle;
279 wrDelta = fOriginalParameters.Opening_angle;
280 if (wrDelta <= 0. || wrDelta >= twopi*(1-
DBL_EPSILON))
286 for (
G4int i=0; i<fOriginalParameters.Num_z_planes; ++i)
288 G4double z = fOriginalParameters.Z_values[i];
289 G4double r = fOriginalParameters.Rmax[i];
290 rzcorners.emplace_back(r,z);
292 for (
G4int i=fOriginalParameters.Num_z_planes-1; i>=0; --i)
294 G4double z = fOriginalParameters.Z_values[i];
295 G4double r = fOriginalParameters.Rmin[i];
296 rzcorners.emplace_back(r,z);
298 std::vector<G4int> iout;
323 return new G4UPolycone(*
this);
333 static G4bool checkBBox =
true;
334 static G4bool checkPhi =
true;
336 G4double rmin = kInfinity, rmax = -kInfinity;
337 G4double zmin = kInfinity, zmax = -kInfinity;
339 for (
G4int i=0; i<GetNumRZCorner(); ++i)
342 if (corner.
r < rmin) rmin = corner.
r;
343 if (corner.
r > rmax) rmax = corner.
r;
344 if (corner.
z < zmin) zmin = corner.
z;
345 if (corner.
z > zmax) zmax = corner.
z;
352 GetSinStartPhi(),GetCosStartPhi(),
353 GetSinEndPhi(),GetCosEndPhi(),
355 pMin.
set(vmin.
x(),vmin.
y(),zmin);
356 pMax.
set(vmax.
x(),vmax.
y(),zmax);
360 pMin.
set(-rmax,-rmax, zmin);
361 pMax.
set( rmax, rmax, zmax);
366 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
368 std::ostringstream message;
369 message <<
"Bad bounding box (min >= max) for solid: "
371 <<
"\npMin = " << pMin
372 <<
"\npMax = " << pMax;
373 G4Exception(
"G4UPolycone::BoundingLimits()",
"GeomMgt0001",
391 std::ostringstream message;
392 message <<
"Inconsistency in bounding boxes for solid: "
394 <<
"\nBBox min: wrapper = " << pMin <<
" solid = " << vmin
395 <<
"\nBBox max: wrapper = " << pMax <<
" solid = " << vmax;
396 G4Exception(
"G4UPolycone::BoundingLimits()",
"GeomMgt0001",
406 if (GetStartPhi() != Base_t::GetStartPhi() ||
407 GetEndPhi() != Base_t::GetEndPhi() ||
408 IsOpen() != (Base_t::GetDeltaPhi() < twopi))
410 std::ostringstream message;
411 message <<
"Inconsistency in Phi angles or # of sides for solid: "
413 <<
"\nPhi start : wrapper = " << GetStartPhi()
414 <<
" solid = " << Base_t::GetStartPhi()
415 <<
"\nPhi end : wrapper = " << GetEndPhi()
416 <<
" solid = " << Base_t::GetEndPhi()
417 <<
"\nPhi is open: wrapper = " << (IsOpen() ?
"true" :
"false")
419 << ((Base_t::GetDeltaPhi() < twopi) ?
"true" :
"false");
420 G4Exception(
"G4UPolycone::BoundingLimits()",
"GeomMgt0001",
431G4bool G4UPolycone::CalculateExtent(
const EAxis pAxis,
441 BoundingLimits(bmin,bmax);
444 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
446 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
448 return exist = pMin < pMax;
457 std::vector<G4int> iout;
462 for (
G4int i=0; i<GetNumRZCorner(); ++i)
465 contourRZ.emplace_back(corner.
r,corner.
z);
469 if (area < 0.) std::reverse(contourRZ.begin(),contourRZ.end());
474 std::ostringstream message;
475 message <<
"Triangulation of RZ contour has failed for solid: "
477 <<
"\nExtent has been calculated using boundary box";
480 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
484 const G4int NSTEPS = 24;
489 G4double dphi = IsOpen() ? ephi-sphi : twopi;
490 G4int ksteps = (dphi <= astep) ? 1 : (
G4int)((dphi-deg)/astep) + 1;
493 G4double sinHalf = std::sin(0.5*ang);
494 G4double cosHalf = std::cos(0.5*ang);
495 G4double sinStep = 2.*sinHalf*cosHalf;
496 G4double cosStep = 1. - 2.*sinHalf*sinHalf;
498 G4double sinStart = GetSinStartPhi();
499 G4double cosStart = GetCosStartPhi();
504 std::vector<const G4ThreeVectorList *> polygons;
505 polygons.resize(ksteps+2);
507 for (
G4int k=0; k<ksteps+2; ++k) pols[k].resize(6);
508 for (
G4int k=0; k<ksteps+2; ++k) polygons[k] = &pols[k];
515 G4int ntria = triangles.size()/3;
516 for (
G4int i=0; i<ntria; ++i)
519 for (
G4int k=0; k<3; ++k)
521 G4int e0 = i3+k, e1 = (k<2) ? e0+1 : i3;
524 r0[k2+0] = triangles[e0].x();
z0[k2+0] = triangles[e0].y();
525 r0[k2+1] = triangles[e1].x();
z0[k2+1] = triangles[e1].y();
529 if (z0[k2+1] - z0[k2+0] <= 0)
continue;
535 G4double sinCur = sinStart*cosHalf + cosStart*sinHalf;
536 G4double cosCur = cosStart*cosHalf - sinStart*sinHalf;
537 for (
G4int j=0; j<6; ++j) pols[0][j].set(r0[j]*cosStart,r0[j]*sinStart,z0[j]);
538 for (
G4int k=1; k<ksteps+1; ++k)
540 for (
G4int j=0; j<6; ++j) pols[k][j].set(r1[j]*cosCur,r1[j]*sinCur,z0[j]);
542 sinCur = sinCur*cosStep + cosCur*sinStep;
543 cosCur = cosCur*cosStep - sinTmp*sinStep;
545 for (
G4int j=0; j<6; ++j) pols[ksteps+1][j].set(r0[j]*cosEnd,r0[j]*sinEnd,z0[j]);
550 if (!benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,emin,emax))
continue;
551 if (emin < pMin) pMin = emin;
552 if (emax > pMax) pMax = emax;
553 if (eminlim > pMin && emaxlim < pMax)
return true;
555 return (pMin < pMax);
const G4double kCarTolerance
std::vector< G4ThreeVector > G4ThreeVectorList
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4GLOB_DLL std::ostream G4cout
void set(double x, double y, double z)
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
G4double GetMinExtent(const EAxis pAxis) const
G4double GetMaxExtent(const EAxis pAxis) const
const char * name(G4int ptype)