DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testSimpleExpander.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/DomainPredicate.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/kernel/sets/DigitalSetSelector.h"
#include "DGtal/kernel/sets/DigitalSetConverter.h"
#include "DGtal/topology/MetricAdjacency.h"
#include "DGtal/topology/DomainMetricAdjacency.h"
#include "DGtal/topology/DomainAdjacency.h"
#include "DGtal/topology/DigitalTopology.h"
#include "DGtal/topology/Object.h"
#include "DGtal/graph/Expander.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/Color.h"
#include "DGtal/helpers/StdDefs.h"

Go to the source code of this file.

Functions

bool testSimpleExpander ()
 
bool testLayers ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2010/09/20

Functions for testing class SimpleExpander.

This file is part of the DGtal library.

Definition in file testSimpleExpander.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 310 of file testSimpleExpander.cpp.

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}
std::ostream & emphase()
std::ostream & info()
Trace trace
Definition: Common.h:154
bool testSimpleExpander()
bool testLayers()

References DGtal::Trace::emphase(), DGtal::Trace::info(), testLayers(), testSimpleExpander(), and DGtal::trace.

◆ testLayers()

bool testLayers ( )

Definition at line 209 of file testSimpleExpander.cpp.

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}
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...
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...
std::string className() const
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="")
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
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
static const DT8_4 dt8_4
Definition: StdDefs.h:114
static const DT4_8 dt4_8
Definition: StdDefs.h:113
Space::Point Point
Definition: StdDefs.h:95
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
Domain domain

References DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::addColor(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::assignFromComplement(), DGtal::Trace::beginBlock(), DGtal::HyperRectDomain< TSpace >::className(), LibBoard::Board::clear(), domain, DGtal::Z2i::dt4_8, DGtal::Z2i::dt8_4, DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::insert(), LibBoard::Board::saveSVG(), LibBoard::Board::setUnit(), DGtal::trace, and LibBoard::Board::UCentimeter.

Referenced by main().

◆ testSimpleExpander()

bool testSimpleExpander ( )

Example of a test. To be completed.

Definition at line 77 of file testSimpleExpander.cpp.

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}
Aim: Represents a digital topology as a couple of adjacency relations.
Aim: Describes digital adjacencies in digital spaces that are defined with the 1-norm and the infinit...
double endBlock()
DigitalTopology< Adj8, Adj4 > DT8_4
Definition: StdDefs.h:94
MetricAdjacency< Space, 1 > Adj4
Definition: StdDefs.h:90
static const Adj4 adj4
Definition: StdDefs.h:111
MetricAdjacency< Space, 2 > Adj8
Definition: StdDefs.h:92
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
DigitalSetByAssociativeContainer< Domain, std::unordered_set< typename Domain::Point > > Type

References DGtal::Z2i::adj4, DGtal::Z2i::adj8, DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::assignFromComplement(), DGtal::Trace::beginBlock(), DGtal::HyperRectDomain< TSpace >::className(), LibBoard::Board::clear(), domain, DGtal::Z2i::dt4_8, DGtal::Z2i::dt8_4, DGtal::Trace::endBlock(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::insert(), DGtal::JORDAN_DT, LibBoard::Board::saveSVG(), LibBoard::Board::setUnit(), DGtal::trace, and LibBoard::Board::UCentimeter.

Referenced by main().