DGtal  1.5.beta
testDepthFirstPropagation.cpp
Go to the documentation of this file.
1 
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/graph/CUndirectedSimpleGraph.h"
38 #include "DGtal/graph/DepthFirstVisitor.h"
39 #include "DGtal/graph/CGraphVisitor.h"
40 #include <set>
41 #include <iterator>
42 #include "DGtal/images/ImageContainerBySTLVector.h"
44 
45 
46 using namespace std;
47 using namespace DGtal;
48 using namespace DGtal::concepts;
49 
51 // Functions for testing objects as graph.
53 
56 {
57  typedef Z2i::Point Point;
58  typedef Z2i::Domain Domain;
60  typedef Z2i::Object4_8 Object;
61 
62  BOOST_CONCEPT_ASSERT(( CUndirectedSimpleGraph<Z2i::Object4_8> ));
63 
64  Point p1( -41, -36 );
65  Point p2( 18, 18 );
66  Domain domain( p1, p2 );
67  Point c1( -2, -1 );
68  Point c2( -14, 5 );
69  Point c3( -30, -15 );
70  Point c4( -10, -20 );
71  Point c5( 12, -1 );
72  DigitalSet shape_set( domain );
73 
74  Shapes<Domain>::addNorm2Ball( shape_set, c1, 9 );
75  Shapes<Domain>::addNorm1Ball( shape_set, c2, 9 );
76  Shapes<Domain>::addNorm1Ball( shape_set, c3, 10 );
77  Shapes<Domain>::addNorm2Ball( shape_set, c4, 12 );
78  Shapes<Domain>::addNorm1Ball( shape_set, c5, 4 );
79 
80  Object obj(Z2i::dt4_8, shape_set);
81 
82 
83  HueShadeColorMap<int,3> cmap_grad( 0, (int)obj.size());
84  //cmap_grad.addColor( Color( 0, 0, 200 ) );
85  //cmap_grad.addColor( Color( 0, 0, 50 ) );
86 
87  Board2D board;
88  board << SetMode( domain.className(), "Paving" )
89  << domain
90  << SetMode( p1.className(), "Paving" );
91 
92  Image image = ImageFromSet<Image>::create(shape_set, 1);
93 
95  BOOST_CONCEPT_ASSERT(( CGraphVisitor<Visitor> ));
96  Visitor bfv (obj, c1);
97 
98  int cpt=0;
99 
100  while( !bfv.finished() )
101  {
102  image.setValue(bfv.current().first, ++cpt);
103  bfv.expand();
104  }
105 
106  string specificStyle = p1.className() + "/Paving";
107 
108  for ( DigitalSet::ConstIterator it = shape_set.begin();
109  it != shape_set.end();
110  ++it )
111  {
112  if( image(*it) == 0)
113  {
114  board << CustomStyle( specificStyle,
115  new CustomColors( Color::Black,
116  Color::Red ) )
117  << *it;
118  }
119  else
120  {
121  if( image(*it) > 0 )
122  {
123  board << CustomStyle( specificStyle,
124  new CustomColors( Color::Black,
125  cmap_grad( image(*it) ) ) )
126  << *it;
127  }
128  else
129  {
130  board << CustomStyle( specificStyle,
131  new CustomColors( Color::Black,
132  cmap_grad( 0 ) ) )
133  << *it;
134  }
135  }
136  }
137  board.saveEPS("testDepthFirstPropagation.eps");
138 
139  board.clear();
140 
141  DepthFirstVisitor<Object, set<Point> > bfv2 (obj, c1);
142 
143 
144  while( !bfv2.finished() )
145  {
146  image.setValue(bfv2.current().first, bfv2.current().second);
147  bfv2.expand();
148  }
149 
150  specificStyle = p1.className() + "/Paving";
151 
152  for ( DigitalSet::ConstIterator it = shape_set.begin();
153  it != shape_set.end();
154  ++it )
155  {
156  if( image(*it) == 0)
157  {
158  board << CustomStyle( specificStyle,
159  new CustomColors( Color::Black,
160  Color::Red ) )
161  << *it;
162  }
163  else
164  {
165  if( image(*it) > 0 )
166  {
167  board << CustomStyle( specificStyle,
168  new CustomColors( Color::Black,
169  cmap_grad( image(*it) ) ) )
170  << *it;
171  }
172  else
173  {
174  board << CustomStyle( specificStyle,
175  new CustomColors( Color::Black,
176  cmap_grad( 0 ) ) )
177  << *it;
178  }
179  }
180  }
181  board.saveEPS("testDepthFirstPropagation-distance.eps");
182 }
183 
184 int main( int /*argc*/, char** /*argv*/ )
185 {
187  return 0;
188 }
189 
190 
191 
192 
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Aim: This class is useful to perform a breadth-first exploration of a graph given a starting point or...
const Node & current() const
Aim: This class is useful to perform a depth-first exploration of a graph given a starting point or s...
const Node & current() const
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Container::const_iterator ConstIterator
ConstIterator type of the container;.
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
std::string className() const
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
Aim: An object (or digital object) represents a set in some digital space associated with a digital t...
Definition: Object.h:120
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:151
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:804
BreadthFirstVisitor< MyDigitalSurface > Visitor
Aim: Gathers several functions useful for concept checks.
DGtal is the top-level namespace which contains all DGtal functions and types.
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:279
Aim: Define utilities to convert a digital set into an image.
Definition: ImageFromSet.h:64
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
Aim: Defines the concept of a visitor onto a graph, that is an object that traverses vertices of the ...
Aim: Represents the concept of local graph: each vertex has neighboring vertices, but we do not neces...
MyPointD Point
Definition: testClone2.cpp:383
ImageContainerBySTLVector< Z2i::Domain, int > Image
int main(int, char **)
void testDepthFirstPropagation()
Domain domain
Image image(domain)
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet