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 vecgeom::XtruVertex2* vertices =
new vecgeom::XtruVertex2[nVertices];
53 vecgeom::XtruSection* 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 vecgeom::XtruVertex2* vertices =
new vecgeom::XtruVertex2[nVertices];
84 vecgeom::XtruSection* 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()
124G4UExtrudedSolid::G4UExtrudedSolid(
const G4UExtrudedSolid &source)
135G4UExtrudedSolid::operator=(
const G4UExtrudedSolid &source)
137 if (
this == &source)
return *
this;
139 Base_t::operator=( source );
149G4int G4UExtrudedSolid::GetNofVertices()
const
151 return Base_t::GetNVertices();
156 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));
168G4int G4UExtrudedSolid::GetNofZSections()
const
170 return Base_t::GetNSections();
172G4UExtrudedSolid::ZSection G4UExtrudedSolid::GetZSection(
G4int i)
const
174 vecgeom::XtruSection sect = Base_t::GetSection(i);
175 return ZSection(sect.fOrigin[2],
179std::vector<G4UExtrudedSolid::ZSection> G4UExtrudedSolid::GetZSections()
const
181 std::vector<G4UExtrudedSolid::ZSection> sections;
182 for (
unsigned int i = 0; i < Base_t::GetNSections(); ++i)
184 vecgeom::XtruSection sect = Base_t::GetSection(i);
185 sections.push_back(ZSection(sect.fOrigin[2],
200 static G4bool checkBBox =
true;
202 G4double xmin0 = kInfinity, xmax0 = -kInfinity;
203 G4double ymin0 = kInfinity, ymax0 = -kInfinity;
205 for (
G4int i=0; i<GetNofVertices(); ++i)
209 if (x < xmin0) xmin0 = x;
210 if (x > xmax0) xmax0 = x;
212 if (y < ymin0) ymin0 = y;
213 if (y > ymax0) ymax0 = y;
216 G4double xmin = kInfinity, xmax = -kInfinity;
217 G4double ymin = kInfinity, ymax = -kInfinity;
219 G4int nsect = GetNofZSections();
220 for (
G4int i=0; i<nsect; ++i)
222 ZSection zsect = GetZSection(i);
226 xmin = std::min(xmin,xmin0*scale+dx);
227 xmax = std::max(xmax,xmax0*scale+dx);
228 ymin = std::min(ymin,ymin0*scale+dy);
229 ymax = std::max(ymax,ymax0*scale+dy);
233 G4double zmax = GetZSection(nsect-1).fZ;
235 pMin.
set(xmin,ymin,zmin);
236 pMax.
set(xmax,ymax,zmax);
240 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
242 std::ostringstream message;
243 message <<
"Bad bounding box (min >= max) for solid: "
245 <<
"\npMin = " << pMin
246 <<
"\npMax = " << pMax;
247 G4Exception(
"G4UExtrudedSolid::BoundingLimits()",
"GeomMgt0001",
257 Base_t::Extent(vmin,vmax);
265 std::ostringstream message;
266 message <<
"Inconsistency in bounding boxes for solid: "
268 <<
"\nBBox min: wrapper = " << pMin <<
" solid = " << vmin
269 <<
"\nBBox max: wrapper = " << pMax <<
" solid = " << vmax;
270 G4Exception(
"G4UExtrudedSolid::BoundingLimits()",
"GeomMgt0001",
283G4UExtrudedSolid::CalculateExtent(
const EAxis pAxis,
293 BoundingLimits(bmin,bmax);
296 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
298 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
300 return exist = (pMin < pMax) ?
true :
false;
315 std::ostringstream message;
316 message <<
"Triangulation of the base polygon has failed for solid: "
318 <<
"\nExtent has been calculated using boundary box";
321 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
325 G4int nsect = GetNofZSections();
326 std::vector<const G4ThreeVectorList *> polygons;
327 polygons.resize(nsect);
333 G4int ntria = triangles.size()/3;
334 for (
G4int i=0; i<ntria; ++i)
337 for (
G4int k=0; k<nsect; ++k)
339 ZSection zsect = GetZSection(k);
346 G4ThreeVectorList::iterator iter = ptr->begin();
347 G4double x0 = triangles[i3+0].x()*scale+dx;
348 G4double y0 = triangles[i3+0].y()*scale+dy;
351 G4double x1 = triangles[i3+1].x()*scale+dx;
352 G4double y1 = triangles[i3+1].y()*scale+dy;
355 G4double x2 = triangles[i3+2].x()*scale+dx;
356 G4double y2 = triangles[i3+2].y()*scale+dy;
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)
break;
369 for (
G4int k=0; k<nsect; ++k) {
delete polygons[k]; polygons[k]=0;}
370 return (pMin < pMax);
378G4Polyhedron* G4UExtrudedSolid::CreatePolyhedron ()
const
380 unsigned int nFacets = Base_t::GetStruct().fTslHelper.fFacets.size();
381 unsigned int nVertices = Base_t::GetStruct().fTslHelper.fVertices.size();
386 for (
unsigned int i = 0; i < nVertices; ++i)
388 U3Vector v = Base_t::GetStruct().fTslHelper.fVertices[i];
393 for (
unsigned int i = 0; i < nFacets; ++i)
396 G4int i1 = Base_t::GetStruct().fTslHelper.fFacets[i]->fIndices[0] + 1;
397 G4int i2 = Base_t::GetStruct().fTslHelper.fFacets[i]->fIndices[1] + 1;
398 G4int i3 = Base_t::GetStruct().fTslHelper.fFacets[i]->fIndices[2] + 1;
399 polyhedron->
SetFacet(i+1, i1, i2, i3);
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
void SetVertex(G4int index, const G4Point3D &v)
void SetFacet(G4int index, G4int iv1, G4int iv2, G4int iv3, G4int iv4=0)
const char * name(G4int ptype)