Belle II Software  release-08-01-10
SVGPrimitivePlotter Class Reference

A concrete plotter that can draw primitive objects to standalone SVG files. More...

#include <SVGPrimitivePlotter.h>

Inheritance diagram for SVGPrimitivePlotter:
Collaboration diagram for SVGPrimitivePlotter:

Public Types

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

Public Member Functions

 SVGPrimitivePlotter ()
 Default constructor for ROOT compatibility.
 
 SVGPrimitivePlotter (const AttributeMap &svgAttributes)
 Constructor taking additional attributes that go into the toplevel svg tag. More...
 
 SVGPrimitivePlotter (const SVGPrimitivePlotter &plotter)
 Copy constructor.
 
std::unique_ptr< PrimitivePlotterclone () const override
 Returns a newly created plotter instance containing all information of this. More...
 
void drawLine (float startX, float startY, float endX, float endY, const AttributeMap &attributeMap=AttributeMap()) override
 Adds a line to the plot. More...
 
void drawArrow (float startX, float startY, float endX, float endY, const AttributeMap &attributeMap=AttributeMap()) override
 Adds an arrow to the plot. More...
 
void drawCircle (float centerX, float centerY, float radius, const AttributeMap &attributeMap=AttributeMap()) override
 Adds a circle to the plot. More...
 
void drawCircleArc (float startX, float startY, float endX, float endY, float radius, bool longArc, bool sweepFlag, const AttributeMap &attributeMap=AttributeMap()) override
 Adds a circle arc to the plot. More...
 
void drawCurve (const std::vector< std::array< float, 2 >> &points, const std::vector< std::array< float, 2 >> &tangents, const AttributeMap &attributeMap=AttributeMap()) override
 Adds a smooth curve to the plot. More...
 
void startGroup (const AttributeMap &attributeMap=AttributeMap()) override
 Indicates the start of a group of drawn elements. More...
 
void endGroup () override
 Indicates the end of a group of drawn elements. More...
 
const std::string save (const std::string &fileName) override
 Saves the current plot state to a file. More...
 
void clear () override
 Clears all drawed 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 drawed objects.
 
void setBoundingBox (const BoundingBox &boundingBox)
 Setter for the bounding box of all drawed 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. More...
 
void setCanvasHeight (float height)
 Setter for the canvas height in pixels The canvas height denotes the size of the image being produced. More...
 

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 Member Functions

void indent ()
 Increases the current indention by one.
 
void dedent ()
 Decreases the current indention by one.
 
void writeSVGHeader (std::ostream &outputStream)
 Writes the xml header that indicates that this document will be a SVG document to the given output stream. More...
 
void writeSVGDefs (std::ostream &outputStream)
 Writes a preamble of definitions that define an arrow cap which can be referenced by lines.
 
void writeOpeningTag (std::ostream &outputStream, const std::string &tagName, const AttributeMap &geometryAttributeMap=AttributeMap(), const AttributeMap &styleAttributeMap=AttributeMap())
 Writes an opening xml tag to the given output stream taking attributes from two sources. More...
 
void writeStandAloneTag (std::ostream &outputStream, const std::string &tagName, const AttributeMap &geometryAttributeMap=AttributeMap(), const AttributeMap &styleAttributeMap=AttributeMap())
 Writes a stand alone xml tag to the given output stream taking attributes from two sources. More...
 
void writeTagIntern (std::ostream &outputStream, const std::string &tagName, const AttributeMap &geometryAttributeMap=AttributeMap(), const AttributeMap &styleAttributeMap=AttributeMap())
 Writes part that belongs between the <, > brakets. More...
 
void writeAttributes (std::ostream &outputStream, const AttributeMap &attributeMap)
 Writes attribute specification that belongs between the <, > brakets after the tag name. More...
 
void writeClosingTag (std::ostream &outputStream, const std::string &tagName)
 Writes a closing xml tag to the given output stream. More...
 

