Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
projection_axes.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve_7
3/// Scales and tick labels for projected views, using REveProjectionAxis.
4///
5/// A barrel and a few jets are projected in RhoPhi and RhoZ, and each projected
6/// view gets an axis. Ticks sit at round numbers in the original space and are
7/// drawn where the projection puts them, so with a non-zero distortion their
8/// spacing on screen is uneven. Change the distortion with the <<< and >>>
9/// buttons in each view, or from the ROOT prompt:
10///
11/// pa_distortion(0.001) // then 0.005, and back to 0
12///
13/// The browser relayouts the labels on zoom and pan. Only a change of the
14/// projection goes back to the server. The axes and buttons are in overlay
15/// scenes, which are drawn in front of the geometry.
16///
17/// \macro_code
18///
19/// \author Matevz Tadel
20
21#include <ROOT/REveElement.hxx>
22#include <ROOT/REveGeoShape.hxx>
23#include <ROOT/REveJetCone.hxx>
24#include <ROOT/REveManager.hxx>
27#include <ROOT/REveScene.hxx>
28#include <ROOT/REveText.hxx>
29#include <ROOT/REveViewer.hxx>
30
31#include "TROOT.h"
32#include "TColor.h"
33#include "TGeoTube.h"
34#include "TMath.h"
35#include "TRandom.h"
36
37using namespace ROOT::Experimental;
38
39REveProjectionManager *gPaRPhi = nullptr;
40REveProjectionManager *gPaRhoZ = nullptr;
41/// Ships with ROOT in TROOT::GetDataDir()/fonts.
42static const char *kAxisFont = "LiberationSerif-Regular";
43
44REveProjectionAxis *gPaAxisRPhi = nullptr;
45REveProjectionAxis *gPaAxisRhoZ = nullptr;
46
47const Double_t kR_min = 240;
48const Double_t kR_max = 250;
49const Double_t kZ_d = 300;
50
51//------------------------------------------------------------------------------
52/// Change the distortion of both projections and rebuild the tick sets.
53/// Callable from the ROOT prompt while the macro runs.
54
55void pa_distortion(float d)
56{
58 for (auto mng : {gPaRPhi, gPaRhoZ}) {
59 if (!mng)
60 continue;
61 mng->GetProjection()->SetDistortion(d);
62 mng->UpdateName();
63 mng->ProjectChildren();
64 }
65}
66
67//------------------------------------------------------------------------------
68
69static REveElement *makeSceneContent(REveManager *eveMng)
70{
71 auto holder = new REveElement("Content");
72
73 auto b = new REveGeoShape("Barrel");
74 b->SetShape(new TGeoTube(kR_min, kR_max, kZ_d));
75 b->SetMainColor(kCyan);
76 b->SetMainTransparency(60);
77 b->SetNSegments(64);
78 holder->AddElement(b);
79
80 TRandom &r = *gRandom;
81 for (int i = 0; i < 4; ++i) {
82 auto jet = new REveJetCone(Form("Jet_%d", i));
83 jet->SetCylinder(2 * kR_max, 2 * kZ_d);
84 jet->AddEllipticCone(r.Uniform(-2.5, 2.5), r.Uniform(0, TMath::TwoPi()), r.Uniform(0.05, 0.2),
85 r.Uniform(0.05, 0.25));
86 jet->SetFillColor(kPink - 8);
87 jet->SetLineColor(kBlack);
88 holder->AddElement(jet);
89 }
90
91 eveMng->GetEventScene()->AddElement(holder);
92 return holder;
93}
94
95/// One projected view: a scene for the projected geometry, an overlay scene for
96/// its axis, and an orthographic viewer showing both.
97static void makeProjectedView(REveManager *eveMng, REveElement *content, REveProjection::EPType_e type,
98 const char *name, REveProjectionManager *&mng, REveProjectionAxis *&axis)
99{
100 auto scene = eveMng->SpawnNewScene(Form("%s Scene", name), name);
101 mng = new REveProjectionManager(type);
102 mng->ImportElements(content, scene);
103
104 // Add the manager to the scene it fills. This gives it an element id, which
105 // the overlay buttons need as their MIR target, and streams its name, which
106 // shows the distortion, e.g. "RhoPhi (5.0)".
107 scene->AddElement(mng);
108
109 auto ovl = eveMng->SpawnNewScene(Form("%s Axis", name), name);
110 ovl->SetIsOverlay(true);
111
112 axis = new REveProjectionAxis(mng, Form("%s Axis", name));
113 axis->SetFontSize(0.022);
114 axis->SetFont(kAxisFont);
115 ovl->AddElement(axis);
116
117 // Distortion controls: three overlay texts laid out as [ <<< | value | >>> ].
118 // SetClickAction() makes a text a button that sends a MIR to the projection
119 // manager. BumpDistortion() reprojects and updates the axes and the read-out.
120 {
121 auto mkbtn = [&](const char *label, Float_t x, const char *mir) {
122 auto b = new REveText(Form("%s %s", name, label), label);
123 b->SetText(label);
124 b->SetFont(kAxisFont);
125 // These views are short, so the controls need a larger font than the
126 // tick labels to stay legible, and enough clearance from the bottom
127 // edge that the frame is not clipped by the pane.
128 b->SetFontSize(0.034);
129 b->SetMode(1); // relative screen coordinates
130 b->SetPosition(REveVector(x, 0.10f, 0.f));
131 b->SetTextAlign(REveText::kCenterH, REveText::kBottom);
132 b->SetTextColor(TColor::GetColor("#1f2d36"));
133 b->SetDrawFrame(true);
134 b->SetFillColor(TColor::GetColor("#dfe6ea"));
135 b->SetFillAlpha(210);
136 b->SetLineColor(TColor::GetColor("#6b8290"));
137 b->SetLineAlpha(255);
138 b->SetLineWidth(0.06); // in units of line height
139 b->SetExtraBorder(0.18); // padding, in font-size units
140 b->SetResizable(false); // a control is not a resizable annotation
141 if (mir)
142 b->SetClickAction(mir, mng);
143 ovl->AddElement(b);
144 return b;
145 };
146
147 // The x positions are set by hand, since only the client knows the glyph
148 // metrics.
149 mkbtn("<<<", 0.26f, "BumpDistortion(-1)");
150 auto val = mkbtn("0.0", 0.50f, nullptr); // read-out, not a button
151 mkbtn(">>>", 0.74f, "BumpDistortion(1)");
152
153 axis->SetDistortionLabel(val);
154 }
155
156 auto view = eveMng->SpawnNewViewer(Form("%s View", name), "");
157 view->SetCameraType(REveViewer::kCameraOrthoXOY);
158 view->AddScene(scene);
159 view->AddScene(ovl);
160}
161
162void projection_axes()
163{
164 auto eveMng = REveManager::Create();
165 eveMng->AllowMultipleRemoteConnections(false, false);
166
167 // Generate the SDF atlas from the font file that ships with ROOT.
168 std::string rf = std::string(TROOT::GetDataDir().Data()) + "/fonts/";
169 REveText::AssertSdfFont(kAxisFont, rf + kAxisFont + ".ttf");
170
171 auto content = makeSceneContent(eveMng);
172
173 makeProjectedView(eveMng, content, REveProjection::kPT_RPhi, "RPhi", gPaRPhi, gPaAxisRPhi);
174 makeProjectedView(eveMng, content, REveProjection::kPT_RhoZ, "RhoZ", gPaRhoZ, gPaAxisRhoZ);
175
176 eveMng->Show();
177}
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
double Double_t
Double 8 bytes.
Definition RtypesCore.h:74
@ kPink
Definition Rtypes.h:67
@ kBlack
Definition Rtypes.h:65
@ kCyan
Definition Rtypes.h:66
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:142
R__EXTERN TRandom * gRandom
Definition TRandom.h:73
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2571
Base class for REveUtil visualization elements, providing hierarchy management, rendering control and...
Wrapper for TGeoShape with absolute positioning and color attributes allowing display of extracted TG...
Draws a jet cone with leading particle is specified in (eta,phi) and cone radius is given.
RAII guard for locking Eve manager (ctor) and processing changes (dtor).
Central application manager for web-based REve.
Scales and tick labels for a projected view, the REve counterpart of TEveProjectionAxes.
Manager class for steering of projections and managing projected objects.
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:1939
Cylindrical tube class.
Definition TGeoTube.h:17
static const TString & GetDataDir()
Get the data directory in the installation. Static utility function.
Definition TROOT.cxx:3406
This is the base class for the ROOT Random number generators.
Definition TRandom.h:28
Double_t x[n]
Definition legend1.C:17
Namespace for ROOT features in testing.
Definition TROOT.h:100
constexpr Double_t TwoPi()
Definition TMath.h:47