DGtal  0.9.2
cubical-complex-illustrations.cpp
1 
30 #include <iostream>
32 #include <map>
33 #include "DGtal/base/Common.h"
34 #include "DGtal/helpers/StdDefs.h"
35 
36 #include "DGtal/topology/KhalimskySpaceND.h"
37 #include "DGtal/topology/CubicalComplex.h"
38 #include "DGtal/topology/CubicalComplexFunctions.h"
39 #include "DGtal/io/boards/Board2D.h"
40 
42 
43 using namespace std;
44 using namespace DGtal;
45 
46 
47 int main( int /* argc */, char** /* argv */ )
48 {
49 
51  using namespace DGtal::Z2i;
53 
54  KSpace K;
55  K.init( Point( 0,0 ), Point( 5,3 ), true );
56  trace.beginBlock( "Creating Cubical Complex" );
57  CC X( K );
58  Domain domain( Point( 0,0 ), Point( 5,3 ) );
59  X.insertCell( K.uSpel( Point(1,1) ) );
60  X.insertCell( K.uSpel( Point(2,1) ) );
61  X.insertCell( K.uSpel( Point(3,1) ) );
62  X.insertCell( K.uSpel( Point(2,2) ) );
63  X.insertCell( K.uSpel( Point(3,2) ) );
64  X.insertCell( K.uSpel( Point(4,2) ) );
65  X.close();
66  trace.endBlock();
67 
68  trace.beginBlock( "Displays Cubical Complex" );
69  Board2D board;
70  board << domain;
71  board << CustomStyle( X.className(),
72  new CustomColors( Color(80,80,100), Color(180,180,200) ) )
73  << X;
74  board.saveTikZ( "cubical-complex-illustrations-X.tikz" );
75  trace.endBlock();
77 
79  CC S( K );
80  S.insertCell( K.uCell( Point( 5, 4 ) ) ); // a linel
81  S.insertCell( K.uCell( Point( 4, 4 ) ) ); // a pointel
82  S.insertCell( K.uCell( Point( 7, 5 ) ) ); // a pixel
83  board << CustomStyle( X.className(),
84  new CustomColors( Color::Black, Color(60,60,60) ) )
85  << S;
86  board.saveTikZ( "cubical-complex-illustrations-S.tikz" );
87  board.clear();
89 
91  board << domain;
92  board << CustomStyle( X.className(),
93  new CustomColors( Color(80,80,100), Color(180,180,200) ) )
94  << X;
95  board << CustomStyle( X.className(),
96  new CustomColors( Color::Red, Color(255,120,120) ) )
97  << X.closure( S );
98  board.saveTikZ( "cubical-complex-illustrations-closure.tikz" );
99  board.clear();
101 
103  board << domain;
104  board << CustomStyle( X.className(),
105  new CustomColors( Color(80,80,100), Color(180,180,200) ) )
106  << X;
107  board << CustomStyle( X.className(),
108  new CustomColors( Color::Blue, Color(120,120,255) ) )
109  << X.star( S );
110  board.saveTikZ( "cubical-complex-illustrations-star.tikz" );
111  board.clear();
113 
115  board << domain;
116  board << CustomStyle( X.className(),
117  new CustomColors( Color(80,80,100), Color(180,180,200) ) )
118  << X;
119  board << CustomStyle( X.className(),
120  new CustomColors( Color::Green, Color(120,255,120) ) )
121  << X.link( S );
122  board.saveTikZ( "cubical-complex-illustrations-link.tikz" );
123  board.clear();
125 
127  board << domain;
128  board << CustomStyle( X.className(),
129  new CustomColors( Color(80,80,100), Color(180,180,200) ) )
130  << X;
131  board << CustomStyle( X.className(),
132  new CustomColors( Color::Magenta, Color(255,120,255) ) )
133  << X.boundary();
134  board.saveTikZ( "cubical-complex-illustrations-bd.tikz" );
135  board.clear();
137 
139  board << domain;
140  board << CustomStyle( X.className(),
141  new CustomColors( Color(80,80,100), Color(180,180,200) ) )
142  << X;
143  board << CustomStyle( X.className(),
144  new CustomColors( Color::Cyan, Color(120,255,255) ) )
145  << X.interior();
146  board.saveTikZ( "cubical-complex-illustrations-int.tikz" );
147  board.clear();
149 
151  board << domain;
152  board << CustomStyle( X.className(),
153  new CustomColors( Color(80,80,100), Color(180,180,200) ) )
154  << X;
155  Cell p1 = K.uCell( Point(2,2) );
156  Cell p2 = K.uCell( Point(10,6) );
157  X[ p1 ] = CC::FIXED;
158  X[ p2 ] = CC::FIXED;
160  functions::collapse( X, X.begin(), X.end(), P, true, true, true );
161  board << CustomStyle( X.className(),
162  new CustomColors( Color(255,120,20), Color(255,150,50) ) )
163  << X
164  << CustomStyle( p1.className(),
165  new CustomColors( Color::Blue, Color(120,120,255) ) )
166  << p1 << p2;
167  board.saveTikZ( "cubical-complex-illustrations-collapse.tikz" );
168  board.clear();
170 
171  return 0;
172 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:130
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
Cell uCell(const PreCell &c) const
void saveTikZ(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1219
bool init(const Point &lower, const Point &upper, bool isClosed)
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.
Z2i this namespace gathers the standard of types for 2D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
Cell uSpel(Point p) const
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex...
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70