34#if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
44G4UExtrudedSolid::G4UExtrudedSolid(
const G4String& name,
45 const std::vector<G4TwoVector>& polygon,
46 const std::vector<ZSection>& zsections)
49 unsigned int nVertices = polygon.size();
50 unsigned int nSections = zsections.size();
52 auto vertices =
new vecgeom::XtruVertex2[nVertices];
53 auto sections =
new vecgeom::XtruSection[nSections];
55 for (
unsigned int i = 0; i < nVertices; ++i)
57 vertices[i].x = polygon[i].x();
58 vertices[i].y = polygon[i].y();
60 for (
unsigned int i = 0; i < nSections; ++i)
62 sections[i].fOrigin.Set(zsections[i].fOffset.x(),
63 zsections[i].fOffset.y(),
65 sections[i].fScale = zsections[i].fScale;
67 Base_t::Initialize(nVertices, vertices, nSections, sections);
73G4UExtrudedSolid::G4UExtrudedSolid(
const G4String& name,
74 const std::vector<G4TwoVector>& polygon,
80 unsigned int nVertices = polygon.size();
81 unsigned int nSections = 2;
83 auto vertices =
new vecgeom::XtruVertex2[nVertices];
84 auto sections =
new vecgeom::XtruSection[nSections];
86 for (
unsigned int i = 0; i < nVertices; ++i)
88 vertices[i].x = polygon[i].x();
89 vertices[i].y = polygon[i].y();
91 sections[0].fOrigin.Set(off1.
x(), off1.
y(), -halfZ);
92 sections[0].fScale = scale1;
93 sections[1].fOrigin.Set(off2.
x(), off2.
y(), halfZ);
94 sections[1].fScale = scale2;
95 Base_t::Initialize(nVertices, vertices, nSections, sections);
104G4UExtrudedSolid::G4UExtrudedSolid(
const G4UExtrudedSolid &source)
115G4UExtrudedSolid::operator=(
const G4UExtrudedSolid &source)
117 if (
this == &source)
return *
this;
119 Base_t::operator=( source );
129G4int G4UExtrudedSolid::GetNofVertices()
const
131 return Base_t::GetNVertices();
137 Base_t::GetVertex(i, xx, yy);
141std::vector<G4TwoVector> G4UExtrudedSolid::GetPolygon()
const
143 std::vector<G4TwoVector> pol;
144 for (
unsigned int i = 0; i < Base_t::GetNVertices(); ++i)
146 pol.push_back(GetVertex(i));
151G4int G4UExtrudedSolid::GetNofZSections()
const
153 return Base_t::GetNSections();
156G4UExtrudedSolid::ZSection G4UExtrudedSolid::GetZSection(
G4int i)
const
158 vecgeom::XtruSection sect = Base_t::GetSection(i);
159 return { sect.fOrigin[2],
164std::vector<G4UExtrudedSolid::ZSection> G4UExtrudedSolid::GetZSections()
const
166 std::vector<G4UExtrudedSolid::ZSection> sections;
167 for (
unsigned int i = 0; i < Base_t::GetNSections(); ++i)
169 vecgeom::XtruSection sect = Base_t::GetSection(i);
170 sections.emplace_back(sect.fOrigin[2],
185 static G4bool checkBBox =
true;
187 G4double xmin0 = kInfinity, xmax0 = -kInfinity;
188 G4double ymin0 = kInfinity, ymax0 = -kInfinity;
190 for (
G4int i=0; i<GetNofVertices(); ++i)
194 if (x < xmin0) xmin0 = x;
195 if (x > xmax0) xmax0 = x;
197 if (y < ymin0) ymin0 = y;
198 if (y > ymax0) ymax0 = y;
201 G4double xmin = kInfinity, xmax = -kInfinity;
202 G4double ymin = kInfinity, ymax = -kInfinity;
204 G4int nsect = GetNofZSections();
205 for (
G4int i=0; i<nsect; ++i)
207 ZSection zsect = GetZSection(i);
211 xmin = std::min(xmin,xmin0*scale+dx);
212 xmax = std::max(xmax,xmax0*scale+dx);
213 ymin = std::min(ymin,ymin0*scale+dy);
214 ymax = std::max(ymax,ymax0*scale+dy);
218 G4double zmax = GetZSection(nsect-1).fZ;
220 pMin.
set(xmin,ymin,zmin);
221 pMax.
set(xmax,ymax,zmax);
225 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
227 std::ostringstream message;
228 message <<
"Bad bounding box (min >= max) for solid: "
230 <<
"\npMin = " << pMin
231 <<
"\npMax = " << pMax;
232 G4Exception(
"G4UExtrudedSolid::BoundingLimits()",
"GeomMgt0001",
242 Base_t::Extent(vmin,vmax);
250 std::ostringstream message;
251 message <<
"Inconsistency in bounding boxes for solid: "
253 <<
"\nBBox min: wrapper = " << pMin <<
" solid = " << vmin
254 <<
"\nBBox max: wrapper = " << pMax <<
" solid = " << vmax;
255 G4Exception(
"G4UExtrudedSolid::BoundingLimits()",
"GeomMgt0001",
268G4UExtrudedSolid::CalculateExtent(
const EAxis pAxis,
278 BoundingLimits(bmin,bmax);
281 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
283 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
285 return exist = pMin < pMax;
300 std::ostringstream message;
301 message <<
"Triangulation of the base polygon has failed for solid: "
303 <<
"\nExtent has been calculated using boundary box";
306 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
310 G4int nsect = GetNofZSections();
311 std::vector<const G4ThreeVectorList *> polygons;
312 polygons.resize(nsect);
318 G4int ntria = triangles.size()/3;
319 for (
G4int i=0; i<ntria; ++i)
322 for (
G4int k=0; k<nsect; ++k)
324 ZSection zsect = GetZSection(k);
331 auto iter = ptr->begin();
332 G4double x0 = triangles[i3+0].x()*scale+dx;
333 G4double y0 = triangles[i3+0].y()*scale+dy;
336 G4double x1 = triangles[i3+1].x()*scale+dx;
337 G4double y1 = triangles[i3+1].y()*scale+dy;
340 G4double x2 = triangles[i3+2].x()*scale+dx;
341 G4double y2 = triangles[i3+2].y()*scale+dy;
348 if (!benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,emin,emax))
continue;
349 if (emin < pMin) pMin = emin;
350 if (emax > pMax) pMax = emax;
351 if (eminlim > pMin && emaxlim < pMax)
break;
354 for (
G4int k=0; k<nsect; ++k) {
delete polygons[k]; polygons[k]=
nullptr;}
355 return (pMin < pMax);
363G4Polyhedron* G4UExtrudedSolid::CreatePolyhedron ()
const
365 unsigned int nFacets = Base_t::GetStruct().fTslHelper.fFacets.size();
366 unsigned int nVertices = Base_t::GetStruct().fTslHelper.fVertices.size();
371 for (
unsigned int i = 0; i < nVertices; ++i)
373 U3Vector v = Base_t::GetStruct().fTslHelper.fVertices[i];
374 polyhedron->SetVertex(i+1,
G4ThreeVector(v.x(), v.y(), v.z()));
378 for (
unsigned int i = 0; i < nFacets; ++i)
381 G4int i1 = Base_t::GetStruct().fTslHelper.fFacets[i]->fIndices[0] + 1;
382 G4int i2 = Base_t::GetStruct().fTslHelper.fFacets[i]->fIndices[1] + 1;
383 G4int i3 = Base_t::GetStruct().fTslHelper.fFacets[i]->fIndices[2] + 1;
384 polyhedron->SetFacet(i+1, i1, i2, i3);
386 polyhedron->SetReferences();
const G4double kCarTolerance
std::vector< G4ThreeVector > G4ThreeVectorList
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
CLHEP::Hep3Vector G4ThreeVector
CLHEP::Hep2Vector G4TwoVector
G4GLOB_DLL std::ostream G4cout
void set(double x, double y, double z)
G4BoundingEnvelope is a helper class to facilitate calculation of the extent of a solid within the li...
G4VoxelLimits represents limitation/restrictions of space, where restrictions are only made perpendic...
G4double GetMinExtent(const EAxis pAxis) const
G4double GetMaxExtent(const EAxis pAxis) const
const char * name(G4int ptype)