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
13// Function creating elements of lists
14void MakeCrazy(TList *list, Int_t maxDepth, Int_t maxObjects, Float_t pList) {
15 const Int_t ncl =12;
16 const char *clnames[ncl] = {"TH1F","TGraph","TGraphErrors","TF1","TPaveText",
17 "TAxis","TF2","TH2D","TLatex","TText","TCutG","THnSparseF"};
18 Int_t nobj = gRandom->Uniform(0,maxObjects);
19 for (Int_t i=0;i<nobj;i++) {
20 if (maxDepth && gRandom->Rndm() < pList) {
21 TList *slist = new TList();
22 slist->SetName(Form("list_%d_%d",maxDepth,i));
23 list->Add(slist);
24 MakeCrazy(slist,maxDepth-1,maxObjects,pList);
25 } else {
26 Int_t icl = (Int_t)gRandom->Uniform(0,ncl);
27 TNamed *named = (TNamed*)gROOT->ProcessLine(Form("new %s;",clnames[icl]));
28 named->SetName(Form("%s_%d_%d",clnames[icl],maxDepth,i));
29 list->Add(named);
30 }
31 }
32}
33
34// function creating a hierachy of objects to test the TStructViewer
35TList *crazy(Int_t maxDepth=5, Int_t maxObjects=20, Float_t pList=0.2) {
36 TList *list = new TList();
37 list->SetName("SuperList");
38 MakeCrazy(list,maxDepth,maxObjects,pList);
39 gROOT->GetListOfTasks()->Add(list);
40 return list;
41}
42// function adding colors to viewer
43void FillColorsMap(TStructViewer* sv)
44{
45 // Fills list fColors with TStructNodeProperty
46 const Int_t ncl =12;
47 const char *clnames[ncl] = {"TH1F","TGraph","TGraphErrors","TF1","TPaveText",
48 "TAxis","TF2","TH2D","TLatex","TText","TCutG","THnSparseF"};
49
50 for (int i = 0; i < ncl ; i++) {
51 sv->SetColor(clnames[i], (Int_t)gRandom->Integer(8)+2);
52 }
53}
54
55
56void gviz3d()
57{
58 // Creating a pointer to list
59 TList* pointer = crazy(2,10);
60 // Creating a viewer
61 TStructViewer* sv = new TStructViewer(pointer);
62 // adding colors
63 FillColorsMap(sv);
64 sv->Draw();
65}
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
#define gROOT
Definition TROOT.h:405
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2467
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:552
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition TRandom.cxx:672
virtual UInt_t Integer(UInt_t imax)
Returns a random integer uniformly distributed on the interval [ 0, imax-1 ].
Definition TRandom.cxx:360
void Draw(Option_t *option="")
Draw object if there is valid pointer.
void SetColor(TString name, Int_t color)
Sets color for the class "name" to color "color".