Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:33:30

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 { kGeoUnion, kGeoIntersection, kGeoSubtraction };
0028    struct ThreadData_t {
0029       Int_t fSelected; // ! selected branch
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};      // shape on the left branch
0044    TGeoShape *fRight{nullptr};     // shape on the right branch
0045    TGeoMatrix *fLeftMat{nullptr};  // transformation that applies to the left branch
0046    TGeoMatrix *fRightMat{nullptr}; // transformation that applies to the right branch
0047    Int_t fNpoints{0};              //! number of points on the mesh
0048    Double_t *fPoints{nullptr};     //! array of mesh points
0049 
0050    mutable std::vector<ThreadData_t *> fThreadData; //! Navigation data per thread
0051    mutable Int_t fThreadSize{0};                    //! Size for the navigation data array
0052    mutable std::mutex fMutex;                       //! Mutex for thread data access
0053                                                     // methods
0054    Bool_t MakeBranch(const char *expr, Bool_t left);
0055    void AssignPoints(Int_t npoints, Double_t *points);
0056 
0057 public:
0058    // constructors
0059    TGeoBoolNode();
0060    TGeoBoolNode(const char *expr1, const char *expr2);
0061    TGeoBoolNode(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
0062 
0063    // destructor
0064    ~TGeoBoolNode() override;
0065    // methods
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) const = 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    Int_t GetNpoints();
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    TGeoShape::EInside Inside(const Double_t *point) const;
0081    virtual TGeoBoolNode *MakeClone() const = 0;
0082    void Paint(Option_t *option) override;
0083    void RegisterMatrices();
0084    Bool_t ReplaceMatrix(TGeoMatrix *mat, TGeoMatrix *newmat);
0085    virtual Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const = 0;
0086    void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0087    virtual void SetPoints(Double_t *points) const;
0088    virtual void SetPoints(Float_t *points) const;
0089    void SetSelected(Int_t sel);
0090    virtual void Sizeof3D() const;
0091 
0092    ClassDefOverride(TGeoBoolNode, 1) // a boolean node
0093 };
0094 
0095 /// Boolean node representing a union between two components.
0096 class TGeoUnion : public TGeoBoolNode {
0097 public:
0098    // constructors
0099    TGeoUnion();
0100    TGeoUnion(const char *expr1, const char *expr2);
0101    TGeoUnion(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
0102 
0103    // destructor
0104    ~TGeoUnion() override;
0105    // methods
0106    void ComputeBBox(Double_t &dx, Double_t &dy, Double_t &dz, Double_t *origin) override;
0107    void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const override;
0108    Bool_t Contains(const Double_t *point) const override;
0109    Int_t DistanceToPrimitive(Int_t px, Int_t py) override;
0110    Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0111                            Double_t *safe = nullptr) const override;
0112    Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0113                             Double_t *safe = nullptr) const override;
0114    EGeoBoolType GetBooleanOperator() const override { return kGeoUnion; }
0115    Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const override;
0116    void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0117    void Sizeof3D() const override;
0118 
0119    // CS specific
0120    TGeoBoolNode *MakeClone() const override;
0121    void Paint(Option_t *option) override;
0122 
0123    ClassDefOverride(TGeoUnion, 1) // union node
0124 };
0125 
0126 /// Boolean node representing an intersection between two components.
0127 class TGeoIntersection : public TGeoBoolNode {
0128 public:
0129    // constructors
0130    TGeoIntersection();
0131    TGeoIntersection(const char *expr1, const char *expr2);
0132    TGeoIntersection(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
0133 
0134    // destructor
0135    ~TGeoIntersection() override;
0136    // methods
0137    void ComputeBBox(Double_t &dx, Double_t &dy, Double_t &dz, Double_t *origin) override;
0138    void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const override;
0139    Bool_t Contains(const Double_t *point) const override;
0140    Int_t DistanceToPrimitive(Int_t px, Int_t py) override;
0141    Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0142                            Double_t *safe = nullptr) const override;
0143    Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0144                             Double_t *safe = nullptr) const override;
0145    EGeoBoolType GetBooleanOperator() const override { return kGeoIntersection; }
0146    Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const override;
0147    void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0148    void Sizeof3D() const override;
0149 
0150    // CS specific
0151    TGeoBoolNode *MakeClone() const override;
0152    void Paint(Option_t *option) override;
0153 
0154    ClassDefOverride(TGeoIntersection, 1) // intersection node
0155 };
0156 
0157 /// Boolean node representing a subtraction
0158 class TGeoSubtraction : public TGeoBoolNode {
0159 public:
0160    // constructors
0161    TGeoSubtraction();
0162    TGeoSubtraction(const char *expr1, const char *expr2);
0163    TGeoSubtraction(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
0164 
0165    // destructor
0166    ~TGeoSubtraction() override;
0167    // methods
0168    void ComputeBBox(Double_t &dx, Double_t &dy, Double_t &dz, Double_t *origin) override;
0169    void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const override;
0170    Bool_t Contains(const Double_t *point) const override;
0171    Int_t DistanceToPrimitive(Int_t px, Int_t py) override;
0172    Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0173                            Double_t *safe = nullptr) const override;
0174    Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact = 1, Double_t step = 0,
0175                             Double_t *safe = nullptr) const override;
0176    EGeoBoolType GetBooleanOperator() const override { return kGeoSubtraction; }
0177    Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const override;
0178    void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0179    void Sizeof3D() const override;
0180 
0181    // CS specific
0182    TGeoBoolNode *MakeClone() const override;
0183    void Paint(Option_t *option) override;
0184 
0185    ClassDefOverride(TGeoSubtraction, 1) // subtraction node
0186 };
0187 
0188 #endif