DGtal 0.3.0

Board.h

Go to the documentation of this file.
00001 /* -*- mode: c++ -*- */
00009 /*
00010  * \@copyright This File is part of the Board library which is
00011  * licensed under the terms of the GNU Lesser General Public Licence.
00012  * See the LICENCE file for further details.
00013  */
00014 #ifndef _BOARD_BOARD_H_
00015 #define _BOARD_BOARD_H_
00016 
00017 #include <ostream>
00018 #include <string>
00019 #include <vector>
00020 
00021 #include "Board/Point.h"
00022 #include "Board/Path.h"
00023 #include "Board/Shapes.h"
00024 #include "Board/ShapeList.h"
00025 
00026 namespace LibBoard {
00027 
00033 class Board : public ShapeList {
00034   
00035 public:
00036 
00037   enum PageSize { BoundingBox, A4, Letter };
00038   enum Unit { UPoint, UInche, UCentimeter, UMillimeter };
00039   static const double Degree;
00040   
00046   Board( const Color & backgroundColor = Color::None );
00047 
00053   Board( const Board & other );
00054 
00055   ~Board();
00056 
00064   Board & operator=( const Board & other );
00065 
00066 
00074   Board & operator<<( const Shape & shape );
00075 
00083   Board & operator<<( Unit unit );
00084   
00090   void clear( const Color & color = Color::None );
00091 
00099   void clear( unsigned char red, unsigned char green, unsigned char blue );
00100 
00101   Shape & rotate( double angle, const Point & center );
00102 
00103   Shape & rotate( double angle );
00104 
00105   Shape & translate( double dx, double dy );
00106 
00107   Shape & scale( double sx, double sy );
00108 
00109   Shape & scale( double s );
00110 
00111   Board rotated( double angle, const Point & center );
00112 
00113   Board rotated( double angle );
00114 
00115   Board translated( double dx, double dy );
00116 
00117   Board scaled( double sx, double sy );
00118 
00119   Board scaled( double s );
00120 
00126   void setUnit( Unit unit );
00127 
00134   void setUnit( double factor, Unit unit );
00135 
00143   void drawDot( double x, double y, int depthValue = -1 );
00144 
00154   void drawLine( double x1, double y1, double x2, double y2, 
00155                  int depthValue = -1 );
00156 
00167   void drawArrow( double x1, double y1, double x2, double y2,
00168                   bool filled = true,
00169                   int depthValue = -1 );
00170 
00182   void drawTriangle( double x1, double y1, 
00183                      double x2, double y2, 
00184                      double x3, double y3, 
00185                      int depthValue = -1 );
00186 
00195   void drawTriangle( const Point & p1,
00196                      const Point & p2, 
00197                      const Point & p3, 
00198                      int depthValue = -1 );
00199 
00211   void fillTriangle( double x1, double y1, 
00212                      double x2, double y2, 
00213                      double x3, double y3, 
00214                      int depthValue = -1 );
00215 
00228   void fillGouraudTriangle( const Point & p1,
00229                             const Color & color1,
00230                             const Point & p2,
00231                             const Color & color2,
00232                             const Point & p3,
00233                             const Color & color3,
00234                             unsigned char divisions = 3,
00235                             int depthValue = -1 );
00236 
00252   void fillGouraudTriangle( const double x1, const double y1,
00253                             const Color & color1,
00254                             const double x2, const double y2, 
00255                             const Color & color2,
00256                             const double x3, const double y3,
00257                             const Color & color3,
00258                             unsigned char divisions = 3,
00259                             int depthValue = -1 );
00260   
00273   void fillGouraudTriangle( const Point & p1,
00274                             const float brightness1,
00275                             const Point & p2,
00276                             const float brightness2,
00277                             const Point & p3,
00278                             const float brightness3,
00279                             unsigned char divisions = 3,
00280                             int depthValue = -1 );
00281 
00298   void fillGouraudTriangle( const double x1, const double y1,
00299                             const float brightness1,
00300                             const double x2, const double y2, 
00301                             const float brightness2,
00302                             const double x3, const double y3,
00303                             const float brightness3,
00304                             unsigned char divisions = 3,
00305                             int depthValue = -1 );
00306   
00307 
00316   void fillTriangle( const Point & p1,
00317                      const Point & p2, 
00318                      const Point & p3, 
00319                      int depthValue = -1 );
00320   
00330   void drawRectangle( double x, double y, 
00331                       double width, double height,
00332                       int depthValue = -1 );
00342   void drawImage( std::string filename, double x, double y, 
00343                       double width, double height,
00344                       int depthValue = -1 );
00345 
00355   void fillRectangle( double x, double y,
00356                       double width, double height,
00357                       int depthValue = -1 );
00358 
00367   void drawCircle( double x, double y, double radius,
00368                    int depthValue = -1 );
00369  
00378   void fillCircle( double x, double y, double radius,
00379                    int depthValue = -1);
00380 
00389   void drawEllipse( double x, double y, 
00390                     double xRadius, double yRadius,
00391                     int depthValue = -1);
00392  
00402   void fillEllipse( double x, double y, 
00403                     double xRadius, double yRadius,
00404                     int depthValue = -1);
00405 
00412   void drawPolyline( const std::vector<Point> & points,
00413                      int depthValue = -1 );
00414   
00421   void drawClosedPolyline( const std::vector<Point> & points,
00422                            int depthValue = -1 );
00423 
00430   void fillPolyline( const std::vector<Point> & points,
00431                      int depthValue = -1 );
00432     
00441   void drawText( double x, double y, const char * text, 
00442                  int depthValue = -1 );
00443 
00452   void drawText( double x, double y, const std::string & str, 
00453                  int depthValue = -1 );
00454 
00462   Board & setFont( const Fonts::Font font, double fontSize );
00463   
00470   Board & setFontSize( double fontSize ); 
00471 
00480   Board & setPenColorRGBi( unsigned char red,
00481                            unsigned char green,
00482                            unsigned char blue,
00483                            unsigned char alpha = 255 );
00484 
00494   Board & setPenColorRGBf(  float red,
00495                             float green,
00496                             float blue, 
00497                             float alpha = 1.0f );
00498 
00506   Board & setPenColor( const Color & color );
00507   
00508 
00518   Board & setFillColorRGBi( unsigned char red,
00519                             unsigned char green,
00520                             unsigned char blue,
00521                             unsigned char alpha = 255 );
00522   
00532   Board & setFillColorRGBf( float red, float green, float blue, float alpha = 1.0f );
00533 
00541   Board & setFillColor( const Color & color );
00542   
00549   Board & setLineWidth( double width );
00550 
00557   Board & setLineStyle( Shape::LineStyle style );
00558   
00567   Board & setLineCap( Shape::LineCap cap ); 
00568  
00577   Board & setLineJoin( Shape::LineJoin join );
00578 
00584   void backgroundColor( const Color & color );
00585 
00591   void drawBoundingBox( int depthValue = -1 );
00592 
00593 
00602   void setClippingRectangle(  double x, double y, 
00603                               double width, double height );
00604 
00610   void setClippingPath(  const std::vector<Point> & points  );
00611 
00617   void setClippingPath( const Path & path );
00618 
00629   void addDuplicates( const Shape & shape,
00630                       unsigned int times,
00631                       double dx, double dy, double scale = 1.0 );
00632 
00646   void addDuplicates( const Shape & shape,
00647                       unsigned int times,
00648                       double dx, double dy,
00649                       double scaleX, 
00650                       double scaleY,
00651                       double angle = 0.0 );
00652 
00662   void save( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const; 
00663   
00674   void save( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const; 
00675 
00684   void saveEPS( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const ;
00685 
00696   void saveEPS( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
00697 
00706   void saveFIG( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
00707 
00718   void saveFIG( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
00719 
00728   void saveSVG( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
00729 
00740   void saveSVG( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
00741 
00742  protected:
00743 
00748   struct State {
00749     Color penColor;                     
00750     Color fillColor;                
00751     double lineWidth;               
00752     Shape::LineStyle lineStyle; 
00753     Shape::LineCap lineCap;         
00754     Shape::LineJoin lineJoin;   
00755     Fonts::Font font;           
00756     double fontSize;                    
00757     double unitFactor;              
00758     State();
00759     double unit( const double & x ) { return x * unitFactor; }
00760     Point unit( const Point & p ) { return Point( p.x * unitFactor, p.y * unitFactor); }
00761     void unit( Shape & shape ) {  shape.scaleAll( unitFactor ); }
00762   };
00763   State _state;                  
00764   Color _backgroundColor;        
00765   Path _clippingPath;
00766 };
00767 
00768 } // namespace LibBoard
00769 
00770 #include "Board.ih"
00771 
00772 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines