DGtal  1.3.beta
cubicalComplexThinning.cpp
Go to the documentation of this file.
1 
30 #include "ConfigExamples.h"
32 #include "DGtal/helpers/StdDefs.h"
33 // Cellular grid
34 #include "DGtal/topology/CubicalComplex.h"
36 #include "DGtal/topology/ParDirCollapse.h"
38 // Shape construction
39 #include "DGtal/shapes/GaussDigitizer.h"
40 #include "DGtal/shapes/Shapes.h"
41 #include "DGtal/shapes/EuclideanShapesDecorator.h"
42 #include "DGtal/shapes/parametric/Flower2D.h"
43 // Drawing
44 #include "DGtal/io/boards/Board2D.h"
46 
47 using namespace std;
48 using namespace DGtal;
49 using namespace Z2i;
50 
52 
53 template <typename CC, typename KSpace>
54 void getComplex ( CC & complex, KSpace & K )
55 {
56  typedef Flower2D< Space > MyEuclideanShape;
57  MyEuclideanShape shape( RealPoint( 0.0, 0.0 ), 16, 5, 5, M_PI_2/2. );
58 
59  typedef GaussDigitizer< Space, MyEuclideanShape > MyGaussDigitizer;
60  MyGaussDigitizer digShape;
61  digShape.attach( shape );
62  digShape.init ( shape.getLowerBound(), shape.getUpperBound(), 1.0 );
63  Domain domainShape = digShape.getDomain();
64  DigitalSet aSet( domainShape );
65  Shapes<Domain>::digitalShaper( aSet, digShape );
66 
67  K.init ( domainShape.lowerBound(), domainShape.upperBound(), true );
68  complex.clear();
69  complex.construct ( aSet );
70 }
71 
72 template <typename CC>
73 void drawComplex ( Board2D & board, CC & complex )
74 {
75  board.clear();
77  for ( Dimension d = 0; d <= 2; ++d )
78  for ( CellMapConstIterator it = complex.begin( d ), itE = complex.end( d );
79  it != itE; ++it )
80  {
81  if ( d == 0 )
82  board << CustomStyle( it->first.className(),
83  new CustomColors( Color( 0, 0, 0 ),
84  Color( 0, 0, 0 ) ) );
85  else if ( d == 1 )
86  board << CustomStyle( it->first.className(),
87  new CustomColors( Color( 200, 0, 0 ),
88  Color( 100, 255, 100 ) ) );
89  else
90  board << CustomStyle( it->first.className(),
91  new CustomColors( Color( 0, 0, 200 ),
92  Color( 100, 255, 100 ) ) );
93  board << it->first;
94  }
95 }
96 
98 // //
99 
100 
101 int main( int, char** )
102 {
103  typedef map<Cell, CubicalCellData> Map;
105  Board2D board;
106  KSpace K;
107  CC complex ( K );
109  ParDirCollapse < CC > thinning ( K );
111  trace.beginBlock ( "ParDirCollapse -- 2 iterations." );
112  getComplex< CC, KSpace > ( complex, K );
113  drawComplex<CC> ( board, complex );
114  board.saveEPS ( "ComplexBeforeThinning.eps" );
116  thinning.attach ( &complex );
118 
120  thinning.eval ( 2 );
122  drawComplex<CC> ( board, complex );
123  board.saveEPS ( "ParDirCollapse_2.eps" );
124  trace.endBlock();
125 
126  trace.beginBlock ( "ParDirCollapse -- collapseSurface." );
127  getComplex< CC, KSpace > ( complex, K );
128  thinning.attach ( &complex );
130  thinning.collapseSurface ();
132  drawComplex<CC> ( board, complex );
133  board.saveEPS ( "ParDirCollapse_collapseSurface.eps" );
134  trace.endBlock();
135 
136  trace.beginBlock ( "ParDirCollapse -- collapseIsthmus." );
137  getComplex< CC, KSpace > ( complex, K );
138  thinning.attach ( &complex );
140  thinning.collapseIsthmus ();
142  drawComplex<CC> ( board, complex );
143  board.saveEPS ( "ParDirCollapse_collapseIsthmus.eps" );
144  trace.endBlock();
145  return 0;
146 }
DGtal::GaussDigitizer< Space, MyEuclideanShape >
DGtal::CubicalComplex::clear
void clear()
DGtal::HyperRectDomain< Space >
DGtal::Trace::endBlock
double endBlock()
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
DGtal::HyperRectDomain::upperBound
const Point & upperBound() const
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.
CellMapConstIterator
CC::CellMapConstIterator CellMapConstIterator
Definition: testCubicalComplex.cpp:59
DGtal::ParDirCollapse
Aim: Implements thinning algorithms in cubical complexes. The implementation supports any model of cu...
Definition: ParDirCollapse.h:77
DGtal::ParDirCollapse::collapseSurface
void collapseSurface()
DGtal::CubicalComplex::begin
ConstIterator begin() const
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::GaussDigitizer::attach
void attach(ConstAlias< EuclideanShape > shape)
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::Dimension
DGtal::uint32_t Dimension
Definition: Common.h:137
DGtal::CubicalComplex::CellMapConstIterator
CellMap::const_iterator CellMapConstIterator
Const iterator for visiting type CellMap.
Definition: CubicalComplex.h:252
DGtal::ParDirCollapse::attach
void attach(Alias< CC > pComplex)
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
getComplex
void getComplex(CC &complex, KSpace &K)
Definition: cubicalComplexThinning.cpp:54
LibBoard::Board::clear
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
Map
std::unordered_map< Cell, CubicalCellData > Map
Definition: testCubicalComplex.cpp:57
DGtal::CubicalComplex::construct
void construct(const TDigitalSet &set)
DGtal::CustomStyle
Definition: Board2D.h:217
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
drawComplex
void drawComplex(Board2D &board, CC &complex)
Definition: cubicalComplexThinning.cpp:73
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::ParDirCollapse::collapseIsthmus
void collapseIsthmus()
main
int main(int, char **)
Definition: cubicalComplexThinning.cpp:101
CC
CubicalComplex< KSpace, Map > CC
Definition: testCubicalComplex.cpp:58
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:70
DGtal::Shapes
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
Definition: DGtal/shapes/Shapes.h:71
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
DGtal::Flower2D
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:64
DGtal::CubicalComplex::end
ConstIterator end() const
DGtal::CubicalComplex
Aim: This class represents an arbitrary cubical complex living in some Khalimsky space....
Definition: CubicalComplex.h:84
RealPoint
Z2i::RealPoint RealPoint
Definition: testAstroid2D.cpp:46
DGtal::ParDirCollapse::eval
unsigned int eval(unsigned int iterations)
DGtal::HyperRectDomain::lowerBound
const Point & lowerBound() const
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64