Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/base/inc/TVirtualPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class TVirtualPS : public TNamed, public TAttLine, public TAttFill, public TAttM
virtual void DrawPolyMarker(Int_t n, Double_t *x, Double_t *y) = 0;
virtual void DrawPS(Int_t n, Float_t *xw, Float_t *yw) = 0;
virtual void DrawPS(Int_t n, Double_t *xw, Double_t *yw) = 0;
virtual void DrawSegments(Int_t n, Double_t *xw, Double_t *yw);
virtual void NewPage() = 0;
virtual void Open(const char *filename, Int_t type=-111) = 0;
virtual void Text(Double_t x, Double_t y, const char *string) = 0;
Expand Down
2 changes: 2 additions & 0 deletions core/base/inc/TVirtualPad.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ class TVirtualPad : public TObject, public TAttLine, public TAttFill,
virtual void PaintPolyLineNDC(Int_t n, Double_t *x, Double_t *y, Option_t *option="") = 0;
virtual void PaintPolyMarker(Int_t n, Float_t *x, Float_t *y, Option_t *option="") = 0;
virtual void PaintPolyMarker(Int_t n, Double_t *x, Double_t *y, Option_t *option="") = 0;
virtual void PaintSegments(Int_t n, Double_t *x, Double_t *y, Option_t *option="");
virtual void PaintSegmentsNDC(Int_t n, Double_t *u, Double_t *v);
virtual void PaintMarker3D(Double_t x, Double_t y, Double_t z) = 0;
virtual void PaintModified() = 0;
virtual void PaintText(Double_t x, Double_t y, const char *text) = 0;
Expand Down
3 changes: 3 additions & 0 deletions core/base/inc/TVirtualPadPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class TVirtualPadPainter {
virtual void DrawPolyLine(Int_t n, const Float_t *x, const Float_t *y) = 0;
virtual void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v) = 0;

virtual void DrawSegments(Int_t n, const Double_t *x, const Double_t *y);
virtual void DrawSegmentsNDC(Int_t n, const Double_t *u, const Double_t *v);

virtual void DrawPolyMarker(Int_t n, const Double_t *x, const Double_t *y) = 0;
virtual void DrawPolyMarker(Int_t n, const Float_t *x, const Float_t *y) = 0;

Expand Down
1 change: 1 addition & 0 deletions core/base/inc/TVirtualX.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class TVirtualX : public TNamed, public TAttLine, public TAttFill, public TAttTe
virtual void DrawFillArea(Int_t n, TPoint *xy);
virtual void DrawLine(Int_t x1, Int_t y1, Int_t x2, Int_t y2);
virtual void DrawPolyLine(Int_t n, TPoint *xy);
virtual void DrawLinesSegments(Int_t n, TPoint *xy);
virtual void DrawPolyMarker(Int_t n, TPoint *xy);
virtual void DrawText(Int_t x, Int_t y, Float_t angle, Float_t mgn, const char *text,
ETextMode mode);
Expand Down
14 changes: 14 additions & 0 deletions core/base/src/TVirtualPS.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,17 @@ void TVirtualPS::PrintRaw(Int_t len, const char *str)
}
fPrinted = kTRUE;
}


////////////////////////////////////////////////////////////////////////////////
/// Print N segments
/// \param [in] n number of segments
/// \param [in] xw array of X coordinates, size 2*n
/// \param [in] yw array of Y coordinates, size 2*n

void TVirtualPS::DrawSegments(Int_t n, Double_t *xw, Double_t *yw)
{
for(Int_t i = 0; i < 2*n; i += 2)
if ((xw[i] != xw[i+1]) || (yw[i] != yw[i+1]))
DrawPS(2, &xw[i], &yw[i]);
}
22 changes: 22 additions & 0 deletions core/base/src/TVirtualPad.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,28 @@ Bool_t TVirtualPad::PadInHighlightMode() const
return kFALSE;
}

////////////////////////////////////////////////////////////////////////////////
/// Paint N individual segments
/// Provided arrays should have 2*n elements
/// IMPORTANT! Provided arrays can be modified after function call!

void TVirtualPad::PaintSegments(Int_t n, Double_t *x, Double_t *y, Option_t *)
{
for (Int_t i = 0; i < 2*n; i += 2)
PaintLine(x[i], y[i], x[i+1], y[i+1]);
}

