93 std::lock_guard<std::mutex> guard(
fMutex);
94 std::vector<ThreadData_t*>::iterator i =
fThreadData.begin();
109 std::lock_guard<std::mutex> guard(
fMutex);
112 for (
Int_t tid=0; tid<nthreads; tid++) {
184 Error(
"ctor",
"left shape is NULL");
188 Error(
"ctor",
"right shape is NULL");
226 TString sleft, sright, stransf;
229 Error(
"MakeBranch",
"invalid expression");
236 if (stransf.
Length() == 0) {
242 Error(
"MakeBranch",
"transformation %s not found", stransf.
Data());
250 Error(
"MakeBranch",
"shape %s not found", sleft.
Data());
276 if (boolop && (!shape || !shape->
IsValid())) {
277 Error(
"MakeBranch",
"Shape %s not valid", newshape.
Data());
278 if (shape)
delete shape;
316 left->PaintComposite(option);
327 right->PaintComposite(option);
354 Error(
"ReplaceMatrix",
"Matrices should not be gGeoIdentity. Use default matrix constructor to represent identities.");
357 if (!mat || !newmat) {
358 Error(
"ReplaceMatrix",
"Matrices should not be null pointers.");
437 Error(
"Paint",
"gPad->GetViewer3D() returned 0, cannot work with composite!\n");
468 Fatal(
"TGeoUnion",
"Unions with a half-space (%s + %s) not allowed", left->
GetName(), right->
GetName());
495 for (i=0; i<8; i++) {
501 if (
pt[2]<zmin) zmin=
pt[2];
502 if (
pt[2]>zmax) zmax=
pt[2];
504 for (i=8; i<16; i++) {
510 if (
pt[2]<zmin) zmin=
pt[2];
511 if (
pt[2]>zmax) zmax=
pt[2];
517 dz = 0.5*(zmax-zmin);
518 origin[2] = 0.5*(zmin+zmax);
529 if (inside)
return kTRUE;
541 norm[0] = norm[1] = 0.;
574 local[0] = point[0] + 1E-5*dir[0];
575 local[1] = point[1] + 1E-5*dir[1];
576 local[2] = point[2] + 1E-5*dir[2];
579 local[0] = point[0] - 1E-5*dir[0];
580 local[1] = point[1] - 1E-5*dir[1];
581 local[2] = point[2] - 1E-5*dir[2];
601 if (iact<3 && safe) {
608 Double_t local[3], local1[3], master[3], ldir[3], rdir[3], pushed[3];
609 memcpy(master, point, 3*
sizeof(
Double_t));
612 Double_t d1=0., d2=0., snxt=0., eps=0.;
618 else memcpy(local1, local, 3*
sizeof(
Double_t));
622 if (!(inside1 | inside2)) {
627 for (i=0; i<3; i++) local1[i] += eps*ldir[i];
635 for (i=0; i<3; i++) local[i] += eps*rdir[i];
642 while (inside1 || inside2) {
643 if (inside1 && inside2) {
649 for (i=0; i<3; i++) master[i] += d1*dir[i];
653 if (!inside2)
return snxt;
661 for (i=0; i<3; i++) master[i] += d2*dir[i];
665 if (!inside1)
return snxt;
675 for (i=0; i<3; i++) {
676 master[i] += d1*dir[i];
682 if (!inside2)
return snxt;
692 for (i=0; i<3; i++) {
693 master[i] += d2*dir[i];
699 if (!inside1)
return snxt;
714 if (iact<3 && safe) {
721 Double_t local[3], ldir[3], rdir[3];
757 for (
Int_t i=0; i<nleft; i++) {
763 for (
Int_t i=0; i<nright; i++) {
788 Bool_t intrue = in1 | in2;
789 if (intrue^in)
return 0.0;
792 if (in1 && in2)
return TMath::Min(saf1, saf2);
793 if (in1)
return saf1;
794 if (in2)
return saf2;
804 out <<
" pBoolNode = new TGeoUnion(";
810 else out <<
"0);" << std::endl;
840 Error(
"Paint",
"gPad->GetViewer3D() returned 0, cannot work with composite!\n");
871 Fatal(
"TGeoSubstraction",
"Subtractions from a half-space (%s) not allowed", left->
GetName());
896 box->SetBoxPoints(&vert[0]);
897 for (i=0; i<8; i++) {
903 if (
pt[2]<zmin) zmin=
pt[2];
904 if (
pt[2]>zmax) zmax=
pt[2];
910 dz = 0.5*(zmax-zmin);
911 origin[2] = 0.5*(zmin+zmax);
920 norm[0] = norm[1] = 0.;
922 Double_t local[3], ldir[3], lnorm[3];
952 local[0] = point[0]+1E-5*dir[0];
953 local[1] = point[1]+1E-5*dir[1];
954 local[2] = point[2]+1E-5*dir[2];
956 local[0] = point[0]-1E-5*dir[0];
957 local[1] = point[1]-1E-5*dir[1];
958 local[2] = point[2]-1E-5*dir[2];
972 if (!inside)
return kFALSE;
992 if (iact<3 && safe) {
999 Double_t local[3], ldir[3], rdir[3];
1023 if (iact<3 && safe) {
1030 Double_t local[3], master[3], ldir[3], rdir[3];
1031 memcpy(&master[0], point, 3*
sizeof(
Double_t));
1046 for (i=0; i<3; i++) master[i] += (d1+1E-8)*dir[i];
1066 for (i=0; i<3; i++) master[i] += (d1+1E-8)*dir[i];
1088 for (
Int_t i=0; i<nleft; i++) {
1096 for (
Int_t i=0; i<nright; i++) {
1121 Bool_t intrue = in1 && (!in2);
1122 if (in^intrue)
return 0.0;
1125 if (in1 && in2)
return saf2;
1137 out <<
" pBoolNode = new TGeoSubtraction(";
1143 else out <<
"0);" << std::endl;
1172 Error(
"Paint",
"gPad->GetViewer3D() returned 0, cannot work with composite!\n");
1204 if (hs1 && hs2)
Fatal(
"ctor",
"cannot intersect two half-spaces: %s * %s", left->
GetName(), right->
GetName());
1225 Double_t xmin1, xmax1, ymin1, ymax1, zmin1, zmax1;
1226 Double_t xmin2, xmax2, ymin2, ymax2, zmin2, zmax2;
1227 xmin1 = ymin1 = zmin1 = xmin2 = ymin2 = zmin2 =
TGeoShape::Big();
1228 xmax1 = ymax1 = zmax1 = xmax2 = ymax2 = zmax2 = -
TGeoShape::Big();
1232 for (i=0; i<8; i++) {
1234 if (
pt[0]<xmin1) xmin1=
pt[0];
1235 if (
pt[0]>xmax1) xmax1=
pt[0];
1236 if (
pt[1]<ymin1) ymin1=
pt[1];
1237 if (
pt[1]>ymax1) ymax1=
pt[1];
1238 if (
pt[2]<zmin1) zmin1=
pt[2];
1239 if (
pt[2]>zmax1) zmax1=
pt[2];
1245 for (i=8; i<16; i++) {
1247 if (
pt[0]<xmin2) xmin2=
pt[0];
1248 if (
pt[0]>xmax2) xmax2=
pt[0];
1249 if (
pt[1]<ymin2) ymin2=
pt[1];
1250 if (
pt[1]>ymax2) ymax2=
pt[1];
1251 if (
pt[2]<zmin2) zmin2=
pt[2];
1252 if (
pt[2]>zmax2) zmax2=
pt[2];
1256 dx = 0.5*(xmax2-xmin2);
1257 origin[0] = 0.5*(xmax2+xmin2);
1258 dy = 0.5*(ymax2-ymin2);
1259 origin[1] = 0.5*(ymax2+ymin2);
1260 dz = 0.5*(zmax2-zmin2);
1261 origin[2] = 0.5*(zmax2+zmin2);
1265 dx = 0.5*(xmax1-xmin1);
1266 origin[0] = 0.5*(xmax1+xmin1);
1267 dy = 0.5*(ymax1-ymin1);
1268 origin[1] = 0.5*(ymax1+ymin1);
1269 dz = 0.5*(zmax1-zmin1);
1270 origin[2] = 0.5*(zmax1+zmin1);
1283 memset(origin, 0, 3*
sizeof(
Double_t));
1286 dx = 0.5*(sort[isort[2]]-sort[isort[1]]);
1287 origin[0] = 0.5*(sort[isort[1]]+sort[isort[2]]);
1296 memset(origin, 0, 3*
sizeof(
Double_t));
1299 dy = 0.5*(sort[isort[2]]-sort[isort[1]]);
1300 origin[1] = 0.5*(sort[isort[1]]+sort[isort[2]]);
1309 memset(origin, 0, 3*
sizeof(
Double_t));
1312 dz = 0.5*(sort[isort[2]]-sort[isort[1]]);
1313 origin[2] = 0.5*(sort[isort[1]]+sort[isort[2]]);
1322 Double_t local[3], ldir[3], lnorm[3];
1323 norm[0] = norm[1] = 0.;
1354 local[0] = point[0] + 1E-5*dir[0];
1355 local[1] = point[1] + 1E-5*dir[1];
1356 local[2] = point[2] + 1E-5*dir[2];
1358 local[0] = point[0] - 1E-5*dir[0];
1359 local[1] = point[1] - 1E-5*dir[1];
1360 local[2] = point[2] - 1E-5*dir[2];
1374 if (!inside)
return kFALSE;
1394 if (iact<3 && safe) {
1401 Double_t local[3], ldir[3], rdir[3];
1426 if (iact<3 && safe) {
1433 Double_t lpt[3], rpt[3], master[3], ldir[3], rdir[3];
1434 memcpy(master, point, 3*
sizeof(
Double_t));
1446 if (inleft && inright) {
1451 if (d1<1.E-3) inleft =
kFALSE;
1452 if (d2<1.E-3) inright =
kFALSE;
1453 if (inleft && inright)
return snext;
1474 for (i=0; i<3; i++) master[i] += d1*dir[i];
1477 for (i=0; i<3; i++) rpt[i] += tol*rdir[i];
1480 if (inright)
return snext;
1487 for (i=0; i<3; i++) master[i] += d2*dir[i];
1490 for (i=0; i<3; i++) lpt[i] += tol*ldir[i];
1493 if (inleft)
return snext;
1514 for (
Int_t i=0; i<nleft; i++) {
1522 for (
Int_t i=0; i<nright; i++) {
1547 Bool_t intrue = in1 & in2;
1548 if (in^intrue)
return 0.0;
1551 if (in1 && in2)
return TMath::Min(saf1, saf2);
1552 if (in1)
return saf2;
1553 if (in2)
return saf1;
1563 out <<
" pBoolNode = new TGeoIntersection(";
1569 else out <<
"0);" << std::endl;
R__EXTERN TGeoManager * gGeoManager
R__EXTERN TGeoIdentity * gGeoIdentity
Generic 3D primitive description class.
Base class for Boolean operations between two shapes.
virtual void Sizeof3D() const
Register size of this 3D object.
Bool_t MakeBranch(const char *expr, Bool_t left)
Mutex for thread data access.
void ClearThreadData() const
Bool_t ReplaceMatrix(TGeoMatrix *mat, TGeoMatrix *newmat)
Replace one of the matrices.
void AssignPoints(Int_t npoints, Double_t *points)
Set fPoints array.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a primitive as a C++ statement(s) on output stream "out".
void CreateThreadData(Int_t nthreads)
Create thread data for n threads max.
void Paint(Option_t *option) override
Special schema for feeding the 3D buffers to the painter client.
virtual void SetPoints(Double_t *points) const
Fill buffer with shape vertices.
Int_t fThreadSize
Navigation data per thread.
std::mutex fMutex
Size for the navigation data array.
std::vector< ThreadData_t * > fThreadData
array of mesh points
void RegisterMatrices()
Register all matrices of the boolean node and descendents.
virtual ~TGeoBoolNode()
Destructor.
virtual Int_t GetNpoints()=0
Double_t * fPoints
number of points on the mesh
TGeoBoolNode()
Default constructor.
ThreadData_t & GetThreadData() const
void SetSelected(Int_t sel)
Set the selected branch.
Composite shapes are Boolean combinations of two or more shape components.
Matrix class used for computing global transformations Should NOT be used for node definition.
void Multiply(const TGeoMatrix *right)
multiply to the right with an other transformation if right is identity matrix, just return
Int_t DistanceToPrimitive(Int_t px, Int_t py) override
Compute minimum distance to shape vertices.
TGeoBoolNode * MakeClone() const override
Make a clone of this. Pointers are preserved.
TGeoIntersection()
Default constructor.
void Sizeof3D() const override
Register 3D size of this shape.
virtual ~TGeoIntersection()
Destructor — deletion of components handled by TGeoManager class.
void ComputeBBox(Double_t &dx, Double_t &dy, Double_t &dz, Double_t *origin) override
Compute bounding box corresponding to a intersection of two shapes.
Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=0, Double_t *safe=nullptr) const override
Compute distance from a given point outside to the shape.
Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const override
Compute safety distance for a union node;.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a primitive as a C++ statement(s) on output stream "out".
Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=0, Double_t *safe=nullptr) const override
Compute distance from a given point inside to the shape boundary.
void Paint(Option_t *option) override
Paint method.
void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) override
Normal computation in POINT. The orientation is chosen so that DIR.dot.NORM>0.
Bool_t Contains(const Double_t *point) const override
Find if a intersection of two shapes contains a given point.
Int_t GetNpoints() override
Returns number of vertices for the composite shape described by this intersection.
TObjArray * GetListOfMatrices() const
static Int_t Parse(const char *expr, TString &expr1, TString &expr2, TString &expr3)
Parse a string boolean expression and do a syntax check.
TObjArray * GetListOfShapes() const
static Int_t ThreadId()
Translates the current thread id to an ordinal number.
Geometrical transformation package.
virtual void LocalToMasterVect(const Double_t *local, Double_t *master) const
convert a vector by multiplying its column vector (x, y, z, 1) to matrix inverse
virtual void MasterToLocal(const Double_t *master, Double_t *local) const
convert a point by multiplying its column vector (x, y, z, 1) to matrix
virtual void MasterToLocalVect(const Double_t *master, Double_t *local) const
convert a point by multiplying its column vector (x, y, z, 1) to matrix
virtual void RegisterYourself()
Register the matrix in the current manager, which will become the owner.
virtual void LocalToMaster(const Double_t *local, Double_t *master) const
convert a point by multiplying its column vector (x, y, z, 1) to matrix inverse
Bool_t IsIdentity() const
char * GetPointerName() const
Provide a pointer name containing uid.
Base abstract class for all shapes.
virtual void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm)=0
virtual const TBuffer3D & GetBuffer3D(Int_t reqSections, Bool_t localFrame) const
Stub implementation to avoid forcing implementation at this stage.
virtual void CreateThreadData(Int_t)
virtual Int_t GetNmeshVertices() const
virtual void Sizeof3D() const =0
virtual Bool_t IsComposite() const
virtual Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const =0
const char * GetPointerName() const
Provide a pointer name containing uid.
virtual const char * GetName() const
Get the shape name.
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 =0
virtual void ComputeBBox()=0
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 =0
static TGeoMatrix * GetTransform()
Returns current transformation matrix that applies to shape.
virtual Bool_t Contains(const Double_t *point) const =0
static Double_t Tolerance()
virtual void SetPoints(Double_t *points) const =0
Bool_t TestShapeBit(UInt_t f) const
TGeoSubtraction()
Default constructor.
void ComputeBBox(Double_t &dx, Double_t &dy, Double_t &dz, Double_t *origin) override
Compute bounding box corresponding to a subtraction of two shapes.
Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const override
Compute safety distance for a union node;.
void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) override
Normal computation in POINT. The orientation is chosen so that DIR.dot.NORM>0.
TGeoBoolNode * MakeClone() const override
Make a clone of this. Pointers are preserved.
Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=0, Double_t *safe=nullptr) const override
Compute distance from a given point outside to the shape.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a primitive as a C++ statement(s) on output stream "out".
Bool_t Contains(const Double_t *point) const override
Find if a subtraction of two shapes contains a given point.
void Sizeof3D() const override
Register 3D size of this shape.
Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=0, Double_t *safe=nullptr) const override
Compute distance from a given point inside to the shape boundary.
void Paint(Option_t *option) override
Paint method.
Int_t DistanceToPrimitive(Int_t px, Int_t py) override
Compute minimum distance to shape vertices.
virtual ~TGeoSubtraction()
Destructor — deletion of components handled by TGeoManager class.
Int_t GetNpoints() override
Returns number of vertices for the composite shape described by this subtraction.
Int_t DistanceToPrimitive(Int_t px, Int_t py) override
Compute minimum distance to shape vertices.
TGeoBoolNode * MakeClone() const override
Make a clone of this. Pointers are preserved.
void ComputeBBox(Double_t &dx, Double_t &dy, Double_t &dz, Double_t *origin) override
Compute bounding box corresponding to a union of two shapes.
Int_t GetNpoints() override
Returns number of vertices for the composite shape described by this union.
virtual ~TGeoUnion()
Destructor — deletion of components handled by TGeoManager class.
Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=0, Double_t *safe=nullptr) const override
Compute distance from a given outside point to the shape.
Bool_t Contains(const Double_t *point) const override
Find if a union of two shapes contains a given point.
Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const override
Compute safety distance for a union node;.
Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=0, Double_t *safe=nullptr) const override
Computes distance from a given point inside the shape to its boundary.
TGeoUnion()
Default constructor.
void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) override
Normal computation in POINT. The orientation is chosen so that DIR.dot.NORM>0.
void Paint(Option_t *option) override
Paint method.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a primitive as a C++ statement(s) on output stream "out".
void Sizeof3D() const override
Register 3D size of this shape.
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
const char * Data() const
Abstract 3D shapes viewer.
virtual Int_t AddObject(const TBuffer3D &buffer, Bool_t *addChildren=0)=0
virtual void AddCompositeOp(UInt_t operation)=0
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Short_t Max(Short_t a, Short_t b)
Short_t Min(Short_t a, Short_t b)
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
ThreadData_t()
Constructor.
~ThreadData_t()
Destructor.
#define snext(osub1, osub2)