// @(#)root/gl:$Id$
// Author:  Matevz Tadel, Jun 2007

/*************************************************************************
 * Copyright (C) 1995-2004, 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 "TF2GL.h"

#include <TF2.h>
#include <TF3.h>
#include <TH2.h>
#include <TVirtualPad.h>

#include "TGLSurfacePainter.h"
#include "TGLTF3Painter.h"
#include "TGLAxisPainter.h"

#include "TGLRnrCtx.h"

#include "TGLIncludes.h"

//______________________________________________________________________
//
// GL renderer for TF2.
// TGLPlotPainter is used internally.

ClassImp(TF2GL);

//______________________________________________________________________________
TF2GL::TF2GL() : TGLPlot3D(), fM(0), fH(0)
{
   // Constructor.
}

//______________________________________________________________________________
TF2GL::~TF2GL()
{
   // Destructor.

   delete fH;
}

/**************************************************************************/

//______________________________________________________________________________
Bool_t TF2GL::SetModel(TObject* obj, const Option_t* opt)
{
   // Set model object.

   TString option(opt);
   option.ToLower();

   fM = SetModelDynCast<TF2>(obj);

   fH = (TH2*) fM->CreateHistogram();
   if (!fH) return kFALSE;

   fH->GetZaxis()->SetLimits(fH->GetMinimum(), fH->GetMaximum());

   if (dynamic_cast<TF3*>(fM))
      SetPainter( new TGLTF3Painter((TF3*)fM, fH, 0, &fCoord) );
   else
      SetPainter( new TGLSurfacePainter(fH, 0, &fCoord) );

   if (option.Index("sph") != kNPOS)
      fCoord.SetCoordType(kGLSpherical);
   else if (option.Index("pol") != kNPOS)
      fCoord.SetCoordType(kGLPolar);
   else if (option.Index("cyl") != kNPOS)
      fCoord.SetCoordType(kGLCylindrical);

   fPlotPainter->AddOption(option);
   fPlotPainter->InitGeometry();

   return kTRUE;
}

//______________________________________________________________________________
void TF2GL::SetBBox()
{
   // Setup bounding-box.

   fBoundingBox.Set(fPlotPainter->RefBackBox().Get3DBox());
}

//______________________________________________________________________________
void TF2GL::DirectDraw(TGLRnrCtx & rnrCtx) const
{
   // Render the object.

   fPlotPainter->RefBackBox().FindFrontPoint();

   glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT);

   glEnable(GL_NORMALIZE);
   glDisable(GL_COLOR_MATERIAL);

   fPlotPainter->InitGL();
   fPlotPainter->DrawPlot();

   glDisable(GL_CULL_FACE);
   glPopAttrib();

   // Axes
   TGLAxisPainterBox axe_painter;
   axe_painter.SetUseAxisColors(kFALSE);
   axe_painter.SetFontMode(TGLFont::kPixmap);
   axe_painter.PlotStandard(rnrCtx, fH, fBoundingBox);
}
 TF2GL.cxx:1
 TF2GL.cxx:2
 TF2GL.cxx:3
 TF2GL.cxx:4
 TF2GL.cxx:5
 TF2GL.cxx:6
 TF2GL.cxx:7
 TF2GL.cxx:8
 TF2GL.cxx:9
 TF2GL.cxx:10
 TF2GL.cxx:11
 TF2GL.cxx:12
 TF2GL.cxx:13
 TF2GL.cxx:14
 TF2GL.cxx:15
 TF2GL.cxx:16
 TF2GL.cxx:17
 TF2GL.cxx:18
 TF2GL.cxx:19
 TF2GL.cxx:20
 TF2GL.cxx:21
 TF2GL.cxx:22
 TF2GL.cxx:23
 TF2GL.cxx:24
 TF2GL.cxx:25
 TF2GL.cxx:26
 TF2GL.cxx:27
 TF2GL.cxx:28
 TF2GL.cxx:29
 TF2GL.cxx:30
 TF2GL.cxx:31
 TF2GL.cxx:32
 TF2GL.cxx:33
 TF2GL.cxx:34
 TF2GL.cxx:35
 TF2GL.cxx:36
 TF2GL.cxx:37
 TF2GL.cxx:38
 TF2GL.cxx:39
 TF2GL.cxx:40
 TF2GL.cxx:41
 TF2GL.cxx:42
 TF2GL.cxx:43
 TF2GL.cxx:44
 TF2GL.cxx:45
 TF2GL.cxx:46
 TF2GL.cxx:47
 TF2GL.cxx:48
 TF2GL.cxx:49
 TF2GL.cxx:50
 TF2GL.cxx:51
 TF2GL.cxx:52
 TF2GL.cxx:53
 TF2GL.cxx:54
 TF2GL.cxx:55
 TF2GL.cxx:56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