29 const UInt_t PolygonStippleSet::fgBitSwap[] = {0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15};
35 #ifndef GL_VERSION_1_2
36 const GLenum lineWidthPNAME = GLenum(0xB22);
37 const GLenum pointSizePNAME = GLenum(0xB12);
39 const GLenum lineWidthPNAME = GLenum(GL_SMOOTH_LINE_WIDTH_RANGE);
40 const GLenum pointSizePNAME = GLenum(GL_SMOOTH_POINT_SIZE_RANGE);
50 PolygonStippleSet::PolygonStippleSet()
83 const UInt_t numOfStipples =
sizeof gStipples /
sizeof gStipples[0];
84 fStipples.resize(kStippleSize * numOfStipples);
86 for (UInt_t i = 0; i < numOfStipples; ++i) {
87 const UInt_t baseInd = i * kStippleSize;
89 for (Int_t j = 15, j1 = 0; j >= 0; --j, ++j1) {
90 const UInt_t rowShift = j1 * kRowSize;
92 for (Int_t k = 1, k1 = 0; k >= 0; --k, ++k1) {
93 const UChar_t pixel = SwapBits(gStipples[i][j * 2 + k]);
94 const UInt_t ind = baseInd + rowShift + k1;
96 fStipples[ind] = pixel;
97 fStipples[ind + 2] = pixel;
98 fStipples[ind + 64] = pixel;
99 fStipples[ind + 66] = pixel;
107 UInt_t PolygonStippleSet::SwapBits(UInt_t b)
114 const UInt_t low = fgBitSwap[b & kLow4] << 4;
115 const UInt_t up = fgBitSwap[(b & kUp4) >> 4];
126 FillAttribSet::FillAttribSet(
const PolygonStippleSet &set, Bool_t ignoreStipple)
127 : fStipple(0), fAlpha(1.)
129 const UInt_t style = gVirtualX->GetFillStyle() / 1000;
131 if (!ignoreStipple) {
133 const UInt_t fasi = gVirtualX->GetFillStyle() % 1000;
134 fStipple = (fasi >= 1 && fasi <=25) ? fasi : 2;
135 glPolygonStipple(&set.fStipples[fStipple * PolygonStippleSet::kStippleSize]);
136 glEnable(GL_POLYGON_STIPPLE);
141 Float_t rgba[] = {0.f, 0.f, 0.f, 1.f};
142 ExtractRGBA(gVirtualX->GetFillColor(), rgba);
146 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
153 FillAttribSet::~FillAttribSet()
156 glDisable(GL_POLYGON_STIPPLE);
166 const UShort_t gLineStipples[] = {0xffff, 0xffff, 0x3333, 0x5555,
167 0xf040, 0xf4f4, 0xf111, 0xf0f0,
168 0xff11, 0x3fff, 0x08ff};
170 const UInt_t gMaxStipple =
sizeof gLineStipples /
sizeof gLineStipples[0];
179 LineAttribSet::LineAttribSet(Bool_t smooth, UInt_t stipple, Double_t maxWidth, Bool_t setWidth)
180 : fSmooth(smooth), fStipple(stipple), fSetWidth(setWidth), fAlpha(0.8)
184 glEnable(GL_LINE_SMOOTH);
185 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
186 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
191 if (fStipple >= gMaxStipple)
194 glEnable(GL_LINE_STIPPLE);
195 glLineStipple(fStipple == 10 ? 2 : 1, gLineStipples[fStipple]);
200 Float_t rgba[] = {0.f, 0.f, 0.f, 0.8f};
201 ExtractRGBA(gVirtualX->GetLineColor(), rgba);
205 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
211 const Width_t w = gVirtualX->GetLineWidth();
212 glLineWidth(w > maxWidth ? maxWidth : !w ? 1.f : w);
218 LineAttribSet::~LineAttribSet()
220 if (fSmooth || fAlpha<0.8) {
221 glDisable(GL_LINE_SMOOTH);
226 glDisable(GL_LINE_STIPPLE);
239 void MarkerPainter::DrawDot(UInt_t n,
const TPoint *xy)
const
243 for (UInt_t i = 0; i < n; ++i)
244 glVertex2d(xy[i].fX, xy[i].fY);
252 void MarkerPainter::DrawPlus(UInt_t n,
const TPoint *xy)
const
254 const Double_t im = 4 * gVirtualX->GetMarkerSize() + 0.5;
257 for (UInt_t i = 0; i < n; ++i) {
258 const Double_t x = xy[i].fX;
259 const Double_t y = xy[i].fY;
260 glVertex2d(-im + x, y);
261 glVertex2d(im + x, y);
262 glVertex2d(x, -im + y);
263 glVertex2d(x, im + y);
272 void MarkerPainter::DrawStar(UInt_t n,
const TPoint *xy)
const
274 SCoord_t im = SCoord_t(4 * gVirtualX->GetMarkerSize() + 0.5);
275 fStar[0].fX = -im; fStar[0].fY = 0;
276 fStar[1].fX = im; fStar[1].fY = 0;
277 fStar[2].fX = 0 ; fStar[2].fY = -im;
278 fStar[3].fX = 0 ; fStar[3].fY = im;
279 im = SCoord_t(0.707*Float_t(im) + 0.5);
280 fStar[4].fX = -im; fStar[4].fY = -im;
281 fStar[5].fX = im; fStar[5].fY = im;
282 fStar[6].fX = -im; fStar[6].fY = im;
283 fStar[7].fX = im; fStar[7].fY = -im;
287 for (UInt_t i = 0; i < n; ++i) {
288 const Double_t x = xy[i].fX;
289 const Double_t y = xy[i].fY;
291 glVertex2d(fStar[0].fX + x, fStar[0].fY + y);
292 glVertex2d(fStar[1].fX + x, fStar[1].fY + y);
293 glVertex2d(fStar[2].fX + x, fStar[2].fY + y);
294 glVertex2d(fStar[3].fX + x, fStar[3].fY + y);
295 glVertex2d(fStar[4].fX + x, fStar[4].fY + y);
296 glVertex2d(fStar[5].fX + x, fStar[5].fY + y);
297 glVertex2d(fStar[6].fX + x, fStar[6].fY + y);
298 glVertex2d(fStar[7].fX + x, fStar[7].fY + y);
306 void MarkerPainter::DrawX(UInt_t n,
const TPoint *xy)
const
308 const Double_t im = 0.707 * (4 * gVirtualX->GetMarkerSize() + 0.5) + 0.5;
312 for (UInt_t i = 0; i < n; ++i) {
313 const Double_t x = xy[i].fX;
314 const Double_t y = xy[i].fY;
316 glVertex2d(-im + x, -im + y);
317 glVertex2d(im + x, im + y);
318 glVertex2d(-im + x, im + y);
319 glVertex2d(im + x, -im + y);
327 void MarkerPainter::DrawFullDotSmall(UInt_t n,
const TPoint *xy)
const
331 for (UInt_t i = 0; i < n; ++i) {
332 const Double_t x = xy[i].fX;
333 const Double_t y = xy[i].fY;
335 glVertex2d(-1. + x, y);
336 glVertex2d(x + 1., y);
337 glVertex2d(x, -1. + y);
338 glVertex2d(x, 1. + y);
346 void MarkerPainter::DrawFullDotMedium(UInt_t n,
const TPoint *xy)
const
348 for (UInt_t i = 0; i < n; ++i)
349 glRectd(xy[i].fX - 1, xy[i].fY - 1, xy[i].fX + 1, xy[i].fY + 1);
354 void CalculateCircle(std::vector<TPoint> &circle, Double_t r, UInt_t pts);
359 void MarkerPainter::DrawCircle(UInt_t n,
const TPoint *xy)
const
361 Double_t r = 4 * gVirtualX->GetMarkerSize() + 0.5;
366 CalculateCircle(fCircle, r, r < 100. ? kSmallCirclePts : kLargeCirclePts);
368 for (UInt_t i = 0; i < n; ++i) {
369 const Double_t x = xy[i].fX;
370 const Double_t y = xy[i].fY;
372 glBegin(GL_LINE_LOOP);
373 for (UInt_t j = 0, e = fCircle.size(); j < e; ++j)
374 glVertex2d(fCircle[j].fX + x, fCircle[j].fY + y);
381 void MarkerPainter::DrawFullDotLarge(UInt_t n,
const TPoint *xy)
const
384 fCircle.push_back(TPoint(0, 0));
386 Double_t r = 4 * gVirtualX->GetMarkerSize() + 0.5;
390 CalculateCircle(fCircle, r, r < 100 ? kSmallCirclePts : kLargeCirclePts);
392 for (UInt_t i = 0; i < n; ++i) {
393 const Double_t x = xy[i].fX;
394 const Double_t y = xy[i].fY;
396 glBegin(GL_TRIANGLE_FAN);
397 for (UInt_t j = 0, e = fCircle.size(); j < e; ++j)
398 glVertex2d(fCircle[j].fX + x, fCircle[j].fY + y);
405 void MarkerPainter::DrawFullSquare(UInt_t n,
const TPoint *xy)
const
407 const Double_t im = 4 * gVirtualX->GetMarkerSize() + 0.5;
408 for (UInt_t i = 0; i < n; ++i)
409 glRectd(xy[i].fX - im, xy[i].fY - im, xy[i].fX + im, xy[i].fY + im);
414 void MarkerPainter::DrawFullTrianlgeUp(UInt_t n,
const TPoint *xy)
const
416 const Double_t im = 4 * gVirtualX->GetMarkerSize() + 0.5;
417 for (UInt_t i = 0; i < n; ++i) {
418 const Double_t x = xy[i].fX;
419 const Double_t y = xy[i].fY;
421 glVertex2d(x - im, y - im);
422 glVertex2d(x + im, y - im);
423 glVertex2d(x, im + y);
430 void MarkerPainter::DrawFullTrianlgeDown(UInt_t n,
const TPoint *xy)
const
432 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
434 for (UInt_t i = 0; i < n; ++i) {
435 const Double_t x = xy[i].fX;
436 const Double_t y = xy[i].fY;
438 glVertex2d(x - im, y + im);
439 glVertex2d(x, y - im);
440 glVertex2d(im + x, y + im);
447 void MarkerPainter::DrawDiamond(UInt_t n,
const TPoint *xy)
const
449 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
450 const Int_t imx = Int_t(2.66 * gVirtualX->GetMarkerSize() + 0.5);
452 for (UInt_t i = 0; i < n; ++i) {
453 const Double_t x = xy[i].fX;
454 const Double_t y = xy[i].fY;
456 glBegin(GL_LINE_LOOP);
457 glVertex2d(x - imx, y);
458 glVertex2d(x, y - im);
459 glVertex2d(x + imx, y);
460 glVertex2d(x, y + im);
467 void MarkerPainter::DrawFullDiamond(UInt_t n,
const TPoint *xy)
const
469 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
470 const Int_t imx = Int_t(2.66 * gVirtualX->GetMarkerSize() + 0.5);
472 for (UInt_t i = 0; i < n; ++i) {
473 const Double_t x = xy[i].fX;
474 const Double_t y = xy[i].fY;
477 glVertex2d(x - imx, y);
478 glVertex2d(x, y - im);
479 glVertex2d(x + imx, y);
480 glVertex2d(x, y + im);
487 void MarkerPainter::DrawOpenTrianlgeDown(UInt_t n,
const TPoint *xy)
const
489 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
491 for (UInt_t i = 0; i < n; ++i) {
492 const Double_t x = xy[i].fX;
493 const Double_t y = xy[i].fY;
494 glBegin(GL_LINE_LOOP);
495 glVertex2d(x - im, y + im);
496 glVertex2d(x, y - im);
497 glVertex2d(im + x, y + im);
504 void MarkerPainter::DrawOpenCross(UInt_t n,
const TPoint *xy)
const
506 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
507 const Int_t imx = Int_t(1.33 * gVirtualX->GetMarkerSize() + 0.5);
509 for (UInt_t i = 0; i < n; ++i) {
510 const Double_t x = xy[i].fX;
511 const Double_t y = xy[i].fY;
513 glBegin(GL_LINE_LOOP);
514 glVertex2d(x - im, y - imx);
515 glVertex2d(x - imx, y - imx);
516 glVertex2d(x - imx, y - im);
517 glVertex2d(x + imx, y - im);
518 glVertex2d(x + imx, y - imx);
519 glVertex2d(x + im, y - imx);
520 glVertex2d(x + im, y + imx);
521 glVertex2d(x + imx, y + imx);
522 glVertex2d(x + imx, y + im);
523 glVertex2d(x - imx, y + im);
524 glVertex2d(x - imx, y + imx);
525 glVertex2d(x - im, y + imx);
532 void MarkerPainter::DrawFullCross(UInt_t n,
const TPoint *xy)
const
534 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
535 const Int_t imx = Int_t(1.33 * gVirtualX->GetMarkerSize() + 0.5);
537 for (UInt_t i = 0; i < n; ++i) {
538 const Double_t x = xy[i].fX;
539 const Double_t y = xy[i].fY;
542 glVertex2d(x - im, y - imx);
543 glVertex2d(x - im, y + imx);
544 glVertex2d(x + im, y + imx);
545 glVertex2d(x + im, y - imx);
548 glVertex2d(x - imx, y + imx);
549 glVertex2d(x - imx, y + im);
550 glVertex2d(x + imx, y + im);
551 glVertex2d(x + imx, y + imx);
555 glVertex2d(x - imx, y - imx);
556 glVertex2d(x - imx, y - im);
557 glVertex2d(x + imx, y - im);
558 glVertex2d(x + imx, y - imx);
566 void MarkerPainter::DrawFullStar(UInt_t n,
const TPoint *xy)
const
568 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
569 const Int_t im1 = Int_t(0.66 * gVirtualX->GetMarkerSize() + 0.5);
570 const Int_t im2 = Int_t(2.00 * gVirtualX->GetMarkerSize() + 0.5);
571 const Int_t im3 = Int_t(2.66 * gVirtualX->GetMarkerSize() + 0.5);
572 const Int_t im4 = Int_t(1.33 * gVirtualX->GetMarkerSize() + 0.5);
574 for (UInt_t i = 0; i < n; ++i) {
575 const Double_t x = xy[i].fX;
576 const Double_t y = xy[i].fY;
578 glBegin(GL_TRIANGLES);
579 glVertex2d(x - im, y - im4);
580 glVertex2d(x - im2, y + im1);
581 glVertex2d(x - im4, y - im4);
583 glVertex2d(x - im2, y + im1);
584 glVertex2d(x - im3, y + im);
585 glVertex2d(x, y + im2);
587 glVertex2d(x, y + im2);
588 glVertex2d(x + im3, y + im);
589 glVertex2d(x + im2, y + im1);
591 glVertex2d(x + im2, y + im1);
592 glVertex2d(x + im, y - im4);
593 glVertex2d(x + im4, y - im4);
595 glVertex2d(x + im4, y - im4);
596 glVertex2d(x, y - im);
597 glVertex2d(x - im4, y - im4);
599 glVertex2d(x - im4, y - im4);
600 glVertex2d(x - im2, y + im1);
601 glVertex2d(x, y + im2);
603 glVertex2d(x - im4, y - im4);
604 glVertex2d(x, y + im2);
605 glVertex2d(x + im2, y + im1);
607 glVertex2d(x - im4, y - im4);
608 glVertex2d(x + im2, y + im1);
609 glVertex2d(x + im4, y - im4);
619 void MarkerPainter::DrawOpenStar(UInt_t n,
const TPoint *xy)
const
621 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
622 const Int_t im1 = Int_t(0.66 * gVirtualX->GetMarkerSize() + 0.5);
623 const Int_t im2 = Int_t(2.00 * gVirtualX->GetMarkerSize() + 0.5);
624 const Int_t im3 = Int_t(2.66 * gVirtualX->GetMarkerSize() + 0.5);
625 const Int_t im4 = Int_t(1.33 * gVirtualX->GetMarkerSize() + 0.5);
627 for (UInt_t i = 0; i < n; ++i) {
628 const Double_t x = xy[i].fX;
629 const Double_t y = xy[i].fY;
631 glBegin(GL_LINE_LOOP);
632 glVertex2d(x - im, y - im4);
633 glVertex2d(x - im2, y + im1);
634 glVertex2d(x - im3, y + im);
635 glVertex2d(x, y + im2);
636 glVertex2d(x + im3, y + im);
637 glVertex2d(x + im2, y + im1);
638 glVertex2d(x + im, y - im4);
639 glVertex2d(x + im4, y - im4);
640 glVertex2d(x, y - im);
641 glVertex2d(x - im4, y - im4);
648 void MarkerPainter::DrawOpenSquareDiagonal(UInt_t n,
const TPoint *xy)
const
650 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
652 for (
unsigned i = 0; i < n; ++i) {
653 const Double_t x = xy[i].fX;
654 const Double_t y = xy[i].fY;
656 glBegin(GL_LINE_LOOP);
657 glVertex2d(x - im, y - im);
658 glVertex2d(x + im, y - im);
659 glVertex2d(x + im, y + im);
660 glVertex2d(x - im, y + im);
661 glVertex2d(x - im, y - im);
662 glVertex2d(x + im, y + im);
663 glVertex2d(x - im, y + im);
664 glVertex2d(x + im, y - im);
671 void MarkerPainter::DrawOpenDiamondCross(UInt_t n,
const TPoint *xy)
const
673 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
675 for (
unsigned i = 0; i < n; ++i) {
676 const Double_t x = xy[i].fX;
677 const Double_t y = xy[i].fY;
679 glBegin(GL_LINE_LOOP);
680 glVertex2d(x - im, y );
681 glVertex2d(x , y - im);
682 glVertex2d(x + im, y );
683 glVertex2d(x , y + im);
684 glVertex2d(x - im, y );
685 glVertex2d(x + im, y );
686 glVertex2d(x , y + im);
687 glVertex2d(x , y - im);
694 void MarkerPainter::DrawOpenThreeTriangles(UInt_t n,
const TPoint *xy)
const
696 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
697 const Int_t im2 = Int_t(2.00 * gVirtualX->GetMarkerSize() + 0.5);
699 for (
unsigned i = 0; i < n; ++i) {
700 const Double_t x = xy[i].fX;
701 const Double_t y = xy[i].fY;
703 glBegin(GL_LINE_LOOP);
705 glVertex2d(x -im2, y + im);
706 glVertex2d(x - im, y );
708 glVertex2d(x -im2, y - im);
709 glVertex2d(x +im2, y - im);
711 glVertex2d(x + im, y );
712 glVertex2d(x +im2, y + im);
720 void MarkerPainter::DrawOctagonCross(UInt_t n,
const TPoint *xy)
const
722 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
723 const Int_t im2 = Int_t(2.00 * gVirtualX->GetMarkerSize() + 0.5);
725 for (
unsigned i = 0; i < n; ++i) {
726 const Double_t x = xy[i].fX;
727 const Double_t y = xy[i].fY;
729 glBegin(GL_LINE_LOOP);
730 glVertex2d(x-im, y );
731 glVertex2d(x-im, y-im2);
732 glVertex2d(x-im2, y-im);
733 glVertex2d(x+im2, y-im);
734 glVertex2d(x+im, y-im2);
735 glVertex2d(x+im, y+im2);
736 glVertex2d(x+im2, y+im);
737 glVertex2d(x-im2, y+im);
738 glVertex2d(x-im, y+im2);
739 glVertex2d(x-im, y );
740 glVertex2d(x+im, y );
742 glVertex2d(x , y-im);
743 glVertex2d(x , y+im);
751 void MarkerPainter::DrawFullThreeTriangles(UInt_t n,
const TPoint *xy)
const
753 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
754 const Int_t im2 = Int_t(2.00 * gVirtualX->GetMarkerSize() + 0.5);
756 for (
unsigned i = 0; i < n; ++i) {
757 const Double_t x = xy[i].fX;
758 const Double_t y = xy[i].fY;
762 glVertex2d(x -im2, y + im);
763 glVertex2d(x - im, y );
765 glVertex2d(x -im2, y - im);
766 glVertex2d(x +im2, y - im);
768 glVertex2d(x + im, y );
769 glVertex2d(x +im2, y + im);
777 void MarkerPainter::DrawOpenFourTrianglesX(UInt_t n,
const TPoint *xy)
const
779 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
780 const Int_t im2 = Int_t(2.00 * gVirtualX->GetMarkerSize() + 0.5);
782 for (
unsigned i = 0; i < n; ++i) {
783 const Double_t x = xy[i].fX;
784 const Double_t y = xy[i].fY;
786 glBegin(GL_LINE_LOOP);
788 glVertex2d(x+im2, y+im);
789 glVertex2d(x+im , y+im2);
791 glVertex2d(x+im , y-im2);
792 glVertex2d(x+im2, y-im);
794 glVertex2d(x-im2, y-im);
795 glVertex2d(x-im , y-im2);
797 glVertex2d(x-im , y+im2);
798 glVertex2d(x-im2, y+im);
806 void MarkerPainter::DrawFullFourTrianglesX(UInt_t n,
const TPoint *xy)
const
808 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
809 const Int_t im2 = Int_t(2.00 * gVirtualX->GetMarkerSize() + 0.5);
811 for (
unsigned i = 0; i < n; ++i) {
812 const Double_t x = xy[i].fX;
813 const Double_t y = xy[i].fY;
817 glVertex2d(x+im2, y+im);
818 glVertex2d(x+im , y+im2);
820 glVertex2d(x+im , y-im2);
821 glVertex2d(x+im2, y-im);
823 glVertex2d(x-im2, y-im);
824 glVertex2d(x-im , y-im2);
826 glVertex2d(x-im , y+im2);
827 glVertex2d(x-im2, y+im);
835 void MarkerPainter::DrawOpenDoubleDiamond(UInt_t n,
const TPoint *xy)
const
837 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
838 const Int_t im4 = Int_t(1.33 * gVirtualX->GetMarkerSize() + 0.5);
840 for (
unsigned i = 0; i < n; ++i) {
841 const Double_t x = xy[i].fX;
842 const Double_t y = xy[i].fY;
844 glBegin(GL_LINE_LOOP);
845 glVertex2d(x , y+im );
846 glVertex2d(x-im4, y+im4);
847 glVertex2d(x-im , y );
848 glVertex2d(x-im4, y-im4);
849 glVertex2d(x , y-im );
850 glVertex2d(x+im4, y-im4);
851 glVertex2d(x+im , y );
852 glVertex2d(x+im4, y+im4);
853 glVertex2d(x , y+im );
860 void MarkerPainter::DrawFullDoubleDiamond(UInt_t n,
const TPoint *xy)
const
862 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
863 const Int_t im4 = Int_t(1.33 * gVirtualX->GetMarkerSize() + 0.5);
865 for (
unsigned i = 0; i < n; ++i) {
866 const Double_t x = xy[i].fX;
867 const Double_t y = xy[i].fY;
870 glVertex2d(x, y+im );
871 glVertex2d(x-im4, y+im4);
875 glVertex2d(x-im4, y+im4);
881 glVertex2d(x-im4, y-im4);
885 glVertex2d(x-im4, y-im4);
891 glVertex2d(x+im4, y-im4);
895 glVertex2d(x+im4, y-im4);
901 glVertex2d(x+im4, y+im4);
905 glVertex2d(x+im4, y+im4);
914 void MarkerPainter::DrawOpenFourTrianglesPlus(UInt_t n,
const TPoint *xy)
const
916 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
917 const Int_t im2 = Int_t(2.00 * gVirtualX->GetMarkerSize() + 0.5);
919 for (
unsigned i = 0; i < n; ++i) {
920 const Double_t x = xy[i].fX;
921 const Double_t y = xy[i].fY;
923 glBegin(GL_LINE_LOOP);
925 glVertex2d(x+im2, y+im);
926 glVertex2d(x-im2, y+im);
927 glVertex2d(x+im2, y-im);
928 glVertex2d(x-im2, y-im);
930 glVertex2d(x+im, y+im2);
931 glVertex2d(x+im, y-im2);
932 glVertex2d(x-im, y+im2);
933 glVertex2d(x-im, y-im2);
941 void MarkerPainter::DrawFullFourTrianglesPlus(UInt_t n,
const TPoint *xy)
const
943 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
944 const Int_t im2 = Int_t(2.00 * gVirtualX->GetMarkerSize() + 0.5);
946 for (
unsigned i = 0; i < n; ++i) {
947 const Double_t x = xy[i].fX;
948 const Double_t y = xy[i].fY;
952 glVertex2d(x+im2, y+im);
953 glVertex2d(x-im2, y+im);
954 glVertex2d(x+im2, y-im);
955 glVertex2d(x-im2, y-im);
957 glVertex2d(x+im, y+im2);
958 glVertex2d(x+im, y-im2);
959 glVertex2d(x-im, y+im2);
960 glVertex2d(x-im, y-im2);
968 void MarkerPainter::DrawOpenCrossX(UInt_t n,
const TPoint *xy)
const
970 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
971 const Int_t im2 = Int_t(2.00 * gVirtualX->GetMarkerSize() + 0.5);
973 for (
unsigned i = 0; i < n; ++i) {
974 const Double_t x = xy[i].fX;
975 const Double_t y = xy[i].fY;
977 glBegin(GL_LINE_LOOP);
978 glVertex2d(x , y +im2);
979 glVertex2d(x -im2, y + im);
980 glVertex2d(x - im, y +im2);
981 glVertex2d(x -im2, y );
982 glVertex2d(x - im, y -im2);
983 glVertex2d(x -im2, y - im);
984 glVertex2d(x , y -im2);
985 glVertex2d(x +im2, y - im);
986 glVertex2d(x + im, y -im2);
987 glVertex2d(x +im2, y );
988 glVertex2d(x + im, y +im2);
989 glVertex2d(x +im2, y + im);
990 glVertex2d(x , y +im2);
997 void MarkerPainter::DrawFullCrossX(UInt_t n,
const TPoint *xy)
const
999 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
1000 const Int_t im2 = Int_t(2.00 * gVirtualX->GetMarkerSize() + 0.5);
1002 for (
unsigned i = 0; i < n; ++i) {
1003 const Double_t x = xy[i].fX;
1004 const Double_t y = xy[i].fY;
1006 glBegin(GL_POLYGON);
1007 glVertex2d(x , y +im2);
1008 glVertex2d(x -im2, y +im);
1009 glVertex2d(x -im , y +im2);
1010 glVertex2d(x -im2, y );
1013 glBegin(GL_POLYGON);
1014 glVertex2d(x -im2, y);
1015 glVertex2d(x -im, y -im2);
1016 glVertex2d(x -im2, y -im);
1017 glVertex2d(x , y-im2);
1020 glBegin(GL_POLYGON);
1021 glVertex2d(x , y -im2);
1022 glVertex2d(x +im2, y -im);
1023 glVertex2d(x +im , y -im2);
1024 glVertex2d(x +im2, y);
1027 glBegin(GL_POLYGON);
1028 glVertex2d(x +im2, y);
1029 glVertex2d(x +im , y +im2);
1030 glVertex2d(x +im2, y +im);
1031 glVertex2d(x , y +im2);
1038 void MarkerPainter::DrawFourSquaresX(UInt_t n,
const TPoint *xy)
const
1040 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
1041 const Int_t im2 = Int_t(2.00 * gVirtualX->GetMarkerSize() + 0.5);
1043 for (
unsigned i = 0; i < n; ++i) {
1044 const Double_t x = xy[i].fX;
1045 const Double_t y = xy[i].fY;
1047 glBegin(GL_POLYGON);
1048 glVertex2d(x, y+im2);
1049 glVertex2d(x-im2 , y+im);
1050 glVertex2d(x-im, y+im2);
1051 glVertex2d(x-im2 , y);
1053 glBegin(GL_POLYGON);
1054 glVertex2d(x-im2, y);
1055 glVertex2d(x-im , y-im2);
1056 glVertex2d(x-im2, y-im);
1057 glVertex2d(x, y-im2);
1059 glBegin(GL_POLYGON);
1060 glVertex2d(x, y-im2);
1061 glVertex2d(x+im2 , y-im);
1062 glVertex2d(x+im, y-im2);
1063 glVertex2d(x+im2, y);
1065 glBegin(GL_POLYGON);
1066 glVertex2d(x+im2, y);
1067 glVertex2d(x+im , y+im2);
1068 glVertex2d(x+im2, y+im);
1069 glVertex2d(x, y+im2);
1076 void MarkerPainter::DrawFourSquaresPlus(UInt_t n,
const TPoint *xy)
const
1078 const Int_t im = Int_t(4 * gVirtualX->GetMarkerSize() + 0.5);
1079 const Int_t im2 = Int_t(1.33 * gVirtualX->GetMarkerSize() + 0.5);
1081 for (
unsigned i = 0; i < n; ++i) {
1082 const Double_t x = xy[i].fX;
1083 const Double_t y = xy[i].fY;
1085 glBegin(GL_POLYGON);
1086 glVertex2d(x+im2, y+im2);
1087 glVertex2d(x+im2, y+im);
1088 glVertex2d(x-im2, y+im);
1089 glVertex2d(x-im2, y+im2);
1091 glBegin(GL_POLYGON);
1092 glVertex2d(x-im2, y+im2);
1093 glVertex2d(x-im, y+im2);
1094 glVertex2d(x-im, y-im2);
1095 glVertex2d(x-im2, y-im2);
1097 glBegin(GL_POLYGON);
1098 glVertex2d(x-im2, y-im2);
1099 glVertex2d(x-im2, y-im);
1100 glVertex2d(x+im2, y-im);
1101 glVertex2d(x+im2, y-im2);
1103 glBegin(GL_POLYGON);
1104 glVertex2d(x+im2, y-im2);
1105 glVertex2d(x+im, y-im2);
1106 glVertex2d(x+im, y+im2);
1107 glVertex2d(x+im2, y+im2);
1120 #if defined(__APPLE_CC__) && __APPLE_CC__ > 4000 && __APPLE_CC__ < 5450 && !defined(__INTEL_COMPILER)
1121 typedef GLvoid (*tess_t)(...);
1122 #elif defined( __mips ) || defined( __linux__ ) || defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __sun ) || defined (__CYGWIN__) || defined (__APPLE__)
1123 typedef GLvoid (*tess_t)();
1124 #elif defined ( WIN32)
1125 typedef GLvoid (CALLBACK *tess_t)( );
1127 #error "Error - need to define type tess_t for this platform/compiler"
1133 void Begin(Int_t type)
1135 Tesselation_t *dump = Tesselator::GetDump();
1139 dump->push_back(MeshPatch_t(type));
1144 void Vertex(
const Double_t *v)
1146 Tesselation_t *dump = Tesselator::GetDump();
1150 std::vector<Double_t> & vs = dump->back().fPatch;
1162 Tesselation_t *Tesselator::fVs = 0;
1166 Tesselator::Tesselator(Bool_t dump)
1169 GLUtesselator *tess = gluNewTess();
1171 throw std::runtime_error(
"tesselator creation failed");
1173 #if defined(__GNUC__) && __GNUC__ >= 8
1174 #pragma GCC diagnostic push
1175 #pragma GCC diagnostic ignored "-Wcast-function-type"
1179 gluTessCallback(tess, (GLenum)GLU_BEGIN, (tess_t) glBegin);
1180 gluTessCallback(tess, (GLenum)GLU_END, (tess_t) glEnd);
1181 gluTessCallback(tess, (GLenum)GLU_VERTEX, (tess_t) glVertex3dv);
1183 gluTessCallback(tess, (GLenum)GLU_BEGIN, (tess_t) Begin);
1184 gluTessCallback(tess, (GLenum)GLU_END, (tess_t) End);
1185 gluTessCallback(tess, (GLenum)GLU_VERTEX, (tess_t) Vertex);
1188 #if defined(__GNUC__) && __GNUC__ >= 8
1189 #pragma GCC diagnostic pop
1192 gluTessProperty(tess, GLU_TESS_TOLERANCE, 1e-10);
1198 Tesselator::~Tesselator()
1200 gluDeleteTess((GLUtesselator *)fTess);
1209 OffScreenDevice::OffScreenDevice(UInt_t w, UInt_t h, UInt_t x, UInt_t y, Bool_t top)
1210 : fW(w), fH(h), fX(x), fY(y), fTop(top)
1216 GLLimits::GLLimits()
1217 : fMaxLineWidth(0.),
1224 Double_t GLLimits::GetMaxLineWidth()
const
1226 if (!fMaxLineWidth) {
1227 Double_t lp[2] = {};
1228 glGetDoublev(lineWidthPNAME, lp);
1229 fMaxLineWidth = lp[1];
1232 return fMaxLineWidth;
1237 Double_t GLLimits::GetMaxPointSize()
const
1239 if (!fMaxPointSize) {
1240 Double_t lp[2] = {};
1241 glGetDoublev(pointSizePNAME, lp);
1242 fMaxPointSize = lp[1];
1245 return fMaxLineWidth;
1251 void ExtractRGBA(Color_t colorIndex, Float_t *rgba)
1253 const TColor *color = gROOT->GetColor(colorIndex);
1255 color->GetRGB(rgba[0], rgba[1], rgba[2]);
1256 rgba[3] = color->GetAlpha();
1262 template<
class ValueType>
1263 BoundingRect<ValueType> FindBoundingRect(Int_t nPoints,
const ValueType *xs,
const ValueType *ys)
1265 assert(nPoints > 0 &&
"FindBoundingRect, invalind number of points");
1266 assert(xs !=
nullptr &&
"FindBoundingRect, parameter 'xs' is null");
1267 assert(ys !=
nullptr &&
"FindBoundingRect, parameter 'ys' is null");
1269 ValueType xMin = xs[0], xMax = xMin;
1270 ValueType yMin = ys[0], yMax = yMin;
1272 for (Int_t i = 1; i < nPoints; ++i) {
1273 xMin = TMath::Min(xMin, xs[i]);
1274 xMax = TMath::Max(xMax, xs[i]);
1276 yMin = TMath::Min(yMin, ys[i]);
1277 yMax = TMath::Max(yMax, ys[i]);
1280 BoundingRect<ValueType> box = {};
1283 box.fWidth = xMax - xMin;
1287 box.fHeight = yMax - yMin;
1292 template BoundingRect<Double_t> FindBoundingRect(Int_t nPoints,
const Double_t *xs,
const Double_t *ys);
1293 template BoundingRect<Float_t> FindBoundingRect(Int_t nPoints,
const Float_t *xs,
const Float_t *ys);
1294 template BoundingRect<Long_t> FindBoundingRect(Int_t nPoints,
const Long_t *xs,
const Long_t *ys);
1295 template BoundingRect<Int_t> FindBoundingRect(Int_t nPoints,
const Int_t *xs,
const Int_t *ys);
1296 template BoundingRect<SCoord_t> FindBoundingRect(Int_t nPoints,
const SCoord_t *xs,
const SCoord_t *ys);
1304 void CalculateCircle(std::vector<TPoint> &circle, Double_t r, UInt_t pts)
1306 const Double_t delta = TMath::TwoPi() / pts;
1307 const UInt_t first = circle.size();
1308 Double_t angle = 0.;
1309 circle.resize(circle.size() + pts + 1);
1311 for (UInt_t i = 0; i < pts; ++i, angle += delta) {
1312 circle[first + i].fX = SCoord_t(r * TMath::Cos(angle));
1313 circle[first + i].fY = SCoord_t(r * TMath::Sin(angle));
1316 circle.back().fX = circle[first].fX;
1317 circle.back().fY = circle[first].fY;