Belle II Software development
PrimitivePlotter Class Reference

A base class for plots of primitive objects. More...

#include <PrimitivePlotter.h>

Inheritance diagram for PrimitivePlotter:
SVGPrimitivePlotter

Public Types

using AttributeMap = Belle2::TrackFindingCDC::AttributeMap
 A map type for attributes names to values for additional drawing information.
 

Public Member Functions

 PrimitivePlotter ()
 Default constructor for ROOT compatibility.
 
virtual ~PrimitivePlotter ()
 Make destructor virtual to handle polymorphic deconstruction.
 
virtual std::unique_ptr< PrimitivePlotterclone () const
 Returns a newly created plotter instance containing all information of this.
 
virtual void drawLine (float startX, float startY, float endX, float endY, const AttributeMap &attributeMap=AttributeMap())
 Adds a line to the plot.
 
virtual void drawArrow (float startX, float startY, float endX, float endY, const AttributeMap &attributeMap=AttributeMap())
 Adds an arrow to the plot.
 
virtual void drawCircle (float centerX, float centerY, float radius, const AttributeMap &attributeMap=AttributeMap())
 Adds a circle to the plot.
 
virtual void drawCircleArc (float startX, float startY, float endX, float endY, float radius, bool longArc, bool sweepFlag, const AttributeMap &attributeMap=AttributeMap())
 Adds a circle arc to the plot.
 
virtual void drawCurve (const std::vector< std::array< float, 2 > > &points, const std::vector< std::array< float, 2 > > &tangents, const AttributeMap &attributeMap=AttributeMap())
 Adds a smooth curve to the plot.
 
virtual void startGroup (const AttributeMap &attributeMap=AttributeMap())
 Indicates the start of a group of drawn elements.
 
virtual void endGroup ()
 Indicates the end of a group of drawn elements.
 
virtual const std::string save (const std::string &fileName)
 Saves the current plot state to a file.
 
virtual void clear ()
 Clears all drawn elements from the plotter.
 
void clearBoundingBox ()
 Clears the current bounding box. Only following draw calls contribute to the bounding box.
 
const BoundingBoxgetBoundingBox () const
 Getter for the bounding box of all drawn objects.
 
void setBoundingBox (const BoundingBox &boundingBox)
 Setter for the bounding box of all drawn objects.
 
float getCanvasWidth ()
 Getter for the canvas width in pixels.
 
float getCanvasHeight ()
 Getter for the canvas height in pixels.
 
void setCanvasWidth (float width)
 Setter for the canvas width in pixels.
 
void setCanvasHeight (float height)
 Setter for the canvas height in pixels The canvas height denotes the size of the image being produced.
 

Static Public Attributes

static const float s_defaultCanvasWidth = 1120.0
 The default width of the canvas to be plotted into.
 
static const float s_defaultCanvasHeight = 1120.0
 The default height of the canvas to be plotted into.
 

Private Attributes

BoundingBox m_boundingBox
 Bounding box of the currently drawn objects.
 
float m_canvasWidth
 Memory for the width of the SVG drawing in pixels.
 
float m_canvasHeight
 Memory for the height of the SVG drawing in pixels.
 

Detailed Description

A base class for plots of primitive objects.

Definition at line 25 of file PrimitivePlotter.h.

Member Typedef Documentation

◆ AttributeMap

using AttributeMap = Belle2::TrackFindingCDC::AttributeMap

A map type for attributes names to values for additional drawing information.

Definition at line 29 of file PrimitivePlotter.h.

Constructor & Destructor Documentation

◆ PrimitivePlotter()

Default constructor for ROOT compatibility.

Definition at line 16 of file PrimitivePlotter.cc.

16 :
20{
21}
BoundingBox m_boundingBox
Bounding box of the currently drawn objects.
float m_canvasHeight
Memory for the height of the SVG drawing in pixels.
static const float s_defaultCanvasHeight
The default height of the canvas to be plotted into.
static const float s_defaultCanvasWidth
The default width of the canvas to be plotted into.
float m_canvasWidth
Memory for the width of the SVG drawing in pixels.

Member Function Documentation

◆ clear()

void clear ( )
virtual

Clears all drawn elements from the plotter.

Base implementation only updates the bounding box.

Reimplemented in SVGPrimitivePlotter.

Definition at line 111 of file PrimitivePlotter.cc.

112{
113}

◆ clearBoundingBox()

