DGtal  0.9.2
dgtalBoard2D-4-colormaps.cpp
1 
30 #include <cmath>
32 #include <iostream>
33 #include "DGtal/base/Common.h"
34 #include "DGtal/io/boards/Board2D.h"
35 #include "DGtal/io/Color.h"
36 #include "DGtal/io/colormaps/GradientColorMap.h"
37 #include "DGtal/shapes/Shapes.h"
38 #include "DGtal/helpers/StdDefs.h"
40 
41 using namespace std;
42 using namespace DGtal;
43 using namespace Z2i;
44 
46 
47 int main()
48 {
49  trace.beginBlock ( "Example dgtalBoard2D-4-colormaps" );
50 
51  Point p1( -10, -7 );
52  Point p2( 10, 7 );
53  Domain domain( p1, p2 );
54  Point c1( -5, -1 );
55  Point c2( 5, 1 );
56  DigitalSet shape_set( domain );
57  Shapes<Domain>::addNorm1Ball( shape_set, c1, 5 );
58  Shapes<Domain>::addNorm1Ball( shape_set, c2, 5 );
59  shape_set.erase( c1 );
60  shape_set.erase( c2 );
61 
62  // Creating colormap.
63  GradientColorMap<int> cmap_grad( 0, 15 );
64  cmap_grad.addColor( Color( 50, 50, 255 ) );
65  cmap_grad.addColor( Color( 255, 0, 0 ) );
66  cmap_grad.addColor( Color( 255, 255, 10 ) );
67 
68  // Creating board.
69  Board2D board;
70  board << SetMode( domain.className(), "Paving" )
71  << domain
72  << SetMode( p1.className(), "Paving" );
73  // This is the name of the style for a Point in mode "Paving".
74  string specificStyle = p1.className() + "/Paving";
75  for ( DigitalSet::ConstIterator it = shape_set.begin();
76  it != shape_set.end();
77  ++it )
78  {
79  unsigned int d = (unsigned int) ceil( ( *it - c1 ).norm() );
80  // specific color depending on the distance to point c1.
81  board << CustomStyle( specificStyle,
82  new CustomColors( Color::Black,
83  cmap_grad( d ) ) )
84  << *it;
85  }
86  board.saveSVG( "dgtalBoard2D-4-colormaps.svg");
87  board.saveEPS( "dgtalBoard2D-4-colormaps.eps");
88  board.saveTikZ( "dgtalBoard2D-4-colormaps.tikz");
89 
90 #ifdef WITH_CAIRO
91  board.saveCairo("dgtalBoard2D-4-colormaps-cairo.pdf", Board2D::CairoPDF);
92  board.saveCairo("dgtalBoard2D-4-colormaps-cairo.png", Board2D::CairoPNG);
93  board.saveCairo("dgtalBoard2D-4-colormaps-cairo.ps", Board2D::CairoPS);
94  board.saveCairo("dgtalBoard2D-4-colormaps-cairo.svg", Board2D::CairoSVG);
95 #endif
96 
97  trace.endBlock();
98  return 0;
99 }
100 // //
void beginBlock(const std::string &keyword="")
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Trace trace
Definition: Common.h:130
STL namespace.
double endBlock()
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
std::string className() const
void saveTikZ(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1219
DGtal is the top-level namespace which contains all DGtal functions and types.
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
std::string className() const
Definition: Board2D.h:197
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70