Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-02 09:24:07

0001 // @(#):$Id$
0002 // Author: Andrei Gheata   30/05/02
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TGeoBoolNode
0013 #define ROOT_TGeoBoolNode
0014 
0015 #include "TGeoShape.h"
0016 
0017 #include <mutex>
0018 #include <vector>
0019 
0020 // forward declarations
0021 class TGeoShape;
0022 class TGeoMatrix;
0023 class TGeoHMatrix;
0024 
0025 class TGeoBoolNode : public TObject {
0026 public:
0027    enum EGeoBoolType {
0028       kGeoUnion,
0029       kGeoIntersection,
0030       kGeoSubtraction
0031    };
0032    struct ThreadData_t {
0033       Int_t fSelected; // ! selected branch
0034 
0035       ThreadData_t();
0036       ~ThreadData_t();
0037    };
0038    ThreadData_t &GetThreadData() const;
0039    void ClearThreadData() const;
0040    void CreateThreadData(Int_t nthreads);
0041 
0042 private:
0043    TGeoBoolNode(const TGeoBoolNode &) = delete;
0044    TGeoBoolNode &operator=(const TGeoBoolNode &) = delete;
0045 
0046 protected:
0047    TGeoShape *fLeft{nullptr};          // shape on the left branch
0048    TGeoShape *fRight{nullptr};         // shape on the right branch
0049    TGeoMatrix *fLeftMat{nullptr};      // transformation that applies to the left branch
0050    TGeoMatrix *fRightMat{nullptr};     // transformation that applies to the right branch
0051    mutable Int_t fNpoints{0};          ///<! number of points on the mesh
0052    mutable Double_t *fPoints{nullptr}; ///<! array of mesh points
0053 
0054    mutable std::vector<ThreadData_t *> fThreadData; ///<! Navigation data per thread
0055    mutable Int_t fThreadSize{0};                    ///<! Size for the navigation data array
0056    mutable std::mutex fMutex;                       ///<! Mutex for thread data access
0057    mutable Bool_t fMeshValid{kFALSE};               ///<! Flag for mesh cache validity
0058                                                     // methods
0059    Bool_t MakeBranch(const char *expr, Bool_t left);
0060    void AssignPoints(Int_t npoints, Double_t *points);
0061 
0062 public:
0063    // constructors
0064    TGeoBoolNode();
0065    TGeoBoolNode(const char *expr1, const char *expr2);
0066    TGeoBoolNode(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
0067 
0068    // destructor
0069    ~TGeoBoolNode() override;
0070    // methods
0071    virtual void ComputeBBox(Double_t &dx, Double_t &dy, Double_t &dz, Double_t *origin) = 0;
0072    virtual void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const = 0;
0073    virtual Bool_t Contains(const Double_t *point) const = 0;
0074    virtual Int_t DistanceToPrimitive(Int_t px, Int_t py) = 0;
0075    virtual Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0076                                    Double_t *safe = nullptr) const = 0;
0077    virtual Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0078                                     Double_t *safe = nullptr) const = 0;
0079    virtual EGeoBoolType GetBooleanOperator() const = 0;
0080    Int_t GetNpoints();
0081    TGeoMatrix *GetLeftMatrix() const { return fLeftMat; }
0082    TGeoMatrix *GetRightMatrix() const { return fRightMat; }
0083    TGeoShape *GetLeftShape() const { return fLeft; }
0084    TGeoShape *GetRightShape() const { return fRight; }
0085    TGeoShape::EInside Inside(const Double_t *point) const;
0086    void InvalidateMeshCaches();
0087    virtual TGeoBoolNode *MakeClone() const = 0;
0088    void Paint(Option_t *option) override;
0089    void RegisterMatrices();
0090    Bool_t ReplaceMatrix(TGeoMatrix *mat, TGeoMatrix *newmat);
0091    virtual Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const = 0;
0092    void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0093    virtual void SetPoints(Double_t *points) const;
0094    virtual void SetPoints(Float_t *points) const;
0095    void SetSelected(Int_t sel);
0096    virtual void Sizeof3D() const;
0097 
0098    ClassDefOverride(TGeoBoolNode, 1) // a boolean node
0099 };
0100 
0101 /// Boolean node representing a union between two components.
0102 class TGeoUnion : public TGeoBoolNode {
0103 public:
0104    // constructors
0105    TGeoUnion();
0106    TGeoUnion(const char *expr1, const char *expr2);
0107    TGeoUnion(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
0108 
0109    // destructor
0110    ~TGeoUnion() override;
0111    // methods
0112    void ComputeBBox(Double_t &dx, Double_t &dy, Double_t &dz, Double_t *origin) override;
0113    void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const override;
0114    Bool_t Contains(const Double_t *point) const override;
0115    Int_t DistanceToPrimitive(Int_t px, Int_t py) override;
0116    Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0117                            Double_t *safe = nullptr) const override;
0118    Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0119                             Double_t *safe = nullptr) const override;
0120    EGeoBoolType GetBooleanOperator() const override { return kGeoUnion; }
0121    Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const override;
0122    void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0123    void Sizeof3D() const override;
0124 
0125    // CS specific
0126    TGeoBoolNode *MakeClone() const override;
0127    void Paint(Option_t *option) override;
0128 
0129    ClassDefOverride(TGeoUnion, 1) // union node
0130 };
0131 
0132 /// Boolean node representing an intersection between two components.
0133 class TGeoIntersection : public TGeoBoolNode {
0134 public:
0135    // constructors
0136    TGeoIntersection();
0137    TGeoIntersection(const char *expr1, const char *expr2);
0138    TGeoIntersection(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
0139 
0140    // destructor
0141    ~TGeoIntersection() override;
0142    // methods
0143    void ComputeBBox(Double_t &dx, Double_t &dy, Double_t &dz, Double_t *origin) override;
0144    void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const override;
0145    Bool_t Contains(const Double_t *point) const override;
0146    Int_t DistanceToPrimitive(Int_t px, Int_t py) override;
0147    Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0148                            Double_t *safe = nullptr) const override;
0149    Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0150                             Double_t *safe = nullptr) const override;
0151    EGeoBoolType GetBooleanOperator() const override { return kGeoIntersection; }
0152    Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const override;
0153    void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0154    void Sizeof3D() const override;
0155 
0156    // CS specific
0157    TGeoBoolNode *MakeClone() const override;
0158    void Paint(Option_t *option) override;
0159 
0160    ClassDefOverride(TGeoIntersection, 1) // intersection node
0161 };
0162 
0163 /// Boolean node representing a subtraction
0164 class TGeoSubtraction : public TGeoBoolNode {
0165 public:
0166    // constructors
0167    TGeoSubtraction();
0168    TGeoSubtraction(const char *expr1, const char *expr2);
0169    TGeoSubtraction(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
0170 
0171    // destructor
0172    ~TGeoSubtraction() override;
0173    // methods
0174    void ComputeBBox(Double_t &dx, Double_t &dy, Double_t &dz, Double_t *origin) override;
0175    void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const override;
0176    Bool_t Contains(const Double_t *point) const override;
0177    Int_t DistanceToPrimitive(Int_t px, Int_t py) override;
0178    Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0179                            Double_t *safe = nullptr) const override;
0180    Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0181                             Double_t *safe = nullptr) const override;
0182    EGeoBoolType GetBooleanOperator() const override { return kGeoSubtraction; }
0183    Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const override;
0184    void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0185    void Sizeof3D() const override;
0186 
0187    // CS specific
0188    TGeoBoolNode *MakeClone() const override;
0189    void Paint(Option_t *option) override;
0190 
0191    ClassDefOverride(TGeoSubtraction, 1) // subtraction node
0192 };
0193 
0194 #endif