Logo ROOT   6.12/07
Reference Guide
shapesAnim.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_geom
3 /// Macro illustrating how to animate a geometry picture using a Timer
4 ///
5 /// \macro_code
6 ///
7 /// \author Rene Brun
8 
10 Float_t theta = 0;
11 Float_t phi = 30;
12 void shapesAnim() {
13  TCanvas *c1 = new TCanvas("c1","Geometry Shapes",10,10,500,500);
14 
15  // Define some volumes
16  TBRIK *brik = new TBRIK("BRIK","BRIK","void",200,150,150);
17  TTRD1 *trd1 = new TTRD1("TRD1","TRD1","void",200,50,100,100);
18  TTRD2 *trd2 = new TTRD2("TRD2","TRD2","void",200,50,200,50,100);
19  TTRAP *trap = new TTRAP("TRAP","TRAP","void",190,0,0,60,40,90,15,120,80,180,15);
20  TPARA *para = new TPARA("PARA","PARA","void",100,200,200,15,30,30);
21  TGTRA *gtra = new TGTRA("GTRA","GTRA","void",390,0,0,20,60,40,90,15,120,80,180,15);
22  TTUBE *tube = new TTUBE("TUBE","TUBE","void",150,200,400);
23  TTUBS *tubs = new TTUBS("TUBS","TUBS","void",80,100,100,90,235);
24  TCONE *cone = new TCONE("CONE","CONE","void",100,50,70,120,150);
25  TCONS *cons = new TCONS("CONS","CONS","void",50,100,100,200,300,90,270);
26  TSPHE *sphe = new TSPHE("SPHE","SPHE","void",25,340, 45,135, 0,270);
27  TSPHE *sphe1 = new TSPHE("SPHE1","SPHE1","void",0,140, 0,180, 0,360);
28  TSPHE *sphe2 = new TSPHE("SPHE2","SPHE2","void",0,200, 10,120, 45,145);
29 
30  TPCON *pcon = new TPCON("PCON","PCON","void",180,270,4);
31  pcon->DefineSection(0,-200,50,100);
32  pcon->DefineSection(1,-50,50,80);
33  pcon->DefineSection(2,50,50,80);
34  pcon->DefineSection(3,200,50,100);
35 
36  TPGON *pgon = new TPGON("PGON","PGON","void",180,270,8,4);
37  pgon->DefineSection(0,-200,50,100);
38  pgon->DefineSection(1,-50,50,80);
39  pgon->DefineSection(2,50,50,80);
40  pgon->DefineSection(3,200,50,100);
41 
42  // Set shapes attributes
43  brik->SetLineColor(1);
44  trd1->SetLineColor(2);
45  trd2->SetLineColor(3);
46  trap->SetLineColor(4);
47  para->SetLineColor(5);
48  gtra->SetLineColor(7);
49  tube->SetLineColor(6);
50  tubs->SetLineColor(7);
51  cone->SetLineColor(2);
52  cons->SetLineColor(3);
53  pcon->SetLineColor(6);
54  pgon->SetLineColor(2);
55  sphe->SetLineColor(kRed);
56  sphe1->SetLineColor(kBlack);
57  sphe2->SetLineColor(kBlue);
58 
59 
60  // Build the geometry hierarchy
61  TNode *node1 = new TNode("NODE1","NODE1","BRIK");
62  node1->cd();
63 
64  TNode *node2 = new TNode("NODE2","NODE2","TRD1",0,0,-1000);
65  TNode *node3 = new TNode("NODE3","NODE3","TRD2",0,0,1000);
66  TNode *node4 = new TNode("NODE4","NODE4","TRAP",0,-1000,0);
67  TNode *node5 = new TNode("NODE5","NODE5","PARA",0,1000,0);
68  TNode *node6 = new TNode("NODE6","NODE6","TUBE",-1000,0,0);
69  TNode *node7 = new TNode("NODE7","NODE7","TUBS",1000,0,0);
70  TNode *node8 = new TNode("NODE8","NODE8","CONE",-300,-300,0);
71  TNode *node9 = new TNode("NODE9","NODE9","CONS",300,300,0);
72  TNode *node10 = new TNode("NODE10","NODE10","PCON",0,-1000,-1000);
73  TNode *node11 = new TNode("NODE11","NODE11","PGON",0,1000,1000);
74  TNode *node12 = new TNode("NODE12","NODE12","GTRA",0,-400,700);
75  TNode *node13 = new TNode("NODE13","NODE13","SPHE",10,-400,500);
76  TNode *node14 = new TNode("NODE14","NODE14","SPHE1",10, 250,300);
77  TNode *node15 = new TNode("NODE15","NODE15","SPHE2",10,-100,-200);
78 
79 
80  // Draw this geometry in the current canvas
81  node1->cd();
82  node1->Draw();
83  c1->Update();
84 
85  //start a Timer
86  TTimer *timer = new TTimer(20);
87  timer->SetCommand("Animate()");
88  timer->TurnOn();
89 }
90 void Animate()
91 {
92  theta += 2;
93  phi += 2;
94  gPad->GetView()->RotateView(theta,phi);
95  gPad->Modified();
96  gPad->Update();
97 }
virtual void Draw(Option_t *option="")
Draw Referenced node with current parameters.
Definition: TNode.cxx:323
A segment of a conical tube.
Definition: TCONS.h:27
static constexpr double pi
float Float_t
Definition: RtypesCore.h:53
virtual void DefineSection(Int_t secNum, Float_t z, Float_t rmin, Float_t rmax)
Defines section secNum of the polycone.
Definition: TPCON.cxx:176
return c1
Definition: legend1.C:41
Definition: Rtypes.h:59
A parallelepiped.
Definition: TPARA.h:30
Definition: Rtypes.h:58
virtual void cd(const char *path=0)
Change Current Reference node to this.
Definition: TNode.cxx:250
TNode description.
Definition: TNode.h:33
A Sphere.
Definition: TSPHE.h:28
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
A trapezoid with both x and y dimensions varying along z.
Definition: TTRD2.h:29
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:51
A general trapezoid.
Definition: TTRAP.h:33
void SetCommand(const char *command)
Set the interpreter command to be executed at time out.
Definition: TTimer.cxx:174
A box with faces perpendicular to the axes.
Definition: TBRIK.h:26
The Canvas class.
Definition: TCanvas.h:31
A polycone.
Definition: TPCON.h:33
A polygon.
Definition: TPGON.h:30
double Double_t
Definition: RtypesCore.h:55
A general twisted trapezoid.
Definition: TGTRA.h:27
A trapezoid with the x dimension varying along z.
Definition: TTRD1.h:28
A tube.
Definition: TTUBE.h:32
#define gPad
Definition: TVirtualPad.h:285
Definition: Rtypes.h:59
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2248
virtual void TurnOn()
Add the timer to the system timer list.
Definition: TTimer.cxx:241
A conical tube.
Definition: TCONE.h:28
A segment of a tube.
Definition: TTUBS.h:29