DGtal  1.3.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;
}
// //
ConstIterator
MyDigitalSurface::ConstIterator ConstIterator
Definition: greedy-plane-segmentation-ex2.cpp:93
DGtal::HyperRectDomain< Space >
DGtal::Trace::endBlock
double endBlock()
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::HyperRectDomain::className
std::string className() const
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::CustomStyle
Definition: Board2D.h:217
DGtal::Z2i::DigitalSet
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::CustomColors
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
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::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:70
DGtal::Shapes
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
Definition: DGtal/shapes/Shapes.h:71
DGtal::GradientColorMap::addColor
void addColor(const Color &color)
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::SetMode
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::GradientColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition: GradientColorMap.h:119