Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:50:34

0001 #pragma once
0002 
0003 #include <string>
0004 #include <map>
0005 #include <vector>
0006 
0007 #include "plog/Severity.h"
0008 struct scanvas ; 
0009 
0010 class G4VSolid ; 
0011 class G4Ellipsoid ; 
0012 class G4Tubs ; 
0013 class G4Polycone ; 
0014 class G4Torus ; 
0015 class G4DisplacedSolid ; 
0016 class G4Box ; 
0017 
0018 #include "G4RotationMatrix.hh" 
0019 #include "G4ThreeVector.hh" 
0020 
0021 
0022 /**
0023 U4SolidTree : CSG tree manipulations  
0024 ======================================
0025 
0026 U4SolidTree was developed initially as j/PMTSim/ZSolid 
0027 
0028 Even though U4SolidTree.h is a "private" header it still needs to be 
0029 used across compilation units (eg for tests) hence assume that 
0030 the API_EXPORT is needed 
0031 **/
0032 
0033 
0034 #include "U4_API_EXPORT.hh"
0035 struct U4_API U4SolidTree   
0036 {
0037     // primary API
0038     static const plog::Severity LEVEL ; 
0039     static const bool verbose ; 
0040     static G4VSolid* ApplyZCutTree( const G4VSolid* original, double zcut ); 
0041     static void Draw(const G4VSolid* original, const char* msg="U4SolidTree::Draw" ); 
0042 
0043     // members
0044     const G4VSolid* original ; 
0045     G4VSolid*       root ;     // DeepClone of original, which is identical to original AND fully independent from it 
0046     bool            edited ;   // false, until root changed  or tree pruned
0047   
0048 
0049     // maps populated by instrumentTree
0050     std::map<const G4VSolid*, const G4VSolid*>* parent_map ; 
0051     std::map<const G4VSolid*, int>*             in_map ; 
0052     std::map<const G4VSolid*, int>*             rin_map ; 
0053     std::map<const G4VSolid*, int>*             pre_map ; 
0054     std::map<const G4VSolid*, int>*             rpre_map ; 
0055     std::map<const G4VSolid*, int>*             post_map ; 
0056     std::map<const G4VSolid*, int>*             rpost_map ; 
0057     std::map<const G4VSolid*, int>*             zcls_map ; 
0058     std::map<const G4VSolid*, int>*             depth_map ; 
0059     std::map<const G4VSolid*, char>*            mkr_map ; 
0060 
0061     unsigned width ; 
0062     unsigned height ; 
0063     unsigned extra_width ; 
0064     unsigned extra_height ; 
0065     scanvas* canvas ; 
0066     std::vector<std::string>* names ; 
0067     const char* nameprefix ; 
0068 
0069     std::vector<const G4VSolid*>* inorder ; 
0070     std::vector<const G4VSolid*>* rinorder ; 
0071     std::vector<const G4VSolid*>* preorder ; 
0072     std::vector<const G4VSolid*>* rpreorder ; 
0073     std::vector<const G4VSolid*>* postorder ; 
0074     std::vector<const G4VSolid*>* rpostorder ; 
0075 
0076     std::vector<G4VSolid*>* crux ; 
0077 
0078     // object methods
0079     U4SolidTree(const G4VSolid* root ); 
0080 
0081 
0082     void init(); 
0083 
0084     void instrumentTree();
0085     void parent_r(    const G4VSolid* node, int depth); 
0086     void depth_r(     const G4VSolid* node, int depth);
0087     void inorder_r(   const G4VSolid* node, int depth);
0088     void rinorder_r(  const G4VSolid* node, int depth);
0089     void preorder_r(  const G4VSolid* node, int depth);
0090     void rpreorder_r( const G4VSolid* node, int depth);
0091     void postorder_r( const G4VSolid* node, int depth);
0092     void rpostorder_r(const G4VSolid* node, int depth);
0093 
0094     const G4VSolid* parent( const G4VSolid* node_) const ;
0095     G4VSolid*       parent_( const G4VSolid* node_) const ;
0096 
0097     int depth( const G4VSolid* node_) const ;
0098     int in(    const G4VSolid* node_) const ;
0099     int rin(   const G4VSolid* node_) const ;
0100     int pre(   const G4VSolid* node_) const ;
0101     int rpre(  const G4VSolid* node_) const ;
0102     int post(  const G4VSolid* node_) const ;
0103     int rpost( const G4VSolid* node_) const ;
0104     int index( const G4VSolid* n, int mode ) const ; 
0105 
0106     enum { IN, RIN, PRE, RPRE, POST, RPOST } ; 
0107 
0108     static const char* IN_ ; 
0109     static const char* RIN_ ;
0110     static const char* PRE_ ; 
0111     static const char* RPRE_ ;
0112     static const char* POST_ ;
0113     static const char* RPOST_ ;
0114     static const char* OrderName(int mode);
0115 
0116 
0117 
0118     double getX(const G4VSolid* node ) const ; 
0119     double getY(const G4VSolid* node ) const ; 
0120     double getZ(const G4VSolid* node ) const ; 
0121 
0122     void   getTreeTransform( G4RotationMatrix* rot, G4ThreeVector* tla, const G4VSolid* node ) const ; 
0123 
0124     int classifyTree( double zcut ); 
0125     int classifyTree_r( G4VSolid* node_, int depth, double zcut ); 
0126 
0127     int classifyMask(const G4VSolid* top) const ;
0128     int classifyMask_r( const G4VSolid* node_, int depth ) const ;
0129 
0130     void apply_cut(double zcut);
0131     void cutTree_r( const G4VSolid* node_, int depth, double zcut ); 
0132     void collectNames_inorder_r( const G4VSolid* n, int depth ); 
0133 
0134 
0135     int zcls( const G4VSolid* node_ ) const ;   // formerly had move bool arg, now using move:false 
0136     void set_zcls( const G4VSolid* node_, int zc ); 
0137 
0138     char mkr( const G4VSolid* node_) const ;
0139     void set_mkr( const G4VSolid* node_, char mk ); 
0140 
0141     bool is_include( const G4VSolid* node_ ) const ; 
0142     bool is_exclude( const G4VSolid* node_ ) const ; 
0143     bool is_exclude_include( const G4VSolid* node_ ) const ;
0144     bool is_include_exclude( const G4VSolid* node_ ) const ;
0145     bool is_crux( const G4VSolid* node_ ) const ;
0146 
0147     int num_prim() const ;
0148     int num_prim_r(const G4VSolid* n) const;
0149     int num_node() const; 
0150     static int NumNode_r(const G4VSolid* n, int depth );
0151 
0152     int num_node_select(int qcls) const; 
0153     int num_node_select_r(const G4VSolid* n, int qcls) const ;
0154 
0155     const char* desc() const ; 
0156 
0157     void prune(bool act, int pass); 
0158     void prune_crux(G4VSolid* x, bool act, int pass);
0159 
0160 
0161     void collectNodes( std::vector<const G4VSolid*>& nodes, const G4VSolid* top, int query_zcls  );
0162     void collectNodes_r( std::vector<const G4VSolid*>& nodes, const G4VSolid* node_, int query_zcls, int depth  );
0163 
0164     void draw(const char* msg="U4SolidTree::draw", int pass=-1); 
0165     void draw_r( const G4VSolid* n, int mode); 
0166 
0167     void dumpNames(const char* msg="U4SolidTree::dumpNames") const  ; 
0168 
0169 
0170     void zdump(const char* msg="U4SolidTree::zdump") const ; 
0171     void zdump_r( const G4VSolid* node_, int mode ) const ; 
0172 
0173 
0174 
0175     int maxdepth() const  ;
0176     static int Maxdepth_r( const G4VSolid* node_, int depth); 
0177 
0178     void dump(const char* msg="U4SolidTree::dump") const ; 
0179 
0180     void dumpUp(const char* msg="U4SolidTree::dumpUp") const ; 
0181     void dumpUp_r(const G4VSolid* node, int depth) const ; 
0182 
0183     void dumpTree(const char* msg="U4SolidTree::dumpTree" ) const ; 
0184     void dumpTree_r( const G4VSolid* node, int depth ) const ; 
0185 
0186     // enumerations
0187     enum { 
0188         _G4Other, 
0189         _G4Ellipsoid, 
0190         _G4Tubs, 
0191         _G4Polycone, 
0192         _G4Torus, 
0193         _G4Box,
0194         _G4Orb,
0195         _G4MultiUnion,
0196         _G4Sphere,
0197         _G4UnionSolid, 
0198         _G4SubtractionSolid, 
0199         _G4IntersectionSolid, 
0200         _G4DisplacedSolid 
0201      }; 
0202 
0203     static const char* G4Ellipsoid_ ; 
0204     static const char* G4Tubs_      ;
0205     static const char* G4Polycone_  ;
0206     static const char* G4Torus_     ;
0207     static const char* G4Box_     ;
0208     static const char* G4Orb_     ;
0209     static const char* G4MultiUnion_     ;
0210     static const char* G4Sphere_     ;
0211     static const char* G4UnionSolid_        ;
0212     static const char* G4SubtractionSolid_  ;
0213     static const char* G4IntersectionSolid_ ;
0214     static const char* G4DisplacedSolid_    ;
0215 
0216     static const char* DirtyEntityTag_( const G4VSolid* node );
0217     static const char* EntityTag_( const G4VSolid* solid );
0218 
0219     enum { 
0220        UNDEFINED=0, 
0221          INCLUDE=1<<0, 
0222         STRADDLE=1<<1, 
0223          EXCLUDE=1<<2, 
0224          MIXED=INCLUDE|EXCLUDE
0225      }; 
0226 
0227     static const char* UNDEFINED_ ; 
0228     static const char* INCLUDE_; 
0229     static const char* STRADDLE_ ; 
0230     static const char* EXCLUDE_; 
0231     static const char* ClassifyName( int zcls ); 
0232     static const char* ClassifyMaskName( int zcls ); 
0233 
0234     // simple static convenience functions
0235     static int    ClassifyZCut( double az0, double az1, double zcut ); 
0236 
0237     // basic solid functions
0238     static int             EntityType(      const G4VSolid* solid) ; 
0239     static const char*     EntityTypeName(  const G4VSolid* solid) ; 
0240     static const char*     EntityTag(       const G4VSolid* solid, bool move ) ; // move:true sees thru G4DisplacedSolid 
0241     static bool            IsBoolean(         const G4VSolid* solid) ;
0242     static bool            IsDisplaced(       const G4VSolid* solid) ;
0243     static std::string     Desc(const G4VSolid* solid); 
0244 
0245     // navigation
0246     static const G4VSolid* Left(  const G4VSolid* node) ;
0247     static const G4VSolid* Right( const G4VSolid* node) ;  // NB the G4VSolid returned might be a G4DisplacedSolid wrapping the G4VSolid 
0248     static const G4VSolid* Moved( const G4VSolid* node) ;
0249     static const G4VSolid* Moved( G4RotationMatrix* rot, G4ThreeVector* tla, const G4VSolid* node) ;
0250 
0251     static       G4VSolid* Left_(       G4VSolid* node) ;
0252     static       G4VSolid* Right_(      G4VSolid* node) ;
0253     static       G4VSolid* Moved_(      G4VSolid* node) ;
0254     static       G4VSolid* Moved_( G4RotationMatrix* rot, G4ThreeVector* tla, G4VSolid* node) ;
0255 
0256     // local node frame access 
0257     static void XRange( double& x0, double& x1,  const G4VSolid* solid ) ; 
0258     static void YRange( double& y0, double& y1,  const G4VSolid* solid ) ; 
0259     static void ZRange( double& z0, double& z1,  const G4VSolid* solid ) ; 
0260 
0261     static bool CanX(   const G4VSolid* solid ); 
0262     static bool CanY(   const G4VSolid* solid ); 
0263     static bool CanZ(   const G4VSolid* solid ); 
0264 
0265     static void GetXRange( const G4Box*       const box      , double& x0, double& x1 );
0266     static void GetYRange( const G4Box*       const box      , double& y0, double& y1 );
0267     static void GetZRange( const G4Box*       const box      , double& z0, double& z1 );
0268 
0269     static void GetZRange( const G4Ellipsoid* const ellipsoid, double& z0, double& z1 );
0270     static void GetZRange( const G4Tubs*      const tubs     , double& z0, double& z1 ); 
0271     static void GetZRange( const G4Polycone*  const polycone , double& z0, double& z1 ); 
0272     static void GetZRange( const G4Torus*     const torus,     double& z0, double& z1 ); 
0273 
0274     // tree cloning methods
0275     static G4VSolid* DeepClone(    const G4VSolid* solid ); 
0276     static G4VSolid* DeepClone_r(  const G4VSolid* solid, int depth, G4RotationMatrix* rot, G4ThreeVector* tla ); 
0277     static G4VSolid* BooleanClone( const G4VSolid* solid, int depth, G4RotationMatrix* rot, G4ThreeVector* tla ); 
0278 
0279     static void DeepCloneDump( int depth, const G4VSolid* node_ , const G4VSolid* node , G4ThreeVector* tla ); 
0280 
0281     static void ExpectNonNull( const G4VSolid* clone, const char* msg ); 
0282     static void ExpectNoRotation(    const G4RotationMatrix* rot, const char* msg ); 
0283     static void ExpectNoTranslation( const G4ThreeVector*    tla, const char* msg, bool skip_assert ); 
0284     static void ExpectNoDisplaced( const G4VSolid* solid, const char* msg ); 
0285 
0286 
0287     static void GetBooleanBytes(char** bytes, int& num_bytes, const G4VSolid* solid );
0288     static int CompareBytes( char* bytes0, char* bytes1, int num_bytes ); 
0289     static void PlacementNewDupe( G4VSolid* solid); 
0290     static void SetLeft(  G4VSolid* node, G4VSolid* left);  
0291     static void SetRight( G4VSolid* node, G4VSolid* right, G4RotationMatrix* rrot=nullptr, G4ThreeVector* rtla=nullptr ); 
0292 
0293 
0294     static void      CheckBooleanClone( const G4VSolid* clone, const G4VSolid* left, const G4VSolid* right ); 
0295     static G4VSolid* PrimitiveClone( const  G4VSolid* solid ); 
0296     static G4VSolid* PrimitiveClone( const  G4VSolid* solid, const char* name ); 
0297 
0298 
0299     static G4VSolid* PromoteTubsToPolycone( const G4VSolid* solid ); 
0300     static const bool PROMOTE_TUBS_TO_POLYCONE ; 
0301 
0302     static void ApplyZCut(             G4VSolid* node, double local_zcut); 
0303     static void ApplyZCut_G4Ellipsoid( G4VSolid* node, double local_zcut);
0304     static void ApplyZCut_G4Tubs(      G4VSolid* node, double local_zcut);
0305     static void ApplyZCut_G4Polycone(  G4VSolid* node, double local_zcut);
0306     static void ApplyZCut_G4Polycone_NotWorking(  G4VSolid* node, double local_zcut);
0307 
0308     static const char* CommonPrefix(const std::vector<std::string>* a); 
0309 
0310 }; 
0311