This example outputs the cover of an open digital curve by maximal DSSs. Maximal DSSs are displayed in blue, green, yellow in convex, concave, inflexion parts respectively. Ends are black. Convex (resp. concave) parts are defined as sequences of maximal DSSs of increasing (resp. decreasing) slope.
Note that the chain code of the input digital curve may be passed as argument as follows:
#include <cmath>
#include <iostream>
#include <sstream>
#include <fstream>
#include "DGtal/base/Common.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/Color.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/SaturatedSegmentation.h"
#include "ConfigExamples.h"
using namespace std;
using namespace Z2i;
template <typename Iterator, typename Board>
void drawCCP(
const Iterator& itb,
const Iterator& ite, Board& aBoard)
{
aBoard << SetMode( "ArithmeticalDSS", "BoundingBox" );
string aStyleName = "ArithmeticalDSS/BoundingBox";
CustomPenColor* aPenColor;
for (Iterator i(itb); i != ite; ++i) {
typedef typename Iterator::SegmentComputer::Primitive DSS;
DSS maximalDSS = i->primitive();
if ( !(i.intersectNext() && i.intersectPrevious()) ) {
aPenColor = new CustomPenColor( Color::Black );
} else {
Point beforeFirst = *(--(i->begin()));
Point afterLast = *(i->end());
Integer r1 = maximalDSS.remainder(beforeFirst);
Integer r2 = maximalDSS.remainder(afterLast);
Integer omega = maximalDSS.omega();
if ( (r1<=mu-1)&&(r2<=mu-1) ) {
aPenColor = new CustomPenColor( Color::Green);
} else if ( (r1>=mu+omega)&&(r2>=mu+omega) ) {
aPenColor = new CustomPenColor( Color::Blue );
} else if ( (r1>=mu+omega)&&(r2<=mu-1) ) {
aPenColor = new CustomPenColor( Color::Yellow );
} else if ( (r1<=mu-1)&&(r2>=mu+omega) ) {
aPenColor = new CustomPenColor( Color::Yellow );
} else {
aPenColor = new CustomPenColor( Color::Red );
}
}
aBoard << CustomStyle( aStyleName, aPenColor )
<< maximalDSS;
}
}
template <typename Iterator, typename Board>
Board& aBoard)
{
typedef typename IteratorCirculatorTraits<Iterator>::Value::Coordinate Coordinate;
typedef ArithmeticalDSSComputer<Iterator,Coordinate,4> RecognitionAlgorithm;
typedef SaturatedSegmentation<RecognitionAlgorithm>
Segmentation;
RecognitionAlgorithm algo;
drawCCP(s.begin(), s.end(), aBoard);
}
int main(
int argc,
char** argv )
{
Board2D aBoard;
string codes;
if (argc >= 2) codes = argv[1];
else codes = "030030330303303030300001010101101011010000030330303303030300001010110101011010000033";
stringstream ss(stringstream::in | stringstream::out);
ss << "0 0 " << codes << endl;
FreemanChain<int> theContour( ss );
trace.
info() <<
"Processing of " << ss.str() << endl;
aBoard
<< SetMode( "PointVector", "Grid" )
<< theContour;
aBoard.saveSVG("convex-and-concave-parts.svg");
#ifdef WITH_CAIRO
aBoard.saveCairo("convex-and-concave-parts.png");
#endif
return 0;
}
void beginBlock(const std::string &keyword="")
Point::Coordinate Integer
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
SaturatedSegmentation< SegmentComputer > Segmentation
void segmentationIntoMaximalDSSs(const Iterator &itb, const Iterator &ite, const Iterator &sitb, const Iterator &site, const string &aMode, Board &aBoard)
void drawCCP(const Iterator &itb, const Iterator &ite, Board &aBoard)