125 ((
TGeoXtru *)
this)->CreateThreadData(1);
134 std::lock_guard<std::mutex> guard(
fMutex);
135 std::vector<ThreadData_t *>::iterator i =
fThreadData.begin();
149 std::lock_guard<std::mutex> guard(
fMutex);
152 for (
Int_t tid = 0; tid < nthreads; tid++) {
164 Error(
"DefinePolygon",
"Shape %s of type XTRU has an illegal polygon.",
GetName());
224 Error(
"ctor",
"Cannot create TGeoXtru %s with less than 2 Z planes",
GetName());
306 for (iz = 0; iz <
fNz - 1; iz++) {
307 dz =
fZ[iz + 1] -
fZ[iz];
312 capacity += (area * dz / 3.) * (sc1 * sc1 + sc1 * sc2 + sc2 * sc2);
324 Error(
"ComputeBBox",
"In shape %s polygon not defined",
GetName());
349 fOrigin[2] = 0.5 * (zmin + zmax);
352 fDZ = 0.5 * (zmax - zmin);
362 memset(norm, 0, 3 *
sizeof(
Double_t));
363 norm[2] = (dir[2] > 0) ? 1 : -1;
369 Double_t ndotd = norm[0] * dir[0] + norm[1] * dir[1] + norm[2] * dir[2];
385 if (point[2] <
fZ[0])
387 if (point[2] >
fZ[
fNz - 1])
390 if (iz < 0 || iz ==
fNz - 1)
447 snext = (
fZ[iz] - point[2]) / dir[2];
450 pt[0] = point[0] + snext * dir[0];
451 pt[1] = point[1] + snext * dir[1];
452 pt[2] = point[2] + snext * dir[2];
463 Double_t ndotd = norm[0] * dir[0] + norm[1] * dir[1] + norm[2] * dir[2];
467 safe = (vert[0] - point[0]) * norm[0] + (vert[1] - point[1]) * norm[1] + (vert[2] - point[2]) * norm[2];
474 safe = (point[0] - vert[0]) * norm[0] + (point[1] - vert[1]) * norm[1] + (point[2] - vert[2]) * norm[2];
478 snext = safe / ndotd;
481 if (
fZ[iz] <
fZ[iz + 1]) {
482 znew = point[2] + snext * dir[2];
485 if (znew >
fZ[iz + 1])
488 pt[0] = point[0] + snext * dir[0];
489 pt[1] = point[1] + snext * dir[1];
490 pt[2] = point[2] + snext * dir[2];
504 if (iact < 3 && safe) {
508 if (iact == 1 && step < *safe)
542 Int_t iv, ipl, inext;
545 for (iv = 0; iv <
fNvert; iv++) {
561 Int_t incseg = (dir[2] > 0) ? 1 : -1;
564 while (iz >= 0 && iz <
fNz - 1) {
566 ipl = iz + ((incseg + 1) >> 1);
567 inext = ipl + incseg;
568 sz = (
fZ[ipl] - point[2]) / dir[2];
572 pt[0] = point[0] + sz * dir[0];
573 pt[1] = point[1] + sz * dir[1];
577 if (ipl == 0 || ipl ==
fNz - 1) {
603 for (iv = 0; iv <
fNvert; iv++) {
629 if (iact < 3 && safe) {
633 if (iact == 1 && step < *safe)
654 snext = (
fZ[0] - point[2]) / dir[2];
657 for (i = 0; i < 3; i++)
658 pt[i] = point[i] + snext * dir[i];
671 snext = (
fZ[
fNz - 1] - point[2]) / dir[2];
674 for (i = 0; i < 3; i++)
675 pt[i] = point[i] + snext * dir[i];
694 for (i = 0; i < 3; i++)
695 pt[i] += dist * dir[i];
699 else if (iz ==
fNz - 1)
712 for (iv = 0; iv <
fNvert; iv++) {
714 if (dist < stepmax) {
717 return (snext + dist);
723 return (snext + stepmax);
727 Int_t incseg = (dir[2] > 0) ? 1 : -1;
728 while (iz >= 0 && iz <
fNz - 1) {
733 for (iv = 0; iv <
fNvert; iv++) {
735 if (dist < stepmax) {
739 return (snext + dist);
745 return (snext + stepmax);
762 Error(
"DefinePolygon",
"In shape %s cannot create polygon with less than 3 vertices",
GetName());
766 for (
Int_t i = 0; i < nvert - 1; i++) {
767 for (
Int_t j = i + 1; j < nvert; j++) {
769 Error(
"DefinePolygon",
"In shape %s 2 vertices cannot be identical",
GetName());
795 if ((snum < 0) || (snum >=
fNz))
802 if (
fZ[snum] <
fZ[snum - 1]) {
804 "In shape: %s, Z position of section "
805 "%i, z=%e, not in increasing order, %i, z=%e",
806 GetName(), snum,
fZ[snum], snum - 1,
fZ[snum - 1]);
810 if (snum == (
fNz - 1)) {
822 if (ipl < 0 || ipl > (
fNz - 1)) {
823 Error(
"GetZ",
"In shape %s, ipl=%i out of range (0,%i)",
GetName(), ipl,
fNz - 1);
836 v1[0] = vert[9] - vert[0];
837 v1[1] = vert[10] - vert[1];
838 v1[2] = vert[11] - vert[2];
839 v2[0] = vert[3] - vert[0];
840 v2[1] = vert[4] - vert[1];
841 v2[2] = vert[5] - vert[2];
842 norm[0] =
v1[1] *
v2[2] -
v1[2] *
v2[1];
843 cross += norm[0] * norm[0];
844 norm[1] =
v1[2] *
v2[0] -
v1[0] *
v2[2];
845 cross += norm[1] * norm[1];
846 norm[2] =
v1[0] *
v2[1] -
v1[1] *
v2[0];
847 cross += norm[2] * norm[2];
851 for (
Int_t i = 0; i < 3; i++)
929 for (
Int_t i = 0; i < 4; i++) {
931 k = 3 * ((i + 1) % 4);
932 v1[0] = point[0] - vert[j];
933 v1[1] = point[1] - vert[j + 1];
934 v1[2] = point[2] - vert[j + 2];
935 v2[0] = vert[k] - vert[j];
936 v2[1] = vert[k + 1] - vert[j + 1];
937 v2[2] = vert[k + 2] - vert[j + 2];
938 cross = (
v1[1] *
v2[2] -
v1[2] *
v2[1]) * norm[0] + (
v1[2] *
v2[0] -
v1[0] *
v2[2]) * norm[1] +
939 (
v1[0] *
v2[1] -
v1[1] *
v2[0]) * norm[2];
951 printf(
"*** Shape %s: TGeoXtru ***\n",
GetName());
952 printf(
" Nz = %i\n",
fNz);
953 printf(
" List of (x,y) of polygon vertices:\n");
955 printf(
" x = %11.5f y = %11.5f\n",
fX[ivert],
fY[ivert]);
956 for (
Int_t ipl = 0; ipl <
fNz; ipl++)
957 printf(
" plane %i: z=%11.5f x0=%11.5f y0=%11.5f scale=%11.5f\n", ipl,
fZ[ipl],
fX0[ipl],
fY0[ipl],
959 printf(
" Bounding box:\n");
971 Int_t nbPnts = nz * nvert;
972 Int_t nbSegs = nvert * (2 * nz - 1);
973 Int_t nbPols = nvert * (nz - 1) + 2;
976 6 * (nbPols - 2) + 2 * (2 + nvert));
995 Int_t indx = 0, indx2, k;
996 for (i = 0; i < nz; i++) {
1000 for (j = 0; j < nvert; j++) {
1001 k = (j + 1) % nvert;
1003 buff.
fSegs[indx++] = indx2 + j;
1004 buff.
fSegs[indx++] = indx2 + k;
1007 for (i = 0; i < nz - 1; i++) {
1011 for (j = 0; j < nvert; j++) {
1014 buff.
fSegs[indx++] = indx2 + j;
1015 buff.
fSegs[indx++] = indx2 + k;
1022 for (i = 0; i < nz - 1; i++) {
1024 for (j = 0; j < nvert; j++) {
1025 k = (j + 1) % nvert;
1026 buff.
fPols[indx++] =
c + j % 3;
1027 buff.
fPols[indx++] = 4;
1028 buff.
fPols[indx++] = indx2 + j;
1029 buff.
fPols[indx++] = nz * nvert + indx2 + k;
1030 buff.
fPols[indx++] = indx2 + nvert + j;
1031 buff.
fPols[indx++] = nz * nvert + indx2 + j;
1034 buff.
fPols[indx++] =
c + 2;
1035 buff.
fPols[indx++] = nvert;
1037 for (j = nvert - 1; j >= 0; --j) {
1038 buff.
fPols[indx++] = indx2 + j;
1042 buff.
fPols[indx++] = nvert;
1043 indx2 = (nz - 1) * nvert;
1045 for (j = 0; j < nvert; j++) {
1046 buff.
fPols[indx++] = indx2 + j;
1071 if ((in1 & !in2) | (in2 & !in1)) {
1082 safz =
fZ[iz] - point[2];
1086 saf1 = point[2] -
fZ[iz + 1];
1101 for (iseg = 0; iseg <
fNvert; iseg++) {
1104 saf1 = (point[0] - vert[0]) * norm[0] + (point[1] - vert[1]) * norm[1] + (point[2] - vert[2]) * norm[2];
1137 for (iz = 0; iz <
fNz - 1; iz++) {
1150 safz =
fZ[0] - point[2];
1152 if (iz ==
fNz - 1) {
1154 safz = point[2] -
fZ[
fNz - 1];
1159 for (i = iz; i <
fNz - 1; i++) {
1165 for (i = iz - 1; i >= 0; i--) {
1181 out <<
" // Shape: " <<
GetName() <<
" type: " <<
ClassName() << std::endl;
1182 out <<
" auto " <<
GetPointerName() <<
" = new TGeoXtru(" <<
fNz <<
");" << std::endl;
1185 out <<
" xvert[" << i <<
"] = " <<
fX[i] <<
"; yvert[" << i <<
"] = " <<
fY[i] <<
";" << std::endl;
1187 out <<
" " <<
GetPointerName() <<
"->DefinePolygon(" <<
fNvert <<
", xvert, yvert);" << std::endl;
1189 out <<
" " <<
GetPointerName() <<
"->DefineSection(" << i <<
", " <<
fZ[i] <<
", " <<
fX0[i] <<
", " <<
fY0[i]
1190 <<
", " <<
fScale[i] <<
");" << std::endl;
1204 a = (
fX0[ind1] *
fZ[ind2] -
fX0[ind2] *
fZ[ind1]) * invdz;
1205 b = (
fX0[ind2] -
fX0[ind1]) * invdz;
1207 a = (
fY0[ind1] *
fZ[ind2] -
fY0[ind2] *
fZ[ind1]) * invdz;
1208 b = (
fY0[ind2] -
fY0[ind1]) * invdz;
1223 td.
fXc[i] = scale *
fX[i] + x0;
1224 td.
fYc[i] = scale *
fY[i] + y0;
1245 Error(
"SetDimensions",
"Cannot create TGeoXtru %s with less than 2 Z planes",
GetName());
1263 DefineSection(i, param[1 + 4 * i], param[2 + 4 * i], param[3 + 4 * i], param[4 + 4 * i]);
1276 for (i = 0; i <
fNz; i++) {
1279 for (j = 0; j <
fNvert; j++) {
1285 for (j = 0; j <
fNvert; j++) {
1305 for (i = 0; i <
fNz; i++) {
1308 for (j = 0; j <
fNvert; j++) {
1314 for (j = 0; j <
fNvert; j++) {
1332 nsegs = nv * (2 * nz - 1);
1333 npols = nv * (nz - 1) + 2;
1362 Int_t nbPnts = nz * nvert;
1363 Int_t nbSegs = nvert * (2 * nz - 1);
1364 Int_t nbPols = nvert * (nz - 1) + 2;
1365 if (buffer.
SetRawSizes(nbPnts, 3 * nbPnts, nbSegs, 3 * nbSegs, nbPols, 6 * (nbPols - 2) + 2 * (2 + nvert))) {
1390 for (
Int_t i = 0; i < vecsize; i++)
1401 for (
Int_t i = 0; i < vecsize; i++)
1411 for (
Int_t i = 0; i < vecsize; i++)
1421 for (
Int_t i = 0; i < vecsize; i++)
1432 for (
Int_t i = 0; i < vecsize; i++)
int Int_t
Signed integer 4 bytes (int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
float Float_t
Float 4 bytes (float).
const char Option_t
Option string (const char).
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.
void FillBuffer3D(TBuffer3D &buffer, Int_t reqSections, Bool_t localFrame) const override
Fill the supplied buffer, with sections in desired frame See TBuffer3D.h for explanation of sections,...
Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=nullptr) const override
TGeoBBox(const TGeoBBox &)=delete
void InspectShape() const override
Bool_t Contains(const Double_t *point) const override
Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const override
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.
void Draw(Option_t *option="") override
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.
const char * GetName() const override
Get the shape name.
static Double_t Tolerance()
Bool_t TestShapeBit(UInt_t f) const
Int_t GetNmeshVertices() const override
Return number of vertices of the mesh representation.
void DistFromInside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const override
Compute distance from array of input points having directions specified by dirs. Store output in dist...
ThreadData_t & GetThreadData() const
void ClearThreadData() const override
Double_t Capacity() const override
Compute capacity [length^3] of this shape.
void ComputeBBox() override
compute bounding box of the pcon
void Contains_v(const Double_t *points, Bool_t *inside, Int_t vecsize) const override
Check the inside status for each of the points in the array.
Bool_t Contains(const Double_t *point) const override
test if point is inside this shape
Int_t fThreadSize
! size of thread-specific array
void SetCurrentVertices(Double_t x0, Double_t y0, Double_t scale)
Set current vertex coordinates according X0, Y0 and SCALE.
TGeoXtru(const TGeoXtru &)=delete
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a primitive as a C++ statement(s) on output stream "out".
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...
void InspectShape() const override
Print actual Xtru parameters.
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
compute closest distance from point px,py to each corner
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.
void Sizeof3D() const override
fill size of this 3-D object
~TGeoXtru() override
destructor
const TBuffer3D & GetBuffer3D(Int_t reqSections, Bool_t localFrame) const override
Fills a static 3D buffer and returns a reference.
Bool_t DefinePolygon(Int_t nvert, const Double_t *xv, const Double_t *yv)
Creates the polygon representing the blueprint of any Xtru section.
void SetCurrentZ(Double_t z, Int_t iz)
Recompute current section vertices for a given Z position within range of section iz.
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.
Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const override
computes the closest distance from given point to this shape, according to option.
void ComputeNormal_v(const Double_t *points, const Double_t *dirs, Double_t *norms, Int_t vecsize) override
Compute the normal for an array o points so that norm.dot.dir is positive Input: Arrays of point coor...
void SetDimensions(Double_t *param) override
void DrawPolygon(Option_t *option="")
Draw the section polygon.
void SetPoints(Double_t *points) const override
create polycone mesh points
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.
Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=nullptr) const override
compute distance from inside point to surface of the polycone locate Z segment
void DistFromOutside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const override
Compute distance from array of input points having directions specified by dirs. Store output in dist...
void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const override
Compute normal to closest surface from POINT.
TBuffer3D * MakeBuffer3D() const override
Creates a TBuffer3D describing this shape.
std::vector< ThreadData_t * > fThreadData
! Navigation data per thread
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.
void SetSegsAndPols(TBuffer3D &buff) const override
Fill TBuffer3D structure for segments and polygons.
void SetSeg(Int_t iseg)
Set current segment.
Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=nullptr) const override
compute distance from outside point to surface of the tube Warning("DistFromOutside",...
std::mutex fMutex
! mutex for thread data
void GetMeshNumbers(Int_t &nvert, Int_t &nsegs, Int_t &npols) const override
Returns numbers of vertices, segments and polygons composing the shape mesh.
void GetPlaneNormal(const Double_t *vert, Double_t *norm) const
Returns normal vector to the planar quadrilateral defined by vector VERT.
void SetIz(Int_t iz)
Set current z-plane.
void Safety_v(const Double_t *points, const Bool_t *inside, Double_t *safe, Int_t vecsize) const override
Compute safe distance from each of the points in the input array.
Bool_t IsConvex() const final
Check shape convexity.
void CreateThreadData(Int_t nthreads) override
Create thread data for n threads max.
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)
Returns the largest of a and b.
Double_t Sqrt(Double_t x)
Returns the square root of x.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Binary search in an array of n values to locate value.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
~ThreadData_t()
Destructor.
ThreadData_t()
Constructor.