DGtal  1.3.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 
607  Board & setLineCap( Shape::LineCap cap );
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
LibBoard::Board::rotated
Board rotated(double angle, const Point &center)
Definition: Board.cpp:209
LibBoard::Board::setUnit
void setUnit(Unit unit)
Definition: Board.cpp:240
LibBoard::Board::setClippingPath
void setClippingPath(const std::vector< Point > &points)
Definition: Board.cpp:739
LibBoard::Board::setFont
Board & setFont(const Fonts::Font font, double fontSize)
Definition: Board.cpp:336
LibBoard::Board::A4
@ A4
Definition: Board.h:42
LibBoard::Shape::filled
bool filled() const
Definition: Board/Shapes.h:111
LibBoard::Board::CairoEPS
@ CairoEPS
Definition: Board.h:40
LibBoard::Board::CairoPDF
@ CairoPDF
Definition: Board.h:40
LibBoard::Board::_clippingPath
Path _clippingPath
Definition: Board.h:957
LibBoard::Board::setPenColor
Board & setPenColor(const DGtal::Color &color)
Definition: Board.cpp:298
LibBoard::Board::drawBoundingBox
void drawBoundingBox(int depthValue=-1)
Definition: Board.cpp:710
LibBoard::Board::State::unit
double unit(const double &x)
Definition: Board.h:951
LibBoard::Board::setPenColorRGBi
Board & setPenColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
Definition: Board.cpp:278
LibBoard::Board::setLineCap
Board & setLineCap(Shape::LineCap cap)
LibBoard::Board::save
void save(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1132
LibBoard::Board::UCentimeter
@ UCentimeter
Definition: Board.h:43
LibBoard::Board::addDuplicates
void addDuplicates(const Shape &shape, unsigned int times, double dx, double dy, double scale=1.0)
Definition: Board.cpp:767
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
LibBoard::Board::fillPolyline
void fillPolyline(const std::vector< Point > &points, int depthValue=-1)
Definition: Board.cpp:551
LibBoard::Board::drawText
void drawText(double x, double y, const char *text, int depthValue=-1)
Definition: Board.cpp:693
LibBoard::Board
Class for EPS, FIG or SVG drawings.
Definition: Board.h:35
LibBoard::Board::drawDot
void drawDot(double x, double y, int depthValue=-1)
Definition: Board.cpp:357
LibBoard::Board::saveCairo
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
LibBoard::Board::State::unitFactor
double unitFactor
Definition: Board.h:949
LibBoard::Board::setFillColorRGBi
Board & setFillColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
Definition: Board.cpp:305
LibBoard::Board::CairoType
CairoType
Definition: Board.h:40
LibBoard::Board::drawClosedPolyline
void drawClosedPolyline(const std::vector< Point > &points, int depthValue=-1)
Definition: Board.cpp:531
LibBoard::Board::drawPolyline
void drawPolyline(const std::vector< Point > &points, int depthValue=-1)
Definition: Board.cpp:511
LibBoard::Shape::LineCap
LineCap
Definition: Board/Shapes.h:60
LibBoard::Board::fillEllipse
void fillEllipse(double x, double y, double xRadius, double yRadius, int depthValue=-1)
Definition: Board.cpp:497
LibBoard::Board::State::unit
Point unit(const Point &p)
Definition: Board.h:952
LibBoard::Board::drawRectangle
void drawRectangle(double x, double y, double width, double height, int depthValue=-1)
Definition: Board.cpp:417
LibBoard::Board::Unit
Unit
Definition: Board.h:43
LibBoard::Board::_backgroundColor
DGtal::Color _backgroundColor
Definition: Board.h:956
LibBoard::Board::scaled
Board scaled(double sx, double sy)
Definition: Board.cpp:227
LibBoard::Board::operator=
Board & operator=(const Board &other)
Definition: Board.cpp:117
LibBoard::Board::translated
Board translated(double dx, double dy)
Definition: Board.cpp:221
LibBoard::Board::setLineStyle
Board & setLineStyle(Shape::LineStyle style)
LibBoard::Board::drawArrow
void drawArrow(double x1, double y1, double x2, double y2, bool filled=true, int depthValue=-1)
Definition: Board.cpp:400
LibBoard::Board::State::lineWidth
double lineWidth
Definition: Board.h:943
LibBoard::Board::fillRectangle
void fillRectangle(double x, double y, double width, double height, int depthValue=-1)
Definition: Board.cpp:439
LibBoard::Board::setLineJoin
Board & setLineJoin(Shape::LineJoin join)
LibBoard::Board::fillTriangle
void fillTriangle(double x1, double y1, double x2, double y2, double x3, double y3, int depthValue=-1)
Definition: Board.cpp:609
LibBoard::Board::State::lineCap
Shape::LineCap lineCap
Definition: Board.h:945
LibBoard::Board::State::fontSize
double fontSize
Definition: Board.h:948
LibBoard::Board::setClippingRectangle
void setClippingRectangle(double x, double y, double width, double height)
Definition: Board.cpp:728
LibBoard::Point
Struct representing a 2D point.
Definition: Point.h:27
LibBoard::Fonts::Font
Font
Definition: PSFonts.h:37
LibBoard::Board::State::penColor
DGtal::Color penColor
Definition: Board.h:941
LibBoard::Board::CairoPS
@ CairoPS
Definition: Board.h:40
LibBoard::Board::State::lineStyle
Shape::LineStyle lineStyle
Definition: Board.h:944
LibBoard::Board::backgroundColor
void backgroundColor(const DGtal::Color &color)
Definition: Board.cpp:351
LibBoard::Board::fillGouraudTriangle
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:647
LibBoard::Board::setFontSize
Board & setFontSize(double fontSize)
Definition: Board.cpp:344
LibBoard::Board::drawImage
void drawImage(std::string filename, double x, double y, double width, double height, int depthValue=-1, double alpha=1.0)
Definition: Board.cpp:428
LibBoard::Board::BoundingBox
@ BoundingBox
Definition: Board.h:42
LibBoard::Board::drawQuadraticBezierCurve
void drawQuadraticBezierCurve(double x1, double y1, double x2, double y2, double x3, double y3, int depthValue=-1)
Definition: Board.cpp:384
LibBoard::Shape::LineJoin
LineJoin
Definition: Board/Shapes.h:61
LibBoard::Board::CairoSVG
@ CairoSVG
Definition: Board.h:40
LibBoard::Board::drawCircle
void drawCircle(double x, double y, double radius, int depthValue=-1)
Definition: Board.cpp:451
LibBoard::Board::~Board
~Board()
Definition: Board.cpp:146
LibBoard::Shape
Abstract structure for a 2D shape.
Definition: Board/Shapes.h:58
LibBoard::Board::Letter
@ Letter
Definition: Board.h:42
LibBoard::Board::setFillColorRGBf
Board & setFillColorRGBf(float red, float green, float blue, float alpha=1.0f)
Definition: Board.cpp:315
LibBoard::Board::Degree
static const double Degree
Definition: Board.h:44
LibBoard::Board::drawTriangle
void drawTriangle(double x1, double y1, double x2, double y2, double x3, double y3, int depthValue=-1)
Definition: Board.cpp:571
LibBoard::Board::Board
Board(const DGtal::Color &backgroundColor=DGtal::Color::None)
Definition: Board.cpp:104
LibBoard::Board::saveSVG
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
LibBoard::Board::CairoPNG
@ CairoPNG
Definition: Board.h:40
LibBoard::Path
A path, according to Postscript and SVG definition.
Definition: Path.h:43
LibBoard::Board::drawEllipse
void drawEllipse(double x, double y, double xRadius, double yRadius, int depthValue=-1)
Definition: Board.cpp:482
LibBoard::Board::fillCircle
void fillCircle(double x, double y, double radius, int depthValue=-1)
Definition: Board.cpp:471
LibBoard::Board::_state
State _state
Definition: Board.h:955
LibBoard
Definition: Board.cpp:87
LibBoard::ShapeList::clear
ShapeList & clear()
Definition: ShapeList.cpp:43
LibBoard::Board::UPoint
@ UPoint
Definition: Board.h:43
LibBoard::Board::saveFIG
void saveFIG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0, bool includeFIGHeader=true) const
Definition: Board.cpp:907
LibBoard::Board::State::fillColor
DGtal::Color fillColor
Definition: Board.h:942
LibBoard::Board::UMillimeter
@ UMillimeter
Definition: Board.h:43
LibBoard::ShapeList
A group of shapes.
Definition: ShapeList.h:28
LibBoard::ShapeList::center
Point center() const
Definition: ShapeList.cpp:192
LibBoard::Board::drawArc
void drawArc(double x, double y, double radius, double angle1, double angle2, bool neg, int depthValue=-1)
Definition: Board.cpp:461
LibBoard::Board::State
Definition: Board.h:940
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
LibBoard::Board::saveTikZ
void saveTikZ(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1219
LibBoard::Board::State::State
State()
Definition: Board.cpp:91
LibBoard::Board::operator<<
Board & operator<<(const Shape &shape)
Definition: Board.cpp:133
LibBoard::Board::rotate
Shape & rotate(double angle, const Point &center)
Definition: Board.cpp:160
LibBoard::Shape::LineStyle
LineStyle
Definition: Board/Shapes.h:62
LibBoard::Board::setPenColorRGBf
Board & setPenColorRGBf(float red, float green, float blue, float alpha=1.0f)
Definition: Board.cpp:288
LibBoard::Shape::scaleAll
virtual void scaleAll(double s)=0
DGtal::Color::None
static const Color None
Definition: Color.h:388
LibBoard::Board::setFillColor
Board & setFillColor(const DGtal::Color &color)
Definition: Board.cpp:322
LibBoard::Board::State::font
Fonts::Font font
Definition: Board.h:947
LibBoard::Board::PageSize
PageSize
Definition: Board.h:42
LibBoard::Board::setLineWidth
Board & setLineWidth(double width)
Definition: Board.cpp:329
LibBoard::Board::translate
Shape & translate(double dx, double dy)
Definition: Board.cpp:176
Point
MyPointD Point
Definition: testClone2.cpp:383
LibBoard::Board::State::lineJoin
Shape::LineJoin lineJoin
Definition: Board.h:946
LibBoard::Board::State::unit
void unit(Shape &shape)
Definition: Board.h:953
LibBoard::Board::drawLine
void drawLine(double x1, double y1, double x2, double y2, int depthValue=-1)
Definition: Board.cpp:368
LibBoard::Board::UInche
@ UInche
Definition: Board.h:43
LibBoard::Board::scale
Shape & scale(double sx, double sy)
Definition: Board.cpp:184