Logo ROOT   6.10/09
Reference Guide
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
14 void 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
35 TList *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
43 void 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 
56 void gviz3d()
57 {
58  // Loading library needed by TStructViewer
59  gSystem->Load("libGviz3d");
60  // Creating a pointer to list
61  TList* pointer = crazy(2,10);
62  // Creating a viewer
63  TStructViewer* sv = new TStructViewer(pointer);
64  // adding colors
65  FillColorsMap(sv);
66  sv->Draw();
67 }
float Float_t
Definition: RtypesCore.h:53
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:131
void Draw(Option_t *option="")
Draw object if there is valid pointer.
#define gROOT
Definition: TROOT.h:375
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1825
int Int_t
Definition: RtypesCore.h:41
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual UInt_t Integer(UInt_t imax)
Returns a random integer on [ 0, imax-1 ].
Definition: TRandom.cxx:320
void SetColor(TString name, Int_t color)
Sets color for the class "name" to color "color".
A doubly linked list.
Definition: TList.h:43
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom.cxx:512
R__EXTERN TSystem * gSystem
Definition: TSystem.h:539
char * Form(const char *fmt,...)
void SetName(const char *name)
Definition: TCollection.h:111
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition: TRandom.cxx:606
virtual void Add(TObject *obj)
Definition: TList.h:77