forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEveStraightLineSetGL.cxx
203 lines (173 loc) · 6.37 KB
/
TEveStraightLineSetGL.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// @(#)root/eve:$Id$
// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
/*************************************************************************
* 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 "TEveStraightLineSetGL.h"
#include "TEveStraightLineSet.h"
#include "TGLIncludes.h"
#include "TGLRnrCtx.h"
#include "TGLSelectRecord.h"
/** \class TEveStraightLineSetGL
\ingroup TEve
GL-renderer for TEveStraightLineSet class.
*/
ClassImp(TEveStraightLineSetGL);
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
TEveStraightLineSetGL::TEveStraightLineSetGL() : TGLObject(), fM(0)
{
// fDLCache = false; // Disable display list.
fMultiColor = kTRUE;
}
////////////////////////////////////////////////////////////////////////////////
/// Set model object.
Bool_t TEveStraightLineSetGL::SetModel(TObject* obj, const Option_t* /*opt*/)
{
fM = SetModelDynCast<TEveStraightLineSet>(obj);
return kTRUE;
}
////////////////////////////////////////////////////////////////////////////////
/// Setup bounding box information.
void TEveStraightLineSetGL::SetBBox()
{
SetAxisAlignedBBox(((TEveStraightLineSet*)fExternalObj)->AssertBBox());
}
////////////////////////////////////////////////////////////////////////////////
/// Override from TGLObject.
/// To account for large point-sizes we modify the projection matrix
/// during selection and thus we need a direct draw.
Bool_t TEveStraightLineSetGL::ShouldDLCache(const TGLRnrCtx& rnrCtx) const
{
if (rnrCtx.Selection()) return kFALSE;
return TGLObject::ShouldDLCache(rnrCtx);
}
////////////////////////////////////////////////////////////////////////////////
/// Draw function for TEveStraightLineSetGL. Skips line-pass of outline mode.
void TEveStraightLineSetGL::Draw(TGLRnrCtx& rnrCtx) const
{
if (rnrCtx.IsDrawPassOutlineLine())
return;
TGLObject::Draw(rnrCtx);
}
////////////////////////////////////////////////////////////////////////////////
/// Render the line-set with GL.
void TEveStraightLineSetGL::DirectDraw(TGLRnrCtx& rnrCtx) const
{
// printf("TEveStraightLineSetGL::DirectDraw LOD %d\n", rnrCtx.ShapeLOD());
TEveStraightLineSet& mL = * fM;
// set depth range when selection is disabled, else can't pick camera center
if (mL.GetDepthTest() == kFALSE && rnrCtx.Selection() == kFALSE)
{
glPushAttrib(GL_VIEWPORT_BIT);
glDepthRange(0, 0.1);
}
// lines
if (mL.GetRnrLines() && mL.GetLinePlex().Size() > 0)
{
glPushAttrib(GL_LINE_BIT | GL_ENABLE_BIT);
glDisable(GL_LIGHTING);
TGLUtil::LineWidth(mL.GetLineWidth());
if (mL.GetLineStyle() > 1) {
// Int_t fac = 1;
UShort_t pat = 0xffff;
switch (mL.GetLineStyle()) {
case 2: pat = 0x3333; break;
case 3: pat = 0x5555; break;
case 4: pat = 0xf040; break;
case 5: pat = 0xf4f4; break;
case 6: pat = 0xf111; break;
case 7: pat = 0xf0f0; break;
case 8: pat = 0xff11; break;
case 9: pat = 0x3fff; break;
case 10: pat = 0x08ff; /* fac = 2; */ break;
}
glLineStipple(1, pat);
glEnable(GL_LINE_STIPPLE);
}
// During selection extend picking region for large line-widths.
Bool_t changePM = rnrCtx.Selection() && mL.GetLineWidth() > rnrCtx.GetPickRadius();
if (changePM)
TGLUtil::BeginExtendPickRegion((Float_t) rnrCtx.GetPickRadius() / mL.GetLineWidth());
TEveChunkManager::iterator li(mL.GetLinePlex());
if (rnrCtx.SecSelection())
{
GLuint name = 0;
glPushName(1);
glPushName(0);
while (li.next())
{
TEveStraightLineSet::Line_t& l = * (TEveStraightLineSet::Line_t*) li();
glLoadName(l.fId);
{
glBegin(GL_LINES);
glVertex3f(l.fV1[0], l.fV1[1], l.fV1[2]);
glVertex3f(l.fV2[0], l.fV2[1], l.fV2[2]);
glEnd();
}
name ++;
}
glPopName();
glPopName();
}
else
{
glBegin(GL_LINES);
while (li.next())
{
TEveStraightLineSet::Line_t& l = * (TEveStraightLineSet::Line_t*) li();
glVertex3f(l.fV1[0], l.fV1[1], l.fV1[2]);
glVertex3f(l.fV2[0], l.fV2[1], l.fV2[2]);
}
glEnd();
}
if (changePM)
TGLUtil::EndExtendPickRegion();
glPopAttrib();
}
// markers
if (mL.GetRnrMarkers() && mL.GetMarkerPlex().Size() > 0)
{
TEveChunkManager::iterator mi(mL.GetMarkerPlex());
Float_t* pnts = new Float_t[mL.GetMarkerPlex().Size()*3];
Float_t* pnt = pnts;
while (mi.next())
{
TEveStraightLineSet::Marker_t& m = * (TEveStraightLineSet::Marker_t*) mi();
pnt[0] = m.fV[0];
pnt[1] = m.fV[1];
pnt[2] = m.fV[2];
pnt += 3;
}
if (rnrCtx.SecSelection()) glPushName(2);
TGLUtil::RenderPolyMarkers((TAttMarker&)mL, mL.GetMainTransparency(),
pnts, mL.GetMarkerPlex().Size(),
rnrCtx.GetPickRadius(),
rnrCtx.Selection(),
rnrCtx.SecSelection());
if (rnrCtx.SecSelection()) glPopName();
delete [] pnts;
}
if (mL.GetDepthTest() == kFALSE && rnrCtx.Selection() == kFALSE)
glPopAttrib();
}
////////////////////////////////////////////////////////////////////////////////
/// Process results of the secondary selection.
void TEveStraightLineSetGL::ProcessSelection(TGLRnrCtx& /*rnrCtx*/,
TGLSelectRecord& rec)
{
if (rec.GetN() != 3) return;
if (rec.GetItem(1) == 1)
{
printf("selected line %d\n", rec.GetItem(2));
}
else
{
TEveStraightLineSet::Marker_t& m = * (TEveStraightLineSet::Marker_t*) fM->GetMarkerPlex().Atom(rec.GetItem(2));
printf("Selected point %d on line %d\n", rec.GetItem(2), m.fLineId);
}
}