void clearBoundingBox ( )

Clears the current bounding box. Only following draw calls contribute to the bounding box.

Definition at line 115 of file PrimitivePlotter.cc.

116{
118}
void clear()
Clears all bounds to NAN.
Definition: BoundingBox.h:87

◆ clone()

std::unique_ptr< PrimitivePlotter > clone ( ) const
virtual

Returns a newly created plotter instance containing all information of this.

The new object is created on the heap. The ownership is to the caller who has the responsibility to destroy it.

Reimplemented in SVGPrimitivePlotter.

Definition at line 25 of file PrimitivePlotter.cc.

26{
27 return std::make_unique<PrimitivePlotter>(*this);
28}

◆ drawArrow()

void drawArrow ( float  startX,
float  startY,
float  endX,
float  endY,
const AttributeMap attributeMap = AttributeMap() 
)
virtual

Adds an arrow to the plot.

Base implementation only updates the bounding box.

Parameters
startXx coordinate where the arrow starts.
startYy coordinate where the arrow starts.
endXx coordinate where the arrow ends.
endYy coordinate where the arrow ends.
attributeMapA map of string keys and values that describe the drawing properties of the line.

Reimplemented in SVGPrimitivePlotter.

Definition at line 42 of file PrimitivePlotter.cc.

47{
48 m_boundingBox &= BoundingBox(startX, startY, endX, endY);
49}
A two dimensional rectangle that keeps track of the extend of a drawing.
Definition: BoundingBox.h:21

◆ drawCircle()

void drawCircle ( float  centerX,
float  centerY,
float  radius,
const AttributeMap attributeMap = AttributeMap() 
)
virtual

Adds a circle to the plot.

Base implementation only updates the bounding box.

Parameters
centerXx coordinate of the circle center.
centerYy coordinate of the circle center.
radiusradius of the circle
attributeMapA map of string keys and values that describe the drawing properties of the line.

Reimplemented in SVGPrimitivePlotter.

Definition at line 52 of file PrimitivePlotter.cc.

56{
57 const float left = centerX - radius;
58 const float bottom = centerY - radius;
59 const float right = centerX + radius;
60 const float top = centerY + radius;
61
62 m_boundingBox &= BoundingBox(left, bottom, right, top);
63}

◆ drawCircleArc()

void drawCircleArc ( float  startX,
float  startY,
float  endX,
float  endY,
float  radius,
bool  longArc,
bool  sweepFlag,
const AttributeMap attributeMap = AttributeMap() 
)
virtual

Adds a circle arc to the plot.

Base implementation only updates the bounding box.

Parameters
startXx coordinate where the line starts.
startYy coordinate where the line starts.
endXx coordinate where the line end.
endYy coordinate where the line end.
radiusRadius of the circle
longArcBoolean indicator if the long arc or the short arc is traversed from one point to the other.
sweepFlagBoolean indicator related to the curvature perceived one the circle arc. False means negative curvature. True mean positive curvature.
attributeMapA map of string keys and values that describe the drawing properties of the line.

Reimplemented in SVGPrimitivePlotter.

Definition at line 66 of file PrimitivePlotter.cc.

74{
75 // The actual extend of the circle arc is more complicating.
76 // Please fill in the solution if you have one.
77 m_boundingBox &= BoundingBox(startX, startY, endX, endY);
78}

◆ drawCurve()

void drawCurve ( const std::vector< std::array< float, 2 > > &  points,
const std::vector< std::array< float, 2 > > &  tangents,
const AttributeMap attributeMap = AttributeMap() 
)
virtual

Adds a smooth curve to the plot.

Base implementation only updates the bounding box.

Parameters
pointsX,Y points on the curve
tangentsTangent vector at each point. Length of tangents does not matter.
attributeMapA map of string keys and values that describe the drawing properties of the line.

Reimplemented in SVGPrimitivePlotter.

Definition at line 80 of file PrimitivePlotter.cc.

83{
84 for (size_t i = 0; i < points.size() - 1; ++i) {
85 float startX = points[i][0];
86 float startY = points[i][1];
87 float endX = points[i + 1][0];
88 float endY = points[i + 1][1];
89 m_boundingBox &= BoundingBox(startX, startY, endX, endY);
90 }
91}

◆ drawLine()

void drawLine ( float  startX,
float  startY,
float  endX,
float  endY,
const AttributeMap attributeMap = AttributeMap() 
)
virtual

