DGtal 1.3.0
Loading...
Searching...
No Matches
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
trace.endBlock();
return 0;
}
// //
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
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
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:1219
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
DGtal is the top-level namespace which contains all DGtal functions and types.
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
int main()
Definition: testBits.cpp:56
MyPointD Point
Definition: testClone2.cpp:383
Domain domain
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet