Logo ROOT   6.12/07
Reference Guide
xtruDraw.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_geom
3 /// Draw a "representative" TXTRU shape
4 ///
5 /// \macro_image
6 /// \macro_code
7 ///
8 /// \author Robert Hatcher (rhatcher@fnal.gov) 2000.09.06
9 
10 void xtruDraw() {
11  TCanvas *canvas = new TCanvas("xtru","Example XTRU object",200,10,640,640);
12 
13 // Create a new geometry
14  TGeometry* geometry = new TGeometry("geometry","geometry");
15  geometry->cd();
16 
17  TXTRU* atxtru = new TXTRU("atxtru","atxtru","void",5,2);
18 
19 // outline and z segment specifications
20 
21  Float_t x[] =
22  { -177.292, -308.432, -308.432, -305.435, -292.456, -280.01
23  , -241.91, -241.91, -177.292, -177.292, 177.292, 177.292
24  , 241.91, 241.91, 280.06, 297.942, 305.435, 308.432
25  , 308.432, 177.292, 177.292, -177.292 };
26  Float_t y[] =
27  { 154.711, 23.5712, 1.1938, 1.1938, 8.6868, 8.6868
28  , -3.7592, -90.0938, -154.711, -190.602, -190.602, -154.711
29  , -90.0938, -3.7592, 8.6868, 8.6868, 1.1938, 1.1938
30  , 23.5712, 154.711, 190.602, 190.602 };
31  Float_t z[] =
32  { 0.00, 500.0 };
33  Float_t scale[] =
34  { 1.00, 1.00 };
35  Float_t x0[] =
36  { 0, 0 };
37  Float_t y0[] =
38  { 0, 0 };
39 
40  Int_t i;
41 
42  Int_t nxy = sizeof(x)/sizeof(Float_t);
43  for (i=0; i<nxy; i++) {
44  atxtru->DefineVertex(i,x[i],y[i]);
45  }
46 
47  Int_t nz = sizeof(z)/sizeof(Float_t);
48  for (i=0; i<nz; i++) {
49  atxtru->DefineSection(i,z[i],scale[i],x0[i],y0[i]);
50  }
51 
52 // Define a TNode where this example resides in the TGeometry
53 // Draw the TGeometry
54 
55  TNode* anode = new TNode("anode","anode",atxtru);
56  anode->SetLineColor(1);
57 
58  geometry->Draw();
59 
60 // Tweak the pad scales so as not to distort the shape
61 
62  TVirtualPad *thisPad = gPad;
63  if (thisPad) {
64  TView *view = thisPad->GetView();
65  if (!view) return;
66  Double_t min[3],max[3],center[3];
67  view->GetRange(min,max);
68  int i;
69  // Find the boxed center
70  for (i=0;i<3; i++) center[i] = 0.5*(max[i]+min[i]);
71  Double_t maxSide = 0;
72  // Find the largest side
73  for (i=0;i<3; i++) maxSide = TMath::Max(maxSide,max[i]-center[i]);
74  file://Adjust scales:
75  for (i=0;i<3; i++) {
76  max[i] = center[i] + maxSide;
77  min[i] = center[i] - maxSide;
78  }
79  view->SetRange(min,max);
80  Int_t ireply;
81  thisPad->Modified();
82  thisPad->Update();
83  }
84 
85 }
float Float_t
Definition: RtypesCore.h:53
virtual void Update()=0
See TView3D.
Definition: TView.h:25
TNode description.
Definition: TNode.h:33
virtual void SetRange(const Double_t *min, const Double_t *max)=0
int Int_t
Definition: RtypesCore.h:41
Double_t x[n]
Definition: legend1.C:17
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:49
virtual TView * GetView() const =0
TGeometry description.
Definition: TGeometry.h:39
virtual void DefineSection(Int_t secNum, Float_t z, Float_t scale=1., Float_t x0=0., Float_t y0=0.)
Set z section iz information expand size of array if necessary.
Definition: TXTRU.cxx:250
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
A poly-extrusion.
Definition: TXTRU.h:22
virtual void Draw(Option_t *option="")
Draw this Geometry.
Definition: TGeometry.cxx:254
virtual void Modified(Bool_t flag=1)=0
The Canvas class.
Definition: TCanvas.h:31
double Double_t
Definition: RtypesCore.h:55
Double_t y[n]
Definition: legend1.C:17
virtual void DefineVertex(Int_t pointNum, Float_t x, Float_t y)
Set vertex point ipt to (x,y) expand size of array if necessary.
Definition: TXTRU.cxx:304
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
virtual void cd(const char *path=0)
Change Current Geometry to this.
Definition: TGeometry.cxx:246
Definition: file.py:1
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:200
virtual void GetRange(Float_t *min, Float_t *max)=0
#define gPad
Definition: TVirtualPad.h:285