Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
geomColors.C File Reference

Detailed Description

Script demonstrating geometry color schemes.

*/
#include <string>
#include <algorithm>
#include "TROOT.h"
#include "TColor.h"
#include "TControlBar.h"
#include "TGeoManager.h"
{
TGeoManager::Import("http://root.cern/files/alice2.root");
gGeoManager->GetVolume("ITSV")->Draw("ogl");
}
void help()
{
printf("In the viewer window:\n"
" - de-select \"Reset on update\"\n"
" - in the \"Clipping\" tab, select \"Plane\"\n"
" - rotate the image as uou wish and zoom using the mouse wheel\n"
" - click on the different default color schemes in control bar menu\n"
" - the \"gray\" function demonstrates overriding the Z-based fallback colors\n"
" - the \"override\" function demonstrates color override from a scheme by using a hook\n"
" - the \"transparency\" function demonstrates transparency override\n");
}
//______________________________________________________________________________
void natural()
{
// Predefined "natural" color scheme
return;
}
//______________________________________________________________________________
void flashy()
{
// Predefined "flashy" color scheme
return;
}
//______________________________________________________________________________
{
// Predefined "high-contrast" color scheme
return;
}
//______________________________________________________________________________
void gray()
{
// Gray palette override of the Z-binned fallback
return;
cs.SetZFallbackHook([](Int_t Z, EGeoColorSet) -> Int_t {
float g = std::min(1.f, Z / 100.f);
return TColor::GetColor(g, g, g);
});
}
//______________________________________________________________________________
{
// Transparency override for a color scheme
return;
if (gTransparent) {
cs.SetTransparencyHook([](const TGeoVolume *v) -> Int_t {
if (!m)
return -1;
// Base glass-like transparency for "everything"
Int_t tr = 85; // 0=opaque, 100=fully transparent
// Make typical gases/fluids even more "invisible"
if (m->GetDensity() < 0.1)
tr = 95;
// Optional: slightly reduce transparency for cables/services so they remain visible
if (m->GetName()) {
std::string n = m->GetName();
std::transform(n.begin(), n.end(), n.begin(), [](unsigned char c) { return (char)std::tolower(c); });
if (n.find("cable") != std::string::npos || n.find("cables") != std::string::npos)
tr = 70;
// Optional: keep heavy metals a bit less transparent to preserve structure
if (n.find("tungsten") != std::string::npos || n.find("_w") != std::string::npos)
tr = 75;
}
return tr;
});
} else {
cs.SetTransparencyHook([](const TGeoVolume *v) -> Int_t { return 0; });
}
}
//______________________________________________________________________________
{
// Color override based on volume-related properties
return;
cs.SetColorHook([](const TGeoVolume *v) -> Int_t {
if (!m || !m->GetName())
return -1;
if (std::string(m->GetName()).find("ITS_GEN") != std::string::npos)
return TColor::GetColor(0.9f, 0.55f, 0.3f);
return -1; // fallback to defaults
});
}
//______________________________________________________________________________
void geomColors()
{
// root[0] .x geomColors.C
//
// This opens a GL viewer showing the detector with the user-defined colors.
// In the viewer window:
// - de-select "Reset on update"
// - in the "Clipping" tab, select "Plane"
// - rotate the image as uou wish and zoom using the mouse wheel
// - click on the different default color schemes (natural, flashy, high-contrast) in control bar menu
// - the "Gray fallback" function demonstrates overriding the Z-based fallback colors
// - the "Color override" function demonstrates color override from a scheme by using a hook
// - the "Transparency" function demonstrates transparency override from a scheme using a hook.
// Transparency is attached to TGeoMaterial, so it affects all volumes sharing the same material
TControlBar *bar = new TControlBar("vertical", "Geometry color schemes", 10, 10);
bar->AddButton("How to run ", "help()", "Instructions for running this macro");
bar->AddButton("Natural ", "natural()",
"A natural color scheme with name-based/Z-binned lookup for material classification");
bar->AddButton("Flashy ", "flashy()", "Flashy, high-contrast, presentation-friendly colors");
bar->AddButton("High contrast ", "high_contrast()", "Darker, saturated colors suited for light backgrounds");
bar->AddButton("Gray fallback ", "gray()", "Demonstrates overriding the Z-based fallback colors");
bar->AddButton("Color override ", "color_override()", "Demonstrates color override from a scheme by using a hook");
bar->AddButton("Transparency ON/OFF ", "transparent()",
"Demonstrates transparency override from a scheme by using a hook");
bar->Show();
gROOT->SaveContext();
}
#define c(i)
Definition RSha256.hxx:101
#define g(i)
Definition RSha256.hxx:105
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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.
R__EXTERN TGeoManager * gGeoManager
#define gROOT
Definition TROOT.h:414
const_iterator begin() const
const_iterator end() const
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition TColor.cxx:1926
A Control Bar is a fully user configurable tool which provides fast access to frequently used operati...
Definition TControlBar.h:26
void Show()
Show control bar.
void AddButton(TControlBarButton *button)
Add button.
Strategy object for assigning colors and transparency to geometry volumes.
static const TGeoMaterial * GetMaterial(const TGeoVolume *vol)
Retrieve the material associated with a geometry volume.
void SetVisLevel(Int_t level=3)
set default level down to which visualization is performed
static TGeoManager * Import(const char *filename, const char *name="", Option_t *option="")
static function Import a geometry from a gdml or ROOT file
TGeoVolume * GetVolume(const char *name) const
Search for a named volume. All trailing blanks stripped.
void DefaultColors(const TGeoColorScheme *cs=nullptr)
Set default volume colors according to A of material.
Base class describing materials.
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43
void Draw(Option_t *option="") override
draw top volume according to option
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:457
const Int_t n
Definition legend1.C:16
TMarker m
Definition textangle.C:8
Author
andre.nosp@m.i.gh.nosp@m.eata@.nosp@m.cern.nosp@m..ch

/

Definition in file geomColors.C.