Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TEveRGBAPaletteOverlay.cxx
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Author: Alja Mrak Tadel 2012
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 
12 #include "TEveRGBAPaletteOverlay.h"
13 #include "TEveRGBAPalette.h"
14 
15 #include "TGLIncludes.h"
16 #include "TGLAxis.h"
17 #include "TGLRnrCtx.h"
18 #include "TGLUtil.h"
19 
20 /** \class TEveRGBAPaletteOverlay
21 \ingroup TEve
22 Description of TEveRGBAPaletteOverlay
23 */
24 
25 ClassImp(TEveRGBAPaletteOverlay);
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 /// Constructor.
29 
30 TEveRGBAPaletteOverlay::TEveRGBAPaletteOverlay(TEveRGBAPalette* p, Float_t posx, Float_t posy,
31  Float_t width, Float_t height) :
32  TGLOverlayElement(),
33  fPalette(p),
34  fPosX(posx),
35  fPosY(posy),
36  fWidth(width),
37  fHeight(height)
38 {
39  fAxis.SetNdivisions(900);
40  fAxisPainter.SetUseAxisColors(kFALSE);
41  fAxisPainter.SetLabelPixelFontSize(10);
42  fAxisPainter.SetFontMode(TGLFont::kPixmap);
43  fAxisPainter.SetLabelAlign(TGLFont::kCenterH, TGLFont::kBottom);
44 }
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Render the overlay.
48 
49 void TEveRGBAPaletteOverlay::Render(TGLRnrCtx& rnrCtx)
50 {
51  const Double_t ca_min = fPalette->GetCAMinAsDouble();
52  const Double_t ca_max = fPalette->GetCAMaxAsDouble();
53 
54  // Uninitialized palette.
55  if (ca_min == ca_max) return;
56 
57  fAxis.SetLimits(ca_min, ca_max);
58 
59  glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
60 
61  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
62  glDisable(GL_CULL_FACE);
63  glEnable(GL_BLEND);
64  glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
65  TGLCapabilitySwitch lights_off(GL_LIGHTING, kFALSE);
66 
67  // reset to [0,1] units
68  glMatrixMode(GL_PROJECTION);
69  glPushMatrix();
70  glLoadIdentity();
71  glOrtho(0, 1, 0, 1, 0, 1);
72  glMatrixMode(GL_MODELVIEW);
73  glPushMatrix();
74  glLoadIdentity();
75 
76  // position palette
77  glTranslatef(fPosX, fPosY, 0);
78 
79  // colored quads
80  {
81  TGLCapabilitySwitch move_to_back(GL_POLYGON_OFFSET_FILL, kTRUE);
82  glPolygonOffset(0.5f, 0.5f);
83 
84  glBegin(GL_QUAD_STRIP);
85  TGLUtil::Color4ubv(fPalette->ColorFromValue(fPalette->fCAMin));
86  glVertex2f(0, 0);
87  glVertex2f(0, fHeight);
88  Float_t xs = fWidth / (fPalette->fCAMax - fPalette->fCAMin);
89  Float_t x = xs;
90  for (Int_t i = fPalette->fCAMin + 1; i < fPalette->fCAMax; ++i)
91  {
92  TGLUtil::Color4ubv(fPalette->ColorFromValue(i));
93  glVertex2f(x, 0);
94  glVertex2f(x, fHeight);
95  x += xs;
96  }
97  TGLUtil::Color4ubv(fPalette->ColorFromValue(fPalette->fCAMax));
98  glVertex2f(fWidth, 0);
99  glVertex2f(fWidth, fHeight);
100  glEnd();
101  }
102 
103  // axis
104  glPushMatrix();
105  Float_t sf = fWidth / (ca_max - ca_min);
106  glScalef(sf, 1, 1);
107  glTranslatef(-ca_min, 0, 0);
108  fAxis.SetTickLength(0.05*fWidth);
109  fAxisPainter.RefTMOff(0).Set(0, -1, 0);
110  fAxisPainter.PaintAxis(rnrCtx, &fAxis);
111  glPopMatrix();
112 
113  // frame around palette
114  glBegin(GL_LINE_LOOP);
115  glVertex2f(0, 0); glVertex2f(fWidth, 0);
116  glVertex2f(fWidth, fHeight); glVertex2f(0, fHeight);
117  glEnd();
118 
119  glMatrixMode(GL_PROJECTION);
120  glPopMatrix();
121  glMatrixMode(GL_MODELVIEW);
122  glPopMatrix();
123 
124  glPopAttrib();
125 }