34#if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
50G4UPolyhedra::G4UPolyhedra(
const G4String& name,
58 : Base_t(
name, phiStart, phiTotal, numSide,
59 numZPlanes, zPlane, rInner, rOuter)
62 SetOriginalParameters();
69 if (wrDelta <= 0. || wrDelta >= twopi*(1-
DBL_EPSILON))
74 G4double convertRad = 1./std::cos(0.5*wrDelta/wrNumSide);
76 for (
G4int i=0; i<numZPlanes; ++i)
80 rzcorners.emplace_back(r,z);
82 for (
G4int i=numZPlanes-1; i>=0; --i)
86 rzcorners.emplace_back(r,z);
88 std::vector<G4int> iout;
97G4UPolyhedra::G4UPolyhedra(
const G4String& name,
104 : Base_t(
name, phiStart, phiTotal, numSide, numRZ, r, z)
107 SetOriginalParameters();
114 if (wrDelta <= 0. || wrDelta >= twopi*(1-
DBL_EPSILON))
120 for (
G4int i=0; i<numRZ; ++i)
122 rzcorners.emplace_back(r[i],z[i]);
124 std::vector<G4int> iout;
134G4UPolyhedra::G4UPolyhedra( __void__& a )
144G4UPolyhedra::~G4UPolyhedra() =
default;
151G4UPolyhedra::G4UPolyhedra(
const G4UPolyhedra& source )
154 fGenericPgon = source.fGenericPgon;
155 fOriginalParameters = source.fOriginalParameters;
156 wrStart = source.wrStart;
157 wrDelta = source.wrDelta;
158 wrNumSide = source.wrNumSide;
159 rzcorners = source.rzcorners;
167G4UPolyhedra& G4UPolyhedra::operator=(
const G4UPolyhedra& source )
169 if (
this == &source)
return *
this;
171 Base_t::operator=( source );
172 fGenericPgon = source.fGenericPgon;
173 fOriginalParameters = source.fOriginalParameters;
174 wrStart = source.wrStart;
175 wrDelta = source.wrDelta;
176 wrNumSide = source.wrNumSide;
177 rzcorners = source.rzcorners;
187G4int G4UPolyhedra::GetNumSide()
const
191G4double G4UPolyhedra::GetStartPhi()
const
195G4double G4UPolyhedra::GetEndPhi()
const
197 return (wrStart + wrDelta);
199G4double G4UPolyhedra::GetSinStartPhi()
const
202 return std::sin(phi);
204G4double G4UPolyhedra::GetCosStartPhi()
const
207 return std::cos(phi);
209G4double G4UPolyhedra::GetSinEndPhi()
const
212 return std::sin(phi);
214G4double G4UPolyhedra::GetCosEndPhi()
const
217 return std::cos(phi);
219G4bool G4UPolyhedra::IsOpen()
const
221 return (wrDelta < twopi);
223G4bool G4UPolyhedra::IsGeneric()
const
227G4int G4UPolyhedra::GetNumRZCorner()
const
229 return rzcorners.size();
242void G4UPolyhedra::SetOriginalParameters()
246 G4int numPlanes = GetZSegmentCount() + 1;
247 G4int numSides = GetSideCount();
249 fOriginalParameters.Start_angle = startPhi;
250 fOriginalParameters.Opening_angle = deltaPhi;
251 fOriginalParameters.Num_z_planes = numPlanes;
252 fOriginalParameters.numSide = numSides;
254 delete [] fOriginalParameters.Z_values;
255 delete [] fOriginalParameters.Rmin;
256 delete [] fOriginalParameters.Rmax;
257 fOriginalParameters.Z_values =
new G4double[numPlanes];
258 fOriginalParameters.Rmin =
new G4double[numPlanes];
259 fOriginalParameters.Rmax =
new G4double[numPlanes];
262 ? 1.0 : std::cos(0.5*deltaPhi/numSides);
263 for (
G4int i=0; i<numPlanes; ++i)
265 fOriginalParameters.Z_values[i] = GetZPlanes()[i];
266 fOriginalParameters.Rmax[i] = GetRMax()[i]/convertRad;
267 fOriginalParameters.Rmin[i] = GetRMin()[i]/convertRad;
272 fOriginalParameters = *pars;
273 fRebuildPolyhedron =
true;
277G4bool G4UPolyhedra::Reset()
281 std::ostringstream message;
282 message <<
"Solid " << GetName() <<
" built using generic construct."
283 <<
G4endl <<
"Not applicable to the generic construct !";
284 G4Exception(
"G4UPolyhedra::Reset()",
"GeomSolids1001",
292 wrStart = fOriginalParameters.Start_angle;
297 wrDelta = fOriginalParameters.Opening_angle;
298 if (wrDelta <= 0. || wrDelta >= twopi*(1-
DBL_EPSILON))
302 wrNumSide = fOriginalParameters.numSide;
304 for (
G4int i=0; i<fOriginalParameters.Num_z_planes; ++i)
306 G4double z = fOriginalParameters.Z_values[i];
307 G4double r = fOriginalParameters.Rmax[i];
308 rzcorners.emplace_back(r,z);
310 for (
G4int i=fOriginalParameters.Num_z_planes-1; i>=0; --i)
312 G4double z = fOriginalParameters.Z_values[i];
313 G4double r = fOriginalParameters.Rmin[i];
314 rzcorners.emplace_back(r,z);
316 std::vector<G4int> iout;
340G4VSolid* G4UPolyhedra::Clone()
const
342 return new G4UPolyhedra(*
this);
353 static G4bool checkBBox =
true;
354 static G4bool checkPhi =
true;
356 G4double rmin = kInfinity, rmax = -kInfinity;
357 G4double zmin = kInfinity, zmax = -kInfinity;
358 for (
G4int i=0; i<GetNumRZCorner(); ++i)
361 if (corner.
r < rmin) rmin = corner.
r;
362 if (corner.
r > rmax) rmax = corner.
r;
363 if (corner.
z < zmin) zmin = corner.
z;
364 if (corner.
z > zmax) zmax = corner.
z;
369 G4double dphi = IsOpen() ? ephi-sphi : twopi;
370 G4int ksteps = GetNumSide();
377 if (!IsOpen()) rmin = 0.;
378 G4double xmin = rmin*cosCur, xmax = xmin;
379 G4double ymin = rmin*sinCur, ymax = ymin;
380 for (
G4int k=0; k<ksteps+1; ++k)
383 if (x < xmin) xmin = x;
384 if (x > xmax) xmax = x;
386 if (y < ymin) ymin = y;
387 if (y > ymax) ymax = y;
391 if (xx < xmin) xmin = xx;
392 if (xx > xmax) xmax = xx;
394 if (yy < ymin) ymin = yy;
395 if (yy > ymax) ymax = yy;
398 sinCur = sinCur*cosStep + cosCur*sinStep;
399 cosCur = cosCur*cosStep - sinTmp*sinStep;
401 pMin.
set(xmin,ymin,zmin);
402 pMax.
set(xmax,ymax,zmax);
406 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
408 std::ostringstream message;
409 message <<
"Bad bounding box (min >= max) for solid: "
411 <<
"\npMin = " << pMin
412 <<
"\npMax = " << pMax;
413 G4Exception(
"G4UPolyhedra::BoundingLimits()",
"GeomMgt0001",
431 std::ostringstream message;
432 message <<
"Inconsistency in bounding boxes for solid: "
434 <<
"\nBBox min: wrapper = " << pMin <<
" solid = " << vmin
435 <<
"\nBBox max: wrapper = " << pMax <<
" solid = " << vmax;
436 G4Exception(
"G4UPolyhedra::BoundingLimits()",
"GeomMgt0001",
446 if (GetStartPhi() != GetPhiStart() ||
447 GetEndPhi() != GetPhiEnd() ||
448 GetNumSide() != GetSideCount() ||
449 IsOpen() != (Base_t::GetPhiDelta() < twopi))
451 std::ostringstream message;
452 message <<
"Inconsistency in Phi angles or # of sides for solid: "
454 <<
"\nPhi start : wrapper = " << GetStartPhi()
455 <<
" solid = " << GetPhiStart()
456 <<
"\nPhi end : wrapper = " << GetEndPhi()
457 <<
" solid = " << GetPhiEnd()
458 <<
"\nPhi # sides: wrapper = " << GetNumSide()
459 <<
" solid = " << GetSideCount()
460 <<
"\nPhi is open: wrapper = " << (IsOpen() ?
"true" :
"false")
462 << ((Base_t::GetPhiDelta() < twopi) ?
"true" :
"false");
463 G4Exception(
"G4UPolyhedra::BoundingLimits()",
"GeomMgt0001",
475G4UPolyhedra::CalculateExtent(
const EAxis pAxis,
485 BoundingLimits(bmin,bmax);
488 if (
true)
return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
490 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
492 return exist = pMin < pMax;
501 std::vector<G4int> iout;
506 for (
G4int i=0; i<GetNumRZCorner(); ++i)
509 contourRZ.emplace_back(corner.
r,corner.
z);
513 if (area < 0.) std::reverse(contourRZ.begin(),contourRZ.end());
518 std::ostringstream message;
519 message <<
"Triangulation of RZ contour has failed for solid: "
521 <<
"\nExtent has been calculated using boundary box";
524 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
530 G4double dphi = IsOpen() ? ephi-sphi : twopi;
531 G4int ksteps = GetNumSide();
535 G4double sinStart = GetSinStartPhi();
536 G4double cosStart = GetCosStartPhi();
539 std::vector<const G4ThreeVectorList *> polygons;
540 polygons.resize(ksteps+1);
541 for (
G4int k=0; k<ksteps+1; ++k)
549 G4int ntria = triangles.size()/3;
550 for (
G4int i=0; i<ntria; ++i)
555 for (
G4int k=0; k<ksteps+1; ++k)
558 auto iter = ptr->begin();
559 iter->set(triangles[i3+0].x()*cosCur,
560 triangles[i3+0].x()*sinCur,
561 triangles[i3+0].y());
563 iter->set(triangles[i3+1].x()*cosCur,
564 triangles[i3+1].x()*sinCur,
565 triangles[i3+1].y());
567 iter->set(triangles[i3+2].x()*cosCur,
568 triangles[i3+2].x()*sinCur,
569 triangles[i3+2].y());
572 sinCur = sinCur*cosStep + cosCur*sinStep;
573 cosCur = cosCur*cosStep - sinTmp*sinStep;
579 if (!benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,emin,emax))
continue;
580 if (emin < pMin) pMin = emin;
581 if (emax > pMax) pMax = emax;
582 if (eminlim > pMin && emaxlim < pMax)
break;
585 for (
G4int k=0; k<ksteps+1; ++k) {
delete polygons[k]; polygons[k]=
nullptr;}
586 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)