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.
$ ./examples/geometry/curves/convex-and-concave-parts
Note that the chain code of the input digital curve may be passed as argument as follows:
$ ./examples/geometry/curves/convex-and-concave-parts 0300303303033030303000010101011010110100000303303033030303
Decomposition into convex and concave parts
- See also
- Digital straight lines and segments and Analysis of one-dimensional discrete structures
#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";
for (Iterator i(itb); i != ite; ++i) {
typedef typename Iterator::SegmentComputer::Primitive DSS;
DSS maximalDSS = i->primitive();
if ( !(i.intersectNext() && i.intersectPrevious()) ) {
} 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) ) {
} else if ( (r1>=mu+omega)&&(r2>=mu+omega) ) {
} else if ( (r1>=mu+omega)&&(r2<=mu-1) ) {
} else if ( (r1<=mu-1)&&(r2>=mu+omega) ) {
} else {
}
}
<< maximalDSS;
}
}
template <typename Iterator, typename Board>
Board& aBoard)
{
RecognitionAlgorithm algo;
drawCCP(s.begin(), s.end(), aBoard);
}
int main(
int argc,
char** argv )
{
string codes;
if (argc >= 2) codes = argv[1];
else codes = "030030330303303030300001010101101011010000030330303303030300001010110101011010000033";
stringstream ss(stringstream::in | stringstream::out);
ss << "0 0 " << codes << endl;
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;
}