34#if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
49G4UGenericPolycone::G4UGenericPolycone(
const G4String& name,
55 : Base_t(
name, phiStart, phiTotal, numRZ, r, z)
57 wrStart = phiStart;
while (wrStart < 0) wrStart += twopi;
59 if (wrDelta <= 0 || wrDelta >= twopi*(1-
DBL_EPSILON))
65 for (
G4int i=0; i<numRZ; ++i)
67 rzcorners.emplace_back(r[i],z[i]);
69 std::vector<G4int> iout;
79G4UGenericPolycone::G4UGenericPolycone(__void__& a)
89G4UGenericPolycone::~G4UGenericPolycone() =
default;
96G4UGenericPolycone::G4UGenericPolycone(
const G4UGenericPolycone& source)
99 wrStart = source.wrStart;
100 wrDelta = source.wrDelta;
101 rzcorners = source.rzcorners;
110G4UGenericPolycone::operator=(
const G4UGenericPolycone& source)
112 if (
this == &source)
return *
this;
114 Base_t::operator=( source );
115 wrStart = source.wrStart;
116 wrDelta = source.wrDelta;
117 rzcorners = source.rzcorners;
122G4double G4UGenericPolycone::GetStartPhi()
const
126G4double G4UGenericPolycone::GetEndPhi()
const
128 return (wrStart + wrDelta);
130G4double G4UGenericPolycone::GetSinStartPhi()
const
132 if (IsOpen())
return 0.;
134 return std::sin(phi);
136G4double G4UGenericPolycone::GetCosStartPhi()
const
138 if (IsOpen())
return 1.;
140 return std::cos(phi);
142G4double G4UGenericPolycone::GetSinEndPhi()
const
144 if (IsOpen())
return 0.;
146 return std::sin(phi);
148G4double G4UGenericPolycone::GetCosEndPhi()
const
150 if (IsOpen())
return 1.;
152 return std::cos(phi);
154G4bool G4UGenericPolycone::IsOpen()
const
156 return (wrDelta < twopi);
158G4int G4UGenericPolycone::GetNumRZCorner()
const
160 return rzcorners.size();
174G4VSolid* G4UGenericPolycone::Clone()
const
176 return new G4UGenericPolycone(*
this);
187 G4double rmin = kInfinity, rmax = -kInfinity;
188 G4double zmin = kInfinity, zmax = -kInfinity;
190 for (
G4int i=0; i<GetNumRZCorner(); ++i)
193 if (corner.
r < rmin) rmin = corner.
r;
194 if (corner.
r > rmax) rmax = corner.
r;
195 if (corner.
z < zmin) zmin = corner.
z;
196 if (corner.
z > zmax) zmax = corner.
z;
203 GetSinStartPhi(),GetCosStartPhi(),
204 GetSinEndPhi(),GetCosEndPhi(),
206 pMin.
set(vmin.
x(),vmin.
y(),zmin);
207 pMax.
set(vmax.
x(),vmax.
y(),zmax);
211 pMin.
set(-rmax,-rmax, zmin);
212 pMax.
set( rmax, rmax, zmax);
217 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
219 std::ostringstream message;
220 message <<
"Bad bounding box (min >= max) for solid: "
222 <<
"\npMin = " << pMin
223 <<
"\npMax = " << pMax;
224 G4Exception(
"G4UGenericPolycone::BoundingLimits()",
"GeomMgt0001",
235G4UGenericPolycone::CalculateExtent(
const EAxis pAxis,
245 BoundingLimits(bmin,bmax);
248 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
250 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
252 return exist = pMin < pMax;
265 for (
G4int i=0; i<GetNumRZCorner(); ++i)
268 contourRZ.emplace_back(corner.
r,corner.
z);
271 if (area < 0.) std::reverse(contourRZ.begin(),contourRZ.end());
276 std::ostringstream message;
277 message <<
"Triangulation of RZ contour has failed for solid: "
279 <<
"\nExtent has been calculated using boundary box";
280 G4Exception(
"G4UGenericPolycone::CalculateExtent()",
282 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
286 const G4int NSTEPS = 24;
291 G4double dphi = IsOpen() ? ephi-sphi : twopi;
292 G4int ksteps = (dphi <= astep) ? 1 : (
G4int)((dphi-deg)/astep) + 1;
295 G4double sinHalf = std::sin(0.5*ang);
296 G4double cosHalf = std::cos(0.5*ang);
297 G4double sinStep = 2.*sinHalf*cosHalf;
298 G4double cosStep = 1. - 2.*sinHalf*sinHalf;
300 G4double sinStart = GetSinStartPhi();
301 G4double cosStart = GetCosStartPhi();
306 std::vector<const G4ThreeVectorList *> polygons;
307 polygons.resize(ksteps+2);
309 for (
G4int k=0; k<ksteps+2; ++k) pols[k].resize(6);
310 for (
G4int k=0; k<ksteps+2; ++k) polygons[k] = &pols[k];
317 G4int ntria = triangles.size()/3;
318 for (
G4int i=0; i<ntria; ++i)
321 for (
G4int k=0; k<3; ++k)
323 G4int e0 = i3+k, e1 = (k<2) ? e0+1 : i3;
326 r0[k2+0] = triangles[e0].x();
z0[k2+0] = triangles[e0].y();
327 r0[k2+1] = triangles[e1].x();
z0[k2+1] = triangles[e1].y();
331 if (z0[k2+1] - z0[k2+0] <= 0)
continue;
337 G4double sinCur = sinStart*cosHalf + cosStart*sinHalf;
338 G4double cosCur = cosStart*cosHalf - sinStart*sinHalf;
339 for (
G4int j=0; j<6; ++j)
341 pols[0][j].set(r0[j]*cosStart,r0[j]*sinStart,z0[j]);
343 for (
G4int k=1; k<ksteps+1; ++k)
345 for (
G4int j=0; j<6; ++j)
347 pols[k][j].set(r1[j]*cosCur,r1[j]*sinCur,z0[j]);
350 sinCur = sinCur*cosStep + cosCur*sinStep;
351 cosCur = cosCur*cosStep - sinTmp*sinStep;
353 for (
G4int j=0; j<6; ++j)
355 pols[ksteps+1][j].set(r0[j]*cosEnd,r0[j]*sinEnd,z0[j]);
361 if (!benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,emin,emax))
continue;
362 if (emin < pMin) pMin = emin;
363 if (emax > pMax) pMax = emax;
364 if (eminlim > pMin && emaxlim < pMax)
return true;
366 return (pMin < pMax);
373G4Polyhedron* G4UGenericPolycone::CreatePolyhedron()
const
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)
G4double GetMinExtent(const EAxis pAxis) const
G4double GetMaxExtent(const EAxis pAxis) const
const char * name(G4int ptype)