TridHistoGLFrame Class Reference

#include <TridHistoGLFrame.h>

Inheritance diagram for TridHistoGLFrame:

TridFlatGLFrame TridGLFrame GuiBase TridSketchList List of all members.

Public Types

typedef enum TridHistoGLFrame::ETridHistoTypes HistoType_t
 kColor = 0
 kTrans
enum  ETridHistoTypes { kColor = 0, kTrans }

Public Member Functions

 TridHistoGLFrame (TridPage *tp, TGWindow &parent, TH1 *hist, TridControl *tc, HistoType_t type=kColor)
virtual ~TridHistoGLFrame ()
virtual void TransformToPOV ()
virtual void SetupProjection ()
virtual void DrawObjects ()
virtual void DrawHUD (const char *="")
virtual Bool_t HandleMotion (Event_t *ev)
virtual void SetHistogram (TH1 *hist)

Protected Attributes

TH1 * fHist
HistoType_t fHistoType

Detailed Description

Definition at line 30 of file TridHistoGLFrame.h.


Member Typedef Documentation

typedef enum TridHistoGLFrame::ETridHistoTypes TridHistoGLFrame::HistoType_t


Member Enumeration Documentation

enum TridHistoGLFrame::ETridHistoTypes

Enumerator:
kColor 
kTrans 

Definition at line 33 of file TridHistoGLFrame.h.

00033                                {
00034     kColor = 0,
00035     kTrans
00036   } HistoType_t;


Constructor & Destructor Documentation

TridHistoGLFrame::TridHistoGLFrame ( TridPage tp,
TGWindow &  parent,
TH1 *  hist,
TridControl tc,
HistoType_t  type = kColor 
)

Definition at line 22 of file TridHistoGLFrame.cxx.

00027   : TridFlatGLFrame( tp, parent, tc ),
00028     fHist(hist),
00029     fHistoType(type)
00030 {
00031   cout << "TridHistoGLFrame constructor." << endl;
00032 }

TridHistoGLFrame::~TridHistoGLFrame (  )  [virtual]

Definition at line 34 of file TridHistoGLFrame.cxx.

00035 {
00036   cout << "TridHistoGLFrame constructor." << endl;
00037 }


Member Function Documentation

void TridHistoGLFrame::DrawHUD ( const char *  = ""  )  [virtual]

Reimplemented from TridGLFrame.

Definition at line 372 of file TridHistoGLFrame.cxx.

00373 {
00374 }

void TridHistoGLFrame::DrawObjects (  )  [virtual]

Reimplemented from TridFlatGLFrame.

Definition at line 210 of file TridHistoGLFrame.cxx.

References TridSketch::Draw(), TridGLFrame::fAspectRatio, fHist, fHistoType, TridGLFrame::fTridControl, GetGoodTickWidth(), kColor, TridSketchText::kJustifyBottom, TridSketchText::kJustifyLeft, TridSketchText::kJustifyRight, TridSketchText::kJustifyTop, kv_x(), kv_y(), kv_z(), TridSketch::SetColor(), TridSketch::SetDefaultColor(), TridSketch::SetDefaultTrans(), TridSketchText::SetJustify(), TridSketchText::SetScale(), and TridSketch::SetTransparency().

