34#if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
46G4UExtrudedSolid::G4UExtrudedSolid(
const G4String& name,
47 const std::vector<G4TwoVector>& polygon,
48 const std::vector<ZSection>& zsections)
51 unsigned int nVertices = polygon.size();
52 unsigned int nSections = zsections.size();
54 vecgeom::XtruVertex2* vertices =
new vecgeom::XtruVertex2[nVertices];
55 vecgeom::XtruSection* sections =
new vecgeom::XtruSection[nSections];
57 for (
unsigned int i = 0; i < nVertices; ++i)
59 vertices[i].x = polygon[i].x();
60 vertices[i].y = polygon[i].y();
62 for (
unsigned int i = 0; i < nSections; ++i)
64 sections[i].fOrigin.Set(zsections[i].fOffset.x(),
65 zsections[i].fOffset.y(),
67 sections[i].fScale = zsections[i].fScale;
69 Base_t::Initialize(nVertices, vertices, nSections, sections);
75G4UExtrudedSolid::G4UExtrudedSolid(
const G4String& name,
76 const std::vector<G4TwoVector>& polygon,
82 unsigned int nVertices = polygon.size();
83 unsigned int nSections = 2;
85 vecgeom::XtruVertex2* vertices =
new vecgeom::XtruVertex2[nVertices];
86 vecgeom::XtruSection* sections =
new vecgeom::XtruSection[nSections];
88 for (
unsigned int i = 0; i < nVertices; ++i)
90 vertices[i].x = polygon[i].x();
91 vertices[i].y = polygon[i].y();
93 sections[0].fOrigin.Set(off1.
x(), off1.
y(), -halfZ);
94 sections[0].fScale = scale1;
95 sections[1].fOrigin.Set(off2.
x(), off2.
y(), halfZ);
96 sections[1].fScale = scale2;
97 Base_t::Initialize(nVertices, vertices, nSections, sections);
107G4UExtrudedSolid::G4UExtrudedSolid(__void__& a)
117G4UExtrudedSolid::~G4UExtrudedSolid()
126G4UExtrudedSolid::G4UExtrudedSolid(
const G4UExtrudedSolid &source)
137G4UExtrudedSolid::operator=(
const G4UExtrudedSolid &source)
139 if (
this == &source)
return *
this;
141 Base_t::operator=( source );
151G4int G4UExtrudedSolid::GetNofVertices()
const
153 return Base_t::GetNVertices();
158 Base_t::GetVertex(i, xx, yy);
161std::vector<G4TwoVector> G4UExtrudedSolid::GetPolygon()
const
163 std::vector<G4TwoVector> pol;
164 for (
unsigned int i = 0; i < Base_t::GetNVertices(); ++i)
166 pol.push_back(GetVertex(i));
170G4int G4UExtrudedSolid::GetNofZSections()
const
172 return Base_t::GetNSections();
174G4UExtrudedSolid::ZSection G4UExtrudedSolid::GetZSection(
G4int i)
const
176 vecgeom::XtruSection sect = Base_t::GetSection(i);
177 return ZSection(sect.fOrigin[2],
181std::vector<G4UExtrudedSolid::ZSection> G4UExtrudedSolid::GetZSections()
const
183 std::vector<G4UExtrudedSolid::ZSection> sections;
184 for (
unsigned int i = 0; i < Base_t::GetNSections(); ++i)
186 vecgeom::XtruSection sect = Base_t::GetSection(i);
187 sections.push_back(ZSection(sect.fOrigin[2],
202 static G4bool checkBBox =
true;
204 G4double xmin0 = kInfinity, xmax0 = -kInfinity;
205 G4double ymin0 = kInfinity, ymax0 = -kInfinity;
207 for (
G4int i=0; i<GetNofVertices(); ++i)
211 if (x < xmin0) xmin0 = x;
212 if (x > xmax0) xmax0 = x;
214 if (y < ymin0) ymin0 = y;
215 if (y > ymax0) ymax0 = y;
218 G4double xmin = kInfinity, xmax = -kInfinity;
219 G4double ymin = kInfinity, ymax = -kInfinity;
221 G4int nsect = GetNofZSections();
222 for (
G4int i=0; i<nsect; ++i)
224 ZSection zsect = GetZSection(i);
228 xmin = std::min(xmin,xmin0*scale+dx);
229 xmax = std::max(xmax,xmax0*scale+dx);
230 ymin = std::min(ymin,ymin0*scale+dy);
231 ymax = std::max(ymax,ymax0*scale+dy);
235 G4double zmax = GetZSection(nsect-1).fZ;
237 pMin.
set(xmin,ymin,zmin);
238 pMax.
set(xmax,ymax,zmax);
242 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
244 std::ostringstream message;
245 message <<
"Bad bounding box (min >= max) for solid: "
247 <<
"\npMin = " << pMin
248 <<
"\npMax = " << pMax;
249 G4Exception(
"G4UExtrudedSolid::BoundingLimits()",
"GeomMgt0001",
259 Base_t::Extent(vmin,vmax);
267 std::ostringstream message;
268 message <<
"Inconsistency in bounding boxes for solid: "
270 <<
"\nBBox min: wrapper = " << pMin <<
" solid = " << vmin
271 <<
"\nBBox max: wrapper = " << pMax <<
" solid = " << vmax;
272 G4Exception(
"G4UExtrudedSolid::BoundingLimits()",
"GeomMgt0001",
285G4UExtrudedSolid::CalculateExtent(
const EAxis pAxis,
295 BoundingLimits(bmin,bmax);
298 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
300 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
302 return exist = (pMin < pMax) ?
true :
false;
317 std::ostringstream message;
318 message <<
"Triangulation of the base polygon has failed for solid: "
320 <<
"\nExtent has been calculated using boundary box";
323 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
327 G4int nsect = GetNofZSections();
328 std::vector<const G4ThreeVectorList *> polygons;
329 polygons.resize(nsect);
335 G4int ntria = triangles.size()/3;
336 for (
G4int i=0; i<ntria; ++i)
339 for (
G4int k=0; k<nsect; ++k)
341 ZSection zsect = GetZSection(k);
348 G4ThreeVectorList::iterator iter = ptr->begin();
349 G4double x0 = triangles[i3+0].x()*scale+dx;
350 G4double y0 = triangles[i3+0].y()*scale+dy;
353 G4double x1 = triangles[i3+1].x()*scale+dx;
354 G4double y1 = triangles[i3+1].y()*scale+dy;
357 G4double x2 = triangles[i3+2].x()*scale+dx;
358 G4double y2 = triangles[i3+2].y()*scale+dy;
365 if (!benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,emin,emax))
continue;
366 if (emin < pMin) pMin = emin;
367 if (emax > pMax) pMax = emax;
368 if (eminlim > pMin && emaxlim < pMax)
break;
371 for (
G4int k=0; k<nsect; ++k) {
delete polygons[k]; polygons[k]=0;}
372 return (pMin < pMax);
380G4Polyhedron* G4UExtrudedSolid::CreatePolyhedron ()
const
382 unsigned int nFacets = Base_t::GetStruct().fTslHelper.fFacets.size();
383 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];
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;
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)
void AddFacet(const G4int iv1, const G4int iv2, const G4int iv3, const G4int iv4=0)
void AddVertex(const G4ThreeVector &v)
G4double GetMinExtent(const EAxis pAxis) const
G4double GetMaxExtent(const EAxis pAxis) const
const char * name(G4int ptype)