DGtal  0.9.3
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"
Include dependency graph for testSimpleExpander.cpp:

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 317 of file testSimpleExpander.cpp.

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

318 {
319  trace.info() << "Args:";
320  for ( int i = 0; i < argc; ++i )
321  trace.info() << " " << argv[ i ];
322  trace.info() << endl;
323 
324  bool res = testSimpleExpander()
325  && testLayers();
326  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
327  return res ? 0 : 1;
328 }
bool testSimpleExpander()
Trace trace
Definition: Common.h:137
std::ostream & emphase()
std::ostream & info()
bool testLayers()

◆ testLayers()

bool testLayers ( )

Definition at line 216 of file testSimpleExpander.cpp.

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::DigitalSetByAssociativeContainer< TDomain, TContainer >::insert(), LibBoard::Board::saveSVG(), LibBoard::Board::setUnit(), DGtal::trace, and LibBoard::Board::UCentimeter.

Referenced by main().

217 {
218 
219  GradientColorMap<int> cmap_grad( 0, 30 );
220  cmap_grad.addColor( Color( 128, 128, 255 ) );
221  cmap_grad.addColor( Color( 255, 255, 128 ) );
222  cmap_grad.addColor( Color( 128, 255, 128 ) );
223  cmap_grad.addColor( Color( 128, 128, 128 ) );
224  //cmap_grad.addColor( Color( 220, 130, 25 ) );
225 
226  trace.beginBlock ( "(4,8) Filling ..." );
227 
228  //typedef Domain::ConstIterator DomainConstIterator;
229  typedef Object8_4 ObjectType;
230  typedef Object4_8 ObjectTypeReverseTopo;
231  typedef Expander<ObjectTypeReverseTopo> ObjectExpanderReverseTopo;
232  typedef Expander<ObjectType> ObjectExpander;
233 
234  Point p1( -5, -5 );
235  Point p2( 5, 5 );
236  Domain domain( p1, p2 );
237 
238 
239  //We construct a simple "house" set
240  DigitalSet houseSet( domain );
241 
242  for ( int k = -3; k < 3 ; k++)
243  {
244  houseSet.insert(Point(k, -3));
245  houseSet.insert(Point(-3, k));
246  houseSet.insert(Point(3, k));
247  houseSet.insert(Point(k, 3));
248  }
249 
250  //We compute the complement
251  DigitalSet houseSetCompl( domain);
252  houseSetCompl.assignFromComplement( houseSet );
253 
254  //We create the objects associated to the sets
255  ObjectType house8( dt8_4, houseSet );
256  ObjectType houseCompl8( dt8_4, houseSetCompl );
257  ObjectTypeReverseTopo house4( dt4_8, houseSet);
258  ObjectTypeReverseTopo houseCompl4( dt4_8, houseSetCompl );
259 
260 
261  //Board Export init
262  Board2D board;
264 
265  //Border=4 Filling=4
266  board.clear();
267  board << SetMode( domain.className(), "Grid" ) << domain;
268  board << SetMode( house4.className(), "DrawAdjacencies" ) << house4;
269  ObjectExpanderReverseTopo expander(houseCompl4, Point(0, 0));
270  board << CustomStyle( expander.core().className(),
271  new CustomFillColor( cmap_grad( 0 ) ) )
272  << expander.core();
273  while (!expander.finished())
274  {
275  for ( ObjectExpander::ConstIterator it = expander.begin();
276  it != expander.end();
277  ++it )
278  std::cout << " " << *it;
279  board << CustomStyle( expander.layer().className(),
280  new CustomFillColor
281  ( cmap_grad( expander.distance() ) ) )
282  << expander.layer();
283 
284  expander.nextLayer();
285  }
286  board.saveSVG("house-layers4-4.svg");
287 
288  //Border=4 Filling=8
289  board.clear();
290  board << SetMode( domain.className(), "Grid" ) << domain;
291  board << SetMode( house4.className(), "DrawAdjacencies" ) << house4;
292  ObjectExpander expander8(houseCompl8, Point(0, 0));
293  board << CustomStyle( expander.core().className(),
294  new CustomFillColor( cmap_grad( 0 ) ) )
295  << expander8.core();
296  while (!expander8.finished())
297  {
298  for ( ObjectExpander::ConstIterator it = expander8.begin();
299  it != expander8.end();
300  ++it )
301  std::cout << " " << *it;
302 
303  board << CustomStyle( expander8.layer().className(),
304  new CustomFillColor
305  ( cmap_grad( expander8.distance() ) ) )
306  << expander8.layer();
307  expander8.nextLayer();
308  }
309  board.saveSVG("house-layers4-8.svg");
310 
311  return true;
312 }
Aim: An object (or digital object) represents a set in some digital space associated with a digital t...
Definition: Object.h:119
void beginBlock(const std::string &keyword="")
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
const Domain domain(Point(1, 2), Point(6, 5))
MyDigitalSurface::ConstIterator ConstIterator
Trace trace
Definition: Common.h:137
Custom style class redefining the fill color. You may use Board2D::Color::None for transparent color...
Definition: Board2D.h:342
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
Aim: This class is useful to visit an object by adjacencies, layer by layer.
Definition: Expander.h:97
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
std::string className() const
MyPointD Point
Definition: testClone2.cpp:383
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
void setUnit(Unit unit)
Definition: Board.cpp:240
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70