00211 {
00212   if(fHist==0) return;
00213   assert(fTridControl.get());
00214 
00215   // Draw everything.
00216   glMatrixMode(GL_MODELVIEW);
00217   
00218   if(!fHist) return;
00219 
00220   // Backing box.
00221   TridSketchPlane backplane ( TVector3(0.5, 0.5, -0.2),
00222                               kv_x, 10.0,
00223                               kv_y, 10.0
00224                               );
00225   backplane.SetColor(fTridControl->GetBackgroundColor());
00226   backplane.Draw();
00227 
00228 
00229   TridSketch::SetDefaultColor(fTridControl->GetForegroundColor());
00230   TridSketch::SetDefaultTrans(1);
00231 
00232   
00233 
00234   //int iminbin = fHist->GetXaxis()->GetFirst()-1;
00235   //int imaxbin = fHist->GetXaxis()->GetLast()+1;
00236   //int nbins   = imaxbin - iminbin;
00237   //double xmin = fHist->GetXaxis()->GetBinLowEdge(iminbin);
00238   //double xmax = fHist->GetXaxis()->GetBinLowEdge(imaxbin);
00239   //double ymin = fHist->GetYaxis()->GetBinLowEdge(0);
00240   //double ymax = fHist->GetMaximum();
00241 
00242   int nbins = fHist->GetNbinsX() + 2;
00243   double xmin,xmax;
00244   if(fHistoType == kColor) {
00245     fTridControl->GetColorRange(xmin,xmax);
00246   } else {
00247     fTridControl->GetTransRange(xmin,xmax);
00248   }
00249 
00250   //double ymin = fHist->GetYaxis()->GetBinLowEdge(0);
00251   double ymin = 0;
00252   double ymax = fHist->GetMaximum();
00253   if(ymax<=0) ymax = 1.0;
00254 
00255   double textScaleX = 1.0;
00256   double textScaleY = 1.0;
00257   if(fAspectRatio>0.4) {
00258     textScaleY = 1.0/fAspectRatio;
00259   } else {
00260     textScaleY = 1.0/0.4;
00261     textScaleX = fAspectRatio/0.4;
00262   }
00263 
00265   // Draw axes.
00266   
00267   // Draw lines.
00268   TridSketchLine xline(TVector3(0,0,0), TVector3(1,0,0));
00269   TridSketchLine yline(TVector3(0,0,0), TVector3(0,1,0));
00270   
00271   xline.Draw();
00272   yline.Draw();
00273 
00274   
00275   // Draw ticks and labels
00276 
00277   // XAxis: Max 20 ticks, each has a label.
00278   char format[10];
00279 
00280   double xTickWidth = GetGoodTickWidth(xmin,xmax,6.0,format);
00281   double xtick = floor(xmin/xTickWidth)*xTickWidth;
00282   while(xtick<xmin) xtick+= xTickWidth;
00283 
00284   while(xtick <= xmax) {
00285     double screenx = (xtick-xmin)/(xmax-xmin);
00286     TridSketchLine tick(TVector3(screenx,0,0),TVector3(screenx,-0.05,0));
00287     tick.Draw();
00288     char buff[10];
00289     sprintf(buff,format,xtick);
00290     TridSketchText ticklabel(TVector3(screenx,-0.05,0),kv_y,kv_z,buff);
00291     ticklabel.SetScale(0.02*textScaleX,0.02*textScaleY);
00292     ticklabel.SetJustify(TridSketchText::kJustifyTop);
00293     ticklabel.Draw();
00294     xtick+= xTickWidth;    
00295   }
00296 
00297   double yTickWidth = GetGoodTickWidth(ymin,ymax,6.0,format);
00298   double ytick = (yTickWidth - fmod(ymin,yTickWidth)) + ymin;
00299     
00300   while(ytick <= ymax) {
00301     double screeny = (ytick-ymin)/(ymax-ymin);
00302     TridSketchLine tick(TVector3(-0.02,screeny,-0.01),TVector3(1,screeny,-0.01));
00303     tick.Draw();
00304     char buff[10];
00305     sprintf(buff,format,ytick);
00306     TridSketchText ticklabel(TVector3(-0.02,screeny,0),kv_y,kv_z,buff);
00307     ticklabel.SetScale(0.02*textScaleX,0.02*textScaleY);
00308     ticklabel.SetJustify(TridSketchText::kJustifyRight);
00309     ticklabel.Draw();
00310     ytick+= yTickWidth;    
00311   }
00312   
00313  
00314   // Draw labels.
00315 
00316   // Draw titles
00317   const char* xtitle_string;
00318   if(fHistoType==kColor) {
00319     xtitle_string =  fTridControl->GetColorModeName();
00320   } else {
00321     xtitle_string =  fTridControl->GetTransModeName();
00322   };
00323   TridSketchText xtitle(TVector3(1.0,-0.15,0),kv_y,kv_z,
00324                           xtitle_string);
00325   xtitle.SetJustify(TridSketchText::kJustifyRight | TridSketchText::kJustifyTop );
00326   xtitle.SetScale(0.03*textScaleX,0.03*textScaleY);
00327   xtitle.Draw();
00328 
00329   TridSketchText ytitle(TVector3(-0.15,1.0,0),kv_x,kv_z,"Counts");
00330   ytitle.SetJustify(TridSketchText::kJustifyRight | TridSketchText::kJustifyBottom );
00331   ytitle.SetScale(0.03*textScaleY,0.03*textScaleX);
00332   ytitle.Draw();
00333 
00334 
00335   TridSketchText histtitle(TVector3(-0.2,-0.3,0),kv_y,kv_z,fHist->GetName());
00336   histtitle.SetColor(1,0.2,0);
00337   histtitle.SetJustify(TridSketchText::kJustifyLeft | TridSketchText::kJustifyBottom );
00338   histtitle.SetScale(0.02*textScaleX,0.02*textScaleY);
00339   histtitle.Draw();
00340  
00342   // Draw bins.
00343 
00344   double pitch = 1.0/(double)(nbins-1);
00345 
00346   glEnable(GL_BLEND);
00347 
00348   for(int i = -1; i<nbins; i++) {
00349     double lowedge = pitch*(double)(i);
00350     double highedge = lowedge + pitch *0.8;
00351  
00352     double top =  (fHist->GetBinContent(i) - ymin)/(ymax-ymin);
00353     if(top>1.05) top = 1.05;
00354 
00355     TVector3 x1(lowedge,  0, 0);
00356     TVector3 x2(highedge, 0, 0);
00357     TVector3 x3(highedge, top, 0);
00358     TVector3 x4(lowedge,  top, 0);
00359     
00360     TridSketchPlane graphbin(x1,x2,x3,x4);
00361     if(fHistoType==kColor) {
00362       graphbin.SetColor(fTridControl->GetColor((lowedge+highedge)*0.5));
00363     } else {
00364       graphbin.SetTransparency(lowedge);
00365     }
00366     graphbin.Draw();
00367   }
00368 
00369   glDisable(GL_BLEND);
00370 }

