Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:50

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 "TObject.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) = 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) // a boolean node
0092 };
0093 
0094 //////////////////////////////////////////////////////////////////////////////
0095 //                                                                          //
0096 // TGeoUnion - Boolean node representing a union between two components.    //
0097 //                                                                          //
0098 //////////////////////////////////////////////////////////////////////////////
0099 
0100 class TGeoUnion : public TGeoBoolNode {
0101 public:
0102    // constructors
0103    TGeoUnion();
0104    TGeoUnion(const char *expr1, const char *expr2);
0105    TGeoUnion(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
0106 
0107    // destructor
0108    ~TGeoUnion() override;
0109    // methods
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    // CS specific
0125    TGeoBoolNode *MakeClone() const override;
0126    void Paint(Option_t *option) override;
0127 
0128    ClassDefOverride(TGeoUnion, 1) // union node
0129 };
0130 
0131 //////////////////////////////////////////////////////////////////////////////
0132 //                                                                          //
0133 // TGeoIntersection - Boolean node representing an intersection between two //
0134 // components.                                                              //
0135 //                                                                          //
0136 //////////////////////////////////////////////////////////////////////////////
0137 
0138 class TGeoIntersection : public TGeoBoolNode {
0139 public:
0140    // constructors
0141    TGeoIntersection();
0142    TGeoIntersection(const char *expr1, const char *expr2);
0143    TGeoIntersection(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
0144 
0145    // destructor
0146    ~TGeoIntersection() override;
0147    // methods
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    // CS specific
0163    TGeoBoolNode *MakeClone() const override;
0164    void Paint(Option_t *option) override;
0165 
0166    ClassDefOverride(TGeoIntersection, 1) // intersection node
0167 };
0168 
0169 //////////////////////////////////////////////////////////////////////////////
0170 //                                                                          //
0171 // TGeoSubtraction - Boolean node representing a subtraction.               //
0172 //                                                                          //
0173 //////////////////////////////////////////////////////////////////////////////
0174 
0175 class TGeoSubtraction : public TGeoBoolNode {
0176 public:
0177    // constructors
0178    TGeoSubtraction();
0179    TGeoSubtraction(const char *expr1, const char *expr2);
0180    TGeoSubtraction(TGeoShape *left, TGeoShape *right, TGeoMatrix *lmat = nullptr, TGeoMatrix *rmat = nullptr);
0181 
0182    // destructor
0183    ~TGeoSubtraction() override;
0184    // methods
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    // CS specific
0200    TGeoBoolNode *MakeClone() const override;
0201    void Paint(Option_t *option) override;
0202 
0203    ClassDefOverride(TGeoSubtraction, 1) // subtraction node
0204 };
0205 
0206 #endif