This example outputs a greedy segmentation of a closed and 4-connected digital curve into DSSs.
#include <cmath>
#include <iostream>
#include <sstream>
#include "DGtal/base/Common.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
#include "DGtal/geometry/curves/FreemanChain.h"
#include "DGtal/geometry/curves/GreedySegmentation.h"
using namespace std;
using namespace Z2i;
{
typedef FreemanChain<int> Contour4;
typedef ArithmeticalDSSComputer<Contour4::ConstIterator,int,4> DSS4;
typedef GreedySegmentation<DSS4> Decomposition4;
std::stringstream ss(stringstream::in | stringstream::out);
ss << "31 16 11121212121212212121212212122122222322323233323333333323333323303330330030300000100010010010001000101010101111" << endl;
Contour4 theContour( ss );
Decomposition4 theDecomposition( theContour.begin(),theContour.end(),DSS4() );
Board2D aBoard;
aBoard << SetMode(
domain.className(),
"Grid" )
<< SetMode( "PointVector", "Grid" );
string styleName = "";
for ( Decomposition4::SegmentComputerIterator
it = theDecomposition.begin(),
itEnd = theDecomposition.end();
it != itEnd; ++it )
{
aBoard << SetMode( "ArithmeticalDSS", "Points" )
<< it->primitive();
aBoard << SetMode( "ArithmeticalDSS", "BoundingBox" )
<< CustomStyle( "ArithmeticalDSS/BoundingBox",
new CustomPenColor( Color::Blue ) )
<< it->primitive();
}
aBoard.saveSVG("greedy-dss-decomposition.svg");
aBoard.saveEPS("greedy-dss-decomposition.eps");
#ifdef WITH_CAIRO
aBoard.saveCairo("greedy-dss-decomposition.png");
#endif
return 0;
}
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
HyperRectDomain< Space > Domain