Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TF2GL.cxx
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Matevz Tadel, Jun 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TF2GL.h"
13 
14 #include <TF2.h>
15 #include <TF3.h>
16 #include <TH2.h>
17 #include <TVirtualPad.h>
18 
19 #include "TGLSurfacePainter.h"
20 #include "TGLTF3Painter.h"
21 #include "TGLAxisPainter.h"
22 
23 #include "TGLRnrCtx.h"
24 
25 #include "TGLIncludes.h"
26 
27 /** \class TF2GL
28 \ingroup opengl
29 GL renderer for TF2.
30 TGLPlotPainter is used internally.
31 */
32 
33 ClassImp(TF2GL);
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// Constructor.
37 
38 TF2GL::TF2GL() : TGLPlot3D(), fM(0), fH(0)
39 {
40 }
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// Destructor.
44 
45 TF2GL::~TF2GL()
46 {
47  delete fH;
48 }
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Set model object.
52 
53 Bool_t TF2GL::SetModel(TObject* obj, const Option_t* opt)
54 {
55  TString option(opt);
56  option.ToLower();
57 
58  fM = SetModelDynCast<TF2>(obj);
59 
60  fH = (TH2*) fM->CreateHistogram();
61  if (!fH) return kFALSE;
62 
63  fH->GetZaxis()->SetLimits(fH->GetMinimum(), fH->GetMaximum());
64 
65  if (dynamic_cast<TF3*>(fM))
66  SetPainter( new TGLTF3Painter((TF3*)fM, fH, 0, &fCoord) );
67  else
68  SetPainter( new TGLSurfacePainter(fH, 0, &fCoord) );
69 
70  if (option.Index("sph") != kNPOS)
71  fCoord.SetCoordType(kGLSpherical);
72  else if (option.Index("pol") != kNPOS)
73  fCoord.SetCoordType(kGLPolar);
74  else if (option.Index("cyl") != kNPOS)
75  fCoord.SetCoordType(kGLCylindrical);
76 
77  fPlotPainter->AddOption(option);
78  fPlotPainter->InitGeometry();
79 
80  return kTRUE;
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// Setup bounding-box.
85 
86 void TF2GL::SetBBox()
87 {
88  fBoundingBox.Set(fPlotPainter->RefBackBox().Get3DBox());
89 }
90 
91 ////////////////////////////////////////////////////////////////////////////////
92 /// Render the object.
93 
94 void TF2GL::DirectDraw(TGLRnrCtx & rnrCtx) const
95 {
96  fPlotPainter->RefBackBox().FindFrontPoint();
97 
98  glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT);
99 
100  glEnable(GL_NORMALIZE);
101  glDisable(GL_COLOR_MATERIAL);
102 
103  fPlotPainter->InitGL();
104  fPlotPainter->DrawPlot();
105 
106  glDisable(GL_CULL_FACE);
107  glPopAttrib();
108 
109  // Axes
110  TGLAxisPainterBox axe_painter;
111  axe_painter.SetUseAxisColors(kFALSE);
112  axe_painter.SetFontMode(TGLFont::kPixmap);
113  axe_painter.PlotStandard(rnrCtx, fH, fBoundingBox);
114 }