DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
kernelDomain.cpp
1 
30 
31 #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  //We create several space models.
50  typedef DGtal::SpaceND<3, DGtal::int32_t> MySpace32;
51  typedef DGtal::SpaceND<1, DGtal::int64_t> MySpace8;
52 
53 #ifdef WITH_BIGINTEGER
54  typedef DGtal::SpaceND<3, DGtal::BigInteger> MySpaceBIGINTEGER;
55 #endif
56 
57  typedef DGtal::Z2i::Space MySpace;
58 
59  //Point lying in the Z2i::Space
60  typedef MySpace::Point MyPoint;
61 
62  MyPoint p(13,-5);
63 
64  trace.info() << "Point p="<<p<<endl;
65 
66  //We create a domain
67  typedef HyperRectDomain<MySpace> MyDomain;
68  MyPoint a(-3,-4);
69  MyPoint b(10,4);
70  MyDomain domain(a,b);
71 
72  //We trace domain information
73  trace.info() <<"Domain domain="<<domain<<endl;
74 
75  //We generate a board
76  Board2D board;
77  board << domain;
78  board.saveSVG("kernel-domain.svg");
79 
80  MyPoint c(5,1);
81 
82  if ( domain.isInside(c) )
83  trace.info() << "C is inside the domain"<<endl;
84  else
85  trace.info() << "C is outside the domain"<<endl;
86 
87  board << c;
88  board.saveSVG("kernel-domain-point.svg");
89 
90 
91  //PointVector example
92  MyPoint q;
93  MyPoint::Coordinate coord = 24;
94  for(MySpace::Dimension d = 0 ; d < MySpace::dimension; d++)
95  q[d] = coord;
96  trace.info()<<"Q="<<q<<endl;
97 
98  MyPoint r;
99  for(MyPoint::Iterator it=r.begin(), itend=r.end() ;
100  it != itend;
101  ++it)
102  (*it) = coord;
103  trace.info()<<"R="<<r<<endl;
104 
105 
106  //We scan the domain
107  for( MyDomain::ConstIterator it = domain.begin(), itend = domain.end();
108  it != itend;
109  ++it)
110  trace.info() << "Processing point"<< (*it) << endl;
111 
112 
113  board.clear();
114  board << domain;
115  //We draw an arrow between two consecutive points during the iteration.
116  MyDomain::ConstIterator itPrec = domain.begin();
117  MyDomain::ConstIterator it = itPrec;
118  MyDomain::Vector shift;
119  ++it;
120 
121  board << (*itPrec); //We display the first point as a pixel.
122  for( MyDomain::ConstIterator itend = domain.end();
123  it != itend;
124  ++it, ++itPrec)
125  {
126  shift = (*it) -(*itPrec);
127  Display2DFactory::draw(board, shift, (*itPrec));
128  }
129  board.saveSVG("kernel-domain-it-arrow.svg");
130 
131  trace.endBlock();
132  return 0;
133 }
134 // //