Private Attributes

std::ostringstream m_svgContentStream
 Memory for the plotted elements. This contains only the fragment that is inbetween the svg tags and comes after the global svg definitions.
 
int m_nIndentationSpaces
 Memory for the number of spaces that shall be prepended to each line.
 
AttributeMap m_svgAttributes
 Memory for additional attributes to the toplevel svg element.
 
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.
 

Static Private Attributes

static const int s_defaultNIndentationSpaces = 2
 Constant for the number of indention space to be used within the svg block.
 
static const int s_addtionalNIndentationSpaces = 2
 Constant for the additional number of space to be prepended with each open tag group.
 

Detailed Description

A concrete plotter that can draw primitive objects to standalone SVG files.

Definition at line 21 of file SVGPrimitivePlotter.h.

Constructor & Destructor Documentation

◆ SVGPrimitivePlotter()

SVGPrimitivePlotter ( const AttributeMap svgAttributes)
explicit

Constructor taking additional attributes that go into the toplevel svg tag.

Parameters
svgAttributesA map of attributes that goes into the toplevel svg tag.

Definition at line 28 of file SVGPrimitivePlotter.cc.

32  , m_svgAttributes(svgAttributes)
33 {
34 }
PrimitivePlotter()
Default constructor for ROOT compatibility.
std::ostringstream m_svgContentStream
Memory for the plotted elements. This contains only the fragment that is inbetween the svg tags and c...
int m_nIndentationSpaces
Memory for the number of spaces that shall be prepended to each line.
static const int s_defaultNIndentationSpaces
Constant for the number of indention space to be used within the svg block.
AttributeMap m_svgAttributes
Memory for additional attributes to the toplevel svg element.

Member Function Documentation

◆ clone()

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

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 from PrimitivePlotter.

Definition at line 44 of file SVGPrimitivePlotter.cc.

◆ drawArrow()

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

Adds an arrow to the plot.

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 sting keys and values that describe the drawing properties of the line.

Reimplemented from PrimitivePlotter.

Definition at line 69 of file SVGPrimitivePlotter.cc.

◆ drawCircle()

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

Adds a circle to the plot.

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

Reimplemented from PrimitivePlotter.

Definition at line 89 of file SVGPrimitivePlotter.cc.

◆ drawCircleArc()

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

Adds a circle arc to the plot.

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 sting keys and values that describe the drawing properties of the line.

Reimplemented from PrimitivePlotter.

Definition at line 107 of file SVGPrimitivePlotter.cc.

◆ drawCurve()

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

Adds a smooth curve to the plot.

Current implementation approxiamtes circle arcs between the points with cubic splines.

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

Reimplemented from PrimitivePlotter.

Definition at line 152 of file SVGPrimitivePlotter.cc.

◆ drawLine()

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

Adds a line to the plot.

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 sting keys and values that describe the drawing properties of the line.

Reimplemented from PrimitivePlotter.

Definition at line 49 of file SVGPrimitivePlotter.cc.

◆ endGroup()

void endGroup ( )
overridevirtual

Indicates the end of a group of drawn elements.

Meaning depends on the actual implementation.

Reimplemented from PrimitivePlotter.

Definition at line 231 of file SVGPrimitivePlotter.cc.

◆ save()

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

Saves the current plot state to a file.

Deriving instances may should implement the approriate 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 concret implementation decides to do so.

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

Reimplemented from PrimitivePlotter.

Definition at line 236 of file SVGPrimitivePlotter.cc.

◆ setCanvasHeight()

void setCanvasHeight ( float  height)
inlineinherited

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 seperate concept which is stored in the bounding box (getBoundingBox()).

Definition at line 230 of file PrimitivePlotter.h.

◆ setCanvasWidth()

void setCanvasWidth ( float  width)
inlineinherited

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 seperate concept which is stored in the bounding box (getBoundingBox()).

Definition at line 219 of file PrimitivePlotter.h.

