DGtal 1.3.0
Loading...
Searching...
No Matches
cubicalComplexThinning.cpp
Go to the documentation of this file.
1
31#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
47using namespace std;
48using namespace DGtal;
49using namespace Z2i;
50
52
53template <typename CC, typename KSpace>
54void 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
72template <typename CC>
73void 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
101int 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}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Aim: This class represents an arbitrary cubical complex living in some Khalimsky space....
ConstIterator end() const
void construct(const TDigitalSet &set)
ConstIterator begin() const
CellMap::const_iterator CellMapConstIterator
Const iterator for visiting type CellMap.
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:65
void attach(ConstAlias< EuclideanShape > shape)
const Point & lowerBound() const
const Point & upperBound() const
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
void attach(Alias< CC > pComplex)
unsigned int eval(unsigned int iterations)
static void digitalShaper(TDigitalSet &aSet, const TShapeFunctor &aFunctor)
void beginBlock(const std::string &keyword="")
double endBlock()
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
void getComplex(CC &complex, KSpace &K)
void drawComplex(Board2D &board, CC &complex)
Space::RealPoint RealPoint
Definition: StdDefs.h:97
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
Definition: Common.h:137
Trace trace
Definition: Common.h:154
STL namespace.
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:279
int main()
Definition: testBits.cpp:56
KSpace K
std::unordered_map< Cell, CubicalCellData > Map
CubicalComplex< KSpace, Map > CC
CC::CellMapConstIterator CellMapConstIterator