TEveCaloLegoOverlay.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveCaloLegoOverlay.cxx 34868 2010-08-19 17:09:30Z matevz $
00002 // Author: Alja Mrak-Tadel 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TEveCaloLegoOverlay.h"
00013 #include "TEveCaloLegoGL.h"
00014 
00015 #include "TAxis.h"
00016 #include "TColor.h"
00017 #include "TROOT.h"
00018 #include "THLimitsFinder.h"
00019 
00020 #include "TGLRnrCtx.h"
00021 #include "TGLIncludes.h"
00022 #include "TGLSelectRecord.h"
00023 #include "TGLUtil.h"
00024 #include "TGLViewerBase.h"
00025 #include "TGLCamera.h"
00026 #include "TGLAxisPainter.h"
00027 #include "TGLFontManager.h"
00028 
00029 #include "TEveCalo.h"
00030 #include "TEveCaloData.h"
00031 #include "TEveRGBAPalette.h"
00032 
00033 #include <KeySymbols.h>
00034 
00035 
00036 //______________________________________________________________________________
00037 //
00038 //
00039 // GL-overaly control GUI for TEveCaloLego.
00040 //
00041 //
00042 
00043 ClassImp(TEveCaloLegoOverlay);
00044 
00045 //______________________________________________________________________________
00046 TEveCaloLegoOverlay::TEveCaloLegoOverlay() :
00047    TGLCameraOverlay(),
00048 
00049    fCalo(0),
00050 
00051    fShowScales(kTRUE),
00052    fScaleColor(-1), fScaleTransparency(0),
00053    fScaleCoordX(0.85), fScaleCoordY(0.65),
00054    fScaleW(0), fScaleH(0),
00055    fCellX(-1), fCellY(-1),
00056 
00057    fFrameColor(-1), fFrameLineTransp(70), fFrameBgTransp(90),
00058 
00059    fMouseX(0),  fMouseY(0),
00060    fInDrag(kFALSE),
00061 
00062    fHeaderSelected(kFALSE),
00063 
00064    fPlaneAxis(0), fAxisPlaneColor(kGray),
00065    fShowPlane(kFALSE),
00066 
00067    fMenuW(0.08),
00068    fButtonW(0.5),
00069    fShowSlider(kFALSE),
00070    fSliderH(0.6),
00071    fSliderPosY(0.15),
00072    fSliderVal(0),
00073 
00074    fActiveID(-1), fActiveCol(kRed-4)
00075 {
00076    // Constructor.
00077 
00078    fPlaneAxis = new TAxis();
00079 }
00080 
00081 /******************************************************************************/
00082 // Virtual event handlers from TGLOverlayElement
00083 /******************************************************************************/
00084 
00085 Bool_t TEveCaloLegoOverlay::SetSliderVal(Event_t* event, TGLRnrCtx &rnrCtx)
00086 {
00087    // Set height of horizontal plane in the calorimeter.
00088 
00089    TGLRect& wprt = rnrCtx.RefCamera().RefViewport();
00090    fSliderVal = (1 -event->fY*1./wprt.Height() -fSliderPosY)/fSliderH;
00091 
00092    if (fSliderVal < 0 )
00093       fSliderVal = 0;
00094    else if (fSliderVal > 1)
00095       fSliderVal = 1;
00096 
00097    fCalo->SetHPlaneVal(fSliderVal);
00098 
00099    return kTRUE;
00100 }
00101 
00102 //______________________________________________________________________________
00103 Bool_t TEveCaloLegoOverlay::Handle(TGLRnrCtx          & rnrCtx,
00104                                    TGLOvlSelectRecord & selRec,
00105                                    Event_t            * event)
00106 {
00107    // Handle overlay event.
00108    // Return TRUE if event was handled.
00109 
00110    if (selRec.GetN() < 2) return kFALSE;
00111 
00112 
00113    if (rnrCtx.RefCamera().IsOrthographic())
00114    {
00115       switch (event->fType)
00116       {      case kButtonPress:
00117          {
00118             fMouseX = event->fX;
00119             fMouseY = event->fY;
00120             fInDrag = kTRUE;
00121             return kTRUE;
00122          }
00123          case kButtonRelease:
00124          {
00125             fInDrag = kFALSE;
00126             return kTRUE;
00127          }
00128          case kMotionNotify:
00129          {
00130             if (fInDrag)
00131             {
00132                const TGLRect& vp = rnrCtx.RefCamera().RefViewport();
00133                fScaleCoordX += (Float_t)(event->fX - fMouseX) / vp.Width();
00134                fScaleCoordY -= (Float_t)(event->fY - fMouseY) / vp.Height();
00135                fMouseX = event->fX;
00136                fMouseY = event->fY;
00137                // Make sure we don't go offscreen (use fDraw variables set in draw)
00138                if (fScaleCoordX < 0)
00139                   fScaleCoordX = 0;
00140                else if (fScaleCoordX + fScaleW > 1.0f)
00141                   fScaleCoordX = 1.0f - fScaleW;
00142                if (fScaleCoordY < 0)
00143                   fScaleCoordY = 0;
00144                else if (fScaleCoordY + fScaleH > 1.0f)
00145                   fScaleCoordY = 1.0f - fScaleH;
00146             }
00147             return kTRUE;
00148          }
00149          default:
00150             break;
00151       }
00152    }
00153 
00154    else
00155    {
00156       switch (event->fType)
00157       {
00158          case kMotionNotify:
00159          {
00160             Int_t item = selRec.GetN() < 2 ? -1 : (Int_t)selRec.GetItem(1);
00161             if (fActiveID != item) {
00162                fActiveID = item;
00163                return kTRUE;
00164             } else {
00165                if (fActiveID == 2 && event->fState == 256)
00166                   return SetSliderVal(event, rnrCtx);
00167 
00168                return kFALSE;
00169             }
00170             break;
00171          }
00172          case kButtonPress:
00173          {
00174             if (event->fCode != kButton1) {
00175                return kFALSE;
00176             }
00177             switch (selRec.GetItem(1))
00178             {
00179                case 1:
00180                   fShowSlider = !fShowSlider;
00181                   fCalo->SetDrawHPlane(fShowSlider);
00182                   break;
00183                case 2:
00184                   return SetSliderVal(event, rnrCtx);
00185                case 3:
00186                   fHeaderSelected = !fHeaderSelected;
00187                default:
00188                   break;
00189             }
00190          }
00191          default:
00192             break;
00193       }
00194    }
00195 
00196    return kFALSE;
00197 }
00198 
00199 //______________________________________________________________________________
00200 Bool_t TEveCaloLegoOverlay::MouseEnter(TGLOvlSelectRecord& /*rec*/)
00201 {
00202    // Mouse has entered overlay area.
00203 
00204    return kTRUE;
00205 }
00206 
00207 //______________________________________________________________________________
00208 void TEveCaloLegoOverlay::MouseLeave()
00209 {
00210    // Mouse has left overlay area.
00211 
00212    fActiveID = -1;
00213 }
00214 
00215 //______________________________________________________________________________
00216 void TEveCaloLegoOverlay::SetScaleColorTransparency(Color_t colIdx, Char_t transp)
00217 {
00218    // Set color and transparency of scales.
00219 
00220    fScaleColor = colIdx;
00221    fScaleTransparency = transp;
00222 }
00223 
00224 //______________________________________________________________________________
00225 void TEveCaloLegoOverlay::SetScalePosition(Double_t x, Double_t y)
00226 {
00227    // Set scale coordinates in range [0,1].
00228 
00229    fScaleCoordX = x;
00230    fScaleCoordY = y;
00231 }
00232 
00233 //______________________________________________________________________________
00234 void TEveCaloLegoOverlay:: SetFrameAttribs(Color_t frameColor, Char_t lineTransp, Char_t bgTransp)
00235 {
00236    // Set frame attribs.
00237 
00238    fFrameColor = frameColor;
00239    fFrameLineTransp = lineTransp;
00240    fFrameBgTransp = bgTransp;
00241 }
00242 
00243 //==============================================================================
00244 void TEveCaloLegoOverlay::RenderHeader(TGLRnrCtx& rnrCtx)
00245 {
00246    // Render text on top right corner of the screen.
00247 
00248    TGLRect &vp = rnrCtx.GetCamera()->RefViewport();
00249 
00250    TGLFont font;
00251    Int_t fs = TMath::Max(TMath::Nint(vp.Height()*0.035), 12);
00252    rnrCtx.RegisterFontNoScale(fs, "arial", TGLFont::kPixmap, font);
00253    font.PreRender();
00254    Float_t off = fs*0.2;
00255    Float_t bb[6];
00256    font.BBox(fHeaderTxt.Data(), bb[0], bb[1], bb[2], bb[3], bb[4], bb[5]);
00257    Float_t x = vp.Width()  -bb[3] -off;
00258    Float_t y = vp.Height() -bb[4] -off;
00259    if (rnrCtx.Selection())
00260    {
00261       glPushName(0);
00262       glLoadName(3);
00263       glBegin(GL_QUADS);
00264       glVertex2f(x/vp.Width(), y/ vp.Height());
00265       glVertex2f(1,  y/ vp.Height());
00266       glVertex2f(1, 1);
00267       glVertex2f(x/vp.Width(), 1);
00268       glEnd();
00269       glPopName();
00270    }
00271    else
00272    {
00273       TGLUtil::Color(fHeaderSelected ? fActiveCol : fCalo->GetFontColor());
00274       glRasterPos2i(0, 0);
00275       glBitmap(0, 0, 0, 0, x, y, 0);
00276       font.Render(fHeaderTxt.Data());
00277    }
00278    font.PostRender();
00279 }
00280 
00281 //______________________________________________________________________________
00282 void TEveCaloLegoOverlay::RenderPlaneInterface(TGLRnrCtx &rnrCtx)
00283 {
00284    // Render menu for plane-value and the plane if marked.
00285 
00286    glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT | GL_LINE_BIT | GL_POINT_BIT);
00287    glEnable(GL_POINT_SMOOTH);
00288    glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
00289    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00290    glEnable(GL_POLYGON_OFFSET_FILL);
00291    glPolygonOffset(0.1, 1);
00292    glDisable(GL_CULL_FACE);
00293    glEnable(GL_BLEND);
00294    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00295 
00296    // move to the center of menu
00297    Double_t maxVal = fCalo->GetMaxVal();
00298 
00299    // button
00300    glPushMatrix();
00301    glTranslatef(1 -fMenuW, (1-fButtonW )*fMenuW*0.8, 0);
00302 
00303    glPushName(0);
00304    glLoadName(1);
00305    Float_t a=0.6;
00306    (fActiveID == 1) ? TGLUtil::Color(fActiveCol):TGLUtil::Color4f(0, 1, 0, a);
00307    Float_t bw = fButtonW*fMenuW*0.5;
00308    Float_t bwt = bw*0.8;
00309    Float_t bh = fButtonW*fMenuW;
00310    glBegin(GL_QUADS);
00311    glVertex2f(-bw, 0);
00312    glVertex2f( bw, 0);
00313    glVertex2f( bwt, bh);
00314    glVertex2f(-bwt, bh);
00315    glEnd();
00316 
00317 
00318    TGLUtil::LineWidth(1);
00319    glBegin(GL_LINES);
00320    TGLUtil::Color(4);
00321    glVertex2f(0, 0); glVertex2f(0, bh);
00322    glVertex2f((bw+bwt)*0.5, bh*0.5); glVertex2f(-(bw+bwt)*0.5, bh*0.5);
00323    glEnd();
00324 
00325    TGLUtil::LineWidth(2);
00326    glBegin(GL_LINE_LOOP);
00327    glVertex2f(-bw, 0);
00328    glVertex2f( bw, 0);
00329    glVertex2f( bwt, bh);
00330    glVertex2f(-bwt, bh);
00331    glEnd();
00332    TGLUtil::LineWidth(1);
00333 
00334    glTranslatef(0, fSliderPosY, 0.5);
00335 
00336    if (fShowSlider)
00337    {
00338       // event handler
00339       if (rnrCtx.Selection())
00340       {
00341          glLoadName(2);
00342          Float_t w = fButtonW*fMenuW*0.5f;
00343          glBegin(GL_QUADS);
00344          glVertex2f(-w, 0);
00345          glVertex2f( w, 0);
00346          glVertex2f( w, fSliderH);
00347          glVertex2f(-w, fSliderH);
00348          glEnd();
00349       }
00350 
00351       // slider axis
00352       fAxisPainter->SetLabelPixelFontSize(TMath::CeilNint(rnrCtx.GetCamera()->RefViewport().Height()*GetAttAxis()->GetLabelSize()));
00353       fAxisPainter->RefDir().Set(0, 1, 0);
00354       fAxisPainter->RefTMOff(0).Set(1, 0, 0);
00355       fAxisPainter->SetLabelAlign(TGLFont::kLeft, TGLFont::kCenterV);
00356       fPlaneAxis->SetRangeUser(0, maxVal);
00357       fPlaneAxis->SetLimits(0, maxVal);
00358       fPlaneAxis->SetNdivisions(710);
00359       fPlaneAxis->SetTickLength(0.02*maxVal);
00360       fPlaneAxis->SetLabelOffset(0.02*maxVal);
00361       fPlaneAxis->SetLabelSize(0.05);
00362 
00363       glPushMatrix();
00364       glScalef(fSliderH/(maxVal), fSliderH/maxVal, 1.);
00365       fAxisPainter->PaintAxis(rnrCtx, fPlaneAxis);
00366       glPopMatrix();
00367 
00368       // marker
00369       TGLUtil::Color((fActiveID == 2) ? fActiveCol : 3);
00370       TGLUtil::PointSize(8);
00371       glBegin(GL_POINTS);
00372       glVertex3f(0, fSliderVal*fSliderH, -0.1);
00373       glEnd();
00374    }
00375 
00376    glPopName();
00377    glPopMatrix();
00378    glPopAttrib();
00379 }
00380 
00381 /******************************************************************************/
00382 void TEveCaloLegoOverlay::RenderLogaritmicScales(TGLRnrCtx& rnrCtx)
00383 {
00384    // Draw slider of calo 2D in mode TEveCalo:fValSize.
00385 
00386    TGLRect &vp = rnrCtx.GetCamera()->RefViewport();
00387 
00388    Double_t maxVal = fCalo->GetMaxVal();
00389    Int_t    maxe   = TMath::CeilNint(TMath::Log10(maxVal+1)); // max round exponent
00390    Double_t sqv    = TMath::Power(10, maxe)+1; // starting max square value
00391    Double_t fc     = TMath::Log10(sqv)/TMath::Log10(fCalo->GetMaxVal()+1);
00392    Double_t cellX = fCellX*fc;
00393    Double_t cellY = fCellY*fc;
00394 
00395    Double_t scaleStepY = 0.1; // step is 10% of screen
00396    Double_t scaleStepX = scaleStepY*vp.Height()/vp.Width(); // step is 10% of screen
00397 
00398    Double_t frameOff = 0.01;
00399 
00400    // define max starting exponent not to take more than scalStepY height
00401    while(cellY > scaleStepY)
00402    {
00403       fc = TMath::Log10(TMath::Power(10, maxe-1)+1)/TMath::Log10(TMath::Power(10, maxe)+1);
00404       maxe --;
00405       cellX *= fc;
00406       cellY *= fc;
00407    }
00408 
00409    sqv =  TMath::Power(10, maxe)+1;
00410    glPushMatrix();
00411    glTranslatef(fScaleCoordX + 0.5*scaleStepX + frameOff, fScaleCoordY + 0.5*scaleStepY + frameOff, 0); // translate to lower left corner
00412 
00413    glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT | GL_LINE_BIT | GL_POINT_BIT);
00414    glEnable(GL_BLEND);
00415    glDisable(GL_CULL_FACE);
00416    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00417    glEnable(GL_POLYGON_OFFSET_FILL);
00418    glPolygonOffset(0.1, 1);
00419 
00420    glPushName(0);
00421    glLoadName(1);
00422 
00423    // draw cells
00424    Color_t color = fScaleColor > -1 ? fScaleColor : rnrCtx.ColorSet().Markup().GetColorIndex();
00425    TGLUtil::ColorTransparency(color, fScaleTransparency);
00426 
00427    Float_t pos, dx, dy;
00428    glBegin(GL_QUADS);
00429    Int_t ne = 3; // max number of columns
00430    for (Int_t i=0; i < ne; ++i)
00431    {
00432       Float_t valFac = TMath::Log10(TMath::Power(10, maxe-i)+1)/TMath::Log10(sqv);
00433       dx = 0.5* cellX * valFac;
00434       dy = 0.5* cellY * valFac;
00435       pos = i* scaleStepY;
00436       glVertex2f( - dx, pos - dy);
00437       glVertex2f( - dx, pos + dy);
00438       glVertex2f( + dx, pos + dy);
00439       glVertex2f( + dx, pos - dy);
00440    }
00441    glEnd();
00442 
00443    // draw points in case suare is below pixels
00444    glBegin(GL_POINTS);
00445    for (Int_t i=0; i < ne; ++i)
00446       glVertex2f(0, i* scaleStepY);
00447    glEnd();
00448 
00449    // draw numbers
00450    TGLFont fontB;
00451    Int_t fsb = TMath::Max(TMath::Nint(vp.Height()*0.03), 12);
00452    rnrCtx.RegisterFontNoScale(fsb, "arial", TGLFont::kPixmap, fontB);
00453    TGLFont fontE;
00454    Int_t fsE = TMath::Max(TMath::Nint(vp.Height()*0.01), 8);
00455    rnrCtx.RegisterFontNoScale(fsE, "arial", TGLFont::kPixmap, fontE);
00456 
00457    Float_t llx, lly, llz, urx, ury, urz;
00458    fontB.BBox("10", llx, lly, llz, urx, ury, urz);
00459    Float_t expX = urx/vp.Width();
00460    Float_t expY = (ury-lly)*0.5/vp.Height();
00461    Float_t expOff = 1;
00462    fontB.PreRender();
00463    fontE.PreRender();
00464    glPushMatrix();
00465    glTranslatef(0.5*scaleStepX, 0, 0.1);
00466    for (Int_t i = 0; i < ne; ++i)
00467    {
00468       if (i == maxe)
00469       {
00470          fontB.Render("1", 0, i*scaleStepY, 0, TGLFont::kLeft, TGLFont::kCenterV);
00471       }
00472       else if ( i == (maxe -1))
00473       {
00474          fontB.Render("10", 0, i*scaleStepY, 0, TGLFont::kLeft, TGLFont::kCenterV);
00475       }
00476       else
00477       {
00478          fontB.Render("10", 0, i*scaleStepY, 0, TGLFont::kLeft, TGLFont::kCenterV);
00479          fontB.BBox(Form("%d",  maxe-i), llx, lly, llz, urx, ury, urz);
00480          if (expOff >  urx/vp.Width()) expOff = urx/vp.Width();
00481          fontE.Render(Form("%d",  maxe-i), expX , i*scaleStepY+expY, 0, TGLFont::kLeft, TGLFont::kCenterV);
00482       }
00483    }
00484    glPopMatrix();
00485    fontB.PostRender();
00486    fontE.PostRender();
00487    if (expOff < 1)  expX += expOff;
00488    glPopMatrix();
00489 
00490    // draw frame
00491    {
00492       fScaleW = scaleStepX + expX+ frameOff*2;
00493       fScaleH = scaleStepY * ne + frameOff*2;
00494       Double_t x0 = fScaleCoordX;
00495       Double_t x1 = x0 + fScaleW;
00496       Double_t y0 = fScaleCoordY;
00497       Double_t y1 = y0 + fScaleH;
00498       Double_t zf = +0.2;
00499 
00500       color = fFrameColor > -1 ?  fFrameColor : rnrCtx.ColorSet().Markup().GetColorIndex();
00501       TGLUtil::ColorTransparency(color, fFrameLineTransp);
00502 
00503       glBegin(GL_LINE_LOOP);
00504       glVertex3f(x0, y0, zf); glVertex3f(x1, y0, zf);
00505       glVertex3f(x1, y1, zf); glVertex3f(x0, y1, zf);
00506       glEnd();
00507 
00508       TGLUtil::ColorTransparency(color, fFrameBgTransp);
00509       glBegin(GL_QUADS);
00510       glVertex2f(x0, y0); glVertex2f(x1, y0);
00511       glVertex2f(x1, y1); glVertex2f(x0, y1);
00512       glEnd();
00513    }
00514    glPopName();
00515 
00516    glPopAttrib();
00517 } // end draw scales
00518 
00519 
00520 /******************************************************************************/
00521 void TEveCaloLegoOverlay::RenderPaletteScales(TGLRnrCtx& rnrCtx)
00522 {
00523    // Draw slider of calo 2D in mode TEveCalo:fValColor.
00524 
00525    glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT | GL_LINE_BIT);
00526    glEnable(GL_BLEND);
00527    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00528    glEnable(GL_POLYGON_OFFSET_FILL);
00529    glPolygonOffset(0.1, 1);
00530 
00531    TGLRect& vp = rnrCtx.RefCamera().RefViewport();
00532    Double_t maxVal = fCalo->GetMaxVal();
00533    Int_t    bn;
00534    Double_t bw; // bin with first second order
00535    Double_t bl, bh; // bin low, high first
00536    THLimitsFinder::Optimize(0, maxVal, 10, bl, bh, bn, bw);
00537    bn = TMath::CeilNint(maxVal/bw) + 1;
00538 
00539    fScaleH = 0.25; // relative height of the scale
00540    fScaleW = fScaleH*1.5/(bn*vp.Aspect());
00541    Float_t h = 0.5 * bw  ;
00542    Float_t w = h * 1.5/ vp.Aspect();
00543 
00544    glPushMatrix();
00545    glTranslatef(fScaleCoordX + fScaleW*0.5, fScaleCoordY + fScaleH/bn*0.5, 0); // translate to lower left corner
00546    glScalef(fScaleH/(bn*bw), fScaleH/(bn*bw), 1.);
00547 
00548    glPushName(0);
00549    glLoadName(1);   
00550    TGLAxisPainter::LabVec_t &labVec = fAxisPainter->RefLabVec();
00551    labVec.clear();
00552    Float_t val = 0;
00553    for (Int_t l= 0; l<bn; l++) {
00554       labVec.push_back( TGLAxisPainter::Lab_t(val, val));
00555       val += bw;
00556    }
00557 
00558    TGLUtil::Color(rnrCtx.ColorSet().Markup().GetColorIndex());
00559    fAxisPainter->RefDir().Set(0, 1, 0);
00560    Int_t fs = TMath::CeilNint(rnrCtx.GetCamera()->RefViewport().Height()*0.02);
00561    fAxisPainter->SetLabelFont(rnrCtx, "arial", fs);
00562    fAxisPainter->SetTextFormat(0, maxVal, bw);
00563    fAxisPainter->SetLabelAlign(TGLFont::kCenterH, TGLFont::kCenterV);
00564    TAttAxis att;
00565    fAxisPainter->SetAttAxis(&att);
00566    fAxisPainter->RnrLabels();
00567 
00568    UChar_t c[4];
00569    Float_t y;
00570    Double_t zf = +0.2;
00571    glBegin(GL_QUADS);
00572    for (TGLAxisPainter::LabVec_t::iterator it = labVec.begin(); it != labVec.end(); ++it)
00573    {
00574       fCalo->GetPalette()->ColorFromValue((Int_t)((*it).first), c);
00575       glColor4ub( c[0], c[1], c[2], c[3]);
00576 
00577       y = (*it).second;
00578       glVertex3f( -w, y - h, zf); glVertex3f( +w, y - h, zf);
00579       glVertex3f( +w, y + h, zf); glVertex3f( -w, y + h, zf);
00580    }
00581    glEnd();
00582 
00583    TGLUtil::Color(rnrCtx.ColorSet().Markup().GetColorIndex());
00584    glBegin(GL_LINE_LOOP);
00585    for (TGLAxisPainter::LabVec_t::iterator it = labVec.begin(); it != labVec.end(); ++it)
00586    {
00587       y = (*it).second;
00588       glVertex3f( -w, y - h, zf); glVertex3f( +w, y - h, zf);
00589       glVertex3f( +w, y + h, zf); glVertex3f( -w, y + h, zf);
00590    }
00591    glEnd();
00592 
00593    glPopName();
00594    glPopMatrix();
00595    glPopAttrib();
00596 }
00597 
00598 /******************************************************************************/
00599 
00600 void TEveCaloLegoOverlay::Render(TGLRnrCtx& rnrCtx)
00601 {
00602    // Draw calorimeter scale info and plane interface.
00603 
00604    if ( fCalo == 0 || fCalo->GetData()->Empty()) return;
00605 
00606    Float_t old_depth_range[2];
00607    glGetFloatv(GL_DEPTH_RANGE, old_depth_range);
00608    glDepthRange(0, 0.001);
00609 
00610    glMatrixMode(GL_PROJECTION);
00611    glPushMatrix();
00612    glLoadIdentity();
00613    if (rnrCtx.Selection())
00614    {
00615       TGLRect rect(*rnrCtx.GetPickRectangle());
00616       rnrCtx.GetCamera()->WindowToViewport(rect);
00617       gluPickMatrix(rect.X(), rect.Y(), rect.Width(), rect.Height(),
00618                     (Int_t*) rnrCtx.GetCamera()->RefViewport().CArr());
00619    }
00620    glMatrixMode(GL_MODELVIEW);
00621    glPushMatrix();
00622    glLoadIdentity();
00623 
00624    glTranslatef(-1, -1, 0);
00625    glScalef(2, 2, 1);
00626 
00627 
00628    TGLCapabilitySwitch lights_off(GL_LIGHTING, kFALSE);
00629    TGLCamera& cam = rnrCtx.RefCamera();
00630    Bool_t drawOverlayAxis = kTRUE;
00631 
00632    if (cam.IsOrthographic())
00633    {
00634       // in 2D need pixel cell dimension
00635       // project lego eta-phi boundraries
00636       TGLVector3 rng(fCalo->GetEtaRng(), fCalo->GetPhiRng(), 0);
00637       TGLVertex3 p;
00638       TGLVector3 res = cam.WorldDeltaToViewport(p, rng);
00639 
00640       TEveCaloLegoGL* lgl = dynamic_cast<TEveCaloLegoGL*>(rnrCtx.RefViewer().FindLogicalInScenes(fCalo));
00641       if (fShowScales && lgl)
00642       {
00643 
00644          // get smallest bin
00645          Double_t sq = 1e4;
00646          if (lgl->fBinStep == 1)
00647          {
00648             TEveCaloData::CellData_t cellData;
00649             for ( TEveCaloData::vCellId_t::iterator i = fCalo->fCellList.begin(); i != fCalo->fCellList.end(); ++i)
00650             {
00651                fCalo->fData->GetCellData(*i, cellData);
00652                if (sq > cellData.EtaDelta()) sq = cellData.EtaDelta();
00653                if (sq > cellData.PhiDelta()) sq = cellData.PhiDelta();
00654             }
00655          }
00656          else
00657          {
00658             TAxis* a;
00659             Int_t nb;
00660             a = fCalo->GetData()->GetEtaBins();
00661             nb = a->GetNbins();
00662             for (Int_t i=1 ; i<=nb; i++)
00663             {
00664                if (sq > a->GetBinWidth(i)) sq = a->GetBinWidth(i);
00665             }
00666 
00667             a = fCalo->GetData()->GetPhiBins();
00668             nb = a->GetNbins();
00669             for (Int_t i=1 ; i<=nb; i++)
00670             {
00671                if (sq > a->GetBinWidth(i)) sq = a->GetBinWidth(i);
00672             }
00673 
00674             sq *= lgl->fBinStep;
00675          }
00676          fCellX = (res.X()*sq)/(fCalo->GetEtaRng()*1.*cam.RefViewport().Width());
00677          fCellY = (res.Y()*sq)/(fCalo->GetPhiRng()*1.*cam.RefViewport().Height());
00678          // printf("bin width %f cells size %f %f\n", sq, fCellX, fCellY);
00679          if (fCalo->Get2DMode() == TEveCaloLego::kValSize)
00680             RenderLogaritmicScales(rnrCtx);
00681          else if (fCalo->GetPalette())
00682             RenderPaletteScales(rnrCtx);
00683       }
00684 
00685       // draw camera overlay if projected lego bbox to large
00686       SetFrustum(cam);
00687       if (   fCalo->GetEtaMin() > fFrustum[0] && fCalo->GetEtaMax() < fFrustum[2]
00688           && fCalo->GetPhiMin() > fFrustum[1] && fCalo->GetPhiMax() < fFrustum[3])
00689             drawOverlayAxis = kFALSE;
00690    }
00691 
00692    if (cam.IsPerspective() && fShowPlane)
00693    {
00694       RenderPlaneInterface(rnrCtx);
00695    }
00696 
00697    // draw info text on yop right corner
00698    if (fHeaderTxt.Length())
00699    {
00700       RenderHeader(rnrCtx);
00701    }
00702 
00703    glPopMatrix();
00704    glMatrixMode(GL_PROJECTION);
00705    glPopMatrix();
00706    glMatrixMode(GL_MODELVIEW);
00707 
00708    glDepthRange(old_depth_range[0], old_depth_range[1]);
00709 
00710    if (drawOverlayAxis) TGLCameraOverlay::Render(rnrCtx);
00711 }

Generated on Tue Jul 5 14:16:11 2011 for ROOT_528-00b_version by  doxygen 1.5.1