DGtal  1.4.beta
digitalSetToCubicalComplexes2D.cpp
Go to the documentation of this file.
1 
40 #include <iostream>
41 #include <cmath>
42 #include <map>
43 #include "ConfigExamples.h"
44 #include "DGtal/helpers/StdDefs.h"
45 #include "DGtal/base/Common.h"
46 // Cellular grid
47 #include "DGtal/topology/CubicalComplex.h"
48 // Shape construction
49 #include "DGtal/shapes/GaussDigitizer.h"
50 #include "DGtal/shapes/Shapes.h"
51 #include "DGtal/shapes/EuclideanShapesDecorator.h"
52 #include "DGtal/shapes/parametric/Flower2D.h"
53 // Drawing
54 #include "DGtal/io/boards/Board2D.h"
55 #include "DGtal/io/Color.h"
57 
58 using namespace std;
59 using namespace DGtal;
60 using namespace functors;
61 using namespace Z2i;
62 
64 
65 int main( int , char** )
66 {
67  trace.beginBlock ( "Example digitalSetToCubicalComplexes2D" );
68  trace.beginBlock ( "Generate a 2D shape." );
69  typedef Flower2D< Space > MyEuclideanShape;
70  MyEuclideanShape shape( RealPoint( 0.0, 0.0 ), 16, 5, 5, M_PI_2/2. );
71 
72  typedef GaussDigitizer< Space, MyEuclideanShape > MyGaussDigitizer;
73  MyGaussDigitizer digShape;
74  digShape.attach( shape );
75  digShape.init ( shape.getLowerBound(), shape.getUpperBound(), 1.0 );
76  Domain domainShape = digShape.getDomain();
77  DigitalSet aSet( domainShape );
78  Shapes<Domain>::digitalShaper( aSet, digShape );
79 
80  Board2D board;
81  board << SetMode( domainShape.className(), "Paving" ) << domainShape;
82  Color dorange ( 255, 136, 0, 220 );
83  board << CustomStyle( aSet.className(), new CustomFillColor ( dorange ) );
84  board << aSet;
85  trace.endBlock();
86 
87  trace.beginBlock ( "Generate a 2D cubical representation." );
88  typedef map<Cell, CubicalCellData> Map;
90 
91  KSpace K;
92  K.init ( domainShape.lowerBound(), domainShape.upperBound(), true );
93  CC complex ( K );
94  complex.construct< DigitalSet >( aSet );
95 
96  board << SetMode( domainShape.className(), "Paving" ) << domainShape;
97 
99  for ( Dimension d = 0; d <= 2; ++d )
100  for ( CellMapConstIterator it = complex.begin( d ), itE = complex.end( d );
101  it != itE; ++it )
102  {
103  if ( d == 0 )
104  board << CustomStyle( it->first.className(),
105  new CustomColors( Color( 0, 0, 0 ),
106  Color( 0, 0, 0 ) ) );
107  else if ( d == 1 )
108  board << CustomStyle( it->first.className(),
109  new CustomColors( Color( 200, 0, 0 ),
110  Color( 100, 255, 100 ) ) );
111  else
112  board << CustomStyle( it->first.className(),
113  new CustomColors( Color( 0, 0, 200 ),
114  Color( 100, 255, 100 ) ) );
115  board << it->first;
116  }
117 
118  board.saveEPS ( "cubicalComplexes.eps" );
119  trace.endBlock();
120  trace.endBlock();
121  return 0;
122 }
123 // //
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
std::string className() 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.
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
void beginBlock(const std::string &keyword="")
double endBlock()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:804
int main(int, char **)
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
Definition: Common.h:136
Trace trace
Definition: Common.h:153
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:279
Custom style class redefining the fill color. You may use Board2D::Color::None for transparent color.
Definition: Board2D.h:343
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
KSpace K
std::unordered_map< Cell, CubicalCellData > Map
CubicalComplex< KSpace, Map > CC
CC::CellMapConstIterator CellMapConstIterator
PointVector< 3, double > RealPoint