This example shows the basic usage of a 8-connected and a 4-connected arithmetical DSS.
#include <iostream>
#include <exception>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/geometry/curves/ArithmeticalDSS.h"
using namespace std;
using namespace Z2i;
{
using namespace Z2i;
NaiveDSS8<Integer> segment( 5, 8,
);
it = segment.begin(),
ite = segment.end();
it != ite; ++it )
{
<< segment.position( *it ) << ","
<< segment.remainder( *it )
<< ") ";
}
Board2D board;
board << SetMode(
domain.className(),
"Grid")
board << SetMode("PointVector", "Both");
board << SetMode(segment.className(), "Points")
<< segment;
board << SetMode(segment.className(), "BoundingBox")
<< segment;
board.saveSVG("NaiveDSS8.svg");
#ifdef WITH_CAIRO
board.saveCairo("NaiveDSS8.png", Board2D::CairoPNG);
#endif
}
{
using namespace Z2i;
StandardDSS4<Integer> segment( 5, 8,
);
Board2D board;
board << SetMode(
domain.className(),
"Grid")
board << SetMode("PointVector", "Grid")
<< SetMode(segment.className(), "Points")
<< segment;
board << SetMode(segment.className(), "BoundingBox")
<< segment;
board.saveSVG("StandardDSS4.svg");
#ifdef WITH_CAIRO
board.saveCairo("StandardDSS4.png", Board2D::CairoPNG);
#endif
board.clear();
board << SetMode(
domain.className(),
"Paving")
board << SetMode("PointVector", "Both");
board << SetMode(segment.className(), "Points")
<< segment;
board << SetMode(segment.className(), "BoundingBox")
<< segment;
board.saveSVG("StandardDSS4bis.svg");
#ifdef WITH_CAIRO
board.saveCairo("StandardDSS4bis.png", Board2D::CairoPNG);
#endif
}
{
using namespace Z2i;
{
NaiveDSS8<Integer> segment(
Point(0,0),
Point(8,5),
true );
}
{
NaiveDSS8<Integer> segment(
Point(0,0),
Point(8,5),
false );
}
{
NaiveDSS8<Integer> segment( NaiveDSL<Integer>(5,8,0),
Point(0,0),
Point(8,5) );
}
{
NaiveDSS8<Integer> bigDSS( NaiveDSL<Integer>(5,8,0),
Point(-8,-5),
Point(16,10) );
NaiveDSS8<Integer> segment( bigDSS,
Point(0,0),
Point(8,5) );
}
std::vector<Point> r;
{
NaiveDSS8<Integer> segment( 5, 8,
);
if (!segment.isValid()) throw std::exception();
std::copy( segment.begin(), segment.end(), std::back_inserter(r) );
}
{
NaiveDSS8<Integer> segment( r.begin(), r.end() );
}
}
{
using namespace Z2i;
NaiveDSS8<Integer> S( 5, 8,
);
if (!S.isValid()) throw std::exception();
NaiveDSS8<Integer> copyOfS = S;
{
Board2D board;
board << SetMode(
domain.className(),
"Grid")
board << SetMode("PointVector", "Both");
board << SetMode(S.className(), "Points")
<< S
<< SetMode(S.className(), "BoundingBox")
<< S;
board.drawArrow(0.0, 0.0, 1.0, 0.0);
board.drawArrow(0.0, 0.0, 0.0, 1.0);
board << SetMode(M.className(), "Both")
<< CustomStyle( M.className(), new CustomColors( Color(255,0,0), Color(192, 0, 0)) )
<< M;
board.saveSVG("NaiveDSS8ExtInit.svg");
#ifdef WITH_CAIRO
board.saveCairo("NaiveDSS8ExtInit.png", Board2D::CairoPNG);
#endif
}
bool resExtention = S.extendFront( M );
if (!resExtention) throw std::exception();
{
Board2D board;
board << SetMode(
domain.className(),
"Grid")
board << SetMode("PointVector", "Both");
board << SetMode(S.className(), "Points")
<< S
<< SetMode(S.className(), "BoundingBox")
<< S;
board.drawArrow(0.0, 0.0, 1.0, 0.0);
board.drawArrow(0.0, 0.0, 0.0, 1.0);
board.saveSVG("NaiveDSS8ExtDone.svg");
#ifdef WITH_CAIRO
board.saveCairo("NaiveDSS8ExtDone.png", Board2D::CairoPNG);
#endif
}
bool resRetraction = S.retractFront();
if (!resRetraction) throw std::exception();
if ( !S.equalsTo(copyOfS) ) throw std::exception();
}
int main(
int argc,
char** argv )
{
for ( int i = 0; i < argc; ++i )
return 0;
}
void beginBlock(const std::string &keyword="")
void exampleUpdate()
Function showing how a DSS can be extended and retracted.
void exampleNaiveDSS()
Function that illustrates the basic usage of a naive DSS.
void exampleStandardDSS()
Function that illustrates the basic usage of a standard DSS.
void exampleConstructors()
Function showing the different ways of constructing DSSs.
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
HyperRectDomain< Space > Domain