Bool_t TridHistoGLFrame::HandleMotion ( Event_t *  ev  )  [virtual]

Reimplemented from TridFlatGLFrame.

Definition at line 65 of file TridHistoGLFrame.cxx.

References TridGLFrame::fButton, TridGLFrame::fButtonTraveled, fHist, fHistoType, TridGLFrame::fMouseLast_x, TridGLFrame::fMouseLast_y, TridGLFrame::fMouseStart_x, TridGLFrame::fMouseStart_y, TridGLFrame::fTridControl, kColor, and TridGLFrame::Update().

00066 {
00067   if(fButton != 0) {
00068    
00069     int delx, dely;
00070     delx = ev->fX - fMouseStart_x;
00071     dely = ev->fY - fMouseStart_y;
00072     fButtonTraveled+= abs(delx) + abs(dely);
00073     
00074     if(abs(delx) + abs(dely)>0){
00075       if( (fButton ==kButton1) || (fButton ==kButton3) ) {
00076         // Slide.
00077         
00078         GLfloat z;
00079         GLdouble x0, y0, z0;
00080         GLdouble x1, y1, z1;
00081         GLdouble x2, y2, z2;
00082         GLdouble  model[16];
00083         GLdouble  proj[16];
00084         GLint     view[4];
00085         glGetDoublev(GL_MODELVIEW_MATRIX, model);
00086         glGetDoublev(GL_PROJECTION_MATRIX, proj);
00087         glGetIntegerv(GL_VIEWPORT, view); 
00088         
00089         //glReadPixels(fMouseStart_x, fHeight-fMouseStart_y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
00090         z = 0;
00091         gluUnProject(fMouseStart_x, fHeight-fMouseStart_y,  z, model, proj, view, &x0, &y0, &z0);
00092         gluUnProject(fMouseLast_x, fHeight-fMouseLast_y,  z, model, proj, view, &x1, &y1, &z1);
00093         gluUnProject(ev->fX,        fHeight-ev->fY,       z, model, proj, view, &x2, &y2, &z2);
00094         
00095         // Click at x1,y1
00096         // Drag to x2,y2
00097 
00098         if(fTridControl==0) return true;
00099 
00100         // Determine where.
00101         if( (x0>0) && ( y0>0) ) {
00102           // Click was in histogram area. Use this to shift histogram without scaling.
00103           // Insist that minimum drag is ~ 1/2 bin width
00104           if( fabs(x1-x2)>0.01 ) {
00105             double xmin, xmax;
00106             if(fHistoType == kColor) {
00107               fTridControl->GetColorRange(xmin,xmax);
00108               double xshift = (x1-x2)*(xmax-xmin);
00109               fTridControl->ChangeColorRange(xmin+xshift,xmax+xshift);
00110             } else {
00111               fTridControl->GetTransRange(xmin,xmax);
00112               double xshift = (x2-x1)*(xmax-xmin);
00113               fTridControl->ChangeTransRange(xmin-xshift,xmax-xshift);
00114             }
00115             fMouseLast_x = ev->fX;
00116             fMouseLast_y = ev->fY;
00117           }
00118         }
00119 
00120         if( (x0<0) && ( y0>0) ) {
00121           // Click was in y-scale area. Scale drag.
00122           if( fabs(y1-y2)>0.01 ) {
00123             double yscale = (y1/y2);
00124             if(yscale<0.1) yscale = 0.1;
00125             if(yscale>10.0) yscale = 10.0;
00126             
00127             double newmax = fHist->GetMaximum()*yscale;
00128             if(newmax<0.1) newmax = 0.1;
00129             if(newmax>1e6) newmax = 1.e6;
00130             fHist->SetMaximum(newmax);      
00131 
00132             fMouseLast_x = ev->fX;
00133             fMouseLast_y = ev->fY;
00134           }
00135         }
00136         
00137         if( (x0>0) && ( y0<0) && (x1>0) && (y1<0) && (x2>0) && (y2<0) ) {
00138           // Click was in x-scale area. Scale drag.
00139           if( fabs(x1-x2)>0.01 ) {
00140             double xmin, xmax;
00141             if(fHistoType == kColor) {
00142               fTridControl->GetColorRange(xmin,xmax);
00143             } else {
00144               fTridControl->GetTransRange(xmin,xmax);
00145             }
00146             
00147             // Obsolete: allows dragging scale on left OR right.
00148             //if(x1<0.5) {
00149             //  xmin = (x1*(xmax-xmin)+xmin-xmax*x2)/(1-x2);
00150             //} else {
00151             //  xmax = xmin + x1*(xmax-xmin)/x2;
00152             //}
00153             
00154             xmax = xmin + x1*(xmax-xmin)/x2;
00155 
00156             if(fHistoType == kColor) {
00157               fTridControl->ChangeColorRange(xmin,xmax);
00158             } else {
00159               fTridControl->ChangeTransRange(xmin,xmax);
00160             }
00161 
00162             
00163             fMouseLast_x = ev->fX;
00164             fMouseLast_y = ev->fY;
00165           }
00166         }
00167                 
00168         Update();
00169       }
00170     }
00171   }
00172   return true;
00173 }

