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

#include <Board/Shapes.h>

Inheritance diagram for LibBoard::Arc:
[legend]
Collaboration diagram for LibBoard::Arc:
[legend]

Public Member Functions

 Arc (double x, double y, double radius, double angle1, double angle2, bool negative, DGtal::Color pen, DGtal::Color fill, double lineWidth, const LineStyle style=SolidStyle, int depthValue=-1)
 
const std::string & name () const
 
void flushPostscript (std::ostream &stream, const TransformEPS &transform) 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
 
- Public Member Functions inherited from LibBoard::Circle
 Circle (double x, double y, double radius, DGtal::Color pen, DGtal::Color fill, double lineWidth, const LineStyle style=SolidStyle, int depthValue=-1)
 
Point center () const
 
Circlerotate (double angle, const Point &center)
 
Circle rotated (double angle, const Point &center) const
 
Circlerotate (double angle)
 
Circle rotated (double angle) const
 
Circletranslate (double dx, double dy)
 
Circle translated (double dx, double dy) const
 
Shapescale (double sx, double sy)
 
Shapescale (double s)
 
Circle scaled (double sx, double sy) const
 
Circle scaled (double s) const
 
void scaleAll (double s)
 
Circleclone () const
 
- Public Member Functions inherited from LibBoard::Ellipse
 Ellipse (double x, double y, double xRadius, double yRadius, DGtal::Color pen, DGtal::Color fill, double lineWidth, const LineStyle lineStyle=SolidStyle, int depthValue=-1)
 
Ellipse rotated (double angle, const Point &center) const
 
Ellipse rotated (double angle) const
 
Ellipse translated (double dx, double dy) const
 
Ellipse scaled (double sx, double sy) const
 
Ellipse scaled (double s) const
 
