DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
topology/khalimskySpaceScanner.cpp

A simple example illustrating different way to scan a Khalimsky space. This program outputs these images:

See also:
  1. Moving within the cellular grid space
khalimskySpaceScanner1.png
khalimskySpaceScanner2.png
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/topology/KhalimskySpaceND.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/boards/Board2D.h"
using namespace std;
using namespace DGtal;
int main( int argc, char** argv )
{
trace.beginBlock ( "Example KhalimskySpaceScanner" );
trace.info() << "Args:";
for ( int i = 0; i < argc; ++i )
trace.info() << " " << argv[ i ];
trace.info() << endl;
Board2D boardScan1; // for 2D display
Board2D boardScan2; // for 2D display
Z2i::Point plow(0,0);
Z2i::Point pup(3,2);
Z2i::Domain dom (plow, pup);
boardScan1 << SetMode( dom.className(), "Paving" )
<< dom;
boardScan2 << SetMode( dom.className(), "Paving" )
<< dom;
K.init( dom.lowerBound(),dom.upperBound(), true );
Z2i::KSpace::Cell q = K.uSpel(plow);
Z2i::KSpace::Cell p = K.uSpel(plow);
Z2i::Vector shift;
bool first=true;
// Simple way to scan Khalimsky space
do
{
boardScan1 << p;
if(first){
first=false;
prec=p;
continue;
}
// Drawing the scan arrows
boardScan1.setPenColor( Color( 30, 30, 200 ));
shift = K.uCoords(p)-K.uCoords(prec);
Display2DFactory::draw(boardScan1, shift, K.uCoords(prec));
prec=p;
}
while ( K.uNext( p, K.uFirst(p), K.uLast(p) ) );
// Other way to scan Khalimsky space by controlling axis order
Z2i::Vector shiftq;
bool firstq=true;
for (q = K.uGetMax(q, 0); K.uIsInside(q,0); q = K.uGetDecr(q, 0))
for ( q = K.uGetMin(q, 1); K.uIsInside(q,1); q = K.uGetIncr(q, 1))
{
boardScan2 << q;
if(firstq){
firstq=false;
precq=q;
continue;
}
// Drawing the scan arrows
shiftq = K.uCoords(q)-K.uCoords(precq);
boardScan2.setPenColor( Color( 30, 30, 200 ));
Display2DFactory::draw(boardScan2, shiftq, K.uCoords(precq));
precq=q;
}
boardScan1.saveSVG("khalimskySpaceScanner1.svg");
boardScan1.saveFIG("khalimskySpaceScanner1.fig");
boardScan2.saveSVG("khalimskySpaceScanner2.svg");
boardScan2.saveFIG("khalimskySpaceScanner2.fig");
return 0;
}
// //