DGtal  0.9.3beta
kernelDomain.cpp
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/kernel/SpaceND.h"
34 #include "DGtal/helpers/StdDefs.h"
35 #include "DGtal/kernel/domains/HyperRectDomain.h"
36 #include "DGtal/io/boards/Board2D.h"
37 
39 
40 using namespace std;
41 using namespace DGtal;
42 
44 
45 int main()
46 {
47  trace.beginBlock ( "Example kernelDomain" );
48 
49  typedef DGtal::Z2i::Space MySpace;
50 
51  //Point lying in the Z2i::Space
52  typedef MySpace::Point MyPoint;
53 
54  MyPoint p(13,-5);
55 
56  trace.info() << "Point p="<<p<<endl;
57 
58  //We create a domain
59  typedef HyperRectDomain<MySpace> MyDomain;
60  MyPoint a(-3,-4);
61  MyPoint b(10,4);
62  MyDomain domain(a,b);
63 
64  //We trace domain information
65  trace.info() <<"Domain domain="<<domain<<endl;
66 
67  //We generate a board
68  Board2D board;
69  board << domain;
70  board.saveSVG("kernel-domain.svg");
71 
72  MyPoint c(5,1);
73 
74  if ( domain.isInside(c) )
75  trace.info() << "C is inside the domain"<<endl;
76  else
77  trace.info() << "C is outside the domain"<<endl;
78 
79  board << c;
80  board.saveSVG("kernel-domain-point.svg");
81 
82 
83  //PointVector example
84  MyPoint q;
85  MyPoint::Coordinate coord = 24;
86  for(MySpace::Dimension d = 0 ; d < MySpace::dimension; d++)
87  q[d] = coord;
88  trace.info()<<"Q="<<q<<endl;
89 
90  MyPoint r;
91  for(MyPoint::Iterator it=r.begin(), itend=r.end() ;
92  it != itend;
93  ++it)
94  (*it) = coord;
95  trace.info()<<"R="<<r<<endl;
96 
97 
98  //We scan the domain
99  for( MyDomain::ConstIterator it = domain.begin(), itend = domain.end();
100  it != itend;
101  ++it)
102  trace.info() << "Processing point"<< (*it) << endl;
103 
104 
105  board.clear();
106  board << domain;
107  //We draw an arrow between two consecutive points during the iteration.
108  MyDomain::ConstIterator itPrec = domain.begin();
109  MyDomain::ConstIterator it = itPrec;
110  MyDomain::Vector shift;
111  ++it;
112 
113  board << (*itPrec); //We display the first point as a pixel.
114  for( MyDomain::ConstIterator itend = domain.end();
115  it != itend;
116  ++it, ++itPrec)
117  {
118  shift = (*it) -(*itPrec);
119  Display2DFactory::draw(board, shift, (*itPrec));
120  }
121  board.saveSVG("kernel-domain-it-arrow.svg");
122 
123  trace.endBlock();
124  return 0;
125 }
126 // //
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
STL namespace.
double endBlock()
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
DGtal is the top-level namespace which contains all DGtal functions and types.
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
std::ostream & info()
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70