ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TGLPadUtils.cxx
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Timur Pocheptsov 06/05/2009
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2009, 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 "Riostream.h"
13 #include <stdexcept>
14 #include <cassert>
15 
16 #include "TVirtualPad.h"
17 #include "TVirtualX.h"
18 #include "RStipples.h"
19 #include "TColor.h"
20 #include "TROOT.h"
21 #include "TMath.h"
22 
23 #include "TGLPadUtils.h"
24 #include "TGLIncludes.h"
25 
26 namespace Rgl {
27 namespace Pad {
28 
29 const UInt_t PolygonStippleSet::fgBitSwap[] = {0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15};
30 
31 
32 /*
33 Temporary fix.
34 */
35 #ifndef GL_VERSION_1_2
36 const GLenum lineWidthPNAME = GLenum(0xB22);
37 const GLenum pointSizePNAME = GLenum(0xB12);
38 #else
39 const GLenum lineWidthPNAME = GLenum(GL_SMOOTH_LINE_WIDTH_RANGE);//Cast for real enums and macros.
40 const GLenum pointSizePNAME = GLenum(GL_SMOOTH_POINT_SIZE_RANGE);
41 #endif
42 
43 /*
44 Auxiliary class to converts ROOT's polygon stipples from
45 RStipples.h into GL's stipples and hold them in a fStipples array.
46 */
47 ////////////////////////////////////////////////////////////////////////////////
48 
50 {
51  /*
52  I have to assume, that gStipple has two chars in a line.
53  There in no way to calculate line length and there are no corresponding constants in RStipple.h.
54  So, these numbers are hardcode here.
55  Ordering in RStipples completely different from OpenGL.
56  In OpenGL, if I have, say, 16x2 pattern, GLbytes will be:
57 
58  [3][4]
59  [1][2]
60 
61  and bits inside them
62 
63  [7 6 5 4 3 2 1 0][7 6 5 4 3 2 1 0]
64  [7 6 5 4 3 2 1 0][7 6 5 4 3 2 1 0].
65 
66  But for X11 this will be:
67 
68  [2][1]
69  [4][3]
70 
71  [0 1 2 3 4 5 6 7][0 1 2 3 4 5 6 7]
72  [0 1 2 3 4 5 6 7][0 1 2 3 4 5 6 7]
73 
74  So, line 0x7, 0xE from X11 must be
75  converted into 0x70, 0xE0 for OpenGL.
76 
77  As OpenGL expects 32x32 pattern, I have to twice each line.
78  */
79 
80  /*If somebody will seriously change gStipples declaration,
81  so, that sizeof gStipples becomes "wrong", change this!*/
82  const UInt_t numOfStipples = sizeof gStipples / sizeof gStipples[0];
83  fStipples.resize(kStippleSize * numOfStipples);
84 
85  for (UInt_t i = 0; i < numOfStipples; ++i) {
86  const UInt_t baseInd = i * kStippleSize;
87 
88  for (Int_t j = 15, j1 = 0; j >= 0; --j, ++j1) {//ROOT uses 16x16 stipples.
89  const UInt_t rowShift = j1 * kRowSize;
90 
91  for (Int_t k = 1, k1 = 0; k >= 0; --k, ++k1) {//Two chars form a line.
92  const UChar_t pixel = SwapBits(gStipples[i][j * 2 + k]);
93  const UInt_t ind = baseInd + rowShift + k1;
94 
95  fStipples[ind] = pixel;
96  fStipples[ind + 2] = pixel;
97  fStipples[ind + 64] = pixel;
98  fStipples[ind + 66] = pixel;
99  }
100  }
101  }
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 
107 {
108 #ifdef WIN32
109  b = ~b & 0xff;
110 #endif
111  b &= k16Bits;
112 
113  const UInt_t low = fgBitSwap[b & kLow4] << 4;
114  const UInt_t up = fgBitSwap[(b & kUp4) >> 4];
115 
116  return low | up;
117 }
118 
119 /*
120 Class to manipulate fill parameters.
121 */
122 ////////////////////////////////////////////////////////////////////////////////
123 ///Polygon stipple, if required.
124 
126  : fStipple(0), fAlpha(1.)
127 {
128  const UInt_t style = gVirtualX->GetFillStyle() / 1000;
129 
130  if (!ignoreStipple) {
131  if (style == 3) {
132  const UInt_t fasi = gVirtualX->GetFillStyle() % 1000;
133  fStipple = (fasi >= 1 && fasi <=25) ? fasi : 2;
134  glPolygonStipple(&set.fStipples[fStipple * PolygonStippleSet::kStippleSize]);
135  glEnable(GL_POLYGON_STIPPLE);
136  }
137  }
138 
139  // Color and transparency
140  Float_t rgba[] = {0.f, 0.f, 0.f, 1.f};
141  ExtractRGBA(gVirtualX->GetFillColor(), rgba);
142  fAlpha = rgba[3];
143  if (fAlpha<1.) {
144  glEnable(GL_BLEND);
145  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
146  }
147  glColor4fv(rgba);
148 }
149 
150 ////////////////////////////////////////////////////////////////////////////////
151 
153 {
154  if (fStipple)
155  glDisable(GL_POLYGON_STIPPLE);
156 
157  if (fAlpha<1.)
158  glDisable(GL_BLEND);
159 }
160 
161 /*
162 "ROOT like" line stipples.
163 */
164 
165 const UShort_t gLineStipples[] = {0xffff, 0xffff, 0x3333, 0x5555,
166  0xf040, 0xf4f4, 0xf111, 0xf0f0,
167  0xff11, 0x3fff, 0x08ff};
168 
169 const UInt_t gMaxStipple = sizeof gLineStipples / sizeof gLineStipples[0];
170 
171 /*
172 Set/unset line attributes.
173 */
174 ////////////////////////////////////////////////////////////////////////////////
175 ///Set up line parameters.
176 ///Smooth.
177 
178 LineAttribSet::LineAttribSet(Bool_t smooth, UInt_t stipple, Double_t maxWidth, Bool_t setWidth)
179  : fSmooth(smooth), fStipple(stipple), fSetWidth(setWidth), fAlpha(0.8)
180 {
181  if (fSmooth) {
182  glEnable(GL_BLEND);
183  glEnable(GL_LINE_SMOOTH);
184  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
185  glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
186  }
187 
188  //Stipple.
189  if (fStipple > 1) {
190  if (fStipple >= gMaxStipple)
191  fStipple = 1;
192  else {
193  glEnable(GL_LINE_STIPPLE);
194  glLineStipple(fStipple == 10 ? 2 : 1, gLineStipples[fStipple]);
195  }
196  }
197 
198  //Color and transparency
199  Float_t rgba[] = {0.f, 0.f, 0.f, 0.8f};
200  ExtractRGBA(gVirtualX->GetLineColor(), rgba);
201  fAlpha = rgba[3];
202  if (fAlpha<0.8) {
203  glEnable(GL_BLEND);
204  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
205  }
206  glColor4fv(rgba);
207 
208  //Width.
209  if (fSetWidth) {
210  const Width_t w = gVirtualX->GetLineWidth();
211  glLineWidth(w > maxWidth ? maxWidth : !w ? 1.f : w);
212  }
213 }
214 
215 ////////////////////////////////////////////////////////////////////////////////
216 
218 {
219  if (fSmooth || fAlpha<0.8) {
220  glDisable(GL_LINE_SMOOTH);
221  glDisable(GL_BLEND);
222  }
223 
224  if (fStipple > 1)
225  glDisable(GL_LINE_STIPPLE);
226 
227  if (fSetWidth)
228  glLineWidth(1.f);
229 }
230 
231 /*
232 Auxiliary class to draw markers in a gl-pad.
233 */
234 ////////////////////////////////////////////////////////////////////////////////
235 ///Simple 1-pixel dots.
236 
238 {
239  glBegin(GL_POINTS);
240 
241  for (UInt_t i = 0; i < n; ++i)
242  glVertex2d(xy[i].fX, xy[i].fY);
243 
244  glEnd();
245 }
246 
247 ////////////////////////////////////////////////////////////////////////////////
248 ///+ sign. 1 pixel width lines.
249 
251 {
252  const Double_t im = 4 * gVirtualX->GetMarkerSize() + 0.5;
253  glBegin(GL_LINES);
254 
255  for (UInt_t i = 0; i < n; ++i) {
256  const Double_t x = xy[i].fX;
257  const Double_t y = xy[i].fY;
258  glVertex2d(-im + x, y);
259  glVertex2d(im + x, y);
260  glVertex2d(x, -im + y);
261  glVertex2d(x, im + y);
262  }
263 
264  glEnd();
265 }
266 
267 ////////////////////////////////////////////////////////////////////////////////
268 ///* - marker.
269 
271 {
272  SCoord_t im = SCoord_t(4 * gVirtualX->GetMarkerSize() + 0.5);
273  fStar[0].fX = -im; fStar[0].fY = 0;
274  fStar[1].fX = im; fStar[1].fY = 0;
275  fStar[2].fX = 0 ; fStar[2].fY = -im;
276  fStar[3].fX = 0 ; fStar[3].fY = im;
277  im = SCoord_t(0.707*Float_t(im) + 0.5);
278  fStar[4].fX = -im; fStar[4].fY = -im;
279  fStar[5].fX = im; fStar[5].fY = im;
280  fStar[6].fX = -im; fStar[6].fY = im;
281  fStar[7].fX = im; fStar[7].fY = -im;
282 
283  glBegin(GL_LINES);
284 
285  for (UInt_t i = 0; i < n; ++i) {
286  const Double_t x = xy[i].fX;
287  const Double_t y = xy[i].fY;
288 
289  glVertex2d(fStar[0].fX + x, fStar[0].fY + y);
290  glVertex2d(fStar[1].fX + x, fStar[1].fY + y);
291  glVertex2d(fStar[2].fX + x, fStar[2].fY + y);
292  glVertex2d(fStar[3].fX + x, fStar[3].fY + y);
293  glVertex2d(fStar[4].fX + x, fStar[4].fY + y);
294  glVertex2d(fStar[5].fX + x, fStar[5].fY + y);
295  glVertex2d(fStar[6].fX + x, fStar[6].fY + y);
296  glVertex2d(fStar[7].fX + x, fStar[7].fY + y);
297  }
298 
299  glEnd();
300 }
301 
302 ////////////////////////////////////////////////////////////////////////////////
303 
305 {
306  const Double_t im = 0.707 * (4 * gVirtualX->GetMarkerSize() + 0.5) + 0.5;
307 
308  glBegin(GL_LINES);
309 
310  for (UInt_t i = 0; i < n; ++i) {
311  const Double_t x = xy[i].fX;
312  const Double_t y = xy[i].fY;
313 
314  glVertex2d(-im + x, -im + y);
315  glVertex2d(im + x, im + y);
316  glVertex2d(-im + x, im + y);
317  glVertex2d(im + x, -im + y);
318  }
319 
320  glEnd();
321 }
322 
323 ////////////////////////////////////////////////////////////////////////////////
324 
326 {
327  glBegin(GL_LINES);
328 
329  for (UInt_t i = 0; i < n; ++i) {
330  const Double_t x = xy[i].fX;
331  const Double_t y = xy[i].fY;
332 
333  glVertex2d(-1. + x, y);
334  glVertex2d(x + 1., y);
335  glVertex2d(x, -1. + y);
336  glVertex2d(x, 1. + y);
337  }
338 
339  glEnd();
340 }
341 
342 ////////////////////////////////////////////////////////////////////////////////
343 
345 {
346  for (UInt_t i = 0; i < n; ++i)
347  glRectd(xy[i].fX - 1, xy[i].fY - 1, xy[i].fX + 1, xy[i].fY + 1);
348 }
349 
350 namespace {
351 //Auxilary function for MarkerPainter. Define near the end of this source file.
352 void CalculateCircle(std::vector<TPoint> &circle, Double_t r, UInt_t pts);
353 }
354 
355 ////////////////////////////////////////////////////////////////////////////////
356 
358 {
359  Double_t r = 4 * gVirtualX->GetMarkerSize() + 0.5;
360  if (r > 100.)
361  r = 100.;//as in TGX11.
362 
363  fCircle.clear();
364  CalculateCircle(fCircle, r, r < 100. ? kSmallCirclePts : kLargeCirclePts);
365 
366  for (UInt_t i = 0; i < n; ++i) {
367  const Double_t x = xy[i].fX;
368  const Double_t y = xy[i].fY;
369 
370  glBegin(GL_LINE_LOOP);
371  for (UInt_t j = 0, e = fCircle.size(); j < e; ++j)
372  glVertex2d(fCircle[j].fX + x, fCircle[j].fY + y);
373  glEnd();
374  }
375 }
376 
377 ////////////////////////////////////////////////////////////////////////////////
378 
380 {
381  fCircle.clear();
382  fCircle.push_back(TPoint(0, 0));
383 
384  Double_t r = 4 * gVirtualX->GetMarkerSize() + 0.5;
385  if (r > 100.)
386  r = 100;//as in TGX11.
387 
388  CalculateCircle(fCircle, r, r < 100 ? kSmallCirclePts : kLargeCirclePts);
389 
390  for (UInt_t i = 0; i < n; ++i) {
391  const Double_t x = xy[i].fX;
392  const Double_t y = xy[i].fY;
393 
394  glBegin(GL_TRIANGLE_FAN);
395  for (UInt_t j = 0, e = fCircle.size(); j < e; ++j)
396  glVertex2d(fCircle[j].fX + x, fCircle[j].fY + y);
397  glEnd();
398  }
399 }
400 
401 ////////////////////////////////////////////////////////////////////////////////
402 
404 {
405  const Double_t im = 4 * gVirtualX->GetMarkerSize() + 0.5;
406  for (UInt_t i = 0; i < n; ++i)
407  glRectd(xy[i].fX - im, xy[i].fY - im, xy[i].fX + im, xy[i].fY + im);
408 }
409 
410 ////////////////////////////////////////////////////////////////////////////////
411 
413 {
414  const Double_t im = 4 * gVirtualX->GetMarkerSize() + 0.5;
415  for (UInt_t i = 0; i < n; ++i) {
416  const Double_t x = xy[i].fX;
417  const Double_t y = xy[i].fY;
418  glBegin(GL_POLYGON);
419  glVertex2d(x - im, y - im);
420  glVertex2d(x + im, y - im);
421  glVertex2d(x, im + y);
422  glEnd();
423  }
424 }
425 
426 ////////////////////////////////////////////////////////////////////////////////
427 
429 {
430  const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
431 
432  for (UInt_t i = 0; i < n; ++i) {
433  const Double_t x = xy[i].fX;
434  const Double_t y = xy[i].fY;
435  glBegin(GL_POLYGON);
436  glVertex2d(x - im, y + im);
437  glVertex2d(x, y - im);
438  glVertex2d(im + x, y + im);
439  glEnd();
440  }
441 }
442 
443 ////////////////////////////////////////////////////////////////////////////////
444 
446 {
447  const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
448  const Int_t imx = Int_t(2.66 * gVirtualX->GetMarkerSize() + 0.5);
449 
450  for (UInt_t i = 0; i < n; ++i) {
451  const Double_t x = xy[i].fX;
452  const Double_t y = xy[i].fY;
453 
454  glBegin(GL_LINE_LOOP);
455  glVertex2d(x - imx, y);
456  glVertex2d(x, y - im);
457  glVertex2d(x + imx, y);
458  glVertex2d(x, y + im);
459  glEnd();
460  }
461 }
462 
463 ////////////////////////////////////////////////////////////////////////////////
464 
466 {
467  const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
468  const Int_t imx = Int_t(1.33 * gVirtualX->GetMarkerSize() + 0.5);
469 
470  for (UInt_t i = 0; i < n; ++i) {
471  const Double_t x = xy[i].fX;
472  const Double_t y = xy[i].fY;
473 
474  glBegin(GL_LINE_LOOP);
475  glVertex2d(x - im, y - imx);
476  glVertex2d(x - imx, y - imx);
477  glVertex2d(x - imx, y - im);
478  glVertex2d(x + imx, y - im);
479  glVertex2d(x + imx, y - imx);
480  glVertex2d(x + im, y - imx);
481  glVertex2d(x + im, y + imx);
482  glVertex2d(x + imx, y + imx);
483  glVertex2d(x + imx, y + im);
484  glVertex2d(x - imx, y + im);
485  glVertex2d(x - imx, y + imx);
486  glVertex2d(x - im, y + imx);
487  glEnd();
488  }
489 }
490 
491 ////////////////////////////////////////////////////////////////////////////////
492 /// HIGZ full star pentagone
493 
495 {
496  const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
497  const Int_t im1 = Int_t(0.66 * gVirtualX->GetMarkerSize() + 0.5);
498  const Int_t im2 = Int_t(2.00 * gVirtualX->GetMarkerSize() + 0.5);
499  const Int_t im3 = Int_t(2.66 * gVirtualX->GetMarkerSize() + 0.5);
500  const Int_t im4 = Int_t(1.33 * gVirtualX->GetMarkerSize() + 0.5);
501 
502  for (UInt_t i = 0; i < n; ++i) {
503  const Double_t x = xy[i].fX;
504  const Double_t y = xy[i].fY;
505 
506  glBegin(GL_TRIANGLES);
507  glVertex2d(x - im, y - im4);//0
508  glVertex2d(x - im2, y + im1);//1
509  glVertex2d(x - im4, y - im4);//9
510 
511  glVertex2d(x - im2, y + im1);//1
512  glVertex2d(x - im3, y + im);//2
513  glVertex2d(x, y + im2);//3
514 
515  glVertex2d(x, y + im2);//3
516  glVertex2d(x + im3, y + im);//4
517  glVertex2d(x + im2, y + im1);//5
518 
519  glVertex2d(x + im2, y + im1);//5
520  glVertex2d(x + im, y - im4);//6
521  glVertex2d(x + im4, y - im4);//7
522 
523  glVertex2d(x + im4, y - im4);//7
524  glVertex2d(x, y - im);//8
525  glVertex2d(x - im4, y - im4);//9
526 
527  glVertex2d(x - im4, y - im4);//9
528  glVertex2d(x - im2, y + im1);//1
529  glVertex2d(x, y + im2);//3
530 
531  glVertex2d(x - im4, y - im4);//9
532  glVertex2d(x, y + im2);//3
533  glVertex2d(x + im2, y + im1);//5
534 
535  glVertex2d(x - im4, y - im4);//9
536  glVertex2d(x + im2, y + im1);//5
537  glVertex2d(x + im4, y - im4);//7
538 
539  glEnd();
540 
541  }
542 }
543 
544 ////////////////////////////////////////////////////////////////////////////////
545 /// HIGZ full star pentagone
546 
548 {
549  const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
550  const Int_t im1 = Int_t(0.66 * gVirtualX->GetMarkerSize() + 0.5);
551  const Int_t im2 = Int_t(2.00 * gVirtualX->GetMarkerSize() + 0.5);
552  const Int_t im3 = Int_t(2.66 * gVirtualX->GetMarkerSize() + 0.5);
553  const Int_t im4 = Int_t(1.33 * gVirtualX->GetMarkerSize() + 0.5);
554 
555  for (UInt_t i = 0; i < n; ++i) {
556  const Double_t x = xy[i].fX;
557  const Double_t y = xy[i].fY;
558 
559  glBegin(GL_LINE_LOOP);
560  glVertex2d(x - im, y - im4);
561  glVertex2d(x - im2, y + im1);
562  glVertex2d(x - im3, y + im);
563  glVertex2d(x, y + im2);
564  glVertex2d(x + im3, y + im);
565  glVertex2d(x + im2, y + im1);
566  glVertex2d(x + im, y - im4);
567  glVertex2d(x + im4, y - im4);
568  glVertex2d(x, y - im);
569  glVertex2d(x - im4, y - im4);
570  glEnd();
571  }
572 }
573 
574 /*
575 Small RAII class for GLU tesselator.
576 */
577 #ifndef CALLBACK
578 #define CALLBACK
579 #endif
580 
581 extern "C" {
582 #if defined(__APPLE_CC__) && __APPLE_CC__ > 4000 && __APPLE_CC__ < 5450 && !defined(__INTEL_COMPILER)
583  typedef GLvoid (*tess_t)(...);
584 #elif defined( __mips ) || defined( __linux__ ) || defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __sun ) || defined (__CYGWIN__) || defined (__APPLE__)
585  typedef GLvoid (*tess_t)();
586 #elif defined ( WIN32)
587  typedef GLvoid (CALLBACK *tess_t)( );
588 #else
589  #error "Error - need to define type tess_t for this platform/compiler"
590 #endif
591 }
592 
593 ////////////////////////////////////////////////////////////////////////////////
594 
596 {
598  if (!dump)
599  return;
600 
601  dump->push_back(MeshPatch_t(type));
602 }
603 
604 ////////////////////////////////////////////////////////////////////////////////
605 
606 void Vertex(const Double_t *v)
607 {
609  if (!dump)
610  return;
611 
612  std::vector<Double_t> & vs = dump->back().fPatch;
613  vs.push_back(v[0]);
614  vs.push_back(v[1]);
615  vs.push_back(v[2]);
616 }
617 
618 ////////////////////////////////////////////////////////////////////////////////
619 
620 void End()
621 {
622 }
623 
625 
626 ////////////////////////////////////////////////////////////////////////////////
627 
629  : fTess(0)
630 {
631  GLUtesselator *tess = gluNewTess();
632  if (!tess)
633  throw std::runtime_error("tesselator creation failed");
634 
635  if (!dump) {
636  gluTessCallback(tess, (GLenum)GLU_BEGIN, (tess_t) glBegin);
637  gluTessCallback(tess, (GLenum)GLU_END, (tess_t) glEnd);
638  gluTessCallback(tess, (GLenum)GLU_VERTEX, (tess_t) glVertex3dv);
639  } else {
640  gluTessCallback(tess, (GLenum)GLU_BEGIN, (tess_t) Begin);
641  gluTessCallback(tess, (GLenum)GLU_END, (tess_t) End);
642  gluTessCallback(tess, (GLenum)GLU_VERTEX, (tess_t) Vertex);
643  }
644 
645  gluTessProperty(tess, GLU_TESS_TOLERANCE, 1e-10);
646  fTess = tess;
647 }
648 
649 ////////////////////////////////////////////////////////////////////////////////
650 
652 {
653  gluDeleteTess((GLUtesselator *)fTess);
654 }
655 
656 /*
657 In future, this should be an interface to per-pad FBO.
658 Currently, in only save sizes and coordinates (?)
659 */
660 ////////////////////////////////////////////////////////////////////////////////
661 
663  : fW(w), fH(h), fX(x), fY(y), fTop(top)
664 {
665 }
666 
667 ////////////////////////////////////////////////////////////////////////////////
668 
670  : fMaxLineWidth(0.),
671  fMaxPointSize(0.)
672 {
673 }
674 
675 ////////////////////////////////////////////////////////////////////////////////
676 
678 {
679  if (!fMaxLineWidth) {
680  Double_t lp[2] = {};
681  glGetDoublev(lineWidthPNAME, lp);//lineWidthPNAME is defined at the top of this file.
682  fMaxLineWidth = lp[1];
683  }
684 
685  return fMaxLineWidth;
686 }
687 
688 ////////////////////////////////////////////////////////////////////////////////
689 
691 {
692  if (!fMaxPointSize) {
693  Double_t lp[2] = {};
694  glGetDoublev(pointSizePNAME, lp);//pointSizePNAME is defined at the top of this file.
695  fMaxPointSize = lp[1];
696  }
697 
698  return fMaxLineWidth;
699 }
700 
701 
702 ////////////////////////////////////////////////////////////////////////////////
703 
704 void ExtractRGBA(Color_t colorIndex, Float_t *rgba)
705 {
706  const TColor *color = gROOT->GetColor(colorIndex);
707  if (color) {
708  color->GetRGB(rgba[0], rgba[1], rgba[2]);
709  rgba[3] = color->GetAlpha();
710  }
711 }
712 
713 ////////////////////////////////////////////////////////////////////////////////
714 
715 template<class ValueType>
716 BoundingRect<ValueType> FindBoundingRect(Int_t nPoints, const ValueType *xs, const ValueType *ys)
717 {
718  assert(nPoints > 0 && "FindBoundingRect, invalind number of points");
719  assert(xs != nullptr && "FindBoundingRect, parameter 'xs' is null");
720  assert(ys != nullptr && "FindBoundingRect, parameter 'ys' is null");
721 
722  ValueType xMin = xs[0], xMax = xMin;
723  ValueType yMin = ys[0], yMax = yMin;
724 
725  for (Int_t i = 1; i < nPoints; ++i) {
726  xMin = TMath::Min(xMin, xs[i]);
727  xMax = TMath::Max(xMax, xs[i]);
728 
729  yMin = TMath::Min(yMin, ys[i]);
730  yMax = TMath::Max(yMax, ys[i]);
731  }
732 
734  box.fXMin = xMin;
735  box.fXMax = xMax;
736  box.fWidth = xMax - xMin;
737 
738  box.fYMin = yMin;
739  box.fYMax = yMax;
740  box.fHeight = yMax - yMin;
741 
742  return box;
743 }
744 
745 template BoundingRect<Double_t> FindBoundingRect(Int_t nPoints, const Double_t *xs, const Double_t *ys);
746 template BoundingRect<Float_t> FindBoundingRect(Int_t nPoints, const Float_t *xs, const Float_t *ys);
747 template BoundingRect<Long_t> FindBoundingRect(Int_t nPoints, const Long_t *xs, const Long_t *ys);
748 template BoundingRect<Int_t> FindBoundingRect(Int_t nPoints, const Int_t *xs, const Int_t *ys);
749 template BoundingRect<SCoord_t> FindBoundingRect(Int_t nPoints, const SCoord_t *xs, const SCoord_t *ys);
750 
751 
752 
753 namespace {
754 
755 ////////////////////////////////////////////////////////////////////////////////
756 
757 void CalculateCircle(std::vector<TPoint> &circle, Double_t r, UInt_t pts)
758 {
759  const Double_t delta = TMath::TwoPi() / pts;
760  const UInt_t first = circle.size();
761  Double_t angle = 0.;
762  circle.resize(circle.size() + pts + 1);
763 
764  for (UInt_t i = 0; i < pts; ++i, angle += delta) {
765  circle[first + i].fX = SCoord_t(r * TMath::Cos(angle));
766  circle[first + i].fY = SCoord_t(r * TMath::Sin(angle));
767  }
768 
769  circle.back().fX = circle[first].fX;
770  circle.back().fY = circle[first].fY;
771 }
772 
773 }//anonymous namespace
774 
775 }//namespace Pad
776 }//namespace Rgl
void DrawDot(UInt_t n, const TPoint *xy) const
Simple 1-pixel dots.
OffScreenDevice(UInt_t w, UInt_t h, UInt_t x, UInt_t y, Bool_t top)
void Begin(Int_t type)
static UInt_t SwapBits(UInt_t bits)
void DrawFullDotLarge(UInt_t n, const TPoint *xy) const
std::vector< TPoint > fCircle
Definition: TGLPadUtils.h:116
Double_t fMaxPointSize
Definition: TGLPadUtils.h:218
float Float_t
Definition: RtypesCore.h:53
Double_t GetMaxLineWidth() const
#define assert(cond)
Definition: unittest.h:542
unsigned short UShort_t
Definition: RtypesCore.h:36
TH1 * h
Definition: legend2.C:5
void DrawCircle(UInt_t n, const TPoint *xy) const
SCoord_t fX
Definition: TPoint.h:37
#define gROOT
Definition: TROOT.h:344
SCoord_t fY
Definition: TPoint.h:38
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:170
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void DrawFullTrianlgeDown(UInt_t n, const TPoint *xy) const
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
Double_t fMaxLineWidth
Definition: TGLPadUtils.h:217
TFile * f
void DrawDiamond(UInt_t n, const TPoint *xy) const
void DrawFullDotMedium(UInt_t n, const TPoint *xy) const
Double_t x[n]
Definition: legend1.C:17
short SCoord_t
Definition: RtypesCore.h:80
void ExtractRGBA(Color_t colorIndex, Float_t *rgba)
std::vector< unsigned char > fStipples
Definition: TGLPadUtils.h:48
Tesselator(Bool_t dump=kFALSE)
void DrawFullSquare(UInt_t n, const TPoint *xy) const
void DrawFullDotSmall(UInt_t n, const TPoint *xy) const
LineAttribSet(Bool_t smooth, UInt_t stipple, Double_t maxWidth, Bool_t setWidth)
Set up line parameters.
const GLenum pointSizePNAME
Definition: TGLPadUtils.cxx:37
Double_t TwoPi()
Definition: TMath.h:45
const UInt_t gMaxStipple
void DrawFullStar(UInt_t n, const TPoint *xy) const
HIGZ full star pentagone.
short Color_t
Definition: RtypesCore.h:79
void DrawPlus(UInt_t n, const TPoint *xy) const
Definition: TPoint.h:33
std::list< MeshPatch_t > Tesselation_t
Definition: TGLPadUtils.h:159
SVector< double, 2 > v
Definition: Dict.h:5
XPoint xy[kMAXMK]
Definition: TGX11.cxx:122
void DrawFullTrianlgeUp(UInt_t n, const TPoint *xy) const
void DrawCross(UInt_t n, const TPoint *xy) const
const UShort_t gLineStipples[]
virtual void GetRGB(Float_t &r, Float_t &g, Float_t &b) const
Definition: TColor.h:79
unsigned int UInt_t
Definition: RtypesCore.h:42
bool first
Definition: line3Dfit.C:48
void DrawStar(UInt_t n, const TPoint *xy) const
tuple w
Definition: qtexample.py:51
static Tesselation_t * fVs
Definition: TGLPadUtils.h:188
const unsigned char gStipples[26][32]
Definition: RStipples.h:28
#define gVirtualX
Definition: TVirtualX.h:362
Double_t Cos(Double_t)
Definition: TMath.h:424
short Width_t
Definition: RtypesCore.h:78
Double_t GetMaxPointSize() const
long Long_t
Definition: RtypesCore.h:50
double Double_t
Definition: RtypesCore.h:55
const GLenum lineWidthPNAME
Definition: TGLPadUtils.cxx:36
int type
Definition: TGX11.cxx:120
TCanvas * style()
Definition: style.C:1
Double_t y[n]
Definition: legend1.C:17
The color creation and management class.
Definition: TColor.h:47
static Tesselation_t * GetDump()
Definition: TGLPadUtils.h:179
static const UInt_t fgBitSwap[]
Definition: TGLPadUtils.h:50
BoundingRect< ValueType > FindBoundingRect(Int_t nPoints, const ValueType *xs, const ValueType *ys)
FillAttribSet(const PolygonStippleSet &set, Bool_t ignoreStipple)
Polygon stipple, if required.
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:202
Double_t Sin(Double_t)
Definition: TMath.h:421
Float_t GetAlpha() const
Definition: TColor.h:91
void End()
unsigned char UChar_t
Definition: RtypesCore.h:34
void DrawX(UInt_t n, const TPoint *xy) const
const Int_t n
Definition: legend1.C:16
#define CALLBACK
void DrawOpenStar(UInt_t n, const TPoint *xy) const
HIGZ full star pentagone.
void Vertex(const Double_t *v)