Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
testSimpleExpander.cpp
Go to the documentation of this file.
1
16
29
31#include <iostream>
32#include "DGtal/base/Common.h"
33#include "DGtal/kernel/SpaceND.h"
34#include "DGtal/kernel/domains/DomainPredicate.h"
35#include "DGtal/kernel/domains/HyperRectDomain.h"
36#include "DGtal/kernel/sets/DigitalSetSelector.h"
37#include "DGtal/kernel/sets/DigitalSetConverter.h"
38#include "DGtal/topology/MetricAdjacency.h"
39#include "DGtal/topology/DomainAdjacency.h"
40#include "DGtal/topology/DigitalTopology.h"
41#include "DGtal/topology/Object.h"
42#include "DGtal/graph/Expander.h"
43#include "DGtal/io/boards/Board2D.h"
44#include "DGtal/io/colormaps/GradientColorMap.h"
45#include "DGtal/io/Color.h"
46#include "DGtal/helpers/StdDefs.h"
48
49using namespace std;
50using namespace DGtal;
51
52
53
55{
56 virtual void setStyle(Board2D & aboard) const
57 {
58 aboard.setFillColorRGBi(0, 169, 0);
59 }
60};
61
63{
64 virtual void setStyle(Board2D & aboard) const
65 {
66 aboard.setFillColorRGBi(169, 0, 0);
67 }
68};
69
70// Functions for testing class SimpleExpander.
72
77{
78 trace.beginBlock ( "(4,8) Filling ..." );
79
80 //typedef int Integer; // choose your digital line here.
81 typedef SpaceND<2> Z2; // Z^2
82 typedef Z2::Point Point;
83 typedef MetricAdjacency<Z2, 1> Adj4; // 4-adjacency type
84 typedef MetricAdjacency<Z2, 2> Adj8; // 8-adjacency type
85 typedef DigitalTopology< Adj8, Adj4 > DT8_4; //8,4 topology type
87 //typedef Domain::ConstIterator DomainConstIterator;
89 typedef Object<DT8_4, DigitalSet> ObjectType;
90
91
92 typedef Object<DT8_4::ReverseTopology, DigitalSet> ObjectTypeReverseTopo;
93
94 typedef Expander<ObjectTypeReverseTopo> ObjectExpanderReverseTopo;
95 typedef Expander<ObjectType> ObjectExpander;
96
97 Point p1( -5, -5 );
98 Point p2( 5, 5 );
99 Domain domain( p1, p2 );
100
101 Adj4 adj4; // instance of 4-adjacency
102 Adj8 adj8; // instance of 8-adjacency
105
106 //We construct a simple "house" set
107 DigitalSet houseSet( domain );
108
109 for ( int k = -3; k < 3 ; k++)
110 {
111 houseSet.insert(Point(k, -3));
112 houseSet.insert(Point(-3, k));
113 houseSet.insert(Point(3, k));
114 houseSet.insert(Point(k, 3));
115 }
116
117 //We compute the complement
118 DigitalSet houseSetCompl( domain);
119 houseSetCompl.assignFromComplement( houseSet );
120
121 //We create the objects associated to the sets
122 ObjectType house8( dt8_4, houseSet );
123 ObjectType houseCompl8( dt8_4, houseSetCompl );
124 ObjectTypeReverseTopo house4(dt4_8, houseSet);
125 ObjectTypeReverseTopo houseCompl4( dt4_8, houseSetCompl );
126
127
128 //Board Export init
129 Board2D board;
131
132 //Border=4 Filling=4
133 board.clear();
134 board << SetMode( domain.className(), "Grid" ) << domain;
135 board << SetMode( house4.className(), "DrawAdjacencies" ) << house4;
136 ObjectExpanderReverseTopo expander(houseCompl4, Point(0, 0));
137 while (!expander.finished())
138 {
139 for ( ObjectExpander::ConstIterator it = expander.begin();
140 it != expander.end();
141 ++it )
142 std::cout << " " << *it;
143
144 expander.nextLayer();
145 }
146 board << CustomStyle(expander.core().className(), new MyStyleCustom) << expander.core();
147 board.saveSVG("house4-4.svg");
148
149 //Border=4 Filling=8
150 board.clear();
151 board << SetMode( domain.className(), "Grid" ) << domain;
152 board << SetMode( house4.className(), "DrawAdjacencies" ) << house4;
153 ObjectExpander expander8(houseCompl8, Point(0, 0));
154 while (!expander8.finished())
155 {
156 for ( ObjectExpander::ConstIterator it = expander8.begin();
157 it != expander8.end();
158 ++it )
159 std::cout << " " << *it;
160
161 expander8.nextLayer();
162 }
163 board << CustomStyle(expander8.core().className(), new MyStyleCustom) << expander8.core();
164 board.saveSVG("house4-8.svg");
165
166 //Border=8 Filling=8
167 board.clear();
168 board << SetMode( domain.className(), "Grid" ) << domain;
169 board << SetMode( house8.className(), "DrawAdjacencies" ) << house8;
170 ObjectExpander expander88(houseCompl8, Point(0, 0));
171 while (!expander88.finished())
172 {
173 for ( ObjectExpander::ConstIterator it = expander88.begin();
174 it != expander88.end();
175 ++it )
176 std::cout << " " << *it;
177
178 expander88.nextLayer();
179 }
180 board << CustomStyle(expander88.core().className(), new MyStyleCustom) << expander88.core();
181 board.saveSVG("house8-8.svg");
182
183 //Border=8 Filling=4
184 board.clear();
185 board << SetMode( domain.className(), "Grid" ) << domain;
186 board << SetMode( house8.className(), "DrawAdjacencies" ) << house8;
187 ObjectExpanderReverseTopo expander84(houseCompl4, Point(0, 0));
188 while (!expander84.finished())
189 {
190 for ( ObjectExpander::ConstIterator it = expander84.begin();
191 it != expander84.end();
192 ++it )
193 std::cout << " " << *it;
194
195 expander84.nextLayer();
196 }
197 board << CustomStyle(expander.core().className(), new MyStyleCustom) << expander84.core();
198 board.saveSVG("house8-4.svg");
199
200
201 trace.endBlock();
202
203 return true;
204}
205
206using namespace DGtal::Z2i;
207
209{
210
211 GradientColorMap<size_t> cmap_grad( 0, 30 );
212 cmap_grad.addColor( Color( 128, 128, 255 ) );
213 cmap_grad.addColor( Color( 255, 255, 128 ) );
214 cmap_grad.addColor( Color( 128, 255, 128 ) );
215 cmap_grad.addColor( Color( 128, 128, 128 ) );
216 //cmap_grad.addColor( Color( 220, 130, 25 ) );
217
218 trace.beginBlock ( "(4,8) Filling ..." );
219
220 //typedef Domain::ConstIterator DomainConstIterator;
221 typedef Object8_4 ObjectType;
222 typedef Object4_8 ObjectTypeReverseTopo;
223 typedef Expander<ObjectTypeReverseTopo> ObjectExpanderReverseTopo;
224 typedef Expander<ObjectType> ObjectExpander;
225
226 Point p1( -5, -5 );
227 Point p2( 5, 5 );
228 Domain domain( p1, p2 );
229
230
231 //We construct a simple "house" set
232 DigitalSet houseSet( domain );
233
234 for ( int k = -3; k < 3 ; k++)
235 {
236 houseSet.insert(Point(k, -3));
237 houseSet.insert(Point(-3, k));
238 houseSet.insert(Point(3, k));
239 houseSet.insert(Point(k, 3));
240 }
241
242 //We compute the complement
243 DigitalSet houseSetCompl( domain);
244 houseSetCompl.assignFromComplement( houseSet );
245
246 //We create the objects associated to the sets
247 ObjectType house8( dt8_4, houseSet );
248 ObjectType houseCompl8( dt8_4, houseSetCompl );
249 ObjectTypeReverseTopo house4( dt4_8, houseSet);
250 ObjectTypeReverseTopo houseCompl4( dt4_8, houseSetCompl );
251
252
253 //Board Export init
254 Board2D board;
256
257 //Border=4 Filling=4
258 board.clear();
259 board << SetMode( domain.className(), "Grid" ) << domain;
260 board << SetMode( house4.className(), "DrawAdjacencies" ) << house4;
261 ObjectExpanderReverseTopo expander(houseCompl4, Point(0, 0));
262 board << CustomStyle( expander.core().className(),
263 new CustomFillColor( cmap_grad( 0 ) ) )
264 << expander.core();
265 while (!expander.finished())
266 {
267 for ( ObjectExpander::ConstIterator it = expander.begin();
268 it != expander.end();
269 ++it )
270 std::cout << " " << *it;
271 board << CustomStyle( expander.layer().className(),
272 new CustomFillColor( cmap_grad( expander.distance() ) ) )
273 << expander.layer();
274
275 expander.nextLayer();
276 }
277 board.saveSVG("house-layers4-4.svg");
278
279 //Border=4 Filling=8
280 board.clear();
281 board << SetMode( domain.className(), "Grid" ) << domain;
282 board << SetMode( house4.className(), "DrawAdjacencies" ) << house4;
283 ObjectExpander expander8(houseCompl8, Point(0, 0));
284 board << CustomStyle( expander.core().className(),
285 new CustomFillColor( cmap_grad( 0 ) ) )
286 << expander8.core();
287 while (!expander8.finished())
288 {
289 for ( ObjectExpander::ConstIterator it = expander8.begin();
290 it != expander8.end();
291 ++it )
292 std::cout << " " << *it;
293
294 board << CustomStyle( expander8.layer().className(),
296 ( cmap_grad( expander8.distance() ) ) )
297 << expander8.layer();
298 expander8.nextLayer();
299 }
300 board.saveSVG("house-layers4-8.svg");
301
302 return true;
303}
304
306// Standard services - public :
307
308int main( int argc, char** argv )
309{
310 trace.info() << "Args:";
311 for ( int i = 0; i < argc; ++i )
312 trace.info() << " " << argv[ i ];
313 trace.info() << endl;
314
315 bool res = testSimpleExpander()
316 && testLayers();
317 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
318 return res ? 0 : 1;
319}
320// //
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:77
void assignFromComplement(const DigitalSetByAssociativeContainer< Domain, Container > &other_set)
DigitalTopology< BackgroundAdjacency, ForegroundAdjacency > ReverseTopology
Aim: This class is useful to visit an object by adjacencies, layer by layer.
Definition Expander.h:98
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Aim: Describes digital adjacencies in digital spaces that are defined with the 1-norm and the infinit...
Aim: An object (or digital object) represents a set in some digital space associated with a digital t...
Definition Object.h:120
PointVector< dim, Integer > Point
Definition SpaceND.h:110
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition Board.cpp:151
Board & setFillColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
Definition Board.cpp:304
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:1011
void setUnit(Unit unit)
Definition Board.cpp:239
Z2i this namespace gathers the standard of types for 2D imagery.
static const DT8_4 dt8_4
Definition StdDefs.h:114
Object< DT8_4, DigitalSet > Object8_4
Definition StdDefs.h:105
DigitalTopology< Adj8, Adj4 > DT8_4
Definition StdDefs.h:94
MetricAdjacency< Space, 1 > Adj4
Definition StdDefs.h:90
static const DT4_8 dt4_8
Definition StdDefs.h:113
Object< DT4_8, DigitalSet > Object4_8
Definition StdDefs.h:101
static const Adj4 adj4
Definition StdDefs.h:111
MetricAdjacency< Space, 2 > Adj8
Definition StdDefs.h:92
Space::Point Point
Definition StdDefs.h:95
static const Adj8 adj8
Definition StdDefs.h:112
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition StdDefs.h:100
Space Z2
Definition StdDefs.h:76
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
STL namespace.
Custom style class redefining the fill color. You may use Board2D::Color::None for transparent color.
Definition Board2D.h:343
DigitalSetByAssociativeContainer< Domain, std::unordered_set< typename Domain::Point > > Type
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition Board2D.h:247
virtual void setStyle(Board2D &aboard) const
virtual void setStyle(Board2D &aboard) const
int main()
Definition testBits.cpp:56
Domain domain
bool testSimpleExpander()
bool testLayers()