DGtal 1.3.0
Loading...
Searching...
No Matches
Public Member Functions | Static Private Attributes
LibBoard::Arrow Struct Reference

A line between two points with an arrow at one extremity. More...

#include <Board/Shapes.h>

Inheritance diagram for LibBoard::Arrow:
LibBoard::Line LibBoard::Shape

Public Member Functions

 Arrow (double x1, double y1, double x2, double y2, DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
 
const std::string & name () const
 
Arrow rotated (double angle, const Point &center) const
 
Arrow rotated (double angle) const
 
Arrow translated (double dx, double dy) const
 
Arrow scaled (double sx, double sy) const
 
Arrow scaled (double s) const
 
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
 
Arrowclone () const
 
- Public Member Functions inherited from 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)
 
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 ()
 
virtual const std::string & name () const
 
virtual Shapeclone () const =0
 
bool filled () const
 
virtual Point center () const =0
 
virtual Shaperotate (double angle, const Point &center)=0
 
virtual Shaperotate (double angle)=0
 
ShaperotateDeg (double angle, const Point &center)
 
ShaperotateDeg (double angle)
 
virtual Shapetranslate (double dx, double dy)=0
 
virtual Shapescale (double sx, double sy)=0
 
virtual Shapescale (double s)=0
 
virtual Rect boundingBox () const =0
 
Rect bbox ()
 
Shapeoperator-- ()
 
Shapeoperator++ ()
 
virtual void scaleAll (double s)=0
 
virtual void flushPostscript (std::ostream &stream, const TransformEPS &transform) const =0
 
virtual void flushFIG (std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const =0
 
virtual void flushSVG (std::ostream &stream, const TransformSVG &transform) const =0
 
virtual void flushCairo (cairo_t *cr, const TransformCairo &transform) const =0
 
virtual void flushTikZ (std::ostream &stream, const TransformTikZ &transform) const =0
 
int depth () const
 
virtual void depth (int)
 
virtual void shiftDepth (int shift)
 
const DGtal::ColorpenColor () const
 
const DGtal::ColorfillColor () const
 

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
 
- Protected Attributes inherited from LibBoard::Line
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
 

Detailed Description

A line between two points with an arrow at one extremity.

The arrow structure.

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

Constructor & Destructor Documentation

◆ Arrow()

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

Constructs an arrow.

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.
penColorThe color of the line.
fillColorThe fill color of the sharp end.
lineWidthThe line thickness.
styleLine style.
capLine cap.
joinLine join.
depthThe depth of the line.

Member Function Documentation

◆ clone()

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

Return a copy of the shape.

Returns
copye of the shape.

Reimplemented from LibBoard::Line.

Definition at line 788 of file Shapes.cpp.

788 {
789 return new Arrow(*this);
790}
Arrow(double x1, double y1, double x2, double y2, DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)

◆ flushCairo()

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

Definition at line 933 of file Shapes.cpp.

935{
936 double dx = _x1 - _x2;
937 double dy = _y1 - _y2;
938 double norm = sqrt( dx*dx + dy*dy );
939 dx /= norm;
940 dy /= norm;
941 dx *= 10 * _lineWidth;
942 dy *= 10 * _lineWidth;
943
944 // double back_x = 0.8 * dx + _x2;
945 // double back_y = 0.8 * dy + _y2;
946
947 double ndx1 = dx*cos(0.3)-dy*sin(0.3);
948 double ndy1 = dx*sin(0.3)+dy*cos(0.3);
949 double ndx2 = dx*cos(-0.3)-dy*sin(-0.3);
950 double ndy2 = dx*sin(-0.3)+dy*cos(-0.3);
951
952 cairo_save (cr);
953
954 // The line
955 cairo_set_source_rgba (cr, _penColor.red()/255.0, _penColor.green()/255.0, _penColor.blue()/255.0, 1.);
956
957 cairo_move_to (cr, transform.mapX( _x1 ), transform.mapY( _y1 ));
958 cairo_line_to (cr, transform.mapX( _x2 + ( dx * cos(0.3) ) ), transform.mapY( _y2 + ( dy * cos(0.3) ) ));
959
960 cairo_set_line_width (cr, _lineWidth);
961 cairo_set_line_cap (cr, cairoLineCap[_lineCap]);
962 cairo_set_line_join (cr, cairoLineJoin[_lineJoin]);
964
965 cairo_stroke (cr);
966
967 // The arrow
968 cairo_set_source_rgba (cr, _fillColor.red()/255.0, _fillColor.green()/255.0, _fillColor.blue()/255.0, 1.);
969
970 cairo_move_to (cr, transform.mapX( _x2 ) + transform.scale( ndx1 ), transform.mapY( _y2 ) - transform.scale( ndy1 ));
971 cairo_line_to (cr, transform.mapX( _x2 ), transform.mapY( _y2 ));
972 cairo_line_to (cr, transform.mapX( _x2 ) + transform.scale( ndx2 ), transform.mapY( _y2 ) - transform.scale( ndy2 ));
973 cairo_close_path (cr);
974
975 if ( filled() )
976 {
978 cairo_fill_preserve (cr);
979 else
980 cairo_fill (cr);
981 }
982
983 //
984
986 {
987 cairo_set_source_rgba (cr, _penColor.red()/255.0, _penColor.green()/255.0, _penColor.blue()/255.0, 1.);
988
989 cairo_set_line_width (cr, _lineWidth);
990 cairo_set_line_cap (cr, cairoLineCap[ButtCap]);
991 cairo_set_line_join (cr, cairoLineJoin[MiterJoin]);
993
994 cairo_stroke (cr);
995 }
996
997 cairo_restore (cr);
998}
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)
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, LibBoard::Shape::_penColor, LibBoard::Line::_x1, LibBoard::Line::_x2, LibBoard::Line::_y1, LibBoard::Line::_y2, DGtal::Color::blue(), LibBoard::Shape::ButtCap, LibBoard::Shape::filled(), DGtal::Color::green(), LibBoard::Shape::MiterJoin, DGtal::Color::None, DGtal::Color::red(), LibBoard::Shape::setCairoDashStyle(), and LibBoard::Shape::SolidStyle.

