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 // Update the ticks and the read-out, as REveProjectionManager::BumpDistortion()
66 // does for the overlay buttons.
67 for (auto ax : {gPaAxisRPhi, gPaAxisRhoZ}) {
68 if (!ax)
69 continue;
70 ax->UpdateTicks();
71 ax->UpdateDistortionLabel();
72 }
73}
74
75//------------------------------------------------------------------------------
76
77static REveElement *makeSceneContent(REveManager *eveMng)
78{
79 auto holder = new REveElement("Content");
80
81 auto b = new REveGeoShape("Barrel");
82 b->SetShape(new TGeoTube(kR_min, kR_max, kZ_d));
83 b->SetMainColor(kCyan);
84 b->SetMainTransparency(60);
85 b->SetNSegments(64);
86 holder->AddElement(b);
87
88 TRandom &r = *gRandom;
89 for (int i = 0; i < 4; ++i) {
90 auto jet = new REveJetCone(Form("Jet_%d", i));
91 jet->SetCylinder(2 * kR_max, 2 * kZ_d);
92 jet->AddEllipticCone(r.Uniform(-2.5, 2.5), r.Uniform(0, TMath::TwoPi()), r.Uniform(0.05, 0.2),
93 r.Uniform(0.05, 0.25));
94 jet->SetFillColor(kPink - 8);
95 jet->SetLineColor(kBlack);
96 holder->AddElement(jet);
97 }
98
99 eveMng->GetEventScene()->AddElement(holder);
100 return holder;
101}
102
103/// One projected view: a scene for the projected geometry, an overlay scene for
104/// its axis, and an orthographic viewer showing both.
105static void makeProjectedView(REveManager *eveMng, REveElement *content, REveProjection::EPType_e type,
106 const char *name, REveProjectionManager *&mng, REveProjectionAxis *&axis)
107{
108 auto scene = eveMng->SpawnNewScene(Form("%s Scene", name), name);
109 mng = new REveProjectionManager(type);
110 mng->ImportElements(content, scene);
111
112 // Add the manager to the element tree. This gives it an element id, which the
113 // overlay buttons need as their MIR target, and streams its name, which shows
114 // the distortion, e.g. "RhoPhi (5.0)".
115 eveMng->GetWorld()->AddElement(mng);
116
117 auto ovl = eveMng->SpawnNewScene(Form("%s Axis", name), name);
118 ovl->SetIsOverlay(true);
119
120 axis = new REveProjectionAxis(mng, Form("%s Axis", name));
121 axis->SetFontSize(0.022);
122 axis->SetFont(kAxisFont);
123 ovl->AddElement(axis);
124
125 // Distortion controls: three overlay texts laid out as [ <<< | value | >>> ].
126 // SetClickAction() makes a text a button that sends a MIR to the projection
127 // manager. BumpDistortion() reprojects and updates the axes and the read-out.
128 {
129 auto mkbtn = [&](const char *label, Float_t x, const char *mir) {
130 auto b = new REveText(Form("%s %s", name, label), label);
131 b->SetText(label);
132 b->SetFont(kAxisFont);
133 // These views are short, so the controls need a larger font than the
134 // tick labels to stay legible, and enough clearance from the bottom
135 // edge that the frame is not clipped by the pane.
136 b->SetFontSize(0.034);
137 b->SetMode(1); // relative screen coordinates
138 b->SetPosition(REveVector(x, 0.10f, 0.f));
139 b->SetTextAlign(REveText::kCenterH, REveText::kBottom);
140 b->SetTextColor(TColor::GetColor("#1f2d36"));
141 b->SetDrawFrame(true);
142 b->SetFillColor(TColor::GetColor("#dfe6ea"));
143 b->SetFillAlpha(210);
144 b->SetLineColor(TColor::GetColor("#6b8290"));
145 b->SetLineAlpha(255);
146 b->SetLineWidth(0.06); // in units of line height
147 b->SetExtraBorder(0.18); // padding, in font-size units
148 b->SetResizable(false); // a control is not a resizable annotation
149 if (mir)
150 b->SetClickAction(mir, mng);
151 ovl->AddElement(b);
152 return b;
153 };
154
155 // The x positions are set by hand, since only the client knows the glyph
156 // metrics.
157 mkbtn("<<<", 0.26f, "BumpDistortion(-1)");
158 auto val = mkbtn("0.0", 0.50f, nullptr); // read-out, not a button
159 mkbtn(">>>", 0.74f, "BumpDistortion(1)");
160
161 axis->SetDistortionLabel(val);
162 }
163
164 auto view = eveMng->SpawnNewViewer(Form("%s View", name), "");
165 view->SetCameraType(REveViewer::kCameraOrthoXOY);
166 view->AddScene(scene);
167 view->AddScene(ovl);
168}
169
170void projection_axes()
171{
172 auto eveMng = REveManager::Create();
173 eveMng->AllowMultipleRemoteConnections(false, false);
174
175 // Generate the SDF atlas from the font file that ships with ROOT.
176 std::string rf = std::string(TROOT::GetDataDir().Data()) + "/fonts/";
177 REveText::AssertSdfFont(kAxisFont, rf + kAxisFont + ".ttf");
178
179 auto content = makeSceneContent(eveMng);
180
181 makeProjectedView(eveMng, content, REveProjection::kPT_RPhi, "RPhi", gPaRPhi, gPaAxisRPhi);
182 makeProjectedView(eveMng, content, REveProjection::kPT_RhoZ, "RhoZ", gPaRhoZ, gPaAxisRhoZ);
183
184 eveMng->Show();
185}
#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