DGtal  1.5.beta
Board/Shapes.h
1 /* -*- mode: c++ -*- */
9 /*
10  * \@copyright This File is part of the Board library which is
11  * licensed under the terms of the GNU Lesser General Public Licence.
12  * See the LICENCE file for further details.
13  */
14 #ifndef _BOARD_SHAPES_H_
15 #define _BOARD_SHAPES_H_
16 
17 #include "Board/Point.h"
18 #include "Board/Rect.h"
19 #include "Board/Path.h"
20 #include "Board/Transforms.h"
21 #include "Board/PSFonts.h"
22 #include "Board/Tools.h"
23 #include <string>
24 #include <vector>
25 #include <iostream>
26 #include <map>
27 #include <cmath>
28 
29 #include "DGtal/io/Color.h"
30 
31 #ifdef WITH_CAIRO
32 // cairo
33 #if defined(__clang__)
34 #pragma clang diagnostic push
35 #pragma clang diagnostic ignored "-Wdocumentation"
36 #endif
37 #include <cairo.h>
38 #if defined(__clang__)
39 #pragma clang diagnostic pop
40 #endif
41 #endif
42 
43 #ifndef M_PI
44 #define M_PI 3.14159265358979323846
45 #endif
46 
47 #ifndef M_PI_2
48 #define M_PI_2 1.57079632679489661923
49 #endif
50 
51 namespace LibBoard {
52 
53 
58 struct Shape {
59 
62  enum LineStyle { SolidStyle = 0,
68 
81  double lineWidth,
82  LineStyle style,
83  const LineCap cap,
84  const LineJoin join,
85  int depth );
86 
90  virtual ~Shape() { }
91 
97  virtual const std::string & name() const;
98 
104  virtual Shape * clone() const = 0;
105 
111  inline bool filled() const { return _fillColor != DGtal::Color::None; }
112 
118  virtual Point center() const = 0;
119 
128  virtual Shape & rotate( double angle, const Point & center ) = 0;
129 
137  virtual Shape & rotate( double angle ) = 0;
138 
147  inline Shape & rotateDeg( double angle, const Point & center );
148 
156  inline Shape & rotateDeg( double angle );
157 
166  virtual Shape & translate( double dx, double dy ) = 0;
167 
176  virtual Shape & scale( double sx, double sy ) = 0;
177 
185  virtual Shape & scale( double s ) = 0;
186 
192  virtual Rect boundingBox() const = 0;
193 
194 
199  inline Rect bbox();
200 
201 
207  inline Shape & operator--();
208 
214  inline Shape & operator++();
215 
216 
223  virtual void scaleAll( double s ) = 0;
224 
225 
233  virtual void flushPostscript( std::ostream & stream,
234  const TransformEPS & transform ) const = 0;
235 
244  virtual void flushFIG( std::ostream & stream,
245  const TransformFIG & transform,
246  std::map<DGtal::Color,int> & colormap ) const = 0;
247 
255  virtual void flushSVG( std::ostream & stream,
256  const TransformSVG & transform ) const = 0;
257 
258 #ifdef WITH_CAIRO
266  virtual void flushCairo( cairo_t *cr,
267  const TransformCairo & transform ) const = 0;
268 #endif
269 
277  virtual void flushTikZ( std::ostream & stream,
278  const TransformTikZ & transform ) const = 0;
279 
280  inline int depth() const;
281 
282  virtual void depth( int );
283 
284  virtual void shiftDepth( int shift );
285 
286  inline const DGtal::Color & penColor() const;
287 
288  inline const DGtal::Color & fillColor() const;
289 
290 private:
291  static const std::string _name;
293 protected:
294 
295  int _depth;
298  double _lineWidth;
309  std::string svgProperties( const TransformSVG & transform ) const;
310 
311 
317  std::string postscriptProperties() const;
318 
319 #ifdef WITH_CAIRO
320  // cairo
326  void setCairoDashStyle(cairo_t *cr, LineStyle type) const;
327 #endif
328 
334  std::string tikzProperties( const TransformTikZ & transform ) const;
335 };
336 
337 
338 inline Rect
340 {
341  return this->boundingBox();
342 }
343 
344 
345 inline Shape &
347 {
348  ++_depth;
349  return *this;
350 }
351 
352 inline Shape &
354 {
355  --_depth;
356  return *this;
357 }
358 
359 
360 inline int
362 {
363  return _depth;
364 }
365 
366 inline const DGtal::Color &
368 {
369  return _penColor;
370 }
371 
372 const DGtal::Color &
374 {
375  return _fillColor;
376 }
377 
378 Shape &
379 Shape::rotateDeg( double angle, const Point & aCenter )
380 {
381  return rotate( angle * ( M_PI / 180.0 ), aCenter );
382 }
383 
384 Shape &
385 Shape::rotateDeg( double angle )
386 {
387  return rotate( angle * ( M_PI / 180.0 ), center() );
388 }
389 
398 struct Dot : public Shape {
399 
400  inline Dot( double x, double y,
401  DGtal::Color color,
402  double lineWidth,
403  int depth = -1 );
404 
410  const std::string & name() const;
411 
412  Point center() const;
413 
422  Dot & rotate( double angle, const Point & center );
423 
432  Dot rotated( double angle, const Point & center ) const;
433 
441  Dot & rotate( double angle );
442 
450  Dot rotated( double angle ) const;
451 
460  Dot & translate( double dx, double dy );
461 
470  Dot translated( double dx, double dy ) const;
471 
472  Shape & scale( double sx, double sy );
473 
474  Shape & scale( double s );
475 
486  Dot scaled( double sx, double sy ) const;
487 
488  Dot scaled( double s ) const;
489 
496  void scaleAll( double s );
497 
498  void flushPostscript( std::ostream & stream,
499  const TransformEPS & transform ) const;
500 
501  void flushFIG( std::ostream & stream,
502  const TransformFIG & transform,
503  std::map<DGtal::Color,int> & colormap ) const;
504 
505  void flushSVG( std::ostream & stream,
506  const TransformSVG & transform ) const;
507 
508 #ifdef WITH_CAIRO
509  void flushCairo( cairo_t *cr,
510  const TransformCairo & transform ) const;
511 #endif
512 
513  void flushTikZ( std::ostream & stream,
514  const TransformTikZ & transform ) const;
515 
516  Rect boundingBox() const;
517 
518  Dot * clone() const;
519 
520 private:
521  static const std::string _name;
523 protected:
524  double _x;
525  double _y;
526 };
527 
528 
529 
534 struct Line : public Shape {
535 
550  inline Line( double x1, double y1, double x2, double y2,
551  DGtal::Color color,
552  double lineWidth,
553  const LineStyle style = SolidStyle,
554  const LineCap cap = ButtCap,
555  const LineJoin join = MiterJoin,
556  int depth = -1 );
557 
563  const std::string & name() const;
564 
565  Point center() const;
566 
567  Line & rotate( double angle, const Point & center );
568 
577  Line rotated( double angle, const Point & center ) const;
578 
579  Line & rotate( double angle );
580 
588  Line rotated( double angle ) const;
589 
590  Line & translate( double dx, double dy );
591 
600  Line translated( double dx, double dy ) const;
601 
602  Shape & scale( double sx, double sy );
603 
604  Shape & scale( double s );
605 
614  Line scaled( double sx, double sy ) const;
615 
616  Line scaled( double s ) const;
617 
624  void scaleAll( double s );
625 
626  void flushPostscript( std::ostream & stream,
627  const TransformEPS & transform ) const;
628 
629  void flushFIG( std::ostream & stream,
630  const TransformFIG & transform,
631  std::map<DGtal::Color,int> & colormap ) const;
632 
633  void flushSVG( std::ostream & stream,
634  const TransformSVG & transform ) const;
635 
636 #ifdef WITH_CAIRO
637  void flushCairo( cairo_t *cr,
638  const TransformCairo & transform ) const;
639 #endif
640 
641  void flushTikZ( std::ostream & stream,
642  const TransformTikZ & transform ) const;
643 
644  Rect boundingBox() const;
645 
646  Line * clone() const;
647 
648 private:
649  static const std::string _name;
651 protected:
652  double _x1;
653  double _y1;
654  double _x2;
655  double _y2;
656 };
657 
658 
659 
660 
665 struct Arrow : public Line {
666 
682  inline Arrow( double x1, double y1, double x2, double y2,
684  double lineWidth,
685  const LineStyle style = SolidStyle,
686  const LineCap cap = ButtCap,
687  const LineJoin join = MiterJoin,
688  int depth = -1 );
689 
695  const std::string & name() const;
696 
705  Arrow rotated( double angle, const Point & center ) const;
706 
714  Arrow rotated( double angle ) const;
715 
724  Arrow translated( double dx, double dy ) const;
725 
734  Arrow scaled( double sx, double sy ) const;
735 
736  Arrow scaled( double s ) const;
737 
738  void flushPostscript( std::ostream & stream,
739  const TransformEPS & transform ) const;
740 
741  void flushFIG( std::ostream & stream,
742  const TransformFIG & transform,
743  std::map<DGtal::Color,int> & colormap ) const;
744  void flushSVG( std::ostream & stream,
745  const TransformSVG & transform ) const;
746 
747 #ifdef WITH_CAIRO
748  void flushCairo( cairo_t *cr,
749  const TransformCairo & transform ) const;
750 #endif
751 
752  void flushTikZ( std::ostream & stream,
753  const TransformTikZ & transform ) const;
754 
755  Arrow * clone() const;
756 
757 private:
758  static const std::string _name;
759 };
760 
765 struct Polyline : public Shape {
766  inline Polyline( const std::vector<Point> & points,
767  bool closed,
769  double lineWidth,
770  const LineStyle lineStyle = SolidStyle,
771  const LineCap cap = ButtCap,
772  const LineJoin join = MiterJoin,
773  int depth = -1 );
774 
775  inline Polyline( const Path & path,
777  double lineWidth,
778  const LineStyle lineStyle = SolidStyle,
779  const LineCap cap = ButtCap,
780  const LineJoin join = MiterJoin,
781  int depth = -1 );
782 
784  double lineWidth,
785  const LineStyle lineStyle = SolidStyle,
786  const LineCap cap = ButtCap,
787  const LineJoin join = MiterJoin,
788  int depth = -1 );
789 
795  const std::string & name() const;
796 
797  Point center() const;
798 
806  Polyline & operator<<( const Point & p );
807 
815  Point & operator[]( const unsigned int n ) {
816  return _path[ n ];
817  }
818 
819 
820  Polyline & rotate( double angle, const Point & center );
821 
830  Polyline rotated( double angle, const Point & center ) const;
831 
832  Polyline & rotate( double angle );
833 
841  Polyline rotated( double angle ) const;
842 
843  Polyline & translate( double dx, double dy );
844 
853  Polyline translated( double dx, double dy ) const;
854 
855  Shape & scale( double sx, double sy );
856 
857  Shape & scale( double s );
858 
867  Polyline scaled( double sx, double sy ) const;
868 
869  Polyline scaled( double s ) const;
870 
877  void scaleAll( double s );
878 
879  void flushPostscript( std::ostream & stream,
880  const TransformEPS & transform ) const;
881 
882  void flushFIG( std::ostream & stream,
883  const TransformFIG & transform,
884  std::map<DGtal::Color,int> & colormap ) const;
885 
886  void flushSVG( std::ostream & stream,
887  const TransformSVG & transform ) const;
888 
889 #ifdef WITH_CAIRO
890  void flushCairo( cairo_t *cr,
891  const TransformCairo & transform ) const;
892 #endif
893 
894  void flushTikZ( std::ostream & stream,
895  const TransformTikZ & transform ) const;
896 
897  Rect boundingBox() const;
898 
899  Polyline * clone() const;
900 
901 private:
902  static const std::string _name;
904 protected:
906 };
907 
912 struct Rectangle : public Polyline {
913 
914  inline Rectangle( double x, double y, double width, double height,
916  double lineWidth,
917  const LineStyle style = SolidStyle,
918  const LineCap cap = ButtCap,
919  const LineJoin join = MiterJoin,
920  int depth = -1 );
921 
922  inline Rectangle( const Rect & rect,
924  double lineWidth,
925  const LineStyle style = SolidStyle,
926  const LineCap cap = ButtCap,
927  const LineJoin join = MiterJoin,
928  int depth = -1 );
929 
935  const std::string & name() const;
936 
937  double x() const { return _path[0].x; }
938  double y() const { return _path[0].y; }
939  double width() { return (_path[1] - _path[0]).norm(); }
940  double height() { return (_path[0] - _path[3]).norm(); }
941  Point topLeft() { return Point( _path[0].x, _path[0].y ); }
942  Point topRight() { return Point( _path[1].x, _path[1].y ); }
943  Point bottomLeft() { return Point( _path[3].x, _path[3].y ); }
944  Point bottomRight() { return Point( _path[2].x, _path[2].y ); }
945 
946 
955  Rectangle rotated( double angle, const Point & center ) const;
956 
964  Rectangle rotated( double angle ) const;
965 
974  Rectangle translated( double dx, double dy ) const;
975 
984  Rectangle scaled( double sx, double sy ) const;
985 
986  Rectangle scaled( double s ) const;
987 
994  void scaleAll( double s );
995 
996  void flushFIG( std::ostream & stream,
997  const TransformFIG & transform,
998  std::map<DGtal::Color,int> & colormap ) const;
999 
1000  void flushSVG( std::ostream & stream,
1001  const TransformSVG & transform ) const;
1002 
1003 #ifdef WITH_CAIRO
1004  void flushCairo( cairo_t *cr,
1005  const TransformCairo & transform ) const;
1006 #endif
1007 
1008  void flushTikZ( std::ostream & stream,
1009  const TransformTikZ & transform ) const;
1010 
1011  Rectangle * clone() const;
1012 
1013 private:
1014  static const std::string _name;
1016 protected:
1018 };
1019 
1020 
1021 
1026 struct Image : public Rectangle {
1027 
1040  inline Image( double x0, double y0, double width, double height,
1041  std::string fileName, int depthValue, double alpha=1.0 );
1047  const std::string & name() const;
1048 
1049  Image * clone() const;
1050 
1051  void flushFIG( std::ostream & stream,
1052  const TransformFIG & transform,
1053  std::map<DGtal::Color,int> & colormap ) const;
1054 
1055  void flushSVG( std::ostream & stream,
1056  const TransformSVG & transform ) const;
1057 
1058 #ifdef WITH_CAIRO
1059  void flushCairo( cairo_t *cr,
1060  const TransformCairo & transform ) const;
1061 #endif
1062 
1063  void flushTikZ( std::ostream & stream,
1064  const TransformTikZ & transform ) const;
1065 
1066 
1067 private:
1068  static const std::string _name;
1070 protected:
1071  double _x0;
1072  double _y0;
1073  double _width;
1074  double _height;
1075  std::string _filename;
1076  double _alpha;
1077 };
1078 
1079 
1080 
1085 struct Triangle : public Polyline {
1086 
1087  Triangle( const Point & p1, const Point & p2, const Point & p3,
1088  DGtal::Color pen,
1089  DGtal::Color fill,
1090  double lineWidth,
1091  const LineStyle style = SolidStyle,
1092  const LineCap cap = ButtCap,
1093  const LineJoin join = MiterJoin,
1094  int depthValue = -1 )
1095  : Polyline( std::vector<Point>(), true, pen, fill, lineWidth, style, cap, join, depthValue ) {
1096  _path << p1;
1097  _path << p2;
1098  _path << p3;
1099  }
1100 
1101  Triangle( const double x1, const double y1,
1102  const double x2, const double y2,
1103  const double x3, const double y3,
1104  DGtal::Color pen,
1105  DGtal::Color fill,
1106  double lineWidth,
1107  const LineStyle style = SolidStyle,
1108  const LineCap cap = ButtCap,
1109  const LineJoin join = MiterJoin,
1110  int depthValue = -1 )
1111  : Polyline( std::vector<Point>(), true, pen, fill, lineWidth, style, cap, join, depthValue ) {
1112  _path << Point( x1, y1 );
1113  _path << Point( x2, y2 );
1114  _path << Point( x3, y3 );
1115  }
1116 
1122  const std::string & name() const;
1123 
1124  Triangle rotated( double angle ) const;
1125 
1134  Triangle translated( double dx, double dy ) const;
1135 
1144  Triangle scaled( double sx, double sy ) const;
1145 
1146  Triangle scaled( double s ) const;
1147 
1148  Triangle * clone() const;
1149 
1150 private:
1151  static const std::string _name;
1153 protected:
1154 };
1155 
1160 struct QuadraticBezierCurve : public Triangle {
1161 
1179  inline QuadraticBezierCurve( double x1, double y1, double x2, double y2, double x3, double y3,
1180  DGtal::Color pen,
1181  DGtal::Color fill,
1182  double lineWidth,
1183  const LineStyle style = SolidStyle,
1184  const LineCap cap = ButtCap,
1185  const LineJoin join = MiterJoin,
1186  int depthValue = -1 )
1187  : Triangle(x1, y1, x2, y2, x3, y3, pen, fill, lineWidth, style, cap, join, depthValue) {}
1188 
1189  void flushPostscript( std::ostream & stream,
1190  const TransformEPS & transform ) const;
1191 
1192  void flushFIG( std::ostream & stream,
1193  const TransformFIG & transform,
1194  std::map<DGtal::Color,int> & colormap ) const;
1195 
1196  void flushSVG( std::ostream & stream,
1197  const TransformSVG & transform ) const;
1198 
1199 #ifdef WITH_CAIRO
1200  void flushCairo( cairo_t *cr,
1201  const TransformCairo & transform ) const;
1202 #endif
1203 
1204  void flushTikZ( std::ostream & stream,
1205  const TransformTikZ & transform ) const;
1206 
1212  const std::string & name() const;
1213 
1214 private:
1215  static const std::string _name;
1217 };
1218 
1223 struct GouraudTriangle : public Polyline {
1224 
1225 
1226  GouraudTriangle( const Point & p0, const DGtal::Color & color0,
1227  const Point & p1, const DGtal::Color & color1,
1228  const Point & p2, const DGtal::Color & color2,
1229  int subdivisions,
1230  int depth = -1 );
1231 
1232  GouraudTriangle( const Point & p0, float brightness0,
1233  const Point & p1, float brightness1,
1234  const Point & p2, float brightness2,
1235  const DGtal::Color & fillColor,
1236  int subdivisions,
1237  int depth = -1 );
1238 
1244  const std::string & name() const;
1245 
1246  Point center() const;
1247 
1248  GouraudTriangle & rotate( double angle, const Point & center );
1249 
1250  GouraudTriangle rotated( double angle, const Point & center ) const;
1251 
1252  GouraudTriangle & rotate( double angle );
1253 
1254  GouraudTriangle rotated( double angle ) const;
1255 
1264  GouraudTriangle translated( double dx, double dy ) const;
1265 
1274  GouraudTriangle scaled( double sx, double sy ) const;
1275 
1276  GouraudTriangle scaled( double s ) const;
1277 
1278 
1285  void scaleAll( double s );
1286 
1293  void flushPostscript( std::ostream & stream,
1294  const TransformEPS & transform ) const;
1295 
1307  void flushFIG( std::ostream & stream,
1308  const TransformFIG & transform,
1309  std::map<DGtal::Color,int> & colormap ) const;
1310 
1311  void flushSVG( std::ostream & stream,
1312  const TransformSVG & transform ) const;
1313 
1314 #ifdef WITH_CAIRO
1315  void flushCairo( cairo_t *cr,
1316  const TransformCairo & transform ) const;
1317 #endif
1318 
1319  void flushTikZ( std::ostream & stream,
1320  const TransformTikZ & transform ) const;
1321 
1322  GouraudTriangle * clone() const;
1323 
1324 private:
1325  static const std::string _name;
1327 protected:
1332 };
1333 
1338 struct Ellipse : public Shape {
1339 
1340  Ellipse( double x, double y,
1341  double xRadius, double yRadius,
1342  DGtal::Color pen, DGtal::Color fill,
1343  double lineWidth,
1344  const LineStyle lineStyle = SolidStyle,
1345  int depthValue = -1 )
1346  : Shape( pen, fill,
1347  lineWidth, lineStyle, ButtCap, MiterJoin, depthValue ),
1348  _center( x, y ), _xRadius( xRadius ), _yRadius( yRadius ),
1349  _angle( 0.0 ),
1350  _circle( false ) {
1351  while ( _angle > M_PI_2 ) _angle -= M_PI;
1352  while ( _angle < -M_PI_2 ) _angle += M_PI;
1353  }
1354 
1360  const std::string & name() const;
1361 
1362  Point center() const;
1363 
1364  Ellipse & rotate( double angle, const Point & center );
1365 
1374  Ellipse rotated( double angle, const Point & center ) const;
1375 
1376  Ellipse & rotate( double angle );
1377 
1385  Ellipse rotated( double angle ) const;
1386 
1387  Ellipse & translate( double dx, double dy );
1388 
1397  Ellipse translated( double dx, double dy ) const;
1398 
1399  Shape & scale( double sx, double sy );
1400 
1401  Shape & scale( double s );
1402 
1411  Ellipse scaled( double sx, double sy ) const;
1412 
1413  Ellipse scaled( double s ) const;
1414 
1421  void scaleAll( double s );
1422 
1423  void flushPostscript( std::ostream & stream,
1424  const TransformEPS & transform ) const;
1425 
1426  void flushFIG( std::ostream & stream,
1427  const TransformFIG & transform,
1428  std::map<DGtal::Color,int> & colormap ) const;
1429 
1430  void flushSVG( std::ostream & stream,
1431  const TransformSVG & transform ) const;
1432 
1433 #ifdef WITH_CAIRO
1434  void flushCairo( cairo_t *cr,
1435  const TransformCairo & transform ) const;
1436 #endif
1437 
1438  void flushTikZ( std::ostream & stream,
1439  const TransformTikZ & transform ) const;
1440 
1441  Rect boundingBox() const;
1442 
1443  Ellipse * clone() const;
1444 
1445 private:
1446  static const std::string _name;
1448 protected:
1450  double _xRadius;
1451  double _yRadius;
1452  double _angle;
1453  bool _circle;
1454 };
1455 
1460 struct Circle : public Ellipse {
1461 
1462  Circle( double x, double y, double radius,
1463  DGtal::Color pen, DGtal::Color fill,
1464  double lineWidth,
1465  const LineStyle style = SolidStyle,
1466  int depthValue = -1 )
1467  : Ellipse( x, y, radius, radius, pen, fill, lineWidth, style, depthValue )
1468  { _circle = true; }
1469 
1475  const std::string & name() const;
1476 
1477  Point center() const;
1478 
1479  Circle & rotate( double angle, const Point & center );
1480 
1481  Circle rotated( double angle, const Point & center ) const;
1482 
1483  Circle & rotate( double angle );
1484 
1485  Circle rotated( double angle ) const;
1486 
1487  Circle & translate( double dx, double dy );
1488 
1489  Circle translated( double dx, double dy ) const;
1490 
1491  Shape & scale( double sx, double sy );
1492 
1493  Shape & scale( double s );
1494 
1495  Circle scaled( double sx, double sy ) const;
1496 
1497  Circle scaled( double s ) const;
1498 
1505  void scaleAll( double s );
1506 
1507  void flushSVG( std::ostream & stream,
1508  const TransformSVG & transform ) const;
1509 
1510 #ifdef WITH_CAIRO
1511  void flushCairo( cairo_t *cr,
1512  const TransformCairo & transform ) const;
1513 #endif
1514 
1515  void flushTikZ( std::ostream & stream,
1516  const TransformTikZ & transform ) const;
1517 
1518  Circle * clone() const;
1519 
1520 private:
1521  static const std::string _name;
1522 };
1523 
1528 struct Arc : public Circle {
1529 
1530  Arc( double x, double y, double radius, double angle1, double angle2, bool negative,
1531  DGtal::Color pen, DGtal::Color fill,
1532  double lineWidth,
1533  const LineStyle style = SolidStyle,
1534  int depthValue = -1 )
1535  : Circle( x, y, radius, pen, fill, lineWidth, style, depthValue )
1536  { _angle1 = angle1; _angle2 = angle2; _negative = negative; }
1537 
1543  const std::string & name() const;
1544  void
1545  flushPostscript( std::ostream & stream,
1546  const TransformEPS & transform ) const;
1547  void
1548  flushSVG( std::ostream & stream,
1549  const TransformSVG & transform ) const;
1550 
1551 #ifdef WITH_CAIRO
1552  void flushCairo( cairo_t *cr,
1553  const TransformCairo & transform ) const;
1554 #endif
1555 
1556  void
1557  flushTikZ( std::ostream & stream,
1558  const TransformTikZ & transform ) const;
1559 
1560 private:
1561  static const std::string _name;
1563 protected:
1564  double _angle1;
1565  double _angle2;
1567 };
1568 
1569 
1574 struct Text : public Shape {
1575 
1588  Text( double x, double y,
1589  const std::string & text,
1590  const Fonts::Font font,
1591  double size,
1593  int depthValue = -1 )
1594  : Shape( color, DGtal::Color::None, 1.0, SolidStyle, ButtCap, MiterJoin, depthValue ),
1595  _position( x, y ), _text( text ), _font( font ),
1596  _angle( 0.0 ), _size( size ),
1597  _xScale( 1.0 ), _yScale( 1.0 ) { }
1598 
1599 
1613  Text( double x, double y,
1614  const std::string & text,
1615  const Fonts::Font font,
1616  const std::string & svgFont,
1617  double size,
1619  int depthValue = -1 )
1620  : Shape( color, DGtal::Color::None, 1.0, SolidStyle, ButtCap, MiterJoin, depthValue ),
1621  _position( x, y ),
1622  _text( text ), _font( font ), _svgFont( svgFont ),
1623  _angle( 0.0 ),
1624  _size( size ),
1625  _xScale( 1.0 ), _yScale( 1.0 ) { }
1626 
1632  const std::string & name() const;
1633 
1634  Point center() const;
1635 
1636  Text & rotate( double angle, const Point & center );
1637 
1638  Text rotated( double angle, const Point & center ) const;
1639 
1640  Text & rotate( double angle );
1641 
1642  Text rotated( double angle ) const;
1643 
1644  Text & translate( double dx, double dy );
1645 
1646  Text translated( double dx, double dy ) const;
1647 
1648  Shape & scale( double sx, double sy );
1649 
1650  Shape & scale( double s );
1651 
1652  Text scaled( double sx, double sy ) const;
1653 
1654  Text scaled( double s ) const;
1655 
1662  void scaleAll( double s );
1663 
1664  void flushPostscript( std::ostream & stream,
1665  const TransformEPS & transform ) const;
1666 
1667  void flushFIG( std::ostream & stream,
1668  const TransformFIG & transform,
1669  std::map<DGtal::Color,int> & colormap ) const;
1670 
1671  void flushSVG( std::ostream & stream,
1672  const TransformSVG & transform ) const;
1673 
1674 #ifdef WITH_CAIRO
1675  void flushCairo( cairo_t *cr,
1676  const TransformCairo & transform ) const;
1677 #endif
1678 
1679  void flushTikZ( std::ostream & stream,
1680  const TransformTikZ & transform ) const;
1681 
1682  Rect boundingBox() const;
1683 
1684  Text * clone() const;
1685 
1686 private:
1687  static const std::string _name;
1689 protected:
1691  std::string _text;
1693  std::string _svgFont;
1694  double _angle;
1695  double _size;
1696  double _xScale;
1697  double _yScale;
1698 };
1699 
1708 bool shapeGreaterDepth( const Shape *s1, const Shape *s2 );
1709 
1710 
1711 } // namespace LibBoard
1712 
1713 /*
1714  * Inline methods
1715  */
1716 #include "Shapes.ih"
1717 
1718 
1719 #endif /* _SHAPE_H_ */
1720 
1721 
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
static const Color None
Definition: Color.h:412
static const Color Black
Definition: Color.h:413
DGtal is the top-level namespace which contains all DGtal functions and types.
bool shapeGreaterDepth(const Shape *s1, const Shape *s2)
Definition: Shapes.cpp:95
static const std::string _name
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Shapes.cpp:1539
const std::string & name() const
Definition: Shapes.cpp:1493
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Definition: Shapes.cpp:1500
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:1579
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)
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:1625
A line between two points with an arrow at one extremity.
Definition: Board/Shapes.h:665
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 * clone() const
Definition: Shapes.cpp:788
Arrow translated(double dx, double dy) const
Definition: Shapes.cpp:758
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:880
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Definition: Shapes.cpp:847
static const std::string _name
Definition: Board/Shapes.h:758
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Definition: Shapes.cpp:933
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:1002
Arrow rotated(double angle, const Point &center) const
Definition: Shapes.cpp:739
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Shapes.cpp:793
Arrow scaled(double sx, double sy) const
Definition: Shapes.cpp:769
const std::string & name() const
Definition: Shapes.cpp:733
void scaleAll(double s)
Definition: Shapes.cpp:1402
const std::string & name() const
Definition: Shapes.cpp:1322
Point center() const
Definition: Shapes.cpp:1328
Circle & translate(double dx, double dy)
Definition: Shapes.cpp:1365
Circle rotated(double angle, const Point &center) const
Definition: Shapes.cpp:1345
static const std::string _name
Circle & rotate(double angle, const Point &center)
Definition: Shapes.cpp:1333
Circle * clone() const
Definition: Shapes.cpp:1410
Circle translated(double dx, double dy) const
Definition: Shapes.cpp:1372
Shape & scale(double sx, double sy)
Definition: Shapes.cpp:1378
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Definition: Shapes.cpp:1431
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:1415
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
Definition: Shapes.cpp:1390
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:1472
A line between two points.
Definition: Board/Shapes.h:398
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Definition: Shapes.cpp:308
Dot(double x, double y, DGtal::Color color, double lineWidth, int depth=-1)
Dot scaled(double sx, double sy) const
Definition: Shapes.cpp:274
Dot & rotate(double angle, const Point &center)
Definition: Shapes.cpp:223
Dot * clone() const
Definition: Shapes.cpp:385
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Shapes.cpp:293
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Definition: Shapes.cpp:348
Point center() const
Definition: Shapes.cpp:218
Dot translated(double dx, double dy) const
Definition: Shapes.cpp:256
Rect boundingBox() const
Definition: Shapes.cpp:379
static const std::string _name
Definition: Board/Shapes.h:521
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:370
Dot & translate(double dx, double dy)
Definition: Shapes.cpp:248
Shape & scale(double sx, double sy)
Definition: Shapes.cpp:262
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:335
const std::string & name() const
Definition: Shapes.cpp:212
Dot rotated(double angle, const Point &center) const
Definition: Shapes.cpp:230
void scaleAll(double s)
Definition: Shapes.cpp:286
static const std::string _name
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:1275
void scaleAll(double s)
Definition: Shapes.cpp:1143
Shape & scale(double sx, double sy)
Definition: Shapes.cpp:1075
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Definition: Shapes.cpp:1185
Point center() const
Definition: Shapes.cpp:1026
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:1213
const std::string & name() const
Definition: Shapes.cpp:1020
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Definition: Shapes.cpp:1232
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Shapes.cpp:1156
Ellipse & rotate(double angle, const Point &center)
Definition: Shapes.cpp:1031
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
Definition: Shapes.cpp:1131
Rect boundingBox() const
Definition: Shapes.cpp:1291
Ellipse * clone() const
Definition: Shapes.cpp:1151
Ellipse rotated(double angle, const Point &center) const
Definition: Shapes.cpp:1044
Ellipse & translate(double dx, double dy)
Definition: Shapes.cpp:1062
Ellipse translated(double dx, double dy) const
Definition: Shapes.cpp:1069
A triangle with shaded filling according to colors given for each vertex.
GouraudTriangle * clone() const
Definition: Shapes.cpp:2194
GouraudTriangle rotated(double angle, const Point &center) const
Definition: Shapes.cpp:2152
void scaleAll(double s)
Definition: Shapes.cpp:2188
Point center() const
Definition: Shapes.cpp:2140
GouraudTriangle scaled(double sx, double sy) const
Definition: Shapes.cpp:2176
GouraudTriangle & rotate(double angle, const Point &center)
Definition: Shapes.cpp:2145
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:2265
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Definition: Shapes.cpp:2228
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:2306
GouraudTriangle translated(double dx, double dy) const
Definition: Shapes.cpp:2170
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)
Definition: Shapes.cpp:2094
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Shapes.cpp:2199
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Definition: Shapes.cpp:2299
const std::string & name() const
Definition: Shapes.cpp:2089
static const std::string _name
Used to draw image in figure.
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Definition: Shapes.cpp:644
const std::string & name() const
Definition: Shapes.cpp:633
std::string _filename
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:669
Image * clone() const
Definition: Shapes.cpp:639
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:714
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Definition: Shapes.cpp:686
static const std::string _name
Image(double x0, double y0, double width, double height, std::string fileName, int depthValue, double alpha=1.0)
A line between two points.
Definition: Board/Shapes.h:534
Line & rotate(double angle, const Point &center)
Definition: Shapes.cpp:407
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)
void scaleAll(double s)
Definition: Shapes.cpp:500
Line rotated(double angle, const Point &center) const
Definition: Shapes.cpp:421
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Shapes.cpp:514
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:593
Line * clone() const
Definition: Shapes.cpp:509
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:558
Point center() const
Definition: Shapes.cpp:402
Line translated(double dx, double dy) const
Definition: Shapes.cpp:450
Line & translate(double dx, double dy)
Definition: Shapes.cpp:440
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Definition: Shapes.cpp:529
Shape & scale(double sx, double sy)
Definition: Shapes.cpp:461
static const std::string _name
Definition: Board/Shapes.h:649
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Definition: Shapes.cpp:571
const std::string & name() const
Definition: Shapes.cpp:396
Line scaled(double sx, double sy) const
Definition: Shapes.cpp:481
Rect boundingBox() const
Definition: Shapes.cpp:604
A path, according to Postscript and SVG definition.
Definition: Path.h:43
Struct representing a 2D point.
Definition: Point.h:27
A polygonal line described by a series of 2D points.
Definition: Board/Shapes.h:765
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:1792
Polyline rotated(double angle, const Point &center) const
Definition: Shapes.cpp:1667
const std::string & name() const
Definition: Shapes.cpp:1642
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Definition: Shapes.cpp:1809
Rect boundingBox() const
Definition: Shapes.cpp:1867
Point center() const
Definition: Shapes.cpp:1655
Shape & scale(double sx, double sy)
Definition: Shapes.cpp:1699
Polyline & operator<<(const Point &p)
Definition: Shapes.cpp:1648
Polyline translated(double dx, double dy) const
Definition: Shapes.cpp:1693
Polyline & rotate(double angle, const Point &center)
Definition: Shapes.cpp:1660
Point & operator[](const unsigned int n)
Definition: Board/Shapes.h:815
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 scaleAll(double s)
Definition: Shapes.cpp:1725
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Definition: Shapes.cpp:1760
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:1850
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)
Polyline & translate(double dx, double dy)
Definition: Shapes.cpp:1686
Polyline * clone() const
Definition: Shapes.cpp:1731
Polyline scaled(double sx, double sy) const
Definition: Shapes.cpp:1713
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Shapes.cpp:1736
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)
static const std::string _name
Definition: Board/Shapes.h:902
A quadratic Bezier curve having 3 control points. NB. It is also a parabola arc.
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:2425
const std::string & name() const
Definition: Shapes.cpp:2360
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Definition: Shapes.cpp:2448
static const std::string _name
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Shapes.cpp:2366
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:2496
QuadraticBezierCurve(double x1, double y1, double x2, double y2, double x3, double y3, DGtal::Color pen, DGtal::Color fill, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depthValue=-1)
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Definition: Shapes.cpp:2416
Struct representing a rectangle on the plane.
Definition: Rect.h:26
Rectangle rotated(double angle, const Point &center) const
Definition: Shapes.cpp:1885
Rectangle scaled(double sx, double sy) const
Definition: Shapes.cpp:1903
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
Definition: Shapes.cpp:1897
Rectangle * clone() const
Definition: Shapes.cpp:1921
Rectangle(const Rect &rect, DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Definition: Shapes.cpp:2010
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:2071
double y() const
Definition: Board/Shapes.h:938
const std::string & name() const
Definition: Shapes.cpp:1879
void scaleAll(double s)
Definition: Shapes.cpp:1915
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Definition: Shapes.cpp:1926
static const std::string _name
double x() const
Definition: Board/Shapes.h:937
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:1971
Abstract structure for a 2D shape.
Definition: Board/Shapes.h:58
std::string svgProperties(const TransformSVG &transform) const
Definition: Shapes.cpp:109
virtual void flushCairo(cairo_t *cr, const TransformCairo &transform) const =0
virtual void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const =0
virtual void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const =0
int depth() const
Definition: Board/Shapes.h:361
virtual void scaleAll(double s)=0
DGtal::Color _fillColor
Definition: Board/Shapes.h:297
virtual void shiftDepth(int shift)
Definition: Shapes.cpp:200
virtual void flushPostscript(std::ostream &stream, const TransformEPS &transform) const =0
const DGtal::Color & penColor() const
Definition: Board/Shapes.h:367
std::string postscriptProperties() const
Definition: Shapes.cpp:140
virtual const std::string & name() const
Definition: Shapes.cpp:103
DGtal::Color _penColor
Definition: Board/Shapes.h:296
LineJoin _lineJoin
Definition: Board/Shapes.h:301
virtual Rect boundingBox() const =0
Shape & rotateDeg(double angle, const Point &center)
Definition: Board/Shapes.h:379
Shape(DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, LineStyle style, const LineCap cap, const LineJoin join, int depth)
std::string tikzProperties(const TransformTikZ &transform) const
Definition: Shapes.cpp:177
virtual Shape & translate(double dx, double dy)=0
virtual Shape & scale(double sx, double sy)=0
static const std::string _name
Definition: Board/Shapes.h:291
Shape & operator--()
Definition: Board/Shapes.h:353
virtual Point center() const =0
void setCairoDashStyle(cairo_t *cr, LineStyle type) const
Definition: Shapes.cpp:153
LineStyle _lineStyle
Definition: Board/Shapes.h:299
Shape & operator++()
Definition: Board/Shapes.h:346
virtual ~Shape()
Definition: Board/Shapes.h:90
bool filled() const
Definition: Board/Shapes.h:111
virtual Shape * clone() const =0
virtual Shape & scale(double s)=0
virtual Shape & rotate(double angle, const Point &center)=0
virtual void flushSVG(std::ostream &stream, const TransformSVG &transform) const =0
const DGtal::Color & fillColor() const
Definition: Board/Shapes.h:373
virtual Shape & rotate(double angle)=0
A piece of text.
Point center() const
Definition: Shapes.cpp:2535
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:2661
Text & translate(double dx, double dy)
Definition: Shapes.cpp:2577
Text(double x, double y, const std::string &text, const Fonts::Font font, double size, DGtal::Color color=DGtal::Color::Black, int depthValue=-1)
Rect boundingBox() const
Definition: Shapes.cpp:2759
Text scaled(double sx, double sy) const
Definition: Shapes.cpp:2605
const std::string & name() const
Definition: Shapes.cpp:2529
static const std::string _name
Text * clone() const
Definition: Shapes.cpp:2623
Text translated(double dx, double dy) const
Definition: Shapes.cpp:2584
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Definition: Shapes.cpp:2641
std::string _text
std::string _svgFont
Text rotated(double angle, const Point &center) const
Definition: Shapes.cpp:2554
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:2701
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Shapes.cpp:2628
Fonts::Font _font
Text & rotate(double angle, const Point &center)
Definition: Shapes.cpp:2540
void scaleAll(double s)
Definition: Shapes.cpp:2617
Text(double x, double y, const std::string &text, const Fonts::Font font, const std::string &svgFont, double size, DGtal::Color color=DGtal::Color::Black, int depthValue=-1)
Shape & scale(double sx, double sy)
Definition: Shapes.cpp:2590
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Definition: Shapes.cpp:2694
Structure representing a scaling and translation suitable for an Cairo output.
Definition: Transforms.h:112
Structure representing a scaling and translation suitable for an EPS output.
Definition: Transforms.h:59
Structure representing a scaling and translation suitable for an XFig output.
Definition: Transforms.h:73
Structure representing a scaling and translation suitable for an SVG output.
Definition: Transforms.h:95
Structure representing a scaling and translation suitable for an TikZ output.
Definition: Transforms.h:129
A triangle. Basically a Polyline with a convenient constructor.
Triangle(const double x1, const double y1, const double x2, const double y2, const double x3, const double y3, DGtal::Color pen, DGtal::Color fill, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depthValue=-1)
static const std::string _name
Triangle translated(double dx, double dy) const
Definition: Shapes.cpp:2332
Triangle(const Point &p1, const Point &p2, const Point &p3, DGtal::Color pen, DGtal::Color fill, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depthValue=-1)
Triangle rotated(double angle) const
Definition: Shapes.cpp:2326
Triangle * clone() const
Definition: Shapes.cpp:2350
const std::string & name() const
Definition: Shapes.cpp:2320
Triangle scaled(double sx, double sy) const
Definition: Shapes.cpp:2338
MyPointD Point
Definition: testClone2.cpp:383