◆ testSimpleExpander()

bool testSimpleExpander ( )

Example of a test. To be completed.

Definition at line 77 of file testSimpleExpander.cpp.

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

Referenced by main().

78 {
79  unsigned int nbok = 0;
80  unsigned int nb = 0;
81 
82  trace.beginBlock ( "(4,8) Filling ..." );
83 
84  //typedef int Integer; // choose your digital line here.
85  typedef SpaceND<2> Z2; // Z^2
86  typedef Z2::Point Point;
87  typedef MetricAdjacency<Z2, 1> Adj4; // 4-adjacency type
88  typedef MetricAdjacency<Z2, 2> Adj8; // 8-adjacency type
89  typedef DigitalTopology< Adj8, Adj4 > DT8_4; //8,4 topology type
91  //typedef Domain::ConstIterator DomainConstIterator;
93  typedef Object<DT8_4, DigitalSet> ObjectType;
94 
95 
96  typedef Object<DT8_4::ReverseTopology, DigitalSet> ObjectTypeReverseTopo;
97 
98  typedef Expander<ObjectTypeReverseTopo> ObjectExpanderReverseTopo;
99  typedef Expander<ObjectType> ObjectExpander;
100 
101  Point p1( -5, -5 );
102  Point p2( 5, 5 );
103  Domain domain( p1, p2 );
104 
105  Adj4 adj4; // instance of 4-adjacency
106  Adj8 adj8; // instance of 8-adjacency
107  DT8_4 dt8_4(adj8, adj4, JORDAN_DT );
108  DT8_4::ReverseTopology dt4_8(adj4, adj8, JORDAN_DT );
109 
110  //We construct a simple "house" set
111  DigitalSet houseSet( domain );
112 
113  for ( int k = -3; k < 3 ; k++)
114  {
115  houseSet.insert(Point(k, -3));
116  houseSet.insert(Point(-3, k));
117  houseSet.insert(Point(3, k));
118  houseSet.insert(Point(k, 3));
119  }
120 
121  //We compute the complement
122  DigitalSet houseSetCompl( domain);
123  houseSetCompl.assignFromComplement( houseSet );
124 
125  //We create the objects associated to the sets
126  ObjectType house8( dt8_4, houseSet );
127  ObjectType houseCompl8( dt8_4, houseSetCompl );
128  ObjectTypeReverseTopo house4(dt4_8, houseSet);
129  ObjectTypeReverseTopo houseCompl4( dt4_8, houseSetCompl );
130 
131 
132  //Board Export init
133  Board2D board;
135 
136  //Border=4 Filling=4
137  board.clear();
138  board << SetMode( domain.className(), "Grid" ) << domain;
139  board << SetMode( house4.className(), "DrawAdjacencies" ) << house4;
140  ObjectExpanderReverseTopo expander(houseCompl4, Point(0, 0));
141  while (!expander.finished())
142  {
143  for ( ObjectExpander::ConstIterator it = expander.begin();
144  it != expander.end();
145  ++it )
146  std::cout << " " << *it;
147 
148  expander.nextLayer();
149  }
150  board << CustomStyle(expander.core().className(), new MyStyleCustom) << expander.core();
151  board.saveSVG("house4-4.svg");
152 
153  //Border=4 Filling=8
154  board.clear();
155  board << SetMode( domain.className(), "Grid" ) << domain;
156  board << SetMode( house4.className(), "DrawAdjacencies" ) << house4;
157  ObjectExpander expander8(houseCompl8, Point(0, 0));
158  while (!expander8.finished())
159  {
160  for ( ObjectExpander::ConstIterator it = expander8.begin();
161  it != expander8.end();
162  ++it )
163  std::cout << " " << *it;
164 
165  expander8.nextLayer();
166  }
167  board << CustomStyle(expander8.core().className(), new MyStyleCustom) << expander8.core();
168  board.saveSVG("house4-8.svg");
169 
170  //Border=8 Filling=8
171  board.clear();
172  board << SetMode( domain.className(), "Grid" ) << domain;
173  board << SetMode( house8.className(), "DrawAdjacencies" ) << house8;
174  ObjectExpander expander88(houseCompl8, Point(0, 0));
175  while (!expander88.finished())
176  {
177  for ( ObjectExpander::ConstIterator it = expander88.begin();
178  it != expander88.end();
179  ++it )
180  std::cout << " " << *it;
181 
182  expander88.nextLayer();
183  }
184  board << CustomStyle(expander88.core().className(), new MyStyleCustom) << expander88.core();
185  board.saveSVG("house8-8.svg");
186 
187  //Border=8 Filling=4
188  board.clear();
189  board << SetMode( domain.className(), "Grid" ) << domain;
190  board << SetMode( house8.className(), "DrawAdjacencies" ) << house8;
191  ObjectExpanderReverseTopo expander84(houseCompl4, Point(0, 0));
192  while (!expander84.finished())
193  {
194  for ( ObjectExpander::ConstIterator it = expander84.begin();
195  it != expander84.end();
196  ++it )
197  std::cout << " " << *it;
198 
199  expander84.nextLayer();
200  }
201  board << CustomStyle(expander.core().className(), new MyStyleCustom) << expander84.core();
202  board.saveSVG("house8-4.svg");
203 
204 
205  nbok += true ? 1 : 0;
206  nb++;
207  trace.info() << "(" << nbok << "/" << nb << ") "
208  << "true == true" << std::endl;
209  trace.endBlock();
210 
211  return nbok == nb;
212 }
Aim: An object (or digital object) represents a set in some digital space associated with a digital t...
Definition: Object.h:119
void beginBlock(const std::string &keyword="")
HyperRectDomain< Space > Domain
const Domain domain(Point(1, 2), Point(6, 5))
MyDigitalSurface::ConstIterator ConstIterator
Trace trace
Definition: Common.h:137
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
Aim: Parallelepidec region of a digital space, model of a &#39;CDomain&#39;.
double endBlock()
Aim: Describes digital adjacencies in digital spaces that are defined with the 1-norm and the infinit...
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
Aim: This class is useful to visit an object by adjacencies, layer by layer.
Definition: Expander.h:97
Aim: Represents a digital topology as a couple of adjacency relations.
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
std::string className() const
MyPointD Point
Definition: testClone2.cpp:383
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
std::ostream & info()
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247
void setUnit(Unit unit)
Definition: Board.cpp:240
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70