59{
61 using namespace Z2i;
62 Point p1( -41, -36 ), p2( 18, 18 );
75
78 cmap_grad.addColor(
Color( 0, 0, 255 ) );
79 cmap_grad.addColor(
Color( 0, 255, 255 ) );
80 cmap_grad.addColor(
Color( 0, 255, 0 ) );
81 cmap_grad.addColor(
Color( 255, 255, 0 ) );
82 cmap_grad.addColor(
Color( 255, 0, 0 ) );
83 cmap_grad.addColor(
Color( 255, 0, 255 ) );
84
88 string specificStyle = p1.className() + "/Paving";
89
91 int n = 0;
92 for ( Graph::ConstIterator it = g.begin(), itEnd = g.end();
93 it != itEnd; ++it, ++n )
94 {
98 cmap_hue( n ) ) )
99 << vtx;
100 }
101 board.
saveEPS(
"graphTraversal-enum.eps");
103
104 {
106 int nn = 0;
107 int mm = 0;
108 std::vector<Vertex> neighbors;
109 for ( Graph::ConstIterator it = g.begin(), itEnd = g.end();
110 it != itEnd; ++it, ++nn )
111 {
113 std::back_insert_iterator< std::vector<Vertex> > neighIt
114 = std::back_inserter( neighbors );
115 g.writeNeighbors( neighIt, vtx );
116 mm += neighbors.size();
117 neighbors.clear();
118 }
119 trace.
info() <<
"Graph has " << nn <<
" vertices and "
120 << (mm/2) << " edges." << std::endl;
122 }
123
129 typedef BFSVisitor::Node Node;
130 BFSVisitor bfv( g,
Point( -2, -1 ) );
131 while( ! bfv.finished() )
132 {
133 Node node = bfv.current();
136 cmap_grad( node.second ) ) )
137 << node.first;
138 bfv.expand();
139 }
140 board.
saveEPS(
"graphTraversal-bfs.eps");
142
149 VisitorRange range(
new DFSVisitor( g,
Point( -2, -1 ) ) );
150 n = 0;
151 for ( VisitorRange::ConstIterator it = range.begin(), itEnd = range.end();
152 it != itEnd; ++it, ++n )
153 {
157 cmap_hue( n ) ) )
158 << vtx;
159 }
160 board.
saveEPS(
"graphTraversal-dfs-range.eps");
162
163 return 0;
164}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Aim: This class is useful to perform a breadth-first exploration of a graph given a starting point or...
Structure representing an RGB triple with alpha component.
Aim: This class is useful to perform a depth-first exploration of a graph given a starting point or s...
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: Transforms a graph visitor into a single pass input range.
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
std::string className() const
static void addNorm1Ball(TDigitalSet &aSet, const Point &aCenter, UnsignedInteger aRadius)
static void addNorm2Ball(TDigitalSet &aSet, const Point &aCenter, UnsignedInteger aRadius)
void clear(const DGtal::Color &color=DGtal::Color::None)
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Object< DT4_8, DigitalSet > Object4_8
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Aim: Represents the concept of local graph: each vertex has neighboring vertices, but we do not neces...