dgtalboard-3-custom-points.cpp

This example shows you how to modify the style of each drawable elements. It is a matter of creating a custom style class which gives in its method selfDraw the specific style parameters. Then, you attach this style to your drawable elements with an instance of CustomStyle outputed in the DGtalBoard stream.

//LICENSE-END

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

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

struct MyDrawStyleCustomColor : public DrawableWithDGtalBoard
{
  DGtalBoard::Color myPenColor;
  DGtalBoard::Color myFillColor;
  MyDrawStyleCustomColor( const DGtalBoard::Color & penColor,
                          const DGtalBoard::Color & fillColor )
    : myPenColor( penColor ), myFillColor( fillColor )
  {}

  virtual void selfDraw( DGtalBoard & aboard) const
  {
    aboard.setFillColor( myFillColor);
    aboard.setPenColor( myPenColor );
  }
};

int main( int argc, char** argv )
{
  trace.beginBlock ( "Example dgtalboard-3-custom-points" );

  Point p1( -3, -2 );
  Point p2( 7, 3 );
  Point p3( 0, 0 );
  Domain domain( p1, p2 );

  DGtalBoard::Color red( 255, 0, 0 );
  DGtalBoard::Color dred( 192, 0, 0 );
  DGtalBoard::Color green( 0, 255, 0 );
  DGtalBoard::Color dgreen( 0, 192, 0 );
  DGtalBoard::Color blue( 0, 0, 255 );
  DGtalBoard::Color dblue( 0, 0, 192 );
  
  DGtalBoard board;
  board << domain 
        << CustomStyle( p1.styleName(), new MyDrawStyleCustomColor( red, dred ) )
        << p1
        << CustomStyle( p2.styleName(), new MyDrawStyleCustomColor( green, dgreen ) )
        << p2
        << CustomStyle( p3.styleName(), new MyDrawStyleCustomColor( blue, dblue ) )
        << p3;
  board.saveSVG("dgtalboard-3-custom-points.svg");
  board.saveEPS("dgtalboard-3-custom-points.eps");
  
  trace.endBlock();
  return 0;
}
//                                                                           //