TGLTF3Painter.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 <typeinfo>
00013 
00014 #include "TVirtualGL.h"
00015 #include "KeySymbols.h"
00016 #include "TVirtualX.h"
00017 #include "Buttons.h"
00018 #include "TString.h"
00019 #include "TROOT.h"
00020 #include "TColor.h"
00021 #include "TMath.h"
00022 #include "TH3.h"
00023 #include "TF3.h"
00024 
00025 #include "TGLMarchingCubes.h"
00026 #include "TGLPlotCamera.h"
00027 #include "TGLTF3Painter.h"
00028 #include "TGLIncludes.h"
00029 
00030 //______________________________________________________________________________
00031 //
00032 // Plot-painter for TF3 functions.
00033 
00034 ClassImp(TGLTF3Painter)
00035 
00036 //______________________________________________________________________________
00037 TGLTF3Painter::TGLTF3Painter(TF3 *fun, TH1 *hist, TGLPlotCamera *camera, TGLPlotCoordinates *coord)
00038                   : TGLPlotPainter(hist, camera, coord, kFALSE, kFALSE, kFALSE),
00039                     fStyle(kDefault),
00040                     fF3(fun),
00041                     fXOZSlice("XOZ", (TH3 *)hist, fun, coord, &fBackBox, TGLTH3Slice::kXOZ),
00042                     fYOZSlice("YOZ", (TH3 *)hist, fun, coord, &fBackBox, TGLTH3Slice::kYOZ),
00043                     fXOYSlice("XOY", (TH3 *)hist, fun, coord, &fBackBox, TGLTH3Slice::kXOY)
00044 {
00045    // Constructor.
00046 }
00047 
00048 //______________________________________________________________________________
00049 char *TGLTF3Painter::GetPlotInfo(Int_t /*px*/, Int_t /*py*/)
00050 {
00051    //Coords for point on surface under cursor.
00052    static char mess[] = { "fun3" };
00053    return mess;
00054 }
00055 
00056 //______________________________________________________________________________
00057 Bool_t TGLTF3Painter::InitGeometry()
00058 {
00059    //Create mesh.
00060    fCoord->SetCoordType(kGLCartesian);
00061 
00062    if (!fCoord->SetRanges(fHist, kFALSE, kTRUE))
00063       return kFALSE;
00064 
00065    fBackBox.SetPlotBox(fCoord->GetXRangeScaled(), fCoord->GetYRangeScaled(), fCoord->GetZRangeScaled());
00066    if (fCamera) fCamera->SetViewVolume(fBackBox.Get3DBox());
00067 
00068    //Build mesh for TF3 surface
00069    fMesh.ClearMesh();
00070 
00071    Rgl::Mc::TMeshBuilder<TF3, Double_t> builder(kFALSE);//no averaged normals.
00072    //Set grid parameters.
00073    Rgl::Mc::TGridGeometry<Double_t> geom(fXAxis, fYAxis, fZAxis, fCoord->GetXScale(),
00074                                          fCoord->GetYScale(), fCoord->GetZScale(),
00075                                          Rgl::Mc::TGridGeometry<Double_t>::kBinEdge);
00076 
00077    builder.BuildMesh(fF3, geom, &fMesh, 0.2);
00078 
00079    if (fCoord->Modified()) {
00080       fUpdateSelection = kTRUE;
00081       const TGLVertex3 &vertex = fBackBox.Get3DBox()[0];
00082       fXOZSectionPos = vertex.Y();
00083       fYOZSectionPos = vertex.X();
00084       fXOYSectionPos = vertex.Z();
00085       fCoord->ResetModified();
00086    }
00087 
00088    return kTRUE;
00089 }
00090 
00091 //______________________________________________________________________________
00092 void TGLTF3Painter::StartPan(Int_t px, Int_t py)
00093 {
00094    //User clicks right mouse button (in a pad).
00095    fMousePosition.fX = px;
00096    fMousePosition.fY = fCamera->GetHeight() - py;
00097    fCamera->StartPan(px, py);
00098    fBoxCut.StartMovement(px, fCamera->GetHeight() - py);
00099 }
00100 
00101 //______________________________________________________________________________
00102 void TGLTF3Painter::Pan(Int_t px, Int_t py)
00103 {
00104    //User's moving mouse cursor, with middle mouse button pressed (for pad).
00105    //Calculate 3d shift related to 2d mouse movement.
00106    //Slicing is disabled (since somebody has broken it).
00107    if (fSelectedPart >= fSelectionBase) {//Pan camera.
00108       SaveModelviewMatrix();
00109       SaveProjectionMatrix();
00110 
00111       fCamera->SetCamera();
00112       fCamera->Apply(fPadPhi, fPadTheta);
00113       fCamera->Pan(px, py);
00114 
00115       RestoreProjectionMatrix();
00116       RestoreModelviewMatrix();
00117    } else if (fSelectedPart > 0) {
00118       //Convert py into bottom-top orientation.
00119       //Possibly, move box here
00120       py = fCamera->GetHeight() - py;
00121 
00122       SaveModelviewMatrix();
00123       SaveProjectionMatrix();
00124 
00125       fCamera->SetCamera();
00126       fCamera->Apply(fPadPhi, fPadTheta);
00127 
00128       if (!fHighColor) {
00129          if (fBoxCut.IsActive() && (fSelectedPart >= kXAxis && fSelectedPart <= kZAxis)) {
00130             fBoxCut.MoveBox(px, py, fSelectedPart);
00131          } else {
00132             //MoveSection(px, py);
00133          }
00134       } else {
00135          //MoveSection(px, py);
00136       }
00137 
00138       RestoreProjectionMatrix();
00139       RestoreModelviewMatrix();
00140    }
00141 
00142    fMousePosition.fX = px, fMousePosition.fY = py;
00143    fUpdateSelection = kTRUE;
00144 }
00145 
00146 //______________________________________________________________________________
00147 void TGLTF3Painter::AddOption(const TString &/*option*/)
00148 {
00149    //No options for tf3
00150 }
00151 
00152 //______________________________________________________________________________
00153 void TGLTF3Painter::ProcessEvent(Int_t event, Int_t /*px*/, Int_t py)
00154 {
00155    //Change color sheme.
00156    if (event == kKeyPress) {
00157       if (py == kKey_s || py == kKey_S) {
00158          fStyle < kMaple2 ? fStyle = ETF3Style(fStyle + 1) : fStyle = kDefault;
00159       } else if (py == kKey_c || py == kKey_C) {
00160          if (fHighColor)
00161             Info("ProcessEvent", "Cut box does not work in high color, please, switch to true color");
00162          else {
00163             fBoxCut.TurnOnOff();
00164             fUpdateSelection = kTRUE;
00165          }
00166       }
00167    } else if (event == kButton1Double && (fBoxCut.IsActive() || HasSections())) {
00168       if (fBoxCut.IsActive())
00169          fBoxCut.TurnOnOff();
00170       const TGLVertex3 *frame = fBackBox.Get3DBox();
00171       fXOZSectionPos = frame[0].Y();
00172       fYOZSectionPos = frame[0].X();
00173       fXOYSectionPos = frame[0].Z();
00174 
00175       if (!gVirtualX->IsCmdThread())
00176          gROOT->ProcessLineFast(Form("((TGLPlotPainter *)0x%lx)->Paint()", (ULong_t)this));
00177       else
00178          Paint();
00179    }
00180 }
00181 
00182 //______________________________________________________________________________
00183 void TGLTF3Painter::InitGL() const
00184 {
00185    //Initialize OpenGL state variables.
00186    glEnable(GL_LIGHTING);
00187    glEnable(GL_LIGHT0);
00188    glEnable(GL_DEPTH_TEST);
00189    glDisable(GL_CULL_FACE);
00190    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
00191 }
00192 
00193 //______________________________________________________________________________
00194 void TGLTF3Painter::DeInitGL() const
00195 {
00196    //Initialize OpenGL state variables.
00197    glDisable(GL_LIGHTING);
00198    glDisable(GL_LIGHT0);
00199    glDisable(GL_DEPTH_TEST);
00200    glDisable(GL_CULL_FACE);
00201    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
00202 }
00203 
00204 //______________________________________________________________________________
00205 void TGLTF3Painter::DrawToSelectionBuffer() const
00206 {
00207    //Draw triangles, no normals, no lighting.
00208    Rgl::ObjectIDToColor(fSelectionBase, fHighColor);
00209 
00210    if (!fBoxCut.IsActive())
00211       Rgl::DrawMesh(fMesh.fVerts, fMesh.fTris);
00212    else
00213       Rgl::DrawMesh(fMesh.fVerts, fMesh.fTris, fBoxCut);
00214 }
00215 
00216 //______________________________________________________________________________
00217 void TGLTF3Painter::DrawDefaultPlot() const
00218 {
00219    //Surface with material properties and lighting.
00220    if (HasSections()) {
00221       glEnable(GL_BLEND);
00222       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00223       glDepthMask(GL_FALSE);
00224    }
00225 
00226    SetSurfaceColor();
00227 
00228    if (!fBoxCut.IsActive()) {
00229       Rgl::DrawMesh(fMesh.fVerts, fMesh.fNorms, fMesh.fTris);
00230    } else {
00231       Rgl::DrawMesh(fMesh.fVerts, fMesh.fNorms, fMesh.fTris, fBoxCut);
00232    }
00233 
00234    if (HasSections()) {
00235       glDisable(GL_BLEND);
00236       glDepthMask(GL_TRUE);
00237    }
00238 }
00239 
00240 //______________________________________________________________________________
00241 void TGLTF3Painter::DrawMaplePlot() const
00242 {
00243    //Colored surface, without lighting and
00244    //material properties.
00245    const TGLDisableGuard lightGuard(GL_LIGHTING);
00246 
00247    if (HasSections() && fStyle < kMaple2) {
00248       glEnable(GL_BLEND);
00249       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00250       glDepthMask(GL_FALSE);
00251    }
00252 
00253    if (fStyle == kMaple1) {//Shaded polygons and outlines.
00254       glEnable(GL_POLYGON_OFFSET_FILL);//[1
00255       glPolygonOffset(1.f, 1.f);
00256    } else if (fStyle == kMaple2)//Colored outlines only.
00257       glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);//[2
00258 
00259    if(!fBoxCut.IsActive())
00260       Rgl::DrawMapleMesh(fMesh.fVerts, fMesh.fNorms, fMesh.fTris);
00261    else
00262       Rgl::DrawMapleMesh(fMesh.fVerts, fMesh.fNorms, fMesh.fTris, fBoxCut);
00263 
00264    if (fStyle == kMaple1) {
00265       //Draw outlines.
00266       glDisable(GL_POLYGON_OFFSET_FILL);//1]
00267       glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);//[3
00268       glColor4d(0., 0., 0., 0.25);
00269 
00270       if(!fBoxCut.IsActive())
00271          Rgl::DrawMesh(fMesh.fVerts, fMesh.fTris);
00272       else
00273          Rgl::DrawMesh(fMesh.fVerts, fMesh.fTris, fBoxCut);
00274 
00275       glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);//[3
00276    } else if (fStyle == kMaple2)
00277       glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00278 
00279    if (HasSections() && fStyle < kMaple2) {
00280       glDisable(GL_BLEND);
00281       glDepthMask(GL_TRUE);
00282    }
00283 }
00284 
00285 //______________________________________________________________________________
00286 void TGLTF3Painter::DrawPlot() const
00287 {
00288    //Draw mesh.
00289 
00290    //Shift plot to point of origin.
00291    const Rgl::PlotTranslation trGuard(this);
00292 
00293    fBackBox.DrawBox(fSelectedPart, fSelectionPass, fZLevels, fHighColor);
00294    DrawSections();
00295 
00296    if (fSelectionPass) {
00297       DrawToSelectionBuffer();
00298    } else if (fStyle == kDefault) {
00299       DrawDefaultPlot();
00300    } else {
00301       DrawMaplePlot();
00302    }
00303 
00304    if (fBoxCut.IsActive())
00305       fBoxCut.DrawBox(fSelectionPass, fSelectedPart);
00306 }
00307 
00308 //______________________________________________________________________________
00309 void TGLTF3Painter::SetSurfaceColor() const
00310 {
00311    //Set color for surface.
00312    Float_t diffColor[] = {0.8f, 0.8f, 0.8f, 0.15f};
00313 
00314    if (fF3->GetFillColor() != kWhite)
00315       if (const TColor *c = gROOT->GetColor(fF3->GetFillColor()))
00316          c->GetRGB(diffColor[0], diffColor[1], diffColor[2]);
00317 
00318    glMaterialfv(GL_BACK, GL_DIFFUSE, diffColor);
00319    diffColor[0] /= 2, diffColor[1] /= 2, diffColor[2] /= 2;
00320    glMaterialfv(GL_FRONT, GL_DIFFUSE, diffColor);
00321    const Float_t specColor[] = {1.f, 1.f, 1.f, 1.f};
00322    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specColor);
00323    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 70.f);
00324 }
00325 
00326 //______________________________________________________________________________
00327 Bool_t TGLTF3Painter::HasSections() const
00328 {
00329    //Any section exists.
00330    return fXOZSectionPos > fBackBox.Get3DBox()[0].Y() ||
00331           fYOZSectionPos > fBackBox.Get3DBox()[0].X() ||
00332           fXOYSectionPos > fBackBox.Get3DBox()[0].Z();
00333 }
00334 
00335 //______________________________________________________________________________
00336 void TGLTF3Painter::DrawSectionXOZ() const
00337 {
00338    // Draw XOZ parallel section.
00339    if (fSelectionPass)
00340       return;
00341    fXOZSlice.DrawSlice(fXOZSectionPos / fCoord->GetYScale());
00342 }
00343 
00344 //______________________________________________________________________________
00345 void TGLTF3Painter::DrawSectionYOZ() const
00346 {
00347    // Draw YOZ parallel section.
00348    if (fSelectionPass)
00349       return;
00350    fYOZSlice.DrawSlice(fYOZSectionPos / fCoord->GetXScale());
00351 }
00352 
00353 //______________________________________________________________________________
00354 void TGLTF3Painter::DrawSectionXOY() const
00355 {
00356    // Draw XOY parallel section.
00357    if (fSelectionPass)
00358       return;
00359    fXOYSlice.DrawSlice(fXOYSectionPos / fCoord->GetZScale());
00360 }
00361 
00362 
00363 //______________________________________________________________________________
00364 //
00365 // "gliso" option for TH3.
00366 
00367 ClassImp(TGLIsoPainter)
00368 
00369 //______________________________________________________________________________
00370 TGLIsoPainter::TGLIsoPainter(TH1 *hist, TGLPlotCamera *camera, TGLPlotCoordinates *coord)
00371                   : TGLPlotPainter(hist, camera, coord, kFALSE, kFALSE, kFALSE),
00372                     fXOZSlice("XOZ", (TH3 *)hist, coord, &fBackBox, TGLTH3Slice::kXOZ),
00373                     fYOZSlice("YOZ", (TH3 *)hist, coord, &fBackBox, TGLTH3Slice::kYOZ),
00374                     fXOYSlice("XOY", (TH3 *)hist, coord, &fBackBox, TGLTH3Slice::kXOY),
00375                     fInit(kFALSE)
00376 {
00377    //Constructor.
00378    if (hist->GetDimension() < 3)
00379       Error("TGLIsoPainter::TGLIsoPainter", "Wrong type of histogramm, must have 3 dimensions");
00380 }
00381 
00382 //______________________________________________________________________________
00383 char *TGLIsoPainter::GetPlotInfo(Int_t /*px*/, Int_t /*py*/)
00384 {
00385    //Return info for plot part under cursor.
00386 
00387    static char mess[] = { "iso" };
00388    return mess;
00389 }
00390 
00391 //______________________________________________________________________________
00392 Bool_t TGLIsoPainter::InitGeometry()
00393 {
00394    //Initializes meshes for 3d iso contours.
00395    if (fHist->GetDimension() < 3) {
00396       Error("TGLIsoPainter::TGLIsoPainter", "Wrong type of histogramm, must have 3 dimensions");
00397       return kFALSE;
00398    }
00399 
00400    //Create mesh.
00401    if (fInit)
00402       return kTRUE;
00403 
00404    //Only in cartesian.
00405    fCoord->SetCoordType(kGLCartesian);
00406    if (!fCoord->SetRanges(fHist, kFALSE, kTRUE))
00407       return kFALSE;
00408 
00409    fBackBox.SetPlotBox(fCoord->GetXRangeScaled(), fCoord->GetYRangeScaled(), fCoord->GetZRangeScaled());
00410    if (fCamera) fCamera->SetViewVolume(fBackBox.Get3DBox());
00411 
00412    //Move old meshes into the cache.
00413    if (!fIsos.empty())
00414       fCache.splice(fCache.begin(), fIsos);
00415    //Number of contours == number of iso surfaces.
00416    UInt_t nContours = fHist->GetContour();
00417 
00418    if (nContours > 1) {
00419       fColorLevels.resize(nContours);
00420       FindMinMax();
00421 
00422       if (fHist->TestBit(TH1::kUserContour)) {
00423          //There are user defined contours (iso-levels).
00424          for (UInt_t i = 0; i < nContours; ++i)
00425             fColorLevels[i] = fHist->GetContourLevelPad(i);
00426       } else {
00427          //Equidistant iso-surfaces.
00428          const Double_t isoStep = (fMinMax.second - fMinMax.first) / nContours;
00429          for (UInt_t i = 0; i < nContours; ++i)
00430             fColorLevels[i] = fMinMax.first + i * isoStep;
00431       }
00432 
00433       fPalette.GeneratePalette(nContours, fMinMax, kFALSE);
00434    } else {
00435       //Only one iso (ROOT's standard).
00436       fColorLevels.resize(nContours = 1);
00437       fColorLevels[0] = fHist->GetSumOfWeights() / (fHist->GetNbinsX() * fHist->GetNbinsY() * fHist->GetNbinsZ());
00438    }
00439 
00440    MeshIter_t firstMesh = fCache.begin();
00441    //Initialize meshes, trying to reuse mesh from
00442    //mesh cache.
00443    for (UInt_t i = 0; i < nContours; ++i) {
00444       if (firstMesh != fCache.end()) {
00445          //There is a mesh in a chache.
00446          SetMesh(*firstMesh, fColorLevels[i]);
00447          MeshIter_t next = firstMesh;
00448          ++next;
00449          fIsos.splice(fIsos.begin(), fCache, firstMesh);
00450          firstMesh = next;
00451       } else {
00452          //No meshes in a cache.
00453          //Create new one and _swap_ data (look at Mesh_t::Swap in a header)
00454          //between empty mesh in a list and this mesh
00455          //to avoid real copying.
00456          Mesh_t newMesh;
00457          SetMesh(newMesh, fColorLevels[i]);
00458          fIsos.push_back(fDummyMesh);
00459          fIsos.back().Swap(newMesh);
00460       }
00461    }
00462 
00463    if (fCoord->Modified()) {
00464       fUpdateSelection = kTRUE;
00465       fXOZSectionPos = fBackBox.Get3DBox()[0].Y();
00466       fYOZSectionPos = fBackBox.Get3DBox()[0].X();
00467       fXOYSectionPos = fBackBox.Get3DBox()[0].Z();
00468       fCoord->ResetModified();
00469    }
00470 
00471    //Avoid rebuilding the mesh.
00472    fInit = kTRUE;
00473 
00474    return kTRUE;
00475 
00476 }
00477 
00478 //______________________________________________________________________________
00479 void TGLIsoPainter::StartPan(Int_t px, Int_t py)
00480 {
00481    //User clicks right mouse button (in a pad).
00482    fMousePosition.fX = px;
00483    fMousePosition.fY = fCamera->GetHeight() - py;
00484    fCamera->StartPan(px, py);
00485    fBoxCut.StartMovement(px, fCamera->GetHeight() - py);
00486 }
00487 
00488 //______________________________________________________________________________
00489 void TGLIsoPainter::Pan(Int_t px, Int_t py)
00490 {
00491    //User's moving mouse cursor, with middle mouse button pressed (for pad).
00492    //Calculate 3d shift related to 2d mouse movement.
00493    //User's moving mouse cursor, with middle mouse button pressed (for pad).
00494    //Calculate 3d shift related to 2d mouse movement.
00495    if (fSelectedPart >= fSelectionBase) {//Pan camera.
00496       SaveModelviewMatrix();
00497       SaveProjectionMatrix();
00498 
00499       fCamera->SetCamera();
00500       fCamera->Apply(fPadPhi, fPadTheta);
00501       fCamera->Pan(px, py);
00502 
00503       RestoreProjectionMatrix();
00504       RestoreModelviewMatrix();
00505    } else if (fSelectedPart > 0) {
00506       //Convert py into bottom-top orientation.
00507       //Possibly, move box here
00508       py = fCamera->GetHeight() - py;
00509 
00510       SaveModelviewMatrix();
00511       SaveProjectionMatrix();
00512 
00513       fCamera->SetCamera();
00514       fCamera->Apply(fPadPhi, fPadTheta);
00515 
00516       if (!fHighColor) {
00517          if (fBoxCut.IsActive() && (fSelectedPart >= kXAxis && fSelectedPart <= kZAxis)) {
00518             fBoxCut.MoveBox(px, py, fSelectedPart);
00519          } else {
00520             //MoveSection(px, py);
00521          }
00522       } else {
00523          //MoveSection(px, py);
00524       }
00525 
00526       RestoreProjectionMatrix();
00527       RestoreModelviewMatrix();
00528 
00529    }
00530 
00531    fMousePosition.fX = px, fMousePosition.fY = py;
00532    fUpdateSelection = kTRUE;
00533 }
00534 
00535 //______________________________________________________________________________
00536 void TGLIsoPainter::AddOption(const TString &/*option*/)
00537 {
00538    //No additional options for TGLIsoPainter.
00539 }
00540 
00541 //______________________________________________________________________________
00542 void TGLIsoPainter::ProcessEvent(Int_t event, Int_t /*px*/, Int_t py)
00543 {
00544    //Change color sheme.
00545    if (event == kKeyPress) {
00546       if (py == kKey_c || py == kKey_C) {
00547          if (fHighColor)
00548             Info("ProcessEvent", "Cut box does not work in high color, please, switch to true color");
00549          else {
00550             fBoxCut.TurnOnOff();
00551             fUpdateSelection = kTRUE;
00552          }
00553       }
00554    } else if (event == kButton1Double && (fBoxCut.IsActive() || HasSections())) {
00555       if (fBoxCut.IsActive())
00556          fBoxCut.TurnOnOff();
00557       const TGLVertex3 *frame = fBackBox.Get3DBox();
00558       fXOZSectionPos = frame[0].Y();
00559       fYOZSectionPos = frame[0].X();
00560       fXOYSectionPos = frame[0].Z();
00561 
00562       if (!gVirtualX->IsCmdThread())
00563          gROOT->ProcessLineFast(Form("((TGLPlotPainter *)0x%lx)->Paint()", (ULong_t)this));
00564       else
00565          Paint();
00566    }
00567 }
00568 
00569 //______________________________________________________________________________
00570 void TGLIsoPainter::InitGL() const
00571 {
00572    //Initialize OpenGL state variables.
00573    glEnable(GL_LIGHTING);
00574    glEnable(GL_LIGHT0);
00575    glEnable(GL_DEPTH_TEST);
00576    glDisable(GL_CULL_FACE);
00577    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
00578 }
00579 
00580 //______________________________________________________________________________
00581 void TGLIsoPainter::DeInitGL() const
00582 {
00583    //Initialize OpenGL state variables.
00584    glDisable(GL_LIGHTING);
00585    glDisable(GL_LIGHT0);
00586    glDisable(GL_DEPTH_TEST);
00587    glDisable(GL_CULL_FACE);
00588    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
00589 }
00590 
00591 //______________________________________________________________________________
00592 void TGLIsoPainter::DrawPlot() const
00593 {
00594    //Draw mesh.
00595 
00596    //Shift plot to point of origin.
00597    const Rgl::PlotTranslation trGuard(this);
00598 
00599 
00600    fBackBox.DrawBox(fSelectedPart, fSelectionPass, fZLevels, fHighColor);
00601    DrawSections();
00602 
00603    if (fIsos.size() != fColorLevels.size()) {
00604       Error("TGLIsoPainter::DrawPlot", "Non-equal number of levels and isos");
00605       return;
00606    }
00607 
00608    if (!fSelectionPass && HasSections()) {
00609       //Surface is semi-transparent during dynamic profiling.
00610       //Having several complex nested surfaces, it's not easy
00611       //(possible?) to implement correct and _efficient_ transparency
00612       //drawing. So, artefacts are possbile.
00613       glEnable(GL_BLEND);
00614       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00615       glDepthMask(GL_FALSE);
00616    }
00617 
00618    UInt_t colorInd = 0;
00619    ConstMeshIter_t iso = fIsos.begin();
00620 
00621    for (; iso != fIsos.end(); ++iso, ++colorInd)
00622       DrawMesh(*iso, colorInd);
00623 
00624    if (!fSelectionPass && HasSections()) {
00625       glDisable(GL_BLEND);
00626       glDepthMask(GL_TRUE);
00627    }
00628 
00629    if (fBoxCut.IsActive())
00630       fBoxCut.DrawBox(fSelectionPass, fSelectedPart);
00631 }
00632 
00633 //______________________________________________________________________________
00634 void TGLIsoPainter::DrawSectionXOZ() const
00635 {
00636    // Draw XOZ parallel section.
00637    if (fSelectionPass)
00638       return;
00639    fXOZSlice.DrawSlice(fXOZSectionPos / fCoord->GetYScale());
00640 }
00641 
00642 //______________________________________________________________________________
00643 void TGLIsoPainter::DrawSectionYOZ() const
00644 {
00645    // Draw YOZ parallel section.
00646    if (fSelectionPass)
00647       return;
00648    fYOZSlice.DrawSlice(fYOZSectionPos / fCoord->GetXScale());
00649 }
00650 
00651 //______________________________________________________________________________
00652 void TGLIsoPainter::DrawSectionXOY() const
00653 {
00654    // Draw XOY parallel section.
00655    if (fSelectionPass)
00656       return;
00657    fXOYSlice.DrawSlice(fXOYSectionPos / fCoord->GetZScale());
00658 }
00659 
00660 //______________________________________________________________________________
00661 Bool_t TGLIsoPainter::HasSections() const
00662 {
00663    //Any section exists.
00664    return fXOZSectionPos > fBackBox.Get3DBox()[0].Y() || fYOZSectionPos > fBackBox.Get3DBox()[0].X() ||
00665           fXOYSectionPos > fBackBox.Get3DBox()[0].Z();
00666 }
00667 
00668 //______________________________________________________________________________
00669 void TGLIsoPainter::SetSurfaceColor(Int_t ind) const
00670 {
00671    //Set color for surface.
00672    Float_t diffColor[] = {0.8f, 0.8f, 0.8f, 0.25f};
00673 
00674    if (fColorLevels.size() == 1) {
00675       if (fHist->GetFillColor() != kWhite)
00676          if (const TColor *c = gROOT->GetColor(fHist->GetFillColor()))
00677             c->GetRGB(diffColor[0], diffColor[1], diffColor[2]);
00678    } else {
00679       const UChar_t *color = fPalette.GetColour(ind);
00680       diffColor[0] = color[0] / 255.;
00681       diffColor[1] = color[1] / 255.;
00682       diffColor[2] = color[2] / 255.;
00683    }
00684 
00685    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffColor);
00686    const Float_t specColor[] = {1.f, 1.f, 1.f, 1.f};
00687    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specColor);
00688    diffColor[0] /= 3.5, diffColor[1] /= 3.5, diffColor[2] /= 3.5;
00689    glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, diffColor);
00690    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 30.f);
00691 }
00692 
00693 //______________________________________________________________________________
00694 void TGLIsoPainter::SetMesh(Mesh_t &m, Double_t isoValue)
00695 {
00696    //Grid geometry.
00697    Rgl::Mc::TGridGeometry<Float_t> geom(fXAxis, fYAxis, fZAxis, fCoord->GetXScale(),
00698                                         fCoord->GetYScale(), fCoord->GetZScale());
00699    //Clear mesh if it was from cache.
00700    m.ClearMesh();
00701    //Select correct TMeshBuilder type.
00702    if (typeid(*fHist) == typeid(TH3C)) {
00703       Rgl::Mc::TMeshBuilder<TH3C, Float_t> builder(kTRUE);
00704       builder.BuildMesh(static_cast<TH3C *>(fHist), geom, &m, isoValue);
00705    } else if (typeid(*fHist) == typeid(TH3S)) {
00706       Rgl::Mc::TMeshBuilder<TH3S, Float_t> builder(kTRUE);
00707       builder.BuildMesh(static_cast<TH3S *>(fHist), geom, &m, isoValue);
00708    } else if (typeid(*fHist) == typeid(TH3I)) {
00709       Rgl::Mc::TMeshBuilder<TH3I, Float_t> builder(kTRUE);
00710       builder.BuildMesh(static_cast<TH3I *>(fHist), geom, &m, isoValue);
00711    } else if (typeid(*fHist) == typeid(TH3F)) {
00712       Rgl::Mc::TMeshBuilder<TH3F, Float_t> builder(kTRUE);
00713       builder.BuildMesh(static_cast<TH3F *>(fHist), geom, &m, isoValue);
00714    } else if (typeid(*fHist) == typeid(TH3D)) {
00715       Rgl::Mc::TMeshBuilder<TH3D, Float_t> builder(kTRUE);
00716       builder.BuildMesh(static_cast<TH3D *>(fHist), geom, &m, isoValue);
00717    }
00718 }
00719 
00720 //______________________________________________________________________________
00721 void TGLIsoPainter::DrawMesh(const Mesh_t &m, Int_t level) const
00722 {
00723    //Draw TF3 surface
00724    if (!fSelectionPass)
00725       SetSurfaceColor(level);
00726 
00727    if (!fBoxCut.IsActive()) {
00728       if (!fSelectionPass)
00729          Rgl::DrawMesh(m.fVerts, m.fNorms, m.fTris);
00730       else {
00731          Rgl::ObjectIDToColor(fSelectionBase, fHighColor);
00732          Rgl::DrawMesh(m.fVerts, m.fTris);
00733       }
00734    } else {
00735       if (!fSelectionPass)
00736          Rgl::DrawMesh(m.fVerts, m.fNorms, m.fTris, fBoxCut);
00737       else {
00738          Rgl::ObjectIDToColor(fSelectionBase, fHighColor);
00739          Rgl::DrawMesh(m.fVerts, m.fTris, fBoxCut);
00740       }
00741    }
00742 }
00743 
00744 //______________________________________________________________________________
00745 void TGLIsoPainter::FindMinMax()
00746 {
00747    //Find max/min bin contents for TH3.
00748    fMinMax.first  = fHist->GetBinContent(fXAxis->GetFirst(), fYAxis->GetFirst(), fZAxis->GetFirst());
00749    fMinMax.second = fMinMax.first;
00750 
00751    for (Int_t i = fXAxis->GetFirst(), ei = fXAxis->GetLast(); i <= ei; ++i) {
00752       for (Int_t j = fYAxis->GetFirst(), ej = fYAxis->GetLast(); j <= ej; ++j) {
00753          for (Int_t k = fZAxis->GetFirst(), ek = fZAxis->GetLast(); k <= ek; ++k) {
00754             const Double_t binContent = fHist->GetBinContent(i, j, k);
00755             fMinMax.first  = TMath::Min(binContent, fMinMax.first);
00756             fMinMax.second = TMath::Max(binContent, fMinMax.second);
00757          }
00758       }
00759    }
00760 }

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