DGtal  1.5.beta
kernelDomain.cpp
Go to the documentation of this file.
1 
41 #include <iostream>
42 #include "DGtal/base/Common.h"
43 #include "DGtal/kernel/SpaceND.h"
44 #include "DGtal/helpers/StdDefs.h"
45 #include "DGtal/kernel/domains/HyperRectDomain.h"
46 #include "DGtal/io/boards/Board2D.h"
47 
49 
50 using namespace std;
51 using namespace DGtal;
52 
54 
55 int main()
56 {
57  trace.beginBlock ( "Example kernelDomain" );
58 
59  typedef DGtal::Z2i::Space MySpace;
60 
61  //Point lying in the Z2i::Space
62  typedef MySpace::Point MyPoint;
63 
64  MyPoint p(13,-5);
65 
66  trace.info() << "Point p="<<p<<endl;
67 
68  //We create a domain
69  typedef HyperRectDomain<MySpace> MyDomain;
70  MyPoint a(-3,-4);
71  MyPoint b(10,4);
72  MyDomain domain(a,b);
73 
74  //We trace domain information
75  trace.info() <<"Domain domain="<<domain<<endl;
76 
77  //We generate a board
78  Board2D board;
79  board << domain;
80  board.saveSVG("kernel-domain.svg");
81 
82  MyPoint c(5,1);
83 
84  if ( domain.isInside(c) )
85  trace.info() << "C is inside the domain"<<endl;
86  else
87  trace.info() << "C is outside the domain"<<endl;
88 
89  board << c;
90  board.saveSVG("kernel-domain-point.svg");
91 
92 
93  //PointVector example
94  MyPoint q;
95  MyPoint::Coordinate coord = 24;
96  for(MySpace::Dimension d = 0 ; d < MySpace::dimension; d++)
97  q[d] = coord;
98  trace.info()<<"Q="<<q<<endl;
99 
100  MyPoint r;
101  for(MyPoint::Iterator it=r.begin(), itend=r.end() ;
102  it != itend;
103  ++it)
104  (*it) = coord;
105  trace.info()<<"R="<<r<<endl;
106 
107 
108  //We scan the domain
109  for( MyDomain::ConstIterator it = domain.begin(), itend = domain.end();
110  it != itend;
111  ++it)
112  trace.info() << "Processing point"<< (*it) << endl;
113 
114 
115  board.clear();
116  board << domain;
117  //We draw an arrow between two consecutive points during the iteration.
119  MyDomain::ConstIterator it = itPrec;
120  MyDomain::Vector shift;
121  ++it;
122 
123  board << (*itPrec); //We display the first point as a pixel.
124  for( MyDomain::ConstIterator itend = domain.end();
125  it != itend;
126  ++it, ++itPrec)
127  {
128  shift = (*it) -(*itPrec);
129  Display2DFactory::draw(board, shift, (*itPrec));
130  }
131  board.saveSVG("kernel-domain-it-arrow.svg");
132 
133  trace.endBlock();
134  return 0;
135 }
136 // //
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'.
bool isInside(const Point &p) const
const ConstIterator & end() const
const ConstIterator & begin() const
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:151
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1011
DigitalPlane::Point Vector
MyDigitalSurface::ConstIterator ConstIterator
int main()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
MyPointD Point
Definition: testClone2.cpp:383
Domain domain
void draw(const Iterator &itb, const Iterator &ite, Board &aBoard)