dgtalboard-2-sets.cpp

This simple example shows also some basic usage of a DGtalBoard to export graphical representations of dgtal objects (here, a digital set and a digital object). Note also the use of different modes that may be defined for some classes. An object may thus be displayed just as a set of points, but also as a set of points with neighborhood structure (a graph).


#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/io/DGtalBoard.h"
#include "DGtal/helpers/Shapes.h"
#include "DGtal/helpers/StdDefs.h"

using namespace std;
using namespace DGtal;
using namespace Z2i;


int main( int argc, char** argv )
{
  trace.beginBlock ( "Example dgtalboard-2-sets" );

  Point p1( -10, -7 );
  Point p2( 10, 7 );
  Domain domain( p1, p2 );
  DigitalSet shape_set( domain );
  Shapes<Domain>::addNorm1Ball( shape_set, Point( -5, -1 ), 5 );
  Shapes<Domain>::addNorm1Ball( shape_set, Point( 5, 1 ), 5 );
  shape_set.erase( Point( -5, -1 ) );
  shape_set.erase( Point( 5, 1 ) );

  DGtalBoard board;
  board << domain << shape_set; // display domain and set
  board.saveSVG( "dgtalboard-2-sets-1.svg");
  board.saveEPS( "dgtalboard-2-sets-1.eps");
  board.clear();

  // Object with couple (4,8) of adjacency.
  Object4_8 shape( dt4_8, shape_set );
  board << domain // display domain
        << SetMode( shape.styleName(), "DrawAdjacencies" )
        << shape; // and object with mode "DrawAdjacencies"
  board.saveSVG( "dgtalboard-2-sets-2.svg");
  board.saveEPS( "dgtalboard-2-sets-2.eps");
  board.clear();

  // Object with couple (8,4) of adjacency.
  Object8_4 shape2( dt8_4, shape_set );
  board << domain // display domain
        << SetMode( shape2.styleName(), "DrawAdjacencies" )
        << shape2; // and object with mode "DrawAdjacencies"
  board.saveSVG( "dgtalboard-2-sets-3.svg");
  board.saveEPS( "dgtalboard-2-sets-3.eps");

  trace.endBlock();
  return 0;
}
//                                                                           //