◆ startGroup()

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

Indicates the start of a group of drawn elements.

Meaning depends on the actual implementation.

Reimplemented from PrimitivePlotter.

Definition at line 226 of file SVGPrimitivePlotter.cc.

◆ writeAttributes()

void writeAttributes ( std::ostream &  outputStream,
const AttributeMap attributeMap 
)
private

Writes attribute specification that belongs between the <, > brakets after the tag name.

Parameters
[out]outputStreamThe output stream to which the result is written.
[in]attributeMapA map of attribute keys to attribute values that shall be attached to the tag.

Definition at line 435 of file SVGPrimitivePlotter.cc.

◆ writeClosingTag()

void writeClosingTag ( std::ostream &  outputStream,
const std::string &  tagName 
)
private

Writes a closing xml tag to the given output stream.

Parameters
[out]outputStreamThe output stream to which the result is written.
[in]tagNameName of the xml tag to be written

Definition at line 463 of file SVGPrimitivePlotter.cc.

◆ writeOpeningTag()

void writeOpeningTag ( std::ostream &  outputStream,
const std::string &  tagName,
const AttributeMap geometryAttributeMap = AttributeMap(),
const AttributeMap styleAttributeMap = AttributeMap() 
)
private

Writes an opening xml tag to the given output stream taking attributes from two sources.

Parameters
[out]outputStreamThe output stream to which the result is written.
[in]tagNameName of the xml tag to be written
[in]geometryAttributeMapA first map of attribute keys to attribute values that shall be attached to the tag. Usually this gives geometrical information but gets essentially treated the same way as the second attribute map
[in]styleAttributeMapA second map of attribute keys to attribute values that shall be attached to the tag. Usually this gives styling information but gets essentially treated the same way as the first attribute map

Definition at line 348 of file SVGPrimitivePlotter.cc.

◆ writeStandAloneTag()

void writeStandAloneTag ( std::ostream &  outputStream,
const std::string &  tagName,
const AttributeMap geometryAttributeMap = AttributeMap(),
const AttributeMap styleAttributeMap = AttributeMap() 
)
private

Writes a stand alone xml tag to the given output stream taking attributes from two sources.

Parameters
[out]outputStreamThe output stream to which the result is written.
[in]tagNameName of the xml tag to be written
[in]geometryAttributeMapA first map of attribute keys to attribute values that shall be attached to the tag. Usually this gives geometrical information but gets essentially treated the same way as the second attribute map
[in]styleAttributeMapA second map of attribute keys to attribute values that shall be attached to the tag. Usually this gives styling information but gets essentially treated the same way as the first attribute map

Definition at line 386 of file SVGPrimitivePlotter.cc.

◆ writeSVGHeader()

void writeSVGHeader ( std::ostream &  outputStream)
private

Writes the xml header that indicates that this document will be a SVG document to the given output stream.

Parameters
[out]outputStreamThe output stream to which the result is written.

Definition at line 313 of file SVGPrimitivePlotter.cc.

◆ writeTagIntern()

void writeTagIntern ( std::ostream &  outputStream,
const std::string &  tagName,
const AttributeMap geometryAttributeMap = AttributeMap(),
const AttributeMap styleAttributeMap = AttributeMap() 
)
private

Writes part that belongs between the <, > brakets.

Used by writeOpeningTag and writeClosing.

Used by writeOpeningTag and writeClosing. Factored to avoid code dublication.

Parameters
[out]outputStreamThe output stream to which the result is written.
[in]tagNameName of the xml tag to be written
[in]geometryAttributeMapA first map of attribute keys to attribute values that shall be attached to the tag. Usually this gives geometrical information but gets essentially treated the same way as the second attribute map
[in]styleAttributeMapA second map of attribute keys to attribute values that shall be attached to the tag. Usually this gives styling information but gets essentially treated the same way as the first attribute map

Definition at line 414 of file SVGPrimitivePlotter.cc.


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