DGtal  1.4.beta
io/boards/dgtalBoard2D-4-colormaps.cpp

This example shows you how to use colormaps with Board2D streams. Note how we redefine the style of a specific mode for the drawable element.

visualization of resulting export.
#include <cmath>
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/helpers/StdDefs.h"
using namespace std;
using namespace DGtal;
using namespace Z2i;
int main()
{
trace.beginBlock ( "Example dgtalBoard2D-4-colormaps" );
Point p1( -10, -7 );
Point p2( 10, 7 );
Domain domain( p1, p2 );
Point c1( -5, -1 );
Point c2( 5, 1 );
DigitalSet shape_set( domain );
Shapes<Domain>::addNorm1Ball( shape_set, c1, 5 );
Shapes<Domain>::addNorm1Ball( shape_set, c2, 5 );
shape_set.erase( c1 );
shape_set.erase( c2 );
// Creating colormap.
GradientColorMap<int> cmap_grad( 0, 15 );
cmap_grad.addColor( Color( 50, 50, 255 ) );
cmap_grad.addColor( Color( 255, 0, 0 ) );
cmap_grad.addColor( Color( 255, 255, 10 ) );
// Creating board.
Board2D board;
board << SetMode( domain.className(), "Paving" )
<< domain
<< SetMode( p1.className(), "Paving" );
// This is the name of the style for a Point in mode "Paving".
string specificStyle = p1.className() + "/Paving";
for ( DigitalSet::ConstIterator it = shape_set.begin();
it != shape_set.end();
++it )
{
unsigned int d = (unsigned int) ceil( ( *it - c1 ).norm() );
// specific color depending on the distance to point c1.
board << CustomStyle( specificStyle,
new CustomColors( Color::Black,
cmap_grad( d ) ) )
<< *it;
}
board.saveSVG( "dgtalBoard2D-4-colormaps.svg");
board.saveEPS( "dgtalBoard2D-4-colormaps.eps");
board.saveTikZ( "dgtalBoard2D-4-colormaps.tikz");
#ifdef WITH_CAIRO
board.saveCairo("dgtalBoard2D-4-colormaps-cairo.pdf", Board2D::CairoPDF);
board.saveCairo("dgtalBoard2D-4-colormaps-cairo.png", Board2D::CairoPNG);
board.saveCairo("dgtalBoard2D-4-colormaps-cairo.ps", Board2D::CairoPS);
board.saveCairo("dgtalBoard2D-4-colormaps-cairo.svg", Board2D::CairoSVG);
#endif
return 0;
}
// //
void beginBlock(const std::string &keyword="")
double endBlock()
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
int main(int argc, char **argv)
MyPointD Point
Definition: testClone2.cpp:383
Domain domain
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet