This example outputs a greedy segmentation of a closed and 4-connected digital curve into DSSs.
* $ ./examples/geometry/curves/greedy-dss-decomposition
*
Greedy segmentation into DSSs
- See also
- Digital straight lines and segments and Analysis of one-dimensional discrete structures
-
geometry/curves/greedy-dss-decomposition.cpp
#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;
{
std::stringstream ss(stringstream::in | stringstream::out);
ss << "31 16 11121212121212212121212212122122222322323233323333333323333323303330330030300000100010010010001000101010101111" << endl;
Contour4 theContour( ss );
Decomposition4 theDecomposition( theContour.begin(),theContour.end(),DSS4() );
<<
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" )
<< 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;
}
std::string className() const