DGtal  1.5.beta
LibBoard::Polyline Struct Reference

A polygonal line described by a series of 2D points. More...

#include <Board/Shapes.h>

Inheritance diagram for LibBoard::Polyline:
[legend]

Public Member Functions

 Polyline (const std::vector< Point > &points, bool closed, DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, const LineStyle lineStyle=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
 
 Polyline (const Path &path, DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, const LineStyle lineStyle=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
 
 Polyline (bool closed, DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, const LineStyle lineStyle=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
 
const std::string & name () const
 
Point center () const
 
Polylineoperator<< (const Point &p)
 
Pointoperator[] (const unsigned int n)
 
Polylinerotate (double angle, const Point &center)
 
Polyline rotated (double angle, const Point &center) const
 
Polylinerotate (double angle)
 
Polyline rotated (double angle) const
 
Polylinetranslate (double dx, double dy)
 
Polyline translated (double dx, double dy) const
 
Shapescale (double sx, double sy)
 
Shapescale (double s)
 
Polyline scaled (double sx, double sy) const
 
Polyline scaled (double s) const
 
void scaleAll (double s)
 
void flushPostscript (std::ostream &stream, const TransformEPS &transform) const
 
void flushFIG (std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
 
void flushSVG (std::ostream &stream, const TransformSVG &transform) const
 
void flushCairo (cairo_t *cr, const TransformCairo &transform) const
 
void flushTikZ (std::ostream &stream, const TransformTikZ &transform) const
 
Rect boundingBox () const
 
Polylineclone () const
 
- Public Member Functions inherited from LibBoard::Shape
 Shape (DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, LineStyle style, const LineCap cap, const LineJoin join, int depth)
 
virtual ~Shape ()
 
bool filled () const
 
ShaperotateDeg (double angle, const Point &center)
 
ShaperotateDeg (double angle)
 
Rect bbox ()
 
Shapeoperator-- ()
 
Shapeoperator++ ()
 
int depth () const
 
virtual void depth (int)
 
virtual void shiftDepth (int shift)
 
const DGtal::ColorpenColor () const
 
const DGtal::ColorfillColor () const
 

Protected Attributes

Path _path
 
- Protected Attributes inherited from LibBoard::Shape
int _depth
 
DGtal::Color _penColor
 
DGtal::Color _fillColor
 
double _lineWidth
 
LineStyle _lineStyle
 
LineCap _lineCap
 
LineJoin _lineJoin
 

Static Private Attributes

static const std::string _name
 

Additional Inherited Members

- Public Types inherited from LibBoard::Shape
enum  LineCap { ButtCap = 0 , RoundCap , SquareCap }
 
enum  LineJoin { MiterJoin = 0 , RoundJoin , BevelJoin }
 
enum  LineStyle {
  SolidStyle = 0 , DashStyle , DotStyle , DashDotStyle ,
  DashDotDotStyle , DashDotDotDotStyle
}
 
- Protected Member Functions inherited from LibBoard::Shape
std::string svgProperties (const TransformSVG &transform) const
 
std::string postscriptProperties () const
 
void setCairoDashStyle (cairo_t *cr, LineStyle type) const
 
std::string tikzProperties (const TransformTikZ &transform) const
 

Detailed Description

A polygonal line described by a series of 2D points.

The polyline structure.

Definition at line 765 of file Board/Shapes.h.

Constructor & Destructor Documentation

◆ Polyline() [1/3]

LibBoard::Polyline::Polyline ( const std::vector< Point > &  points,
bool  closed,
DGtal::Color  penColor,
DGtal::Color  fillColor,
double  lineWidth,
const LineStyle  lineStyle = SolidStyle,
const LineCap  cap = ButtCap,
const LineJoin  join = MiterJoin,
int  depth = -1 
)
inline

◆ Polyline() [2/3]

LibBoard::Polyline::Polyline ( const Path path,
DGtal::Color  penColor,
DGtal::Color  fillColor,
double  lineWidth,
const LineStyle  lineStyle = SolidStyle,
const LineCap  cap = ButtCap,
const LineJoin  join = MiterJoin,
int  depth = -1 
)
inline

◆ Polyline() [3/3]

LibBoard::Polyline::Polyline ( bool  closed,
DGtal::Color  penColor,
DGtal::Color  fillColor,
double  lineWidth,
const LineStyle  lineStyle = SolidStyle,
const LineCap  cap = ButtCap,
const LineJoin  join = MiterJoin,
int  depth = -1 
)
inline

Member Function Documentation

◆ boundingBox()

Rect LibBoard::Polyline::boundingBox ( ) const
virtual

Returns the bounding box of the figure.

Returns
The rectangle of the bounding box.

Implements LibBoard::Shape.

Definition at line 1867 of file Shapes.cpp.

1868 {
1869  return _path.boundingBox();
1870 }
Rect boundingBox() const
Definition: Path.cpp:272

References _path, and LibBoard::Path::boundingBox().

◆ center()

Point LibBoard::Polyline::center ( ) const
virtual

Returns the gravity center of the shape.

Returns
The center of the shape.

Implements LibBoard::Shape.

Reimplemented in LibBoard::GouraudTriangle.

Definition at line 1655 of file Shapes.cpp.

1655  {
1656  return _path.center();
1657 }
Point center() const
Definition: Path.cpp:36

References _path, and LibBoard::Path::center().

Referenced by rotate(), rotated(), and LibBoard::Rectangle::rotated().

◆ clone()

Polyline * LibBoard::Polyline::clone ( ) const
virtual

Return a copy of the shape.

Returns
copye of the shape.

Implements LibBoard::Shape.

Reimplemented in LibBoard::GouraudTriangle, LibBoard::Triangle, LibBoard::Image, and LibBoard::Rectangle.

Definition at line 1731 of file Shapes.cpp.

1731  {
1732  return new Polyline(*this);
1733 }
Polyline(const std::vector< Point > &points, bool closed, DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, const LineStyle lineStyle=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)

References Polyline().

◆ flushCairo()

void LibBoard::Polyline::flushCairo ( cairo_t *  cr,
const TransformCairo transform 
) const
virtual

Writes the cairo code of the shape in a cairo drawing context according to a transform.

Parameters
crThe cairo drawing context.
transformA 2D transform to be applied.

Implements LibBoard::Shape.

Reimplemented in LibBoard::GouraudTriangle, LibBoard::QuadraticBezierCurve, LibBoard::Image, and LibBoard::Rectangle.

Definition at line 1809 of file Shapes.cpp.

1811 {
1812  if ( _path.empty() )
1813  return;
1814 
1815  cairo_save (cr);
1816 
1817  cairo_set_source_rgba (cr, _fillColor.red()/255.0, _fillColor.green()/255.0, _fillColor.blue()/255.0, 1.);
1818 
1819  _path.flushCairoPoints( cr, transform );
1820  if ( _path.closed() )
1821  cairo_close_path (cr);
1822 
1823  if ( filled() )
1824  {
1825  if ( _penColor != DGtal::Color::None )
1826  cairo_fill_preserve (cr);
1827  else
1828  cairo_fill (cr);
1829  }
1830 
1831  //
1832 
1833  if ( _penColor != DGtal::Color::None )
1834  {
1835  cairo_set_source_rgba (cr, _penColor.red()/255.0, _penColor.green()/255.0, _penColor.blue()/255.0, 1.);
1836 
1837  cairo_set_line_width (cr, _lineWidth);
1838  cairo_set_line_cap (cr, cairoLineCap[_lineCap]);
1839  cairo_set_line_join (cr, cairoLineJoin[_lineJoin]);
1841 
1842  cairo_stroke (cr);
1843  }
1844 
1845  cairo_restore (cr);
1846 }
static const Color None
Definition: Color.h:412
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
void blue(const unsigned char aBlueValue)
void flushCairoPoints(cairo_t *cr, const TransformCairo &transform) const
Definition: Path.cpp:235
bool closed() const
Definition: Path.h:237
bool empty() const
Definition: Path.h:243
DGtal::Color _fillColor
Definition: Board/Shapes.h:297
DGtal::Color _penColor
Definition: Board/Shapes.h:296
LineJoin _lineJoin
Definition: Board/Shapes.h:301
void setCairoDashStyle(cairo_t *cr, LineStyle type) const
Definition: Shapes.cpp:153
LineStyle _lineStyle
Definition: Board/Shapes.h:299
bool filled() const
Definition: Board/Shapes.h:111

References LibBoard::Shape::_fillColor, LibBoard::Shape::_lineCap, LibBoard::Shape::_lineJoin, LibBoard::Shape::_lineStyle, LibBoard::Shape::_lineWidth, _path, LibBoard::Shape::_penColor, DGtal::Color::blue(), LibBoard::Path::closed(), LibBoard::Path::empty(), LibBoard::Shape::filled(), LibBoard::Path::flushCairoPoints(), DGtal::Color::green(), DGtal::Color::None, DGtal::Color::red(), and LibBoard::Shape::setCairoDashStyle().

Referenced by LibBoard::Rectangle::flushCairo().

◆ flushFIG()

void LibBoard::Polyline::flushFIG ( std::ostream &  stream,
const TransformFIG transform,
std::map< DGtal::Color, int > &  colormap 
) const
virtual

Writes the FIG code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.
colormapA colormap.

Implements LibBoard::Shape.

Reimplemented in LibBoard::GouraudTriangle, LibBoard::QuadraticBezierCurve, LibBoard::Image, and LibBoard::Rectangle.

Definition at line 1760 of file Shapes.cpp.

1763 {
1764  if ( _path.empty() )
1765  return;
1766  if ( _path.closed() )
1767  stream << "2 3 " << _lineStyle << " ";
1768  else
1769  stream << "2 1 " << _lineStyle << " ";
1770  // Thickness
1771  stream << ( _penColor.valid()?transform.mapWidth( _lineWidth ):0 ) << " ";
1772  // Pen color
1773  stream << colormap[ _penColor ] << " ";
1774  // Fill color
1775  stream << colormap[ _fillColor ] << " ";
1776  // Depth
1777  stream << transform.mapDepth( _depth ) << " ";
1778  // Pen style
1779  stream << "-1 ";
1780  // Area fill, style val, join style, cap style, radius, f_arrow, b_arrow
1781  if ( filled() )
1782  stream << "20 " << (_lineStyle?"4.000 ":"0.000 ") << _lineJoin << " " << _lineCap << " -1 0 0 ";
1783  else
1784  stream << "-1 " << (_lineStyle?"4.000 ":"0.000 ") << _lineJoin << " " << _lineCap << " -1 0 0 ";
1785  // Number of points
1786  stream << _path.size() + _path.closed() << std::endl;
1787  _path.flushFIG( stream << " ", transform );
1788  stream << std::endl;
1789 }
bool valid() const
unsigned int size() const
Definition: Path.h:249
void flushFIG(std::ostream &stream, const TransformFIG &transform) const
Definition: Path.cpp:173

References LibBoard::Shape::_depth, LibBoard::Shape::_fillColor, LibBoard::Shape::_lineCap, LibBoard::Shape::_lineJoin, LibBoard::Shape::_lineStyle, LibBoard::Shape::_lineWidth, _path, LibBoard::Shape::_penColor, LibBoard::Path::closed(), LibBoard::Path::empty(), LibBoard::Shape::filled(), LibBoard::Path::flushFIG(), LibBoard::Path::size(), and DGtal::Color::valid().

Referenced by LibBoard::Rectangle::flushFIG(), and LibBoard::QuadraticBezierCurve::flushFIG().

◆ flushPostscript()

void LibBoard::Polyline::flushPostscript ( std::ostream &  stream,
const TransformEPS transform 
) const
virtual

Writes the EPS code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Implements LibBoard::Shape.

Reimplemented in LibBoard::GouraudTriangle, and LibBoard::QuadraticBezierCurve.

Definition at line 1736 of file Shapes.cpp.

1738 {
1739  if ( _path.empty() ) return;
1740  stream << "\n% Polyline\n";
1741  if ( filled() ) {
1742  stream << "n ";
1743  _path.flushPostscript( stream, transform );
1744  stream << " ";
1745  _fillColor.flushPostscript( stream );
1746  stream << " " << postscriptProperties();
1747  stream << " fill" << std::endl;
1748  }
1749  if ( _penColor != DGtal::Color::None ) {
1750  stream << " " << postscriptProperties() << "\n";
1751  stream << "n ";
1752  _path.flushPostscript( stream, transform );
1753  stream << " ";
1754  _penColor.flushPostscript( stream );
1755  stream << " stroke" << std::endl;
1756  }
1757 }
void flushPostscript(std::ostream &) const
Definition: Color.cpp:142
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Path.cpp:154
std::string postscriptProperties() const
Definition: Shapes.cpp:140

References LibBoard::Shape::_fillColor, _path, LibBoard::Shape::_penColor, LibBoard::Path::empty(), LibBoard::Shape::filled(), DGtal::Color::flushPostscript(), LibBoard::Path::flushPostscript(), DGtal::Color::None, and LibBoard::Shape::postscriptProperties().

Referenced by LibBoard::GouraudTriangle::flushPostscript().

◆ flushSVG()

void LibBoard::Polyline::flushSVG ( std::ostream &  stream,
const TransformSVG transform 
) const
virtual

Writes the SVG code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Implements LibBoard::Shape.

Reimplemented in LibBoard::GouraudTriangle, LibBoard::QuadraticBezierCurve, LibBoard::Image, and LibBoard::Rectangle.

Definition at line 1792 of file Shapes.cpp.

1794 {
1795  if ( _path.empty() )
1796  return;
1797  if ( _path.closed() )
1798  stream << "<polygon";
1799  else
1800  stream << "<polyline";
1801  stream << svgProperties( transform ) << std::endl;
1802  stream << " points=\"";
1803  _path.flushSVGPoints( stream, transform );
1804  stream << "\" />" << std::endl;
1805 }
void flushSVGPoints(std::ostream &stream, const TransformSVG &transform) const
Definition: Path.cpp:215
std::string svgProperties(const TransformSVG &transform) const
Definition: Shapes.cpp:109

References _path, LibBoard::Path::closed(), LibBoard::Path::empty(), LibBoard::Path::flushSVGPoints(), and LibBoard::Shape::svgProperties().

Referenced by LibBoard::Rectangle::flushSVG(), and LibBoard::GouraudTriangle::flushSVG().

◆ flushTikZ()

void LibBoard::Polyline::flushTikZ ( std::ostream &  stream,
const TransformTikZ transform 
) const
virtual

Writes the TikZ code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Implements LibBoard::Shape.

Reimplemented in LibBoard::GouraudTriangle, LibBoard::QuadraticBezierCurve, LibBoard::Image, and LibBoard::Rectangle.

Definition at line 1850 of file Shapes.cpp.

1852 {
1853  if ( _path.empty() )
1854  return;
1855 
1856  stream << "\\path[" << tikzProperties(transform) << "] ";
1857  //stream << svgProperties( transform ) << std::endl;
1858 
1859  _path.flushTikZPoints( stream, transform );
1860 
1861  if ( _path.closed() )
1862  stream << " -- cycle";
1863  stream << ";" << std::endl;
1864 }
void flushTikZPoints(std::ostream &stream, const TransformTikZ &transform) const
Definition: Path.cpp:255
std::string tikzProperties(const TransformTikZ &transform) const
Definition: Shapes.cpp:177

References _path, LibBoard::Path::closed(), LibBoard::Path::empty(), LibBoard::Path::flushTikZPoints(), and LibBoard::Shape::tikzProperties().

Referenced by LibBoard::Rectangle::flushTikZ().

◆ name()

const std::string & LibBoard::Polyline::name ( ) const
virtual

Returns the generic name of the shape (e.g., Circle, Rectangle, etc.)

Returns
object name

Reimplemented from LibBoard::Shape.

Reimplemented in LibBoard::GouraudTriangle, LibBoard::QuadraticBezierCurve, LibBoard::Triangle, LibBoard::Image, and LibBoard::Rectangle.

Definition at line 1642 of file Shapes.cpp.

1643 {
1644  return _name;
1645 }
static const std::string _name
Definition: Board/Shapes.h:902

References _name.

◆ operator<<()

Polyline & LibBoard::Polyline::operator<< ( const Point p)

Add a point to the polyline.

Parameters
ppoint to add
Returns
a polyline

Definition at line 1647 of file Shapes.cpp.

1649 {
1650  _path << p;
1651  return *this;
1652 }

References _path.

◆ operator[]()

Point& LibBoard::Polyline::operator[] ( const unsigned int  n)
inline

Returns the n-th point of the polyline.

Parameters
nindex
Returns
n-th point

Definition at line 815 of file Board/Shapes.h.

815  {
816  return _path[ n ];
817  }

References _path.

◆ rotate() [1/2]

Polyline & LibBoard::Polyline::rotate ( double  angle)
virtual

Rotate the shape around its center.

Parameters
angleThe rotation angle in radian.
Returns
A reference to the shape itself.

Implements LibBoard::Shape.

Reimplemented in LibBoard::GouraudTriangle.

Definition at line 1673 of file Shapes.cpp.

1674 {
1675  _path.rotate( angle, center() );
1676  return *this;
1677 }
Path & rotate(double angle, const Point &center)
Definition: Path.cpp:43
Point center() const
Definition: Shapes.cpp:1655

References _path, center(), and LibBoard::Path::rotate().

◆ rotate() [2/2]

Polyline & LibBoard::Polyline::rotate ( double  angle,
const Point center 
)
virtual

Rotate the shape around a given center of rotation.

Parameters
angleThe rotation angle in radian.
centerThe center of rotation.
Returns
A reference to the shape itself.

Implements LibBoard::Shape.

Reimplemented in LibBoard::GouraudTriangle.

Definition at line 1660 of file Shapes.cpp.

1661 {
1662  _path.rotate( angle, rotCenter );
1663  return *this;
1664 }

References _path, and LibBoard::Path::rotate().

◆ rotated() [1/2]

Polyline LibBoard::Polyline::rotated ( double  angle) const
Parameters
angleangle
Returns
rotated polyline

Definition at line 1680 of file Shapes.cpp.

1681 {
1682  return Polyline(*this).rotate( angle, center() );
1683 }

References center(), and Polyline().

◆ rotated() [2/2]

Polyline LibBoard::Polyline::rotated ( double  angle,
const Point center 
) const
Parameters
angleangle
centercenter
Returns
a polyline

Definition at line 1667 of file Shapes.cpp.

1668 {
1669  return Polyline(*this).rotate( angle, rotCenter );
1670 }

References Polyline().

◆ scale() [1/2]

Shape & LibBoard::Polyline::scale ( double  s)
virtual

Scale the shape along both axis.

Parameters
sThe scale factor along both axis.
Returns
The shape itself.

Implements LibBoard::Shape.

Definition at line 1706 of file Shapes.cpp.

1707 {
1708  Polyline::scale( s, s );
1709  return *this;
1710 }
Shape & scale(double sx, double sy)
Definition: Shapes.cpp:1699

References scale().

◆ scale() [2/2]

Shape & LibBoard::Polyline::scale ( double  sx,
double  sy 
)
virtual

Scale the shape along the x an y axis.

Parameters
sxThe scale factor along the x axis.
syThe scale factor along the y axis.
Returns
The shape itself.

Implements LibBoard::Shape.

Definition at line 1699 of file Shapes.cpp.

1700 {
1701  _path.scale( sx, sy );
1702  return *this;
1703 }
Path & scale(double sx, double sy)
Definition: Path.cpp:108

References _path, and LibBoard::Path::scale().

Referenced by scale().

◆ scaleAll()

void LibBoard::Polyline::scaleAll ( double  s)
virtual

Scales all the values (positions, dimensions, etc.) associated with the shape.

Parameters
sThe scaling factor.

Implements LibBoard::Shape.

Reimplemented in LibBoard::GouraudTriangle, and LibBoard::Rectangle.

Definition at line 1725 of file Shapes.cpp.

1726 {
1727  _path.scaleAll( s );
1728 }
void scaleAll(double s)
Definition: Path.cpp:143

References _path, and LibBoard::Path::scaleAll().

◆ scaled() [1/2]

Polyline LibBoard::Polyline::scaled ( double  s) const

Definition at line 1719 of file Shapes.cpp.

1720 {
1721  return static_cast<Polyline &>( Polyline(*this).scale( s, s ) );
1722 }

References Polyline().

◆ scaled() [2/2]

Polyline LibBoard::Polyline::scaled ( double  sx,
double  sy 
) const
Parameters
sxsx
sysy
Returns
polyline

Definition at line 1713 of file Shapes.cpp.

1714 {
1715  return static_cast<Polyline &>( Polyline(*this).scale( sx, sy ) );
1716 }

References Polyline().

◆ translate()

Polyline & LibBoard::Polyline::translate ( double  dx,
double  dy 
)
virtual

Translate the shape by a given offset.

Parameters
dxThe x offset.
dyThe y offset.
Returns
A reference to the shape itself.

Implements LibBoard::Shape.

Definition at line 1686 of file Shapes.cpp.

1687 {
1688  _path.translate( dx, dy );
1689  return *this;
1690 }
Path & translate(double dx, double dy)
Definition: Path.cpp:81

References _path, and LibBoard::Path::translate().

◆ translated()

Polyline LibBoard::Polyline::translated ( double  dx,
double  dy 
) const
Parameters
dxdx
dydy
Returns
polyline

Definition at line 1693 of file Shapes.cpp.

1694 {
1695  return Polyline(*this).translate( dx, dy );
1696 }

References Polyline().

Field Documentation

◆ _name

const std::string LibBoard::Polyline::_name
staticprivate

The generic name of the shape.

Definition at line 902 of file Board/Shapes.h.

Referenced by name().

◆ _path


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