TGLBoxPainter.cxx

Go to the documentation of this file.
00001 // @(#)root/gl:$Id$
00002 // Author:  Timur Pocheptsov  31/08/2006
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2006, 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 <ctype.h>
00013 
00014 #include "KeySymbols.h"
00015 #include "TVirtualX.h"
00016 #include "Buttons.h"
00017 #include "TString.h"
00018 #include "TROOT.h"
00019 #include "TClass.h"
00020 #include "TColor.h"
00021 #include "TStyle.h"
00022 #include "TH3.h"
00023 
00024 #include "TGLPlotCamera.h"
00025 #include "TGLBoxPainter.h"
00026 #include "TGLIncludes.h"
00027 
00028 //______________________________________________________________________________
00029 //
00030 // Paints TH3 histograms by rendering variable-sized bozes matching the
00031 // bin contents.
00032 
00033 ClassImp(TGLBoxPainter)
00034 
00035 //______________________________________________________________________________
00036 TGLBoxPainter::TGLBoxPainter(TH1 *hist, TGLPlotCamera *cam, TGLPlotCoordinates *coord)
00037                   : TGLPlotPainter(hist, cam, coord, kTRUE, kTRUE, kTRUE),
00038                     fXOZSlice("XOZ", (TH3 *)hist, coord, &fBackBox, TGLTH3Slice::kXOZ),
00039                     fYOZSlice("YOZ", (TH3 *)hist, coord, &fBackBox, TGLTH3Slice::kYOZ),
00040                     fXOYSlice("XOY", (TH3 *)hist, coord, &fBackBox, TGLTH3Slice::kXOY),
00041                     fType(kBox)
00042 {
00043    // Normal constructor.
00044 }
00045 
00046 
00047 //______________________________________________________________________________
00048 char *TGLBoxPainter::GetPlotInfo(Int_t, Int_t)
00049 {
00050    //Show box info (i, j, k, binContent).
00051 
00052    fPlotInfo = "";
00053 
00054    if (fSelectedPart) {
00055       if (fSelectedPart < fSelectionBase) {
00056          if (fHist->Class())
00057             fPlotInfo += fHist->Class()->GetName();
00058          fPlotInfo += "::";
00059          fPlotInfo += fHist->GetName();
00060       } else if (!fHighColor){
00061          const Int_t arr2Dsize = fCoord->GetNYBins() * fCoord->GetNZBins();
00062          const Int_t binI = (fSelectedPart - fSelectionBase) / arr2Dsize + fCoord->GetFirstXBin();
00063          const Int_t binJ = (fSelectedPart - fSelectionBase) % arr2Dsize / fCoord->GetNZBins() + fCoord->GetFirstYBin();
00064          const Int_t binK = (fSelectedPart - fSelectionBase) % arr2Dsize % fCoord->GetNZBins() + fCoord->GetFirstZBin();
00065 
00066          fPlotInfo.Form("(binx = %d; biny = %d; binz = %d; binc = %f)", binI, binJ, binK,
00067                         fHist->GetBinContent(binI, binJ, binK));
00068       } else
00069          fPlotInfo = "Switch to true color mode to get correct info";
00070    }
00071 
00072    return (Char_t *)fPlotInfo.Data();
00073 }
00074 
00075 
00076 //______________________________________________________________________________
00077 Bool_t TGLBoxPainter::InitGeometry()
00078 {
00079   //Set ranges, find min and max bin content.
00080 
00081    fCoord->SetZLog(kFALSE);
00082    fCoord->SetYLog(kFALSE);
00083    fCoord->SetXLog(kFALSE);
00084 
00085    if (!fCoord->SetRanges(fHist, kFALSE, kTRUE))//kFALSE == drawErrors, kTRUE == zAsBins
00086       return kFALSE;
00087 
00088    fBackBox.SetPlotBox(fCoord->GetXRangeScaled(), fCoord->GetYRangeScaled(), fCoord->GetZRangeScaled());
00089    if(fCamera) fCamera->SetViewVolume(fBackBox.Get3DBox());
00090 
00091    fMinMaxVal.second  = fHist->GetBinContent(fCoord->GetFirstXBin(), fCoord->GetFirstYBin(), fCoord->GetFirstZBin());
00092    fMinMaxVal.first = fMinMaxVal.second;
00093    //Bad. You can up-date some bin value and get wrong picture.
00094    for (Int_t ir = fCoord->GetFirstXBin(); ir <= fCoord->GetLastXBin(); ++ir) {
00095       for (Int_t jr = fCoord->GetFirstYBin(); jr <= fCoord->GetLastYBin(); ++jr) {
00096          for (Int_t kr = fCoord->GetFirstZBin();  kr <= fCoord->GetLastZBin(); ++kr) {
00097             fMinMaxVal.second = TMath::Max(fMinMaxVal.second, fHist->GetBinContent(ir, jr, kr));
00098             fMinMaxVal.first = TMath::Min(fMinMaxVal.first, fHist->GetBinContent(ir, jr, kr));
00099          }
00100       }
00101    }
00102 
00103    fXOYSlice.SetMinMax(fMinMaxVal);
00104    fXOZSlice.SetMinMax(fMinMaxVal);
00105    fYOZSlice.SetMinMax(fMinMaxVal);
00106 
00107    if (fCoord->Modified()) {
00108       fUpdateSelection = kTRUE;
00109       fXOZSectionPos = fBackBox.Get3DBox()[0].Y();
00110       fYOZSectionPos = fBackBox.Get3DBox()[0].X();
00111       fXOYSectionPos = fBackBox.Get3DBox()[0].Z();
00112       fCoord->ResetModified();
00113    }
00114 
00115    return kTRUE;
00116 }
00117 
00118 
00119 //______________________________________________________________________________
00120 void TGLBoxPainter::StartPan(Int_t px, Int_t py)
00121 {
00122    // User clicks right mouse button (in a pad).
00123 
00124    fMousePosition.fX = px;
00125    fMousePosition.fY = fCamera->GetHeight() - py;
00126    fCamera->StartPan(px, py);
00127    fBoxCut.StartMovement(px, fCamera->GetHeight() - py);
00128 }
00129 
00130 
00131 //______________________________________________________________________________
00132 void TGLBoxPainter::Pan(Int_t px, Int_t py)
00133 {
00134    // User's moving mouse cursor, with middle mouse button pressed (for pad).
00135    // Calculate 3d shift related to 2d mouse movement.
00136    if (fSelectedPart >= fSelectionBase) {//Pan camera.
00137       SaveModelviewMatrix();
00138       SaveProjectionMatrix();
00139 
00140       fCamera->SetCamera();
00141       fCamera->Apply(fPadPhi, fPadTheta);
00142       fCamera->Pan(px, py);
00143 
00144       RestoreProjectionMatrix();
00145       RestoreModelviewMatrix();
00146    } else if (fSelectedPart > 0) {
00147       //Convert py into bottom-top orientation.
00148       //Possibly, move box here
00149       py = fCamera->GetHeight() - py;
00150       SaveModelviewMatrix();
00151       SaveProjectionMatrix();
00152 
00153       fCamera->SetCamera();
00154       fCamera->Apply(fPadPhi, fPadTheta);
00155 
00156 
00157       if (!fHighColor) {
00158          if (fBoxCut.IsActive() && (fSelectedPart >= kXAxis && fSelectedPart <= kZAxis))
00159             fBoxCut.MoveBox(px, py, fSelectedPart);
00160          else
00161             MoveSection(px, py);
00162       } else {
00163          MoveSection(px, py);
00164       }
00165 
00166       RestoreProjectionMatrix();
00167       RestoreModelviewMatrix();
00168    }
00169 
00170    fMousePosition.fX = px, fMousePosition.fY = py;
00171    fUpdateSelection = kTRUE;
00172 }
00173 
00174 
00175 //______________________________________________________________________________
00176 void TGLBoxPainter::AddOption(const TString &option)
00177 {
00178    // Box1 == spheres.
00179 
00180    const Ssiz_t boxPos = option.Index("box");//"box" _already_ _exists_ in a string.
00181    if (boxPos + 3 < option.Length() && isdigit(option[boxPos + 3]))
00182       option[boxPos + 3] - '0' == 1 ? fType = kBox1 : fType = kBox;
00183    else
00184       fType = kBox;
00185    option.Index("z") == kNPOS ? fDrawPalette = kFALSE : fDrawPalette = kTRUE;
00186 }
00187 
00188 //______________________________________________________________________________
00189 void TGLBoxPainter::ProcessEvent(Int_t event, Int_t /*px*/, Int_t py)
00190 {
00191    // Remove sections.
00192 
00193    if (event == kButton1Double && (HasSections() || fBoxCut.IsActive())) {
00194       fXOZSectionPos = fBackBox.Get3DBox()[0].Y();
00195       fYOZSectionPos = fBackBox.Get3DBox()[0].X();
00196       fXOYSectionPos = fBackBox.Get3DBox()[0].Z();
00197       if (fBoxCut.IsActive())
00198          fBoxCut.TurnOnOff();
00199       if (!gVirtualX->IsCmdThread())
00200          gROOT->ProcessLineFast(Form("((TGLPlotPainter *)0x%lx)->Paint()", (ULong_t)this));
00201       else
00202          Paint();
00203    } else if (event == kKeyPress && (py == kKey_c || py == kKey_C)) {
00204       if (fHighColor)
00205          Info("ProcessEvent", "Switch to true color mode to use box cut");
00206       else {
00207          fBoxCut.TurnOnOff();
00208          fUpdateSelection = kTRUE;
00209       }
00210    }
00211 }
00212 
00213 //______________________________________________________________________________
00214 void TGLBoxPainter::InitGL()const
00215 {
00216    // Initialize some gl state variables.
00217    glEnable(GL_DEPTH_TEST);
00218    glEnable(GL_LIGHTING);
00219    glEnable(GL_LIGHT0);
00220    //For box option back polygons are culled (but not for dynamic profiles).
00221    glEnable(GL_CULL_FACE);
00222    glCullFace(GL_BACK);
00223 
00224    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
00225 }
00226 
00227 //______________________________________________________________________________
00228 void TGLBoxPainter::DeInitGL()const
00229 {
00230    //Return back some gl state variables.
00231    glDisable(GL_DEPTH_TEST);
00232    glDisable(GL_LIGHTING);
00233    glDisable(GL_LIGHT0);
00234    glDisable(GL_CULL_FACE);
00235    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
00236 }
00237 
00238 namespace {
00239 
00240    //______________________________________________________________________________
00241    void DrawMinusSigns(Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax,
00242                        Double_t zMin, Double_t zMax, Int_t fp, Bool_t onSphere, Bool_t transp)
00243    {
00244       //
00245       const TGLDisableGuard depthTest(GL_DEPTH_TEST);
00246       const TGLDisableGuard cullFace(GL_CULL_FACE);
00247 
00248       const Double_t ratio  = onSphere ? 0.4 : 0.15;
00249       const Double_t leftX = xMin + ratio * (xMax - xMin), rightX = xMax - ratio * (xMax - xMin);
00250       const Double_t leftY = yMin + ratio * (yMax - yMin), rightY = yMax - ratio * (yMax - yMin);
00251       const Double_t lowZ = zMin / 2. + zMax / 2. - 0.1 * (zMax - zMin);
00252       const Double_t upZ = zMin / 2. + zMax / 2. + 0.1 * (zMax - zMin);
00253 
00254 
00255       const Double_t minusVerts[][3] = {{xMin, leftY, lowZ}, {xMin, leftY, upZ}, {xMin, rightY, upZ}, {xMin, rightY, lowZ},
00256                                         {leftX, yMin, lowZ}, {rightX, yMin, lowZ}, {rightX, yMin, upZ}, {leftX, yMin, upZ},
00257                                         {xMax, leftY, lowZ}, {xMax, rightY, lowZ}, {xMax, rightY, upZ}, {xMax, leftY, upZ},
00258                                         {rightX, yMax, lowZ}, {leftX, yMax, lowZ}, {leftX, yMax, upZ}, {rightX, yMax, upZ}};
00259       const Int_t minusQuads[][4] = {{0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11}, {12, 13, 14, 15}};
00260 
00261 
00262       TGLDisableGuard light(GL_LIGHTING);
00263       glColor3d(1., 0., 0.);
00264 
00265       const Int_t    frontPlanes[][2] = {{0, 1}, {1, 2}, {2, 3}, {3, 0}};//Code duplication again :(
00266       const Int_t *verts = minusQuads[frontPlanes[fp][0]];
00267 
00268       glBegin(GL_POLYGON);
00269       glVertex3dv(minusVerts[verts[0]]);
00270       glVertex3dv(minusVerts[verts[1]]);
00271       glVertex3dv(minusVerts[verts[2]]);
00272       glVertex3dv(minusVerts[verts[3]]);
00273       glEnd();
00274 
00275       verts = minusQuads[frontPlanes[fp][1]];
00276 
00277       glBegin(GL_POLYGON);
00278       glVertex3dv(minusVerts[verts[0]]);
00279       glVertex3dv(minusVerts[verts[1]]);
00280       glVertex3dv(minusVerts[verts[2]]);
00281       glVertex3dv(minusVerts[verts[3]]);
00282       glEnd();
00283 
00284       const Float_t nullEmission[] = {0.f, 0.f, 0.f, 1.f};
00285       glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, nullEmission);
00286       glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, nullEmission);
00287 
00288       glColor4d(0., 0., 0., 0.25);
00289       glPolygonMode(GL_FRONT, GL_LINE);
00290 
00291       if (!transp) {
00292          glEnable(GL_BLEND);
00293          glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00294       }
00295 
00296       glEnable(GL_LINE_SMOOTH);
00297       glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
00298 
00299       verts = minusQuads[frontPlanes[fp][0]];
00300 
00301       glBegin(GL_POLYGON);
00302       glVertex3dv(minusVerts[verts[0]]);
00303       glVertex3dv(minusVerts[verts[1]]);
00304       glVertex3dv(minusVerts[verts[2]]);
00305       glVertex3dv(minusVerts[verts[3]]);
00306       glEnd();
00307 
00308       verts = minusQuads[frontPlanes[fp][1]];
00309 
00310       glBegin(GL_POLYGON);
00311       glVertex3dv(minusVerts[verts[0]]);
00312       glVertex3dv(minusVerts[verts[1]]);
00313       glVertex3dv(minusVerts[verts[2]]);
00314       glVertex3dv(minusVerts[verts[3]]);
00315       glEnd();
00316 
00317       glPolygonMode(GL_FRONT, GL_FILL);
00318 
00319       if (!transp)
00320          glDisable(GL_BLEND);
00321    }
00322 
00323 }
00324 
00325 //______________________________________________________________________________
00326 void TGLBoxPainter::DrawPlot()const
00327 {
00328    // Draw set of boxes (spheres)
00329 
00330    //Shift plot to point of origin.
00331    const Rgl::PlotTranslation trGuard(this);
00332 
00333    fBackBox.DrawBox(fSelectedPart, fSelectionPass, fZLevels, fHighColor);
00334    glDisable(GL_CULL_FACE);
00335    DrawSections();
00336    glEnable(GL_CULL_FACE);
00337 
00338    if (!fSelectionPass) {
00339       glEnable(GL_POLYGON_OFFSET_FILL);//[0
00340       glPolygonOffset(1.f, 1.f);
00341       SetPlotColor();
00342       if (HasSections()) {
00343          //Boxes are semi-transparent if we have any sections.
00344          glEnable(GL_BLEND);//[1
00345          glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00346       }
00347    }
00348 
00349    //Using front point, find the correct order to draw boxes from
00350    //back to front/from bottom to top (it's important only for semi-transparent boxes).
00351    const Int_t frontPoint = fBackBox.GetFrontPoint();
00352    Int_t irInit = fCoord->GetFirstXBin(), iInit = 0;
00353    const Int_t nX = fCoord->GetNXBins();
00354    Int_t jrInit = fCoord->GetFirstYBin(), jInit = 0;
00355    const Int_t nY = fCoord->GetNYBins();
00356    Int_t krInit = fCoord->GetFirstZBin(), kInit = 0;
00357    const Int_t nZ = fCoord->GetNZBins();
00358 
00359    const Int_t addI = frontPoint == 2 || frontPoint == 1 ? 1 : (iInit = nX - 1, irInit = fCoord->GetLastXBin(), -1);
00360    const Int_t addJ = frontPoint == 2 || frontPoint == 3 ? 1 : (jInit = nY - 1, jrInit = fCoord->GetLastYBin(), -1);
00361    const Int_t addK = fBackBox.Get2DBox()[frontPoint + 4].Y() < fBackBox.Get2DBox()[frontPoint].Y() ? 1
00362                      : (kInit = nZ - 1, krInit = fCoord->GetLastZBin(),-1);
00363    const Double_t xScale = fCoord->GetXScale();
00364    const Double_t yScale = fCoord->GetYScale();
00365    const Double_t zScale = fCoord->GetZScale();
00366    const TAxis   *xA = fXAxis;
00367    const TAxis   *yA = fYAxis;
00368    const TAxis   *zA = fZAxis;
00369 
00370    if (fSelectionPass && fHighColor)
00371       Rgl::ObjectIDToColor(fSelectionBase, fHighColor);//base + 1 == 7
00372 
00373    Double_t maxContent = TMath::Max(TMath::Abs(fMinMaxVal.first), TMath::Abs(fMinMaxVal.second));
00374    if(!maxContent)//bad, find better way to check zero.
00375       maxContent = 1.;
00376 
00377    for(Int_t ir = irInit, i = iInit; addI > 0 ? i < nX : i >= 0; ir += addI, i += addI) {
00378       for(Int_t jr = jrInit, j = jInit; addJ > 0 ? j < nY : j >= 0; jr += addJ, j += addJ) {
00379          for(Int_t kr = krInit, k = kInit; addK > 0 ? k < nZ : k >= 0; kr += addK, k += addK) {
00380             const Double_t binContent = fHist->GetBinContent(ir, jr, kr);
00381             const Double_t w = TMath::Abs(binContent) / maxContent;
00382             if (!w)
00383                continue;
00384 
00385             const Double_t xMin = xScale * (xA->GetBinLowEdge(ir) / 2 + xA->GetBinUpEdge(ir) / 2 - w * xA->GetBinWidth(ir) / 2);
00386             const Double_t xMax = xScale * (xA->GetBinLowEdge(ir) / 2 + xA->GetBinUpEdge(ir) / 2 + w * xA->GetBinWidth(ir) / 2);
00387             const Double_t yMin = yScale * (yA->GetBinLowEdge(jr) / 2 + yA->GetBinUpEdge(jr) / 2 - w * yA->GetBinWidth(jr) / 2);
00388             const Double_t yMax = yScale * (yA->GetBinLowEdge(jr) / 2 + yA->GetBinUpEdge(jr) / 2 + w * yA->GetBinWidth(jr) / 2);
00389             const Double_t zMin = zScale * (zA->GetBinLowEdge(kr) / 2 + zA->GetBinUpEdge(kr) / 2 - w * zA->GetBinWidth(kr) / 2);
00390             const Double_t zMax = zScale * (zA->GetBinLowEdge(kr) / 2 + zA->GetBinUpEdge(kr) / 2 + w * zA->GetBinWidth(kr) / 2);
00391 
00392             if (fBoxCut.IsActive() && fBoxCut.IsInCut(xMin, xMax, yMin, yMax, zMin, zMax))
00393                continue;
00394 
00395             const Int_t binID = fSelectionBase + i * fCoord->GetNZBins() * fCoord->GetNYBins() + j * fCoord->GetNZBins() + k;
00396 
00397             if (fSelectionPass && !fHighColor)
00398                Rgl::ObjectIDToColor(binID, fHighColor);
00399             else if(!fHighColor && fSelectedPart == binID)
00400                glMaterialfv(GL_FRONT, GL_EMISSION, Rgl::gOrangeEmission);
00401 
00402             if (fType == kBox) {
00403                Rgl::DrawBoxFront(xMin, xMax, yMin, yMax, zMin, zMax, frontPoint);
00404             } else {
00405                Rgl::DrawSphere(&fQuadric, xMin, xMax, yMin, yMax, zMin, zMax);
00406             }
00407 
00408             if (binContent < 0. && !fSelectionPass)
00409                DrawMinusSigns(xMin, xMax, yMin, yMax, zMin, zMax, frontPoint, fType != kBox, HasSections());
00410 
00411             if (!fSelectionPass && !fHighColor && fSelectedPart == binID)
00412                glMaterialfv(GL_FRONT, GL_EMISSION, Rgl::gNullEmission);
00413          }
00414       }
00415    }
00416 
00417    if (fBoxCut.IsActive())
00418       fBoxCut.DrawBox(fSelectionPass, fSelectedPart);
00419 
00420    if (!fSelectionPass && fType != kBox1) {
00421       glDisable(GL_POLYGON_OFFSET_FILL);//0]
00422       TGLDisableGuard lightGuard(GL_LIGHTING);//[2 - 2]
00423       glColor4d(0., 0., 0., 0.25);
00424       glPolygonMode(GL_FRONT, GL_LINE);//[3
00425 
00426       const TGLEnableGuard blendGuard(GL_BLEND);//[4-4] + 1]
00427       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00428       const TGLEnableGuard smoothGuard(GL_LINE_SMOOTH);//[5-5]
00429       glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
00430 
00431       for(Int_t ir = irInit, i = iInit; addI > 0 ? i < nX : i >= 0; ir += addI, i += addI) {
00432          for(Int_t jr = jrInit, j = jInit; addJ > 0 ? j < nY : j >= 0; jr += addJ, j += addJ) {
00433             for(Int_t kr = krInit, k = kInit; addK > 0 ? k < nZ : k >= 0; kr += addK, k += addK) {
00434                const Double_t w = TMath::Abs(fHist->GetBinContent(ir, jr, kr)) / maxContent;
00435                if (!w)
00436                   continue;
00437 
00438                const Double_t xMin = xScale * (xA->GetBinLowEdge(ir) / 2 + xA->GetBinUpEdge(ir) / 2 - w * xA->GetBinWidth(ir) / 2);
00439                const Double_t xMax = xScale * (xA->GetBinLowEdge(ir) / 2 + xA->GetBinUpEdge(ir) / 2 + w * xA->GetBinWidth(ir) / 2);
00440                const Double_t yMin = yScale * (yA->GetBinLowEdge(jr) / 2 + yA->GetBinUpEdge(jr) / 2 - w * yA->GetBinWidth(jr) / 2);
00441                const Double_t yMax = yScale * (yA->GetBinLowEdge(jr) / 2 + yA->GetBinUpEdge(jr) / 2 + w * yA->GetBinWidth(jr) / 2);
00442                const Double_t zMin = zScale * (zA->GetBinLowEdge(kr) / 2 + zA->GetBinUpEdge(kr) / 2 - w * zA->GetBinWidth(kr) / 2);
00443                const Double_t zMax = zScale * (zA->GetBinLowEdge(kr) / 2 + zA->GetBinUpEdge(kr) / 2 + w * zA->GetBinWidth(kr) / 2);
00444 
00445                if (fBoxCut.IsActive() && fBoxCut.IsInCut(xMin, xMax, yMin, yMax, zMin, zMax))
00446                   continue;
00447 
00448                Rgl::DrawBoxFront(xMin, xMax, yMin, yMax, zMin, zMax, frontPoint);
00449             }
00450          }
00451       }
00452 
00453       glPolygonMode(GL_FRONT, GL_FILL);//3]
00454    }
00455 
00456    if (!fSelectionPass && fDrawPalette && HasSections())
00457       DrawPalette();
00458 }
00459 
00460 //______________________________________________________________________________
00461 void TGLBoxPainter::SetPlotColor()const
00462 {
00463    // Set boxes color.
00464 
00465    Float_t diffColor[] = {0.8f, 0.8f, 0.8f, 0.05f};
00466 
00467    if (fHist->GetFillColor() != kWhite)
00468       if (const TColor *c = gROOT->GetColor(fHist->GetFillColor()))
00469          c->GetRGB(diffColor[0], diffColor[1], diffColor[2]);
00470 
00471    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffColor);
00472    const Float_t specColor[] = {1.f, 1.f, 1.f, 1.f};
00473    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specColor);
00474    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 70.f);
00475 }
00476 
00477 //______________________________________________________________________________
00478 void TGLBoxPainter::DrawSectionXOZ()const
00479 {
00480    // Draw XOZ parallel section.
00481 
00482    if (fSelectionPass)
00483       return;
00484    fXOZSlice.DrawSlice(fXOZSectionPos / fCoord->GetYScale());
00485 }
00486 
00487 //______________________________________________________________________________
00488 void TGLBoxPainter::DrawSectionYOZ()const
00489 {
00490    // Draw YOZ parallel section.
00491    if (fSelectionPass)
00492       return;
00493    fYOZSlice.DrawSlice(fYOZSectionPos / fCoord->GetXScale());
00494 }
00495 
00496 
00497 //______________________________________________________________________________
00498 void TGLBoxPainter::DrawSectionXOY()const
00499 {
00500    // Draw XOY parallel section.
00501    if (fSelectionPass)
00502       return;
00503    fXOYSlice.DrawSlice(fXOYSectionPos / fCoord->GetZScale());
00504 }
00505 
00506 
00507 //______________________________________________________________________________
00508 Bool_t TGLBoxPainter::HasSections()const
00509 {
00510    // Check, if any section exists.
00511 
00512    return fXOZSectionPos > fBackBox.Get3DBox()[0].Y() || fYOZSectionPos> fBackBox.Get3DBox()[0].X() ||
00513           fXOYSectionPos > fBackBox.Get3DBox()[0].Z();
00514 }
00515 
00516 //______________________________________________________________________________
00517 void TGLBoxPainter::DrawPalette()const
00518 {
00519    //Draw. Palette.
00520    //Originally, fCamera was never null.
00521    //It can be a null now because of gl-viewer.
00522    if (!fCamera) {
00523       //Thank you, gl-viewer!
00524       return;
00525    }
00526 
00527    const TGLLevelPalette * palette = 0;
00528    const TGLVertex3 *frame = fBackBox.Get3DBox();
00529 
00530    if (fXOZSectionPos > frame[0].Y())
00531       palette = &fXOZSlice.GetPalette();
00532    else if (fYOZSectionPos > frame[0].X())
00533       palette = &fYOZSlice.GetPalette();
00534    else if (fXOYSectionPos > frame[0].Z())
00535       palette = &fXOYSlice.GetPalette();
00536 
00537    if (!palette || !palette->GetPaletteSize()) {
00538       return;
00539    }
00540 
00541    Rgl::DrawPalette(fCamera, *palette);
00542 
00543    glFinish();
00544 
00545    fCamera->SetCamera();
00546    fCamera->Apply(fPadPhi, fPadTheta);
00547 }
00548 
00549 //______________________________________________________________________________
00550 void TGLBoxPainter::DrawPaletteAxis()const
00551 {
00552    //Draw. Palette. Axis.
00553    if (HasSections()) {
00554       gVirtualX->SetDrawMode(TVirtualX::kCopy);//TCanvas by default sets in kInverse
00555       Rgl::DrawPaletteAxis(fCamera, fMinMaxVal, fCoord->GetCoordType() == kGLCartesian ? fCoord->GetZLog() : kFALSE);
00556    }
00557 }

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