DGtal  0.9.2
khalimskySpaceScanner.cpp
1 
30 #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  using KPS = Z2i::KPreSpace;
104  for ( KPS::Cell qq = K.uGetMax(q, 0); K.uIsInside(qq, 0); qq = KPS::uGetDecr(qq, 0) )
105  {
106  for ( KPS::uSetKCoord( qq, K.uFirst( qq, 1 ), 1 ); K.uIsInside(qq, 1); qq = KPS::uGetIncr(qq, 1) )
107  {
108  q = K.uCell( qq );
109  boardScan2 << q;
110  if(firstq){
111  firstq = false;
112  precq = q;
113  continue;
114  }
115  // Drawing the scan arrows
116  shiftq = K.uCoords(q) - K.uCoords(precq);
117  boardScan2.setPenColor( Color( 30, 30, 200 ));
118  Display2DFactory::draw(boardScan2, shiftq, K.uCoords(precq));
119  precq = q;
120  }
121  }
122 
123  boardScan1.saveSVG("khalimskySpaceScanner1.svg");
124  boardScan1.saveFIG("khalimskySpaceScanner1.fig");
125 
126  boardScan2.saveSVG("khalimskySpaceScanner2.svg");
127  boardScan2.saveFIG("khalimskySpaceScanner2.fig");
128 
129  return 0;
130 
131 }
132 // //
134 
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:130
Cell uGetMax(Cell p, Dimension k) const
STL namespace.
Aim: This class is a model of CPreCellularGridSpaceND. It represents the cubical grid as a cell compl...
void saveFIG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0, bool includeFIGHeader=true) const
Definition: Board.cpp:907
Cell uCell(const PreCell &c) const
bool init(const Point &lower, const Point &upper, bool isClosed)
bool uIsInside(const PreCell &p, Dimension k) const
Point uCoords(const Cell &c) const
DGtal is the top-level namespace which contains all DGtal functions and types.
Integer uFirst(const PreCell &p, Dimension k) const
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
std::ostream & info()
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247
bool uNext(Cell &p, const Cell &lower, const Cell &upper) const
Integer uLast(const PreCell &p, Dimension k) const
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
Board & setPenColor(const DGtal::Color &color)
Definition: Board.cpp:298
Cell uSpel(Point p) const
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex...
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70