30using size_type = std::vector<TPoint>::size_type;
33void ConvertPoints(
TVirtualPad *pad,
unsigned nPoints,
const T *xs,
const T *ys,
34 std::vector<TPoint> &dst);
36void MergePointsX(std::vector<TPoint> &
points,
unsigned nMerged,
SCoord_t yMin,
40size_type MergePointsInplaceY(std::vector<TPoint> &dst, size_type nMerged,
SCoord_t xMin,
44void ConvertPointsAndMergePassX(
TVirtualPad *pad,
unsigned nPoints,
const T *
x,
const T *
y,
45 std::vector<TPoint> &dst);
47void ConvertPointsAndMergeInplacePassY(std::vector<TPoint> &dst);
50void DrawFillAreaAux(
TVirtualPad *pad,
Int_t nPoints,
const T *xs,
const T *ys);
53void DrawPolyLineAux(
TVirtualPad *pad,
unsigned nPoints,
const T *xs,
const T *ys);
56void 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()) {
578 image->DrawRectangle(0, 0,
w,
h);
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);
641void ConvertPoints(
TVirtualPad *pad,
unsigned nPoints,
const T *
x,
const T *
y,
642 std::vector<TPoint> &dst)
649 for (
unsigned i = 0; i < nPoints; ++i) {
657inline 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;
665 }
else if (nMerged == 3) {
666 yMin == firstPointY ?
points.push_back(
TPoint(firstPointX, yMax)) :
679inline size_type MergePointsInplaceY(std::vector<TPoint> &dst, size_type nMerged,
SCoord_t xMin,
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;
711void 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);
757void 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);
808void 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);
832void DrawFillAreaAux(
TVirtualPad *pad,
Int_t nPoints,
const T *xs,
const T *ys)
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());
861void 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);
886void 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) {
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint angle
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 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 text
Option_t Option_t TPoint TPoint const char y1
Int_t GetCanvasID() const override
UInt_t GetWw() const override
UInt_t GetWh() const override
void Flush()
Flush canvas buffers.
static TImage * Create()
Create an image.
Implement TVirtualPadPainter which abstracts painting operations.
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.
Color_t GetFillColor() const override
Delegate to gVirtualX.
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.
Float_t GetTextAngle() const override
Delegate to gVirtualX.
void CopyDrawable(Int_t device, Int_t px, Int_t py) override
Copy a gVirtualX pixmap.
void SetFillColor(Color_t fcolor) override
Delegate to gVirtualX.
Float_t GetTextSize() const override
Delegate to gVirtualX.
Style_t GetFillStyle() const override
Delegate to gVirtualX.
void DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y) override
Paint Polyline.
Short_t GetTextAlign() const override
Delegate to gVirtualX.
Style_t GetLineStyle() const override
Delegate to gVirtualX.
Bool_t IsTransparent() const override
Delegate to gVirtualX.
Float_t GetTextMagnitude() const override
Delegate to gVirtualX.
Color_t GetTextColor() const override
Delegate to gVirtualX.
Int_t CreateDrawable(UInt_t w, UInt_t h) override
Create a gVirtualX Pixmap.
void SetTextSize(Float_t tsize) override
Delegate to gVirtualX.
void SetTextAlign(Short_t align) override
Delegate to gVirtualX.
void SetFillStyle(Style_t fstyle) override
Delegate to gVirtualX.
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.
void SetTextAngle(Float_t tangle) override
Delegate to gVirtualX.
void DrawTextNDC(Double_t u, Double_t v, const char *text, ETextMode mode) override
Paint text in normalized coordinates.
void SetTextFont(Font_t tfont) override
Delegate to gVirtualX.
void SaveImage(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 SetLineStyle(Style_t lstyle) override
Delegate to gVirtualX.
Font_t GetTextFont() const override
Delegate to gVirtualX.
void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v) override
Paint polyline in normalized coordinates.
void ClearDrawable() override
Clear the current gVirtualX window.
void DestroyDrawable(Int_t device) override
Close the current gVirtualX pixmap.
Width_t GetLineWidth() const override
Delegate to gVirtualX.
void SetTextColor(Color_t tcolor) override
Delegate to gVirtualX.
void SetLineWidth(Width_t lwidth) override
Delegate to gVirtualX.
void SetTextSizePixels(Int_t npixels) override
Delegate to gVirtualX.
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 SetLineColor(Color_t lcolor) override
Delegate to gVirtualX.
Color_t GetLineColor() const override
Delegate to gVirtualX.
void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override
Paint a simple line.
void DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2) override
Paint a simple line in normalized coordinates.
void DrawText(Double_t x, Double_t y, const char *text, ETextMode mode) override
Paint text.
TVirtualPad is an abstract base class for the Pad and Canvas classes.
virtual Int_t YtoPixel(Double_t y) const =0
virtual UInt_t GetWh() const =0
virtual Double_t GetAbsWNDC() const =0
virtual Double_t GetAbsHNDC() const =0
virtual Int_t XtoPixel(Double_t x) const =0
virtual UInt_t GetWw() const =0
virtual TCanvas * GetCanvas() const =0
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.