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