DGtal  1.3.beta
topology/ctopo-2.cpp

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

See also
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/readers/PGMReader.h"
#include "DGtal/io/colormaps/GradientColorMap.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());
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;
SurfelAdjacency<2> SAdj( true );
ks, SAdj, set2d, aCell );
board << CustomStyle( (*(vectBdrySCell.begin())).className(),
new CustomColors( Color( 255, 255, 0 ),
Color( 192, 192, 0 ) ));
GradientColorMap<int> cmap_grad( 0, (int)vectBdrySCell.size() );
cmap_grad.addColor( Color( 50, 50, 255 ) );
cmap_grad.addColor( Color( 255, 0, 0 ) );
cmap_grad.addColor( Color( 255, 255, 10 ) );
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,
cmap_grad( d )))<< *it;
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,
cmap_grad( d )))<< *itB;
d++;
}
std::vector< std::vector<Z2i::SCell> > vectContoursBdrySCell;
ks, SAdj, set2d );
GradientColorMap<int> cmap_grad3( 0, (int)vectContoursBdrySCell.size() );
cmap_grad3.addColor( Color( 50, 50, 255 ) );
cmap_grad3.addColor( Color( 255, 0, 0 ) );
cmap_grad3.addColor( Color( 20, 200, 0 ) );
cmap_grad3.addColor( Color( 200, 200, 200 ) );
cmap_grad3.addColor( Color( 20, 200, 200 ) );
cmap_grad3.addColor( Color( 200, 20, 200 ) );
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,
cmap_grad3( d )))<<vectContoursBdrySCell.at(i).at(j) ;
}
}
board << aCell;
board.saveEPS( "ctopo-2.eps");
board.saveFIG( "ctopo-2.fig");
board2.saveEPS( "ctopo-2d.eps");
board2.saveFIG( "ctopo-2d.fig");
board3.saveEPS( "ctopo-2e.eps");
board3.saveFIG( "ctopo-2e.fig");
return (space_ok);
}
// //
DGtal::Surfaces
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
DGtal::SetFromImage
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:63
DGtal::KhalimskySpaceND::upperBound
const Point & upperBound() const
Return the upper bound for digital points in this space.
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::SurfelAdjacency
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
Definition: SurfelAdjacency.h:65
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
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::lowerBound
const Point & lowerBound() const
Return the lower bound for digital points in this space.
DGtal::SignedKhalimskyCell
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Definition: KhalimskySpaceND.h:208
DGtal::CustomStyle
Definition: Board2D.h:217
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition: testSimpleRandomAccessRangeFromPoint.cpp:45
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::CustomColors
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
DGtal::PGMReader
Aim: Import a 2D or 3D using the Netpbm formats (ASCII mode).
Definition: PGMReader.h:97
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:70
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
DGtal::GradientColorMap::addColor
void addColor(const Color &color)
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
DGtal::GradientColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition: GradientColorMap.h:119
DGtal::DigitalSetByAssociativeContainer
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Definition: DigitalSetByAssociativeContainer.h:89
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64