DGtal  0.9.3
dgtalBoard2D-3-custom-points.cpp
Go to the documentation of this file.
1 
42 #include <iostream>
44 #include "DGtal/base/Common.h"
45 #include "DGtal/io/Color.h"
46 #include "DGtal/io/boards/Board2D.h"
47 #include "DGtal/helpers/StdDefs.h"
49 
50 using namespace std;
51 using namespace DGtal;
52 using namespace DGtal::Z2i;
53 
55 struct MyDrawStyleCustomColor : public DrawableWithBoard2D
56 {
57  Color myPenColor;
58  Color myFillColor;
59  MyDrawStyleCustomColor( const Color & penColor,
60  const Color & fillColor )
61  : myPenColor( penColor ), myFillColor( fillColor )
62  {}
63 
64  virtual void setStyle( Board2D & aboard) const
65  {
66  aboard.setFillColor( myFillColor);
67  aboard.setPenColor( myPenColor );
68  }
69 };
70 
71 int main()
72 {
73  trace.beginBlock ( "Example dgtalBoard2D-3-custom-points" );
74 
75  Point p1( -3, -2 );
76  Point p2( 7, 3 );
77  Point p3( 0, 0 );
78  Domain domain( p1, p2 );
79 
80  Color red( 255, 0, 0 );
81  Color dred( 192, 0, 0 );
82  Color green( 0, 255, 0 );
83  Color dgreen( 0, 192, 0 );
84  Color blue( 0, 0, 255 );
85  Color dblue( 0, 0, 192 );
86 
87  Board2D board;
88  board << domain
89  << CustomStyle( p1.className(), new MyDrawStyleCustomColor( red, dred ) )
90  << p1
91  << CustomStyle( p2.className(), new MyDrawStyleCustomColor( green, dgreen ) )
92  << p2
93  << CustomStyle( p3.className(), new MyDrawStyleCustomColor( blue, dblue ) )
94  << p3;
95  board.saveSVG("dgtalBoard2D-3-custom-points.svg");
96  board.saveEPS("dgtalBoard2D-3-custom-points.eps");
97  board.saveTikZ("dgtalBoard2D-3-custom-points.tikz");
98 
99 #ifdef WITH_CAIRO
100  board.saveCairo("dgtalBoard2D-3-custom-points-cairo.pdf", Board2D::CairoPDF);
101  board.saveCairo("dgtalBoard2D-3-custom-points-cairo.png", Board2D::CairoPNG);
102  board.saveCairo("dgtalBoard2D-3-custom-points-cairo.ps", Board2D::CairoPS);
103  board.saveCairo("dgtalBoard2D-3-custom-points-cairo.svg", Board2D::CairoSVG);
104 #endif
105 
106  trace.endBlock();
107  return 0;
108 }
109 // //
void beginBlock(const std::string &keyword="")
const Domain domain(Point(1, 2), Point(6, 5))
Trace trace
Definition: Common.h:137
STL namespace.
double endBlock()
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
Z2i this namespace gathers the standard of types for 2D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
Board & setFillColor(const DGtal::Color &color)
Definition: Board.cpp:322
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
Board & setPenColor(const DGtal::Color &color)
Definition: Board.cpp:298
std::string className() const
void saveTikZ(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1219
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70