DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testDepthFirstPropagation.cpp
1 
30 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/io/boards/Board2D.h"
34 #include "DGtal/io/Color.h"
35 #include "DGtal/io/colormaps/HueShadeColorMap.h"
36 #include "DGtal/shapes/Shapes.h"
37 #include "DGtal/io/Color.h"
38 #include "DGtal/io/colormaps/GradientColorMap.h"
39 #include "DGtal/topology/CUndirectedSimpleGraph.h"
40 #include "DGtal/topology/DepthFirstVisitor.h"
41 #include <set>
42 #include <iterator>
44 
45 
46 using namespace std;
47 using namespace DGtal;
48 
50 // Functions for testing objects as graph.
52 
54 void testDepthFirstPropagation()
55 {
56  typedef Z2i::Point Point;
57  typedef Z2i::Domain Domain;
59  typedef Z2i::Object4_8 Object;
60 
61  BOOST_CONCEPT_ASSERT(( CUndirectedSimpleGraph<Z2i::Object4_8> ));
62 
63  Point p1( -50, -50 );
64  Point p2( 50, 50 );
65  Domain domain( p1, p2 );
66  Point c1( -2, -1 );
67  Point c2( -14, 5 );
68  Point c3( -30, -15 );
69  Point c4( -10, -20 );
70  Point c5( 12, -1 );
71  DigitalSet shape_set( domain );
72 
73  Shapes<Domain>::addNorm2Ball( shape_set, c1, 9 );
74  Shapes<Domain>::addNorm1Ball( shape_set, c2, 9 );
75  Shapes<Domain>::addNorm1Ball( shape_set, c3, 10 );
76  Shapes<Domain>::addNorm2Ball( shape_set, c4, 12 );
77  Shapes<Domain>::addNorm1Ball( shape_set, c5, 4 );
78 
79  Object obj(Z2i::dt4_8, shape_set);
80 
81 
82  HueShadeColorMap<int,3> cmap_grad( 0, obj.size());
83  //cmap_grad.addColor( Color( 0, 0, 200 ) );
84  //cmap_grad.addColor( Color( 0, 0, 50 ) );
85 
86  Board2D board;
87  board << SetMode( domain.className(), "Paving" )
88  << domain
89  << SetMode( p1.className(), "Paving" );
90 
91  Image image = ImageFromSet<Image>::create(shape_set, 1);
92 
93 
95 
96  int cpt=0;
97 
98  while( !bfv.finished() )
99  {
100  image.setValue(bfv.current().first, ++cpt);
101  bfv.expand();
102  }
103 
104  string specificStyle = p1.className() + "/Paving";
105 
106  for ( DigitalSet::ConstIterator it = shape_set.begin();
107  it != shape_set.end();
108  ++it )
109  {
110  if( image(*it) == 0)
111  {
112  board << CustomStyle( specificStyle,
113  new CustomColors( Color::Black,
114  Color::Red ) )
115  << *it;
116  }
117  else
118  {
119  if( image(*it) > 0 )
120  {
121  board << CustomStyle( specificStyle,
122  new CustomColors( Color::Black,
123  cmap_grad( image(*it) ) ) )
124  << *it;
125  }
126  else
127  {
128  board << CustomStyle( specificStyle,
129  new CustomColors( Color::Black,
130  cmap_grad( 0 ) ) )
131  << *it;
132  }
133  }
134  }
135  board.saveEPS("testDepthFirstPropagation.eps");
136 
137  board.clear();
138 
139  DepthFirstVisitor<Object, set<Point> > bfv2 (obj, c1);
140 
141  cpt=0;
142 
143  while( !bfv2.finished() )
144  {
145  image.setValue(bfv2.current().first, bfv2.current().second);
146  bfv2.expand();
147  }
148 
149  specificStyle = p1.className() + "/Paving";
150 
151  for ( DigitalSet::ConstIterator it = shape_set.begin();
152  it != shape_set.end();
153  ++it )
154  {
155  if( image(*it) == 0)
156  {
157  board << CustomStyle( specificStyle,
158  new CustomColors( Color::Black,
159  Color::Red ) )
160  << *it;
161  }
162  else
163  {
164  if( image(*it) > 0 )
165  {
166  board << CustomStyle( specificStyle,
167  new CustomColors( Color::Black,
168  cmap_grad( image(*it) ) ) )
169  << *it;
170  }
171  else
172  {
173  board << CustomStyle( specificStyle,
174  new CustomColors( Color::Black,
175  cmap_grad( 0 ) ) )
176  << *it;
177  }
178  }
179  }
180  board.saveEPS("testDepthFirstPropagation-distance.eps");
181 }
182 
183 int main( int /*argc*/, char** /*argv*/ )
184 {
185  testDepthFirstPropagation();
186  return 0;
187 }
188 
189 
190 
191