◆ flushFIG()

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

Reimplemented from LibBoard::Line.

Definition at line 847 of file Shapes.cpp.

850{
851 stream << "2 1 ";
852 // Line style
853 stream << _lineStyle << " ";
854 // Thickness
855 stream << ( _penColor.valid()?transform.mapWidth( _lineWidth ):0 ) << " ";
856 // Pen color
857 stream << colormap[ _penColor ] << " ";
858 // Fill color
859 stream << colormap[ _penColor ] << " ";
860 // Depth
861 stream << transform.mapDepth( _depth ) << " ";
862 // Pen style
863 stream << "-1 ";
864 // Area fill, style val, join style, cap style, radius, f_arrow, b_arrow
865 stream << "-1 " << (_lineStyle?"4.000 ":"0.000 ") << _lineJoin << " " << _lineCap << " -1 1 0 ";
866 // Number of points
867 stream << "2\n";
868 if ( filled() )
869 stream << " 1 1 1.00 60.00 120.00\n";
870 else
871 stream << " 1 0 1.00 60.00 120.00\n";
872 stream << " ";
873 stream << static_cast<int>( transform.mapX( _x1 ) ) << " "
874 << static_cast<int>( transform.mapY( _y1 ) ) << " "
875 << static_cast<int>( transform.mapX( _x2 ) ) << " "
876 << static_cast<int>( transform.mapY( _y2 ) ) << std::endl;
877}
bool valid() const

References LibBoard::Shape::_depth, LibBoard::Shape::_lineCap, LibBoard::Shape::_lineJoin, LibBoard::Shape::_lineStyle, LibBoard::Shape::_lineWidth, LibBoard::Shape::_penColor, LibBoard::Line::_x1, LibBoard::Line::_x2, LibBoard::Line::_y1, LibBoard::Line::_y2, LibBoard::Shape::filled(), and DGtal::Color::valid().

◆ flushPostscript()

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

Definition at line 793 of file Shapes.cpp.

