27 const Int_t TGLPlotBox::fgFramePlanes[][4] =
35 const Double_t TGLPlotBox::fgNormals[][3] =
43 const Int_t TGLPlotBox::fgBackPairs[][2] =
51 const Int_t TGLPlotBox::fgFrontPairs[][2] =
62 TGLPlotBox::TGLPlotBox(Bool_t xoy, Bool_t xoz, Bool_t yoz)
75 fSelectablePairs[0][0] = xoz;
76 fSelectablePairs[0][1] = yoz;
78 fSelectablePairs[1][0] = yoz;
79 fSelectablePairs[1][1] = xoz;
81 fSelectablePairs[2][0] = xoz;
82 fSelectablePairs[2][1] = yoz;
84 fSelectablePairs[3][0] = yoz;
85 fSelectablePairs[3][1] = xoz;
92 TGLPlotBox::~TGLPlotBox()
98 void TGLPlotBox::DrawBack(Int_t selected, Bool_t selectionPass,
const std::vector<Double_t> &zLevels,
99 Bool_t highColor)
const
102 TGLDisableGuard depthTest(GL_DEPTH_TEST);
103 glDepthMask(GL_FALSE);
105 if (!selectionPass) {
107 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
108 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
109 glEnable(GL_LINE_SMOOTH);
113 Float_t backColor[] = {0.9f, 0.9f, 0.9f, 0.85f};
115 fFrameColor->GetRGB(backColor[0], backColor[1], backColor[2]);
117 if (!selectionPass) {
118 glMaterialfv(GL_FRONT, GL_DIFFUSE, backColor);
121 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Rgl::gGreenEmission)
123 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Rgl::gRedEmission);
126 ObjectIDToColor(1, highColor);
128 DrawQuadFilled(f3DBox[0], f3DBox[1], f3DBox[2], f3DBox[3], TGLVector3(0., 0., 1.));
130 if (!selectionPass) {
132 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Rgl::gNullEmission);
133 else if (selected == 2)
134 fSelectablePairs[fFrontPoint][0] ? glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Rgl::gGreenEmission)
135 : glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Rgl::gRedEmission);
137 ObjectIDToColor(2, highColor);
139 DrawBackPlane(fgBackPairs[fFrontPoint][0], selectionPass, zLevels);
141 if (!selectionPass) {
143 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Rgl::gNullEmission);
144 else if (selected == 3)
145 fSelectablePairs[fFrontPoint][1] ? glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Rgl::gGreenEmission)
146 : glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Rgl::gRedEmission);
148 ObjectIDToColor(3, highColor);
150 DrawBackPlane(fgBackPairs[fFrontPoint][1], selectionPass, zLevels);
152 glDepthMask(GL_TRUE);
153 if (!selectionPass) {
155 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Rgl::gNullEmission);
157 glDisable(GL_LINE_SMOOTH);
163 void TGLPlotBox::DrawFront()
const
167 const TGLDisableGuard lightGuard(GL_LIGHTING);
172 glColor3d(0., 0., 0.);
174 const Int_t *vertInd = fgFramePlanes[fgFrontPairs[fFrontPoint][0]];
175 DrawQuadOutline(f3DBox[vertInd[0]], f3DBox[vertInd[1]], f3DBox[vertInd[2]], f3DBox[vertInd[3]]);
177 vertInd = fgFramePlanes[fgFrontPairs[fFrontPoint][1]];
178 DrawQuadOutline(f3DBox[vertInd[0]], f3DBox[vertInd[1]], f3DBox[vertInd[2]], f3DBox[vertInd[3]]);
184 void TGLPlotBox::DrawBox(Int_t selected, Bool_t selectionPass,
const std::vector<Double_t> &zLevels,
185 Bool_t highColor)
const
188 DrawBack(selected, selectionPass, zLevels, highColor);
190 if (fDrawFront && !selectionPass)
198 void TGLPlotBox::SetPlotBox(
const Rgl::Range_t &x,
const Rgl::Range_t &y,
const Rgl::Range_t &z)
200 f3DBox[0].Set(x.first, y.first, z.first);
201 f3DBox[1].Set(x.second, y.first, z.first);
202 f3DBox[2].Set(x.second, y.second, z.first);
203 f3DBox[3].Set(x.first, y.second, z.first);
204 f3DBox[4].Set(x.first, y.first, z.second);
205 f3DBox[5].Set(x.second, y.first, z.second);
206 f3DBox[6].Set(x.second, y.second, z.second);
207 f3DBox[7].Set(x.first, y.second, z.second);
213 void TGLPlotBox::SetPlotBox(
const Rgl::Range_t &x, Double_t xr,
const Rgl::Range_t &y, Double_t yr,
214 const Rgl::Range_t &z, Double_t zr)
226 void TGLPlotBox::SetFrameColor(
const TColor *color)
233 bool Compare(
const TGLVertex3 &v1,
const TGLVertex3 &v2)
235 return v1.Z() < v2.Z();
245 Int_t TGLPlotBox::FindFrontPoint()
const
247 Double_t mvMatrix[16] = {0.};
248 glGetDoublev(GL_MODELVIEW_MATRIX, mvMatrix);
249 Double_t prMatrix[16] = {0.};
250 glGetDoublev(GL_PROJECTION_MATRIX, prMatrix);
251 Int_t viewport[4] = {0};
252 glGetIntegerv(GL_VIEWPORT, viewport);
254 const Double_t zMin = f3DBox[0].Z();
255 const Double_t zMax = f3DBox[4].Z();
257 const Double_t uBox[][2] = {{-fRangeXU / 2., -fRangeYU / 2.},
258 { fRangeXU / 2., -fRangeYU / 2.},
259 { fRangeXU / 2., fRangeYU / 2.},
260 {-fRangeXU / 2., fRangeYU / 2.}};
262 for (Int_t i = 0; i < 4; ++i) {
263 gluProject(f3DBox[i].X(), f3DBox[i].Y(), zMin, mvMatrix, prMatrix, viewport,
264 &f2DBox[i].X(), &f2DBox[i].Y(), &f2DBox[i].Z());
265 gluProject(f3DBox[i].X(), f3DBox[i].Y(), zMax, mvMatrix, prMatrix, viewport,
266 &f2DBox[i + 4].X(), &f2DBox[i + 4].Y(), &f2DBox[i + 4].Z());
268 gluProject(uBox[i][0], uBox[i][1], -0.5, mvMatrix, prMatrix, viewport,
269 &f2DBoxU[i].X(), &f2DBoxU[i].Y(), &f2DBoxU[i].Z());
270 gluProject(uBox[i][0], uBox[i][1], 0.5, mvMatrix, prMatrix, viewport,
271 &f2DBoxU[i + 4].X(), &f2DBoxU[i + 4].Y(), &f2DBoxU[i + 4].Z());
276 TGLUtil::InitializeIfNeeded();
277 const Float_t scale = TGLUtil::GetScreenScalingFactor();
279 for (Int_t i = 0; i < 8; ++i) {
281 f2DBoxU[i].X() /= scale;
282 f2DBoxU[i].Y() /= scale;
287 return fFrontPoint = std::min_element(f2DBoxU, f2DBoxU + 4, Compare) - f2DBoxU;
294 Int_t TGLPlotBox::GetFrontPoint()
const
303 const TGLVertex3 *TGLPlotBox::Get3DBox()
const
312 const TGLVertex3 *TGLPlotBox::Get2DBox()
const
321 void TGLPlotBox::DrawBackPlane(Int_t plane, Bool_t selectionPass,
322 const std::vector<Double_t> &zLevels)
const
325 const Int_t *vertInd = fgFramePlanes[plane];
326 DrawQuadFilled(f3DBox[vertInd[0]], f3DBox[vertInd[1]], f3DBox[vertInd[2]],
327 f3DBox[vertInd[3]], fgNormals[plane]);
329 if (!selectionPass) {
330 const TGLDisableGuard lightGuard(GL_LIGHTING);
331 glColor3d(0., 0., 0.);
332 DrawQuadOutline(f3DBox[vertInd[0]], f3DBox[vertInd[1]],
333 f3DBox[vertInd[2]], f3DBox[vertInd[3]]);
335 const TGLEnableGuard stippleGuard(GL_LINE_STIPPLE);
336 const UShort_t stipple = 0x5555;
337 glLineStipple(1, stipple);
339 Double_t lineCaps[][4] =
341 {f3DBox[1].X(), f3DBox[0].Y(), f3DBox[0].X(), f3DBox[0].Y()},
342 {f3DBox[1].X(), f3DBox[0].Y(), f3DBox[1].X(), f3DBox[2].Y()},
343 {f3DBox[1].X(), f3DBox[2].Y(), f3DBox[0].X(), f3DBox[3].Y()},
344 {f3DBox[0].X(), f3DBox[3].Y(), f3DBox[0].X(), f3DBox[0].Y()}
347 for (UInt_t i = 0; i < zLevels.size(); ++i) {
349 glVertex3d(lineCaps[plane][0], lineCaps[plane][1], zLevels[i]);
350 glVertex3d(lineCaps[plane][2], lineCaps[plane][3], zLevels[i]);