Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
texts.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve7
3/// This example display only texts in web browser
4///
5/// \Waad
6///
7
8#include "TRandom.h"
10#include <ROOT/REveScene.hxx>
11#include <ROOT/REveManager.hxx>
12#include <ROOT/REveText.hxx>
13#include <ROOT/REveJetCone.hxx>
14
15namespace REX = ROOT::Experimental;
16
17using namespace ROOT::Experimental;
18
19// 1. Basic fonts
20// Text bluprs to choose from:
21const char *blurbs[] = {"Love", "Peace", "ROOT", "Code", "Courage", "Quiche"};
22const int n_blurbs = sizeof(blurbs) / sizeof(char *);
23
24// Some ROOT fonts are supper old and will error out (arial, times, cour).
25const char *fonts[] = {"comic", "comicbd", "verdana", "BlackChancery", "georgia", "georgiai"};
26const int n_fonts = sizeof(fonts) / sizeof(char *);
27
28// 2. Fonts with diacritcis and most greek letter available through unicode.
29// Not all fonts have them -- most that ship with ROOT don't.
30const char *blurbs2[] = {"Čüšék! Šèžëçàgïlá", "Αβρασαξ", "πφηθωμβτ"};
31const int n_blurbs2 = sizeof(blurbs2) / sizeof(char *);
32
33const char *fonts2[] = {"LiberationMono-Regular", "LiberationSerif-Regular"};
34const int n_fonts2 = sizeof(fonts2) / sizeof(char *);
35
36void makeTexts(int N_Texts, REX::REveElement *textHolder)
37{
38 const double pi = TMath::Pi();
39 const double lim = 300;
40
41 TRandom &r = *gRandom;
42
43 for (int i = 0; i < N_Texts; i++) {
44 std::string word, font;
45 if (r.Integer(2)) {
46 word = blurbs[r.Integer(n_blurbs)];
47 font = fonts[r.Integer(n_fonts)];
48 } else {
49 word = blurbs2[r.Integer(n_blurbs2)];
50 font = fonts2[r.Integer(n_fonts2)];
51 }
52
53 auto name_text = Form("%s_%d", word.data(), i);
54 auto text = new REX::REveText(name_text);
55 text->SetText(name_text);
56
57 text->SetFont(font); // Set by name of file in $ROOTSYS/ui5/eve7/fonts/
58
59 int mode = r.Integer(2);
60 text->SetMode(mode);
61 if (mode == 0) { // world
62 auto &t = text->RefMainTrans();
63 t.SetRotByAngles(r.Uniform(-pi, pi), r.Uniform(-pi, pi), r.Uniform(-pi, pi));
64 t.SetPos(r.Uniform(-lim, lim), r.Uniform(-lim, lim), r.Uniform(-lim, lim));
65 text->SetFontSize(r.Uniform(0.01 * lim, 0.2 * lim));
66 } else { // screen [0, 0] bottom left, [1, 1] top-right corner, font-size in y-units, x scaled with the window
67 // aspect ratio.
68 text->SetPosition(REX::REveVector(r.Uniform(-0.1, 0.9), r.Uniform(0.1, 1.1), r.Uniform(0.0, 1.0)));
69 text->SetFontSize(r.Uniform(0.001, 0.05));
70 }
71 text->SetTextColor(
72 TColor::GetColor((float)r.Uniform(0, 0.5), (float)r.Uniform(0, 0.5), (float)r.Uniform(0, 0.5)));
73 // text->SetMainTransparency();
74 // text->SetLineColor(text->GetTextColor());
75 text->SetLineColor(
76 TColor::GetColor((float)r.Uniform(0, 0.2), (float)r.Uniform(0, 0.2), (float)r.Uniform(0, 0.2)));
77 text->SetLineAlpha(192);
78 text->SetFillColor(
79 TColor::GetColor((float)r.Uniform(0.7, 1.0), (float)r.Uniform(0.7, 1.0), (float)r.Uniform(0.7, 1.0)));
80 text->SetFillAlpha(128);
81 text->SetDrawFrame(true);
82 textHolder->AddElement(text);
83 }
84}
85void makeJets(int N_Jets, REveElement *jetHolder)
86{
87 TRandom &r = *gRandom;
88
89 const Double_t kR_min = 240;
90 const Double_t kR_max = 250;
91 const Double_t kZ_d = 300;
92 for (int i = 0; i < N_Jets; i++) {
93 auto jet = new REveJetCone(Form("Jet_%d", i));
94 jet->SetCylinder(2 * kR_max, 2 * kZ_d);
95 jet->AddEllipticCone(r.Uniform(-0.5, 0.5), r.Uniform(0, TMath::TwoPi()), 0.1, 0.2);
96 jet->SetFillColor(kRed);
97 jet->SetLineColor(kRed);
98
99 jetHolder->AddElement(jet);
100 }
101}
102
103void texts()
104{
105 auto eveMng = REX::REveManager::Create();
107
108 // Initialize SDF fonts.
109 // REveManager needs to be already created as location redirect needs to be set up.
110 // a) When REveText::AssertSdfFont() is called one of the two default locations
111 // will be chosen, if it is writable by the current user:
112 // - $ROOTSYS/ui5/eve7/sdf-fonts/
113 // - sdf-fonts/ in the current working directory.
114 // If neither location is writable, an error will be issued.
115 // b) Alternatively, REveText::SetSdfFontDir(std::string_view dir, bool require_write_access)
116 // can be called to set this directory manually. If the directory is already pre-populated
117 // with fonts one can set the `require_write_access` argument to false to avoid the
118 // requirement of having write access to that directory.
119
120 std::string rf_dir = gSystem->ExpandPathName("${ROOTSYS}/fonts/");
121 for (int i = 0; i < n_fonts; ++i) {
122 REX::REveText::AssertSdfFont(fonts[i], rf_dir + fonts[i] + ".ttf");
123 }
124 for (int i = 0; i < n_fonts2; ++i) {
125 REX::REveText::AssertSdfFont(fonts2[i], rf_dir + fonts2[i] + ".ttf");
126 }
127
128 // add box to overlay
129 REX::REveScene *os = eveMng->SpawnNewScene("OverlyScene", "OverlayTitle");
130 ((REveViewer *)(eveMng->GetViewers()->FirstChild()))->AddScene(os);
131 os->SetIsOverlay(true);
132
133 REX::REveElement *textHolder = new REX::REveElement("texts");
134 makeTexts(100, textHolder);
135 // os->AddElement(textHolder);
136 eveMng->GetEventScene()->AddElement(textHolder);
137
138 auto jetHolder = new REveElement("jets");
139 makeJets(2, jetHolder);
140 eveMng->GetEventScene()->AddElement(jetHolder);
141
142 eveMng->Show();
143}
@ 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:62
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
R__EXTERN TSystem * gSystem
Definition TSystem.h:561
const Double_t kR_max
const Double_t kZ_d
const Double_t kR_min
virtual void AddElement(REveElement *el)
Add el to the list of children.
REveElement * FirstChild() const
Returns the first child element or 0 if the list is empty.
REveScene * GetEventScene() const
void AllowMultipleRemoteConnections(bool loopBack=true, bool useAuthKey=true)
Utility function to allow remote RWebWindow connections.
REveScene * SpawnNewScene(const char *name, const char *title="")
Create a new scene.
REveViewerList * GetViewers() const
void Show(const RWebDisplayArgs &args="")
Show eve manager in specified browser.
REveViewer Reve representation of TGLViewer.
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:1921
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1274
ROOT::Experimental::REveManager * eveMng
constexpr Double_t Pi()
Definition TMath.h:37
constexpr Double_t TwoPi()
Definition TMath.h:44
void makeJets(int N_Jets, REveElement *jetHolder)
Definition texts.C:85
void texts()
Definition texts.C:103
const int n_blurbs
Definition texts.C:22
const int n_fonts
Definition texts.C:26
const char * blurbs[]
Definition texts.C:21
const char * fonts[]
Definition texts.C:25
void makeTexts(int N_Texts, REX::REveElement *textHolder)
Definition texts.C:36
const char * blurbs2[]
Definition texts.C:30
const int n_fonts2
Definition texts.C:34
const char * fonts2[]
Definition texts.C:33
const int n_blurbs2
Definition texts.C:31