Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
gviz3d.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gl
3/// Simple `TStructViewer` tutorial
4///
5/// \macro_code
6///
7/// \author Timur Pocheptsov
8
9#include "TRandom.h"
10#include "TList.h"
11#include "TROOT.h"
12#include "TStructViewer.h"
13
14const Int_t ncl =12;
15const char *clnames[ncl] = {"TH1F","TGraph","TGraphErrors","TF1","TPaveText",
16 "TAxis","TF2","TH2D","TLatex","TText","TCutG","THnSparseF"};
17
18// Function creating elements of lists
19void MakeCrazy(TList *list, Int_t maxDepth, Int_t maxObjects, Float_t pList)
20{
21 Int_t nobj = gRandom->Uniform(0,maxObjects);
22 for (Int_t i = 0; i < nobj; i++) {
23 if (maxDepth && gRandom->Rndm() < pList) {
24 TList *slist = new TList();
25 slist->SetName(Form("list_%d_%d",maxDepth,i));
26 list->Add(slist);
27 MakeCrazy(slist,maxDepth-1,maxObjects,pList);
28 } else {
29 Int_t icl = (Int_t)gRandom->Uniform(0,ncl);
30 TNamed *named = (TNamed*)gROOT->ProcessLine(Form("new %s;",clnames[icl]));
31 named->SetName(Form("%s_%d_%d",clnames[icl],maxDepth,i));
32 list->Add(named);
33 }
34 }
35}
36
37// function creating a hierarchy of objects to test the TStructViewer
38TList *crazy(Int_t maxDepth=5, Int_t maxObjects=20, Float_t pList=0.2)
39{
40 TList *list = new TList();
41 list->SetName("SuperList");
42 MakeCrazy(list,maxDepth,maxObjects,pList);
43 gROOT->GetListOfTasks()->Add(list);
44 return list;
45}
46
47// function adding colors to viewer
48void FillColorsMap(TStructViewer* sv)
49{
50 for (int i = 0; i < ncl ; i++)
51 sv->SetColor(clnames[i], (Int_t)gRandom->Integer(8)+2);
52}
53
54void gviz3d()
55{
56 // Creating a pointer to list
57 TList* pointer = crazy(2,10);
58
59 // Creating a viewer
60 TStructViewer* sv = new TStructViewer(pointer);
61
62 // adding colors
63 FillColorsMap(sv);
64
65 sv->Draw();
66}
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
#define gROOT
Definition TROOT.h:406
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
void SetName(const char *name)
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
Double_t Rndm() override
Machine independent random number generator.
Definition TRandom.cxx:559
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition TRandom.cxx:682
virtual UInt_t Integer(UInt_t imax)
Returns a random integer uniformly distributed on the interval [ 0, imax-1 ].
Definition TRandom.cxx:361
void SetColor(TString name, Int_t color)
Sets color for the class "name" to color "color".
void Draw(Option_t *option="") override
Draw object if there is valid pointer.