DGtal  1.3.beta
io/boards/dgtalBoard2D-3-custom-points.cpp

This example shows you how to modify the style of each drawable elements. It is a matter of creating a custom style class which gives in its method setStyle the specific style parameters. Then, you attach this style to your drawable elements with an instance of CustomStyle outputed in the Board2D stream.

visualization of resulting export.
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/helpers/StdDefs.h"
using namespace std;
using namespace DGtal;
using namespace DGtal::Z2i;
struct MyDrawStyleCustomColor : public DrawableWithBoard2D
{
Color myPenColor;
Color myFillColor;
MyDrawStyleCustomColor( const Color & penColor,
const Color & fillColor )
: myPenColor( penColor ), myFillColor( fillColor )
{}
virtual void setStyle( Board2D & aboard) const
{
aboard.setFillColor( myFillColor);
aboard.setPenColor( myPenColor );
}
};
int main()
{
trace.beginBlock ( "Example dgtalBoard2D-3-custom-points" );
Point p1( -3, -2 );
Point p2( 7, 3 );
Point p3( 0, 0 );
Domain domain( p1, p2 );
Color red( 255, 0, 0 );
Color dred( 192, 0, 0 );
Color green( 0, 255, 0 );
Color dgreen( 0, 192, 0 );
Color blue( 0, 0, 255 );
Color dblue( 0, 0, 192 );
Board2D board;
board << domain
<< CustomStyle( p1.className(), new MyDrawStyleCustomColor( red, dred ) )
<< p1
<< CustomStyle( p2.className(), new MyDrawStyleCustomColor( green, dgreen ) )
<< p2
<< CustomStyle( p3.className(), new MyDrawStyleCustomColor( blue, dblue ) )
<< p3;
board.saveSVG("dgtalBoard2D-3-custom-points.svg");
board.saveEPS("dgtalBoard2D-3-custom-points.eps");
board.saveTikZ("dgtalBoard2D-3-custom-points.tikz");
#ifdef WITH_CAIRO
board.saveCairo("dgtalBoard2D-3-custom-points-cairo.pdf", Board2D::CairoPDF);
board.saveCairo("dgtalBoard2D-3-custom-points-cairo.png", Board2D::CairoPNG);
board.saveCairo("dgtalBoard2D-3-custom-points-cairo.ps", Board2D::CairoPS);
board.saveCairo("dgtalBoard2D-3-custom-points-cairo.svg", Board2D::CairoSVG);
#endif
return 0;
}
// //
LibBoard::Board::setPenColor
Board & setPenColor(const DGtal::Color &color)
Definition: Board.cpp:298
DGtal::HyperRectDomain< Space >
DGtal::Trace::endBlock
double endBlock()
DGtal::Z2i
Z2i this namespace gathers the standard of types for 2D imagery.
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
LibBoard::Board::saveCairo
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::CustomStyle
Definition: Board2D.h:217
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
LibBoard::Board::saveSVG
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::DrawableWithBoard2D
Definition: Common.h:221
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:70
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
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::PointVector< dim, Integer >
LibBoard::Board::setFillColor
Board & setFillColor(const DGtal::Color &color)
Definition: Board.cpp:322