virtual void TridHistoGLFrame::SetHistogram ( TH1 *  hist  )  [inline, virtual]

Definition at line 49 of file TridHistoGLFrame.h.

References fHist.

00049 { fHist = hist; };

void TridHistoGLFrame::SetupProjection (  )  [virtual]

Reimplemented from TridFlatGLFrame.

Definition at line 39 of file TridHistoGLFrame.cxx.

References TridGLFrame::fAspectRatio.

00040 {
00041   // Set up the projection for the 3d window.
00042   fAspectRatio = 1;
00043   if(fWidth>0) fAspectRatio = (double)fHeight/(double)fWidth;
00044 
00045   glOrtho( -0.2, 1.1,
00046            -0.3, 1.1,
00047           -1.,1.);
00048 }

void TridHistoGLFrame::TransformToPOV (  )  [virtual]

Reimplemented from TridFlatGLFrame.

Definition at line 52 of file TridHistoGLFrame.cxx.

References TridGLFrame::NormalizeAndClipPOV().

00053 {
00054   NormalizeAndClipPOV();
00055   
00056   // Need to manipulate the ModelView matrix to move our model around.
00057   glMatrixMode(GL_MODELVIEW);
00058   
00059   // Reset to 0,0,0; no rotation, no scaling.
00060   glLoadIdentity();   
00061 }


Member Data Documentation

TH1* TridHistoGLFrame::fHist [protected]

Definition at line 49 of file TridHistoGLFrame.h.

Referenced by DrawObjects(), HandleMotion(), and SetHistogram().

HistoType_t TridHistoGLFrame::fHistoType [protected]

Definition at line 53 of file TridHistoGLFrame.h.

Referenced by DrawObjects(), and HandleMotion().


The documentation for this class was generated from the following files:
Generated on Wed Dec 10 22:50:38 2014 for loon by  doxygen 1.4.7