DGtal  1.0.0
dgtalBoard2D-4-colormaps.cpp
Go to the documentation of this file.
1 
39 #include <cmath>
41 #include <iostream>
42 #include "DGtal/base/Common.h"
43 #include "DGtal/io/boards/Board2D.h"
44 #include "DGtal/io/Color.h"
45 #include "DGtal/io/colormaps/GradientColorMap.h"
46 #include "DGtal/shapes/Shapes.h"
47 #include "DGtal/helpers/StdDefs.h"
49 
50 using namespace std;
51 using namespace DGtal;
52 using namespace Z2i;
53 
55 
56 int main()
57 {
58  trace.beginBlock ( "Example dgtalBoard2D-4-colormaps" );
59 
60  Point p1( -10, -7 );
61  Point p2( 10, 7 );
62  Domain domain( p1, p2 );
63  Point c1( -5, -1 );
64  Point c2( 5, 1 );
65  DigitalSet shape_set( domain );
66  Shapes<Domain>::addNorm1Ball( shape_set, c1, 5 );
67  Shapes<Domain>::addNorm1Ball( shape_set, c2, 5 );
68  shape_set.erase( c1 );
69  shape_set.erase( c2 );
70 
71  // Creating colormap.
72  GradientColorMap<int> cmap_grad( 0, 15 );
73  cmap_grad.addColor( Color( 50, 50, 255 ) );
74  cmap_grad.addColor( Color( 255, 0, 0 ) );
75  cmap_grad.addColor( Color( 255, 255, 10 ) );
76 
77  // Creating board.
78  Board2D board;
79  board << SetMode( domain.className(), "Paving" )
80  << domain
81  << SetMode( p1.className(), "Paving" );
82  // This is the name of the style for a Point in mode "Paving".
83  string specificStyle = p1.className() + "/Paving";
84  for ( DigitalSet::ConstIterator it = shape_set.begin();
85  it != shape_set.end();
86  ++it )
87  {
88  unsigned int d = (unsigned int) ceil( ( *it - c1 ).norm() );
89  // specific color depending on the distance to point c1.
90  board << CustomStyle( specificStyle,
91  new CustomColors( Color::Black,
92  cmap_grad( d ) ) )
93  << *it;
94  }
95  board.saveSVG( "dgtalBoard2D-4-colormaps.svg");
96  board.saveEPS( "dgtalBoard2D-4-colormaps.eps");
97  board.saveTikZ( "dgtalBoard2D-4-colormaps.tikz");
98 
99 #ifdef WITH_CAIRO
100  board.saveCairo("dgtalBoard2D-4-colormaps-cairo.pdf", Board2D::CairoPDF);
101  board.saveCairo("dgtalBoard2D-4-colormaps-cairo.png", Board2D::CairoPNG);
102  board.saveCairo("dgtalBoard2D-4-colormaps-cairo.ps", Board2D::CairoPS);
103  board.saveCairo("dgtalBoard2D-4-colormaps-cairo.svg", Board2D::CairoSVG);
104 #endif
105 
106  trace.endBlock();
107  return 0;
108 }
109 // //
void beginBlock(const std::string &keyword="")
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
MyDigitalSurface::ConstIterator ConstIterator
Trace trace
Definition: Common.h:144
void addColor(const Color &color)
double endBlock()
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
Domain domain
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
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
std::string className() const
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
std::string className() const
Definition: Board2D.h:197
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
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).
void saveTikZ(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1219
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:70