Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TH3GL.cxx
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Matevz Tadel 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, 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 #include "TH3GL.h"
12 #include "TH3.h"
13 #include "TVirtualPad.h"
14 #include "TAxis.h"
15 #include "TMath.h"
16 
17 #include "TGLSurfacePainter.h"
18 #include "TGLHistPainter.h"
19 #include "TGLLegoPainter.h"
20 #include "TGLBoxPainter.h"
21 #include "TGLTF3Painter.h"
22 #include "TGLAxisPainter.h"
23 #include "TGLPhysicalShape.h"
24 #include "TGLCamera.h"
25 #include "TPolyMarker3D.h"
26 
27 #include "TGLRnrCtx.h"
28 #include "TGLIncludes.h"
29 
30 /** \class TH3GL
31 \ingroup opengl
32 OpenGL renderer class for TH3.
33 */
34 
35 ClassImp(TH3GL);
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Constructor.
39 
40 TH3GL::TH3GL() :
41  TGLPlot3D(), fM(0)
42 {
43 }
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 /// Constructor.
47 
48 TH3GL::TH3GL(TH3 *th3, TPolyMarker3D *pm) :
49  TGLPlot3D(), fM(th3)
50 {
51  SetPainter(new TGLBoxPainter(th3, pm, 0, &fCoord));
52  fPlotPainter->InitGeometry();
53 }
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// Destructor.
57 
58 TH3GL::~TH3GL()
59 {
60 }
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 /// Set model object.
64 
65 Bool_t TH3GL::SetModel(TObject* obj, const Option_t* opt)
66 {
67  TString option(opt);
68  option.ToLower();
69 
70  fM = SetModelDynCast<TH3>(obj);
71 
72  if (option.Index("iso") != kNPOS)
73  SetPainter( new TGLIsoPainter(fM, 0, &fCoord) );
74  else if (option.Index("box") != kNPOS)
75  SetPainter( new TGLBoxPainter(fM, 0, &fCoord) );
76  else {
77  Warning("SetModel", "Option '%s' not supported, assuming 'box'.", option.Data());
78  SetPainter( new TGLBoxPainter(fM, 0, &fCoord) );
79  }
80 
81  fPlotPainter->AddOption(option);
82 
83  Ssiz_t pos = option.Index("fb");
84  if (pos != kNPOS) {
85  option.Remove(pos, 2);
86  fPlotPainter->SetDrawFrontBox(kFALSE);
87  }
88 
89  pos = option.Index("bb");
90  if (pos != kNPOS)
91  fPlotPainter->SetDrawBackBox(kFALSE);
92 
93  pos = option.Index("a");
94  if (pos != kNPOS)
95  fPlotPainter->SetDrawAxes(kFALSE);
96 
97 
98  fPlotPainter->InitGeometry();
99 
100  return kTRUE;
101 }
102 
103 ////////////////////////////////////////////////////////////////////////////////
104 /// Set bounding box.
105 
106 void TH3GL::SetBBox()
107 {
108  fBoundingBox.Set(fPlotPainter->RefBackBox().Get3DBox());
109 }
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 /// Render with OpenGL.
113 
114 void TH3GL::DirectDraw(TGLRnrCtx & rnrCtx) const
115 {
116  if (fFirstPhysical)
117  fPlotPainter->SetPhysicalShapeColor(fFirstPhysical->Color());
118 
119  fPlotPainter->RefBackBox().FindFrontPoint();
120 
121  glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT);
122 
123  glEnable(GL_NORMALIZE);
124  glDisable(GL_COLOR_MATERIAL);
125 
126  fPlotPainter->InitGL();
127  fPlotPainter->DrawPlot();
128 
129  glDisable(GL_CULL_FACE);
130  glPopAttrib();
131 
132  // Axes
133  const Rgl::PlotTranslation trGuard(fPlotPainter);
134 
135  if (fPlotPainter->GetDrawAxes()) {
136  TGLAxisPainterBox axe_painter;
137  axe_painter.SetUseAxisColors(kFALSE);
138  axe_painter.SetFontMode(TGLFont::kPixmap);
139  axe_painter.PlotStandard(rnrCtx, fM, fBoundingBox);
140  }
141 }