795{
796 double dx = _x1 - _x2;
797 double dy = _y1 - _y2;
798 double norm = sqrt( dx*dx + dy*dy );
799 dx /= norm;
800 dy /= norm;
801 dx *= 10*_lineWidth;
802 dy *= 10*_lineWidth;
803
804 // double back_x = 0.8 * dx + _x2;
805 // double back_y = 0.8 * dy + _y2;
806
807 double ndx1 = dx*cos(0.3)-dy*sin(0.3);
808 double ndy1 = dx*sin(0.3)+dy*cos(0.3);
809 double ndx2 = dx*cos(-0.3)-dy*sin(-0.3);
810 double ndy2 = dx*sin(-0.3)+dy*cos(-0.3);
811
812 stream << "\n% Arrow\n";
813 stream << _penColor.postscript() << " srgb "
814 << postscriptProperties() << " "
815 << "n "
816 << transform.mapX( _x1 ) << " "
817 << transform.mapY( _y1 ) << " "
818 << "m "
819 << transform.mapX( _x2 + ( dx * cos(0.3) ) ) << " "
820 << transform.mapY( _y2 + ( dy * cos(0.3) ) ) << " "
821 << "l stroke" << std::endl;
822
823 if ( filled() ) {
824 stream << "n "
825 << transform.mapX( _x2 ) + transform.scale( ndx1 ) << " "
826 << transform.mapY( _y2 ) + transform.scale( ndy1 ) << " "
827 << "m "
828 << transform.mapX( _x2 ) << " "
829 << transform.mapY( _y2 ) << " l "
830 << transform.mapX( _x2 ) + transform.scale( ndx2 ) << " "
831 << transform.mapY( _y2 ) + transform.scale( ndy2 ) << " ";
832 stream << "l cp " << _penColor.postscript() << " srgb fill" << std::endl;
833 }
834
835 stream << "n "
836 << transform.mapX( _x2 ) + transform.scale( ndx1 ) << " "
837 << transform.mapY( _y2 ) + transform.scale( ndy1 ) << " "
838 << "m "
839 << transform.mapX( _x2 ) << " "
840 << transform.mapY( _y2 ) << " l "
841 << transform.mapX( _x2 ) + transform.scale( ndx2 ) << " "
842 << transform.mapY( _y2 ) + transform.scale( ndy2 ) << " l"
843 << " " << _penColor.postscript() << " srgb cp [] 0 sd stroke" << std::endl;
844}
std::string postscript() const
Definition: Color.cpp:150
std::string postscriptProperties() const
Definition: Shapes.cpp:140

References LibBoard::Shape::_lineWidth, LibBoard::Shape::_penColor, LibBoard::Line::_x1, LibBoard::Line::_x2, LibBoard::Line::_y1, LibBoard::Line::_y2, LibBoard::Shape::filled(), DGtal::Color::postscript(), and LibBoard::Shape::postscriptProperties().

◆ flushSVG()

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

Definition at line 880 of file Shapes.cpp.

882{
883 double dx = _x1 - _x2;
884 double dy = _y1 - _y2;
885 double norm = sqrt( dx*dx + dy*dy );
886 dx /= norm;
887 dy /= norm;
888 dx *= 10 * _lineWidth;
889 dy *= 10 * _lineWidth;
890
891 // double back_x = 0.8 * dx + _x2;
892 // double back_y = 0.8 * dy + _y2;
893
894 double ndx1 = dx*cos(0.3)-dy*sin(0.3);
895 double ndy1 = dx*sin(0.3)+dy*cos(0.3);
896 double ndx2 = dx*cos(-0.3)-dy*sin(-0.3);
897 double ndy2 = dx*sin(-0.3)+dy*cos(-0.3);
898
899 stream << "<g>" << std::endl;
900 // The line
901 stream << " <path "
902 << "d=\"M " << transform.mapX( _x1 ) << " " << transform.mapY( _y1 )
903 << " L " << transform.mapX( _x2 + ( dx * cos(0.3) ) )
904 << " " << transform.mapY( _y2 + ( dy * cos(0.3) ) ) << " z\""
905 << " fill=\"none\" stroke=\"" << _penColor.svg() << "\""
906 << _penColor.svgAlpha( " stroke" );
907 if ( _lineStyle != SolidStyle )
908 stream << " style=\"" << xFigDashStylesSVG[ _lineStyle ] << '"';
909 stream << " stroke-width=\"" << transform.mapWidth( _lineWidth ) << "mm\" />";
910
911 // The arrow
912 stream << " <polygon";
913 stream << " fill=\"" << _fillColor.svg() << "\"";
914 stream << " stroke=\"" << _penColor.svg() << "\""
915 << " stroke-width=\"" << transform.mapWidth( /* 0.33 * */ _lineWidth ) << "mm\""
916 << " style=\"stroke-linecap:butt;stroke-linejoin:miter\""
917 << _fillColor.svgAlpha( " fill" )
918 << _penColor.svgAlpha( " stroke" )
919 << " points=\""
920 << transform.mapX( _x2 ) + transform.scale( ndx1 ) << ","
921 << transform.mapY( _y2 ) - transform.scale( ndy1 ) << " "
922 << transform.mapX( _x2 ) << ","
923 << transform.mapY( _y2 ) << " "
924 << transform.mapX( _x2 ) + transform.scale( ndx2 ) << ","
925 << transform.mapY( _y2 ) - transform.scale( ndy2 ) << " "
926 << transform.mapX( _x2 ) + transform.scale( ndx1 ) << ","
927 << transform.mapY( _y2 ) - transform.scale( ndy1 ) << "\" />" << std::endl;
928 stream << "</g>" << std::endl;
929}
std::string svg() const
Definition: Color.cpp:158
std::string svgAlpha(const char *aPrefix) const
Definition: Color.cpp:167

