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)
69 std::vector<G4int> iout;
79G4UGenericPolycone::G4UGenericPolycone(__void__& a)
89G4UGenericPolycone::~G4UGenericPolycone()
98G4UGenericPolycone::G4UGenericPolycone(
const G4UGenericPolycone& source)
101 wrStart = source.wrStart;
102 wrDelta = source.wrDelta;
103 rzcorners = source.rzcorners;
112G4UGenericPolycone::operator=(
const G4UGenericPolycone& source)
114 if (
this == &source)
return *
this;
116 Base_t::operator=( source );
117 wrStart = source.wrStart;
118 wrDelta = source.wrDelta;
119 rzcorners = source.rzcorners;
124G4double G4UGenericPolycone::GetStartPhi()
const
128G4double G4UGenericPolycone::GetEndPhi()
const
130 return (wrStart + wrDelta);
132G4double G4UGenericPolycone::GetSinStartPhi()
const
134 if (IsOpen())
return 0.;
136 return std::sin(phi);
138G4double G4UGenericPolycone::GetCosStartPhi()
const
140 if (IsOpen())
return 1.;
142 return std::cos(phi);
144G4double G4UGenericPolycone::GetSinEndPhi()
const
146 if (IsOpen())
return 0.;
148 return std::sin(phi);
150G4double G4UGenericPolycone::GetCosEndPhi()
const
152 if (IsOpen())
return 1.;
154 return std::cos(phi);
156G4bool G4UGenericPolycone::IsOpen()
const
158 return (wrDelta < twopi);
160G4int G4UGenericPolycone::GetNumRZCorner()
const
162 return rzcorners.size();
176G4VSolid* G4UGenericPolycone::Clone()
const
178 return new G4UGenericPolycone(*
this);
189 G4double rmin = kInfinity, rmax = -kInfinity;
190 G4double zmin = kInfinity, zmax = -kInfinity;
192 for (
G4int i=0; i<GetNumRZCorner(); ++i)
195 if (corner.
r < rmin) rmin = corner.
r;
196 if (corner.
r > rmax) rmax = corner.
r;
197 if (corner.
z < zmin) zmin = corner.
z;
198 if (corner.
z > zmax) zmax = corner.
z;
205 GetSinStartPhi(),GetCosStartPhi(),
206 GetSinEndPhi(),GetCosEndPhi(),
208 pMin.
set(vmin.
x(),vmin.
y(),zmin);
209 pMax.
set(vmax.
x(),vmax.
y(),zmax);
213 pMin.
set(-rmax,-rmax, zmin);
214 pMax.
set( rmax, rmax, zmax);
219 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
221 std::ostringstream message;
222 message <<
"Bad bounding box (min >= max) for solid: "
224 <<
"\npMin = " << pMin
225 <<
"\npMax = " << pMax;
226 G4Exception(
"G4UGenericPolycone::BoundingLimits()",
"GeomMgt0001",
237G4UGenericPolycone::CalculateExtent(
const EAxis pAxis,
247 BoundingLimits(bmin,bmax);
250 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
252 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
254 return exist = (pMin < pMax) ?
true :
false;
267 for (
G4int i=0; i<GetNumRZCorner(); ++i)
273 if (area < 0.) std::reverse(contourRZ.begin(),contourRZ.end());
278 std::ostringstream message;
279 message <<
"Triangulation of RZ contour has failed for solid: "
281 <<
"\nExtent has been calculated using boundary box";
282 G4Exception(
"G4UGenericPolycone::CalculateExtent()",
284 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
288 const G4int NSTEPS = 24;
293 G4double dphi = IsOpen() ? ephi-sphi : twopi;
294 G4int ksteps = (dphi <= astep) ? 1 : (
G4int)((dphi-deg)/astep) + 1;
297 G4double sinHalf = std::sin(0.5*ang);
298 G4double cosHalf = std::cos(0.5*ang);
299 G4double sinStep = 2.*sinHalf*cosHalf;
300 G4double cosStep = 1. - 2.*sinHalf*sinHalf;
302 G4double sinStart = GetSinStartPhi();
303 G4double cosStart = GetCosStartPhi();
308 std::vector<const G4ThreeVectorList *> polygons;
309 polygons.resize(ksteps+2);
311 for (
G4int k=0; k<ksteps+2; ++k) pols[k].resize(6);
312 for (
G4int k=0; k<ksteps+2; ++k) polygons[k] = &pols[k];
319 G4int ntria = triangles.size()/3;
320 for (
G4int i=0; i<ntria; ++i)
323 for (
G4int k=0; k<3; ++k)
325 G4int e0 = i3+k, e1 = (k<2) ? e0+1 : i3;
328 r0[k2+0] = triangles[e0].x();
z0[k2+0] = triangles[e0].y();
329 r0[k2+1] = triangles[e1].x();
z0[k2+1] = triangles[e1].y();
333 if (z0[k2+1] - z0[k2+0] <= 0)
continue;
339 G4double sinCur = sinStart*cosHalf + cosStart*sinHalf;
340 G4double cosCur = cosStart*cosHalf - sinStart*sinHalf;
341 for (
G4int j=0; j<6; ++j)
343 pols[0][j].set(r0[j]*cosStart,r0[j]*sinStart,z0[j]);
345 for (
G4int k=1; k<ksteps+1; ++k)
347 for (
G4int j=0; j<6; ++j)
349 pols[k][j].set(r1[j]*cosCur,r1[j]*sinCur,z0[j]);
352 sinCur = sinCur*cosStep + cosCur*sinStep;
353 cosCur = cosCur*cosStep - sinTmp*sinStep;
355 for (
G4int j=0; j<6; ++j)
357 pols[ksteps+1][j].set(r0[j]*cosEnd,r0[j]*sinEnd,z0[j]);
363 if (!benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,emin,emax))
continue;
364 if (emin < pMin) pMin = emin;
365 if (emax > pMax) pMax = emax;
366 if (eminlim > pMin && emaxlim < pMax)
return true;
368 return (pMin < pMax);
375G4Polyhedron* G4UGenericPolycone::CreatePolyhedron()
const
const G4double kCarTolerance
std::vector< G4ThreeVector > G4ThreeVectorList
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
CLHEP::Hep2Vector G4TwoVector
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)