DGtal  0.9.3beta
Public Member Functions | Protected Attributes | Static Private Attributes
LibBoard::Polyline Struct Reference

#include <Board/Shapes.h>

Inheritance diagram for LibBoard::Polyline:
[legend]
Collaboration 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

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

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 1868 of file Shapes.cpp.

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

1869 {
1870  return _path.boundingBox();
1871 }
Rect boundingBox() const
Definition: Path.cpp:272
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 1656 of file Shapes.cpp.

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

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

1656  {
1657  return _path.center();
1658 }
Point center() const
Definition: Path.cpp:36
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 1732 of file Shapes.cpp.

References Polyline().

1732  {
1733  return new Polyline(*this);
1734 }
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)
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 1810 of file Shapes.cpp.

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().

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

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::TransformFIG::mapDepth(), LibBoard::TransformFIG::mapWidth(), LibBoard::Path::size(), and DGtal::Color::valid().

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

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

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

Referenced by LibBoard::GouraudTriangle::flushPostscript(), and LibBoard::Board::saveEPS().

1739 {
1740  if ( _path.empty() ) return;
1741  stream << "\n% Polyline\n";
1742  if ( filled() ) {
1743  stream << "n ";
1744  _path.flushPostscript( stream, transform );
1745  stream << " ";
1746  _fillColor.flushPostscript( stream );
1747  stream << " " << postscriptProperties();
1748  stream << " fill" << std::endl;
1749  }
1750  if ( _penColor != DGtal::Color::None ) {
1751  stream << " " << postscriptProperties() << "\n";
1752  stream << "n ";
1753  _path.flushPostscript( stream, transform );
1754  stream << " ";
1755  _penColor.flushPostscript( stream );
1756  stream << " stroke" << std::endl;
1757  }
1758 }
std::string postscriptProperties() const
Definition: Shapes.cpp:141
static const Color None
Definition: Color.h:387
void flushPostscript(std::ostream &) const
Definition: Color.cpp:124
bool empty() const
Definition: Path.h:243
bool filled() const
Definition: Board/Shapes.h:111
DGtal::Color _penColor
Definition: Board/Shapes.h:296
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Path.cpp:154
DGtal::Color _fillColor
Definition: Board/Shapes.h:297
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 1793 of file Shapes.cpp.

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

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

1795 {
1796  if ( _path.empty() )
1797  return;
1798  if ( _path.closed() )
1799  stream << "<polygon";
1800  else
1801  stream << "<polyline";
1802  stream << svgProperties( transform ) << std::endl;
1803  stream << " points=\"";
1804  _path.flushSVGPoints( stream, transform );
1805  stream << "\" />" << std::endl;
1806 }
void flushSVGPoints(std::ostream &stream, const TransformSVG &transform) const
Definition: Path.cpp:215
bool empty() const
Definition: Path.h:243
std::string svgProperties(const TransformSVG &transform) const
Definition: Shapes.cpp:110
bool closed() const
Definition: Path.h:237
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 1851 of file Shapes.cpp.

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

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

1853 {
1854  if ( _path.empty() )
1855  return;
1856 
1857  stream << "\\path[" << tikzProperties(transform) << "] ";
1858  //stream << svgProperties( transform ) << std::endl;
1859 
1860  _path.flushTikZPoints( stream, transform );
1861 
1862  if ( _path.closed() )
1863  stream << " -- cycle";
1864  stream << ";" << std::endl;
1865 }
void flushTikZPoints(std::ostream &stream, const TransformTikZ &transform) const
Definition: Path.cpp:255
std::string tikzProperties(const TransformTikZ &transform) const
Definition: Shapes.cpp:178
bool empty() const
Definition: Path.h:243
bool closed() const
Definition: Path.h:237
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 1643 of file Shapes.cpp.

References _name.

1644 {
1645  return _name;
1646 }
static const std::string _name
Definition: Board/Shapes.h:902
Polyline & LibBoard::Polyline::operator<< ( const Point p)

Add a point to the polyline.

Parameters
ppoint to add
Returns
a polyline

Definition at line 1649 of file Shapes.cpp.

References _path.

1650 {
1651  _path << p;
1652  return *this;
1653 }
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.

References _path.

815  {
816  return _path[ n ];
817  }
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 1661 of file Shapes.cpp.

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

1662 {
1663  _path.rotate( angle, rotCenter );
1664  return *this;
1665 }
Path & rotate(double angle, const Point &center)
Definition: Path.cpp:43
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 1674 of file Shapes.cpp.

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

1675 {
1676  _path.rotate( angle, center() );
1677  return *this;
1678 }
Path & rotate(double angle, const Point &center)
Definition: Path.cpp:43
Point center() const
Definition: Shapes.cpp:1656
Polyline LibBoard::Polyline::rotated ( double  angle,
const Point center 
) const
Parameters
angleangle
centercenter
Returns
a polyline

Definition at line 1668 of file Shapes.cpp.

References Polyline().

1669 {
1670  return Polyline(*this).rotate( angle, rotCenter );
1671 }
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 LibBoard::Polyline::rotated ( double  angle) const
Parameters
angleangle
Returns
rotated polyline

Definition at line 1681 of file Shapes.cpp.

References center(), and Polyline().

1682 {
1683  return Polyline(*this).rotate( angle, center() );
1684 }
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)
Point center() const
Definition: Shapes.cpp:1656
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 1700 of file Shapes.cpp.

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

Referenced by scale().

1701 {
1702  _path.scale( sx, sy );
1703  return *this;
1704 }
Path & scale(double sx, double sy)
Definition: Path.cpp:108
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 1707 of file Shapes.cpp.

References scale().

1708 {
1709  Polyline::scale( s, s );
1710  return *this;
1711 }
Shape & scale(double sx, double sy)
Definition: Shapes.cpp:1700
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 1726 of file Shapes.cpp.

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

1727 {
1728  _path.scaleAll( s );
1729 }
void scaleAll(double s)
Definition: Path.cpp:143
Polyline LibBoard::Polyline::scaled ( double  sx,
double  sy 
) const
Parameters
sxsx
sysy
Returns
polyline

Definition at line 1714 of file Shapes.cpp.

References Polyline().

1715 {
1716  return static_cast<Polyline &>( Polyline(*this).scale( sx, sy ) );
1717 }
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 LibBoard::Polyline::scaled ( double  s) const

Definition at line 1720 of file Shapes.cpp.

References Polyline().

1721 {
1722  return static_cast<Polyline &>( Polyline(*this).scale( s, s ) );
1723 }
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 & 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 1687 of file Shapes.cpp.

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

1688 {
1689  _path.translate( dx, dy );
1690  return *this;
1691 }
Path & translate(double dx, double dy)
Definition: Path.cpp:81
Polyline LibBoard::Polyline::translated ( double  dx,
double  dy 
) const
Parameters
dxdx
dydy
Returns
polyline

Definition at line 1694 of file Shapes.cpp.

References Polyline().

1695 {
1696  return Polyline(*this).translate( dx, dy );
1697 }
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)

Field Documentation

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 LibBoard::Polyline::_path
protected

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