// @(#)root/gl:$Id$
// Author:  Timur Pocheptsov  31/08/2006

/*************************************************************************
 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include <algorithm>
#include "Riostream.h"
#include <cstdlib>
#include <cctype>

#include "TVirtualPad.h"
#include "KeySymbols.h"
#include "TVirtualGL.h"
#include "TVirtualX.h"
#include "Buttons.h"
#include "TString.h"
#include "TStyle.h"
#include "TGaxis.h"
#include "TColor.h"
#include "TROOT.h"
#include "TMath.h"
#include "TAxis.h"
#include "TH1.h"
#include "TRandom.h"

#include "TGLSurfacePainter.h"
#include "TGLPlotCamera.h"
#include "TGLIncludes.h"

//______________________________________________________________________________
//
// Implements painting of TH2 with "SURF" option.

ClassImp(TGLSurfacePainter)

TRandom *TGLSurfacePainter::fgRandom = new TRandom(0);

//______________________________________________________________________________
void TGLSurfacePainter::Projection_t::Swap(Projection_t &rhs)
{
   // Constructor.

   fRGBA[0] = rhs.fRGBA[0], fRGBA[1] = rhs.fRGBA[1], fRGBA[2] = rhs.fRGBA[2], fRGBA[3] = rhs.fRGBA[3];
   fVertices.swap(rhs.fVertices);
}

//______________________________________________________________________________
TGLSurfacePainter::TGLSurfacePainter(TH1 *hist, TGLPlotCamera *camera, TGLPlotCoordinates *coord)
                                     : TGLPlotPainter(hist, camera, coord, kTRUE, kTRUE, kTRUE),
                                       fType(kSurf),
                                       fSectionPass(kFALSE),
                                       fUpdateTexMap(kTRUE)
{
   // Constructor.
}

//______________________________________________________________________________
char *TGLSurfacePainter::GetPlotInfo(Int_t px, Int_t py)
{
   //Coords for point on surface under cursor.

   static char null[] = { "" };
   if (fSelectedPart) {
      if (fHighColor)
         return fSelectedPart < fSelectionBase ? (char *)"TF2" : (char *)"Switch to true-color mode to obtain correct info";
      return fSelectedPart < fSelectionBase ? (char *)"TF2" : WindowPointTo3DPoint(px, py);
   }
   return null;
}

//______________________________________________________________________________
Bool_t TGLSurfacePainter::InitGeometry()
{
   //Set mesh, normals.
   Bool_t ret = kFALSE;
   switch (fCoord->GetCoordType()) {
   case kGLCartesian:
      ret = InitGeometryCartesian(); break;
   case kGLPolar:
      ret = InitGeometryPolar(); break;
   case kGLCylindrical:
      ret = InitGeometryCylindrical(); break;
   case kGLSpherical:
      ret = InitGeometrySpherical(); break;
   default:
      return kFALSE;
   }
   if (ret && fCamera) fCamera->SetViewVolume(fBackBox.Get3DBox());
   return ret;
}

//______________________________________________________________________________
void TGLSurfacePainter::StartPan(Int_t px, Int_t py)
{
   //User clicks right mouse button (in a pad).
   fMousePosition.fX = px;
   fMousePosition.fY = fCamera->GetHeight() - py;
   fCamera->StartPan(px, py);
   fBoxCut.StartMovement(px, fCamera->GetHeight() - py);
}

//______________________________________________________________________________
void TGLSurfacePainter::Pan(Int_t px, Int_t py)
{
   //User's moving mouse cursor, with middle mouse button pressed (for pad).
   //Calculate 3d shift related to 2d mouse movement.
   if (fSelectedPart >= fSelectionBase) {//Pan camera.
      SaveModelviewMatrix();
      SaveProjectionMatrix();

      fCamera->SetCamera();
      fCamera->Apply(fPadPhi, fPadTheta);
      fCamera->Pan(px, py);

      RestoreProjectionMatrix();
      RestoreModelviewMatrix();
   } else if (fSelectedPart > 0) {
      //Convert py into bottom-top orientation.
      py = fCamera->GetHeight() - py;

      SaveModelviewMatrix();
      SaveProjectionMatrix();

      fCamera->SetCamera();
      fCamera->Apply(fPadPhi, fPadTheta);


      if (!fHighColor) {
         if (fBoxCut.IsActive() && (fSelectedPart >= kXAxis && fSelectedPart <= kZAxis))
            fBoxCut.MoveBox(px, py, fSelectedPart);
         else
            MoveSection(px, py);
      }
      else
         MoveSection(px, py);

      RestoreProjectionMatrix();
      RestoreModelviewMatrix();
   }

   fMousePosition.fX = px, fMousePosition.fY = py;
   fUpdateSelection = kTRUE;
}

//______________________________________________________________________________
void TGLSurfacePainter::AddOption(const TString &option)
{
   //Additional options for surfaces.
   using namespace std;
   const Ssiz_t surfPos = option.Index("surf");//"surf" _already_ _exists_ in a string.
   if (surfPos + 4 < option.Length() && isdigit(option[surfPos + 4])) {
      switch (option[surfPos + 4] - '0') {
      case 1:
         fType = kSurf1;
         break;
      case 2:
         fType = kSurf2;
         break;
      case 3:
         fType = kSurf3;
         fCoord->SetCoordType(kGLCartesian);
         break;
      case 4:
         fType = kSurf4;
         break;
      case 5:
         if (fCoord->GetCoordType() != kGLSpherical && fCoord->GetCoordType() != kGLCylindrical)
            fType = kSurf3;
         else
            fType = kSurf5;
         break;
      default:
         fType = kSurf;
      }
   } else
      fType = kSurf;

   option.Index("z") == kNPOS ? fDrawPalette = kFALSE : fDrawPalette = kTRUE;
}

//______________________________________________________________________________
void TGLSurfacePainter::ProcessEvent(Int_t event, Int_t /*px*/, Int_t py)
{
   //Remove all profiles/sections.
   const TGLVertex3 *frame = fBackBox.Get3DBox();
   if (py == kKey_P || py == kKey_p) {

      if (HasSections()) {
         fSectionPass = kTRUE;
         DrawSectionXOZ();
         DrawSectionYOZ();
         DrawSectionXOY();
         fXOZSectionPos = frame[0].Y();
         fYOZSectionPos = frame[0].X();
         fXOYSectionPos = frame[0].Z();
         fSectionPass = kFALSE;
      }
   } else if (event == kButton1Double && (HasSections() || HasProjections() || fBoxCut.IsActive())) {
      fXOZSectionPos = frame[0].Y();
      fYOZSectionPos = frame[0].X();
      fXOYSectionPos = frame[0].Z();
      fXOZProj.clear();
      fYOZProj.clear();
      fXOYProj.clear();
      if (fBoxCut.IsActive())
         fBoxCut.TurnOnOff();
      if (!gVirtualX->IsCmdThread())
         gROOT->ProcessLineFast(Form("((TGLPlotPainter *)0x%lx)->Paint()", (ULong_t)this));
      else
         Paint();
   } else if (event == kKeyPress && (py == kKey_c || py == kKey_C)) {
      if (fHighColor)
         Info("ProcessEvent", "Switch to true color to use box cut");
      else {
         fBoxCut.TurnOnOff();
         fUpdateSelection = kTRUE;
      }
   }
}

//______________________________________________________________________________
void TGLSurfacePainter::InitGL()const
{
   //Initialize some OpenGL state variables.
   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);
   glEnable(GL_DEPTH_TEST);
   glDisable(GL_CULL_FACE);
   glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
}

//______________________________________________________________________________
void TGLSurfacePainter::DeInitGL()const
{
   //Initialize some OpenGL state variables.
   glDisable(GL_LIGHTING);
   glDisable(GL_LIGHT0);
   glDisable(GL_DEPTH_TEST);
   glDisable(GL_CULL_FACE);
   glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
}


//______________________________________________________________________________
void TGLSurfacePainter::SetNormals()
{
   //One normal per vertex;
   //this normal is average of
   //neighbouring triangles normals.
   const Int_t nX = fCoord->GetNXBins();
   const Int_t nY = fCoord->GetNYBins();

   fFaceNormals.resize((nX + 1) * (nY + 1));
   fFaceNormals.assign(fFaceNormals.size(), std::pair<TGLVector3, TGLVector3>());
   fFaceNormals.SetRowLen(nY + 1);


   //first, calculate normal for each triangle face
   for (Int_t i = 0; i < nX - 1; ++i) {
      for (Int_t j = 0; j < nY - 1; ++j) {
         //first "bottom-left" triangle
         TMath::Normal2Plane(fMesh[i][j + 1].CArr(), fMesh[i][j].CArr(), fMesh[i + 1][j].CArr(),
                             fFaceNormals[i + 1][j + 1].first.Arr());
         //second "top-right" triangle
         TMath::Normal2Plane(fMesh[i + 1][j].CArr(), fMesh[i + 1][j + 1].CArr(), fMesh[i][j + 1].CArr(),
                             fFaceNormals[i + 1][j + 1].second.Arr());
      }
   }

   fAverageNormals.resize(nX * nY);
   fAverageNormals.SetRowLen(nY);

   fAverageNormals.assign(fAverageNormals.size(), TGLVector3());
   //second, calculate average normal for each vertex
   for (Int_t i = 0; i < nX; ++i) {
      for (Int_t j = 0; j < nY; ++j) {
         TGLVector3 &norm = fAverageNormals[i][j];

         norm += fFaceNormals[i][j].second;
         norm += fFaceNormals[i][j + 1].first;
         norm += fFaceNormals[i][j + 1].second;
         norm += fFaceNormals[i + 1][j].first;
         norm += fFaceNormals[i + 1][j].second;
         norm += fFaceNormals[i + 1][j + 1].first;

         if (!norm.X() && !norm.Y() && !norm.Z())
            continue;

         norm.Normalise();
      }
   }
}

//______________________________________________________________________________
void TGLSurfacePainter::SetSurfaceColor()const
{
   //Set color for surface.
   Float_t diffColor[] = {0.8f, 0.8f, 0.8f, 0.35f};

   if (fHist->GetFillColor() != kWhite && fType != kSurf1 && fType != kSurf2 && fType != kSurf5)
      if (const TColor *c = gROOT->GetColor(fHist->GetFillColor()))
         c->GetRGB(diffColor[0], diffColor[1], diffColor[2]);

   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffColor);
   const Float_t specColor[] = {1.f, 1.f, 1.f, 1.f};
   glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specColor);
   glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 70.f);
}

