DGtal  0.9.2
dgtalBoard2D-3-custom-points.cpp
1 
16 //LICENSE-END
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/io/Color.h"
34 #include "DGtal/io/boards/Board2D.h"
35 #include "DGtal/helpers/StdDefs.h"
37 
38 using namespace std;
39 using namespace DGtal;
40 using namespace DGtal::Z2i;
41 
43 struct MyDrawStyleCustomColor : public DrawableWithBoard2D
44 {
45  Color myPenColor;
46  Color myFillColor;
47  MyDrawStyleCustomColor( const Color & penColor,
48  const Color & fillColor )
49  : myPenColor( penColor ), myFillColor( fillColor )
50  {}
51 
52  virtual void setStyle( Board2D & aboard) const
53  {
54  aboard.setFillColor( myFillColor);
55  aboard.setPenColor( myPenColor );
56  }
57 };
58 
59 int main()
60 {
61  trace.beginBlock ( "Example dgtalBoard2D-3-custom-points" );
62 
63  Point p1( -3, -2 );
64  Point p2( 7, 3 );
65  Point p3( 0, 0 );
66  Domain domain( p1, p2 );
67 
68  Color red( 255, 0, 0 );
69  Color dred( 192, 0, 0 );
70  Color green( 0, 255, 0 );
71  Color dgreen( 0, 192, 0 );
72  Color blue( 0, 0, 255 );
73  Color dblue( 0, 0, 192 );
74 
75  Board2D board;
76  board << domain
77  << CustomStyle( p1.className(), new MyDrawStyleCustomColor( red, dred ) )
78  << p1
79  << CustomStyle( p2.className(), new MyDrawStyleCustomColor( green, dgreen ) )
80  << p2
81  << CustomStyle( p3.className(), new MyDrawStyleCustomColor( blue, dblue ) )
82  << p3;
83  board.saveSVG("dgtalBoard2D-3-custom-points.svg");
84  board.saveEPS("dgtalBoard2D-3-custom-points.eps");
85  board.saveTikZ("dgtalBoard2D-3-custom-points.tikz");
86 
87 #ifdef WITH_CAIRO
88  board.saveCairo("dgtalBoard2D-3-custom-points-cairo.pdf", Board2D::CairoPDF);
89  board.saveCairo("dgtalBoard2D-3-custom-points-cairo.png", Board2D::CairoPNG);
90  board.saveCairo("dgtalBoard2D-3-custom-points-cairo.ps", Board2D::CairoPS);
91  board.saveCairo("dgtalBoard2D-3-custom-points-cairo.svg", Board2D::CairoSVG);
92 #endif
93 
94  trace.endBlock();
95  return 0;
96 }
97 // //
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:130
STL namespace.
double endBlock()
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
void saveTikZ(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1219
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
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
Board & setPenColor(const DGtal::Color &color)
Definition: Board.cpp:298
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70