ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
gviz3d.C
Go to the documentation of this file.
1 // Simple TStructViewer tutorial
2 
3 #include <TRandom.h>
4 #include <TList.h>
5 #include <TROOT.h>
6 
7 // Function creating elements of lists
8 void MakeCrazy(TList *list, Int_t maxDepth, Int_t maxObjects, Float_t pList) {
9  const Int_t ncl =12;
10  const char *clnames[ncl] = {"TH1F","TGraph","TGraphErrors","TF1","TPaveText",
11  "TAxis","TF2","TH2D","TLatex","TText","TCutG","THnSparseF"};
12  Int_t nobj = gRandom->Uniform(0,maxObjects);
13  for (Int_t i=0;i<nobj;i++) {
14  if (maxDepth && gRandom->Rndm() < pList) {
15  TList *slist = new TList();
16  slist->SetName(Form("list_%d_%d",maxDepth,i));
17  list->Add(slist);
18  MakeCrazy(slist,maxDepth-1,maxObjects,pList);
19  } else {
20  Int_t icl = (Int_t)gRandom->Uniform(0,ncl);
21  TNamed *named = (TNamed*)gROOT->ProcessLine(Form("new %s;",clnames[icl]));
22  named->SetName(Form("%s_%d_%d",clnames[icl],maxDepth,i));
23  list->Add(named);
24  }
25  }
26 }
27 
28 // function creating a hierachy of objects to test the TStructViewer
29 TList *crazy(Int_t maxDepth=5, Int_t maxObjects=20, Float_t pList=0.2) {
30  TList *list = new TList();
31  list->SetName("SuperList");
32  MakeCrazy(list,maxDepth,maxObjects,pList);
33  gROOT->GetListOfTasks()->Add(list);
34  return list;
35 }
36 // function adding colors to viewer
38 {
39  // Fills list fColors with TStructNodeProperty
40  const Int_t ncl =12;
41  const char *clnames[ncl] = {"TH1F","TGraph","TGraphErrors","TF1","TPaveText",
42  "TAxis","TF2","TH2D","TLatex","TText","TCutG","THnSparseF"};
43 
44  for (int i = 0; i < ncl ; i++) {
45  sv->SetColor(clnames[i], (Int_t)gRandom->Integer(8)+2);
46  }
47 }
48 
49 
50 void gviz3d()
51 {
52  // Loading library needed by TStructViewer
53  gSystem->Load("libGviz3d");
54  // Creating a pointer to list
55  TList* pointer = crazy(2,10);
56  // Creating a viewer
57  TStructViewer* sv = new TStructViewer(pointer);
58  // adding colors
59  FillColorsMap(sv);
60  sv->Draw();
61 }
float Float_t
Definition: RtypesCore.h:53
virtual Double_t Rndm(Int_t i=0)
Machine independent random number generator.
Definition: TRandom.cxx:512
virtual void SetName(const char *name)
Change (i.e.
Definition: TNamed.cxx:128
void Draw(Option_t *option="")
Draw object if there is valid pointer.
#define gROOT
Definition: TROOT.h:344
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1766
int Int_t
Definition: RtypesCore.h:41
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
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:47
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
char * Form(const char *fmt,...)
void FillColorsMap(TStructViewer *sv)
Definition: gviz3d.C:37
void SetName(const char *name)
Definition: TCollection.h:116
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
TList * crazy(Int_t maxDepth=5, Int_t maxObjects=20, Float_t pList=0.2)
Definition: gviz3d.C:29
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition: TRandom.cxx:606
void MakeCrazy(TList *list, Int_t maxDepth, Int_t maxObjects, Float_t pList)
Definition: gviz3d.C:8
void gviz3d()
Definition: gviz3d.C:50
virtual void Add(TObject *obj)
Definition: TList.h:81