DGtal 1.3.0
Searching...
No Matches
topology/khalimskySpaceScanner.cpp

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

Moving within the cellular grid space
#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;
Z2i::KSpace::Cell precq = q;
bool firstq = true;
using KPS = Z2i::KPreSpace;
for ( KPS::Cell qq = K.uGetMax(q, 0); K.uIsInside(qq, 0); qq = KPS::uGetDecr(qq, 0) )
{
for ( KPS::uSetKCoord( qq, K.uFirst( qq, 1 ), 1 ); K.uIsInside(qq, 1); qq = KPS::uGetIncr(qq, 1) )
{
q = K.uCell( qq );
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;
}
// //
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:68
const Point & lowerBound() const
const Point & upperBound() const
std::string className() const
Aim: This class is a model of CPreCellularGridSpaceND. It represents the cubical grid as a cell compl...
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
void beginBlock(const std::string &keyword="")
std::ostream & info()
Board & setPenColor(const DGtal::Color &color)
Definition: Board.cpp:298
void saveFIG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0, bool includeFIGHeader=true) const
Definition: Board.cpp:907
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
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