dgtalboard-5-greedy-dss.cpp

Another example where the specific mode style of the drawable element ArithmeticDSS is redefined.


#include <cmath>
#include <iostream>
#include <sstream>
#include "DGtal/base/Common.h"
#include "DGtal/io/DGtalBoard.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/helpers/Shapes.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/2d/ArithmeticalDSS.h"
#include "DGtal/geometry/2d/FreemanChain.h"
#include "DGtal/geometry/2d/GreedyDecomposition.h"

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


int main( int argc, char** argv )
{
  trace.beginBlock ( "Example dgtalboard-5-greedy-dss" );

  typedef ArithmeticalDSS<StandardBase<int> > DSS;
  typedef FreemanChain<int> ContourType; 
  typedef GreedyDecomposition< ContourType, DSS > Decomposition;
  // A Freeman chain code is a string composed by the coordinates of the first pixel, and the list of elementary displacements. 
  std::stringstream ss(stringstream::in | stringstream::out);
  ss << "31 16 11121212121212212121212212122122222322323233323333333323333323303330330030300000100010010010001000101010101111" << endl;
  
  // Construct the Freeman chain
  ContourType theContour( ss );
  //Segmentation
  Decomposition theDecomposition( theContour );
  Point p1( 0, 0 );
  Point p2( 31, 31 );
  Domain domain( p1, p2 );
  DGtalBoard aBoard;
  aBoard << SetMode( domain.styleName(), "Grid" )
         << domain
         << theContour;
  //for each segment
  DSS segment;
  aBoard << SetMode( segment.styleName(), "BoundingBox" );
  string styleName = segment.styleName() + "/BoundingBox";
  for ( Decomposition::ConstIterator i = theDecomposition.begin();
        i != theDecomposition.end(); ++i ) 
    {
      segment = *i;
      aBoard << CustomStyle( styleName, 
                             new CustomPenColor( DGtalBoard::Color::Blue ) )
             << segment; // draw each segment
    } 
  aBoard.saveSVG("dgtalboard-5-greedy-dss.svg");
  aBoard.saveSVG("dgtalboard-5-greedy-dss.eps");

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