DGtal  0.9.3beta
topology/ctopo-2.cpp

A simple example illustrating the extraction of the sequence of surfels boudary. This program outputs this image.

The 2D case: the boundary is a sequence of cells
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/topology/KhalimskySpaceND.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/Color.h"
#include "ConfigExamples.h"
using namespace std;
using namespace DGtal;
int main( int /*argc*/, char** /*argv*/ )
{
std::string inputFilename = examplesPath + "samples/circleR10modif.pgm";
Image image = PGMReader<Image>::importPGM( inputFilename );
Z2i::DigitalSet set2d (image.domain());
SetFromImage<Z2i::DigitalSet>::append<Image>(set2d, image, 0, 255);
Board2D board;
board << image.domain() << set2d; // display domain and set
Board2D board2;
board2 << image.domain() << set2d; // display domain and set
Board2D board3;
board3 << image.domain() << set2d; // display domain and set
// Construct the Khalimsky space from the image domain
bool space_ok = ks.init( image.domain().lowerBound(), image.domain().upperBound(), true );
//Extract a boundary cell
// Getting the consecutive surfels of the 2D boundary
std::vector<Z2i::SCell> vectBdrySCell;
board << CustomStyle( (*(vectBdrySCell.begin())).className(),
new CustomColors( Color( 255, 255, 0 ),
Color( 192, 192, 0 ) ));
unsigned int d=0;
std::vector<Z2i::SCell>::iterator it;
for ( it=vectBdrySCell.begin() ; it != vectBdrySCell.end(); it++ ){
board<< CustomStyle((*it).className() ,
new CustomColors( Color::Black,
d++;
}
// Extract all boundaries:
std::set<Z2i::SCell> bdry;
// Z2i::Cell low = ks.uFirst(ks.uSpel(ks.lowerBound()));
// Z2i::Cell upp = ks.uLast(ks.uSpel(ks.upperBound()));
( bdry,
ks, set2d, ks.lowerBound(), ks.upperBound() );
std::set<Z2i::SCell>::iterator itB;
for ( itB=bdry.begin() ; itB != bdry.end(); itB++ ){
board2<< CustomStyle((*itB).className() ,
new CustomColors( Color::Black,
d++;
}
std::vector< std::vector<Z2i::SCell> > vectContoursBdrySCell;
d=0;
for(unsigned int i=0; i< vectContoursBdrySCell.size(); i++){
d++;
for(unsigned int j=0; j< vectContoursBdrySCell.at(i).size(); j++){
board3<< CustomStyle(vectContoursBdrySCell.at(i).at(j).className() ,
new CustomColors( Color::Black,