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);
414 ::Error(
"TPadPainter::DrawFillArea",
"invalid number of points %d", nPoints);
418 DrawFillAreaAux(
gPad, nPoints, xs, ys);
428 ::Error(
"TPadPainter::DrawFillArea",
"invalid number of points %d", nPoints);
432 DrawFillAreaAux(
gPad, nPoints, xs, ys);
443 ::Error(
"TPadPainter::DrawPolyLine",
"invalid number of points");
447 DrawPolyLineAux(
gPad, n, xs, ys);
459 ::Error(
"TPadPainter::DrawPolyLine",
"invalid number of points");
463 DrawPolyLineAux(
gPad, n, xs, ys);
475 ::Error(
"TPadPainter::DrawPolyLineNDC",
"invalid number of points %d", n);
479 std::vector<TPoint>
xy(n);
481 for (
Int_t i = 0; i <
n; ++i) {
496 ::Error(
"TPadPainter::DrawPolyMarker",
"invalid number of points %d", n);
500 DrawPolyMarkerAux(
gPad, n, x, y);
510 ::Error(
"TPadPainter::DrawPolyMarker",
"invalid number of points %d", n);
514 DrawPolyMarkerAux(
gPad, n, x, y);
572 const std::unique_ptr<unsigned char[]>
575 if (pixelData.get()) {
579 if (
unsigned char *argb = (
unsigned char *)image->
GetArgbArray()) {
581 if (
sizeof(
UInt_t) == 4) {
584 std::copy(pixelData.get(), pixelData.get() + 4 * w *
h, argb);
588 const unsigned shift = std::numeric_limits<unsigned char>::digits;
590 unsigned *dstPixel = (
unsigned *)argb, *end = dstPixel + w * h;
591 const unsigned char *srcPixel = pixelData.get();
592 for (;dstPixel != end; ++dstPixel, srcPixel += 4) {
594 *dstPixel = srcPixel[0] & (srcPixel[1] << shift) &
595 (srcPixel[2] << 2 * shift) &
596 (srcPixel[3] << 3 * shift);
641 void ConvertPoints(
TVirtualPad *pad,
unsigned nPoints,
const T *
x,
const T *
y,
642 std::vector<TPoint> &dst)
649 for (
unsigned i = 0; i < nPoints; ++i) {
657 inline void MergePointsX(std::vector<TPoint> &
points,
unsigned nMerged,
SCoord_t yMin,
660 const auto firstPointX = points.back().fX;
661 const auto firstPointY = points.back().fY;
664 points.push_back(
TPoint(firstPointX, yLast));
665 }
else if (nMerged == 3) {
666 yMin == firstPointY ? points.push_back(
TPoint(firstPointX, yMax)) :
667 points.push_back(
TPoint(firstPointX, yMin));
668 points.push_back(
TPoint(firstPointX, yLast));
670 points.push_back(
TPoint(firstPointX, yMin));
671 points.push_back(
TPoint(firstPointX, yMax));
672 points.push_back(
TPoint(firstPointX, yLast));
679 inline size_type MergePointsInplaceY(std::vector<TPoint> &dst, size_type nMerged,
SCoord_t xMin,
682 const TPoint &firstPoint = dst[first];
685 dst[first + 1].fX = xLast;
686 dst[first + 1].fY = firstPoint.
fY;
687 }
else if (nMerged == 3) {
688 dst[first + 1].fX = xMin == firstPoint.
fX ? xMax : xMin;
689 dst[first + 1].fY = firstPoint.
fY;
690 dst[first + 2].fX = xLast;
691 dst[first + 2].fY = firstPoint.
fY;
693 dst[first + 1].fX = xMin;
694 dst[first + 1].fY = firstPoint.
fY;
695 dst[first + 2].fX = xMax;
696 dst[first + 2].fY = firstPoint.
fY;
697 dst[first + 3].fX = xLast;
698 dst[first + 3].fY = firstPoint.
fY;
711 void ConvertPointsAndMergePassX(
TVirtualPad *pad,
unsigned nPoints,
const T *x,
const T *y,
712 std::vector<TPoint> &dst)
716 SCoord_t yMin = 0, yMax = 0, yLast = 0;
717 unsigned nMerged = 0;
720 for (
unsigned i = 0; i < nPoints;) {
724 yMin = currentPoint.
fY;
727 dst.push_back(currentPoint);
731 for (
unsigned j = i + 1; j < nPoints; ++j) {
734 if (newX == currentPoint.
fX) {
741 MergePointsX(dst, nMerged, yMin, yMax, yLast);
747 if (!merged && nMerged > 1)
748 MergePointsX(dst, nMerged, yMin, yMax, yLast);
757 void ConvertPointsAndMergeInplacePassY(std::vector<TPoint> &dst)
760 for (size_type j = 1, nPoints = dst.size(); i < nPoints;) {
762 const TPoint ¤tPoint = dst[i];
769 size_type nMerged = 1;
771 for (; j < nPoints; ++j) {
772 const TPoint &nextPoint = dst[j];
774 if (nextPoint.
fY == currentPoint.
fY) {
775 xLast = nextPoint.
fX;
781 nMerged = MergePointsInplaceY(dst, nMerged, xMin, xMax, xLast, i);
787 if (!merged && nMerged > 1)
788 nMerged = MergePointsInplaceY(dst, nMerged, xMin, xMax, xLast, i);
808 void ConvertPointsAndMerge(
TVirtualPad *pad,
unsigned threshold,
unsigned nPoints,
const T *x,
809 const T *y, std::vector<TPoint> &dst)
819 dst.reserve(threshold);
821 ConvertPointsAndMergePassX(pad, nPoints, x, y, dst);
823 if (dst.size() < threshold)
826 ConvertPointsAndMergeInplacePassY(dst);
834 std::vector<TPoint>
xy;
839 if (threshold <= 0) {
841 ::Error(
"DrawFillAreaAux",
"invalid pad's geometry");
845 if (nPoints < threshold)
846 ConvertPoints(
gPad, nPoints, xs, ys, xy);
848 ConvertPointsAndMerge(
gPad, threshold, nPoints, xs, ys, xy);
852 xy.push_back(xy.front());
855 gVirtualX->DrawFillArea(xy.size(), &xy[0]);
861 void DrawPolyLineAux(
TVirtualPad *pad,
unsigned nPoints,
const T *xs,
const T *ys)
863 std::vector<TPoint>
xy;
868 if (threshold <= 0) {
869 ::Error(
"DrawPolyLineAux",
"invalid pad's geometry");
873 if (nPoints < (
unsigned)threshold)
874 ConvertPoints(pad, nPoints, xs, ys, xy);
876 ConvertPointsAndMerge(pad, threshold, nPoints, xs, ys, xy);
879 gVirtualX->DrawPolyLine(xy.size(), &xy[0]);
886 void DrawPolyMarkerAux(
TVirtualPad *pad,
unsigned nPoints,
const T *xs,
const T *ys)
888 std::vector<TPoint>
xy(nPoints);
890 for (
unsigned i = 0; i < nPoints; ++i) {
895 gVirtualX->DrawPolyMarker(nPoints, &xy[0]);
void DrawPolyMarker(Int_t n, const Double_t *x, const Double_t *y)
Paint polymarker.
void DestroyDrawable(Int_t device)
Close the current 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.
void CopyDrawable(Int_t device, Int_t px, Int_t py)
Copy a gVirtualX pixmap.
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.
TPadPainter()
Empty ctor. We need it only because of explicit copy ctor.
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 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