Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGLCameraOverlay.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Alja Mrak-Tadel 2007
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 "TGLIncludes.h"
13#include "TGLCameraOverlay.h"
14#include "TGLViewer.h"
15#include "TGLCamera.h"
16#include "TGLSelectRecord.h"
17#include "TGLUtil.h"
18#include "TGLRnrCtx.h"
19#include "TGLAxisPainter.h"
20
21#include "TMath.h"
22#include "TAxis.h"
23#include "THLimitsFinder.h"
24
25/** \class TGLCameraOverlay
26\ingroup opengl
27A GL overlay element which displays camera furstum.
28*/
29
30
31////////////////////////////////////////////////////////////////////////////////
32
35
36 fShowOrthographic(showOrtho),
37 fShowPerspective(showPersp),
38
39 fOrthographicMode(kAxis),
40 fPerspectiveMode(kPlaneIntersect),
41
42 fAxisPainter(nullptr),
43 fAxis(nullptr),
44 fAxisExtend(0.9),
45 fUseAxisColors(kFALSE),
46
47 fExternalRefPlane(),
48 fUseExternalRefPlane(kFALSE)
49{
50 // Constructor.
51
52 fFrustum[0] = fFrustum[1] = fFrustum[2] = fFrustum[3] = 0;
53
54 fAxis = new TAxis();
55 fAxis->SetNdivisions(710);
56 fAxis->SetLabelSize(0.018);
57 fAxis->SetLabelOffset(0.01);
60
64}
65
66////////////////////////////////////////////////////////////////////////////////
67/// Destructor.
68
74
75////////////////////////////////////////////////////////////////////////////////
76/// Get axis attributes.
77
79{
80 return dynamic_cast<TAttAxis*>(fAxis);
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Set frustum values from given camera.
85
87{
88 TGLVector3 absRef(1., 1., 1.); // needed in case if orthographic camera is negative
89 Float_t l = -cam.FrustumPlane(TGLCamera::kLeft).D() * Dot(cam.GetCamBase().GetBaseVec(2), absRef);
90 Float_t r = cam.FrustumPlane(TGLCamera::kRight).D() * Dot(cam.GetCamBase().GetBaseVec(2), absRef);
91 Float_t t = cam.FrustumPlane(TGLCamera::kTop).D();
92 Float_t b = -cam.FrustumPlane(TGLCamera::kBottom).D();
93
94 fFrustum[0] = l;
95 fFrustum[1] = b;
96 fFrustum[2] = r;
97 fFrustum[3] = t;
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Draw cross section coordinates in top right corner of screen.
102
104{
105 TGLCamera &cam = rnrCtx.RefCamera();
106 // get eye line
107 const TGLMatrix& mx = cam.GetCamBase() * cam.GetCamTrans();
108 TGLVertex3 d = mx.GetTranslation();
109 TGLVertex3 p = d + mx.GetBaseVec(1);
110 TGLLine3 line(d, p);
111 // get ref plane
113 TGLPlane(cam.GetCamBase().GetBaseVec(3), TGLVertex3());
114 // get intersection
115 std::pair<Bool_t, TGLVertex3> intersection;
117
118 if (intersection.first)
119 {
120 TGLVertex3 v = intersection.second;
121
123 glPushMatrix();
125
127 glPushMatrix();
129
130 TGLRect &vp = rnrCtx.GetCamera()->RefViewport();
131 TGLFont font;
132 Int_t fs = TMath::Nint(TMath::Sqrt(vp.Width()*vp.Width() + vp.Height()*vp.Height())*0.02);
133 rnrCtx.RegisterFontNoScale(fs, "arial", TGLFont::kPixmap, font);
134 const char* txt = Form("(%f, %f, %f)", v[0], v[1], v[2]);
135 TGLUtil::Color(rnrCtx.ColorSet().Markup());
136 font.Render(txt, 0.98, 0.98, 0, TGLFont::kRight, TGLFont::kBottom);
137
138 // render cross
140 Float_t w = 0.02; // cross size
141 Float_t ce = 0.15; // empty space
142 glBegin(GL_LINES);
143 glVertex2f(0 +w*ce, 0);
144 glVertex2f(0 +w, 0);
145
146 glVertex2f(0 -w*ce, 0);
147 glVertex2f(0 -w, 0);
148
149 Float_t h = w*vp.Width()/vp.Height();
150 glVertex2f(0, 0 +h*ce);
151 glVertex2f(0, 0 +h);
152
153 glVertex2f(0, 0 -h*ce);
154 glVertex2f(0, 0 -h);
155 glEnd();
156
157 glPopMatrix();
159 glPopMatrix();
161 }
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// Draw axis on four edges and a transparent grid.
166
168{
171
172 Color_t lineColor = fUseAxisColors ? fAxis->GetAxisColor() : rnrCtx.ColorSet().Markup().GetColorIndex();
173
174 // font size calculated relative to viewport diagonal
176 Float_t rl = 0.5 *((vp[2]-vp[0]) + (vp[3]-vp[1]));
178 // tick length
179 Float_t tlY = 0.015*rl/(vp[2]-vp[0]);
180 Float_t tlX = 0.015*rl/(vp[3]-vp[1]);
181 // corner vectors
183 TGLVector3 xdir = rnrCtx.RefCamera().GetCamBase().GetBaseVec(2); xdir.Normalise(); // left
184 if (fFrustum[2] > fFrustum[0] )
185 {
186 minX = fFrustum[0];
187 maxX = fFrustum[2];
188 }
189 else {
190 xdir = -xdir;
191 minX = fFrustum[2];
192 maxX = fFrustum[0];
193 }
194
195 TGLVector3 ydir = rnrCtx.RefCamera().GetCamBase().GetBaseVec(3); ydir.Normalise(); // up
198
201 // range
202 Double_t rngY = fFrustum[3] - fFrustum[1];
204 Double_t off = TMath::Sqrt((rngX*rngX)+(rngY*rngY)) * 0.03;
205 Double_t minY = fFrustum[1] + off;
206 Double_t maxY = fFrustum[3] - off;
207 minX += off;
208 maxX -= off;
209
210 // grid lines
211 Char_t alpha = 80; //primary
212 Char_t alpha2 = 90; //secondary
214 GLushort stipple = 0x5555; // 33333 more rare
215
216 // horizontal X
217 //
223
224 // bottom
225 glPushMatrix();
226 glTranslated(vy1.X(), vy1.Y(), vy1.Z());
229 glPopMatrix();
230
231 // top
232 glPushMatrix();
233 glTranslated(vy2.X(), vy2.Y(), vy2.Z());
238 glPopMatrix();
239
241 if (grid)
242 {
244 TGLVector3 tmp;
245 // draw label vertical lines
247 glBegin(GL_LINES);
248 for (TGLAxisPainter::LabVec_t::iterator i = labs.begin(); i != labs.end(); ++i) {
249 tmp = vy1 + xdir * (i->first);
250 glVertex3dv(tmp.Arr());
251 tmp = vy2 + xdir * (i->first);
252 glVertex3dv(tmp.Arr());
253 }
254 glEnd();
255
256 // secondary tick mark lines
257 if (labs.size() > 1)
258 {
263
264 glBegin(GL_LINES);
265 Int_t ondiv = 0;
266 Double_t omin = 0, omax = 0, bw1 = 0;
267 THLimitsFinder::Optimize(labs[0].second, labs[1].second, secSteps, omin, omax, ondiv, bw1);
268 Double_t val = labs[0].second;
269 while (val < fFrustum[2])
270 {
271 for (Int_t k=0; k<ondiv; k++)
272 {
273 val += bw1;
274 tmp = vy1 + xdir * val;
275 glVertex3dv(tmp.Arr());
276 tmp = vy2 + xdir * val;
277 glVertex3dv(tmp.Arr());
278 }
279 }
280 val = labs[0].second - bw1;
281 while(val > fFrustum[0])
282 {
283 tmp = vy1 + xdir * val;
284 glVertex3dv(tmp.Arr());
285 tmp = vy2 + xdir * val;
286 glVertex3dv(tmp.Arr());
287 val -= bw1;
288 }
289 glEnd();
290 glPopAttrib();
291 }
292 } // draw grid
293
294 //
295 // vertical Y axis
296 //
297
302 // left
303 glPushMatrix();
304 glTranslated(vx1.X(), vx1.Y(), vx1.Z());
307 glPopMatrix();
308 // right
309 glPushMatrix();
310 glTranslated(vx2.X(), vx2.Y(), vx2.Z());
315 glPopMatrix();
316
317 if (grid)
318 {
320 TGLVector3 tmp;
321 // draw label horizontal lines
323 glBegin(GL_LINES);
324 for (TGLAxisPainter::LabVec_t::iterator i = labs.begin(); i != labs.end(); ++i) {
325 tmp = vx1 + ydir *(i->first);
326 glVertex3dv(tmp.Arr());
327 tmp = vx2 + ydir *(i->first);
328 glVertex3dv(tmp.Arr());
329 }
330 glEnd();
331
332 // secondary tick mark lines
333 if (labs.size() > 1)
334 {
339
340 glBegin(GL_LINES);
341 Int_t ondiv;
342 Double_t omin = 0, omax = 0, bw1 = 0;
343 Double_t val = 0;
344 THLimitsFinder::Optimize(labs[0].second, labs[1].second, secSteps, omin, omax, ondiv, bw1);
345 val = labs[0].second;
346 while(val < fFrustum[3])
347 {
348 for(Int_t k=0; k<ondiv; k++)
349 {
350 val += bw1;
351 tmp = vx1 + ydir *val;
352 glVertex3dv(tmp.Arr());
353 tmp = vx2 + ydir * val;
354 glVertex3dv(tmp.Arr());
355 }
356 }
357
358 val = labs[0].second - bw1;
359 while(val > fFrustum[1])
360 {
361 tmp = vx1 + ydir *val;
362 glVertex3dv(tmp.Arr());
363 tmp = vx2 + ydir * val;
364 glVertex3dv(tmp.Arr());
365 val -= bw1;
366 }
367 glEnd();
368 glPopAttrib();
369 }
370 } // draw grid
371}
372
373////////////////////////////////////////////////////////////////////////////////
374/// Show frustum size with fixed screen line length and printed value.
375
377{
378 // factors 10, 5 and 2 are allowed
380 Float_t barsize= 0.14* wfrust;
384 if (fact > 5)
385 {
386 red = 5*TMath::Power(10, exp);
387 }
388 else if (fact > 2)
389 {
390 red = 2*TMath::Power(10, exp);
391 } else
392 {
393 red = TMath::Power(10, exp);
394 }
395
397 TGLVector3 xdir = rnrCtx.RefCamera().GetCamBase().GetBaseVec(2); // left
398 TGLVector3 ydir = rnrCtx.RefCamera().GetCamBase().GetBaseVec(3); // up
399 xdir.Normalise();
400 ydir.Normalise();
401
402 TGLUtil::Color(rnrCtx.ColorSet().Foreground());
403
404 const char* txt = Form("%.*f", (exp < 0) ? -exp : 0, red);
405 Float_t bb[6];
406 TGLFont font;
407 rnrCtx.RegisterFont(12, "arial", TGLFont::kPixmap, font);
408 font.BBox(txt, bb[0], bb[1], bb[2], bb[3], bb[4], bb[5]);
409 TGLRect &vp = rnrCtx.GetCamera()->RefViewport();
410 Double_t mH = (fFrustum[3]-fFrustum[1])*bb[4]/vp.Height();
411 glPushMatrix();
412 v = xdir*(fFrustum[2]-barsize) + ydir*(fFrustum[3] - mH*1.5);
413 glTranslated(v.X(), v.Y(), v.Z());
414 glRasterPos2i(0,0);
415 font.Render(txt);
416 glPopMatrix();
417
420 glPushMatrix();
421 Float_t xt = fFrustum[2] - 1.1*barsize;
422 Float_t yt = fFrustum[3] - 2.1*mH;
423 v = xdir*xt + ydir*yt;
424 glTranslated(v.X(), v.Y(), v.Z());
425
426 glBegin(GL_LINES);
427 // horizontal static
428 v = red*xdir;
429 glVertex3dv(v.Arr());
430 v = barsize*xdir;
431 glVertex3dv(v.Arr());
432 // corner bars end
433 v = xdir*barsize + ydir*mH;
434 glVertex3dv(v.Arr());
435 v = xdir*barsize - ydir*mH;
436 glVertex3dv(v.Arr());
437 // corner bar start
439 v = ydir*mH;
440 glVertex3dv(v.Arr());
441 v.Negate();
442 glVertex3dv(v.Arr());
443 // marker pointer
444 v = red*ydir;
445 glVertex3dv(v.Arr());
446 v += ydir*mH;
447 glVertex3dv(v.Arr());
448 //marker line
449 glVertex3d(0, 0., 0.);
450 v = red*xdir;
451 glVertex3dv(v.Arr());
452 glEnd();
453 glPopAttrib();
454 glPopMatrix();
455}
456
457////////////////////////////////////////////////////////////////////////////////
458/// Display coordinates info of current frustum.
459
461{
462 TGLCamera &cam = rnrCtx.RefCamera();
463
464 if (rnrCtx.Selection() ||
465 (cam.IsPerspective() && ! fShowPerspective) ||
466 (cam.IsOrthographic() && ! fShowOrthographic))
467 {
468 return;
469 }
470
474
475 TGLUtil::Color(rnrCtx.ColorSet().Markup());
479
481
482 if (cam.IsOrthographic())
483 {
484 switch (fOrthographicMode)
485 {
486 case kBar:
487 glDepthRange(0, 0.1);
489 break;
490 case kAxis:
491 glDepthRange(0, 0.1);
493 break;
494 case kGridFront:
495 glDepthRange(0, 0.1);
497 break;
498 case kGridBack:
499 glDepthRange(1, 0.9);
501 break;
502 default:
503 break;
504 };
505 }
506 else
507 {
509 }
510
512 glPopAttrib();
513}
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define h(i)
Definition RSha256.hxx:106
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
short Color_t
Color number (short)
Definition RtypesCore.h:99
char Char_t
Character 1 byte (char)
Definition RtypesCore.h:51
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kGray
Definition Rtypes.h:66
@ kRed
Definition Rtypes.h:67
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Double_t Dot(const TGLVector3 &v1, const TGLVector3 &v2)
Definition TGLUtil.h:317
std::pair< Bool_t, TGLLine3 > Intersection(const TGLPlane &p1, const TGLPlane &p2)
Find 3D line interestion of this plane with 'other'.
Definition TGLUtil.cxx:511
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize fs
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char mx
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2495
@ kAxis
const_iterator begin() const
const_iterator end() const
Manages histogram axis attributes.
Definition TAttAxis.h:19
virtual Int_t GetNdivisions() const
Definition TAttAxis.h:37
virtual Color_t GetAxisColor() const
Definition TAttAxis.h:38
virtual void SetAxisColor(Color_t color=1, Float_t alpha=1.)
Set color of the line axis and tick marks.
Definition TAttAxis.cxx:141
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels.
Definition TAttAxis.cxx:184
virtual void SetLabelOffset(Float_t offset=0.005)
Set distance between the axis and the labels.
Definition TAttAxis.cxx:172
virtual Float_t GetLabelSize() const
Definition TAttAxis.h:42
virtual void SetTickLength(Float_t length=0.03)
Set tick mark length.
Definition TAttAxis.cxx:265
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition TAttAxis.cxx:214
virtual void SetLabelColor(Color_t color=1, Float_t alpha=1.)
Set color of labels.
Definition TAttAxis.cxx:151
Class to manage histogram axis.
Definition TAxis.h:32
virtual void SetLimits(Double_t xmin, Double_t xmax)
Definition TAxis.h:166
Utility class to paint axis in GL.
void RnrLabels() const
Render label reading prepared list ov value-pos pairs.
void RnrLines() const
Render axis main line and tick-marks.
TGLVector3 & RefDir()
void SetLabelAlign(TGLFont::ETextAlignH_e, TGLFont::ETextAlignV_e)
Set label align.
std::vector< Lab_t > LabVec_t
LabVec_t & RefLabVec()
void SetUseAxisColors(Bool_t x)
void SetAttAxis(TAttAxis *a)
void SetLabelPixelFontSize(Int_t fs)
TGLVector3 & RefTMOff(Int_t i)
void SetFontMode(TGLFont::EMode m)
void PaintAxis(TGLRnrCtx &ctx, TAxis *ax)
GL render TAxis.
void RenderAxis(TGLRnrCtx &rnrCtx, Bool_t drawGrid)
Draw axis on four edges and a transparent grid.
TGLAxisPainter * fAxisPainter
void SetFrustum(TGLCamera &cam)
Set frustum values from given camera.
~TGLCameraOverlay() override
Destructor.
void RenderPlaneIntersect(TGLRnrCtx &rnrCtx)
Draw cross section coordinates in top right corner of screen.
TAttAxis * GetAttAxis()
Get axis attributes.
void Render(TGLRnrCtx &rnrCtx) override
Display coordinates info of current frustum.
TGLCameraOverlay(const TGLCameraOverlay &)=delete
void RenderBar(TGLRnrCtx &rnrCtx)
Show frustum size with fixed screen line length and printed value.
Abstract base camera class - concrete classes for orthographic and perspective cameras derive from it...
Definition TGLCamera.h:44
A wrapper class for FTFont.
void BBox(const char *txt, Float_t &llx, Float_t &lly, Float_t &llz, Float_t &urx, Float_t &ury, Float_t &urz) const
Get bounding box.
void Render(const char *txt, Double_t x, Double_t y, Double_t angle, Double_t mgn) const
3D space, fixed length, line class, with direction / length 'vector', passing through point 'vertex'.
Definition TGLUtil.h:387
16 component (4x4) transform matrix - column MAJOR as per GL.
Definition TGLUtil.h:598
An overlay element.
Definition TGLOverlay.h:23
3D plane class - of format Ax + By + Cz + D = 0
Definition TGLUtil.h:525
Viewport (pixel base) 2D rectangle class.
Definition TGLUtil.h:422
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition TGLRnrCtx.h:41
static void ColorTransparency(Color_t color_index, Char_t transparency=0)
Set color from color_index and ROOT-style transparency (default 0).
Definition TGLUtil.cxx:1732
static void Color(const TGLColor &color)
Set color from TGLColor.
Definition TGLUtil.cxx:1688
static Float_t LineWidth()
Get the line-width, taking the global scaling into account.
Definition TGLUtil.cxx:1934
3 component (x/y/z) vector class.
Definition TGLUtil.h:248
3 component (x/y/z) vertex class.
Definition TGLUtil.h:84
void Negate()
Definition TGLUtil.h:141
static void Optimize(Double_t A1, Double_t A2, Int_t nold, Double_t &BinLow, Double_t &BinHigh, Int_t &nbins, Double_t &BWID, Option_t *option="")
Static function to compute reasonable axis limits.
TLine * line
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
Definition TMath.h:704
Double_t Floor(Double_t x)
Rounds x downward, returning the largest integral value that is not greater than x.
Definition TMath.h:691
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:673
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition TMath.h:732
Double_t Log10(Double_t x)
Returns the common (base-10) logarithm of x.
Definition TMath.h:773
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:124
TLine l
Definition textangle.C:4