File indexing completed on 2025-01-18 10:11:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TGeoBoolNode
0013 #define ROOT_TGeoBoolNode
0014
0015 #include "TObject.h"
0016
0017 #include <mutex>
0018 #include <vector>
0019
0020
0021 class TGeoShape;
0022 class TGeoMatrix;
0023 class TGeoHMatrix;
0024
0025 class TGeoBoolNode : public TObject {
0026 public:
0027 enum EGeoBoolType { kGeoUnion, kGeoIntersection, kGeoSubtraction };
0028 struct ThreadData_t {
0029 Int_t fSelected;
0030
0031 ThreadData_t();
0032 ~ThreadData_t();
0033 };
0034 ThreadData_t &GetThreadData() const;
0035 void ClearThreadData() const;
0036 void CreateThreadData(Int_t nthreads);
0037
0038 private:
0039 TGeoBoolNode(const TGeoBoolNode &) = delete;
0040 TGeoBoolNode &operator=(const TGeoBoolNode &) = delete;
0041
0042 protected:
0043 TGeoShape *fLeft{nullptr};
0044 TGeoShape *fRight{nullptr};
0045 TGeoMatrix *fLeftMat{nullptr};
0046 TGeoMatrix *fRightMat{nullptr};
0047 Int_t fNpoints{0};
0048 Double_t *fPoints{nullptr};
0049
0050 mutable std::vector<ThreadData_t *> fThreadData;
0051 mutable Int_t fThreadSize{0};
0052 mutable std::mutex fMutex;
0053
0054 Bool_t MakeBranch(const char *expr, Bool_t left);
0055 void AssignPoints(Int_t npoints, Double_t *points);
0056
0057 public:
0058
0059 TGeoBoolNode();
0060 TGeoBoolNode(const char *expr1, const char *expr2);
0061 TGeoBoolNode(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
0062
0063
0064 ~TGeoBoolNode() override;
0065
0066 virtual void ComputeBBox(Double_t &dx, Double_t &dy, Double_t &dz, Double_t *origin) = 0;
0067 virtual void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) = 0;
0068 virtual Bool_t Contains(const Double_t *point) const = 0;
0069 virtual Int_t DistanceToPrimitive(Int_t px, Int_t py) = 0;
0070 virtual Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0071 Double_t *safe = nullptr) const = 0;
0072 virtual Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0073 Double_t *safe = nullptr) const = 0;
0074 virtual EGeoBoolType GetBooleanOperator() const = 0;
0075 virtual Int_t GetNpoints() = 0;
0076 TGeoMatrix *GetLeftMatrix() const { return fLeftMat; }
0077 TGeoMatrix *GetRightMatrix() const { return fRightMat; }
0078 TGeoShape *GetLeftShape() const { return fLeft; }
0079 TGeoShape *GetRightShape() const { return fRight; }
0080 virtual TGeoBoolNode *MakeClone() const = 0;
0081 void Paint(Option_t *option) override;
0082 void RegisterMatrices();
0083 Bool_t ReplaceMatrix(TGeoMatrix *mat, TGeoMatrix *newmat);
0084 virtual Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const = 0;
0085 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0086 virtual void SetPoints(Double_t *points) const;
0087 virtual void SetPoints(Float_t *points) const;
0088 void SetSelected(Int_t sel);
0089 virtual void Sizeof3D() const;
0090
0091 ClassDefOverride(TGeoBoolNode, 1)
0092 };
0093
0094
0095
0096
0097
0098
0099
0100 class TGeoUnion : public TGeoBoolNode {
0101 public:
0102
0103 TGeoUnion();
0104 TGeoUnion(const char *expr1, const char *expr2);
0105 TGeoUnion(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
0106
0107
0108 ~TGeoUnion() override;
0109
0110 void ComputeBBox(Double_t &dx, Double_t &dy, Double_t &dz, Double_t *origin) override;
0111 void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) override;
0112 Bool_t Contains(const Double_t *point) const override;
0113 Int_t DistanceToPrimitive(Int_t px, Int_t py) override;
0114 Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0115 Double_t *safe = nullptr) const override;
0116 Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0117 Double_t *safe = nullptr) const override;
0118 EGeoBoolType GetBooleanOperator() const override { return kGeoUnion; }
0119 Int_t GetNpoints() override;
0120 Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const override;
0121 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0122 void Sizeof3D() const override;
0123
0124
0125 TGeoBoolNode *MakeClone() const override;
0126 void Paint(Option_t *option) override;
0127
0128 ClassDefOverride(TGeoUnion, 1)
0129 };
0130
0131
0132
0133
0134
0135
0136
0137
0138 class TGeoIntersection : public TGeoBoolNode {
0139 public:
0140
0141 TGeoIntersection();
0142 TGeoIntersection(const char *expr1, const char *expr2);
0143 TGeoIntersection(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
0144
0145
0146 ~TGeoIntersection() override;
0147
0148 void ComputeBBox(Double_t &dx, Double_t &dy, Double_t &dz, Double_t *origin) override;
0149 void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) override;
0150 Bool_t Contains(const Double_t *point) const override;
0151 Int_t DistanceToPrimitive(Int_t px, Int_t py) override;
0152 Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0153 Double_t *safe = nullptr) const override;
0154 Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0155 Double_t *safe = nullptr) const override;
0156 EGeoBoolType GetBooleanOperator() const override { return kGeoIntersection; }
0157 Int_t GetNpoints() override;
0158 Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const override;
0159 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0160 void Sizeof3D() const override;
0161
0162
0163 TGeoBoolNode *MakeClone() const override;
0164 void Paint(Option_t *option) override;
0165
0166 ClassDefOverride(TGeoIntersection, 1)
0167 };
0168
0169
0170
0171
0172
0173
0174
0175 class TGeoSubtraction : public TGeoBoolNode {
0176 public:
0177
0178 TGeoSubtraction();
0179 TGeoSubtraction(const char *expr1, const char *expr2);
0180 TGeoSubtraction(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
0181
0182
0183 ~TGeoSubtraction() override;
0184
0185 void ComputeBBox(Double_t &dx, Double_t &dy, Double_t &dz, Double_t *origin) override;
0186 void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) override;
0187 Bool_t Contains(const Double_t *point) const override;
0188 Int_t DistanceToPrimitive(Int_t px, Int_t py) override;
0189 Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0190 Double_t *safe = nullptr) const override;
0191 Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0192 Double_t *safe = nullptr) const override;
0193 EGeoBoolType GetBooleanOperator() const override { return kGeoSubtraction; }
0194 Int_t GetNpoints() override;
0195 Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const override;
0196 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0197 void Sizeof3D() const override;
0198
0199
0200 TGeoBoolNode *MakeClone() const override;
0201 void Paint(Option_t *option) override;
0202
0203 ClassDefOverride(TGeoSubtraction, 1)
0204 };
0205
0206 #endif