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)
65 continue;
66 for (Int_t xycase = 0; xycase < 3; xycase++) {
67 if (xycase == 1 && !domalformed)
68 continue;
69
70 char name[9];
71 sprintf(name, "txtru%1d%1d%1d", xycase, zcase, zseg);
72 TXTRU *mytxtru = new TXTRU(name, name, "void", 8, 2);
73
74 Int_t i, j;
75 Float_t xsign = (makecw) ? -1 : 1;
76 Float_t zsign = (reversez) ? -1 : 1;
77
78 // set the vertex points
79 for (i = 0; i < nxy; i++) {
80 Float_t xtmp = x[i] * xsign;
81 Float_t ytmp = y[i];
82 if (i == 0 || i == 3 || i == 4 || i == 7)
83 xtmp *= convexscale[xycase];
84 if (xycase == 2)
85 xtmp *= 2;
86 mytxtru->DefineVertex(i, xtmp, ytmp);
87 }
88 // set the z segment positions and scales
89 for (i = 0, j = 0; i < zseg; i++) {
90 Float_t ztmp = z[i] * zsign;
91 if (i == 0 || i == 5)
92 ztmp *= convexscale[zcase];
93 if (zcase == 2)
94 ztmp *= 2.5;
95 if (zseg > 2 && zcase != 2 && (i == 1 || i == 4))
96 continue;
97 mytxtru->DefineSection(j, ztmp, s[i]);
98 j++;
99 }
100
101 TNode *txtrunode = new TNode(name, name, mytxtru);
102 txtrunode->SetLineColor(icolor[3 * zcase + xycase]);
103 Float_t pos_scale = (domalformed) ? 10 : 6;
104 Float_t xpos = (xycase - 1) * pos_scale * unit;
105 Float_t ypos = (zcase - 1) * pos_scale * unit;
106 txtrunode->SetPosition(xpos, ypos, 0.);
107 }
108 }
109
110 // Some extra shapes to show the direction of "z"
111 Float_t zhalf = 0.5 * bigdim;
112 Float_t rmax = 0.03 * bigdim;
113 TCONE *zcone = new TCONE("zcone", "zcone", "void", zhalf, 0., rmax, 0., 0.);
114 zcone->SetVisibility(extravis);
115 TNode *zconenode = new TNode("zconenode", "zconenode", zcone);
116 zconenode->SetLineColor(3);
117
118 Float_t dzstub = 2 * rmax;
119 TBRIK *zbrik = new TBRIK("zbrik", "zbrik", "void", rmax, rmax, dzstub);
120 zbrik->SetVisibility(extravis);
121 TNode *zbriknode = new TNode("zbriknode", "zbriknode", zbrik);
122 zbriknode->SetPosition(0., 0., zhalf + dzstub);
123 zbriknode->SetLineColor(3);
124
125 // geom->ls();
126
127 geom->Draw();
128
129 // Tweak the pad so that it displays the entire geometry undistorted
130 TVirtualPad *thisPad = gPad;
131 if (thisPad) {
132 TView *view = thisPad->GetView();
133 if (!view)
134 return;
135 Double_t min[3], max[3], center[3];
136 view->GetRange(min, max);
137 int i;
138 // Find the boxed center
139 for (i = 0; i < 3; i++)
140 center[i] = 0.5 * (max[i] + min[i]);
141 Double_t maxSide = 0;
142 // Find the largest side
143 for (i = 0; i < 3; i++)
144 maxSide = TMath::Max(maxSide, max[i] - center[i]);
145 file: // Adjust scales:
146 for (i = 0; i < 3; i++) {
147 max[i] = center[i] + maxSide;
148 min[i] = center[i] - maxSide;
149 }
150 view->SetRange(min, max);
151 thisPad->Modified();
152 thisPad->Update();
153 }
154}
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void xpos
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void ypos
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
void Draw(Option_t *option="") override
Draw this Geometry.
virtual void cd(const char *path=nullptr)
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 cd(const char *path=nullptr)
Change Current Reference node to this.
Definition TNode.cxx:249
virtual void SetVisibility(Int_t vis=1)
Set visibility for this node and its sons.
Definition TNode.cxx:758
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:274
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:220
Double_t y[n]
Definition legend1.C:17
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17
__device__ AFloat max(AFloat x, AFloat y)
Definition Kernels.cuh:207
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:250