////////////////////////////////////////////////////////////////////////////////
/// Paint N individual segments in NDC coordinates
/// Provided arrays should have 2*n elements

void TVirtualPad::PaintSegmentsNDC(Int_t n, Double_t *u, Double_t *v)
{
for (Int_t i = 0; i < 2*n; i += 2)
PaintLineNDC(u[i], v[i], u[i+1], v[i+1]);
}


////////////////////////////////////////////////////////////////////////////////
/// Does nothing, unless you implement your own picking.
/// When complex object containing sub-objects (which can be picked)
Expand Down
23 changes: 23 additions & 0 deletions core/base/src/TVirtualPadPainter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,26 @@ TVirtualPadPainter *TVirtualPadPainter::PadPainter(Option_t *type)

return painter;
}


////////////////////////////////////////////////////////////////////////////////
/// Draw N segments on the pad
/// Exclude segments where both points match

void TVirtualPadPainter::DrawSegments(Int_t n, const Double_t *x, const Double_t *y)
{
for(Int_t i = 0; i <= 2*n; i += 2)
if ((x[i] != x[i+1]) || (y[i] != y[i + 1]))
DrawLine(x[i], y[i], x[i+1], y[i+1]);
}

////////////////////////////////////////////////////////////////////////////////
/// Draw N segments in NDC coordinates on the pad
/// Exclude segments where both points match

void TVirtualPadPainter::DrawSegmentsNDC(Int_t n, const Double_t *u, const Double_t *v)
{
for(Int_t i = 0; i <= 2*n; i += 2)
if ((u[i] != u[i+1]) || (v[i] != v[i + 1]))
DrawLineNDC(u[i], v[i], u[i+1], v[i+1]);
}
14 changes: 14 additions & 0 deletions core/base/src/TVirtualX.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ An instance of TVirtualX itself defines a batch interface to the graphics system

#include "TVirtualX.h"
#include "TString.h"
#include "TPoint.h"


Atom_t gWM_DELETE_WINDOW;
Expand Down Expand Up @@ -320,6 +321,19 @@ void TVirtualX::DrawPolyLine(Int_t /*n*/, TPoint * /*xy*/)
{
}

////////////////////////////////////////////////////////////////////////////////
/// Draws N segments between provided points
///
/// \param [in] n number of segemtns
/// \param [in] xy list of points, size 2*n

void TVirtualX::DrawLinesSegments(Int_t n, TPoint *xy)
{
for(Int_t i = 0; i < 2*n; i += 2)
DrawPolyLine(2, &xy[i]);
}


////////////////////////////////////////////////////////////////////////////////
/// Draws "n" markers with the current attributes at position [x,y].
///
Expand Down
2 changes: 2 additions & 0 deletions graf2d/gpad/inc/TPad.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ friend class TWebCanvas;
void PaintPolyLineNDC(Int_t n, Double_t *x, Double_t *y, Option_t *option="") override;
void PaintPolyMarker(Int_t n, Float_t *x, Float_t *y, Option_t *option="") override;
void PaintPolyMarker(Int_t n, Double_t *x, Double_t *y, Option_t *option="") override;
void PaintSegments(Int_t n, Double_t *x, Double_t *y, Option_t *option="") override;
void PaintSegmentsNDC(Int_t n, Double_t *u, Double_t *v) override;
void PaintMarker3D(Double_t x, Double_t y, Double_t z) override;
void PaintModified() override;
void PaintText(Double_t x, Double_t y, const char *text) override;
Expand Down
3 changes: 3 additions & 0 deletions graf2d/gpad/inc/TPadPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class TPadPainter : public TVirtualPadPainter {
void DrawPolyLine(Int_t n, const Float_t *x, const Float_t *y) override;
void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v) override;

void DrawSegments(Int_t n, const Double_t *x, const Double_t *y) override;
void DrawSegmentsNDC(Int_t n, const Double_t *u, const Double_t *v) override;

//TPad needs both versions.
void DrawPolyMarker(Int_t n, const Double_t *x, const Double_t *y) override;
void DrawPolyMarker(Int_t n, const Float_t *x, const Float_t *y) override;
Expand Down
64 changes: 64 additions & 0 deletions graf2d/gpad/src/TPad.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4751,6 +4751,70 @@ void TPad::PaintPolyMarker(Int_t nn, Double_t *x, Double_t *y, Option_t *)
Modified();
}

