13#include "Board/Rect.h"
14#include "Board/Shapes.h"
15#include "Board/Tools.h"
16#include "Board/PSFonts.h"
25#define M_PI 3.14159265358979323846
34const char * xFigDashStylesPS[] = {
38 " [4.5 2.3 1.5 2.3] 0 sd ",
39 " [4.5 2.0 1.5 1.5 1.5 2.0] 0 sd ",
40 " [4.5 1.8 1.5 1.4 1.5 1.4 1.5 1.8 ] 0 sd "
43const char * xFigDashStylesSVG[] = {
45 "stroke-dasharray:1,1;stroke-dashoffset:0",
46 "stroke-dasharray:1.5,4.5;stroke-dashoffset:45",
47 "stroke-dasharray:4.5,2.3,1.5,2.3;stroke-dashoffset:0",
48 "stroke-dasharray:4.5,2.0,1.5,1.5,1.5,2.0;stroke-dashoffset;0",
49 "stroke-dasharray:4.5,1.8,1.5,1.4,1.5,1.4,1.5,1.8;stroke-dashoffset:0"
52const char * xFigDashStylesTikZ[] = {
54 "dash pattern=on 1pt off 1pt,",
58 "dash pattern=on 2pt off 3pt on 4pt off 4pt,"
63cairo_line_cap_t cairoLineCap[] = {
69cairo_line_join_t cairoLineJoin[] = {
70 CAIRO_LINE_JOIN_MITER,
71 CAIRO_LINE_JOIN_ROUND,
75#define ARRAY_SIZE(A) (sizeof(A)/sizeof(A[0]))
77const double cairoSolidStyle[] = {1, 0};
const double cairoSolidStyle_offset = 0;
78const double cairoDashStyle[] = {1, 1};
const double cairoDashStyle_offset = 0;
79const double cairoDotStyle[] = {1.5, 4.5};
const double cairoDotStyle_offset = 45;
80const double cairoDashDotStyle[] = {4.5, 2.3, 1.5, 2.3};
const double cairoDashDotStyle_offset = 0;
81const double cairoDashDotDotStyle[] = {4.5, 2.0, 1.5, 1.5, 1.5, 2.0};
const double cairoDashDotDotStyle_offset = 0;
82const double cairoDashDotDotDotStyle[] = {4.5, 1.8, 1.5, 1.4, 1.5, 1.4, 1.5, 1.8};
const double cairoDashDotDotDotStyle_offset = 0;
100const std::string Shape::_name(
"AbstractShape");
111 static const char * capStrings[3] = {
"butt",
"round",
"square" };
112 static const char * joinStrings[3] = {
"miter",
"round",
"bevel" };
113 std::stringstream str;
117 <<
" stroke-width=\"" << transform.mapWidth(
_lineWidth ) <<
"mm\""
118 <<
" style=\"stroke-linecap:" << capStrings[
_lineCap ]
119 <<
";stroke-linejoin:" << joinStrings[
_lineJoin ];
121 str <<
";" << xFigDashStylesSVG[
_lineStyle ];
129 <<
" stroke=\"none\""
130 <<
" stroke-width=\"0\""
131 <<
" style=\"stroke-linecap:round;stroke-linejoin:round;"
140Shape::postscriptProperties()
const
142 std::stringstream str;
153Shape::setCairoDashStyle(cairo_t *cr,
LineStyle type)
const
158 cairo_set_dash (cr, cairoSolidStyle, ARRAY_SIZE(cairoSolidStyle), cairoSolidStyle_offset);
break;
160 cairo_set_dash (cr, cairoDashStyle, ARRAY_SIZE(cairoDashStyle), cairoDashStyle_offset);
break;
162 cairo_set_dash (cr, cairoDotStyle, ARRAY_SIZE(cairoDotStyle), cairoDotStyle_offset);
break;
164 cairo_set_dash (cr, cairoDashDotStyle, ARRAY_SIZE(cairoDashDotStyle), cairoDashDotStyle_offset);
break;
166 cairo_set_dash (cr, cairoDashDotDotStyle, ARRAY_SIZE(cairoDashDotDotStyle), cairoDashDotDotStyle_offset);
break;
168 cairo_set_dash (cr, cairoDashDotDotDotStyle, ARRAY_SIZE(cairoDashDotDotDotStyle), cairoDashDotDotDotStyle_offset);
break;
171 cairo_set_dash (cr, cairoSolidStyle, ARRAY_SIZE(cairoSolidStyle), cairoSolidStyle_offset);
179 static const char * capStrings[3] = {
"" ,
"line cap=round,",
"line cap=rect," };
180 static const char * joinStrings[3] = {
"" ,
"line join=round",
"line join=bevel" };
182 std::stringstream str;
185 str <<
"line width=" << transform.mapWidth(
_lineWidth ) <<
"mm,";
200Shape::shiftDepth(
int shift )
232 return Dot(*this).
rotate( angle, rotCenter );
296 stream <<
"\n% Dot\n";
299 << transform.mapX(
_x ) <<
" "
300 << transform.mapY(
_y ) <<
" "
302 << transform.mapX(
_x ) <<
" "
303 << transform.mapY(
_y ) <<
" "
310 std::map<DGtal::Color,int> & colormap )
const
320 stream << transform.mapDepth(
_depth ) <<
" ";
328 stream << static_cast<int>( transform.mapX(
_x ) ) <<
" "
329 <<
static_cast<int>( transform.mapY(
_y ) ) <<
" "
330 <<
static_cast<int>( transform.mapX(
_x ) ) <<
" "
331 <<
static_cast<int>( transform.mapY(
_y ) ) << std::endl;
338 stream <<
"<line x1=\"" << transform.mapX(
_x ) <<
"\""
339 <<
" y1=\"" << transform.mapY(
_y ) <<
"\""
340 <<
" x2=\"" << transform.mapX(
_x ) <<
"\""
341 <<
" y2=\"" << transform.mapY(
_y ) <<
"\""
343 <<
" />" << std::endl;
355 cairo_move_to (cr, transform.mapX(
_x ), transform.mapY(
_y ));
356 cairo_line_to (cr, transform.mapX(
_x ), transform.mapY(
_y ));
359 cairo_set_line_cap (cr, cairoLineCap[
_lineCap]);
360 cairo_set_line_join (cr, cairoLineJoin[
_lineJoin]);
375 stream <<
"% FIXME: Dot::flushTikZ unimplemented" << std::endl;
386 return new Dot(*
this);
424 Point(
_x1,
_y1 ).rotate( angle, rotCenter ).get( res._x1, res._y1 );
425 Point(
_x2,
_y2 ).rotate( angle, rotCenter ).get( res._x2, res._y2 );
434 Point(
_x1,
_y1 ).rotate( angle, c ).get( res._x1, res._y1 );
435 Point(
_x2,
_y2 ).rotate( angle, c ).get( res._x2, res._y2 );
489 Point delta = c - res.center();
490 return res.translate( delta.
x, delta.
y );
510 return new Line(*
this);
517 stream <<
"\n% Line\n";
520 << transform.mapX(
_x1 ) <<
" "
521 << transform.mapY(
_y1 ) <<
" "
523 << transform.mapX(
_x2 ) <<
" "
524 << transform.mapY(
_y2 ) <<
" "
531 std::map<DGtal::Color,int> & colormap )
const
543 stream << transform.mapDepth(
_depth ) <<
" ";
551 stream << static_cast<int>( transform.mapX(
_x1 ) ) <<
" "
552 <<
static_cast<int>( transform.mapY(
_y1 ) ) <<
" "
553 <<
static_cast<int>( transform.mapX(
_x2 ) ) <<
" "
554 <<
static_cast<int>( transform.mapY(
_y2 ) ) << std::endl;
561 stream <<
"<line x1=\"" << transform.mapX(
_x1 ) <<
"\""
562 <<
" y1=\"" << transform.mapY(
_y1 ) <<
"\""
563 <<
" x2=\"" << transform.mapX(
_x2 ) <<
"\""
564 <<
" y2=\"" << transform.mapY(
_y2 ) <<
"\""
566 <<
" />" << std::endl;
578 cairo_move_to (cr, transform.mapX(
_x1 ), transform.mapY(
_y1 ));
579 cairo_line_to (cr, transform.mapX(
_x2 ), transform.mapY(
_y2 ));
582 cairo_set_line_cap (cr, cairoLineCap[
_lineCap]);
583 cairo_set_line_join (cr, cairoLineJoin[
_lineJoin]);
597 << transform.mapX(
_x1 ) <<
',' << transform.mapY(
_y1 )
599 << transform.mapX(
_x2 ) <<
',' << transform.mapY(
_y2 )
600 <<
");" << std::endl;
630const std::string Image::_name(
"Image");
639Image::clone()
const {
640 return new Image(*
this);
644Image::flushFIG( std::ostream & stream,
646 std::map<DGtal::Color,int> & colormap )
const
659 stream << transform.mapDepth(
_depth ) <<
" "
660 <<
"-1 -1 0.000 0 0 -1 0 0 5" << std::endl <<
" 0 "
669Image::flushSVG( std::ostream & stream,
673 stream <<
"<image x=\"" << transform.mapX(
_path[0].x ) <<
'"'
674 <<
" y=\"" << transform.mapY(
_path[0].y ) <<
'"'
675 <<
" width=\"" << transform.scale( (
_path[1] -
_path[0]).norm() ) <<
'"'
676 <<
" height=\"" << transform.scale( (
_path[0] -
_path[3]).norm() ) <<
'"'
677 <<
" xlink:href=\""<<
_filename <<
"\" >" << std::endl
678 <<
" <title>My image</title>"<<std::endl
679 <<
" </image>" << std::endl;
686Image::flushCairo( cairo_t *cr,
690 cairo_surface_t *image;
693 ASSERT(extension==
"png");
694 image = cairo_image_surface_create_from_png (
_filename.c_str());
695 assert(cairo_surface_status (image) == CAIRO_STATUS_SUCCESS);
696 w = cairo_image_surface_get_width (image);
697 h = cairo_image_surface_get_height (image);
700 cairo_translate (cr, transform.mapX(
_path[0].x ), transform.mapY(
_path[0].y ));
702 cairo_scale (cr, transform.scale( (
_path[1] -
_path[0]).norm() )/w, transform.scale( (
_path[0] -
_path[3]).norm() )/h);
705 cairo_set_source_surface (cr, image, 0, 0);
706 cairo_paint_with_alpha(cr,
_alpha);
707 cairo_surface_destroy (image);
714Image::flushTikZ( std::ostream & stream,
718 stream <<
"\\node [below right=0pt] at ("
719 << transform.mapX(
_path[0].x ) <<
"pt,"
720 << transform.mapY(
_path[0].y ) <<
"pt) {\\pgfimage["
721 <<
"width=" << transform.scale( (
_path[1] -
_path[0]).norm() ) <<
"pt,"
722 <<
"height=" << transform.scale( (
_path[0] -
_path[3]).norm() ) <<
"pt,"
723 <<
"]{" <<
_filename <<
"}};" << std::endl;
742 Point(
_x1,
_y1 ).rotate( angle, rotCenter ).get( res._x1, res._y1 );
743 Point(
_x2,
_y2 ).rotate( angle, rotCenter ).get( res._x2, res._y2 );
752 Point(
_x1,
_y1 ).rotate( angle, c ).get( res._x1, res._y1 );
753 Point(
_x2,
_y2 ).rotate( angle, c ).get( res._x2, res._y2 );
777 Point delta = c - res.center();
778 return static_cast<Arrow &
>( res.translate( delta.
x, delta.
y ) );
789 return new Arrow(*
this);
798 double norm = sqrt( dx*dx + dy*dy );
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);
812 stream <<
"\n% Arrow\n";
816 << transform.mapX(
_x1 ) <<
" "
817 << transform.mapY(
_y1 ) <<
" "
819 << transform.mapX(
_x2 + ( dx * cos(0.3) ) ) <<
" "
820 << transform.mapY(
_y2 + ( dy * cos(0.3) ) ) <<
" "
821 <<
"l stroke" << std::endl;
825 << transform.mapX(
_x2 ) + transform.scale( ndx1 ) <<
" "
826 << transform.mapY(
_y2 ) + transform.scale( ndy1 ) <<
" "
828 << transform.mapX(
_x2 ) <<
" "
829 << transform.mapY(
_y2 ) <<
" l "
830 << transform.mapX(
_x2 ) + transform.scale( ndx2 ) <<
" "
831 << transform.mapY(
_y2 ) + transform.scale( ndy2 ) <<
" ";
836 << transform.mapX(
_x2 ) + transform.scale( ndx1 ) <<
" "
837 << transform.mapY(
_y2 ) + transform.scale( ndy1 ) <<
" "
839 << transform.mapX(
_x2 ) <<
" "
840 << transform.mapY(
_y2 ) <<
" l "
841 << transform.mapX(
_x2 ) + transform.scale( ndx2 ) <<
" "
842 << transform.mapY(
_y2 ) + transform.scale( ndy2 ) <<
" l"
849 std::map<DGtal::Color,int> & colormap )
const
861 stream << transform.mapDepth(
_depth ) <<
" ";
869 stream <<
" 1 1 1.00 60.00 120.00\n";
871 stream <<
" 1 0 1.00 60.00 120.00\n";
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;
885 double norm = sqrt( dx*dx + dy*dy );
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);
899 stream <<
"<g>" << std::endl;
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() <<
"\""
908 stream <<
" style=\"" << xFigDashStylesSVG[
_lineStyle ] <<
'"';
909 stream <<
" stroke-width=\"" << transform.mapWidth(
_lineWidth ) <<
"mm\" />";
912 stream <<
" <polygon";
915 <<
" stroke-width=\"" << transform.mapWidth(
_lineWidth ) <<
"mm\""
916 <<
" style=\"stroke-linecap:butt;stroke-linejoin:miter\""
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;
938 double norm = sqrt( dx*dx + dy*dy );
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);
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) ) ));
961 cairo_set_line_cap (cr, cairoLineCap[
_lineCap]);
962 cairo_set_line_join (cr, cairoLineJoin[
_lineJoin]);
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);
978 cairo_fill_preserve (cr);
990 cairo_set_line_cap (cr, cairoLineCap[
ButtCap]);
991 cairo_set_line_join (cr, cairoLineJoin[
MiterJoin]);
1007 << transform.mapX(
_x1 ) <<
',' << transform.mapY(
_y1 )
1009 << transform.mapX(
_x2 ) <<
',' << transform.mapY(
_y2 )
1010 <<
");" << std::endl;
1037 Point axis = re - rc;
1080 double co = cos(
_angle );
1081 double si = sin(
_angle );
1084 double m00 = ( 1 /
_xRadius ) * co;
1085 double m01 = ( 1 /
_xRadius ) * si;
1086 double m10 = - ( 1 /
_yRadius ) * si;
1087 double m11 = ( 1 /
_yRadius ) * co;
1091 double a = ( m00 * m00 ) + ( m10 * m10 );
1092 double b = 2 * ( ( m00 * m01 ) + ( m10 * m11 ) );
1093 double c = ( m01 * m01 ) + ( m11 * m11 );
1096 a = a / ( sx * sx );
1097 b = b / ( sx * sy );
1098 c = c / ( sy * sy );
1102 }
else if ( a == c ) {
1107 _angle = 0.5 * atan( b / ( a - c ) );
1108 double k = 1 + ( ( b * b ) / ( ( a - c ) * ( a - c ) ) );
1112 a = 0.5 * ( c + k );
1113 c = 0.5 * ( c - k );
1160 stream <<
"\n% Ellipse\n";
1163 << transform.mapX(
_center.
x ) <<
" " << transform.mapY(
_center.
y ) <<
" tr";
1164 if (
_angle != 0.0 ) stream <<
" " << (
_angle*180/M_PI) <<
" rot ";
1165 if ( !
_circle ) stream <<
" " << 1.0 <<
" " << yScale <<
" sc";
1166 stream <<
" n " << transform.scale(
_xRadius ) <<
" 0 m "
1167 <<
" 0 0 " << transform.scale(
_xRadius ) <<
" 0.0 360.0 arc ";
1169 stream <<
" fill gr" << std::endl;
1174 stream <<
"gs " << transform.mapX(
_center.
x ) <<
" " << transform.mapY(
_center.
y ) <<
" tr";
1175 if (
_angle != 0.0 ) stream <<
" " << (
_angle*180/M_PI) <<
" rot ";
1176 if ( !
_circle ) stream <<
" " << 1.0 <<
" " << yScale <<
" sc";
1177 stream <<
" n " << transform.scale(
_xRadius ) <<
" 0 m "
1178 <<
" 0 0 " << transform.scale(
_xRadius ) <<
" 0.0 360.0 arc ";
1180 stream <<
" stroke gr" << std::endl;
1187 std::map<DGtal::Color,int> & colormap )
const
1199 stream << transform.mapDepth(
_depth ) <<
" -1 20 " << (
_lineStyle?
"4.000 ":
"0.000 ") <<
" 1 " <<
_angle <<
" ";
1201 stream << transform.mapDepth(
_depth ) <<
" -1 -1 " << (
_lineStyle?
"4.000 ":
"0.000 ") <<
" 1 " <<
_angle <<
" ";
1202 stream << static_cast<int>( transform.mapX(
_center.
x ) ) <<
" "
1203 <<
static_cast<int>( transform.mapY(
_center.
y ) ) <<
" "
1204 <<
static_cast<int>( transform.scale(
_xRadius ) ) <<
" "
1205 <<
static_cast<int>( transform.scale(
_yRadius ) ) <<
" "
1206 <<
static_cast<int>( transform.mapX(
_center.
x ) ) <<
" "
1207 <<
static_cast<int>( transform.mapY(
_center.
y ) ) <<
" "
1208 <<
static_cast<int>( transform.mapX(
_center.
x ) + transform.scale(
_xRadius ) ) <<
" "
1209 <<
static_cast<int>( transform.mapY(
_center.
y ) ) <<
"\n";
1216 stream <<
"<ellipse cx=\"" << transform.mapX(
_center.
x ) <<
'"'
1217 <<
" cy=\"" << transform.mapY(
_center.
y ) <<
'"'
1218 <<
" rx=\"" << transform.scale(
_xRadius ) <<
'"'
1219 <<
" ry=\"" << transform.scale(
_yRadius ) <<
'"'
1222 stream <<
" transform=\"rotate( "
1223 << -(
_angle*180/M_PI) <<
", "
1224 << transform.mapX(
_center.
x ) <<
", "
1225 << transform.mapY(
_center.
y ) <<
" )\" ";
1227 stream <<
" />" << std::endl;
1240 cairo_translate (cr, transform.mapX(
_center.
x ), transform.mapY(
_center.
y ));
1242 cairo_rotate (cr,
_angle);
1243 cairo_scale (cr, transform.scale(
_xRadius ), transform.scale(
_yRadius ));
1246 cairo_arc (cr, 0, 0, 1, 0, 2*M_PI);
1251 cairo_fill_preserve (cr);
1263 cairo_set_line_cap (cr, cairoLineCap[
_lineCap]);
1264 cairo_set_line_join (cr, cairoLineJoin[
_lineJoin]);
1279 stream <<
"% FIXME: Ellipse::flushTikZ unimplemented" << std::endl;
1281 << transform.mapX(
_center.
x ) <<
','
1282 << transform.mapY(
_center.
y ) <<
')'
1283 <<
" circle [x radius=" << transform.scale(
_xRadius ) <<
','
1284 <<
"y radius=" << transform.scale(
_yRadius ) <<
','
1285 <<
"rotate=" << -(
_angle*180/M_PI)
1336 if ( rotCenter ==
_center )
return *
this;
1392 return static_cast<Circle &
>(
Circle(*this).scale( sx, sy ) );
1398 return static_cast<Circle &
>(
Circle(*this).scale( s, s ) );
1411 return new Circle(*
this);
1421 stream <<
"<circle cx=\"" << transform.mapX(
_center.
x ) <<
'"'
1422 <<
" cy=\"" << transform.mapY(
_center.
y ) <<
'"'
1423 <<
" r=\"" << transform.scale(
_xRadius ) <<
'"'
1425 <<
" />" << std::endl;
1447 cairo_fill_preserve (cr);
1459 cairo_set_line_cap (cr, cairoLineCap[
_lineCap]);
1460 cairo_set_line_join (cr, cairoLineJoin[
_lineJoin]);
1479 << transform.mapX(
_center.
x ) <<
','
1480 << transform.mapY(
_center.
y ) <<
')'
1481 <<
" circle (" << transform.scale(
_xRadius ) <<
");"
1515 cairo_fill_preserve (cr);
1527 cairo_set_line_cap (cr, cairoLineCap[
_lineCap]);
1528 cairo_set_line_join (cr, cairoLineJoin[
_lineJoin]);
1557 stream <<
"\n% Arc\n";
1560 << transform.mapX(
_center.
x ) <<
" " << transform.mapY(
_center.
y ) <<
" "
1561 << transform.scale(
_xRadius )<<
" " << (a1*180/M_PI) <<
" "
1562 << (a2*180/M_PI) <<
" "<<
"arc ";
1564 stream <<
" fill gr" << std::endl;
1570 << transform.mapX(
_center.
x ) <<
" " << transform.mapY(
_center.
y ) <<
" "
1571 << transform.scale(
_xRadius )<<
" " << (a1*180/M_PI) <<
" "
1572 << (a2*180/M_PI) <<
" "<<
"arc ";
1574 stream <<
" stroke gr" << std::endl;
1591stream <<
"d='M " << transform.mapX( fx );
1592stream <<
"," << transform.mapY( fy );
1594stream <<
" A " << transform.scale(
_xRadius ) <<
" " << transform.scale(
_xRadius );
1618stream <<
" " << transform.mapX( lx );
1619stream <<
"," << transform.mapY( ly );
1629 << transform.mapX(
_center.
x ) <<
',' << transform.mapY(
_center.
y ) <<
')'
1630 <<
" +(" << -
_angle1/M_PI*180. <<
':' << transform.scale(
_xRadius) <<
')'
1740 stream <<
"\n% Polyline\n";
1747 stream <<
" fill" << std::endl;
1755 stream <<
" stroke" << std::endl;
1762 std::map<DGtal::Color,int> & colormap )
const
1777 stream << transform.mapDepth(
_depth ) <<
" ";
1788 stream << std::endl;
1798 stream <<
"<polygon";
1800 stream <<
"<polyline";
1802 stream <<
" points=\"";
1804 stream <<
"\" />" << std::endl;
1821 cairo_close_path (cr);
1826 cairo_fill_preserve (cr);
1838 cairo_set_line_cap (cr, cairoLineCap[
_lineCap]);
1839 cairo_set_line_join (cr, cairoLineJoin[
_lineJoin]);
1862 stream <<
" -- cycle";
1863 stream <<
";" << std::endl;
1928 std::map<DGtal::Color,int> & colormap )
const
1943 if ( fabs(x1*x2 + y1*y2) > 0.01 ) {
1957 stream << transform.mapDepth(
_depth ) <<
" ";
1967 stream << std::endl;
1979 if ( fabs(x1*x2 + y1*y2) > 0.01 ) {
1986 stream <<
"<rect x=\"" << transform.mapX(
_path[0].x ) <<
'"'
1987 <<
" y=\"" << transform.mapY(
_path[0].y ) <<
'"'
1988 <<
" width=\"" << transform.scale(
_path[1].x -
_path[0].x ) <<
'"'
1989 <<
" height=\"" << transform.scale(
_path[0].y -
_path[3].y ) <<
'"'
1991 <<
" />" << std::endl;
1995 double angle = (
_path[1].y >
_path[0].y ) ? acos( v *
Point(1,0) ) : -acos( v *
Point( 1, 0 ) );
1996 angle = ( angle * 180 ) / M_PI;
1997 stream <<
"<rect x=\"" << transform.mapX(
_path[0].x ) <<
'"'
1998 <<
" y=\"" << transform.mapY(
_path[0].y ) <<
'"'
1999 <<
" width=\"" << transform.scale( (
_path[1] -
_path[0]).norm() ) <<
'"'
2000 <<
" height=\"" << transform.scale( (
_path[0] -
_path[3]).norm() ) <<
'"'
2002 <<
" transform=\"rotate(" << -angle <<
", "
2003 << transform.mapX(
_path[0].x ) <<
", " << transform.mapY(
_path[0].y ) <<
") \" "
2004 <<
" />" << std::endl;
2018 if ( fabs(x1*x2 + y1*y2) > 0.01 ) {
2029 cairo_rectangle (cr, transform.mapX(
_path[0].x ), transform.mapY(
_path[0].y ), transform.scale(
_path[1].x -
_path[0].x ), transform.scale(
_path[0].y -
_path[3].y ));
2034 double angle = (
_path[1].y >
_path[0].y ) ? acos( v *
Point(1,0) ) : -acos( v *
Point( 1, 0 ) );
2037 cairo_translate (cr, transform.mapX(
_path[0].x )+transform.scale(
_path[1].x -
_path[0].x )/2., transform.mapY(
_path[0].y )+transform.scale(
_path[0].y -
_path[3].y )/2.);
2038 cairo_rotate (cr, angle);
2041 cairo_rectangle (cr, -transform.scale(
_path[1].x -
_path[0].x )/2., -transform.scale(
_path[0].y -
_path[3].y )/2., transform.scale( (
_path[1] -
_path[0]).norm() ), transform.scale( (
_path[0] -
_path[3]).norm() ));
2047 cairo_fill_preserve (cr);
2059 cairo_set_line_cap (cr, cairoLineCap[
_lineCap]);
2060 cairo_set_line_join (cr, cairoLineJoin[
_lineJoin]);
2079 <<
" rectangle (" <<
_path[1].x <<
',' <<
_path[3].y <<
"); ";
2100 0.0f, SolidStyle, ButtCap, MiterJoin, depthValue ),
2101 _color0( color0 ), _color1( color1 ), _color2( color2 ), _subdivisions( subdivisions ) {
2106 Shape::_fillColor.red( ( color0.
red() + color1.
red() + color2.
red() ) / 3 );
2107 Shape::_fillColor.green( ( color0.
green() + color1.
green() + color2.
green() ) / 3 );
2108 Shape::_fillColor.blue( ( color0.
blue() + color1.
blue() + color2.
blue() ) / 3 );
2112 const Point & p1,
float brightness1,
2113 const Point & p2,
float brightness2,
2118 0.0f, SolidStyle, ButtCap, MiterJoin, depthValue ),
2119 _color0( fill ), _color1( fill ), _color2( fill ), _subdivisions( subdivisions )
2209 Point p01( 0.5*(p0.
x+p1.
x), 0.5*(p0.
y+p1.
y) );
2213 Point p12( 0.5*(p1.
x+p2.
x), 0.5*(p1.
y+p2.
y) );
2217 Point p20( 0.5*(p2.
x+p0.
x), 0.5*(p2.
y+p0.
y) );
2230 std::map<DGtal::Color,int> & colormap )
const
2275 Point p01( 0.5*(p0.
x+p1.
x), 0.5*(p0.
y+p1.
y) );
2279 Point p12( 0.5*(p1.
x+p2.
x), 0.5*(p1.
y+p2.
y) );
2283 Point p20( 0.5*(p2.
x+p0.
x), 0.5*(p2.
y+p0.
y) );
2310 stream <<
"% FIXME: GouraudTriangle::flushTikZ unimplemented" << std::endl;
2317const std::string Triangle::_name(
"Triangle");
2320Triangle::name()
const
2326Triangle::rotated(
double angle )
const
2332Triangle::translated(
double dx,
double dy )
const
2338Triangle::scaled(
double sx,
double sy )
const
2344Triangle::scaled(
double s )
const
2350Triangle::clone()
const {
2369 double x1, y1, x2, y2, x3, y3, x4, y4;
2370 _path[ 0 ].get(x1, y1);
2371 _path[ 1 ].get(x3, y3);
2372 _path[ 2 ].get(x4, y4);
2375 x2 = x1 + 2/3.0*(x3-x1);
2376 y2 = y1 + 2/3.0*(y3-y1);
2377 x3 = x2 + 1/3.0*(x4-x1);
2378 y3 = y2 + 1/3.0*(y4-y1);
2380 stream << std::endl <<
"% Bezier curve" << std::endl;
2383 << transform.mapX( x1 ) <<
" "
2384 << transform.mapY( y1 ) <<
" "
2386 << transform.mapX( x2 ) <<
" "
2387 << transform.mapY( y2 ) <<
" "
2388 << transform.mapX( x3 ) <<
" "
2389 << transform.mapY( y3 ) <<
" "
2390 << transform.mapX( x4 ) <<
" "
2391 << transform.mapY( y4 ) <<
" "
2395 stream <<
" fill" << std::endl;
2400 << transform.mapX( x1 ) <<
" "
2401 << transform.mapY( y1 ) <<
" "
2403 << transform.mapX( x2 ) <<
" "
2404 << transform.mapY( y2 ) <<
" "
2405 << transform.mapX( x3 ) <<
" "
2406 << transform.mapY( y3 ) <<
" "
2407 << transform.mapX( x4 ) <<
" "
2408 << transform.mapY( y4 ) <<
" "
2411 stream <<
" stroke" << std::endl;
2418 std::map<DGtal::Color,int> & colormap )
const
2420 stream <<
"#FIXME: quadratic Bezier curve unimplemented" << std::endl;
2421 Triangle::flushFIG(stream, transform, colormap);
2428 double x1, y1, x2, y2, x3, y3;
2429 _path[ 0 ].get(x1, y1);
2430 _path[ 1 ].get(x2, y2);
2431 _path[ 2 ].get(x3, y3);
2436 stream <<
"d='M " << transform.mapX( x1 );
2437 stream <<
"," << transform.mapY( y1 );
2439 stream <<
" Q " << transform.mapX( x2 ) <<
"," << transform.mapY( y2 );
2441 stream <<
" " << transform.mapX( x3 );
2442 stream <<
"," << transform.mapY( y3 );
2451 double x1, y1, x2, y2, x3, y3, x4, y4;
2452 _path[ 0 ].get(x1, y1);
2453 _path[ 1 ].get(x3, y3);
2454 _path[ 2 ].get(x4, y4);
2457 x2 = x1 + 2/3.0*(x3-x1);
2458 y2 = y1 + 2/3.0*(y3-y1);
2459 x3 = x2 + 1/3.0*(x4-x1);
2460 y3 = y2 + 1/3.0*(y4-y1);
2466 cairo_move_to( cr, transform.mapX( x1 ), transform.mapY( y1 ) );
2467 cairo_curve_to( cr, transform.mapX( x2 ), transform.mapY( y2 ),
2468 transform.mapX( x3 ), transform.mapY( y3 ),
2469 transform.mapX( x4 ), transform.mapY( y4 ) );
2474 cairo_fill_preserve (cr);
2484 cairo_set_line_cap (cr, cairoLineCap[
_lineCap]);
2485 cairo_set_line_join (cr, cairoLineJoin[
_lineJoin]);
2499 double x1, y1, x2, y2, x3, y3, x4, y4;
2500 _path[ 0 ].get(x1, y1);
2501 _path[ 1 ].get(x3, y3);
2502 _path[ 2 ].get(x4, y4);
2505 x2 = x1 + 2/3.0*(x3-x1);
2506 y2 = y1 + 2/3.0*(y3-y1);
2507 x3 = x2 + 1/3.0*(x4-x1);
2508 y3 = y2 + 1/3.0*(y4-y1);
2511 << transform.mapX( x1 ) <<
',' << transform.mapY( y1 )
2512 <<
") .. controls ("
2513 << transform.mapX( x2 ) <<
',' << transform.mapY( y2 )
2515 << transform.mapX( x3 ) <<
',' << transform.mapY( y3 )
2517 << transform.mapX( x4 ) <<
',' << transform.mapY( y4 )
2518 <<
");" << std::endl;
2544 endPos.
rotate( angle, rotCenter );
2547 if ( v.x >= 0 )
_angle = asin( v.y );
2548 else if ( v.y > 0 )
_angle = (M_PI/2.0) + acos( v.y );
2549 else _angle = (-M_PI/2.0) - acos( -v.y );
2556 return Text(*this).
rotate( angle, rotCenter );
2586 return static_cast<Text&
>(
Text(*this).translate( dx, dy ) );
2607 return static_cast<Text &
>(
Text(*this).scale( sx, sy ) );
2613 return static_cast<Text &
>(
Text(*this).scale( s, s ) );
2624 return new Text(*
this);
2631 stream <<
"\n% Text\n";
2633 stream <<
" " << transform.mapX(
_position.
x ) <<
" " << transform.mapY(
_position.
y ) <<
" m";
2634 if (
_angle != 0.0 ) stream <<
" " << (
_angle/M_PI)*180.0 <<
" rot ";
2635 stream <<
" (" <<
_text <<
")"
2637 <<
" sh gr" << std::endl;
2643 std::map<DGtal::Color,int> & colormap )
const
2647 stream << colormap[
_penColor ] <<
" " << transform.mapDepth(
_depth ) <<
" -1 " <<
_font <<
" ";
2651 stream << static_cast<int>(
_size * 135 / 12.0 ) <<
" ";
2653 stream << static_cast<int>(
_text.size() *
_size * 135 / 12.0 ) <<
" ";
2655 stream << static_cast<int>( transform.mapX(
_position.
x ) ) <<
" "
2656 <<
static_cast<int>( transform.mapY(
_position.
y ) ) <<
" ";
2657 stream <<
_text <<
"\\001\n";
2665 stream <<
"<g transform=\"translate("
2668 <<
"<g transform=\"rotate(" << (-
_angle*180.0/M_PI) <<
")\" >"
2669 <<
"<text x=\"0\" y=\"0\""
2671 <<
" font-size=\"" <<
_size <<
"\""
2677 <<
"</text></g></g>" << std::endl;
2679 stream <<
"<text x=\"" << transform.mapX(
_position.
x )
2680 <<
"\" y=\"" << transform.mapY(
_position.
y ) <<
"\" "
2682 <<
" font-size=\"" <<
_size <<
"\""
2688 <<
"</text>" << std::endl;
2705#define BOLD_FONT 0x01
2706#define ITALIC_FONT 0x02
2707#define MONOSPACE_FONT 0x04
2708#define SANSSERIF_FONT 0x08
2709 char fontTraits[] = {
2713 BOLD_FONT | ITALIC_FONT,
2715 SANSSERIF_FONT | ITALIC_FONT,
2717 SANSSERIF_FONT | ITALIC_FONT,
2723 MONOSPACE_FONT | ITALIC_FONT,
2724 MONOSPACE_FONT | BOLD_FONT,
2725 MONOSPACE_FONT | BOLD_FONT | ITALIC_FONT,
2727 SANSSERIF_FONT | ITALIC_FONT,
2728 SANSSERIF_FONT | BOLD_FONT,
2729 SANSSERIF_FONT | BOLD_FONT | ITALIC_FONT,
2731 SANSSERIF_FONT | ITALIC_FONT,
2732 SANSSERIF_FONT | BOLD_FONT,
2733 SANSSERIF_FONT | BOLD_FONT | ITALIC_FONT,
2737 BOLD_FONT | ITALIC_FONT,
2741 BOLD_FONT | ITALIC_FONT,
2750 << (fontTraits[
_font ] & ITALIC_FONT ?
"\\itshape " :
"")
2751 << (fontTraits[
_font ] & BOLD_FONT ?
"\\bfseries " :
"")
2752 << (fontTraits[
_font ] & MONOSPACE_FONT ?
"\\ttfamily " :
"")
2753 << (fontTraits[
_font ] & SANSSERIF_FONT ?
"\\sffamily " :
"")
2755 <<
"};" << std::endl;
Structure representing an RGB triple with alpha component.
std::string postscript() const
void flushPostscript(std::ostream &) const
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
std::string svgAlpha(const char *aPrefix) const
void blue(const unsigned char aBlueValue)
DGtal is the top-level namespace which contains all DGtal functions and types.
bool shapeGreaterDepth(const Shape *s1, const Shape *s2)
const char * XFigPostscriptFontnames[]
const char * PSFontNames[]
static const std::string _name
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
const std::string & name() const
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
A line between two points with an arrow at one extremity.
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)
Arrow translated(double dx, double dy) const
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
static const std::string _name
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Arrow rotated(double angle, const Point ¢er) const
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Arrow scaled(double sx, double sy) const
const std::string & name() const
const std::string & name() const
Circle & translate(double dx, double dy)
Circle rotated(double angle, const Point ¢er) const
static const std::string _name
Circle & rotate(double angle, const Point ¢er)
Circle translated(double dx, double dy) const
Shape & scale(double sx, double sy)
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Circle(double x, double y, double radius, DGtal::Color pen, DGtal::Color fill, double lineWidth, const LineStyle style=SolidStyle, int depthValue=-1)
Circle scaled(double sx, double sy) const
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
A line between two points.
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Dot(double x, double y, DGtal::Color color, double lineWidth, int depth=-1)
Dot scaled(double sx, double sy) const
Dot & rotate(double angle, const Point ¢er)
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Dot translated(double dx, double dy) const
static const std::string _name
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Dot & translate(double dx, double dy)
Shape & scale(double sx, double sy)
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
const std::string & name() const
Dot rotated(double angle, const Point ¢er) const
static const std::string _name
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Shape & scale(double sx, double sy)
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
const std::string & name() const
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Ellipse & rotate(double angle, const Point ¢er)
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 scaled(double sx, double sy) const
Ellipse rotated(double angle, const Point ¢er) const
Ellipse & translate(double dx, double dy)
Ellipse translated(double dx, double dy) const
A triangle with shaded filling according to colors given for each vertex.
GouraudTriangle * clone() const
GouraudTriangle rotated(double angle, const Point ¢er) const
GouraudTriangle scaled(double sx, double sy) const
GouraudTriangle & rotate(double angle, const Point ¢er)
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
GouraudTriangle translated(double dx, double dy) const
GouraudTriangle(const Point &p0, const DGtal::Color &color0, const Point &p1, const DGtal::Color &color1, const Point &p2, const DGtal::Color &color2, int subdivisions, int depth=-1)
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
const std::string & name() const
static const std::string _name
Used to draw image in figure.
static const std::string _name
A line between two points.
Line & rotate(double angle, const Point ¢er)
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)
Line rotated(double angle, const Point ¢er) const
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Line translated(double dx, double dy) const
Line & translate(double dx, double dy)
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Shape & scale(double sx, double sy)
static const std::string _name
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
const std::string & name() const
Line scaled(double sx, double sy) const
unsigned int size() const
void flushCairoPoints(cairo_t *cr, const TransformCairo &transform) const
Path & scale(double sx, double sy)
void flushFIG(std::ostream &stream, const TransformFIG &transform) const
void flushSVGPoints(std::ostream &stream, const TransformSVG &transform) const
Path & translate(double dx, double dy)
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
void flushTikZPoints(std::ostream &stream, const TransformTikZ &transform) const
Path & rotate(double angle, const Point ¢er)
Struct representing a 2D point.
Point rotated(double angle) const
Point & rotate(double angle)
A polygonal line described by a series of 2D points.
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Polyline rotated(double angle, const Point ¢er) const
const std::string & name() const
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Shape & scale(double sx, double sy)
Polyline & operator<<(const Point &p)
Polyline translated(double dx, double dy) const
Polyline & rotate(double angle, const Point ¢er)
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 flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Polyline & translate(double dx, double dy)
Polyline scaled(double sx, double sy) const
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
static const std::string _name
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
const std::string & name() const
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
static const std::string _name
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Struct representing a rectangle on the plane.
Rectangle rotated(double angle, const Point ¢er) const
Rectangle scaled(double sx, double sy) const
Rectangle(double x, double y, double width, double height, DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
Rectangle translated(double dx, double dy) const
Rectangle * clone() const
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
const std::string & name() const
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
static const std::string _name
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Abstract structure for a 2D shape.
std::string svgProperties(const TransformSVG &transform) const
std::string postscriptProperties() const
std::string tikzProperties(const TransformTikZ &transform) const
static const std::string _name
void setCairoDashStyle(cairo_t *cr, LineStyle type) const
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Text & translate(double dx, double dy)
Text(double x, double y, const std::string &text, const Fonts::Font font, double size, DGtal::Color color=DGtal::Color::Black, int depthValue=-1)
Text scaled(double sx, double sy) const
const std::string & name() const
static const std::string _name
Text translated(double dx, double dy) const
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Text rotated(double angle, const Point ¢er) const
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Text & rotate(double angle, const Point ¢er)
Shape & scale(double sx, double sy)
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
A triangle. Basically a Polyline with a convenient constructor.
static const std::string _name
HalfEdgeDataStructure::Triangle Triangle
ImageContainerBySTLVector< Domain, Value > Image