DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Board.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_BOARD_H_
15 #define _BOARD_BOARD_H_
16 
17 #include <ostream>
18 #include <string>
19 #include <vector>
20 
21 #include "Board/Point.h"
22 #include "Board/Path.h"
23 #include "Board/Shapes.h"
24 #include "Board/ShapeList.h"
25 
26 #include "DGtal/io/Color.h"
27 
28 namespace LibBoard {
29 
35 class Board : public ShapeList {
36 
37 public:
38 
39  // cairo
41 
42  enum PageSize { BoundingBox, A4, Letter };
44  static const double Degree;
45 
52 
58  Board( const Board & other );
59 
60  ~Board();
61 
69  Board & operator=( const Board & other );
70 
71 
79  Board & operator<<( const Shape & shape );
80 
88  Board & operator<<( Unit unit );
89 
95  void clear( const DGtal::Color & color = DGtal::Color::None );
96 
104  void clear( unsigned char red, unsigned char green, unsigned char blue );
105 
106  Shape & rotate( double angle, const Point & center );
107 
108  Shape & rotate( double angle );
109 
110  Shape & translate( double dx, double dy );
111 
112  Shape & scale( double sx, double sy );
113 
114  Shape & scale( double s );
115 
116  Board rotated( double angle, const Point & center );
117 
118  Board rotated( double angle );
119 
120  Board translated( double dx, double dy );
121 
122  Board scaled( double sx, double sy );
123 
124  Board scaled( double s );
125 
131  void setUnit( Unit unit );
132 
139  void setUnit( double factor, Unit unit );
140 
148  void drawDot( double x, double y, int depthValue = -1 );
149 
159  void drawLine( double x1, double y1, double x2, double y2,
160  int depthValue = -1 );
161 
172  void drawArrow( double x1, double y1, double x2, double y2,
173  bool filled = true,
174  int depthValue = -1 );
175 
187  void drawTriangle( double x1, double y1,
188  double x2, double y2,
189  double x3, double y3,
190  int depthValue = -1 );
191 
200  void drawTriangle( const Point & p1,
201  const Point & p2,
202  const Point & p3,
203  int depthValue = -1 );
204 
205 
217  void drawArc(double x, double y, double radius, double angle1, double angle2,
218  bool neg, int depthValue = -1 );
219 
231  void fillTriangle( double x1, double y1,
232  double x2, double y2,
233  double x3, double y3,
234  int depthValue = -1 );
235 
248  void fillGouraudTriangle( const Point & p1,
249  const DGtal::Color & color1,
250  const Point & p2,
251  const DGtal::Color & color2,
252  const Point & p3,
253  const DGtal::Color & color3,
254  unsigned char divisions = 3,
255  int depthValue = -1 );
256 
272  void fillGouraudTriangle( const double x1, const double y1,
273  const DGtal::Color & color1,
274  const double x2, const double y2,
275  const DGtal::Color & color2,
276  const double x3, const double y3,
277  const DGtal::Color & color3,
278  unsigned char divisions = 3,
279  int depthValue = -1 );
280 
293  void fillGouraudTriangle( const Point & p1,
294  const float brightness1,
295  const Point & p2,
296  const float brightness2,
297  const Point & p3,
298  const float brightness3,
299  unsigned char divisions = 3,
300  int depthValue = -1 );
301 
318  void fillGouraudTriangle( const double x1, const double y1,
319  const float brightness1,
320  const double x2, const double y2,
321  const float brightness2,
322  const double x3, const double y3,
323  const float brightness3,
324  unsigned char divisions = 3,
325  int depthValue = -1 );
326 
327 
336  void fillTriangle( const Point & p1,
337  const Point & p2,
338  const Point & p3,
339  int depthValue = -1 );
340 
350  void drawRectangle( double x, double y,
351  double width, double height,
352  int depthValue = -1 );
363  void drawImage( std::string filename, double x, double y,
364  double width, double height,
365  int depthValue = -1, double alpha=1.0 );
366 
376  void fillRectangle( double x, double y,
377  double width, double height,
378  int depthValue = -1 );
379 
388  void drawCircle( double x, double y, double radius,
389  int depthValue = -1 );
390 
399  void fillCircle( double x, double y, double radius,
400  int depthValue = -1);
401 
410  void drawEllipse( double x, double y,
411  double xRadius, double yRadius,
412  int depthValue = -1);
413 
423  void fillEllipse( double x, double y,
424  double xRadius, double yRadius,
425  int depthValue = -1);
426 
433  void drawPolyline( const std::vector<Point> & points,
434  int depthValue = -1 );
435 
442  void drawClosedPolyline( const std::vector<Point> & points,
443  int depthValue = -1 );
444 
451  void fillPolyline( const std::vector<Point> & points,
452  int depthValue = -1 );
453 
462  void drawText( double x, double y, const char * text,
463  int depthValue = -1 );
464 
473  void drawText( double x, double y, const std::string & str,
474  int depthValue = -1 );
475 
483  Board & setFont( const Fonts::Font font, double fontSize );
484 
491  Board & setFontSize( double fontSize );
492 
501  Board & setPenColorRGBi( unsigned char red,
502  unsigned char green,
503  unsigned char blue,
504  unsigned char alpha = 255 );
505 
515  Board & setPenColorRGBf( float red,
516  float green,
517  float blue,
518  float alpha = 1.0f );
519 
527  Board & setPenColor( const DGtal::Color & color );
528 
529 
539  Board & setFillColorRGBi( unsigned char red,
540  unsigned char green,
541  unsigned char blue,
542  unsigned char alpha = 255 );
543 
553  Board & setFillColorRGBf( float red, float green, float blue, float alpha = 1.0f );
554 
562  Board & setFillColor( const DGtal::Color & color );
563 
570  Board & setLineWidth( double width );
571 
579 
588  Board & setLineCap( Shape::LineCap cap );
589 
599 
605  void backgroundColor( const DGtal::Color & color );
606 
612  void drawBoundingBox( int depthValue = -1 );
613 
614 
623  void setClippingRectangle( double x, double y,
624  double width, double height );
625 
631  void setClippingPath( const std::vector<Point> & points );
632 
638  void setClippingPath( const Path & path );
639 
650  void addDuplicates( const Shape & shape,
651  unsigned int times,
652  double dx, double dy, double scale = 1.0 );
653 
667  void addDuplicates( const Shape & shape,
668  unsigned int times,
669  double dx, double dy,
670  double scaleX,
671  double scaleY,
672  double angle = 0.0 );
673 
683  void save( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
684 
695  void save( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const;
696 
705  void saveEPS( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const ;
706 
715  void saveEPS(std::ostream &out , PageSize size = Board::BoundingBox, double margin = 10.0 ) const ;
716 
717 
728  void saveEPS( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
729 
730 
731 
742  void saveEPS( std::ostream &out, double pageWidth, double pageHeight, double margin = 10.0) const ;
743 
753  void saveFIG( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0,
754  bool includeFIGHeader=true) const;
755 
765  void saveFIG( std::ostream &out, PageSize size = Board::BoundingBox, double margin = 10.0,
766  bool includeFIGHeader=true) const;
767 
779  void saveFIG( const char * filename, double pageWidth, double pageHeight, double margin = 10.0,
780  bool includeFIGHeader=true) const ;
781 
795  void saveFIG( std::ostream &out, double pageWidth, double pageHeight, double margin = 10.0,
796  bool includeFIGHeader=true ) const ;
797 
806  void saveSVG( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
807 
818  void saveSVG( std::ostream &out, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
819 
830  void saveSVG( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
831 
842  void saveSVG( std::ostream &out, double pageWidth, double pageHeight, double margin = 10.0,
843  string filename="output.svg") const ;
844 
845 
846 #ifdef WITH_CAIRO
847  // cairo
857  void saveCairo( const char * filename, CairoType type = CairoPNG, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
858 
869  void saveCairo( const char * filename, CairoType type, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
870 
871 
872 #endif
873 
882  void saveTikZ( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
893  void saveTikZ( std::ostream &out, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
894 
905  void saveTikZ( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
906 
919  void saveTikZ( std::ostream &out, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
920 
921  protected:
922 
927  struct State {
930  double lineWidth;
934  Fonts::Font font;
935  double fontSize;
936  double unitFactor;
937  State();
938  double unit( const double & x ) { return x * unitFactor; }
939  Point unit( const Point & p ) { return Point( p.x * unitFactor, p.y * unitFactor); }
940  void unit( Shape & shape ) { shape.scaleAll( unitFactor ); }
941  };
942  State _state;
944  Path _clippingPath;
945 };
946 
947 } // namespace LibBoard
948 
949 #include "Board.ih"
950 
951 #endif