DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testBreadthFirstPropagation.cpp
1 
29 
30 #include <iostream>
31 #include "DGtal/base/Common.h"
32 #include "DGtal/io/boards/Board2D.h"
33 #include "DGtal/io/Color.h"
34 #include "DGtal/io/colormaps/GradientColorMap.h"
35 #include "DGtal/shapes/Shapes.h"
36 #include "DGtal/io/Color.h"
37 #include "DGtal/io/colormaps/GradientColorMap.h"
38 #include "DGtal/topology/CUndirectedSimpleGraph.h"
39 #include "DGtal/topology/BreadthFirstVisitor.h"
40 #include <set>
41 #include <iterator>
43 
44 
45 using namespace std;
46 using namespace DGtal;
47 
49 // Functions for testing objects as graph.
51 
53 void testBreadthFirstPropagation()
54 {
55  typedef Z2i::Point Point;
56  typedef Z2i::Domain Domain;
58  typedef Z2i::Object4_8 Object;
59 
60  BOOST_CONCEPT_ASSERT(( CUndirectedSimpleGraph<Z2i::Object4_8> ));
61 
62  Point p1( -50, -50 );
63  Point p2( 50, 50 );
64  Domain domain( p1, p2 );
65  Point c1( -2, -1 );
66  Point c2( -14, 5 );
67  Point c3( -30, -15 );
68  Point c4( -10, -20 );
69  Point c5( 12, -1 );
70  DigitalSet shape_set( domain );
71 
72  Shapes<Domain>::addNorm2Ball( shape_set, c1, 9 );
73  Shapes<Domain>::addNorm1Ball( shape_set, c2, 9 );
74  Shapes<Domain>::addNorm1Ball( shape_set, c3, 10 );
75  Shapes<Domain>::addNorm2Ball( shape_set, c4, 12 );
76  Shapes<Domain>::addNorm1Ball( shape_set, c5, 4 );
77 
78  Object obj(Z2i::dt4_8, shape_set);
79 
80 
81  GradientColorMap<int> cmap_grad( 0, 52);
82  cmap_grad.addColor( Color( 0, 0, 200 ) );
83  cmap_grad.addColor( Color( 0, 0, 50 ) );
84 
85  Board2D board;
86  board << SetMode( domain.className(), "Paving" )
87  << domain
88  << SetMode( p1.className(), "Paving" );
89 
90  Image image = ImageFromSet<Image>::create(shape_set, 1);
91 
92 
94 
95 
96  while( !bfv.finished() )
97  {
98  image.setValue(bfv.current().first, bfv.current().second);
99  bfv.expand();
100  }
101 
102  string specificStyle = p1.className() + "/Paving";
103 
104  for ( DigitalSet::ConstIterator it = shape_set.begin();
105  it != shape_set.end();
106  ++it )
107  {
108  if( image(*it) == 0)
109  {
110  board << CustomStyle( specificStyle,
111  new CustomColors( Color::Black,
112  Color::Red ) )
113  << *it;
114  }
115  else
116  {
117  if( image(*it) > 0 )
118  {
119  board << CustomStyle( specificStyle,
120  new CustomColors( Color::Black,
121  cmap_grad( image(*it) ) ) )
122  << *it;
123  }
124  else
125  {
126  board << CustomStyle( specificStyle,
127  new CustomColors( Color::Black,
128  cmap_grad( 0 ) ) )
129  << *it;
130  }
131  }
132  }
133 
134  board.saveEPS("testBreadthFirstPropagation.eps");
135 }
136 
137 int main( int /*argc*/, char** /*argv*/ )
138 {
139  testBreadthFirstPropagation();
140  return 0;
141 }
142 
143 
144 
145