DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dgtalBoard2D-4-colormaps.cpp
1 
30 
31 #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 // //