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"
template <typename Iterator, typename Board>
{
aBoard <<
SetMode(
"ArithmeticalDSS",
"BoundingBox" );
string aStyleName = "ArithmeticalDSS/BoundingBox";
typedef typename Iterator::SegmentComputer::Primitive DSS;
DSS maximalDSS = i->primitive();
if ( !(i.intersectNext() && i.intersectPrevious()) ) {
} else {
typedef typename DSS::Point
Point;
Point beforeFirst = *(--(i->begin()));
Point afterLast = *(i->end());
typedef typename DSS::Integer
Integer;
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 )
{
trace.beginBlock (
"Example convex-and-concave-parts" );
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 DGTAL_WITH_CAIRO
aBoard.
saveCairo(
"convex-and-concave-parts.png");
#endif
return 0;
}
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
static const Color Yellow
Aim: Computes the saturated segmentation, that is the whole set of maximal segments within a range gi...
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Point::Coordinate Integer
Z2i this namespace gathers the standard of types for 2D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
Custom style class redefining the pen color. You may use Board2D::Color::None for transparent color.
Aim: Provides nested types for both iterators and circulators: Type, Category, Value,...
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
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)