File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/config/TeX-MML-AM_CHTML/MathJax.js
DGtal 2.0.0
khalimskySpaceScanner.cpp
Go to the documentation of this file.
1
16
29
45
46
48#include <iostream>
49#include "DGtal/base/Common.h"
50#include "DGtal/topology/KhalimskySpaceND.h"
51#include "DGtal/helpers/StdDefs.h"
52#include "DGtal/io/Color.h"
53#include "DGtal/io/boards/Board2D.h"
54
56
57using namespace std;
58using namespace DGtal;
59
61
62int main( int argc, char** argv )
63{
64 trace.beginBlock ( "Example KhalimskySpaceScanner" );
65 trace.info() << "Args:";
66 for ( int i = 0; i < argc; ++i )
67 trace.info() << " " << argv[ i ];
68 trace.info() << endl;
69
70
71 Board2D boardScan1; // for 2D display
72 Board2D boardScan2; // for 2D display
73
74
76 Z2i::Point plow(0,0);
77 Z2i::Point pup(3,2);
78
79 Z2i::Domain dom (plow, pup);
80 boardScan1 << SetMode( dom.className(), "Paving" )
81 << dom;
82 boardScan2 << SetMode( dom.className(), "Paving" )
83 << dom;
84
85 K.init( dom.lowerBound(),dom.upperBound(), true );
86
87
88
89 Z2i::KSpace::Cell q = K.uSpel(plow);
90 Z2i::KSpace::Cell p = K.uSpel(plow);
91
92
93 Z2i::Vector shift;
94 Z2i::KSpace::Cell prec=p;
95 bool first=true;
96 // Simple way to scan Khalimsky space
97 do
98 {
99 boardScan1 << p;
100 if(first){
101 first=false;
102 prec=p;
103 continue;
104 }
105 // Drawing the scan arrows
106 boardScan1.setPenColor( Color( 30, 30, 200 ));
107 shift = K.uCoords(p)-K.uCoords(prec);
108 Display2DFactory::draw(boardScan1, shift, K.uCoords(prec));
109 prec=p;
110 }
111 while ( K.uNext( p, K.uFirst(p), K.uLast(p) ) );
112
113
114
115
116 // Other way to scan Khalimsky space by controlling axis order
117 Z2i::Vector shiftq;
118 Z2i::KSpace::Cell precq = q;
119 bool firstq = true;
120 using KPS = Z2i::KPreSpace;
121 for ( KPS::Cell qq = K.uGetMax(q, 0); K.uIsInside(qq, 0); qq = KPS::uGetDecr(qq, 0) )
122 {
123 for ( KPS::uSetKCoord( qq, K.uFirst( qq, 1 ), 1 ); K.uIsInside(qq, 1); qq = KPS::uGetIncr(qq, 1) )
124 {
125 q = K.uCell( qq );
126 boardScan2 << q;
127 if(firstq){
128 firstq = false;
129 precq = q;
130 continue;
131 }
132 // Drawing the scan arrows
133 shiftq = K.uCoords(q) - K.uCoords(precq);
134 boardScan2.setPenColor( Color( 30, 30, 200 ));
135 Display2DFactory::draw(boardScan2, shiftq, K.uCoords(precq));
136 precq = q;
137 }
138 }
139
140 boardScan1.saveSVG("khalimskySpaceScanner1.svg");
141 boardScan1.saveFIG("khalimskySpaceScanner1.fig");
142
143 boardScan2.saveSVG("khalimskySpaceScanner2.svg");
144 boardScan2.saveFIG("khalimskySpaceScanner2.fig");
145
146 return 0;
147
148}
149// //
151
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition Board2D.h:71
Structure representing an RGB triple with alpha component.
Definition Color.h:77
const Point & lowerBound() const
const Point & upperBound() const
std::string className() const
KhalimskyCell< dim, Integer > Cell
Board & setPenColor(const DGtal::Color &color)
Definition Board.cpp:297
void saveFIG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0, bool includeFIGHeader=true) const
Definition Board.cpp:906
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:1011
KhalimskyPreSpaceND< 2, Integer > KPreSpace
Definition StdDefs.h:83
KhalimskySpaceND< 2, Integer > KSpace
Definition StdDefs.h:77
Space::Vector Vector
Definition StdDefs.h:96
Space::Point Point
Definition StdDefs.h:95
HyperRectDomain< Space > Domain
Definition StdDefs.h:99
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
STL namespace.
static void draw(DGtal::Board2D &board, const DGtal::DiscreteExteriorCalculus< dimEmbedded, dimAmbient, TLinearAlgebraBackend, TInteger > &calculus)
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition Board2D.h:247
int main()
Definition testBits.cpp:56
KSpace K