forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEvePolygonSetProjectedGL.cxx
207 lines (172 loc) · 5.57 KB
/
TEvePolygonSetProjectedGL.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
204
205
206
207
// @(#)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 "TEvePolygonSetProjectedGL.h"
#include "TEvePolygonSetProjected.h"
#include "TEveVector.h"
#include "TGLRnrCtx.h"
#include "TGLCamera.h"
#include "TGLPhysicalShape.h"
#include "TGLIncludes.h"
/** \class TEvePolygonSetProjectedGL
\ingroup TEve
GL-renderer for TEvePolygonSetProjected class.
*/
ClassImp(TEvePolygonSetProjectedGL);
////////////////////////////////////////////////////////////////////////////////
/// Constructor
TEvePolygonSetProjectedGL::TEvePolygonSetProjectedGL() : TGLObject()
{
// fDLCache = kFALSE; // Disable DL.
fMultiColor = kTRUE; // Potentially false, reset in DirectDraw().
}
////////////////////////////////////////////////////////////////////////////////
/// Set model object.
Bool_t TEvePolygonSetProjectedGL::SetModel(TObject* obj, const Option_t* /*opt*/)
{
fM = SetModelDynCast<TEvePolygonSetProjected>(obj);
return kTRUE;
}
////////////////////////////////////////////////////////////////////////////////
/// Setup bounding-box information.
void TEvePolygonSetProjectedGL::SetBBox()
{
SetAxisAlignedBBox(fM->AssertBBox());
}
////////////////////////////////////////////////////////////////////////////////
/// Draw function for TEvePolygonSetProjectedGL.
/// Skips line-pass of outline mode.
void TEvePolygonSetProjectedGL::Draw(TGLRnrCtx& rnrCtx) const
{
if (rnrCtx.IsDrawPassOutlineLine())
return;
TGLObject::Draw(rnrCtx);
}
////////////////////////////////////////////////////////////////////////////////
/// Draw polygons outline.
void TEvePolygonSetProjectedGL::DrawOutline() const
{
if (fM->fPols.size() == 0) return;
Bool_t done_p = kFALSE;
if (fM->GetMiniFrame())
{
std::map<Edge_t, Int_t> edges;
for (TEvePolygonSetProjected::vpPolygon_ci i = fM->fPols.begin();
i != fM->fPols.end(); ++i)
{
for(Int_t k = 0; k < i->fNPnts - 1; ++k)
{
++edges[Edge_t(i->fPnts[k], i->fPnts[k+1])];
}
++edges[Edge_t(i->fPnts[0], i->fPnts[i->fNPnts - 1])];
}
glBegin(GL_LINES);
for (std::map<Edge_t, Int_t>::iterator i = edges.begin(); i != edges.end(); ++i)
{
if (i->second == 1)
{
glVertex3fv(fM->fPnts[i->first.fI].Arr());
glVertex3fv(fM->fPnts[i->first.fJ].Arr());
done_p = kTRUE;
}
}
glEnd();
}
if ( ! done_p)
{
for (TEvePolygonSetProjected::vpPolygon_ci i = fM->fPols.begin();
i != fM->fPols.end(); ++i)
{
glBegin(GL_LINE_LOOP);
for(Int_t k = 0; k < i->fNPnts; ++k)
{
glVertex3fv(fM->fPnts[i->fPnts[k]].Arr());
}
glEnd();
}
}
}
////////////////////////////////////////////////////////////////////////////////
/// Do GL rendering.
void TEvePolygonSetProjectedGL::DirectDraw(TGLRnrCtx& /*rnrCtx*/) const
{
if (fM->fPols.size() == 0) return;
glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_POLYGON_BIT);
glDisable(GL_LIGHTING);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glDisable(GL_CULL_FACE);
// This tells TGLObject we don't want display-lists in some cases.
fMultiColor = fM->fDrawFrame;
// polygons
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1, 1);
GLUtesselator *tessObj = TGLUtil::GetDrawTesselator3fv();
TEveVector* pnts = fM->fPnts;
for (TEvePolygonSetProjected::vpPolygon_ci i = fM->fPols.begin();
i != fM->fPols.end(); ++i)
{
Int_t vi; //current vertex index of curent polygon
Int_t pntsN = (*i).fNPnts; // number of points in current polygon
if (pntsN < 4)
{
glBegin(GL_POLYGON);
for (Int_t k = 0; k < pntsN; ++k)
{
vi = (*i).fPnts[k];
glVertex3fv(pnts[vi].Arr());
}
glEnd();
}
else
{
gluBeginPolygon(tessObj);
gluNextContour(tessObj, (GLenum)GLU_UNKNOWN);
glNormal3f(0, 0, 1);
Double_t coords[3];
coords[2] = 0;
for (Int_t k = 0; k < pntsN; ++k)
{
vi = (*i).fPnts[k];
coords[0] = pnts[vi].fX;
coords[1] = pnts[vi].fY;
gluTessVertex(tessObj, coords, pnts[vi].Arr());
}
gluEndPolygon(tessObj);
}
}
glDisable(GL_POLYGON_OFFSET_FILL);
// Outline
if (fM->fDrawFrame)
{
TGLUtil::Color(fM->fLineColor);
glEnable(GL_LINE_SMOOTH);
TGLUtil::LineWidth(fM->fLineWidth);
DrawOutline();
}
glPopAttrib();
}
////////////////////////////////////////////////////////////////////////////////
/// Draw polygons in highlight mode.
void TEvePolygonSetProjectedGL::DrawHighlight(TGLRnrCtx& rnrCtx, const TGLPhysicalShape* pshp, Int_t lvl) const
{
if (lvl < 0) lvl = pshp->GetSelected();
glColor4ubv(rnrCtx.ColorSet().Selection(lvl).CArr());
TGLUtil::LockColor();
if (fM->GetHighlightFrame())
{
DrawOutline();
}
else
{
Draw(rnrCtx);
}
TGLUtil::UnlockColor();
}