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