DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
khalimskySpaceScanner.cpp
1 
30 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/topology/KhalimskySpaceND.h"
34 #include "DGtal/helpers/StdDefs.h"
35 #include "DGtal/io/Color.h"
36 #include "DGtal/io/boards/Board2D.h"
37 
39 
40 using namespace std;
41 using namespace DGtal;
42 
44 
45 int main( int argc, char** argv )
46 {
47  trace.beginBlock ( "Example KhalimskySpaceScanner" );
48  trace.info() << "Args:";
49  for ( int i = 0; i < argc; ++i )
50  trace.info() << " " << argv[ i ];
51  trace.info() << endl;
52 
53 
54  Board2D boardScan1; // for 2D display
55  Board2D boardScan2; // for 2D display
56 
57 
58  Z2i::KSpace K;
59  Z2i::Point plow(0,0);
60  Z2i::Point pup(3,2);
61 
62  Z2i::Domain dom (plow, pup);
63  boardScan1 << SetMode( dom.className(), "Paving" )
64  << dom;
65  boardScan2 << SetMode( dom.className(), "Paving" )
66  << dom;
67 
68  K.init( dom.lowerBound(),dom.upperBound(), true );
69 
70 
71 
72  Z2i::KSpace::Cell q = K.uSpel(plow);
73  Z2i::KSpace::Cell p = K.uSpel(plow);
74 
75 
76  Z2i::Vector shift;
77  Z2i::KSpace::Cell prec=p;
78  bool first=true;
79  // Simple way to scan Khalimsky space
80  do
81  {
82  boardScan1 << p;
83  if(first){
84  first=false;
85  prec=p;
86  continue;
87  }
88  // Drawing the scan arrows
89  boardScan1.setPenColor( Color( 30, 30, 200 ));
90  shift = K.uCoords(p)-K.uCoords(prec);
91  Display2DFactory::draw(boardScan1, shift, K.uCoords(prec));
92  prec=p;
93  }
94  while ( K.uNext( p, K.uFirst(p), K.uLast(p) ) );
95 
96 
97 
98 
99  // Other way to scan Khalimsky space by controlling axis order
100  Z2i::Vector shiftq;
101  Z2i::KSpace::Cell precq=q;
102  bool firstq=true;
103  for (q = K.uGetMax(q, 0); K.uIsInside(q,0); q = K.uGetDecr(q, 0))
104  for ( q = K.uGetMin(q, 1); K.uIsInside(q,1); q = K.uGetIncr(q, 1))
105  {
106  boardScan2 << q;
107  if(firstq){
108  firstq=false;
109  precq=q;
110  continue;
111  }
112  // Drawing the scan arrows
113  shiftq = K.uCoords(q)-K.uCoords(precq);
114  boardScan2.setPenColor( Color( 30, 30, 200 ));
115  Display2DFactory::draw(boardScan2, shiftq, K.uCoords(precq));
116  precq=q;
117  }
118 
119 
120  boardScan1.saveSVG("khalimskySpaceScanner1.svg");
121  boardScan1.saveFIG("khalimskySpaceScanner1.fig");
122 
123  boardScan2.saveSVG("khalimskySpaceScanner2.svg");
124  boardScan2.saveFIG("khalimskySpaceScanner2.fig");
125 
126  return 0;
127 
128 }
129 // //
131