DGtal  1.1.0
topology/khalimskySpaceScanner.cpp

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

See also
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::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;
}
// //
DGtal::KhalimskySpaceND::uFirst
Integer uFirst(const PreCell &p, Dimension k) const
Return the k-th Khalimsky coordinate of the first cell of the space with the same type as [p].
DGtal::KhalimskySpaceND::uCell
Cell uCell(const PreCell &c) const
From an unsigned cell, returns an unsigned cell lying into this Khalismky space.
LibBoard::Board::setPenColor
Board & setPenColor(const DGtal::Color &color)
Definition: Board.cpp:298
DGtal::HyperRectDomain< Space >
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:67
DGtal::KhalimskySpaceND::uSpel
Cell uSpel(Point p) const
From the digital coordinates of a point in Zn, builds the corresponding spel (cell of maximal dimensi...
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
DGtal::KhalimskySpaceND::uLast
Integer uLast(const PreCell &p, Dimension k) const
Return the k-th Khalimsky coordinate of the last cell of the space with the same type as [p].
DGtal::trace
Trace trace
Definition: Common.h:150
DGtal::HyperRectDomain::className
std::string className() const
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::KhalimskyPreSpaceND
Aim: This class is a model of CPreCellularGridSpaceND. It represents the cubical grid as a cell compl...
Definition: KhalimskyPreSpaceND.h:380
DGtal::Trace::info
std::ostream & info()
draw
void draw(const Iterator &itb, const Iterator &ite, Board &aBoard)
Definition: testSegmentation.cpp:75
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: ClosedIntegerHalfPlane.h:49
DGtal::KhalimskySpaceND::uIsInside
bool uIsInside(const PreCell &p, Dimension k) const
Useful to check if you are going out of the space.
LibBoard::Board::saveSVG
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
DGtal::KhalimskySpaceND::uCoords
Point uCoords(const Cell &c) const
Return its digital coordinates.
LibBoard::Board::saveFIG
void saveFIG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0, bool includeFIGHeader=true) const
Definition: Board.cpp:907
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
DGtal::PointVector< dim, Integer >
DGtal::SetMode
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
Cell
KSpace::Cell Cell
Definition: testCubicalComplex.cpp:56
DGtal::KhalimskySpaceND::uGetMax
Cell uGetMax(Cell p, Dimension k) const
Useful to check if you are going out of the space.
DGtal::KhalimskyCell< dim, Integer >
DGtal::KhalimskySpaceND::uNext
bool uNext(Cell &p, const Cell &lower, const Cell &upper) const
Increment the cell [p] to its next position (as classically done in a scanning).
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:394