DGtal 1.3.0
Loading...
Searching...
No Matches
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();
MyDomain::ConstIterator it = itPrec;
MyDomain::Vector shift;
++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");
trace.endBlock();
return 0;
}
// //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
int main()
Definition: testBits.cpp:56
Domain domain