Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TH2GL.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 "TH2GL.h"
13 #include "TH2.h"
14 #include "TVirtualPad.h"
15 #include "TAxis.h"
16 #include "TMath.h"
17 
18 #include "TGLSurfacePainter.h"
19 #include "TGLHistPainter.h"
20 #include "TGLLegoPainter.h"
21 #include "TGLBoxPainter.h"
22 #include "TGLTF3Painter.h"
23 #include "TGLAxisPainter.h"
24 #include "TGLCamera.h"
25 
26 #include "TGLRnrCtx.h"
27 
28 #include "TGLIncludes.h"
29 
30 /** \class TH2GL
31 \ingroup opengl
32 Rendering of TH2 and derived classes.
33 Interface to plot-painters also used for gl-in-pad.
34 */
35 
36 ClassImp(TH2GL);
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// Constructor.
40 
41 TH2GL::TH2GL() :
42  TGLPlot3D(), fM(0)
43 {
44 }
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Destructor.
48 
49 TH2GL::~TH2GL()
50 {
51 }
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Set model object.
55 
56 Bool_t TH2GL::SetModel(TObject* obj, const Option_t* opt)
57 {
58  TString option(opt);
59  option.ToLower();
60 
61  fM = SetModelDynCast<TH2>(obj);
62 
63  // Plot type
64  if (option.Index("surf") != kNPOS)
65  SetPainter( new TGLSurfacePainter(fM, 0, &fCoord) );
66  else
67  SetPainter( new TGLLegoPainter(fM, 0, &fCoord) );
68 
69  if (option.Index("sph") != kNPOS)
70  fCoord.SetCoordType(kGLSpherical);
71  else if (option.Index("pol") != kNPOS)
72  fCoord.SetCoordType(kGLPolar);
73  else if (option.Index("cyl") != kNPOS)
74  fCoord.SetCoordType(kGLCylindrical);
75 
76  fPlotPainter->AddOption(option);
77 
78  Ssiz_t pos = option.Index("fb");
79  if (pos != kNPOS) {
80  option.Remove(pos, 2);
81  fPlotPainter->SetDrawFrontBox(kFALSE);
82  }
83 
84  pos = option.Index("bb");
85  if (pos != kNPOS)
86  fPlotPainter->SetDrawBackBox(kFALSE);
87 
88  pos = option.Index("a");
89  if (pos != kNPOS)
90  fPlotPainter->SetDrawAxes(kFALSE);
91 
92  fPlotPainter->InitGeometry();
93 
94  return kTRUE;
95 }
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// Setup bounding-box.
99 
100 void TH2GL::SetBBox()
101 {
102  fBoundingBox.Set(fPlotPainter->RefBackBox().Get3DBox());
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// Render the object.
107 
108 void TH2GL::DirectDraw(TGLRnrCtx & rnrCtx) const
109 {
110  fPlotPainter->RefBackBox().FindFrontPoint();
111 
112  glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT);
113 
114  glEnable(GL_NORMALIZE);
115  glDisable(GL_COLOR_MATERIAL);
116 
117  fPlotPainter->InitGL();
118  fPlotPainter->DrawPlot();
119 
120  glDisable(GL_CULL_FACE);
121  glPopAttrib();
122 
123  // Axes
124  if (fPlotPainter->GetDrawAxes()) {
125  TGLAxisPainterBox axe_painter;
126  axe_painter.SetUseAxisColors(kFALSE);
127  axe_painter.SetFontMode(TGLFont::kPixmap);
128  axe_painter.PlotStandard(rnrCtx, fM, fBoundingBox);
129  }
130 }