Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPadPainter.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Olivier Couet, Timur Pocheptsov (vertex merge) 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 <algorithm>
13#include <limits>
14#include <memory>
15#include <vector>
16
17#include "TPadPainter.h"
18#include "TVirtualX.h"
19#include "TSystem.h"
20#include "TASUtils.h"
21#include "TCanvas.h"
22#include "TPoint.h"
23#include "TError.h"
24#include "TImage.h"
25#include "TROOT.h"
26#include "TMath.h"
27#include "TPad.h"
28
29namespace {
30
31//Typedef is fine, but let's pretend we look cool and modern:
32using size_type = std::vector<TPoint>::size_type;
33
34template<typename T>
35void ConvertPoints(TVirtualPad *pad, unsigned nPoints, const T *xs, const T *ys,
36 std::vector<TPoint> &dst, Bool_t absCoord = kFALSE);
37inline
38void MergePointsX(std::vector<TPoint> &points, unsigned nMerged, SCoord_t yMin,
39 SCoord_t yMax, SCoord_t yLast);
40
41inline
42size_type MergePointsInplaceY(std::vector<TPoint> &dst, size_type nMerged, SCoord_t xMin,
43 SCoord_t xMax, SCoord_t xLast, size_type first);
44
45template<typename T>
46void ConvertPointsAndMergePassX(TVirtualPad *pad, unsigned nPoints, const T *x, const T *y,
47 std::vector<TPoint> &dst);
48
49void ConvertPointsAndMergeInplacePassY(std::vector<TPoint> &dst);
50
51template<class T>
52void DrawFillAreaAux(TVirtualPad *pad, WinContext_t cont, Bool_t absCoord, Int_t nPoints, const T *xs, const T *ys, Bool_t add_first_point);
53
54template<typename T>
55void DrawPolyLineAux(TVirtualPad *pad, WinContext_t cont, Bool_t absCoord, unsigned nPoints, const T *xs, const T *ys);
56
57template<class T>
58void DrawPolyMarkerAux(TVirtualPad *pad, WinContext_t cont, Bool_t absCoord, unsigned nPoints, const T *xs, const T *ys);
59
60
61}
62
63
64/** \class TPadPainter
65\ingroup gpad
66
67Implement TVirtualPadPainter which abstracts painting operations.
68*/
69
70////////////////////////////////////////////////////////////////////////////////
71///Empty ctor. We need it only because of explicit copy ctor.
72
76
77/*
78Line/fill/etc. attributes can be set inside TPad, but not only where:
79many of them are set by base sub-objects of 2d primitives
80(2d primitives usually inherit TAttLine or TAttFill etc.). And these sub-objects
81call gVirtualX->SetLineWidth ... etc. So, if I save some attributes in my painter,
82it will be mess - at any moment I do not know, where to take line attribute - from
83gVirtualX or from my own member. So! All attributed, _ALL_ go to/from gVirtualX.
84*/
85
86
87////////////////////////////////////////////////////////////////////////////////
88/// Delegate to gVirtualX.
89
94
95////////////////////////////////////////////////////////////////////////////////
96/// Delegate to gVirtualX.
97
99{
100 return gVirtualX->GetTextMagnitude();
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// Create a gVirtualX Pixmap.
105
107{
108 return gVirtualX->OpenPixmap(Int_t(w), Int_t(h));
109}
110
111////////////////////////////////////////////////////////////////////////////////
112/// Resize a gVirtualX Pixmap.
113
115{
116 return gVirtualX->ResizePixmap(device, w, h);
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// Returns true when X11 backend is used
121
123{
124 return gVirtualX->InheritsFrom("TGX11");
125}
126
127////////////////////////////////////////////////////////////////////////////////
128/// Returns true when cocoa backend is used
129
131{
132 return gVirtualX->InheritsFrom("TGCocoa");
133}
134
135////////////////////////////////////////////////////////////////////////////////
136/// Returns true if transparent colors are supported
137
139{
140 return gVirtualX->InheritsFrom("TGQuartz");
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Clear the current gVirtualX window - calling gVirtualX->ClearWindowW
145
147{
148 if (fWinContext)
149 gVirtualX->ClearWindowW(fWinContext);
150}
151
152////////////////////////////////////////////////////////////////////////////////
153/// Clear specified window - calling gVirtualX->ClearWindowW
154
156{
157 auto ctxt = gVirtualX->GetWindowContext(device);
158 if (ctxt)
159 gVirtualX->ClearWindowW(ctxt);
160}
161
162////////////////////////////////////////////////////////////////////////////////
163/// Copy a gVirtualX pixmap.
164
166{
167 gVirtualX->CopyPixmapW(fWinContext, device, px, py);
168}
169
170////////////////////////////////////////////////////////////////////////////////
171/// Close the current gVirtualX pixmap.
172
174{
175 gVirtualX->SelectWindow(device);
176 gVirtualX->ClosePixmap();
178}
179
180////////////////////////////////////////////////////////////////////////////////
181/// Select the window in which the graphics will go.
182
184{
185 gVirtualX->SelectWindow(device);
186 fWinContext = gVirtualX->GetWindowContext(device);
187}
188
189////////////////////////////////////////////////////////////////////////////////
190/// Call low-level update of selected drawable, redirect to gVirtualX.
191
193{
194 gVirtualX->UpdateWindowW(fWinContext, mode);
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// Set drawing mode for specified device
199
201{
202 gVirtualX->SetDrawModeW(gVirtualX->GetWindowContext(device), (TVirtualX::EDrawMode) mode);
203}
204
205////////////////////////////////////////////////////////////////////////////////
206/// Set double buffer mode for specified device
207
209{
210 // important flag - when disabled canvas pixmap used directly
211 // so one need to use absolute coordinates
213
214 gVirtualX->SetDoubleBuffer(device, mode);
215}
216
217////////////////////////////////////////////////////////////////////////////////
218/// Return true if TTF font can be used
219
221{
222 return gVirtualX->HasTTFonts();
223}
224
225////////////////////////////////////////////////////////////////////////////////
226/// Draw image on the gVirtualX window
227
229{
230 Window_t wid = gVirtualX->GetWindowID(fPad->GetPixmapID());
231
232 // use old API to draw image on gVirtualX window
233 // img->PaintImage(wid, x, y, 0, 0, 0, 0, flags ? "" : "opaque");
234
235 // new API invokes
236 TASUtils::PaintImage(img, wid, x, y, !flags);
237}
238
239////////////////////////////////////////////////////////////////////////////////
240///Noop, for non-gl pad TASImage calls gVirtualX->CopyArea.
241
242void TPadPainter::DrawPixels(const unsigned char * /*pixelData*/, UInt_t /*width*/, UInt_t /*height*/,
243 Int_t /*dstX*/, Int_t /*dstY*/, Bool_t /*enableAlphaBlending*/)
244{
245}
246
247////////////////////////////////////////////////////////////////////////////////
248/// Set fill attributes
249
251{
253
255
256 gVirtualX->SetAttFill(fWinContext, fill);
257}
258
259////////////////////////////////////////////////////////////////////////////////
260/// Set line attributes
261
263{
265
266 gVirtualX->SetAttLine(fWinContext, att);
267}
268
269////////////////////////////////////////////////////////////////////////////////
270/// Set marker attributes
271
273{
275
276 gVirtualX->SetAttMarker(fWinContext, att);
277}
278
279////////////////////////////////////////////////////////////////////////////////
280/// Set text attributes
281
283{
285
286 // TODO: in ROOT7 move text size handling directly to correspondent PS engine
287 // One not need to recalculate text size many time back and forth
288
289 if (!fPad)
290 Fatal("SetAttText", "Pad not specified");
291
292 TAttText attm(att);
294
295 gVirtualX->SetAttText(fWinContext, attm);
296}
297
298////////////////////////////////////////////////////////////////////////////////
299/// Paint a simple line.
300
302{
303 if (fAttLine.GetLineWidth() <= 0)
304 return;
305
306 const Int_t px1 = fDoubleBuffer ? gPad->XtoPixel(x1) : gPad->XtoAbsPixel(x1);
307 const Int_t px2 = fDoubleBuffer ? gPad->XtoPixel(x2) : gPad->XtoAbsPixel(x2);
308 const Int_t py1 = fDoubleBuffer ? gPad->YtoPixel(y1) : gPad->YtoAbsPixel(y1);
309 const Int_t py2 = fDoubleBuffer ? gPad->YtoPixel(y2) : gPad->YtoAbsPixel(y2);
310 gVirtualX->DrawLineW(fWinContext, px1, py1, px2, py2);
311}
312
313
314////////////////////////////////////////////////////////////////////////////////
315/// Paint a simple line in normalized coordinates.
316
318{
319 if (fAttLine.GetLineWidth() <= 0)
320 return;
321
322 const Int_t px1 = fDoubleBuffer ? gPad->UtoPixel(u1) : gPad->UtoAbsPixel(u1);
323 const Int_t py1 = fDoubleBuffer ? gPad->VtoPixel(v1) : gPad->VtoAbsPixel(v1);
324 const Int_t px2 = fDoubleBuffer ? gPad->UtoPixel(u2) : gPad->UtoAbsPixel(u2);
325 const Int_t py2 = fDoubleBuffer ? gPad->VtoPixel(v2) : gPad->VtoAbsPixel(v2);
326 gVirtualX->DrawLineW(fWinContext, px1, py1, px2, py2);
327}
328
329
330////////////////////////////////////////////////////////////////////////////////
331/// Paint a simple box.
332
334{
336 return;
337
339 return;
340
341 Int_t px1 = fDoubleBuffer ? gPad->XtoPixel(x1) : gPad->XtoAbsPixel(x1);
342 Int_t px2 = fDoubleBuffer ? gPad->XtoPixel(x2) : gPad->XtoAbsPixel(x2);
343 Int_t py1 = fDoubleBuffer ? gPad->YtoPixel(y1) : gPad->YtoAbsPixel(y1);
344 Int_t py2 = fDoubleBuffer ? gPad->YtoPixel(y2) : gPad->YtoAbsPixel(y2);
345
346 // Box width must be at least one pixel (WTF is this code???)
347 if (TMath::Abs(px2 - px1) < 1)
348 px2 = px1 + 1;
349 if (TMath::Abs(py1 - py2) < 1)
350 py1 = py2 + 1;
351
352 gVirtualX->DrawBoxW(fWinContext, px1, py1, px2, py2, (TVirtualX::EBoxMode)mode);
353}
354
355////////////////////////////////////////////////////////////////////////////////
356/// Paint filled area.
357
358void TPadPainter::DrawFillArea(Int_t nPoints, const Double_t *xs, const Double_t *ys)
359{
360 if (nPoints < 3) {
361 ::Error("TPadPainter::DrawFillArea", "invalid number of points %d", nPoints);
362 return;
363 }
364
365 // if fully transparent, add first point to draw line
366 DrawFillAreaAux(gPad, fWinContext, !fDoubleBuffer, nPoints, xs, ys, fFullyTransparent);
367}
368
369
370////////////////////////////////////////////////////////////////////////////////
371/// Paint filled area.
372
373void TPadPainter::DrawFillArea(Int_t nPoints, const Float_t *xs, const Float_t *ys)
374{
375 if (nPoints < 3) {
376 ::Error("TPadPainter::DrawFillArea", "invalid number of points %d", nPoints);
377 return;
378 }
379
380 // if fully transparent, add first point to draw line
381 DrawFillAreaAux(gPad, fWinContext, !fDoubleBuffer, nPoints, xs, ys, fFullyTransparent);
382}
383
384////////////////////////////////////////////////////////////////////////////////
385/// Paint Polyline.
386
388{
389 if (fAttLine.GetLineWidth() <= 0)
390 return;
391
392 if (n < 2) {
393 ::Error("TPadPainter::DrawPolyLine", "invalid number of points");
394 return;
395 }
396
397 DrawPolyLineAux(gPad, fWinContext, !fDoubleBuffer, n, xs, ys);
398}
399
400
401////////////////////////////////////////////////////////////////////////////////
402/// Paint polyline.
403
405{
406 if (fAttLine.GetLineWidth() <= 0)
407 return;
408
409 if (n < 2) {
410 ::Error("TPadPainter::DrawPolyLine", "invalid number of points");
411 return;
412 }
413
414 DrawPolyLineAux(gPad, fWinContext, !fDoubleBuffer, n, xs, ys);
415}
416
417
418////////////////////////////////////////////////////////////////////////////////
419/// Paint polyline in normalized coordinates.
420
422{
423 if (fAttLine.GetLineWidth() <= 0)
424 return;
425
426 if (n < 2) {
427 ::Error("TPadPainter::DrawPolyLineNDC", "invalid number of points %d", n);
428 return;
429 }
430
431 std::vector<TPoint> xy(n);
432
433 for (Int_t i = 0; i < n; ++i) {
434 xy[i].fX = (SCoord_t)gPad->UtoPixel(u[i]);
435 xy[i].fY = (SCoord_t)gPad->VtoPixel(v[i]);
436 }
437
438 gVirtualX->DrawPolyLineW(fWinContext, n, &xy[0]);
439}
440
441////////////////////////////////////////////////////////////////////////////////
442/// Paint N segments on the pad
443
445{
446 if (fAttLine.GetLineWidth() <= 0)
447 return;
448
449 if (n < 1) {
450 ::Error("TPadPainter::DrawSegments", "invalid number of segments %d", n);
451 return;
452 }
453
454 std::vector<TPoint> xy(n*2);
455 Int_t cnt = 0;
456 for (Int_t i = 0; i < n*2; ++i) {
457 if ((i % 2 == 0) && (x[i] == x[i+1]) && (y[i] == y[i+1])) {
458 // exclude empty segment
459 i++;
460 continue;
461 }
462
463 xy[cnt].fX = (SCoord_t)gPad->XtoPixel(x[i]);
464 xy[cnt].fY = (SCoord_t)gPad->YtoPixel(y[i]);
465 cnt++;
466 }
467
468 if (cnt > 1)
469 gVirtualX->DrawLinesSegmentsW(fWinContext, cnt/2, &xy[0]);
470}
471
472////////////////////////////////////////////////////////////////////////////////
473/// Paint N segments in normalized coordinates on the pad
474
476{
477 if (fAttLine.GetLineWidth() <= 0)
478 return;
479
480 if (n < 1) {
481 ::Error("TPadPainter::DrawSegmentsNDC", "invalid number of segments %d", n);
482 return;
483 }
484
485 std::vector<TPoint> xy(n*2);
486 Int_t cnt = 0;
487 for (Int_t i = 0; i < n*2; ++i) {
488 if ((i % 2 == 0) && (u[i] == u[i+1]) && (v[i] == v[i+1])) {
489 // exclude empty segment
490 i++;
491 continue;
492 }
493
494 xy[cnt].fX = (SCoord_t)gPad->UtoPixel(u[i]);
495 xy[cnt].fY = (SCoord_t)gPad->VtoPixel(v[i]);
496 cnt++;
497 }
498
499 if (cnt > 1)
500 gVirtualX->DrawLinesSegmentsW(fWinContext, cnt/2, &xy[0]);
501}
502
503
504
505////////////////////////////////////////////////////////////////////////////////
506/// Paint polymarker.
507
509{
510 if (n < 1) {
511 ::Error("TPadPainter::DrawPolyMarker", "invalid number of points %d", n);
512 return;
513 }
514
515 DrawPolyMarkerAux(gPad, fWinContext, !fDoubleBuffer, n, x, y);
516}
517
518////////////////////////////////////////////////////////////////////////////////
519/// Paint polymarker.
520
522{
523 if (n < 1) {
524 ::Error("TPadPainter::DrawPolyMarker", "invalid number of points %d", n);
525 return;
526 }
527
528 DrawPolyMarkerAux(gPad, fWinContext, !fDoubleBuffer, n, x, y);
529}
530
531////////////////////////////////////////////////////////////////////////////////
532/// Paint TTF glyps on virtualx device
533
538
539////////////////////////////////////////////////////////////////////////////////
540/// Helper method to check if TImage is present in list of primitives
541
543{
544 TIter next(pad->GetListOfPrimitives());
545
546 while (auto obj = next()) {
547 if (obj->InheritsFrom(TImage::Class()))
548 return kTRUE;
549 if (auto subpad = dynamic_cast<TPad *>(obj))
550 if (ContainsTImage(subpad))
551 return kTRUE;
552 }
553 return kFALSE;
554}
555
556////////////////////////////////////////////////////////////////////////////////
557/// Save the image displayed in the canvas pointed by "pad" into a binary file.
558
560{
561 // for X11 and Winows there is special GIF, which works only with maximal 256-colors
562 // Do not try to use it for pads with TImage inside - it most probably fails
563 if ((type == TImage::kGif) && pad && !IsCocoa() && !ContainsTImage(pad)) {
564 gVirtualX->Update(1);
565 gSystem->Sleep(30);
567
568 Int_t wid = (pad == pad->GetCanvas()) ? pad->GetCanvasID() : pad->GetPixmapID();
569 auto ctxt = gVirtualX->GetWindowContext(wid);
570 // TODO: GIF image is special, if fail - try use TImage functionality
571 Int_t res = gVirtualX->WriteGIFW(ctxt, fileName);
572 if (res > 0)
573 return kSaveOk;
574 }
575
577}
578
579////////////////////////////////////////////////////////////////////////////////
580/// Fill image object with the pixel data from the pad
581/// Use TASUtils::FillImageFromWindow method which provides native X11 handling
582
584{
585 if (!image || !pad)
586 return kFALSE;
587
588 auto width = pad->GetPadWidth();
589 auto height = pad->GetPadHeight();
590
591 Int_t wid = (pad == pad->GetCanvas()) ? pad->GetCanvasID() : pad->GetPixmapID();
592 gVirtualX->SelectWindow(wid);
593
594 Window_t wd = gVirtualX->GetCurrentWindow();
595 return TASUtils::FillImageFromWindow(image, wd, width, height);
596}
597
598//Aux. private functions.
599namespace {
600
601////////////////////////////////////////////////////////////////////////////////
602///I'm using 'pad' pointer to get rid of this damned gPad.
603///Unfortunately, TPadPainter itself still has to use it.
604///But at least this code does not have to be fixed.
605
606template<typename T>
607void ConvertPoints(TVirtualPad *pad, unsigned nPoints, const T *x, const T *y,
608 std::vector<TPoint> &dst, Bool_t absCoord)
609{
610 if (!nPoints)
611 return;
612
613 dst.resize(nPoints);
614
615 if (absCoord) {
616 for (unsigned i = 0; i < nPoints; ++i) {
617 dst[i].fX = (SCoord_t) pad->XtoAbsPixel(x[i]);
618 dst[i].fY = (SCoord_t) pad->YtoAbsPixel(y[i]);
619 }
620 } else {
621 for (unsigned i = 0; i < nPoints; ++i) {
622 dst[i].fX = (SCoord_t) pad->XtoPixel(x[i]);
623 dst[i].fY = (SCoord_t) pad->YtoPixel(y[i]);
624 }
625 }
626}
627
628////////////////////////////////////////////////////////////////////////////////
629
630inline void MergePointsX(std::vector<TPoint> &points, unsigned nMerged, SCoord_t yMin,
631 SCoord_t yMax, SCoord_t yLast)
632{
633 const auto firstPointX = points.back().fX;
634 const auto firstPointY = points.back().fY;
635
636 if (nMerged == 2) {
637 points.push_back(TPoint(firstPointX, yLast));//We have not merge anything.
638 } else if (nMerged == 3) {
639 yMin == firstPointY ? points.push_back(TPoint(firstPointX, yMax)) :
640 points.push_back(TPoint(firstPointX, yMin));
641 points.push_back(TPoint(firstPointX, yLast));
642 } else {
643 points.push_back(TPoint(firstPointX, yMin));
644 points.push_back(TPoint(firstPointX, yMax));
645 points.push_back(TPoint(firstPointX, yLast));
646 }
647}
648
649////////////////////////////////////////////////////////////////////////////////
650///Indices below are _valid_.
651
652inline size_type MergePointsInplaceY(std::vector<TPoint> &dst, size_type nMerged, SCoord_t xMin,
653 SCoord_t xMax, SCoord_t xLast, size_type first)
654{
655 const TPoint &firstPoint = dst[first];//This point is never updated.
656
657 if (nMerged == 2) {
658 dst[first + 1].fX = xLast;
659 dst[first + 1].fY = firstPoint.fY;
660 } else if (nMerged == 3) {
661 dst[first + 1].fX = xMin == firstPoint.fX ? xMax : xMin;
662 dst[first + 1].fY = firstPoint.fY;
663 dst[first + 2].fX = xLast;
664 dst[first + 2].fY = firstPoint.fY;
665 } else {
666 dst[first + 1].fX = xMin;
667 dst[first + 1].fY = firstPoint.fY;
668 dst[first + 2].fX = xMax;
669 dst[first + 2].fY = firstPoint.fY;
670 dst[first + 3].fX = xLast;
671 dst[first + 3].fY = firstPoint.fY;
672 nMerged = 4;//Adjust the shift.
673 }
674
675 return nMerged;
676}
677
678////////////////////////////////////////////////////////////////////////////////
679/// I'm using 'pad' pointer to get rid of this damned gPad.
680/// Unfortunately, TPadPainter itself still has to use it.
681/// But at least this code does not have to be fixed.
682
683template<typename T>
684void ConvertPointsAndMergePassX(TVirtualPad *pad, unsigned nPoints, const T *x, const T *y,
685 std::vector<TPoint> &dst)
686{
687 //The "first" pass along X axis.
688 TPoint currentPoint;
689 SCoord_t yMin = 0, yMax = 0, yLast = 0;
690 unsigned nMerged = 0;
691
692 //The first pass along X.
693 for (unsigned i = 0; i < nPoints;) {
694 currentPoint.fX = (SCoord_t)pad->XtoPixel(x[i]);
695 currentPoint.fY = (SCoord_t)pad->YtoPixel(y[i]);
696
697 yMin = currentPoint.fY;
698 yMax = yMin;
699
700 dst.push_back(currentPoint);
701 bool merged = false;
702 nMerged = 1;
703
704 for (unsigned j = i + 1; j < nPoints; ++j) {
705 const SCoord_t newX = pad->XtoPixel(x[j]);
706
707 if (newX == currentPoint.fX) {
708 yLast = pad->YtoPixel(y[j]);
709 yMin = TMath::Min(yMin, yLast);
710 yMax = TMath::Max(yMax, yLast);//We continue.
711 ++nMerged;
712 } else {
713 if (nMerged > 1)
714 MergePointsX(dst, nMerged, yMin, yMax, yLast);
715 merged = true;
716 break;
717 }
718 }
719
720 if (!merged && nMerged > 1)
721 MergePointsX(dst, nMerged, yMin, yMax, yLast);
722
723 i += nMerged;
724 }
725}
726
727////////////////////////////////////////////////////////////////////////////////
728/// This pass is a bit more complicated, since we have to 'compact' in-place.
729
730void ConvertPointsAndMergeInplacePassY(std::vector<TPoint> &dst)
731{
732 size_type i = 0;
733 for (size_type j = 1, nPoints = dst.size(); i < nPoints;) {
734 //i is always less than j, so i is always valid here.
735 const TPoint &currentPoint = dst[i];
736
737 SCoord_t xMin = currentPoint.fX;
738 SCoord_t xMax = xMin;
739 SCoord_t xLast = 0;
740
741 bool merged = false;
742 size_type nMerged = 1;
743
744 for (; j < nPoints; ++j) {
745 const TPoint &nextPoint = dst[j];
746
747 if (nextPoint.fY == currentPoint.fY) {
748 xLast = nextPoint.fX;
749 xMin = TMath::Min(xMin, xLast);
750 xMax = TMath::Max(xMax, xLast);
751 ++nMerged;//and we continue ...
752 } else {
753 if (nMerged > 1)
754 nMerged = MergePointsInplaceY(dst, nMerged, xMin, xMax, xLast, i);
755 merged = true;
756 break;
757 }
758 }
759
760 if (!merged && nMerged > 1)
761 nMerged = MergePointsInplaceY(dst, nMerged, xMin, xMax, xLast, i);
762
763 i += nMerged;
764
765 if (j < nPoints) {
766 dst[i] = dst[j];
767 ++j;
768 } else
769 break;
770 }
771
772 dst.resize(i);
773}
774
775////////////////////////////////////////////////////////////////////////////////
776/// This is a quite simple algorithm, using the fact, that after conversion many
777/// subsequent vertices can have the same 'x' or 'y' coordinate and this part of
778/// a polygon will look like a line on the screen.
779
780template<typename T>
781void ConvertPointsAndMerge(TVirtualPad *pad, unsigned threshold, unsigned nPoints, const T *x,
782 const T *y, std::vector<TPoint> &dst)
783{
784 //I'm using 'pad' pointer to get rid of this damned gPad.
785 //Unfortunately, TPadPainter itself still has to use it.
786 //But at least this code does not have to be fixed.
787
788 if (!nPoints)
789 return;
790
791 dst.clear();
792 dst.reserve(threshold);
793
794 ConvertPointsAndMergePassX(pad, nPoints, x, y, dst);
795
796 if (dst.size() < threshold)
797 return;
798
799 ConvertPointsAndMergeInplacePassY(dst);
800}
801
802////////////////////////////////////////////////////////////////////////////////
803
804template<class T>
805void DrawFillAreaAux(TVirtualPad *pad, WinContext_t cont, Bool_t absCoord, Int_t nPoints, const T *xs, const T *ys, Bool_t add_first_point)
806{
807 std::vector<TPoint> xy;
808
809 const Int_t threshold = Int_t(TMath::Min(pad->GetWw() * pad->GetAbsWNDC(),
810 pad->GetWh() * pad->GetAbsHNDC())) * 2;
811
812 if (threshold <= 0) {
813 //Ooops, pad is invisible or something really bad and stupid happened.
814 ::Error("DrawFillAreaAux", "invalid pad's geometry");
815 return;
816 }
817
818 if (absCoord || (nPoints < threshold))
819 ConvertPoints(pad, nPoints, xs, ys, xy, absCoord);
820 else
821 ConvertPointsAndMerge(pad, threshold, nPoints, xs, ys, xy);
822
823 //We close the 'polygon' so it can be rendered as a polyline by gVirtualX.
824 if (add_first_point)
825 xy.push_back(xy.front());
826
827 if (xy.size() > 2)
828 gVirtualX->DrawFillAreaW(cont, xy.size(), xy.data());
829}
830
831////////////////////////////////////////////////////////////////////////////////
832
833template <typename T>
834void DrawPolyLineAux(TVirtualPad *pad, WinContext_t cont, Bool_t absCoord, unsigned nPoints, const T *xs, const T *ys)
835{
836 std::vector<TPoint> xy;
837
838 const UInt_t threshold = TMath::Min(pad->GetPadWidth(), pad->GetPadHeight()) * 2;
839
840 if (threshold == 0) {//Ooops, pad is invisible or something really bad and stupid happened.
841 ::Error("DrawPolyLineAux", "invalid pad's geometry");
842 return;
843 }
844
845 if (absCoord || (nPoints < threshold))
846 ConvertPoints(pad, nPoints, xs, ys, xy, absCoord);
847 else
848 ConvertPointsAndMerge(pad, threshold, nPoints, xs, ys, xy);
849
850 if (xy.size() > 1)
851 gVirtualX->DrawPolyLineW(cont, xy.size(), xy.data());
852}
853
854////////////////////////////////////////////////////////////////////////////////
855
856template<class T>
857void DrawPolyMarkerAux(TVirtualPad *pad, WinContext_t cont, Bool_t absCoord, unsigned nPoints, const T *xs, const T *ys)
858{
859 std::vector<TPoint> xy;
860
861 ConvertPoints(pad, nPoints, xs, ys, xy, absCoord);
862
863 gVirtualX->DrawPolyMarkerW(cont, nPoints, xy.data());
864}
865
866}
Handle_t WinContext_t
Window drawing context.
Definition GuiTypes.h:30
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
#define h(i)
Definition RSha256.hxx:106
double * dst
char * device
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:78
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:61
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
short SCoord_t
Screen coordinates (short)
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
void Fatal(const char *location, const char *msgfmt,...)
Use this function in case of a fatal error. It will abort the program.
Definition TError.cxx:267
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize wid
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint xy
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t points
Option_t Option_t width
Option_t Option_t TPoint TPoint percent
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 Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Option_t Option_t TPoint TPoint const char y1
static Bool_t ContainsTImage(const TVirtualPad *pad)
Helper method to check if TImage is present in list of primitives.
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
#define gPad
#define gVirtualX
Definition TVirtualX.h:391
static Bool_t FillImageFromWindow(TImage *img, Window_t wid, Int_t width, Int_t height)
Create an image from the given window.
Definition TASUtils.cxx:161
static Bool_t PaintImage(TImage *timg, Drawable_t wid, Int_t x, Int_t y, Bool_t opaque=kFALSE)
Paint image on specified window.
Definition TASUtils.cxx:259
Fill Area Attributes class.
Definition TAttFill.h:21
Line Attributes class.
Definition TAttLine.h:21
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:38
Marker Attributes class.
Definition TAttMarker.h:22
Text Attributes class.
Definition TAttText.h:21
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:53
virtual Float_t GetTextSizePixels(TVirtualPad &pad) const
Return the text size in pixels for specified pad.
Definition TAttText.cxx:350
An abstract interface to image processing library.
Definition TImage.h:30
@ kGif
Definition TImage.h:49
static TClass * Class()
void SetAttFill(const TAttFill &att) override
Set fill attributes.
ESaveImageResult SaveAsImage(TVirtualPad *pad, const char *fileName, Int_t type) const override
Store pad image into the file One should provide FillImageFromPad implementation in the subclass.
void SetAttText(const TAttText &att) override
Set text attributes.
TAttLine fAttLine
current line attributes
Bool_t fFullyTransparent
if transformed fill attributes fully transparent
void SetAttMarker(const TAttMarker &att) override
Set marker attributes.
void SetAttLine(const TAttLine &att) override
Set line attributes.
WinContext_t fWinContext
TVirtualPad * fPad
TAttFill GetAttFillInternal(Bool_t with_transparency)
Returns fill attributes after modification Checks for special fill styles 4000 .
void DrawSegments(Int_t n, Double_t *x, Double_t *y) override
Paint N segments on the pad.
TPadPainter()
Empty ctor. We need it only because of explicit copy ctor.
void DrawFillArea(Int_t n, const Double_t *x, const Double_t *y) override
Paint filled area.
void SetAttText(const TAttText &att) override
Set text attributes.
void DrawPixels(const unsigned char *pixelData, UInt_t width, UInt_t height, Int_t dstX, Int_t dstY, Bool_t enableAlphaBlending) override
Noop, for non-gl pad TASImage calls gVirtualX->CopyArea.
void UpdateDrawable(Int_t mode) override
Call low-level update of selected drawable, redirect to gVirtualX.
void CopyDrawable(Int_t device, Int_t px, Int_t py) override
Copy a gVirtualX pixmap.
void SetAttMarker(const TAttMarker &att) override
Set marker attributes.
void DrawTTFglyphs(Int_t x, Int_t y, TTFhandle &ttf, ETextMode mode) override
Paint TTF glyps on virtualx device.
void DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y) override
Paint Polyline.
Int_t fDoubleBuffer
Definition TPadPainter.h:27
Int_t ResizeDrawable(Int_t device, UInt_t w, UInt_t h) override
Resize a gVirtualX Pixmap.
Float_t GetTextMagnitude() const override
Delegate to gVirtualX.
Bool_t IsX11() const override
Returns true when X11 backend is used.
Bool_t IsSupportAlpha() const override
Returns true if transparent colors are supported.
void ClearWindow(Int_t device) override
Clear specified window - calling gVirtualX->ClearWindowW.
Int_t CreateDrawable(UInt_t w, UInt_t h) override
Create a gVirtualX Pixmap.
void SetAttFill(const TAttFill &att) override
Set fill attributes.
void DrawPolyMarker(Int_t n, const Double_t *x, const Double_t *y) override
Paint polymarker.
void SetOpacity(Int_t percent) override
Delegate to gVirtualX.
Bool_t IsCocoa() const override
Returns true when cocoa backend is used.
Bool_t FillImageFromPad(TImage *image, TVirtualPad *pad) const override
Fill image object with the pixel data from the pad Use TASUtils::FillImageFromWindow method which pro...
void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v) override
Paint polyline in normalized coordinates.
Bool_t HasTTFonts() const override
Return true if TTF font can be used.
void SetDrawMode(Int_t device, Int_t mode) override
Set drawing mode for specified device.
void ClearDrawable() override
Clear the current gVirtualX window - calling gVirtualX->ClearWindowW.
void DestroyDrawable(Int_t device) override
Close the current gVirtualX pixmap.
void DrawSegmentsNDC(Int_t n, Double_t *u, Double_t *v) override
Paint N segments in normalized coordinates on the pad.
void SetAttLine(const TAttLine &att) override
Set line attributes.
void SelectDrawable(Int_t device) override
Select the window in which the graphics will go.
void DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, EBoxMode mode) override
Paint a simple box.
void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override
Paint a simple line.
ESaveImageResult SaveAsImage(TVirtualPad *pad, const char *fileName, Int_t type) const override
Save the image displayed in the canvas pointed by "pad" into a binary file.
void DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2) override
Paint a simple line in normalized coordinates.
void DrawImage(TImage *img, Int_t x, Int_t y, Int_t flags=0) override
Draw image on the gVirtualX window.
void SetDoubleBuffer(Int_t device, Int_t mode) override
Set double buffer mode for specified device.
The most important graphics class in the ROOT system.
Definition TPad.h:32
SCoord_t fY
Definition TPoint.h:36
SCoord_t fX
Definition TPoint.h:35
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition TSystem.cxx:441
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition TSystem.cxx:420
Dynamic handle to work with freetype 2 library.
Definition TTFhandle.h:22
virtual void const char * fileName
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:53
virtual Int_t YtoAbsPixel(Double_t y) const =0
virtual TList * GetListOfPrimitives() const =0
virtual Int_t YtoPixel(Double_t y) const =0
virtual UInt_t GetWh() const =0
virtual Int_t XtoAbsPixel(Double_t x) const =0
virtual UInt_t GetPadWidth() const =0
virtual Int_t GetPixmapID() const =0
virtual Double_t GetAbsWNDC() const =0
virtual UInt_t GetPadHeight() const =0
virtual Double_t GetAbsHNDC() const =0
virtual Int_t XtoPixel(Double_t x) const =0
virtual UInt_t GetWw() const =0
virtual Int_t GetCanvasID() const =0
virtual TCanvas * GetCanvas() const =0
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:249
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:197
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:122