DGtal 1.3.0
Loading...
Searching...
No Matches
testSimpleExpander.cpp
Go to the documentation of this file.
1
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/DomainMetricAdjacency.h"
40#include "DGtal/topology/DomainAdjacency.h"
41#include "DGtal/topology/DigitalTopology.h"
42#include "DGtal/topology/Object.h"
43#include "DGtal/graph/Expander.h"
44#include "DGtal/io/boards/Board2D.h"
45#include "DGtal/io/colormaps/GradientColorMap.h"
46#include "DGtal/io/Color.h"
47#include "DGtal/helpers/StdDefs.h"
49
50using namespace std;
51using namespace DGtal;
52
53
54
55struct MyStyleCustom : public DrawableWithBoard2D
56{
57 virtual void setStyle(Board2D & aboard) const
58 {
59 aboard.setFillColorRGBi(0, 169, 0);
60 }
61};
62
63struct MyStyleCustomRed : public DrawableWithBoard2D
64{
65 virtual void setStyle(Board2D & aboard) const
66 {
67 aboard.setFillColorRGBi(169, 0, 0);
68 }
69};
71// Functions for testing class SimpleExpander.
73
78{
79 trace.beginBlock ( "(4,8) Filling ..." );
80
81 //typedef int Integer; // choose your digital line here.
82 typedef SpaceND<2> Z2; // Z^2
83 typedef Z2::Point Point;
84 typedef MetricAdjacency<Z2, 1> Adj4; // 4-adjacency type
85 typedef MetricAdjacency<Z2, 2> Adj8; // 8-adjacency type
86 typedef DigitalTopology< Adj8, Adj4 > DT8_4; //8,4 topology type
88 //typedef Domain::ConstIterator DomainConstIterator;
90 typedef Object<DT8_4, DigitalSet> ObjectType;
91
92
93 typedef Object<DT8_4::ReverseTopology, DigitalSet> ObjectTypeReverseTopo;
94
95 typedef Expander<ObjectTypeReverseTopo> ObjectExpanderReverseTopo;
96 typedef Expander<ObjectType> ObjectExpander;
97
98 Point p1( -5, -5 );
99 Point p2( 5, 5 );
100 Domain domain( p1, p2 );
101
102 Adj4 adj4; // instance of 4-adjacency
103 Adj8 adj8; // instance of 8-adjacency
106
107 //We construct a simple "house" set
108 DigitalSet houseSet( domain );
109
110 for ( int k = -3; k < 3 ; k++)
111 {
112 houseSet.insert(Point(k, -3));
113 houseSet.insert(Point(-3, k));
114 houseSet.insert(Point(3, k));
115 houseSet.insert(Point(k, 3));
116 }
117
118 //We compute the complement
119 DigitalSet houseSetCompl( domain);
120 houseSetCompl.assignFromComplement( houseSet );
121
122 //We create the objects associated to the sets
123 ObjectType house8( dt8_4, houseSet );
124 ObjectType houseCompl8( dt8_4, houseSetCompl );
125 ObjectTypeReverseTopo house4(dt4_8, houseSet);
126 ObjectTypeReverseTopo houseCompl4( dt4_8, houseSetCompl );
127
128
129 //Board Export init
130 Board2D board;
132
133 //Border=4 Filling=4
134 board.clear();
135 board << SetMode( domain.className(), "Grid" ) << domain;
136 board << SetMode( house4.className(), "DrawAdjacencies" ) << house4;
137 ObjectExpanderReverseTopo expander(houseCompl4, Point(0, 0));
138 while (!expander.finished())
139 {
140 for ( ObjectExpander::ConstIterator it = expander.begin();
141 it != expander.end();
142 ++it )
143 std::cout << " " << *it;
144
145 expander.nextLayer();
146 }
147 board << CustomStyle(expander.core().className(), new MyStyleCustom) << expander.core();
148 board.saveSVG("house4-4.svg");
149
150 //Border=4 Filling=8
151 board.clear();
152 board << SetMode( domain.className(), "Grid" ) << domain;
153 board << SetMode( house4.className(), "DrawAdjacencies" ) << house4;
154 ObjectExpander expander8(houseCompl8, Point(0, 0));
155 while (!expander8.finished())
156 {
157 for ( ObjectExpander::ConstIterator it = expander8.begin();
158 it != expander8.end();
159 ++it )
160 std::cout << " " << *it;
161
162 expander8.nextLayer();
163 }
164 board << CustomStyle(expander8.core().className(), new MyStyleCustom) << expander8.core();
165 board.saveSVG("house4-8.svg");
166
167 //Border=8 Filling=8
168 board.clear();
169 board << SetMode( domain.className(), "Grid" ) << domain;
170 board << SetMode( house8.className(), "DrawAdjacencies" ) << house8;
171 ObjectExpander expander88(houseCompl8, Point(0, 0));
172 while (!expander88.finished())
173 {
174 for ( ObjectExpander::ConstIterator it = expander88.begin();
175 it != expander88.end();
176 ++it )
177 std::cout << " " << *it;
178
179 expander88.nextLayer();
180 }
181 board << CustomStyle(expander88.core().className(), new MyStyleCustom) << expander88.core();
182 board.saveSVG("house8-8.svg");
183
184 //Border=8 Filling=4
185 board.clear();
186 board << SetMode( domain.className(), "Grid" ) << domain;
187 board << SetMode( house8.className(), "DrawAdjacencies" ) << house8;
188 ObjectExpanderReverseTopo expander84(houseCompl4, Point(0, 0));
189 while (!expander84.finished())
190 {
191 for ( ObjectExpander::ConstIterator it = expander84.begin();
192 it != expander84.end();
193 ++it )
194 std::cout << " " << *it;
195
196 expander84.nextLayer();
197 }
198 board << CustomStyle(expander.core().className(), new MyStyleCustom) << expander84.core();
199 board.saveSVG("house8-4.svg");
200
201
202 trace.endBlock();
203
204 return true;
205}
206
207using namespace DGtal::Z2i;
208
210{
211
212 GradientColorMap<int> cmap_grad( 0, 30 );
213 cmap_grad.addColor( Color( 128, 128, 255 ) );
214 cmap_grad.addColor( Color( 255, 255, 128 ) );
215 cmap_grad.addColor( Color( 128, 255, 128 ) );
216 cmap_grad.addColor( Color( 128, 128, 128 ) );
217 //cmap_grad.addColor( Color( 220, 130, 25 ) );
218
219 trace.beginBlock ( "(4,8) Filling ..." );
220
221 //typedef Domain::ConstIterator DomainConstIterator;
222 typedef Object8_4 ObjectType;
223 typedef Object4_8 ObjectTypeReverseTopo;
224 typedef Expander<ObjectTypeReverseTopo> ObjectExpanderReverseTopo;
225 typedef Expander<ObjectType> ObjectExpander;
226
227 Point p1( -5, -5 );
228 Point p2( 5, 5 );
229 Domain domain( p1, p2 );
230
231
232 //We construct a simple "house" set
233 DigitalSet houseSet( domain );
234
235 for ( int k = -3; k < 3 ; k++)
236 {
237 houseSet.insert(Point(k, -3));
238 houseSet.insert(Point(-3, k));
239 houseSet.insert(Point(3, k));
240 houseSet.insert(Point(k, 3));
241 }
242
243 //We compute the complement
244 DigitalSet houseSetCompl( domain);
245 houseSetCompl.assignFromComplement( houseSet );
246
247 //We create the objects associated to the sets
248 ObjectType house8( dt8_4, houseSet );
249 ObjectType houseCompl8( dt8_4, houseSetCompl );
250 ObjectTypeReverseTopo house4( dt4_8, houseSet);
251 ObjectTypeReverseTopo houseCompl4( dt4_8, houseSetCompl );
252
253
254 //Board Export init
255 Board2D board;
257
258 //Border=4 Filling=4
259 board.clear();
260 board << SetMode( domain.className(), "Grid" ) << domain;
261 board << SetMode( house4.className(), "DrawAdjacencies" ) << house4;
262 ObjectExpanderReverseTopo expander(houseCompl4, Point(0, 0));
263 board << CustomStyle( expander.core().className(),
264 new CustomFillColor( cmap_grad( 0 ) ) )
265 << expander.core();
266 while (!expander.finished())
267 {
268 for ( ObjectExpander::ConstIterator it = expander.begin();
269 it != expander.end();
270 ++it )
271 std::cout << " " << *it;
272 board << CustomStyle( expander.layer().className(),
274 ( cmap_grad( expander.distance() ) ) )
275 << expander.layer();
276
277 expander.nextLayer();
278 }
279 board.saveSVG("house-layers4-4.svg");
280
281 //Border=4 Filling=8
282 board.clear();
283 board << SetMode( domain.className(), "Grid" ) << domain;
284 board << SetMode( house4.className(), "DrawAdjacencies" ) << house4;
285 ObjectExpander expander8(houseCompl8, Point(0, 0));
286 board << CustomStyle( expander.core().className(),
287 new CustomFillColor( cmap_grad( 0 ) ) )
288 << expander8.core();
289 while (!expander8.finished())
290 {
291 for ( ObjectExpander::ConstIterator it = expander8.begin();
292 it != expander8.end();
293 ++it )
294 std::cout << " " << *it;
295
296 board << CustomStyle( expander8.layer().className(),
298 ( cmap_grad( expander8.distance() ) ) )
299 << expander8.layer();
300 expander8.nextLayer();
301 }
302 board.saveSVG("house-layers4-8.svg");
303
304 return true;
305}
306
308// Standard services - public :
309
310int main( int argc, char** argv )
311{
312 trace.info() << "Args:";
313 for ( int i = 0; i < argc; ++i )
314 trace.info() << " " << argv[ i ];
315 trace.info() << endl;
316
317 bool res = testSimpleExpander()
318 && testLayers();
319 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
320 return res ? 0 : 1;
321}
322// //
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: A wrapper class around a STL associative container for storing sets of digital points within som...
void assignFromComplement(const DigitalSetByAssociativeContainer< Domain, Container > &other_set)
Aim: Represents a digital topology as a couple of adjacency relations.
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'.
std::string className() const
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
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
Board & setFillColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
Definition: Board.cpp:305
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
void setUnit(Unit unit)
Definition: Board.cpp:240
Z2i this namespace gathers the standard of types for 2D imagery.
static const DT8_4 dt8_4
Definition: StdDefs.h:114
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
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
HyperRectDomain< Space > Domain
Definition: StdDefs.h:99
Space Z2
Definition: StdDefs.h:76
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
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
virtual void setStyle(Board2D &) const
Definition: Common.h:226
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
int main()
Definition: testBits.cpp:56
Domain domain
bool testSimpleExpander()
bool testLayers()