DGtal  1.0.0
testDepthFirstPropagation.cpp
Go to the documentation of this file.
1 
30 #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/graph/CUndirectedSimpleGraph.h"
38 #include "DGtal/graph/DepthFirstVisitor.h"
39 #include "DGtal/graph/CGraphVisitor.h"
40 #include <set>
41 #include <iterator>
43 
44 
45 using namespace std;
46 using namespace DGtal;
47 using namespace DGtal::concepts;
48 
50 // Functions for testing objects as graph.
52 
55 {
56  typedef Z2i::Point Point;
57  typedef Z2i::Domain Domain;
58  typedef Z2i::DigitalSet DigitalSet;
59  typedef Z2i::Object4_8 Object;
60 
61  BOOST_CONCEPT_ASSERT(( CUndirectedSimpleGraph<Z2i::Object4_8> ));
62 
63  Point p1( -41, -36 );
64  Point p2( 18, 18 );
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 
94  BOOST_CONCEPT_ASSERT(( CGraphVisitor<Visitor> ));
95  Visitor bfv (obj, c1);
96 
97  int cpt=0;
98 
99  while( !bfv.finished() )
100  {
101  image.setValue(bfv.current().first, ++cpt);
102  bfv.expand();
103  }
104 
105  string specificStyle = p1.className() + "/Paving";
106 
107  for ( DigitalSet::ConstIterator it = shape_set.begin();
108  it != shape_set.end();
109  ++it )
110  {
111  if( image(*it) == 0)
112  {
113  board << CustomStyle( specificStyle,
114  new CustomColors( Color::Black,
115  Color::Red ) )
116  << *it;
117  }
118  else
119  {
120  if( image(*it) > 0 )
121  {
122  board << CustomStyle( specificStyle,
123  new CustomColors( Color::Black,
124  cmap_grad( image(*it) ) ) )
125  << *it;
126  }
127  else
128  {
129  board << CustomStyle( specificStyle,
130  new CustomColors( Color::Black,
131  cmap_grad( 0 ) ) )
132  << *it;
133  }
134  }
135  }
136  board.saveEPS("testDepthFirstPropagation.eps");
137 
138  board.clear();
139 
140  DepthFirstVisitor<Object, set<Point> > bfv2 (obj, c1);
141 
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 {
186  return 0;
187 }
188 
189 
190 
191 
Aim: An object (or digital object) represents a set in some digital space associated with a digital t...
Definition: Object.h:119
HyperRectDomain< Space > Domain
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
MyDigitalSurface::ConstIterator ConstIterator
Aim: Define utilities to convert a digital set into an image.
Definition: ImageFromSet.h:63
Aim: This class is useful to perform a depth-first exploration of a graph given a starting point or s...
const Node & current() const
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
BreadthFirstVisitor< MyDigitalSurface > Visitor
Aim: Gathers several functions useful for concept checks.
Domain domain
void testDepthFirstPropagation()
std::string className() const
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Represents the concept of local graph: each vertex has neighboring vertices, but we do not neces...
Aim: This class is useful to perform a breadth-first exploration of a graph given a starting point or...
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
int main(int, char **)
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
const Node & current() const
Image image(domain)
ImageSelector< Z2i::Domain, int >::Type Image
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:70
Aim: Defines the concept of a visitor onto a graph, that is an object that traverses vertices of the ...