ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
xtruSamples.C
Go to the documentation of this file.
1 void xtruSamples()
2 {
3 // Draw a sample of TXTRU shapes some convex, concave (and possibly malformed)
4 // Change Bool_t's to test alternative specifications
5 // Author: Robert Hatcher (rhatcher@fnal.gov) 2000.09.06
6 
7 // One normally specifies the x-y points in counter-clockwise order;
8 // flip this to TRUE to test that it doesn't matter.
9  Bool_t makecw = kFALSE;
10 
11 // One normally specifies the z points in increasing z order;
12 // flip this to TRUE to test that it doesn't matter.
13  Bool_t reversez = kFALSE;
14 
15 // One shouldn't be creating malformed polygons
16 // but to test what happens when one does here's a flag.
17 // The effect will be only apparent in solid rendering mode
18  Bool_t domalformed = kFALSE;
19 // domalformed = kTRUE;
20 
21  c1 = new TCanvas("c1","sample TXTRU Shapes",200,10,640,640);
22 
23 // Create a new geometry
24  TGeometry* geom = new TGeometry("sample","sample");
25  geom->cd();
26 
27 // Define the complexity of the drawing
28  Int_t zseg = 6; // either 2 or 6
29  Int_t extravis = 0; // make extra z "arrow" visible
30 
31  Float_t unit = 1;
32 
33 // Create a large BRIK to embed things into
34  Float_t bigdim = 12.5*unit;
35  TBRIK* world = new TBRIK("world","world","void",bigdim,bigdim,bigdim);
36 
37  // Create the main node, make it invisible
38  TNode* worldnode = new TNode("worldnode","world node",world);
39  worldnode->SetVisibility(0);
40  worldnode->cd();
41 
42 // Canonical shape ... gets further modified by scale factors
43 // to create convex (and malformed) versions
44  Float_t x[] = { -0.50, -1.20, 1.20, 0.50, 0.50, 1.20, -1.20, -0.50 };
45  Float_t y[] = { -0.75, -2.00, -2.00, -0.75, 0.75, 2.00, 2.00, 0.75 };
46  Float_t z[] = { -0.50, -1.50, -1.50, 1.50, 1.50, 0.50 };
47  Float_t s[] = { 0.50, 1.00, 1.50, 1.50, 1.00, 0.50 };
48  Int_t nxy = sizeof(x)/sizeof(Float_t);
49  Float_t convexscale[] = { 7.0, -1.0, 1.5 };
50 
51  Int_t icolor[] = { 1, 2, 3, 2, 2, 2, 4, 2, 6 };
52 
53 // xycase and zcase: 0=convex, 1=malformed, 2=concave
54 // this will either create a 2x2 matrix of shapes
55 // or a 3x3 array (if displaying malformed versions)
56  for (Int_t zcase = 0; zcase<3; zcase++) {
57  if (zcase == 1 && !domalformed) continue;
58  for (Int_t xycase = 0; xycase<3; xycase++) {
59  if (xycase == 1 && !domalformed) continue;
60 
61  char name[9];
62  sprintf(name,"txtru%1d%1d%1d",xycase,zcase,zseg);
63  TXTRU* mytxtru = new TXTRU(name,name,"void",8,2);
64 
65  Int_t i, j;
66  Float_t xsign = (makecw) ? -1 : 1;
67  Float_t zsign = (reversez) ? -1 : 1;
68 
69  // set the vertex points
70  for (i=0; i<nxy; i++) {
71  Float_t xtmp = x[i]*xsign;
72  Float_t ytmp = y[i];
73  if (i==0||i==3||i==4||i==7) xtmp *= convexscale[xycase];
74  if (xycase==2) xtmp *=2;
75  mytxtru->DefineVertex(i,xtmp,ytmp);
76  }
77  // set the z segment positions and scales
78  for (i=0, j=0; i<zseg; i++) {
79  Float_t ztmp = z[i]*zsign;
80  if (i==0||i==5) ztmp *= convexscale[zcase];
81  if (zcase==2) ztmp *= 2.5;
82  if (zseg>2 && zcase!=2 && (i==1||i==4)) continue;
83  mytxtru->DefineSection(j,ztmp,s[i]);
84  j++;
85  }
86 
87  TNode* txtrunode = new TNode(name,name,mytxtru);
88  txtrunode->SetLineColor(icolor[3*zcase+xycase]);
89  Float_t pos_scale = (domalformed) ? 10 : 6;
90  Float_t xpos = (xycase-1)*pos_scale*unit;
91  Float_t ypos = (zcase-1)*pos_scale*unit;
92  txtrunode->SetPosition(xpos,ypos,0.);
93  }
94  }
95 
96 
97 // Some extra shapes to show the direction of "z"
98  Float_t zhalf = 0.5*bigdim;
99  Float_t rmax = 0.03*bigdim;
100  TCONE* zcone = new TCONE("zcone","zcone","void",zhalf,0.,rmax,0.,0.);
101  zcone->SetVisibility(extravis);
102  TNode* zconenode = new TNode("zconenode","zconenode",zcone);
103  zconenode->SetLineColor(3);
104 
105  Float_t dzstub = 2*rmax;
106  TBRIK* zbrik = new TBRIK("zbrik","zbrik","void",rmax,rmax,dzstub);
107  zbrik->SetVisibility(extravis);
108  TNode* zbriknode = new TNode("zbriknode","zbriknode",zbrik);
109  zbriknode->SetPosition(0.,0.,zhalf+dzstub);
110  zbriknode->SetLineColor(3);
111 
112 // geom->ls();
113 
114  geom->Draw();
115 
116 // Tweak the pad so that it displays the entire geometry undistorted
117  TVirtualPad *thisPad = gPad;
118  if (thisPad) {
119  TView *view = thisPad->GetView();
120  if (!view) return;
121  Double_t min[3],max[3],center[3];
122  view->GetRange(min,max);
123  int i;
124  // Find the boxed center
125  for (i=0;i<3; i++) center[i] = 0.5*(max[i]+min[i]);
126  Double_t maxSide = 0;
127  // Find the largest side
128  for (i=0;i<3; i++) maxSide = TMath::Max(maxSide,max[i]-center[i]);
129  file://Adjust scales:
130  for (i=0;i<3; i++) {
131  max[i] = center[i] + maxSide;
132  min[i] = center[i] - maxSide;
133  }
134  view->SetRange(min,max);
135  thisPad->Modified();
136  thisPad->Update();
137  }
138 
139 }
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
Definition: vector.h:433
float Float_t
Definition: RtypesCore.h:53
TCanvas * c1
Definition: legend1.C:2
virtual void Update()=0
virtual void cd(const char *path=0)
Change Current Reference node to this.
Definition: TNode.cxx:250
See TView3D.
Definition: TView.h:36
TNode description.
Definition: TNode.h:43
virtual void SetRange(const Double_t *min, const Double_t *max)=0
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Double_t x[n]
Definition: legend1.C:17
virtual void SetVisibility(Int_t vis=1)
Set visibility for this node and its sons.
Definition: TNode.cxx:759
Float_t z[5]
Definition: Ifit.C:16
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:59
void xtruSamples()
Definition: xtruSamples.C:1
virtual TView * GetView() const =0
TGeometry description.
Definition: TGeometry.h:43
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)
Definition: TAttLine.h:54
virtual void SetPosition(Double_t x=0, Double_t y=0, Double_t z=0)
Definition: TNode.h:99
A poly-extrusion.
Definition: TXTRU.h:24
virtual void Draw(Option_t *option="")
Draw this Geometry.
Definition: TGeometry.cxx:254
virtual void SetVisibility(Int_t vis)
Definition: TShape.h:74
A box with faces perpendicular to the axes.
Definition: TBRIK.h:28
virtual void Modified(Bool_t flag=1)=0
The Canvas class.
Definition: TCanvas.h:48
tuple file
Definition: fildir.py:20
double Double_t
Definition: RtypesCore.h:55
Double_t y[n]
Definition: legend1.C:17
tuple view
Definition: tornado.py:20
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
#define name(a, b)
Definition: linkTestLib0.cpp:5
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
virtual void cd(const char *path=0)
Change Current Geometry to this.
Definition: TGeometry.cxx:246
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:202
virtual void GetRange(Float_t *min, Float_t *max)=0
#define gPad
Definition: TVirtualPad.h:288
A conical tube.
Definition: TCONE.h:30