Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
texts.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve_7
3/// This example display only texts in web browser
4///
5/// \macro_code
6///
7/// \author Waad Fahad
8
9#include "TRandom.h"
10#include <ROOT/REveElement.hxx>
11#include <ROOT/REveScene.hxx>
12#include <ROOT/REveManager.hxx>
13#include <ROOT/REveText.hxx>
14#include <ROOT/REveJetCone.hxx>
15
16namespace REX = ROOT::Experimental;
17
18using namespace ROOT::Experimental;
19
20// 1. Basic fonts
21// Text bluprs to choose from:
22const char *blurbs[] = {"Love", "Peace", "ROOT", "Code", "Courage", "Quiche"};
23const int n_blurbs = sizeof(blurbs) / sizeof(char *);
24
25// These six faces ship with REve and need no TTF and no display.
26// The other fonts in TROOT::GetDataDir()/fonts, such as verdana, georgia, comic and
27// BlackChancery, can be used too: REveText::AssertSdfFont() generates them from the
28// TTF, which needs a display. Some ROOT fonts are super old and will error out
29// (arial, times, cour).
30// clang-format off
31const char *fonts[] = {"LiberationSans-Regular", "LiberationSans-Bold",
32 "LiberationSerif-Regular", "LiberationSerif-Bold",
33 "LiberationMono-Regular", "LiberationMono-Bold"};
34// clang-format on
35const int n_fonts = sizeof(fonts) / sizeof(char *);
36
37// 2. Fonts with diacritcis and most greek letter available through unicode.
38// Not all fonts have them -- most that ship with ROOT don't.
39const char *blurbs2[] = {"Čüšék! Šèžëçàgïlá", "Αβρασαξ", "πφηθωμβτ"};
40const int n_blurbs2 = sizeof(blurbs2) / sizeof(char *);
41
42const char *fonts2[] = {"LiberationMono-Regular", "LiberationSerif-Regular"};
43const int n_fonts2 = sizeof(fonts2) / sizeof(char *);
44
45void makeTexts(int N_Texts, REX::REveElement *textHolder)
46{
47 const double pi = TMath::Pi();
48 const double lim = 300;
49
50 TRandom &r = *gRandom;
51
52 for (int i = 0; i < N_Texts; i++) {
53 std::string word, font;
54 if (r.Integer(2)) {
55 word = blurbs[r.Integer(n_blurbs)];
56 font = fonts[r.Integer(n_fonts)];
57 } else {
58 word = blurbs2[r.Integer(n_blurbs2)];
59 font = fonts2[r.Integer(n_fonts2)];
60 }
61
62 auto name_text = Form("%s_%d", word.data(), i);
63 auto text = new REX::REveText(name_text);
64 text->SetText(name_text);
65
66 text->SetFont(font); // Set by name of file in $ROOTSYS/ui5/eve7/fonts/
67
68 int mode = r.Integer(2);
69 text->SetMode(mode);
70 if (mode == 0) { // world
71 auto &t = text->RefMainTrans();
72 t.SetRotByAngles(r.Uniform(-pi, pi), r.Uniform(-pi, pi), r.Uniform(-pi, pi));
73 t.SetPos(r.Uniform(-lim, lim), r.Uniform(-lim, lim), r.Uniform(-lim, lim));
74 text->SetFontSize(r.Uniform(0.01 * lim, 0.2 * lim));
75 } else { // screen [0, 0] bottom left, [1, 1] top-right corner, font-size in y-units, x scaled with the window
76 // aspect ratio.
77 text->SetPosition(REX::REveVector(r.Uniform(-0.1, 0.9), r.Uniform(0.1, 1.1), r.Uniform(0.0, 1.0)));
78 text->SetFontSize(r.Uniform(0.001, 0.05));
79 }
80 text->SetTextColor(
81 TColor::GetColor((float)r.Uniform(0, 0.5), (float)r.Uniform(0, 0.5), (float)r.Uniform(0, 0.5)));
82 // text->SetMainTransparency();
83 // text->SetLineColor(text->GetTextColor());
84 text->SetLineColor(
85 TColor::GetColor((float)r.Uniform(0, 0.2), (float)r.Uniform(0, 0.2), (float)r.Uniform(0, 0.2)));
86 text->SetLineAlpha(192);
87 text->SetFillColor(
88 TColor::GetColor((float)r.Uniform(0.7, 1.0), (float)r.Uniform(0.7, 1.0), (float)r.Uniform(0.7, 1.0)));
89 text->SetFillAlpha(128);
90 text->SetDrawFrame(true);
91 textHolder->AddElement(text);
92 }
93}
94void makeJets(int N_Jets, REveElement *jetHolder)
95{
96 TRandom &r = *gRandom;
97
98 const Double_t kR_min = 240;
99 const Double_t kR_max = 250;
100 const Double_t kZ_d = 300;
101 for (int i = 0; i < N_Jets; i++) {
102 auto jet = new REveJetCone(Form("Jet_%d", i));
103 jet->SetCylinder(2 * kR_max, 2 * kZ_d);
104 jet->AddEllipticCone(r.Uniform(-0.5, 0.5), r.Uniform(0, TMath::TwoPi()), 0.1, 0.2);
105 jet->SetFillColor(kRed);
106 jet->SetLineColor(kRed);
107
108 jetHolder->AddElement(jet);
109 }
110}
111
112void texts()
113{
114 auto eveMng = REX::REveManager::Create();
115 eveMng->AllowMultipleRemoteConnections(false, false);
116
117 // Initialize SDF fonts.
118 // a) REveText::AssertSdfFont() looks for the font in the SDF font directory and
119 // then in the fonts shipped with REve. A missing font is generated into the
120 // SDF font directory, by default the first of these writable by the current user:
121 // - $ROOTSYS/ui5/eve7/sdf-fonts/
122 // - sdf-fonts/ in the current working directory.
123 // b) Alternatively, REveText::SetSdfFontDir(std::string_view dir, bool require_write_access)
124 // can be called to set this directory manually. If the directory is already pre-populated
125 // with fonts one can set the `require_write_access` argument to false to avoid the
126 // requirement of having write access to that directory.
127
128 std::string rf_dir = gSystem->ExpandPathName("${ROOTSYS}/fonts/");
129 for (int i = 0; i < n_fonts; ++i) {
130 REX::REveText::AssertSdfFont(fonts[i], rf_dir + fonts[i] + ".ttf");
131 }
132 for (int i = 0; i < n_fonts2; ++i) {
133 REX::REveText::AssertSdfFont(fonts2[i], rf_dir + fonts2[i] + ".ttf");
134 }
135
136 // add box to overlay
137 REX::REveScene *os = eveMng->SpawnNewScene("OverlyScene", "OverlayTitle");
138 ((REveViewer *)(eveMng->GetViewers()->FirstChild()))->AddScene(os);
139 os->SetIsOverlay(true);
140
141 REX::REveElement *textHolder = new REX::REveElement("texts");
142 makeTexts(100, textHolder);
143 // os->AddElement(textHolder);
144 eveMng->GetEventScene()->AddElement(textHolder);
145
146 auto jetHolder = new REveElement("jets");
147 makeJets(2, jetHolder);
148 eveMng->GetEventScene()->AddElement(jetHolder);
149
150 eveMng->Show();
151}
double Double_t
Double 8 bytes.
Definition RtypesCore.h:74
@ kRed
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 mode
Option_t Option_t TPoint TPoint const char text
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
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
Base class for REveUtil visualization elements, providing hierarchy management, rendering control and...
Draws a jet cone with leading particle is specified in (eta,phi) and cone radius is given.
Eve representation of a GL view.
virtual void AddElement(REveElement *el)
Add el to the list of children.
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
This is the base class for the ROOT Random number generators.
Definition TRandom.h:28
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1296
TCanvas * fonts()
Definition fonts.C:10
Namespace for ROOT features in testing.
Definition TROOT.h:100
constexpr Double_t Pi()
Definition TMath.h:40
constexpr Double_t TwoPi()
Definition TMath.h:47