Skip to content
Draft
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
8 changes: 7 additions & 1 deletion core/base/inc/TAttMarker.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ class TAttMarker {
virtual void SetMarkerSize(Size_t msize = 1);

enum EMarkerShape { kShapeDot, kShapeCircle, kShapeFilledCircle, kShapePolyLine, kShapeFilledArea, kShapeSegments, kShapeTriangles };
enum {
kPreferTriangles = BIT(0), // return kShapeTriangles instead of kShapeFilledArea
kDotAsLines = BIT(1), // convert small and medium dot into lines/segments, used in graphics output
kDotAsCircle = BIT(2), // convert small and medium dots into circles
kUsePSWidthScale = BIT(3) // special scaling factor for the marker size calculations
};

EMarkerShape GetMarkerShape(Int_t &sz, std::vector<TPoint> &points, Float_t scale = 1., Bool_t prefer_triangles = kFALSE) const;
EMarkerShape GetMarkerShape(Int_t &sz, std::vector<TPoint> &points, Float_t scale = 1., UInt_t flags = 0) const;

static Style_t GetMarkerStyleBase(Style_t style);
static Width_t GetMarkerLineWidth(Style_t style);
Expand Down
109 changes: 71 additions & 38 deletions core/base/src/TAttMarker.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -404,16 +404,23 @@ void TAttMarker::SetMarkerSize(Size_t msize)
////////////////////////////////////////////////////////////////////////////////
/// Return marker shape.
/// Depending from configured marker style different marker shapes are returned
/// For simple shape like circle just size is assigned, for other points vector is filled as well
/// For special applications (like GL) one can create set of triangles instead of complex filled shapes
/// This is required while GL not always able to correctly fill closed shape

TAttMarker::EMarkerShape TAttMarker::GetMarkerShape(Int_t &sz, std::vector<TPoint> &shape, Float_t scale, Bool_t prefer_triangles) const
/// \param sz return pixel size of the marker shape is returned (diamter for circle shapes)
/// \param shape will contains vector of shape points
/// \param scale defines scaling factor for size and shape coordinates
/// \param flags let configure following options:
/// kPreferTriangles - return kShapeTriangles instead of kShapeFilledArea, used when graphics engine not able to fill complex area
/// kDotAsLines - convert small and medium dot into lines/fillrec which are directly drawn by pixel devices
/// kDotAsCircle - automatically convert small and medium dots into circles
/// kUsePSWidthScale - use gStyle->GetLineScalePS() for marker size calculations

TAttMarker::EMarkerShape TAttMarker::GetMarkerShape(Int_t &sz, std::vector<TPoint> &shape, Float_t scale, UInt_t flags) const
{
Int_t markerStyle = GetMarkerStyleBase(GetMarkerStyle());
Int_t markerLineWidth = GetMarkerLineWidth(GetMarkerStyle());

Float_t markerSizeReduced = scale * (GetMarkerSize() - std::floor(markerLineWidth/2.)/4.);
Float_t wscale = (flags & kUsePSWidthScale) ? gStyle->GetLineScalePS() / 4. : 1.;

Float_t markerSizeReduced = scale * (GetMarkerSize() - std::floor(markerLineWidth/2.)/4. * wscale);
const auto im = std::round(4*markerSizeReduced);
const auto im2 = std::round(2*markerSizeReduced);

Expand All @@ -433,11 +440,12 @@ TAttMarker::EMarkerShape TAttMarker::GetMarkerShape(Int_t &sz, std::vector<TPoin
shape.emplace_back(x2, y1);
};

sz = 0;
sz = 2 * im;
shape.clear();

switch (markerStyle) {
case kDot:
sz = 1;
return kShapeDot;
case kPlus:
shape.resize(4);
Expand Down Expand Up @@ -474,20 +482,36 @@ TAttMarker::EMarkerShape TAttMarker::GetMarkerShape(Int_t &sz, std::vector<TPoin
return kShapeSegments;
}
case kFullDotSmall:
shape.resize(4);
shape[0].fX = -1; shape[0].fY = 0;
shape[1].fX = 1; shape[1].fY = 0;
shape[2].fX = 0; shape[2].fY = -1;
shape[3].fX = 0; shape[3].fY = 1;
return kShapeSegments;
if (flags & kDotAsLines) {
shape.resize(4);
shape[0].fX = -1; shape[0].fY = 0;
shape[1].fX = 1; shape[1].fY = 0;
shape[2].fX = 0; shape[2].fY = -1;
shape[3].fX = 0; shape[3].fY = 1;
return kShapeSegments;
} else if (flags & kDotAsCircle) {
sz = 4;
return kShapeFilledCircle;
} else {
sz = 2;
return kShapeDot;
}
case kFullDotMedium:
shape.resize(5);
shape[0].fX = -1; shape[0].fY = -1;
shape[1].fX = 1; shape[1].fY = -1;
shape[2].fX = 1; shape[2].fY = 1;
shape[3].fX = -1; shape[3].fY = 1;
shape[4].fX = -1; shape[4].fY = -1;
return kShapeFilledArea;
if (flags & kDotAsLines) {
shape.resize(5);
shape[0].fX = -1; shape[0].fY = -1;
shape[1].fX = 1; shape[1].fY = -1;
shape[2].fX = 1; shape[2].fY = 1;
shape[3].fX = -1; shape[3].fY = 1;
shape[4].fX = -1; shape[4].fY = -1;
return kShapeFilledArea;
} else if (flags & kDotAsCircle) {
sz = 6;
return kShapeFilledCircle;
} else {
sz = 3;
return kShapeDot;
}
case kFullDotLarge:
case kFullCircle:
sz = im * 2;
Expand Down Expand Up @@ -536,7 +560,7 @@ TAttMarker::EMarkerShape TAttMarker::GetMarkerShape(Int_t &sz, std::vector<TPoin
return markerStyle == kFullDiamond ? kShapeFilledArea : kShapePolyLine;
}
case kFullCross:
if (prefer_triangles) {
if (flags & kPreferTriangles) {
const auto imx = std::round(1.33*markerSizeReduced);
shape.reserve(3 * 6);
addSquare( -im, -imx, -imx, imx);
Expand All @@ -563,7 +587,7 @@ TAttMarker::EMarkerShape TAttMarker::GetMarkerShape(Int_t &sz, std::vector<TPoin
return markerStyle == kFullCross ? kShapeFilledArea : kShapePolyLine;
}
case kFullStar:
if (prefer_triangles) {
if (flags & kPreferTriangles) {
const auto im1 = std::round(0.66*markerSizeReduced);
const auto im3 = std::round(2.66*markerSizeReduced);
const auto im4 = std::round(1.33*markerSizeReduced);
Expand Down Expand Up @@ -598,27 +622,35 @@ TAttMarker::EMarkerShape TAttMarker::GetMarkerShape(Int_t &sz, std::vector<TPoin
return markerStyle == kFullStar ? kShapeFilledArea : kShapePolyLine;
}
case kOpenDiamondCross:
shape.resize(8);
shape.resize(12);
shape[0].fX =-im; shape[0].fY = 0;
shape[1].fX = 0; shape[1].fY = -im;
shape[2].fX = im; shape[2].fY = 0;
shape[3].fX = 0; shape[3].fY = im;
shape[4].fX =-im; shape[4].fY = 0;
shape[5].fX = im; shape[5].fY = 0;
shape[2].fX = 0; shape[2].fY = -im;
shape[3].fX = im; shape[3].fY = 0;
shape[4].fX = im; shape[4].fY = 0;
shape[5].fX = 0; shape[5].fY = im;
shape[6].fX = 0; shape[6].fY = im;
shape[7].fX = 0; shape[7].fY =-im;
return kShapePolyLine;
shape[7].fX =-im; shape[7].fY = 0;
shape[8].fX =-im; shape[8].fY = 0;
shape[9].fX = im; shape[9].fY = 0;
shape[10].fX = 0; shape[10].fY = im;
shape[11].fX = 0; shape[11].fY =-im;
return kShapeSegments;
case kOpenSquareDiagonal:
shape.resize(8);
shape.resize(12);
shape[0].fX = -im; shape[0].fY = -im;
shape[1].fX = im; shape[1].fY = -im;
shape[2].fX = im; shape[2].fY = im;
shape[3].fX = -im; shape[3].fY = im;
shape[4].fX = -im; shape[4].fY = -im;
shape[5].fX = im; shape[5].fY = im;
shape[2].fX = im; shape[2].fY = -im;
shape[3].fX = im; shape[3].fY = im;
shape[4].fX = im; shape[4].fY = im;
shape[5].fX = -im; shape[5].fY = im;
shape[6].fX = -im; shape[6].fY = im;
shape[7].fX = im; shape[7].fY = -im;
return kShapePolyLine;
shape[7].fX = -im; shape[7].fY = -im;
shape[8].fX = -im; shape[8].fY = -im;
shape[9].fX = im; shape[9].fY = im;
shape[10].fX = -im; shape[10].fY = im;
shape[11].fX = im; shape[11].fY = -im;
return kShapeSegments;
case kOpenThreeTriangles:
shape.resize(10);
shape[0].fX = 0; shape[0].fY = 0;
Expand Down Expand Up @@ -680,7 +712,7 @@ TAttMarker::EMarkerShape TAttMarker::GetMarkerShape(Int_t &sz, std::vector<TPoin
addTriangle(-im2, -im, -im, -im2);
return kShapeTriangles;
case kFullDoubleDiamond:
if (prefer_triangles) {
if (flags & kPreferTriangles) {
const auto im4 = std::round(markerSizeReduced);
shape.reserve(8 * 3);
addTriangle( 0, im, -im4, im4);
Expand Down Expand Up @@ -729,7 +761,7 @@ TAttMarker::EMarkerShape TAttMarker::GetMarkerShape(Int_t &sz, std::vector<TPoin
addTriangle( -im, -im2, -im, im2);
return kShapeTriangles;
case kFullCrossX:
if (prefer_triangles) {
if (flags & kPreferTriangles) {
shape.reserve(6 * 3);
addTriangle(-im2, 0, -im, im2, -im2, im);
addTriangle(-im2, 0, -im2, im, 0, im2);
Expand Down Expand Up @@ -777,5 +809,6 @@ TAttMarker::EMarkerShape TAttMarker::GetMarkerShape(Int_t &sz, std::vector<TPoin
}
}

sz = 1;
return kShapeDot;
}
5 changes: 4 additions & 1 deletion graf2d/postscript/inc/TPDF.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class TPDF : public TVirtualPS {

void EnsureBufferSize(Int_t required_size);

template<typename T>
void PrintPolyMarkerShape(Int_t n, T *x, T* y);

public:
TPDF();
TPDF(const char *filename, Int_t type=-111);
Expand Down Expand Up @@ -154,7 +157,7 @@ class TPDF : public TVirtualPS {
Double_t XtoPDF(Double_t x);
Double_t YtoPDF(Double_t y);

ClassDefOverride(TPDF, 1); // PDF driver
ClassDefOverride(TPDF, 0); // PDF driver
};

#endif
10 changes: 8 additions & 2 deletions graf2d/postscript/inc/TPostScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

#include "TVirtualPS.h"

#include <map>
#include <string>

class TPoints;

class TPostScript : public TVirtualPS {
Expand Down Expand Up @@ -78,10 +81,14 @@ class TPostScript : public TVirtualPS {
TString fFileName; ///< PS file name
Bool_t fFontEmbed = kFALSE; ///< True is FontEmbed has been called
Bool_t fMustEmbed[29]; ///< flag to embed font
std::map<std::string,bool> fMarkers; ///<! array of already defined markers

static Int_t fgLineJoin; ///< Appearance of joining lines
static Int_t fgLineCap; ///< Appearance of line caps

template<typename T>
void DrawPolyMarkerShape(Int_t n, T *x, T *y);

public:
TPostScript();
TPostScript(const char *filename, Int_t type=-111);
Expand All @@ -93,7 +100,6 @@ class TPostScript : public TVirtualPS {
void CellArrayEnd() override;
void Close(Option_t *opt="") override;
Int_t CMtoPS(Double_t u) {return Int_t(0.5 + 72*u/2.54);}
void DefineMarkers();
void DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override;
void DrawFrame(Double_t xl, Double_t yl, Double_t xt, Double_t yt, Int_t mode, Int_t border, Int_t dark,
Int_t light) override;
Expand Down Expand Up @@ -143,7 +149,7 @@ class TPostScript : public TVirtualPS {
Int_t YtoPS(Double_t y);
void Zone();

ClassDefOverride(TPostScript,1) //PostScript driver
ClassDefOverride(TPostScript,0) //PostScript driver
};

#endif
4 changes: 2 additions & 2 deletions graf2d/postscript/inc/TSVG.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class TSVG : public TVirtualPS {
void PrintPath(Bool_t convert, Int_t n, Double_t *xs, Double_t *ys, Bool_t close_path = kTRUE);
void PrintLineStyleOnEndOfPath();
void PrintLineJointAttributes();
template<class T>
void PrintPolyMarker(Int_t n, T *x, T* y);
template<typename T>
void PrintPolyMarkerShape(Int_t n, T *x, T* y);

public:
TSVG();
Expand Down
12 changes: 9 additions & 3 deletions graf2d/postscript/inc/TTeXDump.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// @(#)root/postscript:$Id$
// Author: Olivier Couet
// Author: Olivier Couet, Sergey Linev

/*************************************************************************
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
* Copyright (C) 1995-2026, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
Expand All @@ -17,6 +17,8 @@

class TPoints;

#include <map>

class TTeXDump : public TVirtualPS {

protected:
Expand All @@ -32,6 +34,11 @@ class TTeXDump : public TVirtualPS {
Float_t fCurrentAlpha = 1.; ///< Current Alpha value
Float_t fLineScale = 0.; ///< Line width scale factor

std::map<Style_t,bool> fMarkers; ///< map of already defined markers

template<typename T>
void DrawPolyMarkerShape(Int_t n, T *xw, T *yw);

public:
TTeXDump();
TTeXDump(const char *filename, Int_t type=-113);
Expand All @@ -42,7 +49,6 @@ class TTeXDump : public TVirtualPS {
void CellArrayEnd() override;
void Close(Option_t *opt="") override;
Int_t CMtoTeX(Double_t u) { return Int_t(0.5 + 72*u/2.54); }
void DefineMarkers();
void DrawBox(Double_t x1, Double_t y1,Double_t x2, Double_t y2) override;
void DrawFrame(Double_t xl, Double_t yl, Double_t xt, Double_t yt,
Int_t mode, Int_t border, Int_t dark, Int_t light) override;
Expand Down
2 changes: 1 addition & 1 deletion graf2d/postscript/src/TImageDump.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void TImageDump::DrawPolyMarker(Int_t n, Double_t *xw, Double_t *yw)
Int_t markerSize = 0; ///< size of simple markers
std::vector<TPoint> markerShape; ///< marker shape points
// prefer to use triangles while image not always correctly fill complex polygon
auto markerType = GetMarkerShape(markerSize, markerShape, gStyle->GetImageScaling(), kTRUE);
auto markerType = GetMarkerShape(markerSize, markerShape, gStyle->GetImageScaling(), TAttMarker::kPreferTriangles | TAttMarker::kDotAsLines);

// workaround of ASImage error - it is not able to draw circle with transparent color
if ((markerType == TAttMarker::kShapeFilledCircle) && (col->GetAlpha() < 1.)) {
Expand Down
Loading
Loading