DGtal  0.9.2
digitalSetToCubicalComplexes2D.cpp
1 
30 #include <iostream>
32 #include <cmath>
33 #include <map>
34 #include "ConfigExamples.h"
35 #include "DGtal/helpers/StdDefs.h"
36 #include "DGtal/base/Common.h"
37 // Cellular grid
38 #include "DGtal/topology/CubicalComplex.h"
39 // Shape construction
40 #include "DGtal/shapes/GaussDigitizer.h"
41 #include "DGtal/shapes/Shapes.h"
42 #include "DGtal/shapes/EuclideanShapesDecorator.h"
43 #include "DGtal/shapes/parametric/Flower2D.h"
44 // Drawing
45 #include "DGtal/io/boards/Board2D.h"
46 #include "DGtal/io/Color.h"
48 
49 using namespace std;
50 using namespace DGtal;
51 using namespace functors;
52 using namespace Z2i;
53 
55 
56 int main( int , char** )
57 {
58  trace.beginBlock ( "Example digitalSetToCubicalComplexes2D" );
59  trace.beginBlock ( "Generate a 2D shape." );
60  typedef Flower2D< Space > MyEuclideanShape;
61  MyEuclideanShape shape( RealPoint( 0.0, 0.0 ), 16, 5, 5, M_PI_2/2. );
62 
63  typedef GaussDigitizer< Space, MyEuclideanShape > MyGaussDigitizer;
64  MyGaussDigitizer digShape;
65  digShape.attach( shape );
66  digShape.init ( shape.getLowerBound(), shape.getUpperBound(), 1.0 );
67  Domain domainShape = digShape.getDomain();
68  DigitalSet aSet( domainShape );
69  Shapes<Domain>::digitalShaper( aSet, digShape );
70 
71  Board2D board;
72  board << SetMode( domainShape.className(), "Paving" ) << domainShape;
73  Color dorange ( 255, 136, 0, 220 );
74  board << CustomStyle( aSet.className(), new CustomFillColor ( dorange ) );
75  board << aSet;
76  trace.endBlock();
77 
78  trace.beginBlock ( "Generate a 2D cubical representation." );
79  typedef map<Cell, CubicalCellData> Map;
81 
82  KSpace K;
83  K.init ( domainShape.lowerBound(), domainShape.upperBound(), true );
84  CC complex ( K );
85  complex.construct< DigitalSet >( aSet );
86 
87  board << SetMode( domainShape.className(), "Paving" ) << domainShape;
88 
89  typedef CC::CellMapConstIterator CellMapConstIterator;
90  for ( Dimension d = 0; d <= 2; ++d )
91  for ( CellMapConstIterator it = complex.begin( d ), itE = complex.end( d );
92  it != itE; ++it )
93  {
94  if ( d == 0 )
95  board << CustomStyle( it->first.className(),
96  new CustomColors( Color( 0, 0, 0 ),
97  Color( 0, 0, 0 ) ) );
98  else if ( d == 1 )
99  board << CustomStyle( it->first.className(),
100  new CustomColors( Color( 200, 0, 0 ),
101  Color( 100, 255, 100 ) ) );
102  else
103  board << CustomStyle( it->first.className(),
104  new CustomColors( Color( 0, 0, 200 ),
105  Color( 100, 255, 100 ) ) );
106  board << it->first;
107  }
108 
109  board.saveEPS ( "cubicalComplexes.eps" );
110  trace.endBlock();
111  trace.endBlock();
112  return 0;
113 }
114 // //
void beginBlock(const std::string &keyword="")
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
Trace trace
Definition: Common.h:130
Custom style class redefining the fill color. You may use Board2D::Color::None for transparent color...
Definition: Board2D.h:342
DGtal::uint32_t Dimension
Definition: Common.h:113
KhalimskySpaceND< 2, Integer > KSpace
Definition: StdDefs.h:77
STL namespace.
double endBlock()
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
std::string className() const
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.
const Point & upperBound() const
DGtal is the top-level namespace which contains all DGtal functions and types.
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
Space::RealPoint RealPoint
Definition: StdDefs.h:97
const Point & lowerBound() const
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70