xtruSamples.C

Go to the documentation of this file.
00001 void xtruSamples()
00002 {
00003 // Draw a sample of TXTRU shapes some convex, concave (and possibly malformed)
00004 // Change Bool_t's to test alternative specifications
00005 // Author: Robert Hatcher (rhatcher@fnal.gov) 2000.09.06
00006 
00007 // One normally specifies the x-y points in counter-clockwise order;
00008 // flip this to TRUE to test that it doesn't matter.
00009   Bool_t makecw      = kFALSE;
00010 
00011 // One normally specifies the z points in increasing z order;
00012 // flip this to TRUE to test that it doesn't matter.
00013   Bool_t reversez    = kFALSE;
00014 
00015 // One shouldn't be creating malformed polygons
00016 // but to test what happens when one does here's a flag.
00017 // The effect will be only apparent in solid rendering mode
00018   Bool_t domalformed = kFALSE;
00019 //  domalformed = kTRUE;
00020 
00021   c1 = new TCanvas("c1","sample TXTRU Shapes",200,10,640,640);
00022 
00023 // Create a new geometry
00024   TGeometry* geom = new TGeometry("sample","sample");
00025   geom->cd();
00026 
00027 // Define the complexity of the drawing
00028   Float_t zseg   = 6;  // either 2 or 6
00029   Int_t extravis = 0;  // make extra z "arrow" visible
00030 
00031   Float_t unit = 1;
00032 
00033 // Create a large BRIK to embed things into
00034   Float_t bigdim = 12.5*unit;
00035   TBRIK* world = new TBRIK("world","world","void",bigdim,bigdim,bigdim);
00036 
00037   // Create the main node, make it invisible
00038   TNode* worldnode = new TNode("worldnode","world node",world);
00039   worldnode->SetVisibility(0);
00040   worldnode->cd();
00041 
00042 // Canonical shape ... gets further modified by scale factors
00043 // to create convex (and malformed) versions
00044   Float_t x[] = { -0.50, -1.20,  1.20,  0.50,  0.50,  1.20, -1.20, -0.50 };
00045   Float_t y[] = { -0.75, -2.00, -2.00, -0.75,  0.75,  2.00,  2.00,  0.75 };
00046   Float_t z[] = { -0.50, -1.50, -1.50,  1.50,  1.50,  0.50 };
00047   Float_t s[] = {  0.50,  1.00,  1.50,  1.50,  1.00,  0.50 };
00048   Int_t   nxy = sizeof(x)/sizeof(Float_t);
00049   Float_t convexscale[] = { 7.0, -1.0, 1.5 };
00050 
00051   Int_t icolor[] = { 1, 2, 3, 2, 2, 2, 4, 2, 6 };
00052 
00053 // xycase and zcase:  0=convex, 1=malformed, 2=concave
00054 // this will either create a 2x2 matrix of shapes
00055 // or a 3x3 array (if displaying malformed versions)
00056   for (Int_t zcase = 0; zcase<3; zcase++) {
00057      if (zcase == 1 && !domalformed) continue;
00058      for (Int_t xycase = 0; xycase<3; xycase++) {
00059         if (xycase == 1 && !domalformed) continue;
00060 
00061         Char_t *name = "txtruXYZ";
00062         sprintf(name,"txtru%1d%1d%1d",xycase,zcase,zseg);
00063         TXTRU* mytxtru = new TXTRU(name,name,"void",8,2);
00064 
00065         Int_t i, j;
00066         Float_t xsign = (makecw) ? -1 : 1;
00067         Float_t zsign = (reversez) ? -1 : 1;
00068 
00069         // set the vertex points
00070         for (i=0; i<nxy; i++) {
00071            Float_t xtmp = x[i]*xsign;
00072            Float_t ytmp = y[i];
00073            if (i==0||i==3||i==4||i==7) xtmp *= convexscale[xycase];
00074            if (xycase==2) xtmp *=2;
00075            mytxtru->DefineVertex(i,xtmp,ytmp);
00076         }
00077         // set the z segment positions and scales
00078         for (i=0, j=0; i<zseg; i++) {
00079            Float_t ztmp = z[i]*zsign;
00080            if (i==0||i==5) ztmp *= convexscale[zcase];
00081            if (zcase==2) ztmp *= 2.5;
00082            if (zseg>2 && zcase!=2 && (i==1||i==4)) continue;
00083            mytxtru->DefineSection(j,ztmp,s[i]);
00084            j++;
00085         }
00086 
00087         TNode* txtrunode = new TNode(name,name,mytxtru);
00088         txtrunode->SetLineColor(icolor[3*zcase+xycase]);
00089         Float_t pos_scale = (domalformed) ? 10 : 6;
00090         Float_t xpos = (xycase-1)*pos_scale*unit;
00091         Float_t ypos = (zcase-1)*pos_scale*unit;
00092         txtrunode->SetPosition(xpos,ypos,0.);
00093      }
00094   }
00095 
00096 
00097 // Some extra shapes to show the direction of "z"
00098   Float_t zhalf = 0.5*bigdim;
00099   Float_t rmax = 0.03*bigdim;
00100   TCONE* zcone = new TCONE("zcone","zcone","void",zhalf,0.,rmax,0.,0.);
00101   zcone->SetVisibility(extravis);
00102   TNode* zconenode = new TNode("zconenode","zconenode",zcone);
00103   zconenode->SetLineColor(3);
00104 
00105   Float_t dzstub = 2*rmax; 
00106   TBRIK* zbrik = new TBRIK("zbrik","zbrik","void",rmax,rmax,dzstub);
00107   zbrik->SetVisibility(extravis);
00108   TNode* zbriknode = new TNode("zbriknode","zbriknode",zbrik);
00109   zbriknode->SetPosition(0.,0.,zhalf+dzstub);
00110   zbriknode->SetLineColor(3);
00111 
00112 //  geom->ls();
00113 
00114   geom->Draw();
00115 
00116 // Tweak the pad so that it displays the entire geometry undistorted
00117   TVirtualPad *thisPad = gPad;
00118   if (thisPad) {
00119     TView *view = thisPad->GetView(); 
00120     if (!view) return;
00121     Double_t min[3],max[3],center[3];
00122     view->GetRange(min,max);
00123     int i;
00124     // Find the boxed center
00125     for (i=0;i<3; i++) center[i] = 0.5*(max[i]+min[i]);
00126     Double_t maxSide = 0;
00127     // Find the largest side
00128     for (i=0;i<3; i++) maxSide = TMath::Max(maxSide,max[i]-center[i]);
00129     file://Adjust scales:
00130     for (i=0;i<3; i++) {
00131        max[i] = center[i] + maxSide;
00132        min[i] = center[i] - maxSide;
00133     }
00134     view->SetRange(min,max);
00135     thisPad->Modified();
00136     thisPad->Update();
00137   }
00138 
00139 }

Generated on Tue Jul 5 15:44:17 2011 for ROOT_528-00b_version by  doxygen 1.5.1