DGtal  1.5.beta
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 
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 
174  void drawQuadraticBezierCurve( double x1, double y1, double x2, double y2, double x3, double y3,
175  int depthValue = -1 );
176 
187  void drawArrow( double x1, double y1, double x2, double y2,
188  bool filled = true,
189  int depthValue = -1 );
190 
202  void drawTriangle( double x1, double y1,
203  double x2, double y2,
204  double x3, double y3,
205  int depthValue = -1 );
206 
215  void drawTriangle( const Point & p1,
216  const Point & p2,
217  const Point & p3,
218  int depthValue = -1 );
219 
220 
232  void drawArc(double x, double y, double radius, double angle1, double angle2,
233  bool neg, int depthValue = -1 );
234 
246  void fillTriangle( double x1, double y1,
247  double x2, double y2,
248  double x3, double y3,
249  int depthValue = -1 );
250 
263  void fillGouraudTriangle( const Point & p1,
264  const DGtal::Color & color1,
265  const Point & p2,
266  const DGtal::Color & color2,
267  const Point & p3,
268  const DGtal::Color & color3,
269  unsigned char divisions = 3,
270  int depthValue = -1 );
271 
287  void fillGouraudTriangle( const double x1, const double y1,
288  const DGtal::Color & color1,
289  const double x2, const double y2,
290  const DGtal::Color & color2,
291  const double x3, const double y3,
292  const DGtal::Color & color3,
293  unsigned char divisions = 3,
294  int depthValue = -1 );
295 
308  void fillGouraudTriangle( const Point & p1,
309  const float brightness1,
310  const Point & p2,
311  const float brightness2,
312  const Point & p3,
313  const float brightness3,
314  unsigned char divisions = 3,
315  int depthValue = -1 );
316 
333  void fillGouraudTriangle( const double x1, const double y1,
334  const float brightness1,
335  const double x2, const double y2,
336  const float brightness2,
337  const double x3, const double y3,
338  const float brightness3,
339  unsigned char divisions = 3,
340  int depthValue = -1 );
341 
342 
351  void fillTriangle( const Point & p1,
352  const Point & p2,
353  const Point & p3,
354  int depthValue = -1 );
355 
365  void drawRectangle( double x, double y,
366  double width, double height,
367  int depthValue = -1 );
379  void drawImage( std::string filename, double x, double y,
380  double width, double height,
381  int depthValue = -1, double alpha=1.0 );
382 
392  void fillRectangle( double x, double y,
393  double width, double height,
394  int depthValue = -1 );
395 
404  void drawCircle( double x, double y, double radius,
405  int depthValue = -1 );
406 
415  void fillCircle( double x, double y, double radius,
416  int depthValue = -1);
417 
427  void drawEllipse( double x, double y,
428  double xRadius, double yRadius,
429  int depthValue = -1);
430 
440  void fillEllipse( double x, double y,
441  double xRadius, double yRadius,
442  int depthValue = -1);
443 
450  void drawPolyline( const std::vector<Point> & points,
451  int depthValue = -1 );
452 
459  void drawClosedPolyline( const std::vector<Point> & points,
460  int depthValue = -1 );
461 
468  void fillPolyline( const std::vector<Point> & points,
469  int depthValue = -1 );
470 
479  void drawText( double x, double y, const char * text,
480  int depthValue = -1 );
481 
490  void drawText( double x, double y,
491  const std::string & str,
492  int depthValue = -1 );
493 
501  Board & setFont( const Fonts::Font font, double fontSize );
502 
509  Board & setFontSize( double fontSize );
510 
520  Board & setPenColorRGBi( unsigned char red,
521  unsigned char green,
522  unsigned char blue,
523  unsigned char alpha = 255 );
524 
534  Board & setPenColorRGBf( float red,
535  float green,
536  float blue,
537  float alpha = 1.0f );
538 
546  Board & setPenColor( const DGtal::Color & color );
547 
548 
558  Board & setFillColorRGBi( unsigned char red,
559  unsigned char green,
560  unsigned char blue,
561  unsigned char alpha = 255 );
562 
572  Board & setFillColorRGBf( float red, float green, float blue, float alpha = 1.0f );
573 
581  Board & setFillColor( const DGtal::Color & color );
582 
589  Board & setLineWidth( double width );
590 
598 
608 
618 
624  void backgroundColor( const DGtal::Color & color );
625 
631  void drawBoundingBox( int depthValue = -1 );
632 
633 
642  void setClippingRectangle( double x, double y,
643  double width, double height );
644 
650  void setClippingPath( const std::vector<Point> & points );
651 
657  void setClippingPath( const Path & path );
658 
669  void addDuplicates( const Shape & shape,
670  unsigned int times,
671  double dx, double dy, double scale = 1.0 );
672 
685  void addDuplicates( const Shape & shape,
686  unsigned int times,
687  double dx, double dy,
688  double scaleX,
689  double scaleY,
690  double angle = 0.0 );
691 
701  void save( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
702 
713  void save( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const;
714 
723  void saveEPS( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const ;
724 
733  void saveEPS(std::ostream &out , PageSize size = Board::BoundingBox, double margin = 10.0 ) const ;
734 
735 
745  void saveEPS( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
746 
747 
748 
758  void saveEPS( std::ostream &out, double pageWidth, double pageHeight, double margin = 10.0) const ;
759 
769  void saveFIG( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0,
770  bool includeFIGHeader=true) const;
771 
781  void saveFIG( std::ostream &out, PageSize size = Board::BoundingBox, double margin = 10.0,
782  bool includeFIGHeader=true) const;
783 
794  void saveFIG( const char * filename, double pageWidth, double pageHeight, double margin = 10.0,
795  bool includeFIGHeader=true) const ;
796 
809  void saveFIG( std::ostream &out, double pageWidth, double pageHeight, double margin = 10.0,
810  bool includeFIGHeader=true ) const ;
811 
820  void saveSVG( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
821 
832  void saveSVG( std::ostream &out, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
833 
843  void saveSVG( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
844 
856  void saveSVG( std::ostream &out, double pageWidth, double pageHeight, double margin = 10.0,
857  std::string filename="output.svg") const ;
858 
859 
860 #ifdef WITH_CAIRO
861  // cairo
871  void saveCairo( const char * filename, CairoType type = CairoPNG,
872  PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
873 
884  void saveCairo( const char * filename, CairoType type, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
885 
886 
887 #endif
888 
897  void saveTikZ( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
908  void saveTikZ( std::ostream &out, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
909 
919  void saveTikZ( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
920 
932  void saveTikZ( std::ostream &out, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
933 
934  protected:
935 
940  struct State {
943  double lineWidth;
948  double fontSize;
949  double unitFactor;
950  State();
951  double unit( const double & x ) { return x * unitFactor; }
952  Point unit( const Point & p ) { return Point( p.x * unitFactor, p.y * unitFactor); }
953  void unit( Shape & shape ) { shape.scaleAll( unitFactor ); }
954  };
958 };
959 
960 } // namespace LibBoard
961 
962 #include "Board.ih"
963 
964 #endif
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
static const Color None
Definition: Color.h:412
Class for EPS, FIG or SVG drawings.
Definition: Board.h:35
Board & setLineStyle(Shape::LineStyle style)
void drawRectangle(double x, double y, double width, double height, int depthValue=-1)
Definition: Board.cpp:416
Board & setFont(const Fonts::Font font, double fontSize)
Definition: Board.cpp:335
Board & setPenColor(const DGtal::Color &color)
Definition: Board.cpp:297
void fillTriangle(double x1, double y1, double x2, double y2, double x3, double y3, int depthValue=-1)
Definition: Board.cpp:608
void setClippingRectangle(double x, double y, double width, double height)
Definition: Board.cpp:727
void clear(unsigned char red, unsigned char green, unsigned char blue)
DGtal::Color _backgroundColor
Definition: Board.h:956
void drawEllipse(double x, double y, double xRadius, double yRadius, int depthValue=-1)
Definition: Board.cpp:481
State _state
Definition: Board.h:955
void drawPolyline(const std::vector< Point > &points, int depthValue=-1)
Definition: Board.cpp:510
Board & setFontSize(double fontSize)
Definition: Board.cpp:343
void saveTikZ(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1218
void saveFIG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0, bool includeFIGHeader=true) const
Definition: Board.cpp:906
void setClippingPath(const std::vector< Point > &points)
Definition: Board.cpp:738
Board & operator<<(const Shape &shape)
Definition: Board.cpp:132
void drawTriangle(double x1, double y1, double x2, double y2, double x3, double y3, int depthValue=-1)
Definition: Board.cpp:570
Board & setLineCap(Shape::LineCap cap)
Board & setLineJoin(Shape::LineJoin join)
void drawQuadraticBezierCurve(double x1, double y1, double x2, double y2, double x3, double y3, int depthValue=-1)
Definition: Board.cpp:383
void fillCircle(double x, double y, double radius, int depthValue=-1)
Definition: Board.cpp:470
void drawLine(double x1, double y1, double x2, double y2, int depthValue=-1)
Definition: Board.cpp:367
void fillPolyline(const std::vector< Point > &points, int depthValue=-1)
Definition: Board.cpp:550
Board & operator=(const Board &other)
Definition: Board.cpp:116
void save(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1131
Board & setPenColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
Definition: Board.cpp:277
void drawDot(double x, double y, int depthValue=-1)
Definition: Board.cpp:356
static const double Degree
Definition: Board.h:44
void drawClosedPolyline(const std::vector< Point > &points, int depthValue=-1)
Definition: Board.cpp:530
void drawArc(double x, double y, double radius, double angle1, double angle2, bool neg, int depthValue=-1)
Definition: Board.cpp:460
void fillGouraudTriangle(const Point &p1, const DGtal::Color &color1, const Point &p2, const DGtal::Color &color2, const Point &p3, const DGtal::Color &color3, unsigned char divisions=3, int depthValue=-1)
Definition: Board.cpp:646
void drawArrow(double x1, double y1, double x2, double y2, bool filled=true, int depthValue=-1)
Definition: Board.cpp:399
Board & setPenColorRGBf(float red, float green, float blue, float alpha=1.0f)
Definition: Board.cpp:287
void drawCircle(double x, double y, double radius, int depthValue=-1)
Definition: Board.cpp:450
Shape & translate(double dx, double dy)
Definition: Board.cpp:175
void fillGouraudTriangle(const double x1, const double y1, const float brightness1, const double x2, const double y2, const float brightness2, const double x3, const double y3, const float brightness3, unsigned char divisions=3, int depthValue=-1)
void fillRectangle(double x, double y, double width, double height, int depthValue=-1)
Definition: Board.cpp:438
Board translated(double dx, double dy)
Definition: Board.cpp:220
Shape & rotate(double angle, const Point &center)
Definition: Board.cpp:159
void addDuplicates(const Shape &shape, unsigned int times, double dx, double dy, double scale=1.0)
Definition: Board.cpp:766
Board scaled(double sx, double sy)
Definition: Board.cpp:226
void drawText(double x, double y, const char *text, int depthValue=-1)
Definition: Board.cpp:692
Board & setFillColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
Definition: Board.cpp:304
Board & setFillColor(const DGtal::Color &color)
Definition: Board.cpp:321
Board & setLineWidth(double width)
Definition: Board.cpp:328
void fillEllipse(double x, double y, double xRadius, double yRadius, int depthValue=-1)
Definition: Board.cpp:496
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:804
void fillGouraudTriangle(const double x1, const double y1, const DGtal::Color &color1, const double x2, const double y2, const DGtal::Color &color2, const double x3, const double y3, const DGtal::Color &color3, unsigned char divisions=3, int depthValue=-1)
void backgroundColor(const DGtal::Color &color)
Definition: Board.cpp:350
void drawImage(std::string filename, double x, double y, double width, double height, int depthValue=-1, double alpha=1.0)
Definition: Board.cpp:427
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1011
Board & setFillColorRGBf(float red, float green, float blue, float alpha=1.0f)
Definition: Board.cpp:314
Board(const DGtal::Color &backgroundColor=DGtal::Color::None)
Definition: Board.cpp:103
void setUnit(Unit unit)
Definition: Board.cpp:239
Path _clippingPath
Definition: Board.h:957
Shape & scale(double sx, double sy)
Definition: Board.cpp:183
Board rotated(double angle, const Point &center)
Definition: Board.cpp:208
void drawBoundingBox(int depthValue=-1)
Definition: Board.cpp:709
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1138
double unit(const double &x)
Definition: Board.h:951
DGtal::Color penColor
Definition: Board.h:941
Shape::LineJoin lineJoin
Definition: Board.h:946
Shape::LineCap lineCap
Definition: Board.h:945
Fonts::Font font
Definition: Board.h:947
void unit(Shape &shape)
Definition: Board.h:953
Shape::LineStyle lineStyle
Definition: Board.h:944
DGtal::Color fillColor
Definition: Board.h:942
Point unit(const Point &p)
Definition: Board.h:952
A path, according to Postscript and SVG definition.
Definition: Path.h:43
Struct representing a 2D point.
Definition: Point.h:27
A group of shapes.
Definition: ShapeList.h:28
Point center() const
Definition: ShapeList.cpp:192
ShapeList & clear()
Definition: ShapeList.cpp:43
Abstract structure for a 2D shape.
Definition: Board/Shapes.h:58
virtual void scaleAll(double s)=0
bool filled() const
Definition: Board/Shapes.h:111
MyPointD Point
Definition: testClone2.cpp:383