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);
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);
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) {
static const double x2[5]
static const double x1[5]
void Error(const char *location, const char *msgfmt,...)
UInt_t GetWh() const
Get Wh.
Int_t GetCanvasID() const
Get canvas identifier.
UInt_t GetWw() const
Get Ww.
void Flush()
Flush canvas buffers.
static TImage * Create()
Create an image.
Implement TVirtualPadPainter which abstracts painting operations.
void SetFillColor(Color_t fcolor)
Delegate to gVirtualX.
Float_t GetTextAngle() const
Delegate to gVirtualX.
void SetLineColor(Color_t lcolor)
Delegate to gVirtualX.
TPadPainter()
Empty ctor. We need it only because of explicit copy ctor.
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.
Int_t CreateDrawable(UInt_t w, UInt_t h)
Create a gVirtualX Pixmap.
void SetLineStyle(Style_t lstyle)
Delegate to gVirtualX.
void SetTextSize(Float_t tsize)
Delegate to gVirtualX.
Style_t GetFillStyle() const
Delegate to gVirtualX.
void SetTextSizePixels(Int_t npixels)
Delegate to gVirtualX.
void DestroyDrawable(Int_t device)
Close the current gVirtualX pixmap.
void DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y)
Paint Polyline.
Color_t GetTextColor() const
Delegate to gVirtualX.
void DrawTextNDC(Double_t u, Double_t v, const char *text, ETextMode mode)
Paint text in normalized coordinates.
Style_t GetLineStyle() const
Delegate to gVirtualX.
void SetLineWidth(Width_t lwidth)
Delegate to gVirtualX.
Float_t GetTextMagnitude() const
Delegate to gVirtualX.
Short_t GetTextAlign() const
Delegate to gVirtualX.
void SetTextFont(Font_t tfont)
Delegate to gVirtualX.
void DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, EBoxMode mode)
Paint a simple box.
void SetTextAlign(Short_t align)
Delegate to gVirtualX.
Color_t GetFillColor() const
Delegate to gVirtualX.
Color_t GetLineColor() const
Delegate to gVirtualX.
void SetFillStyle(Style_t fstyle)
Delegate to gVirtualX.
Bool_t IsTransparent() const
Delegate to gVirtualX.
void SetTextAngle(Float_t tangle)
Delegate to gVirtualX.
Width_t GetLineWidth() const
Delegate to gVirtualX.
void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Paint a simple line.
void ClearDrawable()
Clear the current gVirtualX window.
void SetOpacity(Int_t percent)
Delegate to gVirtualX.
void DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2)
Paint a simple line in normalized coordinates.
void SelectDrawable(Int_t device)
Select the window in which the graphics will go.
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.
Float_t GetTextSize() const
Delegate to gVirtualX.
void CopyDrawable(Int_t device, Int_t px, Int_t py)
Copy a gVirtualX pixmap.
void DrawText(Double_t x, Double_t y, const char *text, ETextMode mode)
Paint text.
void SetTextColor(Color_t tcolor)
Delegate to gVirtualX.
void DrawPolyMarker(Int_t n, const Double_t *x, const Double_t *y)
Paint polymarker.
void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v)
Paint polyline in normalized coordinates.
void DrawFillArea(Int_t n, const Double_t *x, const Double_t *y)
Paint filled area.
Font_t GetTextFont() const
Delegate to gVirtualX.
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)
Short_t Min(Short_t a, Short_t b)