74 fSeg(0), fIz(0), fXc(0), fYc(0), fPoly(0)
101 std::lock_guard<std::mutex> guard(
fMutex);
102 std::vector<ThreadData_t*>::iterator i =
fThreadData.begin();
117 std::lock_guard<std::mutex> guard(
fMutex);
120 for (
Int_t tid=0; tid<nthreads; tid++) {
132 Error(
"DefinePolygon",
"Shape %s of type XTRU has an illegal polygon.",
GetName());
192 Error(
"ctor",
"Cannot create TGeoXtru %s with less than 2 Z planes",
GetName());
235 if (
fX) {
delete[]
fX;
fX = 0;}
236 if (
fY) {
delete[]
fY;
fY = 0;}
237 if (
fZ) {
delete[]
fZ;
fZ = 0;}
256 for (iz=0; iz<
fNz-1; iz++) {
257 dz =
fZ[iz+1]-
fZ[iz];
261 capacity += (area*dz/3.)*(sc1*sc1+sc1*sc2+sc2*sc2);
273 Error(
"ComputeBBox",
"In shape %s polygon not defined",
GetName());
297 fDZ = 0.5*(zmax-zmin);
308 norm[2] = (dir[2]>0)?1:-1;
314 Double_t ndotd = norm[0]*dir[0]+norm[1]*dir[1]+norm[2]*dir[2];
385 snext = (
fZ[iz]-point[2])/dir[2];
397 Double_t ndotd = norm[0]*dir[0]+norm[1]*dir[1]+norm[2]*dir[2];
400 safe = (vert[0]-point[0])*norm[0]+
401 (vert[1]-point[1])*norm[1]+
402 (vert[2]-point[2])*norm[2];
407 safe = (point[0]-vert[0])*norm[0]+
408 (point[1]-vert[1])*norm[1]+
409 (point[2]-vert[2])*norm[2];
414 if (
fZ[iz]<
fZ[iz+1]) {
415 znew = point[2] +
snext*dir[2];
433 if (iact<3 && safe) {
467 Int_t iv, ipl, inext;
470 for (iv=0; iv<
fNvert; iv++) {
476 if (convex)
return snext;
484 Int_t incseg = (dir[2]>0)?1:-1;
487 while (iz>=0 && iz<
fNz-1) {
489 ipl = iz+((incseg+1)>>1);
491 sz = (
fZ[ipl]-point[2])/dir[2];
495 pt[0] = point[0]+sz*dir[0];
496 pt[1] = point[1]+sz*dir[1];
500 if (ipl==0 || ipl==
fNz-1) {
502 if (convex)
return sz;
512 if (convex)
return sz;
524 for (iv=0; iv<
fNvert; iv++) {
530 if (convex)
return snext;
534 if (zexit)
return snext;
547 if (iact<3 && safe) {
568 snext = (
fZ[0] - point[2])/dir[2];
570 for (i=0; i<3; i++)
pt[i] = point[i] +
snext*dir[i];
584 for (i=0; i<3; i++)
pt[i] = point[i] +
snext*dir[i];
598 if (dist>1E-6) dist-=1E-6;
600 for (i=0; i<3; i++)
pt[i] += dist*dir[i];
603 else if (iz==
fNz-1) iz =
fNz-2;
615 for (iv=0; iv<
fNvert; iv++) {
619 if (convex)
return (
snext+dist);
624 if (hit)
return (
snext+stepmax);
628 Int_t incseg = (dir[2]>0)?1:-1;
629 while (iz>=0 && iz<
fNz-1) {
633 for (iv=0; iv<
fNvert; iv++) {
638 if (convex)
return (
snext+dist);
643 if (hit)
return (
snext+stepmax);
660 Error(
"DefinePolygon",
"In shape %s cannot create polygon with less than 3 vertices",
GetName());
664 for (
Int_t i=0; i<nvert-1; i++) {
665 for (
Int_t j=i+1; j<nvert; j++) {
668 Error(
"DefinePolygon",
"In shape %s 2 vertices cannot be identical",
GetName());
675 if (
fX)
delete []
fX;
677 if (
fY)
delete []
fY;
692 if ((snum<0) || (snum>=
fNz))
return;
698 if (
fZ[snum]<
fZ[snum-1]) {
699 Warning(
"DefineSection",
"In shape: %s, Z position of section "
700 "%i, z=%e, not in increasing order, %i, z=%e",
716 if (ipl<0 || ipl>(
fNz-1)) {
717 Error(
"GetZ",
"In shape %s, ipl=%i out of range (0,%i)",
GetName(),ipl,
fNz-1);
730 v1[0] = vert[9]-vert[0];
731 v1[1] = vert[10]-vert[1];
732 v1[2] = vert[11]-vert[2];
733 v2[0] = vert[3]-vert[0];
734 v2[1] = vert[4]-vert[1];
735 v2[2] = vert[5]-vert[2];
737 cross += norm[0]*norm[0];
739 cross += norm[1]*norm[1];
741 cross += norm[2]*norm[2];
744 for (
Int_t i=0; i<3; i++) norm[i] *= cross;
811 for (
Int_t i=0; i<4; i++) {
814 v1[0] = point[0]-vert[j];
815 v1[1] = point[1]-vert[j+1];
816 v1[2] = point[2]-vert[j+2];
817 v2[0] = vert[k]-vert[j];
818 v2[1] = vert[k+1]-vert[j+1];
819 v2[2] = vert[k+2]-vert[j+2];
820 cross = (
v1[1]*
v2[2]-
v1[2]*
v2[1])*norm[0]+
823 if (cross<0)
return kFALSE;
833 printf(
"*** Shape %s: TGeoXtru ***\n",
GetName());
834 printf(
" Nz = %i\n",
fNz);
835 printf(
" List of (x,y) of polygon vertices:\n");
837 printf(
" x = %11.5f y = %11.5f\n",
fX[ivert],
fY[ivert]);
839 printf(
" plane %i: z=%11.5f x0=%11.5f y0=%11.5f scale=%11.5f\n", ipl,
fZ[ipl],
fX0[ipl],
fY0[ipl],
fScale[ipl]);
840 printf(
" Bounding box:\n");
852 Int_t nbPnts = nz*nvert;
853 Int_t nbSegs = nvert*(2*nz-1);
854 Int_t nbPols = nvert*(nz-1)+2;
857 nbPnts, 3*nbPnts, nbSegs, 3*nbSegs, nbPols, 6*(nbPols-2)+2*(2+nvert));
877 Int_t indx, indx2, k;
879 for (i=0; i<nz; i++) {
883 for (j=0; j<nvert; j++) {
886 buff.
fSegs[indx++] = indx2+j;
887 buff.
fSegs[indx++] = indx2+k;
890 for (i=0; i<nz-1; i++) {
894 for (j=0; j<nvert; j++) {
897 buff.
fSegs[indx++] = indx2+j;
898 buff.
fSegs[indx++] = indx2+k;
905 for (i=0; i<nz-1; i++) {
907 for (j=0; j<nvert; j++) {
909 buff.
fPols[indx++] =
c+j%3;
910 buff.
fPols[indx++] = 4;
911 buff.
fPols[indx++] = indx2+j;
912 buff.
fPols[indx++] = nz*nvert+indx2+k;
913 buff.
fPols[indx++] = indx2+nvert+j;
914 buff.
fPols[indx++] = nz*nvert+indx2+j;
918 buff.
fPols[indx++] = nvert;
920 for (j = nvert - 1; j >= 0; --j) {
921 buff.
fPols[indx++] = indx2+j;
925 buff.
fPols[indx++] = nvert;
926 indx2 = (nz-1)*nvert;
928 for (j=0; j<nvert; j++) {
929 buff.
fPols[indx++] = indx2+j;
955 if ((in1&!in2)|(in2&!in1)) {
965 safz =
fZ[iz]-point[2];
968 saf1 = point[2]-
fZ[iz+1];
982 for (iseg=0; iseg<
fNvert; iseg++) {
985 saf1 = (point[0]-vert[0])*norm[0]+(point[1]-vert[1])*norm[1]+(point[2]-vert[2])*norm[2];
986 if (in) saf1 = -saf1;
988 if (saf1<-1.E-8)
continue;
991 if (safe>safmin)
continue;
995 if (found)
return safmin;
1013 for (iz=0; iz<
fNz-1; iz++) {
1015 if (safe<safmin) safmin = safe;
1024 safz =
fZ[0] - point[2];
1028 safz = point[2] -
fZ[
fNz-1];
1033 for (i=iz; i<
fNz-1; i++) {
1035 if (safe<safmin) safmin=safe;
1038 for (i=iz-1; i>=0; i--) {
1040 if (safe<safmin) safmin=safe;
1052 out <<
" // Shape: " <<
GetName() <<
" type: " <<
ClassName() << std::endl;
1053 out <<
" nz = " <<
fNz <<
";" << std::endl;
1054 out <<
" nvert = " <<
fNvert <<
";" << std::endl;
1055 out <<
" TGeoXtru *xtru = new TGeoXtru(nz);" << std::endl;
1056 out <<
" xtru->SetName(\"" <<
GetName() <<
"\");" << std::endl;
1058 for (i=0; i<
fNvert; i++) {
1059 out <<
" xvert[" << i <<
"] = " <<
fX[i] <<
"; yvert[" << i <<
"] = " <<
fY[i] <<
";" << std::endl;
1061 out <<
" xtru->DefinePolygon(nvert,xvert,yvert);" << std::endl;
1062 for (i=0; i<
fNz; i++) {
1063 out <<
" zsect = " <<
fZ[i] <<
";" << std::endl;
1064 out <<
" x0 = " <<
fX0[i] <<
";" << std::endl;
1065 out <<
" y0 = " <<
fY0[i] <<
";" << std::endl;
1066 out <<
" scale0 = " <<
fScale[i] <<
";" << std::endl;
1067 out <<
" xtru->DefineSection(" << i <<
",zsect,x0,y0,scale0);" << std::endl;
1069 out <<
" TGeoShape *" <<
GetPointerName() <<
" = xtru;" << std::endl;
1083 a = (
fX0[ind1]*
fZ[ind2]-
fX0[ind2]*
fZ[ind1])*invdz;
1084 b = (
fX0[ind2]-
fX0[ind1])*invdz;
1086 a = (
fY0[ind1]*
fZ[ind2]-
fY0[ind2]*
fZ[ind1])*invdz;
1087 b = (
fY0[ind2]-
fY0[ind1])*invdz;
1102 td.
fXc[i] = scale*
fX[i] + x0;
1103 td.
fYc[i] = scale*
fY[i] + y0;
1124 Error(
"SetDimensions",
"Cannot create TGeoXtru %s with less than 2 Z planes",
GetName());
1128 if (
fZ)
delete []
fZ;
1138 DefineSection(i, param[1+4*i], param[2+4*i], param[3+4*i], param[4+4*i]);
1151 for (i = 0; i <
fNz; i++) {
1154 for (j = 0; j <
fNvert; j++) {
1160 for (j = 0; j <
fNvert; j++) {
1180 for (i = 0; i <
fNz; i++) {
1183 for (j = 0; j <
fNvert; j++) {
1189 for (j = 0; j <
fNvert; j++) {
1207 nsegs = nv*(2*nz-1);
1208 npols = nv*(nz-1)+2;
1239 Int_t nbPnts = nz*nvert;
1240 Int_t nbSegs = nvert*(2*nz-1);
1241 Int_t nbPols = nvert*(nz-1)+2;
1242 if (buffer.
SetRawSizes(nbPnts, 3*nbPnts, nbSegs, 3*nbSegs, nbPols, 6*(nbPols-2)+2*(2+nvert))) {
Generic 3D primitive description class.
Bool_t SectionsValid(UInt_t mask) const
void SetSectionsValid(UInt_t mask)
Bool_t SetRawSizes(UInt_t reqPnts, UInt_t reqPntsCapacity, UInt_t reqSegs, UInt_t reqSegsCapacity, UInt_t reqPols, UInt_t reqPolsCapacity)
Set kRaw tessellation section of buffer with supplied sizes.
virtual Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const
Computes the closest distance from given point to this shape.
virtual Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=0) const
Compute distance from outside point to surface of the box.
virtual void InspectShape() const
Prints shape parameters.
virtual Bool_t Contains(const Double_t *point) const
Test if point is inside this shape.
virtual void FillBuffer3D(TBuffer3D &buffer, Int_t reqSections, Bool_t localFrame) const
Fills the supplied buffer, with sections in desired frame See TBuffer3D.h for explanation of sections...
static Int_t ThreadId()
Translates the current thread id to an ordinal number.
An arbitrary polygon defined by vertices.
Double_t Safety(const Double_t *point, Int_t &isegment) const
Compute minimum distance from POINT to any segment. Returns segment index.
void SetXY(Double_t *x, Double_t *y)
Set X/Y array pointer for the polygon and daughters.
Double_t Area() const
Computes area of the polygon in [length^2].
Bool_t Contains(const Double_t *point) const
Check if a point given by X = point[0], Y = point[1] is inside the polygon.
Bool_t IsIllegalCheck() const
Check for illegal crossings between non-consecutive segments.
virtual void Draw(Option_t *option="")
Draw the polygon.
Bool_t IsClockwise() const
void FinishPolygon()
Decompose polygon in a convex outscribed part and a list of daughter polygons that have to be subtrac...
Int_t GetBasicColor() const
Get the basic color (0-7).
void TransformPoints(Double_t *points, UInt_t NbPoints) const
Tranform a set of points (LocalToMaster)
void SetShapeBit(UInt_t f, Bool_t set)
Equivalent of TObject::SetBit.
static Bool_t IsSameWithinTolerance(Double_t a, Double_t b)
Check if two numbers differ with less than a tolerance.
const char * GetPointerName() const
Provide a pointer name containing uid.
Int_t ShapeDistancetoPrimitive(Int_t numpoints, Int_t px, Int_t py) const
Returns distance to shape primitive mesh.
virtual const char * GetName() const
Get the shape name.
static Double_t Tolerance()
Bool_t TestShapeBit(UInt_t f) const
An extrusion with fixed outline shape in x-y and a sequence of z extents (segments).
virtual Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=0) const
compute distance from outside point to surface of the tube Warning("DistFromOutside",...
virtual void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm)
Compute normal to closest surface from POINT.
virtual Bool_t Contains(const Double_t *point) const
test if point is inside this shape
ThreadData_t & GetThreadData() const
virtual void ComputeBBox()
compute bounding box of the pcon
Int_t fThreadSize
Navigation data per thread.
void SetCurrentVertices(Double_t x0, Double_t y0, Double_t scale)
Set current vertex coordinates according X0, Y0 and SCALE.
virtual Double_t Capacity() const
Compute capacity [length^3] of this shape.
virtual void ComputeNormal_v(const Double_t *points, const Double_t *dirs, Double_t *norms, Int_t vecsize)
Compute the normal for an array o points so that norm.dot.dir is positive Input: Arrays of point coor...
virtual void DistFromOutside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const
Compute distance from array of input points having directions specified by dirs. Store output in dist...
void GetPlaneVertices(Int_t iz, Int_t ivert, Double_t *vert) const
Returns (x,y,z) of 3 vertices of the surface defined by Z sections (iz, iz+1) and polygon vertices (i...
virtual void Sizeof3D() const
fill size of this 3-D object
Bool_t IsPointInsidePlane(const Double_t *point, Double_t *vert, Double_t *norm) const
Check if the quadrilateral defined by VERT contains a coplanar POINT.
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
virtual void SetPoints(Double_t *points) const
create polycone mesh points
Bool_t DefinePolygon(Int_t nvert, const Double_t *xv, const Double_t *yv)
Creates the polygon representing the blueprint of any Xtru section.
virtual void CreateThreadData(Int_t nthreads)
Create thread data for n threads max.
void SetCurrentZ(Double_t z, Int_t iz)
Recompute current section vertices for a given Z position within range of section iz.
virtual TBuffer3D * MakeBuffer3D() const
Creates a TBuffer3D describing this shape.
virtual void DefineSection(Int_t snum, Double_t z, Double_t x0=0., Double_t y0=0., Double_t scale=1.)
defines z position of a section plane, rmin and rmax at this z.
void DrawPolygon(Option_t *option="")
Draw the section polygon.
virtual const TBuffer3D & GetBuffer3D(Int_t reqSections, Bool_t localFrame) const
Fills a static 3D buffer and returns a reference.
Double_t SafetyToSector(const Double_t *point, Int_t iz, Double_t safmin, Bool_t in)
Compute safety to sector iz, returning also the closest segment index.
virtual void Safety_v(const Double_t *points, const Bool_t *inside, Double_t *safe, Int_t vecsize) const
Compute safe distance from each of the points in the input array.
virtual void SetSegsAndPols(TBuffer3D &buff) const
Fill TBuffer3D structure for segments and polygons.
virtual void GetMeshNumbers(Int_t &nvert, Int_t &nsegs, Int_t &npols) const
Returns numbers of vertices, segments and polygons composing the shape mesh.
virtual void DistFromInside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const
Compute distance from array of input points having directions specified by dirs. Store output in dist...
virtual void SetDimensions(Double_t *param)
virtual void ClearThreadData() const
virtual ~TGeoXtru()
destructor
Double_t DistToPlane(const Double_t *point, const Double_t *dir, Int_t iz, Int_t ivert, Double_t stepmax, Bool_t in) const
Compute distance to a Xtru lateral surface.
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
compute closest distance from point px,py to each corner
void SetSeg(Int_t iseg)
Set current segment.
std::mutex fMutex
size of thread-specific array
virtual void InspectShape() const
Print actual Xtru parameters.
virtual Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const
computes the closest distance from given point to this shape, according to option.
void GetPlaneNormal(const Double_t *vert, Double_t *norm) const
Returns normal vector to the planar quadrilateral defined by vector VERT.
virtual Int_t GetNmeshVertices() const
Return number of vertices of the mesh representation.
std::vector< ThreadData_t * > fThreadData
virtual void Contains_v(const Double_t *points, Bool_t *inside, Int_t vecsize) const
Check the inside status for each of the points in the array.
void SetIz(Int_t iz)
Set current z-plane.
virtual Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=0) const
compute distance from inside point to surface of the polycone locate Z segment
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Short_t Max(Short_t a, Short_t b)
Double_t Sqrt(Double_t x)
Short_t Min(Short_t a, Short_t b)
Long64_t BinarySearch(Long64_t n, const T *array, T value)
~ThreadData_t()
Destructor.
ThreadData_t()
Constructor.
#define snext(osub1, osub2)