30 using size_type = std::vector<TPoint>::size_type;
33 void ConvertPoints(
TVirtualPad *pad,
unsigned nPoints,
const T *xs,
const T *ys,
34 std::vector<TPoint> &dst);
36 void MergePointsX(std::vector<TPoint> &
points,
unsigned nMerged,
SCoord_t yMin,
40 size_type MergePointsInplaceY(std::vector<TPoint> &dst, size_type nMerged,
SCoord_t xMin,
44 void ConvertPointsAndMergePassX(
TVirtualPad *pad,
unsigned nPoints,
const T *
x,
const T *
y,
45 std::vector<TPoint> &dst);
47 void ConvertPointsAndMergeInplacePassY(std::vector<TPoint> &dst);
53 void DrawPolyLineAux(
TVirtualPad *pad,
unsigned nPoints,
const T *xs,
const T *ys);
56 void DrawPolyMarkerAux(
TVirtualPad *pad,
unsigned nPoints,
const T *xs,
const T *ys);
413 ::Error(
"TPadPainter::DrawFillArea",
"invalid number of points %d", nPoints);
417 DrawFillAreaAux(
gPad, nPoints, xs, ys);
427 ::Error(
"TPadPainter::DrawFillArea",
"invalid number of points %d", nPoints);
431 DrawFillAreaAux(
gPad, nPoints, xs, ys);
442 ::Error(
"TPadPainter::DrawPolyLine",
"invalid number of points");
446 DrawPolyLineAux(
gPad, n, xs, ys);
458 ::Error(
"TPadPainter::DrawPolyLine",
"invalid number of points");
462 DrawPolyLineAux(
gPad, n, xs, ys);
474 ::Error(
"TPadPainter::DrawPolyLineNDC",
"invalid number of points %d", n);
478 std::vector<TPoint>
xy(n);
480 for (
Int_t i = 0; i <
n; ++i) {
495 ::Error(
"TPadPainter::DrawPolyMarker",
"invalid number of points %d", n);
499 DrawPolyMarkerAux(
gPad, n, x, y);
509 ::Error(
"TPadPainter::DrawPolyMarker",
"invalid number of points %d", n);
513 DrawPolyMarkerAux(
gPad, n, x, y);
571 const std::unique_ptr<unsigned char[]>
574 if (pixelData.get()) {
578 if (
unsigned char *argb = (
unsigned char *)image->
GetArgbArray()) {
580 if (
sizeof(
UInt_t) == 4) {
583 std::copy(pixelData.get(), pixelData.get() + 4 * w *
h, argb);
587 const unsigned shift = std::numeric_limits<unsigned char>::digits;
589 unsigned *dstPixel = (
unsigned *)argb, *end = dstPixel + w * h;
590 const unsigned char *srcPixel = pixelData.get();
591 for (;dstPixel != end; ++dstPixel, srcPixel += 4) {
593 *dstPixel = srcPixel[0] & (srcPixel[1] << shift) &
594 (srcPixel[2] << 2 * shift) &
595 (srcPixel[3] << 3 * shift);
640 void ConvertPoints(
TVirtualPad *pad,
unsigned nPoints,
const T *
x,
const T *
y,
641 std::vector<TPoint> &dst)
648 for (
unsigned i = 0; i < nPoints; ++i) {
656 inline void MergePointsX(std::vector<TPoint> &
points,
unsigned nMerged,
SCoord_t yMin,
659 const auto firstPointX = points.back().fX;
660 const auto firstPointY = points.back().fY;
663 points.push_back(
TPoint(firstPointX, yLast));
664 }
else if (nMerged == 3) {
665 yMin == firstPointY ? points.push_back(
TPoint(firstPointX, yMax)) :
666 points.push_back(
TPoint(firstPointX, yMin));
667 points.push_back(
TPoint(firstPointX, yLast));
669 points.push_back(
TPoint(firstPointX, yMin));
670 points.push_back(
TPoint(firstPointX, yMax));
671 points.push_back(
TPoint(firstPointX, yLast));
678 inline size_type MergePointsInplaceY(std::vector<TPoint> &dst, size_type nMerged,
SCoord_t xMin,
681 const TPoint &firstPoint = dst[first];
684 dst[first + 1].fX = xLast;
685 dst[first + 1].fY = firstPoint.
fY;
686 }
else if (nMerged == 3) {
687 dst[first + 1].fX = xMin == firstPoint.
fX ? xMax : xMin;
688 dst[first + 1].fY = firstPoint.
fY;
689 dst[first + 2].fX = xLast;
690 dst[first + 2].fY = firstPoint.
fY;
692 dst[first + 1].fX = xMin;
693 dst[first + 1].fY = firstPoint.
fY;
694 dst[first + 2].fX = xMax;
695 dst[first + 2].fY = firstPoint.
fY;
696 dst[first + 3].fX = xLast;
697 dst[first + 3].fY = firstPoint.
fY;
710 void ConvertPointsAndMergePassX(
TVirtualPad *pad,
unsigned nPoints,
const T *x,
const T *y,
711 std::vector<TPoint> &dst)
715 SCoord_t yMin = 0, yMax = 0, yLast = 0;
716 unsigned nMerged = 0;
719 for (
unsigned i = 0; i < nPoints;) {
723 yMin = currentPoint.
fY;
726 dst.push_back(currentPoint);
730 for (
unsigned j = i + 1; j < nPoints; ++j) {
733 if (newX == currentPoint.
fX) {
740 MergePointsX(dst, nMerged, yMin, yMax, yLast);
746 if (!merged && nMerged > 1)
747 MergePointsX(dst, nMerged, yMin, yMax, yLast);
756 void ConvertPointsAndMergeInplacePassY(std::vector<TPoint> &dst)
759 for (size_type j = 1, nPoints = dst.size(); i < nPoints;) {
761 const TPoint ¤tPoint = dst[i];
768 size_type nMerged = 1;
770 for (; j < nPoints; ++j) {
771 const TPoint &nextPoint = dst[j];
773 if (nextPoint.
fY == currentPoint.
fY) {
774 xLast = nextPoint.
fX;
780 nMerged = MergePointsInplaceY(dst, nMerged, xMin, xMax, xLast, i);
786 if (!merged && nMerged > 1)
787 nMerged = MergePointsInplaceY(dst, nMerged, xMin, xMax, xLast, i);
807 void ConvertPointsAndMerge(
TVirtualPad *pad,
unsigned threshold,
unsigned nPoints,
const T *x,
808 const T *y, std::vector<TPoint> &dst)
818 dst.reserve(threshold);
820 ConvertPointsAndMergePassX(pad, nPoints, x, y, dst);
822 if (dst.size() < threshold)
825 ConvertPointsAndMergeInplacePassY(dst);
833 std::vector<TPoint>
xy;
838 if (threshold <= 0) {
840 ::Error(
"DrawFillAreaAux",
"invalid pad's geometry");
844 if (nPoints < threshold)
845 ConvertPoints(
gPad, nPoints, xs, ys, xy);
847 ConvertPointsAndMerge(
gPad, threshold, nPoints, xs, ys, xy);
851 xy.push_back(xy.front());
854 gVirtualX->DrawFillArea(xy.size(), &xy[0]);
860 void DrawPolyLineAux(
TVirtualPad *pad,
unsigned nPoints,
const T *xs,
const T *ys)
862 std::vector<TPoint>
xy;
867 if (threshold <= 0) {
868 ::Error(
"DrawPolyLineAux",
"invalid pad's geometry");
872 if (nPoints < (
unsigned)threshold)
873 ConvertPoints(pad, nPoints, xs, ys, xy);
875 ConvertPointsAndMerge(pad, threshold, nPoints, xs, ys, xy);
878 gVirtualX->DrawPolyLine(xy.size(), &xy[0]);
885 void DrawPolyMarkerAux(
TVirtualPad *pad,
unsigned nPoints,
const T *xs,
const T *ys)
887 std::vector<TPoint>
xy(nPoints);
889 for (
unsigned i = 0; i < nPoints; ++i) {
894 gVirtualX->DrawPolyMarker(nPoints, &xy[0]);
void DrawPolyMarker(Int_t n, const Double_t *x, const Double_t *y)
Paint polymarker.
void CopyDrawable(Int_t id, Int_t px, Int_t py)
Copy a gVirtualX pixmap.
Style_t GetLineStyle() const
Delegate to gVirtualX.
Float_t GetTextAngle() const
Delegate to gVirtualX.
Int_t GetCanvasID() const
Get canvas identifier.
Float_t GetTextSize() const
Delegate to gVirtualX.
void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v)
Paint polyline in normalized coordinates.
virtual void WriteImage(const char *, EImageFileTypes=TImage::kUnknown)
virtual Int_t XtoPixel(Double_t x) const =0
void SetFillStyle(Style_t fstyle)
Delegate to gVirtualX.
virtual UInt_t * GetArgbArray()
virtual Double_t GetAbsWNDC() const =0
virtual Int_t YtoPixel(Double_t y) const =0
void SetLineStyle(Style_t lstyle)
Delegate to gVirtualX.
Short_t Min(Short_t a, Short_t b)
void SelectDrawable(Int_t device)
Select the window in which the graphics will go.
virtual UInt_t GetWh() const =0
void SetTextColor(Color_t tcolor)
Delegate to gVirtualX.
void Flush()
Flush canvas buffers.
void SetTextSizePixels(Int_t npixels)
Delegate to gVirtualX.
virtual Double_t GetAbsHNDC() const =0
static const double x2[5]
void DrawFillArea(Int_t n, const Double_t *x, const Double_t *y)
Paint filled area.
UInt_t GetWw() const
Get Ww.
virtual void DrawRectangle(UInt_t, UInt_t, UInt_t, UInt_t, const char *="#000000", UInt_t=1)
void DrawText(Double_t x, Double_t y, const char *text, ETextMode mode)
Paint text.
TVirtualPad is an abstract base class for the Pad and Canvas classes.
void ClearDrawable()
Clear the current gVirtualX window.
void Error(const char *location, const char *msgfmt,...)
Short_t GetTextAlign() const
Delegate to gVirtualX.
void SetFillColor(Color_t fcolor)
Delegate to gVirtualX.
void SetTextAlign(Short_t align)
Delegate to gVirtualX.
Color_t GetTextColor() const
Delegate to gVirtualX.
void DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, EBoxMode mode)
Paint a simple box.
void SetLineWidth(Width_t lwidth)
Delegate to gVirtualX.
void DrawPixels(const unsigned char *pixelData, UInt_t width, UInt_t height, Int_t dstX, Int_t dstY, Bool_t enableAlphaBlending)
Noop, for non-gl pad TASImage calls gVirtualX->CopyArea.
void DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2)
Paint a simple line in normalized coordinates.
Float_t GetTextMagnitude() const
Delegate to gVirtualX.
UInt_t GetWh() const
Get Wh.
void SetOpacity(Int_t percent)
Delegate to gVirtualX.
virtual UInt_t GetWw() const =0
Color_t GetFillColor() const
Delegate to gVirtualX.
void DestroyDrawable()
Close the current gVirtualX pixmap.
void SaveImage(TVirtualPad *pad, const char *fileName, Int_t type) const
Save the image displayed in the canvas pointed by "pad" into a binary file.
Width_t GetLineWidth() const
Delegate to gVirtualX.
static const double x1[5]
void SetTextAngle(Float_t tangle)
Delegate to gVirtualX.
void SetTextSize(Float_t tsize)
Delegate to gVirtualX.
virtual void FromPad(TVirtualPad *, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Int_t CreateDrawable(UInt_t w, UInt_t h)
Create a gVirtualX Pixmap.
Bool_t IsTransparent() const
Delegate to gVirtualX.
void SetLineColor(Color_t lcolor)
Delegate to gVirtualX.
void DrawTextNDC(Double_t u, Double_t v, const char *text, ETextMode mode)
Paint text in normalized coordinates.
void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Paint a simple line.
Color_t GetLineColor() const
Delegate to gVirtualX.
void DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y)
Paint Polyline.
Short_t Max(Short_t a, Short_t b)
Font_t GetTextFont() const
Delegate to gVirtualX.
Implement TVirtualPadPainter which abstracts painting operations.
static TImage * Create()
Create an image.
Style_t GetFillStyle() const
Delegate to gVirtualX.
void SetTextFont(Font_t tfont)
Delegate to gVirtualX.
virtual TCanvas * GetCanvas() const =0