//______________________________________________________________________________
void TGLSurfacePainter::DrawPlot()const
{
   //Draw surf/surf1/surf2/surf4

   //Shift plot to point of origin.
   const Rgl::PlotTranslation trGuard(this);

   if (fCoord->GetCoordType() == kGLCartesian) {
      fBackBox.DrawBox(fSelectedPart, fSelectionPass, fZLevels, fHighColor);
      DrawSections();
      if (!fSelectionPass)
         DrawProjections();
   }

   if (!fSelectionPass) {
      SetSurfaceColor();
      glEnable(GL_POLYGON_OFFSET_FILL);
      glPolygonOffset(1.f, 1.f);

      if (HasSections() || HasProjections())
      {
         //Surface is semi-transparent during dynamic profiling
         glEnable(GL_BLEND);
         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      }

   }

   if (Textured() && !fSelectionPass) {
      if (!PreparePalette()) {
         fType = kSurf;
         fDrawPalette = kFALSE;
      }
      else if (fType != kSurf3)
         fPalette.EnableTexture(GL_MODULATE);
   }

   const Int_t nX = fCoord->GetNXBins();
   const Int_t nY = fCoord->GetNYBins();
   const Int_t frontPoint = fBackBox.GetFrontPoint();
   Int_t i = 0, firstJ = 0;
   const Int_t addI = frontPoint == 2 || frontPoint == 1 ? i = 0, 1 : (i = nX - 2, -1);
   const Int_t addJ = frontPoint == 2 || frontPoint == 3 ? firstJ = 0, 1 : (firstJ = nY - 2, -1);

   if (fHighColor && fSelectionPass)
      Rgl::ObjectIDToColor(fSelectionBase, kTRUE);

   for (; addI > 0 ? i < nX - 1 : i >= 0; i += addI) {
      for (Int_t j = firstJ; addJ > 0 ? j < nY - 1 : j >= 0; j += addJ) {
         Int_t triNumber = 2 * i * (nY - 1) + j * 2 + fSelectionBase;

         Double_t xMin = TMath::Min(TMath::Min(fMesh[i][j + 1].X(), fMesh[i][j].X()), fMesh[i + 1][j].X());
         Double_t xMax = TMath::Max(TMath::Max(fMesh[i][j + 1].X(), fMesh[i][j].X()), fMesh[i + 1][j].X());
         Double_t yMin = TMath::Min(TMath::Min(fMesh[i][j + 1].Y(), fMesh[i][j].Y()), fMesh[i + 1][j].Y());
         Double_t yMax = TMath::Max(TMath::Max(fMesh[i][j + 1].Y(), fMesh[i][j].Y()), fMesh[i + 1][j].Y());
         Double_t zMin = TMath::Min(TMath::Min(fMesh[i][j + 1].Z(), fMesh[i][j].Z()), fMesh[i + 1][j].Z());
         Double_t zMax = TMath::Max(TMath::Max(fMesh[i][j + 1].Z(), fMesh[i][j].Z()), fMesh[i + 1][j].Z());

         if (fBoxCut.IsActive() && fBoxCut.IsInCut(xMin, xMax, yMin, yMax, zMin, zMax))
            continue;

         if (fSelectionPass && !fHighColor)
            Rgl::ObjectIDToColor(triNumber, kFALSE);

         if ((fType == kSurf1 || fType == kSurf2 || fType == kSurf5) && !fSelectionPass)
            Rgl::DrawFaceTextured(fMesh[i][j + 1], fMesh[i][j], fMesh[i + 1][j],
                                 fTexMap[i][j + 1], fTexMap[i][j], fTexMap[i + 1][j],
                                 fAverageNormals[i][j + 1], fAverageNormals[i][j],
                                 fAverageNormals[i + 1][j]);
         else
            Rgl::DrawSmoothFace(fMesh[i][j + 1], fMesh[i][j], fMesh[i + 1][j],
                              fAverageNormals[i][j + 1], fAverageNormals[i][j],
                              fAverageNormals[i + 1][j]);

         ++triNumber;

         if (fSelectionPass && !fHighColor)
            Rgl::ObjectIDToColor(triNumber, kFALSE);

         if ((fType == kSurf1 || fType == kSurf2 || fType == kSurf5) && !fSelectionPass)
            Rgl::DrawFaceTextured(fMesh[i + 1][j], fMesh[i + 1][j + 1], fMesh[i][j + 1],
                                 fTexMap[i + 1][j], fTexMap[i + 1][j + 1], fTexMap[i][j + 1],
                                 fAverageNormals[i + 1][j], fAverageNormals[i + 1][j + 1],
                                 fAverageNormals[i][j + 1]);
         else
            Rgl::DrawSmoothFace(fMesh[i + 1][j], fMesh[i + 1][j + 1], fMesh[i][j + 1],
                              fAverageNormals[i + 1][j], fAverageNormals[i + 1][j + 1],
                              fAverageNormals[i][j + 1]);
      }
   }

   if (!fSelectionPass)
      glDisable(GL_POLYGON_OFFSET_FILL);

   if (fBoxCut.IsActive())
      fBoxCut.DrawBox(fSelectionPass, fSelectedPart);

   if (fType != kSurf3 && Textured() && !fSelectionPass)
      fPalette.DisableTexture();

   //Draw outlines here
   if (!fSelectionPass) {
      const TGLEnableGuard  blendGuard(GL_BLEND);

      if (fType == kSurf || fType == kSurf1 || fType == kSurf3) {
         const TGLDisableGuard lightGuard(GL_LIGHTING);
         const TGLEnableGuard  smoothGuard(GL_LINE_SMOOTH);

         glDepthMask(GL_FALSE);

         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
         glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

         glColor4d(0., 0., 0., 0.5);

         for (i = 0; i < nX - 1; ++i) {
            for (Int_t j = 0; j < nY - 1; ++j) {
               Rgl::DrawQuadOutline(fMesh[i][j + 1], fMesh[i][j], fMesh[i + 1][j], fMesh[i + 1][j + 1]);
            }
         }

         glDepthMask(GL_TRUE);
      }
   }

   if (fType == kSurf3 && !fSelectionPass) {
      fPalette.EnableTexture(GL_MODULATE);
      const TGLEnableGuard blend(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      DrawContoursProjection();
      fPalette.DisableTexture();
   }

   if (!fSelectionPass && fSelectedPart > 6) {
      //Draw red outline for surface.
      const TGLDisableGuard lightGuard(GL_LIGHTING);
      const TGLEnableGuard blendGuard(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      const TGLEnableGuard smoothGuard(GL_LINE_SMOOTH);
      glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
      glLineWidth(3.f);

      glColor4d(1.f, 0.f, 0.4f, 0.6f);
      glBegin(GL_LINE_STRIP);
      for (i = 0; i < nX; ++i)
         glVertex3dv(fMesh[i][0].CArr());
      for (Int_t j = 0; j < nY; ++j)
         glVertex3dv(fMesh[nX - 1][j].CArr());
      for (i = nX - 1; i >= 0; --i)
         glVertex3dv(fMesh[i][nY - 1].CArr());
      for (Int_t j = nY - 1; j >= 0; --j)
         glVertex3dv(fMesh[0][j].CArr());
      glEnd();
      glLineWidth(1.f);
   }

   if (!fSelectionPass && fDrawPalette)
      DrawPalette();
}

//______________________________________________________________________________
Bool_t TGLSurfacePainter::InitGeometryCartesian()
{
   //Find bin ranges for X and Y axes,
   //axes ranges for X, Y and Z.
   //Function returns false, if logarithmic scale for
   //some axis was requested, but we cannot
   //find correct range.

   if (!fCoord->SetRanges(fHist, kFALSE, kFALSE)) //the second arg must be drawErrors, the third is always kFALSE.
      return kFALSE;

   fBackBox.SetPlotBox(fCoord->GetXRangeScaled(), fCoord->GetYRangeScaled(), fCoord->GetZRangeScaled());
   //Set surface's mesh
   //Calculates table of X and Y for lego (Z is obtained during drawing) or
   //calculate mesh of triangles with vertices in the centres of bins
   const Int_t nX = fCoord->GetNXBins();
   const Int_t nY = fCoord->GetNYBins();

   fMesh.resize(nX * nY);
   fMesh.SetRowLen(nY);

   for (Int_t i = 0, ir = fCoord->GetFirstXBin(); i < nX; ++i, ++ir) {
      for (Int_t j = 0, jr = fCoord->GetFirstYBin(); j < nY; ++j, ++jr) {
         fCoord->GetXLog() ? fMesh[i][j].X() = TMath::Log10(fXAxis->GetBinCenter(ir)) * fCoord->GetXScale()
                           : fMesh[i][j].X() = fXAxis->GetBinCenter(ir) * fCoord->GetXScale();
         fCoord->GetYLog() ? fMesh[i][j].Y() = TMath::Log10(fYAxis->GetBinCenter(jr)) * fCoord->GetYScale()
                           : fMesh[i][j].Y() = fYAxis->GetBinCenter(jr) * fCoord->GetYScale();

         Double_t z = fHist->GetBinContent(ir, jr);
         ClampZ(z);
         fMesh[i][j].Z() = z;
      }
   }

   if (Textured()) {
      fMinMaxVal.first  = fHist->GetBinContent(fCoord->GetFirstXBin(), fCoord->GetFirstYBin());
      fMinMaxVal.second = fMinMaxVal.first;

      for (Int_t i = fCoord->GetFirstXBin(), e = fCoord->GetLastXBin(); i <= e; ++i) {
         for (Int_t j = fCoord->GetFirstYBin(), e1 = fCoord->GetLastYBin(); j <= e1; ++j) {
            const Double_t val = fHist->GetBinContent(i, j);
            fMinMaxVal.first  = TMath::Min(fMinMaxVal.first, val);
            fMinMaxVal.second = TMath::Max(fMinMaxVal.second, val);
         }
      }

      ClampZ(fMinMaxVal.first);
      ClampZ(fMinMaxVal.second);

      fUpdateTexMap = kTRUE;
   }

   SetNormals();

   if (fCoord->Modified()) {
      fUpdateSelection = kTRUE;
      const TGLVertex3 &vertex = fBackBox.Get3DBox()[0];
      fXOZSectionPos = vertex.Y();
      fYOZSectionPos = vertex.X();
      fXOYSectionPos = vertex.Z();
      fCoord->ResetModified();
      Rgl::SetZLevels(fZAxis, fCoord->GetZRange().first, fCoord->GetZRange().second, fCoord->GetZScale(), fZLevels);
   }

   return kTRUE;
}

//______________________________________________________________________________
Bool_t TGLSurfacePainter::InitGeometryPolar()
{
   //Find bin ranges for X and Y axes,
   //axes ranges for X, Y and Z.
   //Function returns false, if logarithmic scale for
   //some axis was requested, but we cannot
   //find correct range.

   if (!fCoord->SetRanges(fHist, kFALSE, kFALSE))
      return kFALSE;

   fBackBox.SetPlotBox(fCoord->GetXRangeScaled(), fCoord->GetYRangeScaled(), fCoord->GetZRangeScaled());

   if (fCoord->Modified()) {
      fUpdateSelection = kTRUE;
      const TGLVertex3 &vertex = fBackBox.Get3DBox()[0];
      fXOZSectionPos = vertex.Y();
      fYOZSectionPos = vertex.X();
      fXOYSectionPos = vertex.Z();
      fCoord->ResetModified();
   }

   const Int_t nY = fCoord->GetNYBins();
   const Int_t nX = fCoord->GetNXBins();

   fMesh.resize(nX * nY);
   fMesh.SetRowLen(nY);

   const Double_t fullAngle = fXAxis->GetBinCenter(fXAxis->GetNbins()) - fXAxis->GetBinCenter(1);
   const Double_t phiLow    = fXAxis->GetBinCenter(1);
   const Double_t rRange    = fYAxis->GetBinCenter(fYAxis->GetNbins()) - fYAxis->GetBinCenter(1);

   for (Int_t i = 0, ir = fCoord->GetFirstXBin(); i < nX; ++i, ++ir) {
      for (Int_t j = 0, jr = fCoord->GetFirstYBin(); j < nY; ++j, ++jr) {
         const Double_t angle  = (fXAxis->GetBinCenter(ir) - phiLow) / fullAngle * TMath::TwoPi();
         const Double_t radius = ((fYAxis->GetBinCenter(jr)) - fYAxis->GetBinCenter(1)) /
                                 rRange * fCoord->GetYScale();
         fMesh[i][j].X() = radius * TMath::Cos(angle);
         fMesh[i][j].Y() = radius * TMath::Sin(angle);
         Double_t z = fHist->GetBinContent(ir, jr);
         ClampZ(z);
         fMesh[i][j].Z() = z;
      }
   }

   SetNormals();

   if (Textured()) {
      fMinMaxVal.first  = fHist->GetBinContent(fCoord->GetFirstXBin(), fCoord->GetFirstYBin());
      fMinMaxVal.second = fMinMaxVal.first;

      for (Int_t i = fCoord->GetFirstXBin(), e = fCoord->GetLastXBin(); i <= e; ++i) {
         for (Int_t j = fCoord->GetFirstYBin(), e1 = fCoord->GetLastYBin(); j <= e1; ++j) {
            const Double_t val = fHist->GetBinContent(i, j);
            fMinMaxVal.first  = TMath::Min(fMinMaxVal.first, val);
            fMinMaxVal.second = TMath::Max(fMinMaxVal.second, val);
         }
      }

      fUpdateTexMap = kTRUE;
   }


   return kTRUE;
}

//______________________________________________________________________________
Bool_t TGLSurfacePainter::InitGeometryCylindrical()
{
   //Find bin ranges for X and Y axes,
   //axes ranges for X, Y and Z.
   //Function returns false, if logarithmic scale for
   //some axis was requested, but we cannot
   //find correct range.

   if (!fCoord->SetRanges(fHist, kFALSE, kFALSE))
      return kFALSE;

   fBackBox.SetPlotBox(fCoord->GetXRangeScaled(), fCoord->GetYRangeScaled(), fCoord->GetZRangeScaled());

   if (fCoord->Modified()) {
      fUpdateSelection = kTRUE;
      const TGLVertex3 &vertex = fBackBox.Get3DBox()[0];
      fXOZSectionPos = vertex.Y();
      fYOZSectionPos = vertex.X();
      fXOYSectionPos = vertex.Z();
      fCoord->ResetModified();
   }

   const Int_t nY = fCoord->GetNYBins();
   const Int_t nX = fCoord->GetNXBins();
   fMesh.resize(nX * nY);
   fMesh.SetRowLen(nY);

   Double_t legoR = gStyle->GetLegoInnerR();
   if (legoR > 1. || legoR < 0.)
      legoR = 0.5;
   const Double_t rRange = fCoord->GetZLength();
   const Double_t sc = (1 - legoR) * fCoord->GetXScale();
   legoR *= fCoord->GetXScale();

   const Double_t fullAngle = fXAxis->GetBinCenter(fXAxis->GetNbins()) - fXAxis->GetBinCenter(1);
   const Double_t phiLow    = fXAxis->GetBinCenter(1);
   Double_t angle = 0.;

   for (Int_t i = 0, ir = fCoord->GetFirstXBin(); i < nX; ++i, ++ir) {
      for (Int_t j = 0, jr = fCoord->GetFirstYBin(); j < nY; ++j, ++jr) {
         angle = (fXAxis->GetBinLowEdge(ir) - phiLow) / fullAngle * TMath::TwoPi();
         Double_t r = fType != kSurf5 ? legoR + (fHist->GetBinContent(ir, jr) - fCoord->GetZRange().first) / rRange * sc : legoR;
         fMesh[i][j].X() = r * TMath::Cos(angle);
         fMesh[i][j].Y() = fCoord->GetYLog() ?
                              TMath::Log10(fYAxis->GetBinCenter(jr)) * fCoord->GetYScale()
                                          :
                              fYAxis->GetBinCenter(jr) * fCoord->GetYScale();
         fMesh[i][j].Z() = r * TMath::Sin(angle);
      }
   }

   if (Textured()) {
      fMinMaxVal.first  = fHist->GetBinContent(fCoord->GetFirstXBin(), fCoord->GetFirstYBin());
      fMinMaxVal.second = fMinMaxVal.first;

      for (Int_t i = fCoord->GetFirstXBin(), e = fCoord->GetLastXBin(); i <= e; ++i) {
         for (Int_t j = fCoord->GetFirstYBin(), e1 = fCoord->GetLastYBin(); j <= e1; ++j) {
            const Double_t val = fHist->GetBinContent(i, j);
            fMinMaxVal.first  = TMath::Min(fMinMaxVal.first, val);
            fMinMaxVal.second = TMath::Max(fMinMaxVal.second, val);
         }
      }

      fUpdateTexMap = kTRUE;
   }


   SetNormals();

   return kTRUE;
}

//______________________________________________________________________________
Bool_t TGLSurfacePainter::InitGeometrySpherical()
{
   //Find bin ranges for X and Y axes,
   //axes ranges for X, Y and Z.
   //Function returns false, if logarithmic scale for
   //some axis was requested, but we cannot
   //find correct range.

   if (!fCoord->SetRanges(fHist, kFALSE, kFALSE))
      return kFALSE;

   fBackBox.SetPlotBox(fCoord->GetXRangeScaled(), fCoord->GetYRangeScaled(), fCoord->GetZRangeScaled());

   if (fCoord->Modified()) {
      fUpdateSelection = kTRUE;
      const TGLVertex3 &vertex = fBackBox.Get3DBox()[0];
      fXOZSectionPos = vertex.Y();
      fYOZSectionPos = vertex.X();
      fXOYSectionPos = vertex.Z();
      fCoord->ResetModified();
   }

   const Int_t nY = fCoord->GetNYBins();
   const Int_t nX = fCoord->GetNXBins();
   fMesh.resize(nX * nY);
   fMesh.SetRowLen(nY);

   Double_t legoR = gStyle->GetLegoInnerR();
   if (legoR > 1. || legoR < 0.)
      legoR = 0.5;
   const Double_t rRange = fCoord->GetZLength();
   const Double_t sc = (1 - legoR) * fCoord->GetXScale();
   legoR *= fCoord->GetXScale();

   //0 <= theta <= 2 * pi
   const Double_t fullTheta   = fXAxis->GetBinCenter(fXAxis->GetNbins()) - fXAxis->GetBinCenter(1);
   const Double_t thetaLow    = fXAxis->GetBinCenter(1);
   //0 <= phi <= pi
   const Double_t fullPhi = fYAxis->GetBinCenter(fYAxis->GetNbins()) - fYAxis->GetBinCenter(1);
   const Double_t phiLow  = fYAxis->GetBinCenter(1);

   for (Int_t i = 0, ir = fCoord->GetFirstXBin(); i < nX; ++i, ++ir) {

      const Double_t theta = (fXAxis->GetBinCenter(ir) - thetaLow) / fullTheta * TMath::TwoPi();

      for (Int_t j = 0, jr = fCoord->GetFirstYBin(); j < nY; ++j, ++jr) {

         const Double_t phi = (fYAxis->GetBinCenter(jr) - phiLow) / fullPhi * TMath::Pi();
         const Double_t r   = fType != kSurf5 ? legoR + (fHist->GetBinContent(ir, jr) - fCoord->GetZRange().first) / rRange * sc
                                             : legoR;

         fMesh[i][j].X() = r * TMath::Sin(phi) * TMath::Cos(theta);
         fMesh[i][j].Y() = r * TMath::Sin(phi) * TMath::Sin(theta);
         fMesh[i][j].Z() = r * TMath::Cos(phi);
      }
   }

   if (Textured()) {
      fMinMaxVal.first  = fHist->GetBinContent(fCoord->GetFirstXBin(), fCoord->GetFirstYBin());
      fMinMaxVal.second = fMinMaxVal.first;

      for (Int_t i = fCoord->GetFirstXBin(), e = fCoord->GetLastXBin(); i <= e; ++i) {
         for (Int_t j = fCoord->GetFirstYBin(), e1 = fCoord->GetLastYBin(); j <= e1; ++j) {
            const Double_t val = fHist->GetBinContent(i, j);
            fMinMaxVal.first  = TMath::Min(fMinMaxVal.first, val);
            fMinMaxVal.second = TMath::Max(fMinMaxVal.second, val);
         }
      }

      fUpdateTexMap = kTRUE;
   }


   SetNormals();

   return kTRUE;
}

//______________________________________________________________________________
void TGLSurfacePainter::DrawProjections()const
{
   // Draw projections.

   const TGLDisableGuard lightGuard(GL_LIGHTING);
   const TGLEnableGuard  blendGuard(GL_BLEND);
   const TGLEnableGuard  lineSmooth(GL_LINE_SMOOTH);
   glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
   glDepthMask(GL_FALSE);
   glLineWidth(3.f);

   typedef std::list<Projection_t>::const_iterator CLI_t;
   for (CLI_t begin = fXOZProj.begin(), end = fXOZProj.end(); begin != end; ++begin) {
      const Projection_t &proj = *begin;
      glColor4ub(proj.fRGBA[0], proj.fRGBA[1], proj.fRGBA[2], proj.fRGBA[3]);

      for(UInt_t i = 0, e = proj.fVertices.size() / 3; i < e; ++i) {
         glBegin(GL_LINE_STRIP);
         glVertex3dv(proj.fVertices[i * 3].CArr());
         glVertex3dv(proj.fVertices[i * 3 + 1].CArr());
         glVertex3dv(proj.fVertices[i * 3 + 2].CArr());
         glEnd();
      }
      const Double_t y = fBackBox.GetFrontPoint() == 2 || fBackBox.GetFrontPoint() == 3 ? fBackBox.Get3DBox()[0].Y() : fBackBox.Get3DBox()[2].Y();
      for(UInt_t i = 0, e = proj.fVertices.size() / 3; i < e; ++i) {
         glBegin(GL_LINE_STRIP);
         const TGLVertex3 &v1 = proj.fVertices[i * 3];
         glVertex3d(v1.X(), y, v1.Z());
         const TGLVertex3 &v2 = proj.fVertices[i * 3 + 1];
         glVertex3d(v2.X(), y, v2.Z());
         const TGLVertex3 &v3 = proj.fVertices[i * 3 + 2];
         glVertex3d(v3.X(), y, v3.Z());
         glEnd();
      }
   }

   for (CLI_t begin = fYOZProj.begin(), end = fYOZProj.end(); begin != end; ++begin) {
      const Projection_t &proj = *begin;
      glColor4ub(proj.fRGBA[0], proj.fRGBA[1], proj.fRGBA[2], proj.fRGBA[3]);

      for(UInt_t i = 0, e = proj.fVertices.size() / 3; i < e; ++i) {
         glBegin(GL_LINE_STRIP);
         glVertex3dv(proj.fVertices[i * 3].CArr());
         glVertex3dv(proj.fVertices[i * 3 + 1].CArr());
         glVertex3dv(proj.fVertices[i * 3 + 2].CArr());
         glEnd();
      }

      const Double_t x = fBackBox.GetFrontPoint() == 2 || fBackBox.GetFrontPoint() == 1 ? fBackBox.Get3DBox()[0].X() : fBackBox.Get3DBox()[2].X();
      for(UInt_t i = 0, e = proj.fVertices.size() / 3; i < e; ++i) {
         glBegin(GL_LINE_STRIP);
         const TGLVertex3 &v1 = proj.fVertices[i * 3];
         glVertex3d(x, v1.Y(), v1.Z());
         const TGLVertex3 &v2 = proj.fVertices[i * 3 + 1];
         glVertex3d(x, v2.Y(), v2.Z());
         const TGLVertex3 &v3 = proj.fVertices[i * 3 + 2];
         glVertex3d(x, v3.Y(), v3.Z());
         glEnd();
      }
   }

   for (CLI_t begin = fXOYProj.begin(), end = fXOYProj.end(); begin != end; ++begin) {
      const Projection_t &proj = *begin;
      glColor4ub(proj.fRGBA[0], proj.fRGBA[1], proj.fRGBA[2], proj.fRGBA[3]);

      for(UInt_t i = 0, e = proj.fVertices.size() / 2; i < e; ++i) {
         glBegin(GL_LINES);
         glVertex3dv(proj.fVertices[i * 2].CArr());
         glVertex3dv(proj.fVertices[i * 2 + 1].CArr());
         glEnd();
      }


      for(UInt_t i = 0, e = proj.fVertices.size() / 2; i < e; ++i) {
         glBegin(GL_LINES);
         const TGLVertex3 &v1 = proj.fVertices[i * 2];
         glVertex3d(v1.X(), v1.Y(), fBackBox.Get3DBox()[0].Z());
         const TGLVertex3 &v2 = proj.fVertices[i * 2 + 1];
         glVertex3d(v2.X(), v2.Y(), fBackBox.Get3DBox()[0].Z());
         glEnd();
      }

   }

   glDepthMask(GL_TRUE);
   glLineWidth(1.f);
}

//______________________________________________________________________________
void TGLSurfacePainter::DrawSectionXOZ()const
{
   // Draw section X.

   using namespace std;
   //XOZ parallel section.
   Int_t binY = -1;
   for (Int_t j = 0, e = fCoord->GetNYBins() - 1; j < e; ++j) {
      if (fMesh[0][j].Y() <= fXOZSectionPos && fXOZSectionPos <= fMesh[0][j + 1].Y()) {
         binY = j;
         break;
      }
   }

   if (binY >= 0) {
      //Draw 2d curve on the profile's plane.
      const TGLPlane profilePlane(0., 1., 0., -fXOZSectionPos);

      if (!fSectionPass) {
         glColor3d(1., 0., 0.);
         glLineWidth(3.f);

         for (Int_t i = 0, e = fCoord->GetNXBins() - 1; i < e; ++i) {
            glBegin(GL_LINE_STRIP);
            glVertex3dv(Intersection(profilePlane, TGLLine3(fMesh[i + 1][binY], fMesh[i + 1][binY + 1]), kFALSE).second.CArr());
            glVertex3dv(Intersection(profilePlane, TGLLine3(fMesh[i + 1][binY], fMesh[i][binY + 1]), kFALSE).second.CArr());
            glVertex3dv(Intersection(profilePlane, TGLLine3(fMesh[i][binY], fMesh[i][binY + 1]), kFALSE).second.CArr());
            glEnd();
         }
         glLineWidth(1.f);
      } else {
         fProj.fVertices.clear();
         for (Int_t i = 0, e = fCoord->GetNXBins() - 1; i < e; ++i) {
            fProj.fVertices.push_back(Intersection(profilePlane, TGLLine3(fMesh[i + 1][binY], fMesh[i + 1][binY + 1]), kFALSE).second);
            fProj.fVertices.push_back(Intersection(profilePlane, TGLLine3(fMesh[i + 1][binY], fMesh[i][binY + 1]), kFALSE).second);
            fProj.fVertices.push_back(Intersection(profilePlane, TGLLine3(fMesh[i][binY], fMesh[i][binY + 1]), kFALSE).second);
         }
         if (fProj.fVertices.size()) {
            fProj.fRGBA[0] = (UChar_t) (50 + fgRandom->Integer(206));
            fProj.fRGBA[1] = (UChar_t) fgRandom->Integer(150);
            fProj.fRGBA[2] = (UChar_t) fgRandom->Integer(150);
            fProj.fRGBA[3] = 150;
            static Projection_t dummy;
            fXOZProj.push_back(dummy);
            fXOZProj.back().Swap(fProj);
         }
      }
   }
}

//______________________________________________________________________________
void TGLSurfacePainter::DrawSectionYOZ()const
{
   // Draw section Y.

   using namespace std;
   //YOZ parallel section.
   Int_t binX = -1;
   for (Int_t i = 0, e = fCoord->GetNXBins() - 1; i < e; ++i) {
      if (fMesh[i][0].X() <= fYOZSectionPos && fYOZSectionPos <= fMesh[i + 1][0].X()) {
         binX = i;
         break;
      }
   }

   if (binX >= 0) {
      //Draw 2d curve on the profile's plane.
      const TGLPlane profilePlane(1., 0., 0., -fYOZSectionPos);

      if (!fSectionPass) {
         glColor3d(1., 0., 0.);
         glLineWidth(3.f);
         for (Int_t j = 0, e = fCoord->GetNYBins() - 1; j < e; ++j) {
            glBegin(GL_LINE_STRIP);
            glVertex3dv(Intersection(profilePlane, TGLLine3(fMesh[binX][j + 1], fMesh[binX + 1][j + 1]), kFALSE).second.CArr());
            glVertex3dv(Intersection(profilePlane, TGLLine3(fMesh[binX][j + 1], fMesh[binX + 1][j]), kFALSE).second.CArr());
            glVertex3dv(Intersection(profilePlane, TGLLine3(fMesh[binX][j], fMesh[binX + 1][j]), kFALSE).second.CArr());
            glEnd();
         }
         glLineWidth(1.f);
      } else {
         fProj.fVertices.clear();
         for (Int_t j = 0, e = fCoord->GetNYBins() - 1; j < e; ++j) {
            fProj.fVertices.push_back(Intersection(profilePlane, TGLLine3(fMesh[binX][j + 1], fMesh[binX + 1][j + 1]), kFALSE).second);
            fProj.fVertices.push_back(Intersection(profilePlane, TGLLine3(fMesh[binX][j + 1], fMesh[binX + 1][j]), kFALSE).second);
            fProj.fVertices.push_back(Intersection(profilePlane, TGLLine3(fMesh[binX][j], fMesh[binX + 1][j]), kFALSE).second);
         }
         if (fProj.fVertices.size()) {
            fProj.fRGBA[0] = (UChar_t) (50 + fgRandom->Integer(206));
            fProj.fRGBA[1] = (UChar_t) fgRandom->Integer(150);
            fProj.fRGBA[2] = (UChar_t) fgRandom->Integer(150);
            fProj.fRGBA[3] = 150;
            static Projection_t dummy;
            fYOZProj.push_back(dummy);
            fYOZProj.back().Swap(fProj);
         }
      }

   }
}

//______________________________________________________________________________
void TGLSurfacePainter::DrawSectionXOY()const
{
   // Draw section Z.

   using namespace std;
   //XOY parallel section.
   const Int_t nX = fCoord->GetNXBins();
   const Int_t nY = fCoord->GetNYBins();
   const TGLPlane profilePlane(0., 0., 1., -fXOYSectionPos);
   TGLVertex3 intersection[2];


   if (fSectionPass)
      fProj.fVertices.clear();
   else {
      glColor3d(1., 0., 0.);
      glLineWidth(3.f);
   }

   for (Int_t i = 0; i < nX - 1; ++i) {
      for (Int_t j = 0; j < nY - 1; ++j) {
         const TGLVertex3 &v1 = fMesh[i + 1][j], &v2 = fMesh[i][j], &v3 = fMesh[i][j + 1], &v4 = fMesh[i + 1][j + 1];
         Double_t zMin = TMath::Min(TMath::Min(v1.Z(), v2.Z()), v3.Z());
         Double_t zMax = TMath::Max(TMath::Max(v1.Z(), v2.Z()), v3.Z());

         if (zMin < fXOYSectionPos && zMax > fXOYSectionPos) {
            Int_t np = 0;
            if ((v1.Z() > fXOYSectionPos && v2.Z() < fXOYSectionPos) || (v2.Z() > fXOYSectionPos && v1.Z() < fXOYSectionPos)) {
               TGLLine3 line(v1, v2);
               intersection[np++] = Intersection(profilePlane, line, kFALSE).second;
            }
            if ((v2.Z() > fXOYSectionPos && v3.Z() < fXOYSectionPos) || (v3.Z() > fXOYSectionPos && v2.Z() < fXOYSectionPos)) {
               TGLLine3 line(v2, v3);
               intersection[np++] = Intersection(profilePlane, line, kFALSE).second;
            }
            if ((np < 2 && v1.Z() > fXOYSectionPos && v3.Z() < fXOYSectionPos) || (v3.Z() > fXOYSectionPos && v1.Z() < fXOYSectionPos)) {
               TGLLine3 line(v1, v3);
               intersection[np++] = Intersection(profilePlane, line, kFALSE).second;
            }
            if (np > 1) {
               if (!fSectionPass) {
                  glBegin(GL_LINES);
                  glVertex3dv(intersection[0].CArr());
                  glVertex3dv(intersection[1].CArr());
                  glEnd();
               } else {
                  fProj.fVertices.push_back(intersection[0]);
                  fProj.fVertices.push_back(intersection[1]);
               }
            }
         }
         zMin = TMath::Min(v4.Z(), zMin);
         zMax = TMath::Max(v4.Z(), zMax);
         if (zMin < fXOYSectionPos && zMax > fXOYSectionPos) {
            Int_t np = 0;
            if ((v3.Z() > fXOYSectionPos && v4.Z() < fXOYSectionPos) || (v4.Z() > fXOYSectionPos && v3.Z() < fXOYSectionPos)) {
               TGLLine3 line(v3, v4);
               intersection[np++] = Intersection(profilePlane, line, kFALSE).second;
            }
            if ((v4.Z() > fXOYSectionPos && v1.Z() < fXOYSectionPos) || (v1.Z() > fXOYSectionPos && v4.Z() < fXOYSectionPos)) {
               TGLLine3 line(v4, v1);
               intersection[np++] = Intersection(profilePlane, line, kFALSE).second;
            }
            if ((np < 2 && v3.Z() > fXOYSectionPos && v1.Z() < fXOYSectionPos) || (v1.Z() > fXOYSectionPos && v3.Z() < fXOYSectionPos)) {
               TGLLine3 line(v3, v1);
               intersection[np++] = Intersection(profilePlane, line, kFALSE).second;
            }
            if (np > 1) {
               if (!fSectionPass) {
                  glBegin(GL_LINES);
                  glVertex3dv(intersection[0].CArr());
                  glVertex3dv(intersection[1].CArr());
                  glEnd();
               } else {
                  fProj.fVertices.push_back(intersection[0]);
                  fProj.fVertices.push_back(intersection[1]);
               }
            }
         }
      }
   }

   if (fSectionPass && fProj.fVertices.size()) {
      fProj.fRGBA[0] = (UChar_t) fgRandom->Integer(150);
      fProj.fRGBA[1] = (UChar_t) fgRandom->Integer(150);
      fProj.fRGBA[2] = (UChar_t) (50 + fgRandom->Integer(206));
      fProj.fRGBA[3] = 150;
      static Projection_t dummy;
      fXOYProj.push_back(dummy);
      fXOYProj.back().Swap(fProj);
   }

   if (!fSectionPass)
      glLineWidth(1.f);
}

//______________________________________________________________________________
void TGLSurfacePainter::ClampZ(Double_t &zVal)const
{
   //Clamp z value.
   const TGLVertex3 *frame = fBackBox.Get3DBox();

   if (fCoord->GetZLog())
      if (zVal <= 0.)
         zVal = frame[0].Z();
      else
         zVal = TMath::Log10(zVal) * fCoord->GetZScale();
   else
      zVal *= fCoord->GetZScale();

   if (zVal > frame[4].Z())
      zVal = frame[4].Z();
   else if (zVal < frame[0].Z())
      zVal = frame[0].Z();
}

//______________________________________________________________________________
char *TGLSurfacePainter::WindowPointTo3DPoint(Int_t px, Int_t py)const
{
   //Find 3d coords using mouse cursor coords.
/*   if (!MakeGLContextCurrent()) {
      static char err[] = { "Apocalipshit!" };
      return err;
   }*/

   py = fCamera->GetHeight() - py;

   const Int_t nY = fCoord->GetNYBins() - 1;
   Int_t selected = fSelectedPart - (fSelectionBase - 1);
   Int_t k = selected / 2;
   Int_t i = k / nY;
   Int_t j = k % nY;

   const Bool_t odd = selected & 1;
   const TGLVertex3 &v1 = odd ? fMesh[i][j + 1] : fMesh[i + 1][j];
   const TGLVertex3 &v2 = odd ? fMesh[i + 1][j + 1] : fMesh[i][j];
   const TGLVertex3 &v3 = odd ? fMesh[i + 1][j] : fMesh[i][j + 1];

   TGLVertex3 winV1, winV2, winV3;

   Double_t mvMatrix[16] = {0.};
   glGetDoublev(GL_MODELVIEW_MATRIX, mvMatrix);
   Double_t prMatrix[16] = {0.};
   glGetDoublev(GL_PROJECTION_MATRIX, prMatrix);
   Int_t viewport[4] = {0};
   glGetIntegerv(GL_VIEWPORT, viewport);

   gluProject(v1.X(), v1.Y(), v1.Z(), mvMatrix, prMatrix, viewport, &winV1.X(), &winV1.Y(), &winV1.Z());
   gluProject(v2.X(), v2.Y(), v2.Z(), mvMatrix, prMatrix, viewport, &winV2.X(), &winV2.Y(), &winV2.Z());
   gluProject(v3.X(), v3.Y(), v3.Z(), mvMatrix, prMatrix, viewport, &winV3.X(), &winV3.Y(), &winV3.Z());

   Double_t planeABCD[4] = {0.};
   TMath::Normal2Plane(winV1.CArr(), winV2.CArr(), winV3.CArr(), planeABCD);
   planeABCD[3] = - winV1.X() * planeABCD[0] - winV1.Y() * planeABCD[1] - winV1.Z() * planeABCD[2];
   Double_t pz = (-planeABCD[3] - planeABCD[0] * px - planeABCD[1] * py) / planeABCD[2];
   Double_t rez[3] = {0.};

   gluUnProject(px, py, pz, mvMatrix, prMatrix, viewport, rez, rez + 1, rez + 2);

   fObjectInfo.Form("(x == %f, y == %f, z == %f)",
                    rez[0] / fCoord->GetXScale(),
                    rez[1] / fCoord->GetYScale(),
                    rez[2] / fCoord->GetZScale());

   return (char *)fObjectInfo.Data();
}

//______________________________________________________________________________
Bool_t TGLSurfacePainter::PreparePalette()const
{
   //Generate palette.
   if (!fUpdateTexMap)
      return kTRUE;

   if(fMinMaxVal.first == fMinMaxVal.second)
      return kFALSE;//must be std::abs(fMinMaxVal.second - fMinMaxVal.first) < ...

   //User-defined contours are disabled. To be fixed.
   if (fHist->TestBit(TH1::kUserContour))
      fHist->ResetBit(TH1::kUserContour);

   UInt_t paletteSize = gStyle->GetNumberContours();
   if (!paletteSize)
      paletteSize = 20;

   Bool_t rez = fPalette.GeneratePalette(paletteSize, fMinMaxVal);

   if (rez && fUpdateTexMap) {
      GenTexMap();
      fUpdateTexMap = kFALSE;
   }

   return rez;
}

//______________________________________________________________________________
void TGLSurfacePainter::GenTexMap()const
{
   //Find texture coordinates.
   const Int_t nX = fCoord->GetNXBins();
   const Int_t nY = fCoord->GetNYBins();

   fTexMap.resize(nX * nY);
   fTexMap.SetRowLen(nY);

   for (Int_t i = 0, ir = fCoord->GetFirstXBin(); i < nX; ++i, ++ir) {
      for (Int_t j = 0, jr = fCoord->GetFirstYBin(); j < nY; ++j, ++jr) {
         Double_t z = fHist->GetBinContent(ir, jr);
         if (fCoord->GetCoordType() == kGLCartesian)
            ClampZ(z);
         fTexMap[i][j] = fPalette.GetTexCoord(z);
      }
   }
}

//______________________________________________________________________________
void TGLSurfacePainter::DrawContoursProjection()const
{
   //Draw flat textured surface.
   static const Float_t whiteDiffuse[] = {0.8f, 0.8f, 0.8f, 0.65f};
   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, whiteDiffuse);
   for (Int_t i = 0, ei = fCoord->GetNXBins() - 1; i < ei; ++i) {
      for (Int_t j = 0, ej = fCoord->GetNYBins() - 1; j < ej; ++j) {
         Rgl::DrawFaceTextured(fMesh[i][j + 1], fMesh[i][j], fMesh[i + 1][j],
                               fTexMap[i][j + 1], fTexMap[i][j], fTexMap[i + 1][j],
                               fBackBox.Get3DBox()[4].Z(), TGLVector3(0., 0., 1.));
         Rgl::DrawFaceTextured(fMesh[i + 1][j], fMesh[i + 1][j + 1], fMesh[i][j + 1],
                               fTexMap[i + 1][j], fTexMap[i + 1][j + 1], fTexMap[i][j + 1],
                               fBackBox.Get3DBox()[4].Z(), TGLVector3(0., 0., 1.));
      }
   }
}

//______________________________________________________________________________
Bool_t TGLSurfacePainter::Textured()const
{
   //Checks, if surf requires texture.
   switch (fType) {
   case kSurf1:
   case kSurf2:
   case kSurf3:
   case kSurf5:
      return kTRUE;
   default:;
   }

   return kFALSE;
}

//______________________________________________________________________________
Bool_t TGLSurfacePainter::HasSections()const
{
   //Any section exists.
   return fXOZSectionPos > fBackBox.Get3DBox()[0].Y() || fYOZSectionPos > fBackBox.Get3DBox()[0].X() ||
          fXOYSectionPos > fBackBox.Get3DBox()[0].Z();
}

//______________________________________________________________________________
Bool_t TGLSurfacePainter::HasProjections()const
{
   //Any projection exists.
   return fXOZProj.size() || fYOZProj.size() || fXOYProj.size();
}

//______________________________________________________________________________
void TGLSurfacePainter::DrawPalette()const
{
   //Draw. Palette.
   //Originally, fCamera was never null.
   //It can be a null now because of gl-viewer.
   if (!fCamera) {
      //Thank you, gl-viewer!
      return;
   }

   Rgl::DrawPalette(fCamera, fPalette);

   glFinish();

   fCamera->SetCamera();
   fCamera->Apply(fPadPhi, fPadTheta);
}

//______________________________________________________________________________
void TGLSurfacePainter::DrawPaletteAxis()const
{
   //Draw. Palette. Axis.
   gVirtualX->SetDrawMode(TVirtualX::kCopy);//TCanvas by default sets in kInverse
   Rgl::DrawPaletteAxis(fCamera, fMinMaxVal, fCoord->GetCoordType() == kGLCartesian ? fCoord->GetZLog() : kFALSE);
}
 TGLSurfacePainter.cxx:1
 TGLSurfacePainter.cxx:2
 TGLSurfacePainter.cxx:3
 TGLSurfacePainter.cxx:4
 TGLSurfacePainter.cxx:5
 TGLSurfacePainter.cxx:6
 TGLSurfacePainter.cxx:7
 TGLSurfacePainter.cxx:8
 TGLSurfacePainter.cxx:9
 TGLSurfacePainter.cxx:10
 TGLSurfacePainter.cxx:11
 TGLSurfacePainter.cxx:12
 TGLSurfacePainter.cxx:13
 TGLSurfacePainter.cxx:14
 TGLSurfacePainter.cxx:15
 TGLSurfacePainter.cxx:16
 TGLSurfacePainter.cxx:17
 TGLSurfacePainter.cxx:18
 TGLSurfacePainter.cxx:19
 TGLSurfacePainter.cxx:20
 TGLSurfacePainter.cxx:21
 TGLSurfacePainter.cxx:22
 TGLSurfacePainter.cxx:23
 TGLSurfacePainter.cxx:24
 TGLSurfacePainter.cxx:25
 TGLSurfacePainter.cxx:26
 TGLSurfacePainter.cxx:27
 TGLSurfacePainter.cxx:28
 TGLSurfacePainter.cxx:29
 TGLSurfacePainter.cxx:30
 TGLSurfacePainter.cxx:31
 TGLSurfacePainter.cxx:32
 TGLSurfacePainter.cxx:33
 TGLSurfacePainter.cxx:34
 TGLSurfacePainter.cxx:35
 TGLSurfacePainter.cxx:36
 TGLSurfacePainter.cxx:37
 TGLSurfacePainter.cxx:38
 TGLSurfacePainter.cxx:39
 TGLSurfacePainter.cxx:40
 TGLSurfacePainter.cxx:41
 TGLSurfacePainter.cxx:42
 TGLSurfacePainter.cxx:43
 TGLSurfacePainter.cxx:44
 TGLSurfacePainter.cxx:45
 TGLSurfacePainter.cxx:46
 TGLSurfacePainter.cxx:47
 TGLSurfacePainter.cxx:48
 TGLSurfacePainter.cxx:49
 TGLSurfacePainter.cxx:50
 TGLSurfacePainter.cxx:51
 TGLSurfacePainter.cxx:52
 TGLSurfacePainter.cxx:53
 TGLSurfacePainter.cxx:54
 TGLSurfacePainter.cxx:55
 TGLSurfacePainter.cxx:56
 TGLSurfacePainter.cxx:57
 TGLSurfacePainter.cxx:58
 TGLSurfacePainter.cxx:59
 TGLSurfacePainter.cxx:60
 TGLSurfacePainter.cxx:61
 TGLSurfacePainter.cxx:62
 TGLSurfacePainter.cxx:63
 TGLSurfacePainter.cxx:64
 TGLSurfacePainter.cxx:65
 TGLSurfacePainter.cxx:66
 TGLSurfacePainter.cxx:67
 TGLSurfacePainter.cxx:68
 TGLSurfacePainter.cxx:69
 TGLSurfacePainter.cxx:70
 TGLSurfacePainter.cxx:71
 TGLSurfacePainter.cxx:72
 TGLSurfacePainter.cxx:73
 TGLSurfacePainter.cxx:74
 TGLSurfacePainter.cxx:75
 TGLSurfacePainter.cxx:76
 TGLSurfacePainter.cxx:77
 TGLSurfacePainter.cxx:78
 TGLSurfacePainter.cxx:79
 TGLSurfacePainter.cxx:80
 TGLSurfacePainter.cxx:81
 TGLSurfacePainter.cxx:82
 TGLSurfacePainter.cxx:83
 TGLSurfacePainter.cxx:84
 TGLSurfacePainter.cxx:85
 TGLSurfacePainter.cxx:86
 TGLSurfacePainter.cxx:87
 TGLSurfacePainter.cxx:88
 TGLSurfacePainter.cxx:89
 TGLSurfacePainter.cxx:90
 TGLSurfacePainter.cxx:91
 TGLSurfacePainter.cxx:92
 TGLSurfacePainter.cxx:93
 TGLSurfacePainter.cxx:94
 TGLSurfacePainter.cxx:95
 TGLSurfacePainter.cxx:96
 TGLSurfacePainter.cxx:97
 TGLSurfacePainter.cxx:98
 TGLSurfacePainter.cxx:99
 TGLSurfacePainter.cxx:100
 TGLSurfacePainter.cxx:101
 TGLSurfacePainter.cxx:102
 TGLSurfacePainter.cxx:103
 TGLSurfacePainter.cxx:104
 TGLSurfacePainter.cxx:105
 TGLSurfacePainter.cxx:106
 TGLSurfacePainter.cxx:107
 TGLSurfacePainter.cxx:108
 TGLSurfacePainter.cxx:109
 TGLSurfacePainter.cxx:110
 TGLSurfacePainter.cxx:111
 TGLSurfacePainter.cxx:112
 TGLSurfacePainter.cxx:113
 TGLSurfacePainter.cxx:114
 TGLSurfacePainter.cxx:115
 TGLSurfacePainter.cxx:116
 TGLSurfacePainter.cxx:117
 TGLSurfacePainter.cxx:118
 TGLSurfacePainter.cxx:119
 TGLSurfacePainter.cxx:120
 TGLSurfacePainter.cxx:121
 TGLSurfacePainter.cxx:122
 TGLSurfacePainter.cxx:123
 TGLSurfacePainter.cxx:124
 TGLSurfacePainter.cxx:125
 TGLSurfacePainter.cxx:126
 TGLSurfacePainter.cxx:127
 TGLSurfacePainter.cxx:128
 TGLSurfacePainter.cxx:129
 TGLSurfacePainter.cxx:130
 TGLSurfacePainter.cxx:131
 TGLSurfacePainter.cxx:132
 TGLSurfacePainter.cxx:133
 TGLSurfacePainter.cxx:134
 TGLSurfacePainter.cxx:135
 TGLSurfacePainter.cxx:136
 TGLSurfacePainter.cxx:137
 TGLSurfacePainter.cxx:138
 TGLSurfacePainter.cxx:139
 TGLSurfacePainter.cxx:140
 TGLSurfacePainter.cxx:141
 TGLSurfacePainter.cxx:142
 TGLSurfacePainter.cxx:143
 TGLSurfacePainter.cxx:144
 TGLSurfacePainter.cxx:145
 TGLSurfacePainter.cxx:146
 TGLSurfacePainter.cxx:147
 TGLSurfacePainter.cxx:148
 TGLSurfacePainter.cxx:149
 TGLSurfacePainter.cxx:150
 TGLSurfacePainter.cxx:151
 TGLSurfacePainter.cxx:152
 TGLSurfacePainter.cxx:153
 TGLSurfacePainter.cxx:154
 TGLSurfacePainter.cxx:155
 TGLSurfacePainter.cxx:156
 TGLSurfacePainter.cxx:157
 TGLSurfacePainter.cxx:158
 TGLSurfacePainter.cxx:159
 TGLSurfacePainter.cxx:160
 TGLSurfacePainter.cxx:161
 TGLSurfacePainter.cxx:162
 TGLSurfacePainter.cxx:163
 TGLSurfacePainter.cxx:164
 TGLSurfacePainter.cxx:165
 TGLSurfacePainter.cxx:166
 TGLSurfacePainter.cxx:167
 TGLSurfacePainter.cxx:168
 TGLSurfacePainter.cxx:169
 TGLSurfacePainter.cxx:170
 TGLSurfacePainter.cxx:171
 TGLSurfacePainter.cxx:172
 TGLSurfacePainter.cxx:173
 TGLSurfacePainter.cxx:174
 TGLSurfacePainter.cxx:175
 TGLSurfacePainter.cxx:176
 TGLSurfacePainter.cxx:177
 TGLSurfacePainter.cxx:178
 TGLSurfacePainter.cxx:179
 TGLSurfacePainter.cxx:180
 TGLSurfacePainter.cxx:181
 TGLSurfacePainter.cxx:182
 TGLSurfacePainter.cxx:183
 TGLSurfacePainter.cxx:184
 TGLSurfacePainter.cxx:185
 TGLSurfacePainter.cxx:186
 TGLSurfacePainter.cxx:187
 TGLSurfacePainter.cxx:188
 TGLSurfacePainter.cxx:189
 TGLSurfacePainter.cxx:190
 TGLSurfacePainter.cxx:191
 TGLSurfacePainter.cxx:192
 TGLSurfacePainter.cxx:193
 TGLSurfacePainter.cxx:194
 TGLSurfacePainter.cxx:195
 TGLSurfacePainter.cxx:196
 TGLSurfacePainter.cxx:197
 TGLSurfacePainter.cxx:198
 TGLSurfacePainter.cxx:199
 TGLSurfacePainter.cxx:200
 TGLSurfacePainter.cxx:201
 TGLSurfacePainter.cxx:202
 TGLSurfacePainter.cxx:203
 TGLSurfacePainter.cxx:204
 TGLSurfacePainter.cxx:205
 TGLSurfacePainter.cxx:206
 TGLSurfacePainter.cxx:207
 TGLSurfacePainter.cxx:208
 TGLSurfacePainter.cxx:209
 TGLSurfacePainter.cxx:210
 TGLSurfacePainter.cxx:211
 TGLSurfacePainter.cxx:212
 TGLSurfacePainter.cxx:213
 TGLSurfacePainter.cxx:214
 TGLSurfacePainter.cxx:215
 TGLSurfacePainter.cxx:216
 TGLSurfacePainter.cxx:217
 TGLSurfacePainter.cxx:218
 TGLSurfacePainter.cxx:219
 TGLSurfacePainter.cxx:220
 TGLSurfacePainter.cxx:221
 TGLSurfacePainter.cxx:222
 TGLSurfacePainter.cxx:223
 TGLSurfacePainter.cxx:224
 TGLSurfacePainter.cxx:225
 TGLSurfacePainter.cxx:226
 TGLSurfacePainter.cxx:227
 TGLSurfacePainter.cxx:228
 TGLSurfacePainter.cxx:229
 TGLSurfacePainter.cxx:230
 TGLSurfacePainter.cxx:231
 TGLSurfacePainter.cxx:232
 TGLSurfacePainter.cxx:233
 TGLSurfacePainter.cxx:234
 TGLSurfacePainter.cxx:235
 TGLSurfacePainter.cxx:236
 TGLSurfacePainter.cxx:237
 TGLSurfacePainter.cxx:238
 TGLSurfacePainter.cxx:239
 TGLSurfacePainter.cxx:240
 TGLSurfacePainter.cxx:241
 TGLSurfacePainter.cxx:242
 TGLSurfacePainter.cxx:243
 TGLSurfacePainter.cxx:244
 TGLSurfacePainter.cxx:245
 TGLSurfacePainter.cxx:246
 TGLSurfacePainter.cxx:247
 TGLSurfacePainter.cxx:248
 TGLSurfacePainter.cxx:249
 TGLSurfacePainter.cxx:250
 TGLSurfacePainter.cxx:251
 TGLSurfacePainter.cxx:252
 TGLSurfacePainter.cxx:253
 TGLSurfacePainter.cxx:254
 TGLSurfacePainter.cxx:255
 TGLSurfacePainter.cxx:256
 TGLSurfacePainter.cxx:257
 TGLSurfacePainter.cxx:258
 TGLSurfacePainter.cxx:259
 TGLSurfacePainter.cxx:260
 TGLSurfacePainter.cxx:261
 TGLSurfacePainter.cxx:262
 TGLSurfacePainter.cxx:263
 TGLSurfacePainter.cxx:264
 TGLSurfacePainter.cxx:265
 TGLSurfacePainter.cxx:266
 TGLSurfacePainter.cxx:267
 TGLSurfacePainter.cxx:268
 TGLSurfacePainter.cxx:269
 TGLSurfacePainter.cxx:270
 TGLSurfacePainter.cxx:271
 TGLSurfacePainter.cxx:272
 TGLSurfacePainter.cxx:273
 TGLSurfacePainter.cxx:274
 TGLSurfacePainter.cxx:275
 TGLSurfacePainter.cxx:276
 TGLSurfacePainter.cxx:277
 TGLSurfacePainter.cxx:278
 TGLSurfacePainter.cxx:279
 TGLSurfacePainter.cxx:280
 TGLSurfacePainter.cxx:281
 TGLSurfacePainter.cxx:282
 TGLSurfacePainter.cxx:283
 TGLSurfacePainter.cxx:284
 TGLSurfacePainter.cxx:285
 TGLSurfacePainter.cxx:286
 TGLSurfacePainter.cxx:287
 TGLSurfacePainter.cxx:288
 TGLSurfacePainter.cxx:289
 TGLSurfacePainter.cxx:290
 TGLSurfacePainter.cxx:291
 TGLSurfacePainter.cxx:292
 TGLSurfacePainter.cxx:293
 TGLSurfacePainter.cxx:294
 TGLSurfacePainter.cxx:295
 TGLSurfacePainter.cxx:296
 TGLSurfacePainter.cxx:297
 TGLSurfacePainter.cxx:298
 TGLSurfacePainter.cxx:299
 TGLSurfacePainter.cxx:300
 TGLSurfacePainter.cxx:301
 TGLSurfacePainter.cxx:302
 TGLSurfacePainter.cxx:303
 TGLSurfacePainter.cxx:304
 TGLSurfacePainter.cxx:305
 TGLSurfacePainter.cxx:306
 TGLSurfacePainter.cxx:307
 TGLSurfacePainter.cxx:308
 TGLSurfacePainter.cxx:309
 TGLSurfacePainter.cxx:310
 TGLSurfacePainter.cxx:311
 TGLSurfacePainter.cxx:312
 TGLSurfacePainter.cxx:313
 TGLSurfacePainter.cxx:314
 TGLSurfacePainter.cxx:315
 TGLSurfacePainter.cxx:316
 TGLSurfacePainter.cxx:317
 TGLSurfacePainter.cxx:318
 TGLSurfacePainter.cxx:319
 TGLSurfacePainter.cxx:320
 TGLSurfacePainter.cxx:321
 TGLSurfacePainter.cxx:322
 TGLSurfacePainter.cxx:323
 TGLSurfacePainter.cxx:324
 TGLSurfacePainter.cxx:325
 TGLSurfacePainter.cxx:326
 TGLSurfacePainter.cxx:327
 TGLSurfacePainter.cxx:328
 TGLSurfacePainter.cxx:329
 TGLSurfacePainter.cxx:330
 TGLSurfacePainter.cxx:331
 TGLSurfacePainter.cxx:332
 TGLSurfacePainter.cxx:333
 TGLSurfacePainter.cxx:334
 TGLSurfacePainter.cxx:335
 TGLSurfacePainter.cxx:336
 TGLSurfacePainter.cxx:337
 TGLSurfacePainter.cxx:338
 TGLSurfacePainter.cxx:339
 TGLSurfacePainter.cxx:340
 TGLSurfacePainter.cxx:341
 TGLSurfacePainter.cxx:342
 TGLSurfacePainter.cxx:343
 TGLSurfacePainter.cxx:344
 TGLSurfacePainter.cxx:345
 TGLSurfacePainter.cxx:346
 TGLSurfacePainter.cxx:347
 TGLSurfacePainter.cxx:348
 TGLSurfacePainter.cxx:349
 TGLSurfacePainter.cxx:350
 TGLSurfacePainter.cxx:351
 TGLSurfacePainter.cxx:352
 TGLSurfacePainter.cxx:353
 TGLSurfacePainter.cxx:354
 TGLSurfacePainter.cxx:355
 TGLSurfacePainter.cxx:356
 TGLSurfacePainter.cxx:357
 TGLSurfacePainter.cxx:358
 TGLSurfacePainter.cxx:359
 TGLSurfacePainter.cxx:360
 TGLSurfacePainter.cxx:361
 TGLSurfacePainter.cxx:362
 TGLSurfacePainter.cxx:363
 TGLSurfacePainter.cxx:364
 TGLSurfacePainter.cxx:365
 TGLSurfacePainter.cxx:366
 TGLSurfacePainter.cxx:367
 TGLSurfacePainter.cxx:368
 TGLSurfacePainter.cxx:369
 TGLSurfacePainter.cxx:370
 TGLSurfacePainter.cxx:371
 TGLSurfacePainter.cxx:372
 TGLSurfacePainter.cxx:373
 TGLSurfacePainter.cxx:374
 TGLSurfacePainter.cxx:375
 TGLSurfacePainter.cxx:376
 TGLSurfacePainter.cxx:377
 TGLSurfacePainter.cxx:378
 TGLSurfacePainter.cxx:379
 TGLSurfacePainter.cxx:380
 TGLSurfacePainter.cxx:381
 TGLSurfacePainter.cxx:382
 TGLSurfacePainter.cxx:383
 TGLSurfacePainter.cxx:384
 TGLSurfacePainter.cxx:385
 TGLSurfacePainter.cxx:386
 TGLSurfacePainter.cxx:387
 TGLSurfacePainter.cxx:388
 TGLSurfacePainter.cxx:389
 TGLSurfacePainter.cxx:390
 TGLSurfacePainter.cxx:391
 TGLSurfacePainter.cxx:392
 TGLSurfacePainter.cxx:393
 TGLSurfacePainter.cxx:394
 TGLSurfacePainter.cxx:395
 TGLSurfacePainter.cxx:396
 TGLSurfacePainter.cxx:397
 TGLSurfacePainter.cxx:398
 TGLSurfacePainter.cxx:399
 TGLSurfacePainter.cxx:400
 TGLSurfacePainter.cxx:401
 TGLSurfacePainter.cxx:402
 TGLSurfacePainter.cxx:403
 TGLSurfacePainter.cxx:404
 TGLSurfacePainter.cxx:405
 TGLSurfacePainter.cxx:406
 TGLSurfacePainter.cxx:407
 TGLSurfacePainter.cxx:408
 TGLSurfacePainter.cxx:409
 TGLSurfacePainter.cxx:410
 TGLSurfacePainter.cxx:411
 TGLSurfacePainter.cxx:412
 TGLSurfacePainter.cxx:413
 TGLSurfacePainter.cxx:414
 TGLSurfacePainter.cxx:415
 TGLSurfacePainter.cxx:416
 TGLSurfacePainter.cxx:417
 TGLSurfacePainter.cxx:418
 TGLSurfacePainter.cxx:419
 TGLSurfacePainter.cxx:420
 TGLSurfacePainter.cxx:421
 TGLSurfacePainter.cxx:422
 TGLSurfacePainter.cxx:423
 TGLSurfacePainter.cxx:424
 TGLSurfacePainter.cxx:425
 TGLSurfacePainter.cxx:426
 TGLSurfacePainter.cxx:427
 TGLSurfacePainter.cxx:428
 TGLSurfacePainter.cxx:429
 TGLSurfacePainter.cxx:430
 TGLSurfacePainter.cxx:431
 TGLSurfacePainter.cxx:432
 TGLSurfacePainter.cxx:433
 TGLSurfacePainter.cxx:434
 TGLSurfacePainter.cxx:435
 TGLSurfacePainter.cxx:436
 TGLSurfacePainter.cxx:437
 TGLSurfacePainter.cxx:438
 TGLSurfacePainter.cxx:439
 TGLSurfacePainter.cxx:440
 TGLSurfacePainter.cxx:441
 TGLSurfacePainter.cxx:442
 TGLSurfacePainter.cxx:443
 TGLSurfacePainter.cxx:444
 TGLSurfacePainter.cxx:445
 TGLSurfacePainter.cxx:446
 TGLSurfacePainter.cxx:447
 TGLSurfacePainter.cxx:448
 TGLSurfacePainter.cxx:449
 TGLSurfacePainter.cxx:450
 TGLSurfacePainter.cxx:451
 TGLSurfacePainter.cxx:452
 TGLSurfacePainter.cxx:453
 TGLSurfacePainter.cxx:454
 TGLSurfacePainter.cxx:455
 TGLSurfacePainter.cxx:456
 TGLSurfacePainter.cxx:457
 TGLSurfacePainter.cxx:458
 TGLSurfacePainter.cxx:459
 TGLSurfacePainter.cxx:460
 TGLSurfacePainter.cxx:461
 TGLSurfacePainter.cxx:462
 TGLSurfacePainter.cxx:463
 TGLSurfacePainter.cxx:464
 TGLSurfacePainter.cxx:465
 TGLSurfacePainter.cxx:466
 TGLSurfacePainter.cxx:467
 TGLSurfacePainter.cxx:468
 TGLSurfacePainter.cxx:469
 TGLSurfacePainter.cxx:470
 TGLSurfacePainter.cxx:471
 TGLSurfacePainter.cxx:472
 TGLSurfacePainter.cxx:473
 TGLSurfacePainter.cxx:474
 TGLSurfacePainter.cxx:475
 TGLSurfacePainter.cxx:476
 TGLSurfacePainter.cxx:477
 TGLSurfacePainter.cxx:478
 TGLSurfacePainter.cxx:479
 TGLSurfacePainter.cxx:480
 TGLSurfacePainter.cxx:481
 TGLSurfacePainter.cxx:482
 TGLSurfacePainter.cxx:483
 TGLSurfacePainter.cxx:484
 TGLSurfacePainter.cxx:485
 TGLSurfacePainter.cxx:486
 TGLSurfacePainter.cxx:487
 TGLSurfacePainter.cxx:488
 TGLSurfacePainter.cxx:489
 TGLSurfacePainter.cxx:490
 TGLSurfacePainter.cxx:491
 TGLSurfacePainter.cxx:492
 TGLSurfacePainter.cxx:493
 TGLSurfacePainter.cxx:494
 TGLSurfacePainter.cxx:495
 TGLSurfacePainter.cxx:496
 TGLSurfacePainter.cxx:497
 TGLSurfacePainter.cxx:498
 TGLSurfacePainter.cxx:499
 TGLSurfacePainter.cxx:500
 TGLSurfacePainter.cxx:501
 TGLSurfacePainter.cxx:502
 TGLSurfacePainter.cxx:503
 TGLSurfacePainter.cxx:504
 TGLSurfacePainter.cxx:505
 TGLSurfacePainter.cxx:506
 TGLSurfacePainter.cxx:507
 TGLSurfacePainter.cxx:508
 TGLSurfacePainter.cxx:509
 TGLSurfacePainter.cxx:510
 TGLSurfacePainter.cxx:511
 TGLSurfacePainter.cxx:512
 TGLSurfacePainter.cxx:513
 TGLSurfacePainter.cxx:514
 TGLSurfacePainter.cxx:515
 TGLSurfacePainter.cxx:516
 TGLSurfacePainter.cxx:517
 TGLSurfacePainter.cxx:518
 TGLSurfacePainter.cxx:519
 TGLSurfacePainter.cxx:520
 TGLSurfacePainter.cxx:521
 TGLSurfacePainter.cxx:522
 TGLSurfacePainter.cxx:523
 TGLSurfacePainter.cxx:524
 TGLSurfacePainter.cxx:525
 TGLSurfacePainter.cxx:526
 TGLSurfacePainter.cxx:527
 TGLSurfacePainter.cxx:528
 TGLSurfacePainter.cxx:529
 TGLSurfacePainter.cxx:530
 TGLSurfacePainter.cxx:531
 TGLSurfacePainter.cxx:532
 TGLSurfacePainter.cxx:533
 TGLSurfacePainter.cxx:534
 TGLSurfacePainter.cxx:535
 TGLSurfacePainter.cxx:536
 TGLSurfacePainter.cxx:537
 TGLSurfacePainter.cxx:538
 TGLSurfacePainter.cxx:539
 TGLSurfacePainter.cxx:540
 TGLSurfacePainter.cxx:541
 TGLSurfacePainter.cxx:542
 TGLSurfacePainter.cxx:543
 TGLSurfacePainter.cxx:544
 TGLSurfacePainter.cxx:545
 TGLSurfacePainter.cxx:546
 TGLSurfacePainter.cxx:547
 TGLSurfacePainter.cxx:548
 TGLSurfacePainter.cxx:549
 TGLSurfacePainter.cxx:550
 TGLSurfacePainter.cxx:551
 TGLSurfacePainter.cxx:552
 TGLSurfacePainter.cxx:553
 TGLSurfacePainter.cxx:554
 TGLSurfacePainter.cxx:555
 TGLSurfacePainter.cxx:556
 TGLSurfacePainter.cxx:557
 TGLSurfacePainter.cxx:558
 TGLSurfacePainter.cxx:559
 TGLSurfacePainter.cxx:560
 TGLSurfacePainter.cxx:561
 TGLSurfacePainter.cxx:562
 TGLSurfacePainter.cxx:563
 TGLSurfacePainter.cxx:564
 TGLSurfacePainter.cxx:565
 TGLSurfacePainter.cxx:566
 TGLSurfacePainter.cxx:567
 TGLSurfacePainter.cxx:568
 TGLSurfacePainter.cxx:569
 TGLSurfacePainter.cxx:570
 TGLSurfacePainter.cxx:571
 TGLSurfacePainter.cxx:572
 TGLSurfacePainter.cxx:573
 TGLSurfacePainter.cxx:574
 TGLSurfacePainter.cxx:575
 TGLSurfacePainter.cxx:576
 TGLSurfacePainter.cxx:577
 TGLSurfacePainter.cxx:578
 TGLSurfacePainter.cxx:579
 TGLSurfacePainter.cxx:580
 TGLSurfacePainter.cxx:581
 TGLSurfacePainter.cxx:582
 TGLSurfacePainter.cxx:583
 TGLSurfacePainter.cxx:584
 TGLSurfacePainter.cxx:585
 TGLSurfacePainter.cxx:586
 TGLSurfacePainter.cxx:587
 TGLSurfacePainter.cxx:588
 TGLSurfacePainter.cxx:589
 TGLSurfacePainter.cxx:590
 TGLSurfacePainter.cxx:591
 TGLSurfacePainter.cxx:592
 TGLSurfacePainter.cxx:593
 TGLSurfacePainter.cxx:594
 TGLSurfacePainter.cxx:595
 TGLSurfacePainter.cxx:596
 TGLSurfacePainter.cxx:597
 TGLSurfacePainter.cxx:598
 TGLSurfacePainter.cxx:599
 TGLSurfacePainter.cxx:600
 TGLSurfacePainter.cxx:601
 TGLSurfacePainter.cxx:602
 TGLSurfacePainter.cxx:603
 TGLSurfacePainter.cxx:604
 TGLSurfacePainter.cxx:605
 TGLSurfacePainter.cxx:606
 TGLSurfacePainter.cxx:607
 TGLSurfacePainter.cxx:608
 TGLSurfacePainter.cxx:609
 TGLSurfacePainter.cxx:610
 TGLSurfacePainter.cxx:611
 TGLSurfacePainter.cxx:612
 TGLSurfacePainter.cxx:613
 TGLSurfacePainter.cxx:614
 TGLSurfacePainter.cxx:615
 TGLSurfacePainter.cxx:616
 TGLSurfacePainter.cxx:617
 TGLSurfacePainter.cxx:618
 TGLSurfacePainter.cxx:619
 TGLSurfacePainter.cxx:620
 TGLSurfacePainter.cxx:621
 TGLSurfacePainter.cxx:622
 TGLSurfacePainter.cxx:623
 TGLSurfacePainter.cxx:624
 TGLSurfacePainter.cxx:625
 TGLSurfacePainter.cxx:626
 TGLSurfacePainter.cxx:627
 TGLSurfacePainter.cxx:628
 TGLSurfacePainter.cxx:629
 TGLSurfacePainter.cxx:630
 TGLSurfacePainter.cxx:631
 TGLSurfacePainter.cxx:632
 TGLSurfacePainter.cxx:633
 TGLSurfacePainter.cxx:634
 TGLSurfacePainter.cxx:635
 TGLSurfacePainter.cxx:636
 TGLSurfacePainter.cxx:637
 TGLSurfacePainter.cxx:638
 TGLSurfacePainter.cxx:639
 TGLSurfacePainter.cxx:640
 TGLSurfacePainter.cxx:641
 TGLSurfacePainter.cxx:642
 TGLSurfacePainter.cxx:643
 TGLSurfacePainter.cxx:644
 TGLSurfacePainter.cxx:645
 TGLSurfacePainter.cxx:646
 TGLSurfacePainter.cxx:647
 TGLSurfacePainter.cxx:648
 TGLSurfacePainter.cxx:649
 TGLSurfacePainter.cxx:650
 TGLSurfacePainter.cxx:651
 TGLSurfacePainter.cxx:652
 TGLSurfacePainter.cxx:653
 TGLSurfacePainter.cxx:654
 TGLSurfacePainter.cxx:655
 TGLSurfacePainter.cxx:656
 TGLSurfacePainter.cxx:657
 TGLSurfacePainter.cxx:658
 TGLSurfacePainter.cxx:659
 TGLSurfacePainter.cxx:660
 TGLSurfacePainter.cxx:661
 TGLSurfacePainter.cxx:662
 TGLSurfacePainter.cxx:663
 TGLSurfacePainter.cxx:664
 TGLSurfacePainter.cxx:665
 TGLSurfacePainter.cxx:666
 TGLSurfacePainter.cxx:667
 TGLSurfacePainter.cxx:668
 TGLSurfacePainter.cxx:669
 TGLSurfacePainter.cxx:670
 TGLSurfacePainter.cxx:671
 TGLSurfacePainter.cxx:672
 TGLSurfacePainter.cxx:673
 TGLSurfacePainter.cxx:674
 TGLSurfacePainter.cxx:675
 TGLSurfacePainter.cxx:676
 TGLSurfacePainter.cxx:677
 TGLSurfacePainter.cxx:678
 TGLSurfacePainter.cxx:679
 TGLSurfacePainter.cxx:680
 TGLSurfacePainter.cxx:681
 TGLSurfacePainter.cxx:682
 TGLSurfacePainter.cxx:683
 TGLSurfacePainter.cxx:684
 TGLSurfacePainter.cxx:685
 TGLSurfacePainter.cxx:686
 TGLSurfacePainter.cxx:687
 TGLSurfacePainter.cxx:688
 TGLSurfacePainter.cxx:689
 TGLSurfacePainter.cxx:690
 TGLSurfacePainter.cxx:691
 TGLSurfacePainter.cxx:692
 TGLSurfacePainter.cxx:693
 TGLSurfacePainter.cxx:694
 TGLSurfacePainter.cxx:695
 TGLSurfacePainter.cxx:696
 TGLSurfacePainter.cxx:697
 TGLSurfacePainter.cxx:698
 TGLSurfacePainter.cxx:699
 TGLSurfacePainter.cxx:700
 TGLSurfacePainter.cxx:701
 TGLSurfacePainter.cxx:702
 TGLSurfacePainter.cxx:703
 TGLSurfacePainter.cxx:704
 TGLSurfacePainter.cxx:705
 TGLSurfacePainter.cxx:706
 TGLSurfacePainter.cxx:707
 TGLSurfacePainter.cxx:708
 TGLSurfacePainter.cxx:709
 TGLSurfacePainter.cxx:710
 TGLSurfacePainter.cxx:711
 TGLSurfacePainter.cxx:712
 TGLSurfacePainter.cxx:713
 TGLSurfacePainter.cxx:714
 TGLSurfacePainter.cxx:715
 TGLSurfacePainter.cxx:716
 TGLSurfacePainter.cxx:717
 TGLSurfacePainter.cxx:718
 TGLSurfacePainter.cxx:719
 TGLSurfacePainter.cxx:720
 TGLSurfacePainter.cxx:721
 TGLSurfacePainter.cxx:722
 TGLSurfacePainter.cxx:723
 TGLSurfacePainter.cxx:724
 TGLSurfacePainter.cxx:725
 TGLSurfacePainter.cxx:726
 TGLSurfacePainter.cxx:727
 TGLSurfacePainter.cxx:728
 TGLSurfacePainter.cxx:729
 TGLSurfacePainter.cxx:730
 TGLSurfacePainter.cxx:731
 TGLSurfacePainter.cxx:732
 TGLSurfacePainter.cxx:733
 TGLSurfacePainter.cxx:734
 TGLSurfacePainter.cxx:735
 TGLSurfacePainter.cxx:736
 TGLSurfacePainter.cxx:737
 TGLSurfacePainter.cxx:738
 TGLSurfacePainter.cxx:739
 TGLSurfacePainter.cxx:740
 TGLSurfacePainter.cxx:741
 TGLSurfacePainter.cxx:742
 TGLSurfacePainter.cxx:743
 TGLSurfacePainter.cxx:744
 TGLSurfacePainter.cxx:745
 TGLSurfacePainter.cxx:746
 TGLSurfacePainter.cxx:747
 TGLSurfacePainter.cxx:748
 TGLSurfacePainter.cxx:749
 TGLSurfacePainter.cxx:750
 TGLSurfacePainter.cxx:751
 TGLSurfacePainter.cxx:752
 TGLSurfacePainter.cxx:753
 TGLSurfacePainter.cxx:754
 TGLSurfacePainter.cxx:755
 TGLSurfacePainter.cxx:756
 TGLSurfacePainter.cxx:757
 TGLSurfacePainter.cxx:758
 TGLSurfacePainter.cxx:759
 TGLSurfacePainter.cxx:760
 TGLSurfacePainter.cxx:761
 TGLSurfacePainter.cxx:762
 TGLSurfacePainter.cxx:763
 TGLSurfacePainter.cxx:764
 TGLSurfacePainter.cxx:765
 TGLSurfacePainter.cxx:766
 TGLSurfacePainter.cxx:767
 TGLSurfacePainter.cxx:768
 TGLSurfacePainter.cxx:769
 TGLSurfacePainter.cxx:770
 TGLSurfacePainter.cxx:771
 TGLSurfacePainter.cxx:772
 TGLSurfacePainter.cxx:773
 TGLSurfacePainter.cxx:774
 TGLSurfacePainter.cxx:775
 TGLSurfacePainter.cxx:776
 TGLSurfacePainter.cxx:777
 TGLSurfacePainter.cxx:778
 TGLSurfacePainter.cxx:779
 TGLSurfacePainter.cxx:780
 TGLSurfacePainter.cxx:781
 TGLSurfacePainter.cxx:782
 TGLSurfacePainter.cxx:783
 TGLSurfacePainter.cxx:784
 TGLSurfacePainter.cxx:785
 TGLSurfacePainter.cxx:786
 TGLSurfacePainter.cxx:787
 TGLSurfacePainter.cxx:788
 TGLSurfacePainter.cxx:789
 TGLSurfacePainter.cxx:790
 TGLSurfacePainter.cxx:791
 TGLSurfacePainter.cxx:792
 TGLSurfacePainter.cxx:793
 TGLSurfacePainter.cxx:794
 TGLSurfacePainter.cxx:795
 TGLSurfacePainter.cxx:796
 TGLSurfacePainter.cxx:797
 TGLSurfacePainter.cxx:798
 TGLSurfacePainter.cxx:799
 TGLSurfacePainter.cxx:800
 TGLSurfacePainter.cxx:801
 TGLSurfacePainter.cxx:802
 TGLSurfacePainter.cxx:803
 TGLSurfacePainter.cxx:804
 TGLSurfacePainter.cxx:805
 TGLSurfacePainter.cxx:806
 TGLSurfacePainter.cxx:807
 TGLSurfacePainter.cxx:808
 TGLSurfacePainter.cxx:809
 TGLSurfacePainter.cxx:810
 TGLSurfacePainter.cxx:811
 TGLSurfacePainter.cxx:812
 TGLSurfacePainter.cxx:813
 TGLSurfacePainter.cxx:814
 TGLSurfacePainter.cxx:815
 TGLSurfacePainter.cxx:816
 TGLSurfacePainter.cxx:817
 TGLSurfacePainter.cxx:818
 TGLSurfacePainter.cxx:819
 TGLSurfacePainter.cxx:820
 TGLSurfacePainter.cxx:821
 TGLSurfacePainter.cxx:822
 TGLSurfacePainter.cxx:823
 TGLSurfacePainter.cxx:824
 TGLSurfacePainter.cxx:825
 TGLSurfacePainter.cxx:826
 TGLSurfacePainter.cxx:827
 TGLSurfacePainter.cxx:828
 TGLSurfacePainter.cxx:829
 TGLSurfacePainter.cxx:830
 TGLSurfacePainter.cxx:831
 TGLSurfacePainter.cxx:832
 TGLSurfacePainter.cxx:833
 TGLSurfacePainter.cxx:834
 TGLSurfacePainter.cxx:835
 TGLSurfacePainter.cxx:836
 TGLSurfacePainter.cxx:837
 TGLSurfacePainter.cxx:838
 TGLSurfacePainter.cxx:839
 TGLSurfacePainter.cxx:840
 TGLSurfacePainter.cxx:841
 TGLSurfacePainter.cxx:842
 TGLSurfacePainter.cxx:843
 TGLSurfacePainter.cxx:844
 TGLSurfacePainter.cxx:845
 TGLSurfacePainter.cxx:846
 TGLSurfacePainter.cxx:847
 TGLSurfacePainter.cxx:848
 TGLSurfacePainter.cxx:849
 TGLSurfacePainter.cxx:850
 TGLSurfacePainter.cxx:851
 TGLSurfacePainter.cxx:852
 TGLSurfacePainter.cxx:853
 TGLSurfacePainter.cxx:854
 TGLSurfacePainter.cxx:855
 TGLSurfacePainter.cxx:856
 TGLSurfacePainter.cxx:857
 TGLSurfacePainter.cxx:858
 TGLSurfacePainter.cxx:859
 TGLSurfacePainter.cxx:860
 TGLSurfacePainter.cxx:861
 TGLSurfacePainter.cxx:862
 TGLSurfacePainter.cxx:863
 TGLSurfacePainter.cxx:864
 TGLSurfacePainter.cxx:865
 TGLSurfacePainter.cxx:866
 TGLSurfacePainter.cxx:867
 TGLSurfacePainter.cxx:868
 TGLSurfacePainter.cxx:869
 TGLSurfacePainter.cxx:870
 TGLSurfacePainter.cxx:871
 TGLSurfacePainter.cxx:872
 TGLSurfacePainter.cxx:873
 TGLSurfacePainter.cxx:874
 TGLSurfacePainter.cxx:875
 TGLSurfacePainter.cxx:876
 TGLSurfacePainter.cxx:877
 TGLSurfacePainter.cxx:878
 TGLSurfacePainter.cxx:879
 TGLSurfacePainter.cxx:880
 TGLSurfacePainter.cxx:881
 TGLSurfacePainter.cxx:882
 TGLSurfacePainter.cxx:883
 TGLSurfacePainter.cxx:884
 TGLSurfacePainter.cxx:885
 TGLSurfacePainter.cxx:886
 TGLSurfacePainter.cxx:887
 TGLSurfacePainter.cxx:888
 TGLSurfacePainter.cxx:889
 TGLSurfacePainter.cxx:890
 TGLSurfacePainter.cxx:891
 TGLSurfacePainter.cxx:892
 TGLSurfacePainter.cxx:893
 TGLSurfacePainter.cxx:894
 TGLSurfacePainter.cxx:895
 TGLSurfacePainter.cxx:896
 TGLSurfacePainter.cxx:897
 TGLSurfacePainter.cxx:898
 TGLSurfacePainter.cxx:899
 TGLSurfacePainter.cxx:900
 TGLSurfacePainter.cxx:901
 TGLSurfacePainter.cxx:902
 TGLSurfacePainter.cxx:903
 TGLSurfacePainter.cxx:904
 TGLSurfacePainter.cxx:905
 TGLSurfacePainter.cxx:906
 TGLSurfacePainter.cxx:907
 TGLSurfacePainter.cxx:908
 TGLSurfacePainter.cxx:909
 TGLSurfacePainter.cxx:910
 TGLSurfacePainter.cxx:911
 TGLSurfacePainter.cxx:912
 TGLSurfacePainter.cxx:913
 TGLSurfacePainter.cxx:914
 TGLSurfacePainter.cxx:915
 TGLSurfacePainter.cxx:916
 TGLSurfacePainter.cxx:917
 TGLSurfacePainter.cxx:918
 TGLSurfacePainter.cxx:919
 TGLSurfacePainter.cxx:920
 TGLSurfacePainter.cxx:921
 TGLSurfacePainter.cxx:922
 TGLSurfacePainter.cxx:923
 TGLSurfacePainter.cxx:924
 TGLSurfacePainter.cxx:925
 TGLSurfacePainter.cxx:926
 TGLSurfacePainter.cxx:927
 TGLSurfacePainter.cxx:928
 TGLSurfacePainter.cxx:929
 TGLSurfacePainter.cxx:930
 TGLSurfacePainter.cxx:931
 TGLSurfacePainter.cxx:932
 TGLSurfacePainter.cxx:933
 TGLSurfacePainter.cxx:934
 TGLSurfacePainter.cxx:935
 TGLSurfacePainter.cxx:936
 TGLSurfacePainter.cxx:937
 TGLSurfacePainter.cxx:938
 TGLSurfacePainter.cxx:939
 TGLSurfacePainter.cxx:940
 TGLSurfacePainter.cxx:941
 TGLSurfacePainter.cxx:942
 TGLSurfacePainter.cxx:943
 TGLSurfacePainter.cxx:944
 TGLSurfacePainter.cxx:945
 TGLSurfacePainter.cxx:946
 TGLSurfacePainter.cxx:947
 TGLSurfacePainter.cxx:948
 TGLSurfacePainter.cxx:949
 TGLSurfacePainter.cxx:950
 TGLSurfacePainter.cxx:951
 TGLSurfacePainter.cxx:952
 TGLSurfacePainter.cxx:953
 TGLSurfacePainter.cxx:954
 TGLSurfacePainter.cxx:955
 TGLSurfacePainter.cxx:956
 TGLSurfacePainter.cxx:957
 TGLSurfacePainter.cxx:958
 TGLSurfacePainter.cxx:959
 TGLSurfacePainter.cxx:960
 TGLSurfacePainter.cxx:961
 TGLSurfacePainter.cxx:962
 TGLSurfacePainter.cxx:963
 TGLSurfacePainter.cxx:964
 TGLSurfacePainter.cxx:965
 TGLSurfacePainter.cxx:966
 TGLSurfacePainter.cxx:967
 TGLSurfacePainter.cxx:968
 TGLSurfacePainter.cxx:969
 TGLSurfacePainter.cxx:970
 TGLSurfacePainter.cxx:971
 TGLSurfacePainter.cxx:972
 TGLSurfacePainter.cxx:973
 TGLSurfacePainter.cxx:974
 TGLSurfacePainter.cxx:975
 TGLSurfacePainter.cxx:976
 TGLSurfacePainter.cxx:977
 TGLSurfacePainter.cxx:978
 TGLSurfacePainter.cxx:979
 TGLSurfacePainter.cxx:980
 TGLSurfacePainter.cxx:981
 TGLSurfacePainter.cxx:982
 TGLSurfacePainter.cxx:983
 TGLSurfacePainter.cxx:984
 TGLSurfacePainter.cxx:985
 TGLSurfacePainter.cxx:986
 TGLSurfacePainter.cxx:987
 TGLSurfacePainter.cxx:988
 TGLSurfacePainter.cxx:989
 TGLSurfacePainter.cxx:990
 TGLSurfacePainter.cxx:991
 TGLSurfacePainter.cxx:992
 TGLSurfacePainter.cxx:993
 TGLSurfacePainter.cxx:994
 TGLSurfacePainter.cxx:995
 TGLSurfacePainter.cxx:996
 TGLSurfacePainter.cxx:997
 TGLSurfacePainter.cxx:998
 TGLSurfacePainter.cxx:999
 TGLSurfacePainter.cxx:1000
 TGLSurfacePainter.cxx:1001
 TGLSurfacePainter.cxx:1002
 TGLSurfacePainter.cxx:1003
 TGLSurfacePainter.cxx:1004
 TGLSurfacePainter.cxx:1005
 TGLSurfacePainter.cxx:1006
 TGLSurfacePainter.cxx:1007
 TGLSurfacePainter.cxx:1008
 TGLSurfacePainter.cxx:1009
 TGLSurfacePainter.cxx:1010
 TGLSurfacePainter.cxx:1011
 TGLSurfacePainter.cxx:1012
 TGLSurfacePainter.cxx:1013
 TGLSurfacePainter.cxx:1014
 TGLSurfacePainter.cxx:1015
 TGLSurfacePainter.cxx:1016
 TGLSurfacePainter.cxx:1017
 TGLSurfacePainter.cxx:1018
 TGLSurfacePainter.cxx:1019
 TGLSurfacePainter.cxx:1020
 TGLSurfacePainter.cxx:1021
 TGLSurfacePainter.cxx:1022
 TGLSurfacePainter.cxx:1023
 TGLSurfacePainter.cxx:1024
 TGLSurfacePainter.cxx:1025
 TGLSurfacePainter.cxx:1026
 TGLSurfacePainter.cxx:1027
 TGLSurfacePainter.cxx:1028
 TGLSurfacePainter.cxx:1029
 TGLSurfacePainter.cxx:1030
 TGLSurfacePainter.cxx:1031
 TGLSurfacePainter.cxx:1032
 TGLSurfacePainter.cxx:1033
 TGLSurfacePainter.cxx:1034
 TGLSurfacePainter.cxx:1035
 TGLSurfacePainter.cxx:1036
 TGLSurfacePainter.cxx:1037
 TGLSurfacePainter.cxx:1038
 TGLSurfacePainter.cxx:1039
 TGLSurfacePainter.cxx:1040
 TGLSurfacePainter.cxx:1041
 TGLSurfacePainter.cxx:1042
 TGLSurfacePainter.cxx:1043
 TGLSurfacePainter.cxx:1044
 TGLSurfacePainter.cxx:1045
 TGLSurfacePainter.cxx:1046
 TGLSurfacePainter.cxx:1047
 TGLSurfacePainter.cxx:1048
 TGLSurfacePainter.cxx:1049
 TGLSurfacePainter.cxx:1050
 TGLSurfacePainter.cxx:1051
 TGLSurfacePainter.cxx:1052
 TGLSurfacePainter.cxx:1053
 TGLSurfacePainter.cxx:1054
 TGLSurfacePainter.cxx:1055
 TGLSurfacePainter.cxx:1056
 TGLSurfacePainter.cxx:1057
 TGLSurfacePainter.cxx:1058
 TGLSurfacePainter.cxx:1059
 TGLSurfacePainter.cxx:1060
 TGLSurfacePainter.cxx:1061
 TGLSurfacePainter.cxx:1062
 TGLSurfacePainter.cxx:1063
 TGLSurfacePainter.cxx:1064
 TGLSurfacePainter.cxx:1065
 TGLSurfacePainter.cxx:1066
 TGLSurfacePainter.cxx:1067
 TGLSurfacePainter.cxx:1068
 TGLSurfacePainter.cxx:1069
 TGLSurfacePainter.cxx:1070
 TGLSurfacePainter.cxx:1071
 TGLSurfacePainter.cxx:1072
 TGLSurfacePainter.cxx:1073
 TGLSurfacePainter.cxx:1074
 TGLSurfacePainter.cxx:1075
 TGLSurfacePainter.cxx:1076
 TGLSurfacePainter.cxx:1077
 TGLSurfacePainter.cxx:1078
 TGLSurfacePainter.cxx:1079
 TGLSurfacePainter.cxx:1080
 TGLSurfacePainter.cxx:1081
 TGLSurfacePainter.cxx:1082
 TGLSurfacePainter.cxx:1083
 TGLSurfacePainter.cxx:1084
 TGLSurfacePainter.cxx:1085
 TGLSurfacePainter.cxx:1086
 TGLSurfacePainter.cxx:1087
 TGLSurfacePainter.cxx:1088
 TGLSurfacePainter.cxx:1089
 TGLSurfacePainter.cxx:1090
 TGLSurfacePainter.cxx:1091
 TGLSurfacePainter.cxx:1092
 TGLSurfacePainter.cxx:1093
 TGLSurfacePainter.cxx:1094
 TGLSurfacePainter.cxx:1095
 TGLSurfacePainter.cxx:1096
 TGLSurfacePainter.cxx:1097
 TGLSurfacePainter.cxx:1098
 TGLSurfacePainter.cxx:1099
 TGLSurfacePainter.cxx:1100
 TGLSurfacePainter.cxx:1101
 TGLSurfacePainter.cxx:1102
 TGLSurfacePainter.cxx:1103
 TGLSurfacePainter.cxx:1104
 TGLSurfacePainter.cxx:1105
 TGLSurfacePainter.cxx:1106
 TGLSurfacePainter.cxx:1107
 TGLSurfacePainter.cxx:1108
 TGLSurfacePainter.cxx:1109
 TGLSurfacePainter.cxx:1110
 TGLSurfacePainter.cxx:1111
 TGLSurfacePainter.cxx:1112
 TGLSurfacePainter.cxx:1113
 TGLSurfacePainter.cxx:1114
 TGLSurfacePainter.cxx:1115
 TGLSurfacePainter.cxx:1116
 TGLSurfacePainter.cxx:1117
 TGLSurfacePainter.cxx:1118
 TGLSurfacePainter.cxx:1119
 TGLSurfacePainter.cxx:1120
 TGLSurfacePainter.cxx:1121
 TGLSurfacePainter.cxx:1122
 TGLSurfacePainter.cxx:1123
 TGLSurfacePainter.cxx:1124
 TGLSurfacePainter.cxx:1125
 TGLSurfacePainter.cxx:1126
 TGLSurfacePainter.cxx:1127
 TGLSurfacePainter.cxx:1128
 TGLSurfacePainter.cxx:1129
 TGLSurfacePainter.cxx:1130
 TGLSurfacePainter.cxx:1131
 TGLSurfacePainter.cxx:1132
 TGLSurfacePainter.cxx:1133
 TGLSurfacePainter.cxx:1134
 TGLSurfacePainter.cxx:1135
 TGLSurfacePainter.cxx:1136
 TGLSurfacePainter.cxx:1137
 TGLSurfacePainter.cxx:1138
 TGLSurfacePainter.cxx:1139
 TGLSurfacePainter.cxx:1140
 TGLSurfacePainter.cxx:1141
 TGLSurfacePainter.cxx:1142
 TGLSurfacePainter.cxx:1143
 TGLSurfacePainter.cxx:1144
 TGLSurfacePainter.cxx:1145
 TGLSurfacePainter.cxx:1146
 TGLSurfacePainter.cxx:1147
 TGLSurfacePainter.cxx:1148
 TGLSurfacePainter.cxx:1149
 TGLSurfacePainter.cxx:1150
 TGLSurfacePainter.cxx:1151
 TGLSurfacePainter.cxx:1152
 TGLSurfacePainter.cxx:1153
 TGLSurfacePainter.cxx:1154
 TGLSurfacePainter.cxx:1155
 TGLSurfacePainter.cxx:1156
 TGLSurfacePainter.cxx:1157
 TGLSurfacePainter.cxx:1158
 TGLSurfacePainter.cxx:1159
 TGLSurfacePainter.cxx:1160
 TGLSurfacePainter.cxx:1161
 TGLSurfacePainter.cxx:1162
 TGLSurfacePainter.cxx:1163
 TGLSurfacePainter.cxx:1164
 TGLSurfacePainter.cxx:1165
 TGLSurfacePainter.cxx:1166
 TGLSurfacePainter.cxx:1167
 TGLSurfacePainter.cxx:1168
 TGLSurfacePainter.cxx:1169
 TGLSurfacePainter.cxx:1170
 TGLSurfacePainter.cxx:1171
 TGLSurfacePainter.cxx:1172
 TGLSurfacePainter.cxx:1173
 TGLSurfacePainter.cxx:1174
 TGLSurfacePainter.cxx:1175
 TGLSurfacePainter.cxx:1176
 TGLSurfacePainter.cxx:1177
 TGLSurfacePainter.cxx:1178
 TGLSurfacePainter.cxx:1179
 TGLSurfacePainter.cxx:1180
 TGLSurfacePainter.cxx:1181
 TGLSurfacePainter.cxx:1182
 TGLSurfacePainter.cxx:1183
 TGLSurfacePainter.cxx:1184
 TGLSurfacePainter.cxx:1185
 TGLSurfacePainter.cxx:1186
 TGLSurfacePainter.cxx:1187
 TGLSurfacePainter.cxx:1188
 TGLSurfacePainter.cxx:1189
 TGLSurfacePainter.cxx:1190
 TGLSurfacePainter.cxx:1191
 TGLSurfacePainter.cxx:1192
 TGLSurfacePainter.cxx:1193
 TGLSurfacePainter.cxx:1194
 TGLSurfacePainter.cxx:1195
 TGLSurfacePainter.cxx:1196
 TGLSurfacePainter.cxx:1197
 TGLSurfacePainter.cxx:1198
 TGLSurfacePainter.cxx:1199
 TGLSurfacePainter.cxx:1200
 TGLSurfacePainter.cxx:1201
 TGLSurfacePainter.cxx:1202
 TGLSurfacePainter.cxx:1203
 TGLSurfacePainter.cxx:1204
 TGLSurfacePainter.cxx:1205
 TGLSurfacePainter.cxx:1206
 TGLSurfacePainter.cxx:1207
 TGLSurfacePainter.cxx:1208
 TGLSurfacePainter.cxx:1209
 TGLSurfacePainter.cxx:1210
 TGLSurfacePainter.cxx:1211
 TGLSurfacePainter.cxx:1212
 TGLSurfacePainter.cxx:1213
 TGLSurfacePainter.cxx:1214
 TGLSurfacePainter.cxx:1215
 TGLSurfacePainter.cxx:1216
 TGLSurfacePainter.cxx:1217
 TGLSurfacePainter.cxx:1218
 TGLSurfacePainter.cxx:1219
 TGLSurfacePainter.cxx:1220
 TGLSurfacePainter.cxx:1221
 TGLSurfacePainter.cxx:1222
 TGLSurfacePainter.cxx:1223
 TGLSurfacePainter.cxx:1224
 TGLSurfacePainter.cxx:1225
 TGLSurfacePainter.cxx:1226
 TGLSurfacePainter.cxx:1227
 TGLSurfacePainter.cxx:1228
 TGLSurfacePainter.cxx:1229
 TGLSurfacePainter.cxx:1230
 TGLSurfacePainter.cxx:1231
 TGLSurfacePainter.cxx:1232
 TGLSurfacePainter.cxx:1233
 TGLSurfacePainter.cxx:1234
 TGLSurfacePainter.cxx:1235
 TGLSurfacePainter.cxx:1236
 TGLSurfacePainter.cxx:1237
 TGLSurfacePainter.cxx:1238
 TGLSurfacePainter.cxx:1239
 TGLSurfacePainter.cxx:1240
 TGLSurfacePainter.cxx:1241
 TGLSurfacePainter.cxx:1242
 TGLSurfacePainter.cxx:1243
 TGLSurfacePainter.cxx:1244
 TGLSurfacePainter.cxx:1245