DGtal  0.9.3
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 }
void beginBlock(const std::string &keyword="")
std::unordered_map< Cell, CubicalCellData > Map
ConstIterator begin() const
Trace trace
Definition: Common.h:137
DGtal::uint32_t Dimension
Definition: Common.h:120
const Point & upperBound() const
void getComplex(CC &complex, KSpace &K)
STL namespace.
double endBlock()
void construct(const TDigitalSet &set)
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
CellMap::const_iterator CellMapConstIterator
Const iterator for visiting type CellMap.
void attach(const EuclideanShape &shape)
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:64
void attach(Alias< CC > pComplex)
CC::CellMapConstIterator CellMapConstIterator
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
Aim: This class represents an arbitrary cubical complex living in some Khalimsky space. Cubical complexes are sets of cells of different dimensions related together with incidence relations. Two cells in a cubical complex are incident if and only if they are incident in the surrounding Khalimsky space. In other words, cubical complexes are defined here as subsets of Khalimsky spaces.
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Implements thinning algorithms in cubical complexes. The implementation supports any model of cu...
unsigned int eval(unsigned int iterations)
CubicalComplex< KSpace, Map > CC
ConstIterator end() const
const Point & lowerBound() const
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
KSpace K
int main(int, char **)
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
void drawComplex(Board2D &board, CC &complex)
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70