Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGeoBoolNode.h
Go to the documentation of this file.
1// @(#):$Id$
2// Author: Andrei Gheata 30/05/02
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TGeoBoolNode
13#define ROOT_TGeoBoolNode
14
15#include "TGeoShape.h"
16
17#include <algorithm>
18#include <atomic>
19#include <vector>
20
21// forward declarations
22class TGeoShape;
23class TGeoMatrix;
24class TGeoHMatrix;
25
26class TGeoBoolNode : public TObject {
27 static std::atomic<UInt_t> fgInstanceCount; //! source of monotonic per-object indices
28 UInt_t fIndex{fgInstanceCount++}; //! non-reused index of this node into the per-thread vector
29
30public:
36 struct ThreadData_t {
37 Int_t fSelected{0}; //! selected branch
38 };
39
40 /// Per-thread scratch state, owned by the calling thread and indexed by this node.
41 /// Each thread owns its whole vector, so no two threads ever write the same cache line.
42 /// The vector retains its high-water size until the owning thread exits.
44 {
45 thread_local std::vector<ThreadData_t> tdata;
46 if (tdata.size() <= fIndex)
47 tdata.resize(std::max<size_t>(fgInstanceCount.load(std::memory_order_relaxed), fIndex + 1));
48 return tdata[fIndex];
49 }
50 void ClearThreadData() const {}
51 /// No-op: this node allocates its scratch state lazily for every calling thread.
53
54private:
55 TGeoBoolNode(const TGeoBoolNode &) = delete;
57
58protected:
59 TGeoShape *fLeft{nullptr}; // shape on the left branch
60 TGeoShape *fRight{nullptr}; // shape on the right branch
61 TGeoMatrix *fLeftMat{nullptr}; // transformation that applies to the left branch
62 TGeoMatrix *fRightMat{nullptr}; // transformation that applies to the right branch
63 mutable Int_t fNpoints{0}; ///<! number of points on the mesh
64 mutable Double_t *fPoints{nullptr}; ///<! array of mesh points
65
66 mutable Bool_t fMeshValid{kFALSE}; ///<! Flag for mesh cache validity
67 // methods
68 Bool_t MakeBranch(const char *expr, Bool_t left);
70
71public:
72 // constructors
74 TGeoBoolNode(const char *expr1, const char *expr2);
75 TGeoBoolNode(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
76
77 // destructor
78 ~TGeoBoolNode() override;
79 // methods
81 virtual void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const = 0;
82 virtual Bool_t Contains(const Double_t *point) const = 0;
83 virtual Int_t DistanceToPrimitive(Int_t px, Int_t py) = 0;
84 virtual Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
85 Double_t *safe = nullptr) const = 0;
86 virtual Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
87 Double_t *safe = nullptr) const = 0;
88 virtual EGeoBoolType GetBooleanOperator() const = 0;
90 TGeoMatrix *GetLeftMatrix() const { return fLeftMat; }
91 TGeoMatrix *GetRightMatrix() const { return fRightMat; }
92 TGeoShape *GetLeftShape() const { return fLeft; }
93 TGeoShape *GetRightShape() const { return fRight; }
94 TGeoShape::EInside Inside(const Double_t *point) const;
96 virtual TGeoBoolNode *MakeClone() const = 0;
97 void Paint(Option_t *option) override;
98 void RegisterMatrices();
100 virtual Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const = 0;
101 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
102 virtual void SetPoints(Double_t *points) const;
103 virtual void SetPoints(Float_t *points) const;
104 void SetSelected(Int_t sel);
105 virtual void Sizeof3D() const;
106
107 ClassDefOverride(TGeoBoolNode, 1) // a boolean node
108};
109
110/// Boolean node representing a union between two components.
111class TGeoUnion : public TGeoBoolNode {
112public:
113 // constructors
114 TGeoUnion();
115 TGeoUnion(const char *expr1, const char *expr2);
116 TGeoUnion(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
117
118 // destructor
119 ~TGeoUnion() override;
120 // methods
122 void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const override;
123 Bool_t Contains(const Double_t *point) const override;
124 Int_t DistanceToPrimitive(Int_t px, Int_t py) override;
125 Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
126 Double_t *safe = nullptr) const override;
127 Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
128 Double_t *safe = nullptr) const override;
129 EGeoBoolType GetBooleanOperator() const override { return kGeoUnion; }
130 Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const override;
131 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
132 void Sizeof3D() const override;
133
134 // CS specific
135 TGeoBoolNode *MakeClone() const override;
136 void Paint(Option_t *option) override;
137
138 ClassDefOverride(TGeoUnion, 1) // union node
139};
140
141/// Boolean node representing an intersection between two components.
143public:
144 // constructors
146 TGeoIntersection(const char *expr1, const char *expr2);
147 TGeoIntersection(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
148
149 // destructor
150 ~TGeoIntersection() override;
151 // methods
153 void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const override;
154 Bool_t Contains(const Double_t *point) const override;
155 Int_t DistanceToPrimitive(Int_t px, Int_t py) override;
156 Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
157 Double_t *safe = nullptr) const override;
158 Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
159 Double_t *safe = nullptr) const override;
161 Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const override;
162 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
163 void Sizeof3D() const override;
164
165 // CS specific
166 TGeoBoolNode *MakeClone() const override;
167 void Paint(Option_t *option) override;
168
169 ClassDefOverride(TGeoIntersection, 1) // intersection node
170};
171
172/// Boolean node representing a subtraction
174public:
175 // constructors
177 TGeoSubtraction(const char *expr1, const char *expr2);
178 TGeoSubtraction(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
179
180 // destructor
181 ~TGeoSubtraction() override;
182 // methods
184 void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const override;
185 Bool_t Contains(const Double_t *point) const override;
186 Int_t DistanceToPrimitive(Int_t px, Int_t py) override;
187 Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
188 Double_t *safe = nullptr) const override;
189 Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
190 Double_t *safe = nullptr) const override;
192 Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const override;
193 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
194 void Sizeof3D() const override;
195
196 // CS specific
197 TGeoBoolNode *MakeClone() const override;
198 void Paint(Option_t *option) override;
199
200 ClassDefOverride(TGeoSubtraction, 1) // subtraction node
201};
202
203#endif
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:78
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
double Double_t
Double 8 bytes.
Definition RtypesCore.h:74
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
#define ClassDefOverride(name, id)
Definition Rtypes.h:347
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t sel
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t points
Base class for Boolean operations between two shapes.
virtual void Sizeof3D() const
Register size of this 3D object.
Int_t fNpoints
! number of points on the mesh
Bool_t MakeBranch(const char *expr, Bool_t left)
Expands the boolean expression either on left or right branch, creating component elements (composite...
TGeoMatrix * fLeftMat
void ClearThreadData() const
~TGeoBoolNode() override
Destructor.
TGeoShape::EInside Inside(const Double_t *point) const
Implementation of the inside function using just Contains and GetNormal.
TGeoShape * fLeft
Bool_t ReplaceMatrix(TGeoMatrix *mat, TGeoMatrix *newmat)
Replace one of the matrices.
virtual Int_t DistanceToPrimitive(Int_t px, Int_t py)=0
virtual EGeoBoolType GetBooleanOperator() const =0
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".
TGeoMatrix * GetRightMatrix() const
TGeoShape * GetLeftShape() const
void Paint(Option_t *option) override
Special schema for feeding the 3D buffers to the painter client.
ThreadData_t & GetThreadData() const
Per-thread scratch state, owned by the calling thread and indexed by this node.
TGeoMatrix * GetLeftMatrix() const
UInt_t fIndex
source of monotonic per-object indices
TGeoBoolNode(const TGeoBoolNode &)=delete
virtual void SetPoints(Double_t *points) const
Fill buffer with shape vertices.
TGeoBoolNode & operator=(const TGeoBoolNode &)=delete
virtual Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const =0
void RegisterMatrices()
Register all matrices of the boolean node and descendents.
virtual Bool_t Contains(const Double_t *point) const =0
virtual void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const =0
virtual void ComputeBBox(Double_t &dx, Double_t &dy, Double_t &dz, Double_t *origin)=0
TGeoShape * fRight
EGeoBoolType
non-reused index of this node into the per-thread vector
Bool_t fMeshValid
! Flag for mesh cache validity
Double_t * fPoints
! array of mesh points
void InvalidateMeshCaches()
Invalidate mesh caching recursively.
virtual Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=0, Double_t *safe=nullptr) const =0
TGeoShape * GetRightShape() const
TGeoBoolNode()
Default constructor.
virtual Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=0, Double_t *safe=nullptr) const =0
Int_t GetNpoints()
Returns number of vertices for the composite shape described by this node.
TGeoMatrix * fRightMat
virtual TGeoBoolNode * MakeClone() const =0
void CreateThreadData(Int_t)
No-op: this node allocates its scratch state lazily for every calling thread.
static std::atomic< UInt_t > fgInstanceCount
void SetSelected(Int_t sel)
Set the selected branch.
Matrix class used for computing global transformations Should NOT be used for node definition.
Definition TGeoMatrix.h:459
Boolean node representing an intersection between two components.
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.
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.
EGeoBoolType GetBooleanOperator() const override
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".
void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const override
Normal computation in POINT. The orientation is chosen so that DIR.dot.NORM>0.
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.
~TGeoIntersection() override
Destructor — deletion of components handled by TGeoManager class.
Bool_t Contains(const Double_t *point) const override
Find if a intersection of two shapes contains a given point.
Geometrical transformation package.
Definition TGeoMatrix.h:39
Base abstract class for all shapes.
Definition TGeoShape.h:25
Boolean node representing a subtraction.
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.
~TGeoSubtraction() override
Destructor — deletion of components handled by TGeoManager class.
Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const override
Compute safety distance for a union node;.
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.
void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const override
Normal computation in POINT. The orientation is chosen so that DIR.dot.NORM>0.
EGeoBoolType GetBooleanOperator() const override
Boolean node representing a union between two components.
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.
void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const override
Normal computation in POINT. The orientation is chosen so that DIR.dot.NORM>0.
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;.
EGeoBoolType GetBooleanOperator() const override
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() override
Destructor — deletion of components handled by TGeoManager class.
TGeoUnion()
Default constructor.
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.
Mother of all ROOT objects.
Definition TObject.h:42