////////////////////////////////////////////////////////////////////////////////
/// Paint N individual segments
/// Provided arrays should have 2*n elements
/// IMPORTANT! Provided arrays can be modified after function call!

void TPad::PaintSegments(Int_t n, Double_t *x, Double_t *y, Option_t *option)
{
if (n < 1)
return;

Double_t xmin,xmax,ymin,ymax;
Bool_t mustClip = kTRUE, isAny = kFALSE;
if (TestBit(TGraph::kClipFrame)) {
xmin = fUxmin; ymin = fUymin; xmax = fUxmax; ymax = fUymax;
} else {
xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
if (option && *option == 'C') mustClip = kFALSE;
}

if (!mustClip)
isAny = kTRUE;
else {
for (Int_t i = 0; i < 2*n; i+=2) {
Int_t iclip = Clip(&x[i],&y[i],xmin,ymin,xmax,ymax);
if (iclip == 2)
x[i] = y[i] = x[i+1] = y[i+1] = 0;
else
isAny = kTRUE;
}
}

if (isAny && !gPad->IsBatch() && GetPainter())
GetPainter()->DrawSegments(n, x, y);

if (isAny && gVirtualPS)
gVirtualPS->DrawSegments(n, x, y);

Modified();
}


////////////////////////////////////////////////////////////////////////////////
/// Paint N individual segments in NDC coordinates
/// Provided arrays should have 2*n elements
/// IMPORTANT! Provided arrays can be modified after function call!

void TPad::PaintSegmentsNDC(Int_t n, Double_t *u, Double_t *v)
{
if (!gPad->IsBatch() && GetPainter())
GetPainter()->DrawSegmentsNDC(n, u, v);

if (gVirtualPS) {
// recalculate values into normal coordiantes
for (Int_t i = 0; i < 2*n; i++) {
u[i] = fX1 + u[i]*(fX2 - fX1);
v[i] = fY1 + v[i]*(fY2 - fY1);
}
gVirtualPS->DrawSegments(n, u, v);
}

Modified();
}


////////////////////////////////////////////////////////////////////////////////
/// Paint text in CurrentPad World coordinates.

Expand Down
63 changes: 63 additions & 0 deletions graf2d/gpad/src/TPadPainter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,69 @@ void TPadPainter::DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v)
gVirtualX->DrawPolyLine(n, &xy[0]);
}

////////////////////////////////////////////////////////////////////////////////
/// Paint N segments on the pad

void TPadPainter::DrawSegments(Int_t n, const Double_t *x, const Double_t *y)
{
if (GetLineWidth() <= 0)
return;

if (n < 1) {
::Error("TPadPainter::DrawSegments", "invalid number of segments %d", n);
return;
}

std::vector<TPoint> xy(n*2);
Int_t cnt = 0;
for (Int_t i = 0; i < n*2; ++i) {
if ((i % 2 == 0) && (x[i] == x[i+1]) && (y[i] == y[i+1])) {
// exclude empty segment
i++;
continue;
}

xy[cnt].fX = (SCoord_t)gPad->XtoPixel(x[i]);
xy[cnt].fY = (SCoord_t)gPad->YtoPixel(y[i]);
cnt++;
}

if (cnt > 1)
gVirtualX->DrawLinesSegments(cnt/2, &xy[0]);
}

////////////////////////////////////////////////////////////////////////////////
/// Paint N segments in normalized coordinates on the pad

void TPadPainter::DrawSegmentsNDC(Int_t n, const Double_t *u, const Double_t *v)
{
if (GetLineWidth() <= 0)
return;

if (n < 1) {
::Error("TPadPainter::DrawSegmentsNDC", "invalid number of segments %d", n);
return;
}

std::vector<TPoint> xy(n*2);
Int_t cnt = 0;
for (Int_t i = 0; i < n*2; ++i) {
if ((i % 2 == 0) && (u[i] == u[i+1]) && (v[i] == v[i+1])) {
// exclude empty segment
i++;
continue;
}

xy[cnt].fX = (SCoord_t)gPad->UtoPixel(u[i]);
xy[cnt].fY = (SCoord_t)gPad->VtoPixel(v[i]);
cnt++;
}

if (cnt > 1)
gVirtualX->DrawLinesSegments(cnt/2, &xy[0]);
}



////////////////////////////////////////////////////////////////////////////////
/// Paint polymarker.
Expand Down
Loading
Loading