References LibBoard::Shape::_fillColor, LibBoard::Shape::_lineStyle, LibBoard::Shape::_lineWidth, LibBoard::Shape::_penColor, LibBoard::Line::_x1, LibBoard::Line::_x2, LibBoard::Line::_y1, LibBoard::Line::_y2, LibBoard::Shape::SolidStyle, DGtal::Color::svg(), and DGtal::Color::svgAlpha().

◆ flushTikZ()

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

Definition at line 1002 of file Shapes.cpp.

1004{
1005 //stream << "\\path[-triangle 45," << tikzProperties(transform) << "] (" // Requires \usetikzlibrary{arrows}
1006 stream << "\\path[-latex," << tikzProperties(transform) << "] ("
1007 << transform.mapX( _x1 ) << ',' << transform.mapY( _y1 )
1008 << ") -- ("
1009 << transform.mapX( _x2 ) << ',' << transform.mapY( _y2 )
1010 << ");" << std::endl;
1011}
std::string tikzProperties(const TransformTikZ &transform) const
Definition: Shapes.cpp:177

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

◆ name()

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

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

Returns
object name

Reimplemented from LibBoard::Line.

Definition at line 733 of file Shapes.cpp.

734{
735 return _name;
736}
static const std::string _name
Definition: Board/Shapes.h:758

References _name.

◆ rotated() [1/2]

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

Returns a copy of the arrow, 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 748 of file Shapes.cpp.

749{
750 Arrow res(*this);
751 Point c = center();
752 Point( _x1, _y1 ).rotate( angle, c ).get( res._x1, res._y1 );
753 Point( _x2, _y2 ).rotate( angle, c ).get( res._x2, res._y2 );
754 return res;
755}
Point center() const
Definition: Shapes.cpp:402
MyPointD Point
Definition: testClone2.cpp:383

References LibBoard::Line::_x1, LibBoard::Line::_x2, LibBoard::Line::_y1, LibBoard::Line::_y2, LibBoard::Line::center(), LibBoard::Point::get(), and LibBoard::Point::rotate().

◆ rotated() [2/2]

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

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

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

Definition at line 739 of file Shapes.cpp.

740{
741 Arrow res(*this);
742 Point( _x1, _y1 ).rotate( angle, rotCenter ).get( res._x1, res._y1 );
743 Point( _x2, _y2 ).rotate( angle, rotCenter ).get( res._x2, res._y2 );
744 return res;
745}

References LibBoard::Line::_x1, LibBoard::Line::_x2, LibBoard::Line::_y1, LibBoard::Line::_y2, LibBoard::Point::get(), and LibBoard::Point::rotate().

◆ scaled() [1/2]

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

Definition at line 782 of file Shapes.cpp.

783{
784 return Arrow::scaled( s, s );
785}
Arrow scaled(double sx, double sy) const
Definition: Shapes.cpp:769

References scaled().

◆ scaled() [2/2]

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

Returns a scaled copy of the arrow.

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

Definition at line 769 of file Shapes.cpp.

770{
771 Arrow res(*this);
772 Point c = center();
773 res._x1 *= sx;
774 res._x2 *= sx;
775 res._y1 *= sy;
776 res._y2 *= sy;
777 Point delta = c - res.center();
778 return static_cast<Arrow &>( res.translate( delta.x, delta.y ) );
779}

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

Referenced by scaled().

◆ translated()

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

Returns a translated copy of the arrow.

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

Definition at line 758 of file Shapes.cpp.

759{
760 Arrow res(*this);
761 res._x1 += dx;
762 res._x2 += dx;
763 res._y1 += dy;
764 res._y2 += dy;
765 return res;
766}

Field Documentation

◆ _name

const std::string LibBoard::Arrow::_name
staticprivate

The generic name of the shape.

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

Referenced by name().


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