void flushFIG (std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
 
Rect boundingBox () 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

double _angle1
 
double _angle2
 
bool _negative
 
- Protected Attributes inherited from LibBoard::Ellipse
Point _center
 
double _xRadius
 
double _yRadius
 
double _angle
 
bool _circle
 
- 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

An arc.

The arc structure.

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

Constructor & Destructor Documentation

LibBoard::Arc::Arc ( double  x,
double  y,
double  radius,
double  angle1,
double  angle2,
bool  negative,
DGtal::Color  pen,
DGtal::Color  fill,
double  lineWidth,
const LineStyle  style = SolidStyle,
int  depthValue = -1 
)
inline

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

References _angle1, _angle2, and _negative.

1535  : Circle( x, y, radius, pen, fill, lineWidth, style, depthValue )
1536  { _angle1 = angle1; _angle2 = angle2; _negative = negative; }
Circle(double x, double y, double radius, DGtal::Color pen, DGtal::Color fill, double lineWidth, const LineStyle style=SolidStyle, int depthValue=-1)

Member Function Documentation

void LibBoard::Arc::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.

Reimplemented from LibBoard::Circle.

Definition at line 1501 of file Shapes.cpp.

References _angle1, _angle2, LibBoard::Ellipse::_center, LibBoard::Shape::_fillColor, LibBoard::Shape::_lineCap, LibBoard::Shape::_lineJoin, LibBoard::Shape::_lineStyle, LibBoard::Shape::_lineWidth, _negative, LibBoard::Shape::_penColor, LibBoard::Ellipse::_xRadius, DGtal::Color::blue(), LibBoard::Shape::filled(), DGtal::Color::green(), LibBoard::Transform::mapX(), LibBoard::TransformCairo::mapY(), DGtal::Color::None, DGtal::Color::red(), LibBoard::Transform::scale(), LibBoard::Shape::setCairoDashStyle(), LibBoard::Point::x, and LibBoard::Point::y.

1503 {
1504  cairo_save (cr);
1505 
1506  cairo_set_source_rgba (cr, _fillColor.red()/255.0, _fillColor.green()/255.0, _fillColor.blue()/255.0, 1.);
1507 
1508  if (_negative) // important: here for Cairo we must inverse 'cairo_arc' and 'cairo_arc_negative' and change alpha with 2.*M_PI-alpha
1509  cairo_arc (cr, transform.mapX( _center.x ), transform.mapY( _center.y ), transform.scale( _xRadius ), 2.*M_PI-_angle1, 2.*M_PI-_angle2);
1510  else
1511  cairo_arc_negative (cr, transform.mapX( _center.x ), transform.mapY( _center.y ), transform.scale( _xRadius ), 2.*M_PI-_angle1, 2.*M_PI-_angle2);
1512 
1513  if ( filled() )
1514  {
1515  if ( _penColor != DGtal::Color::None )
1516  cairo_fill_preserve (cr);
1517  else
1518  cairo_fill (cr);
1519  }
1520 
1521  //
1522 
1523  if ( _penColor != DGtal::Color::None )
1524  {
1525  cairo_set_source_rgba (cr, _penColor.red()/255.0, _penColor.green()/255.0, _penColor.blue()/255.0, 1.);
1526 
1527  cairo_set_line_width (cr, _lineWidth);
1528  cairo_set_line_cap (cr, cairoLineCap[_lineCap]);
1529  cairo_set_line_join (cr, cairoLineJoin[_lineJoin]);
1531 
1532  cairo_stroke (cr);
1533  }
1534 
1535  cairo_restore (cr);
1536 }
static const Color None
Definition: Color.h:387
double x
Definition: Point.h:29
LineJoin _lineJoin
Definition: Board/Shapes.h:301
bool filled() const
Definition: Board/Shapes.h:111
void green(const unsigned char aGreenValue)
double y
Definition: Point.h:30
DGtal::Color _penColor
Definition: Board/Shapes.h:296
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
DGtal::Color _fillColor
Definition: Board/Shapes.h:297
void blue(const unsigned char aBlueValue)
void LibBoard::Arc::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.

Reimplemented from LibBoard::Ellipse.

Definition at line 1540 of file Shapes.cpp.

References _angle1, _angle2, LibBoard::Ellipse::_center, LibBoard::Shape::_fillColor, _negative, LibBoard::Shape::_penColor, LibBoard::Ellipse::_xRadius, LibBoard::Shape::filled(), DGtal::Color::flushPostscript(), LibBoard::Transform::mapX(), LibBoard::TransformEPS::mapY(), DGtal::Color::None, DGtal::Color::postscript(), LibBoard::Transform::scale(), LibBoard::Point::x, and LibBoard::Point::y.

1542 {
1543 
1544 //The arc is generated by sweeping a line segment of length r, and tied at the point (x-coord y-coord), in a counter-clockwise direction from an angle _angle1 to an angle _angle2.
1545 //Thus, we have to swap _angle1 and _angle2 according to bool _negative
1546  double a1, a2;
1547  if (_negative == true)
1548  {
1549  a1 = _angle2;
1550  a2 = _angle1;
1551  }
1552  else
1553  {
1554  a1 = _angle1;
1555  a2 = _angle2;
1556  }
1557 
1558  stream << "\n% Arc\n";
1559  if ( filled() ) {
1560  stream << "gs "
1561  << transform.mapX( _center.x ) << " " << transform.mapY( _center.y ) << " "
1562  << transform.scale( _xRadius )<< " " << (a1*180/M_PI) << " "
1563  << (a2*180/M_PI) << " "<< "arc ";
1564  stream << " " << _fillColor.postscript() << " srgb";
1565  stream << " fill gr" << std::endl;
1566  }
1567 
1568  if ( _penColor != DGtal::Color::None ) {
1569 
1570  stream << "gs "
1571  << transform.mapX( _center.x ) << " " << transform.mapY( _center.y ) << " "
1572  << transform.scale( _xRadius )<< " " << (a1*180/M_PI) << " "
1573  << (a2*180/M_PI) << " "<< "arc ";
1574  _penColor.flushPostscript( stream );
1575  stream << " stroke gr" << std::endl;
1576  }
1577 }
static const Color None
Definition: Color.h:387
void flushPostscript(std::ostream &) const
Definition: Color.cpp:124
double x
Definition: Point.h:29
std::string postscript() const
Definition: Color.cpp:132
bool filled() const
Definition: Board/Shapes.h:111
double y
Definition: Point.h:30
DGtal::Color _penColor
Definition: Board/Shapes.h:296
DGtal::Color _fillColor
Definition: Board/Shapes.h:297
void LibBoard::Arc::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.

Reimplemented from LibBoard::Circle.

Definition at line 1580 of file Shapes.cpp.

References _angle1, _angle2, LibBoard::Ellipse::_center, _negative, LibBoard::Ellipse::_xRadius, LibBoard::Transform::mapX(), LibBoard::TransformSVG::mapY(), LibBoard::Transform::scale(), LibBoard::Shape::svgProperties(), LibBoard::Point::x, and LibBoard::Point::y.

1582 {
1583 
1584 double fx = _center.x + _xRadius*std::cos(_angle1);
1585 double fy = _center.y + _xRadius*std::sin(_angle1);
1586 double lx = _center.x + _xRadius*std::cos(_angle2);
1587 double ly = _center.y + _xRadius*std::sin(_angle2);
1588 
1589 stream << "<path ";
1590 stream << svgProperties( transform ) << " ";
1591 //first point
1592 stream << "d='M " << transform.mapX( fx );
1593 stream << "," << transform.mapY( fy );
1594 //arc
1595 stream << " A " << transform.scale( _xRadius ) << " " << transform.scale( _xRadius );
1596 //something
1597 stream << " 0";
1598 //orientation and center position
1599 if (_negative)
1600 {
1601  if ( (std::cos(_angle1)*std::sin(_angle2) - std::sin(_angle1)*std::cos(_angle2))<0 )
1602  {
1603  stream << " 0 1";
1604  } else
1605  {
1606  stream << " 1 1";
1607  }
1608 } else
1609 {
1610  if ( (std::cos(_angle1)*std::sin(_angle2) - std::sin(_angle1)*std::cos(_angle2))<0 )
1611  {
1612  stream << " 1 0";
1613  } else
1614  {
1615  stream << " 0 0";
1616  }
1617 }
1618 //last point
1619 stream << " " << transform.mapX( lx );
1620 stream << "," << transform.mapY( ly );
1621 stream << "' />";
1622 
1623 }
double x
Definition: Point.h:29
std::string svgProperties(const TransformSVG &transform) const
Definition: Shapes.cpp:110
double y
Definition: Point.h:30
void LibBoard::Arc::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.

Reimplemented from LibBoard::Circle.

Definition at line 1626 of file Shapes.cpp.

References _angle1, _angle2, LibBoard::Ellipse::_center, _negative, LibBoard::Ellipse::_xRadius, LibBoard::Transform::mapX(), LibBoard::TransformSVG::mapY(), LibBoard::Transform::scale(), LibBoard::Shape::tikzProperties(), LibBoard::Point::x, and LibBoard::Point::y.

1628 {
1629  stream << "\\path[" << tikzProperties(transform) << "] ("
1630  << transform.mapX( _center.x ) << ',' << transform.mapY( _center.y ) << ')' // center
1631  << " +(" << -_angle1/M_PI*180. << ':' << transform.scale( _xRadius) << ')' // first point of arc
1632  << " arc (" << -_angle1/M_PI*180. << ':' << -_angle2/M_PI*180. + _negative * 360. << ':' << transform.scale( _xRadius ) << ");"
1633  << std::endl;
1634 }
std::string tikzProperties(const TransformTikZ &transform) const
Definition: Shapes.cpp:178
double x
Definition: Point.h:29
double y
Definition: Point.h:30
const std::string & LibBoard::Arc::name ( ) const
virtual

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

Returns
object name

Reimplemented from LibBoard::Circle.

Definition at line 1494 of file Shapes.cpp.

References _name.

1495 {
1496  return _name;
1497 }
static const std::string _name

Field Documentation

double LibBoard::Arc::_angle1
protected

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

Referenced by Arc(), flushCairo(), flushPostscript(), flushSVG(), and flushTikZ().

double LibBoard::Arc::_angle2
protected

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

Referenced by Arc(), flushCairo(), flushPostscript(), flushSVG(), and flushTikZ().

const std::string LibBoard::Arc::_name
staticprivate

The generic name of the shape.

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

Referenced by name().

bool LibBoard::Arc::_negative
protected

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

Referenced by Arc(), flushCairo(), flushPostscript(), flushSVG(), and flushTikZ().


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