ROOT logo

From $ROOTSYS/tutorials/geom/xtruDraw.C

void xtruDraw() {
// Draw a "representative" TXTRU shape
// Canvas saved as xtru.gif can be used for TXTRU THtml output
// Author: Robert Hatcher (rhatcher@fnal.gov) 2000.09.06

  TCanvas *canvas = new TCanvas("xtru","Example XTRU object",200,10,640,640);

// Create a new geometry
  TGeometry* geometry = new TGeometry("geometry","geometry");
  geometry->cd();

  TXTRU* atxtru = new TXTRU("atxtru","atxtru","void",5,2);

// outline and z segment specifications

  Float_t x[] = 
    {   -177.292,   -308.432,   -308.432,   -305.435,   -292.456,    -280.01
    ,    -241.91,    -241.91,   -177.292,   -177.292,    177.292,    177.292
    ,     241.91,     241.91,     280.06,    297.942,    305.435,    308.432
    ,    308.432,    177.292,    177.292,   -177.292 };
  Float_t y[] = 
    {    154.711,    23.5712,     1.1938,     1.1938,     8.6868,     8.6868
    ,    -3.7592,   -90.0938,   -154.711,   -190.602,   -190.602,   -154.711
    ,   -90.0938,    -3.7592,     8.6868,     8.6868,     1.1938,     1.1938
    ,    23.5712,    154.711,    190.602,    190.602 };
  Float_t z[] = 
    {       0.00,      500.0 };
  Float_t scale[] = 
    {       1.00,       1.00 };
  Float_t x0[] = 
    {          0,          0 };
  Float_t y0[] = 
    {          0,          0 };

  Int_t i;

  Int_t nxy = sizeof(x)/sizeof(Float_t);
  for (i=0; i<nxy; i++) {
     atxtru->DefineVertex(i,x[i],y[i]);
  }

  Int_t nz = sizeof(z)/sizeof(Float_t);
  for (i=0; i<nz; i++) {
     atxtru->DefineSection(i,z[i],scale[i],x0[i],y0[i]);
  }

// Define a TNode where this example resides in the TGeometry
// Draw the TGeometry

  TNode* anode = new TNode("anode","anode",atxtru);
  anode->SetLineColor(1);

  geometry->Draw();

// Tweak the pad scales so as not to distort the shape

  TVirtualPad *thisPad = gPad;
  if (thisPad) {
    TView *view = thisPad->GetView(); 
    if (!view) return;
    Double_t min[3],max[3],center[3];
    view->GetRange(min,max);
    int i;
    // Find the boxed center
    for (i=0;i<3; i++) center[i] = 0.5*(max[i]+min[i]);
    Double_t maxSide = 0;
    // Find the largest side
    for (i=0;i<3; i++) maxSide = TMath::Max(maxSide,max[i]-center[i]);
    file://Adjust scales:
    for (i=0;i<3; i++) {
       max[i] = center[i] + maxSide;
       min[i] = center[i] - maxSide;
    }
    view->SetRange(min,max);
    Int_t ireply;
    thisPad->Modified();
    thisPad->Update();
  }

}
 xtruDraw.C:1
 xtruDraw.C:2
 xtruDraw.C:3
 xtruDraw.C:4
 xtruDraw.C:5
 xtruDraw.C:6
 xtruDraw.C:7
 xtruDraw.C:8
 xtruDraw.C:9
 xtruDraw.C:10
 xtruDraw.C:11
 xtruDraw.C:12
 xtruDraw.C:13
 xtruDraw.C:14
 xtruDraw.C:15
 xtruDraw.C:16
 xtruDraw.C:17
 xtruDraw.C:18
 xtruDraw.C:19
 xtruDraw.C:20
 xtruDraw.C:21
 xtruDraw.C:22
 xtruDraw.C:23
 xtruDraw.C:24
 xtruDraw.C:25
 xtruDraw.C:26
 xtruDraw.C:27
 xtruDraw.C:28
 xtruDraw.C:29
 xtruDraw.C:30
 xtruDraw.C:31
 xtruDraw.C:32
 xtruDraw.C:33
 xtruDraw.C:34
 xtruDraw.C:35
 xtruDraw.C:36
 xtruDraw.C:37
 xtruDraw.C:38
 xtruDraw.C:39
 xtruDraw.C:40
 xtruDraw.C:41
 xtruDraw.C:42
 xtruDraw.C:43
 xtruDraw.C:44
 xtruDraw.C:45
 xtruDraw.C:46
 xtruDraw.C:47
 xtruDraw.C:48
 xtruDraw.C:49
 xtruDraw.C:50
 xtruDraw.C:51
 xtruDraw.C:52
 xtruDraw.C:53
 xtruDraw.C:54
 xtruDraw.C:55
 xtruDraw.C:56
 xtruDraw.C:57
 xtruDraw.C:58
 xtruDraw.C:59
 xtruDraw.C:60
 xtruDraw.C:61
 xtruDraw.C:62
 xtruDraw.C:63
 xtruDraw.C:64
 xtruDraw.C:65
 xtruDraw.C:66
 xtruDraw.C:67
 xtruDraw.C:68
 xtruDraw.C:69
 xtruDraw.C:70
 xtruDraw.C:71
 xtruDraw.C:72
 xtruDraw.C:73
 xtruDraw.C:74
 xtruDraw.C:75
 xtruDraw.C:76
 xtruDraw.C:77
 xtruDraw.C:78
 xtruDraw.C:79
 xtruDraw.C:80
 xtruDraw.C:81
thumb