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

#include <Board/Shapes.h>

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

Public Member Functions

 Line (double x1, double y1, double x2, double y2, DGtal::Color color, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
 
const std::string & name () const
 
Point center () const
 
Linerotate (double angle, const Point &center)
 
Line rotated (double angle, const Point &center) const
 
Linerotate (double angle)
 
Line rotated (double angle) const
 
Linetranslate (double dx, double dy)
 
Line translated (double dx, double dy) const
 
Shapescale (double sx, double sy)
 
Shapescale (double s)
 
Line scaled (double sx, double sy) const
 
Line 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
 
Lineclone () 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 _x1
 
double _y1
 
double _x2
 
double _y2
 
- 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 line between two points.

The line structure.

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

Constructor & Destructor Documentation

◆ Line()

LibBoard::Line::Line ( double  x1,
double  y1,
double  x2,
double  y2,
DGtal::Color  color,
double  lineWidth,
const LineStyle  style = SolidStyle,
const LineCap  cap = ButtCap,
const LineJoin  join = MiterJoin,
int  depth = -1 
)
inline

Constructs a line.

Parameters
x1First coordinate of the start point.
y1Second coordinate of the start point.
x2First coordinate of the end point.
y2Second coordinate of the end point.
colorThe color of the line.
lineWidthThe line thickness.
styleThe line style.
capThe line cap.
joinThe line join.
depthThe depth of the line.

Member Function Documentation

◆ boundingBox()

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

Returns the bounding box of the figure.

Returns
The rectangle of the bounding box.

Implements LibBoard::Shape.

Definition at line 605 of file Shapes.cpp.

References LibBoard::Image::_name, LibBoard::Rect::height, LibBoard::Rect::left, LibBoard::Rect::top, and LibBoard::Rect::width.

606 {
607  Rect rect;
608  if ( _x1 > _x2 ) {
609  rect.width = _x1 - _x2;
610  rect.left = _x2;
611  } else {
612  rect.width = _x2 - _x1;
613  rect.left = _x1;
614  }
615  if ( _y1 > _y2 ) {
616  rect.top = _y1;
617  rect.height = _y1 - _y2;
618  } else {
619  rect.top = _y2;
620  rect.height = _y2 - _y1;
621  }
622  return rect;
623 }

◆ center()

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

Returns the gravity center of the shape.

Returns
The center of the shape.

Implements LibBoard::Shape.

Definition at line 403 of file Shapes.cpp.

Referenced by scaled(), and LibBoard::Arrow::scaled().

403  {
404  return 0.5 * Point( _x1 + _x2, _y1 + _y2 );
405 }
MyPointD Point
Definition: testClone2.cpp:383

◆ clone()

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

Return a copy of the shape.

Returns
copye of the shape.

Implements LibBoard::Shape.

Reimplemented in LibBoard::Arrow.

Definition at line 510 of file Shapes.cpp.

510  {
511  return new Line(*this);
512 }
Line(double x1, double y1, double x2, double y2, DGtal::Color color, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)

◆ flushCairo()

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

Definition at line 572 of file Shapes.cpp.

References LibBoard::Shape::_lineCap, LibBoard::Shape::_lineJoin, LibBoard::Shape::_lineStyle, LibBoard::Shape::_lineWidth, LibBoard::Shape::_penColor, DGtal::Color::blue(), DGtal::Color::green(), LibBoard::Transform::mapX(), LibBoard::TransformCairo::mapY(), DGtal::Color::red(), and LibBoard::Shape::setCairoDashStyle().

574 {
575  cairo_save (cr);
576 
577  cairo_set_source_rgba (cr, _penColor.red()/255.0, _penColor.green()/255.0, _penColor.blue()/255.0, 1.);
578 
579  cairo_move_to (cr, transform.mapX( _x1 ), transform.mapY( _y1 ));
580  cairo_line_to (cr, transform.mapX( _x2 ), transform.mapY( _y2 ));
581 
582  cairo_set_line_width (cr, _lineWidth);
583  cairo_set_line_cap (cr, cairoLineCap[_lineCap]);
584  cairo_set_line_join (cr, cairoLineJoin[_lineJoin]);
586 
587  cairo_stroke (cr);
588 
589  cairo_restore (cr);
590 }
void setCairoDashStyle(cairo_t *cr, LineStyle type) const
Definition: Shapes.cpp:154
LineJoin _lineJoin
Definition: Board/Shapes.h:301
void green(const unsigned char aGreenValue)
DGtal::Color _penColor
Definition: Board/Shapes.h:296
void red(const unsigned char aRedValue)
LineStyle _lineStyle
Definition: Board/Shapes.h:299
void blue(const unsigned char aBlueValue)

◆ flushFIG()

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

Definition at line 530 of file Shapes.cpp.

References LibBoard::Shape::_depth, LibBoard::Shape::_lineCap, LibBoard::Shape::_lineJoin, LibBoard::Shape::_lineStyle, LibBoard::Shape::_lineWidth, LibBoard::Shape::_penColor, LibBoard::TransformFIG::mapDepth(), LibBoard::TransformFIG::mapWidth(), LibBoard::Transform::mapX(), LibBoard::TransformFIG::mapY(), and DGtal::Color::valid().

533 {
534  stream << "2 1 ";
535  // Line style
536  stream << _lineStyle << " ";
537  // Thickness
538  stream << ( _penColor.valid()?transform.mapWidth( _lineWidth ):0 ) << " ";
539  // Pen color
540  stream << colormap[ _penColor ] << " ";
541  // Fill color
542  stream << "0 ";
543  // Depth
544  stream << transform.mapDepth( _depth ) << " ";
545  // Pen style
546  stream << "-1 ";
547  // Area fill, style val, join style, cap style, radius, f_arrow, b_arrow
548  stream << "-1 " << (_lineStyle?"4.000 ":"0.000 ") << _lineJoin << " " << _lineCap << " -1 0 0 ";
549  // Number of points
550  stream << "2\n";
551  stream << " ";
552  stream << static_cast<int>( transform.mapX( _x1 ) ) << " "
553  << static_cast<int>( transform.mapY( _y1 ) ) << " "
554  << static_cast<int>( transform.mapX( _x2 ) ) << " "
555  << static_cast<int>( transform.mapY( _y2 ) ) << std::endl;
556 }
LineJoin _lineJoin
Definition: Board/Shapes.h:301
bool valid() const
DGtal::Color _penColor
Definition: Board/Shapes.h:296
LineStyle _lineStyle
Definition: Board/Shapes.h:299

◆ flushPostscript()

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

Definition at line 515 of file Shapes.cpp.

References LibBoard::Shape::_penColor, LibBoard::Transform::mapX(), LibBoard::TransformEPS::mapY(), DGtal::Color::postscript(), and LibBoard::Shape::postscriptProperties().

517 {
518  stream << "\n% Line\n";
519  stream << postscriptProperties() << " "
520  << "n "
521  << transform.mapX( _x1 ) << " "
522  << transform.mapY( _y1 ) << " "
523  << "m "
524  << transform.mapX( _x2 ) << " "
525  << transform.mapY( _y2 ) << " "
526  << "l " << _penColor.postscript() << " srgb stroke" << std::endl;
527 }
std::string postscript() const
Definition: Color.cpp:132
DGtal::Color _penColor
Definition: Board/Shapes.h:296
std::string postscriptProperties() const
Definition: Shapes.cpp:141

◆ flushSVG()

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

Definition at line 559 of file Shapes.cpp.

References LibBoard::Transform::mapX(), LibBoard::TransformSVG::mapY(), and LibBoard::Shape::svgProperties().

561 {
562  stream << "<line x1=\"" << transform.mapX( _x1 ) << "\""
563  << " y1=\"" << transform.mapY( _y1 ) << "\""
564  << " x2=\"" << transform.mapX( _x2 ) << "\""
565  << " y2=\"" << transform.mapY( _y2 ) << "\""
566  << svgProperties( transform )
567  << " />" << std::endl;
568 }
std::string svgProperties(const TransformSVG &transform) const
Definition: Shapes.cpp:110

◆ flushTikZ()

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

Definition at line 594 of file Shapes.cpp.

References LibBoard::Transform::mapX(), LibBoard::TransformSVG::mapY(), and LibBoard::Shape::tikzProperties().

596 {
597  stream << "\\path[" << tikzProperties(transform) << "] ("
598  << transform.mapX( _x1 ) << ',' << transform.mapY( _y1 )
599  << ") -- ("
600  << transform.mapX( _x2 ) << ',' << transform.mapY( _y2 )
601  << ");" << std::endl;
602 }
std::string tikzProperties(const TransformTikZ &transform) const
Definition: Shapes.cpp:178

◆ name()

const std::string & LibBoard::Line::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::Arrow.

Definition at line 397 of file Shapes.cpp.

References LibBoard::Shape::_name.

398 {
399  return _name;
400 }
static const std::string _name
Definition: Board/Shapes.h:649

◆ rotate() [1/2]

Line & LibBoard::Line::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.

Definition at line 408 of file Shapes.cpp.

Referenced by rotate().

409 {
410  Point( _x1, _y1 ).rotate( angle, rotCenter ).get( _x1, _y1 );
411  Point( _x2, _y2 ).rotate( angle, rotCenter ).get( _x2, _y2 );
412  return *this;
413 }
MyPointD Point
Definition: testClone2.cpp:383

◆ rotate() [2/2]

Line & LibBoard::Line::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.

Definition at line 416 of file Shapes.cpp.

References LibBoard::Shape::center(), and rotate().

417 {
418  return Line::rotate( angle, center() );
419 }
Point center() const
Definition: Shapes.cpp:403
Line & rotate(double angle, const Point &center)
Definition: Shapes.cpp:408

◆ rotated() [1/2]

Line LibBoard::Line::rotated ( double  angle,
const Point center 
) const

Returns a copy of the line, rotated around a given rotation center.

Parameters
angleThe rotation angle.
centerThe center of rotation.
Returns
The rotated copy of the line.

Definition at line 422 of file Shapes.cpp.

References _x1, _x2, _y1, and _y2.

423 {
424  Line res(*this);
425  Point( _x1, _y1 ).rotate( angle, rotCenter ).get( res._x1, res._y1 );
426  Point( _x2, _y2 ).rotate( angle, rotCenter ).get( res._x2, res._y2 );
427  return res;
428 }
Line(double x1, double y1, double x2, double y2, DGtal::Color color, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
MyPointD Point
Definition: testClone2.cpp:383

◆ rotated() [2/2]

Line LibBoard::Line::rotated ( double  angle) const

Returns a copy of the line, rotated around its center.

Parameters
angleThe angle of rotation.
Returns
A copy of the lines, rotated around its center by the given angle.

Definition at line 431 of file Shapes.cpp.

References _x1, _x2, _y1, _y2, and LibBoard::Shape::center().

432 {
433  Line res(*this);
434  Point c = center();
435  Point( _x1, _y1 ).rotate( angle, c ).get( res._x1, res._y1 );
436  Point( _x2, _y2 ).rotate( angle, c ).get( res._x2, res._y2 );
437  return res;
438 }
Line(double x1, double y1, double x2, double y2, DGtal::Color color, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
Point center() const
Definition: Shapes.cpp:403
MyPointD Point
Definition: testClone2.cpp:383

◆ scale() [1/2]

Shape & LibBoard::Line::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 462 of file Shapes.cpp.

References LibBoard::Shape::center(), LibBoard::Shape::translate(), LibBoard::Point::x, and LibBoard::Point::y.

463 {
464  Point c = center();
465  _x1 *= sx;
466  _x2 *= sx;
467  _y1 *= sy;
468  _y2 *= sy;
469  Point delta = c - center();
470  translate( delta.x, delta.y );
471  return *this;
472 }
Point center() const
Definition: Shapes.cpp:403
MyPointD Point
Definition: testClone2.cpp:383
Line & translate(double dx, double dy)
Definition: Shapes.cpp:441

◆ scale() [2/2]

Shape & LibBoard::Line::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 475 of file Shapes.cpp.

References LibBoard::Shape::scale().

476 {
477  scale( s, s );
478  return (*this);
479 }
Shape & scale(double sx, double sy)
Definition: Shapes.cpp:462

◆ scaleAll()

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

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

Parameters
sThe scaling factor.

Implements LibBoard::Shape.

Definition at line 501 of file Shapes.cpp.

502 {
503  _x1 *= s;
504  _y1 *= s;
505  _x2 *= s;
506  _y2 *= s;
507 }

◆ scaled() [1/2]

Line LibBoard::Line::scaled ( double  sx,
double  sy 
) const

Returns a scaled copy of the line.

Parameters
sxScale factor along the x axis.
syScale factor along the y axis.
Returns
A scaled copy of the line.

Definition at line 482 of file Shapes.cpp.

References _x1, _x2, _y1, _y2, LibBoard::Shape::center(), center(), translate(), LibBoard::Point::x, and LibBoard::Point::y.

Referenced by scaled().

483 {
484  Line res(*this);
485  Point c = center();
486  res._x1 *= sx;
487  res._x2 *= sx;
488  res._y1 *= sy;
489  res._y2 *= sy;
490  Point delta = c - res.center();
491  return res.translate( delta.x, delta.y );
492 }
Line(double x1, double y1, double x2, double y2, DGtal::Color color, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
Point center() const
Definition: Shapes.cpp:403
MyPointD Point
Definition: testClone2.cpp:383

◆ scaled() [2/2]

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

Definition at line 495 of file Shapes.cpp.

References scaled().

496 {
497  return Line::scaled( s , s );
498 }
Line scaled(double sx, double sy) const
Definition: Shapes.cpp:482

◆ translate()

Line & LibBoard::Line::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 441 of file Shapes.cpp.

Referenced by scaled(), and LibBoard::Arrow::scaled().

442 {
443  _x1 += dx;
444  _x2 += dx;
445  _y1 += dy;
446  _y2 += dy;
447  return *this;
448 }

◆ translated()

Line LibBoard::Line::translated ( double  dx,
double  dy 
) const

Returns a translated copy of the line.

Parameters
dxThe shift along the x axis.
dyThe shift along the y axis.
Returns
A translated copy of the line.

Definition at line 451 of file Shapes.cpp.

References _x1, _x2, _y1, and _y2.

452 {
453  Line res(*this);
454  res._x1 += dx;
455  res._x2 += dx;
456  res._y1 += dy;
457  res._y2 += dy;
458  return *this;
459 }
Line(double x1, double y1, double x2, double y2, DGtal::Color color, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)

Field Documentation

◆ _name

const std::string LibBoard::Line::_name
staticprivate

The generic name of the shape.

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

Referenced by LibBoard::Dot::clone().

◆ _x1

double LibBoard::Line::_x1
protected

First coordinate of the start point.

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

Referenced by rotated(), LibBoard::Arrow::rotated(), scaled(), LibBoard::Arrow::scaled(), translated(), and LibBoard::Arrow::translated().

◆ _x2

double LibBoard::Line::_x2
protected

First coordinate of the end point.

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

Referenced by rotated(), LibBoard::Arrow::rotated(), scaled(), LibBoard::Arrow::scaled(), translated(), and LibBoard::Arrow::translated().

◆ _y1

double LibBoard::Line::_y1
protected

Second coordinate of the start point.

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

Referenced by rotated(), LibBoard::Arrow::rotated(), scaled(), LibBoard::Arrow::scaled(), translated(), and LibBoard::Arrow::translated().

◆ _y2

double LibBoard::Line::_y2
protected

Second coordinate of the end point.

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

Referenced by rotated(), LibBoard::Arrow::rotated(), scaled(), LibBoard::Arrow::scaled(), translated(), and LibBoard::Arrow::translated().


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