Adds a line to the plot.

Base implementation only updates the bounding box.

Parameters
startXx coordinate where the line starts.
startYy coordinate where the line starts.
endXx coordinate where the line ends.
endYy coordinate where the line ends.
attributeMapA map of string keys and values that describe the drawing properties of the line.

Reimplemented in SVGPrimitivePlotter.

Definition at line 32 of file PrimitivePlotter.cc.

37{
38 m_boundingBox &= BoundingBox(startX, startY, endX, endY);
39}

◆ endGroup()

void endGroup ( )
virtual

Indicates the end of a group of drawn elements.

Meaning depends on the actual implementation.

Does nothing in the base implementation

Reimplemented in SVGPrimitivePlotter.

Definition at line 100 of file PrimitivePlotter.cc.

101{
102}

◆ getBoundingBox()

const BoundingBox & getBoundingBox ( ) const
inline

Getter for the bounding box of all drawn objects.

Definition at line 189 of file PrimitivePlotter.h.

190 {
191 return m_boundingBox;
192 }

◆ getCanvasHeight()

float getCanvasHeight ( )
inline

Getter for the canvas height in pixels.

Definition at line 208 of file PrimitivePlotter.h.

209 {
210 return m_canvasHeight;
211 }

◆ getCanvasWidth()

float getCanvasWidth ( )
inline

Getter for the canvas width in pixels.

Definition at line 202 of file PrimitivePlotter.h.

203 {
204 return m_canvasWidth;
205 }

◆ save()

const std::string save ( const std::string &  fileName)
virtual

Saves the current plot state to a file.

Deriving instances may should implement the appropriate thing here and may return a modified string indicating the file name to which the plot as been written. It is allowed to append or change the file extension if the concrete implementation decides to do so.

Parameters
fileNameFile name where the plot shall be saved
Returns
Potentially modified file name where the file has actually been written to.

Reimplemented in SVGPrimitivePlotter.

Definition at line 105 of file PrimitivePlotter.cc.

106{
107 return "";
108}

◆ setBoundingBox()

void setBoundingBox ( const BoundingBox boundingBox)
inline

Setter for the bounding box of all drawn objects.

Definition at line 195 of file PrimitivePlotter.h.

196 {
197 m_boundingBox = boundingBox;
198 }

◆ setCanvasHeight()

void setCanvasHeight ( float  height)
inline

Setter for the canvas height in pixels The canvas height denotes the size of the image being produced.

The coordinates space that is visible in the picture is a separate concept which is stored in the bounding box (getBoundingBox()).

Definition at line 230 of file PrimitivePlotter.h.

231 {
232 m_canvasHeight = height;
233 }

◆ setCanvasWidth()

void setCanvasWidth ( float  width)
inline

Setter for the canvas width in pixels.

The canvas height denotes the size of the image being produced. The coordinates space that is visible in the picture is a separate concept which is stored in the bounding box (getBoundingBox()).

Definition at line 219 of file PrimitivePlotter.h.

220 {
221 m_canvasWidth = width;
222 }

◆ startGroup()

void startGroup ( const AttributeMap attributeMap = AttributeMap())
virtual

Indicates the start of a group of drawn elements.

Meaning depends on the actual implementation.

Does nothing in the base implementation

Reimplemented in SVGPrimitivePlotter.

Definition at line 95 of file PrimitivePlotter.cc.

96{
97}

Member Data Documentation

◆ m_boundingBox

BoundingBox m_boundingBox
private

Bounding box of the currently drawn objects.

Definition at line 237 of file PrimitivePlotter.h.

◆ m_canvasHeight

float m_canvasHeight
private

Memory for the height of the SVG drawing in pixels.

Definition at line 243 of file PrimitivePlotter.h.

◆ m_canvasWidth

float m_canvasWidth
private

Memory for the width of the SVG drawing in pixels.

Definition at line 240 of file PrimitivePlotter.h.

◆ s_defaultCanvasHeight

const float s_defaultCanvasHeight = 1120.0
static

The default height of the canvas to be plotted into.

Definition at line 36 of file PrimitivePlotter.h.

◆ s_defaultCanvasWidth

const float s_defaultCanvasWidth = 1120.0
static

The default width of the canvas to be plotted into.

Definition at line 33 of file PrimitivePlotter.h.


The documentation for this class was generated from the following files: