DGtal  1.5.beta
doc-examples/kernelDomain.cpp

Example of DGtal kernel with Domain.

See also
DGtal Space
Iteration over a domain with displacements depicted as arrows.
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/io/boards/Board2D.h"
using namespace std;
using namespace DGtal;
int main()
{
trace.beginBlock ( "Example kernelDomain" );
typedef DGtal::Z2i::Space MySpace;
//Point lying in the Z2i::Space
typedef MySpace::Point MyPoint;
MyPoint p(13,-5);
trace.info() << "Point p="<<p<<endl;
//We create a domain
typedef HyperRectDomain<MySpace> MyDomain;
MyPoint a(-3,-4);
MyPoint b(10,4);
MyDomain domain(a,b);
//We trace domain information
trace.info() <<"Domain domain="<<domain<<endl;
//We generate a board
Board2D board;
board << domain;
board.saveSVG("kernel-domain.svg");
MyPoint c(5,1);
if ( domain.isInside(c) )
trace.info() << "C is inside the domain"<<endl;
else
trace.info() << "C is outside the domain"<<endl;
board << c;
board.saveSVG("kernel-domain-point.svg");
//PointVector example
MyPoint q;
MyPoint::Coordinate coord = 24;
for(MySpace::Dimension d = 0 ; d < MySpace::dimension; d++)
q[d] = coord;
trace.info()<<"Q="<<q<<endl;
MyPoint r;
for(MyPoint::Iterator it=r.begin(), itend=r.end() ;
it != itend;
++it)
(*it) = coord;
trace.info()<<"R="<<r<<endl;
//We scan the domain
for( MyDomain::ConstIterator it = domain.begin(), itend = domain.end();
it != itend;
++it)
trace.info() << "Processing point"<< (*it) << endl;
board.clear();
board << domain;
//We draw an arrow between two consecutive points during the iteration.
MyDomain::ConstIterator itPrec = domain.begin();
++it;
board << (*itPrec); //We display the first point as a pixel.
for( MyDomain::ConstIterator itend = domain.end();
it != itend;
++it, ++itPrec)
{
shift = (*it) -(*itPrec);
Display2DFactory::draw(board, shift, (*itPrec));
}
board.saveSVG("kernel-domain-it-arrow.svg");
return 0;
}
// //
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
DigitalPlane::Point Vector
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
int main(int argc, char **argv)
MyPointD Point
Definition: testClone2.cpp:383
Domain domain
void draw(const Iterator &itb, const Iterator &ite, Board &aBoard)