Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGeoColorScheme.h
Go to the documentation of this file.
1//==============================================================================
2// TGeoColorScheme.h
3//==============================================================================
4
5#ifndef ROOT_TGeoColorScheme
6#define ROOT_TGeoColorScheme
7
8#include "Rtypes.h"
9#include <functional>
10
11class TGeoVolume;
12class TGeoMaterial;
13
14/**
15 * @enum EGeoColorSet
16 * @brief Enumeration of predefined geometry color schemes.
17 *
18 * These values select the built-in default coloring policy used by
19 * TGeoColorScheme when assigning colors to geometry volumes.
20 *
21 * @see TGeoColorScheme
22 */
23enum class EGeoColorSet {
24 kNatural = 0, ///< Natural, material-inspired colors (default)
25 kFlashy, ///< Bright, high-contrast colors for presentations
26 kHighContrast ///< Dark, saturated colors for light backgrounds
27};
28
29/**
30 * @class TGeoColorScheme
31 * @brief Strategy object for assigning colors and transparency to geometry volumes.
32 *
33 * This class is used by TGeoManager::DefaultColors(const TGeoColorScheme*)
34 * to assign visualization colors and transparency to geometry volumes,
35 * typically after GDML import where no color information is stored.
36 *
37 * The default implementation combines:
38 * - name-based material classification (e.g. metals, polymers, gases),
39 * - a Z-binned fallback lookup when no name-based rule applies.
40 *
41 * This class is intended for runtime use only (not persistified).
42 * Users can extend or override the default behavior by:
43 * - installing hooks via std::function, or
44 * - subclassing and overriding virtual methods.
45 *
46 * @see TGeoManager::DefaultColors
47 */
49public:
50 /// Type of user hook for overriding color assignment.
51 using ColorHook_t = std::function<Int_t(const TGeoVolume *)>;
52
53 /// Type of user hook for overriding transparency assignment.
54 using TranspHook_t = std::function<Int_t(const TGeoVolume *)>;
55
56 /// Type of user hook for overriding the Z-based fallback coloring.
57 using ZFallbackHook_t = std::function<Int_t(Int_t /*Z*/, EGeoColorSet /*set*/)>;
58
59 /**
60 * @brief Constructor.
61 *
62 * \param set Initial color set selection (natural, flashy, high-contrast).
63 */
65
66 /// @brief Virtual destructor.
68
69 /**
70 * @brief Compute the color for a given volume.
71 *
72 * This method is called by TGeoManager::DefaultColors() for each volume.
73 * The default implementation:
74 * - calls the user color hook if installed,
75 * - applies name-based material overrides,
76 * - falls back to ColorForZ() if no rule matches.
77 *
78 * @param vol Geometry volume to be colored.
79 * @return ROOT color index (>=0) to apply, or <0 for "no decision".
80 *
81 * @see Transparency
82 * @see ColorForZ
83 * @see TGeoManager::DefaultColors
84 */
85 virtual Int_t Color(const TGeoVolume *vol) const;
86
87 /**
88 * @brief Compute the transparency for a given volume.
89 *
90 * The default implementation:
91 * - calls the user transparency hook if installed,
92 * - makes very low-density materials (e.g. gases) semi-transparent.
93 *
94 * @param vol Geometry volume.
95 * @return Transparency value in [0..100] to apply, or <0 to leave unchanged.
96 *
97 * @see Color
98 * @see TGeoManager::DefaultColors
99 */
100 virtual Int_t Transparency(const TGeoVolume *vol) const;
101
102 /**
103 * @brief Compute fallback color based on material effective Z.
104 *
105 * This method is used when no name-based material override applies.
106 * Users may override this behavior via SetZFallbackHook() or by
107 * subclassing and overriding this method.
108 *
109 * @param Z Effective atomic number of the material.
110 * @param set Active color set selection.
111 * @return ROOT color index (>=0) to apply.
112 *
113 * @see SetZFallbackHook
114 */
115 virtual Int_t ColorForZ(Int_t Z, EGeoColorSet set) const;
116
117 /**
118 * @brief Set a user hook for color assignment.
119 *
120 * The hook is called before any built-in logic.
121 * Returning a value <0 delegates the decision to the default implementation.
122 *
123 * @param h Color hook (set to nullptr to disable).
124 *
125 * @see Color
126 */
127 void SetColorHook(ColorHook_t h) { fColorHook = std::move(h); }
128
129 /**
130 * @brief Set a user hook for transparency assignment.
131 *
132 * The hook is called before the default transparency logic.
133 * Returning a value <0 delegates the decision to the default implementation.
134 *
135 * @param h Transparency hook (set to nullptr to disable).
136 *
137 * @see Transparency
138 */
140
141 /**
142 * @brief Set a user hook for Z-based fallback coloring.
143 *
144 * The hook is called before the built-in Z-binned lookup.
145 * Returning a value <0 delegates the decision to the default implementation.
146 *
147 * @param h Z-fallback hook (set to nullptr to disable).
148 *
149 * @see ColorForZ
150 */
152
153 /// @brief Get the active color set.
154 EGeoColorSet GetSet() const { return fSet; }
155
156 /// @brief Set the active color set.
157 void SetSet(EGeoColorSet s) { fSet = s; }
158
159 /**
160 * @brief Retrieve the material associated with a geometry volume.
161 *
162 * This helper performs all necessary pointer checks and may be safely
163 * used inside user hooks.
164 *
165 * @param vol Geometry volume.
166 * @return Pointer to the associated material, or nullptr if unavailable.
167 */
168 static const TGeoMaterial *GetMaterial(const TGeoVolume *vol);
169
170private:
171 EGeoColorSet fSet; ///< Active color set selection
172
173 ColorHook_t fColorHook = nullptr; ///< Optional user hook for color assignment
174 TranspHook_t fTranspHook = nullptr; ///< Optional user hook for transparency
175 ZFallbackHook_t fZFallbackHook = nullptr; ///< Optional user hook for Z fallback
176};
177
178#endif // ROOT_TGeoColorScheme
#define h(i)
Definition RSha256.hxx:106
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
EGeoColorSet
Enumeration of predefined geometry color schemes.
@ kNatural
Natural, material-inspired colors (default)
@ kFlashy
Bright, high-contrast colors for presentations.
@ kHighContrast
Dark, saturated colors for light backgrounds.
Strategy object for assigning colors and transparency to geometry volumes.
virtual Int_t Transparency(const TGeoVolume *vol) const
Compute the transparency for a given volume.
std::function< Int_t(Int_t, EGeoColorSet)> ZFallbackHook_t
Type of user hook for overriding the Z-based fallback coloring.
std::function< Int_t(const TGeoVolume *)> ColorHook_t
Type of user hook for overriding color assignment.
TGeoColorScheme(EGeoColorSet set=EGeoColorSet::kNatural)
Constructor.
virtual Int_t ColorForZ(Int_t Z, EGeoColorSet set) const
Compute fallback color based on material effective Z.
void SetColorHook(ColorHook_t h)
Set a user hook for color assignment.
void SetSet(EGeoColorSet s)
Set the active color set.
virtual Int_t Color(const TGeoVolume *vol) const
Compute the color for a given volume.
EGeoColorSet fSet
Active color set selection.
EGeoColorSet GetSet() const
Get the active color set.
TranspHook_t fTranspHook
Optional user hook for transparency.
static const TGeoMaterial * GetMaterial(const TGeoVolume *vol)
Retrieve the material associated with a geometry volume.
std::function< Int_t(const TGeoVolume *)> TranspHook_t
Type of user hook for overriding transparency assignment.
ZFallbackHook_t fZFallbackHook
Optional user hook for Z fallback.
virtual ~TGeoColorScheme()
Virtual destructor.
void SetZFallbackHook(ZFallbackHook_t h)
Set a user hook for Z-based fallback coloring.
ColorHook_t fColorHook
Optional user hook for color assignment.
void SetTransparencyHook(TranspHook_t h)
Set a user hook for transparency assignment.
Base class describing materials.
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43