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);
105G4UExtrudedSolid::G4UExtrudedSolid(__void__& a)
115G4UExtrudedSolid::~G4UExtrudedSolid() =
default;
122G4UExtrudedSolid::G4UExtrudedSolid(
const G4UExtrudedSolid &source)
133G4UExtrudedSolid::operator=(
const G4UExtrudedSolid &source)
135 if (
this == &source)
return *
this;
137 Base_t::operator=( source );
147G4int G4UExtrudedSolid::GetNofVertices()
const
149 return Base_t::GetNVertices();
155 Base_t::GetVertex(i, xx, yy);
159std::vector<G4TwoVector> G4UExtrudedSolid::GetPolygon()
const
161 std::vector<G4TwoVector> pol;
162 for (
unsigned int i = 0; i < Base_t::GetNVertices(); ++i)
164 pol.push_back(GetVertex(i));
169G4int G4UExtrudedSolid::GetNofZSections()
const
171 return Base_t::GetNSections();
174G4UExtrudedSolid::ZSection G4UExtrudedSolid::GetZSection(
G4int i)
const
176 vecgeom::XtruSection sect = Base_t::GetSection(i);
177 return { sect.fOrigin[2],
182std::vector<G4UExtrudedSolid::ZSection> G4UExtrudedSolid::GetZSections()
const
184 std::vector<G4UExtrudedSolid::ZSection> sections;
185 for (
unsigned int i = 0; i < Base_t::GetNSections(); ++i)
187 vecgeom::XtruSection sect = Base_t::GetSection(i);
188 sections.emplace_back(sect.fOrigin[2],
203 static G4bool checkBBox =
true;
205 G4double xmin0 = kInfinity, xmax0 = -kInfinity;
206 G4double ymin0 = kInfinity, ymax0 = -kInfinity;
208 for (
G4int i=0; i<GetNofVertices(); ++i)
212 if (x < xmin0) xmin0 = x;
213 if (x > xmax0) xmax0 = x;
215 if (y < ymin0) ymin0 = y;
216 if (y > ymax0) ymax0 = y;
219 G4double xmin = kInfinity, xmax = -kInfinity;
220 G4double ymin = kInfinity, ymax = -kInfinity;
222 G4int nsect = GetNofZSections();
223 for (
G4int i=0; i<nsect; ++i)
225 ZSection zsect = GetZSection(i);
229 xmin = std::min(xmin,xmin0*scale+dx);
230 xmax = std::max(xmax,xmax0*scale+dx);
231 ymin = std::min(ymin,ymin0*scale+dy);
232 ymax = std::max(ymax,ymax0*scale+dy);
236 G4double zmax = GetZSection(nsect-1).fZ;
238 pMin.
set(xmin,ymin,zmin);
239 pMax.
set(xmax,ymax,zmax);
243 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
245 std::ostringstream message;
246 message <<
"Bad bounding box (min >= max) for solid: "
248 <<
"\npMin = " << pMin
249 <<
"\npMax = " << pMax;
250 G4Exception(
"G4UExtrudedSolid::BoundingLimits()",
"GeomMgt0001",
260 Base_t::Extent(vmin,vmax);
268 std::ostringstream message;
269 message <<
"Inconsistency in bounding boxes for solid: "
271 <<
"\nBBox min: wrapper = " << pMin <<
" solid = " << vmin
272 <<
"\nBBox max: wrapper = " << pMax <<
" solid = " << vmax;
273 G4Exception(
"G4UExtrudedSolid::BoundingLimits()",
"GeomMgt0001",
286G4UExtrudedSolid::CalculateExtent(
const EAxis pAxis,
296 BoundingLimits(bmin,bmax);
299 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
301 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
303 return exist = pMin < pMax;
318 std::ostringstream message;
319 message <<
"Triangulation of the base polygon has failed for solid: "
321 <<
"\nExtent has been calculated using boundary box";
324 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
328 G4int nsect = GetNofZSections();
329 std::vector<const G4ThreeVectorList *> polygons;
330 polygons.resize(nsect);
336 G4int ntria = triangles.size()/3;
337 for (
G4int i=0; i<ntria; ++i)
340 for (
G4int k=0; k<nsect; ++k)
342 ZSection zsect = GetZSection(k);
349 auto iter = ptr->begin();
350 G4double x0 = triangles[i3+0].x()*scale+dx;
351 G4double y0 = triangles[i3+0].y()*scale+dy;
354 G4double x1 = triangles[i3+1].x()*scale+dx;
355 G4double y1 = triangles[i3+1].y()*scale+dy;
358 G4double x2 = triangles[i3+2].x()*scale+dx;
359 G4double y2 = triangles[i3+2].y()*scale+dy;
366 if (!benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,emin,emax))
continue;
367 if (emin < pMin) pMin = emin;
368 if (emax > pMax) pMax = emax;
369 if (eminlim > pMin && emaxlim < pMax)
break;
372 for (
G4int k=0; k<nsect; ++k) {
delete polygons[k]; polygons[k]=
nullptr;}
373 return (pMin < pMax);
381G4Polyhedron* G4UExtrudedSolid::CreatePolyhedron ()
const
383 unsigned int nFacets = Base_t::GetStruct().fTslHelper.fFacets.size();
384 unsigned int nVertices = Base_t::GetStruct().fTslHelper.fVertices.size();
389 for (
unsigned int i = 0; i < nVertices; ++i)
391 U3Vector v = Base_t::GetStruct().fTslHelper.fVertices[i];
392 polyhedron->SetVertex(i+1,
G4ThreeVector(v.x(), v.y(), v.z()));
396 for (
unsigned int i = 0; i < nFacets; ++i)
399 G4int i1 = Base_t::GetStruct().fTslHelper.fFacets[i]->fIndices[0] + 1;
400 G4int i2 = Base_t::GetStruct().fTslHelper.fFacets[i]->fIndices[1] + 1;
401 G4int i3 = Base_t::GetStruct().fTslHelper.fFacets[i]->fIndices[2] + 1;
402 polyhedron->SetFacet(i+1, i1, i2, i3);
404 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)
G4double GetMinExtent(const EAxis pAxis) const
G4double GetMaxExtent(const EAxis pAxis) const
const char * name(G4int ptype)