DGtal 1.4.0
Loading...
Searching...
No Matches
dgtalBoard2D-4-colormaps.cpp
Go to the documentation of this file.
1
40#include <cmath>
41#include <iostream>
42#include "DGtal/base/Common.h"
43#include "DGtal/io/boards/Board2D.h"
44#include "DGtal/io/Color.h"
45#include "DGtal/io/colormaps/GradientColorMap.h"
46#include "DGtal/shapes/Shapes.h"
47#include "DGtal/helpers/StdDefs.h"
49
50using namespace std;
51using namespace DGtal;
52using namespace Z2i;
53
55
56int main()
57{
58 trace.beginBlock ( "Example dgtalBoard2D-4-colormaps" );
59
60 Point p1( -10, -7 );
61 Point p2( 10, 7 );
62 Domain domain( p1, p2 );
63 Point c1( -5, -1 );
64 Point c2( 5, 1 );
65 DigitalSet shape_set( domain );
66 Shapes<Domain>::addNorm1Ball( shape_set, c1, 5 );
67 Shapes<Domain>::addNorm1Ball( shape_set, c2, 5 );
68 shape_set.erase( c1 );
69 shape_set.erase( c2 );
70
71 // Creating colormap.
72 GradientColorMap<int> cmap_grad( 0, 15 );
73 cmap_grad.addColor( Color( 50, 50, 255 ) );
74 cmap_grad.addColor( Color( 255, 0, 0 ) );
75 cmap_grad.addColor( Color( 255, 255, 10 ) );
76
77 // Creating board.
78 Board2D board;
79 board << SetMode( domain.className(), "Paving" )
80 << domain
81 << SetMode( p1.className(), "Paving" );
82 // This is the name of the style for a Point in mode "Paving".
83 string specificStyle = p1.className() + "/Paving";
84 for ( DigitalSet::ConstIterator it = shape_set.begin();
85 it != shape_set.end();
86 ++it )
87 {
88 unsigned int d = (unsigned int) ceil( ( *it - c1 ).norm() );
89 // specific color depending on the distance to point c1.
90 board << CustomStyle( specificStyle,
92 cmap_grad( d ) ) )
93 << *it;
94 }
95 board.saveSVG( "dgtalBoard2D-4-colormaps.svg");
96 board.saveEPS( "dgtalBoard2D-4-colormaps.eps");
97 board.saveTikZ( "dgtalBoard2D-4-colormaps.tikz");
98
99#ifdef WITH_CAIRO
100 board.saveCairo("dgtalBoard2D-4-colormaps-cairo.pdf", Board2D::CairoPDF);
101 board.saveCairo("dgtalBoard2D-4-colormaps-cairo.png", Board2D::CairoPNG);
102 board.saveCairo("dgtalBoard2D-4-colormaps-cairo.ps", Board2D::CairoPS);
103 board.saveCairo("dgtalBoard2D-4-colormaps-cairo.svg", Board2D::CairoSVG);
104#endif
105
106 trace.endBlock();
107 return 0;
108}
109// //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition Board2D.h:71
Structure representing an RGB triple with alpha component.
Definition Color.h:68
static const Color Black
Definition Color.h:413
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Container::const_iterator ConstIterator
ConstIterator type of the container;.
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
std::string className() const
std::string className() const
static void addNorm1Ball(TDigitalSet &aSet, const Point &aCenter, UnsignedInteger aRadius)
void beginBlock(const std::string &keyword="")
double endBlock()
void saveTikZ(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:1218
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:804
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:1011
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:1138
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition Common.h:153
STL namespace.
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition Board2D.h:279
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition Board2D.h:247
Domain domain