DGtal
0.6.devel
Main Page
Related Pages
Modules
Namespaces
Data Structures
Examples
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
src
DGtal
topology
DepthFirstVisitor.h
1
17
#pragma once
18
33
#if defined(DepthFirstVisitor_RECURSES)
34
#error Recursive header files inclusion detected in DepthFirstVisitor.h
35
#else // defined(DepthFirstVisitor_RECURSES)
36
37
#define DepthFirstVisitor_RECURSES
38
39
#if !defined DepthFirstVisitor_h
40
41
#define DepthFirstVisitor_h
42
44
// Inclusions
45
#include <iostream>
46
#include <stack>
47
#include "DGtal/base/Common.h"
48
#include "DGtal/base/CountedPtr.h"
49
#include "DGtal/kernel/sets/DigitalSetSelector.h"
50
#include "DGtal/kernel/sets/DigitalSetDomain.h"
51
#include "DGtal/topology/DomainAdjacency.h"
52
#include "DGtal/topology/CUndirectedSimpleLocalGraph.h"
54
55
namespace
DGtal
56
{
57
59
// template class DepthFirstVisitor
92
template
<
typename
TGraph,
93
typename
TMarkSet =
typename
TGraph::VertexSet >
94
class
DepthFirstVisitor
95
{
96
// ----------------------- Associated types ------------------------------
97
public
:
98
typedef
DepthFirstVisitor<TGraph,TMarkSet>
Self
;
99
typedef
TGraph
Graph
;
100
typedef
TMarkSet
MarkSet
;
101
typedef
typename
Graph::Size
Size
;
102
typedef
typename
Graph::Vertex
Vertex
;
103
104
//BOOST_CONCEPT_ASSERT(( CUndirectedSimpleLocalGraph< Graph > ));
105
// Cannot check this since some types using it are incomplete.
106
//BOOST_CONCEPT_ASSERT(( CSet< MarkSet, Vertex > ));
107
108
// ----------------------- defined types ------------------------------
109
public
:
110
113
typedef
std::pair< Vertex, Size >
Node
;
115
typedef
std::stack< Node >
NodeQueue
;
117
typedef
std::vector< Vertex >
VertexList
;
118
123
struct
NodeAccessor
{
124
typedef
const
Node
value
;
125
typedef
const
Node
value_type
;
126
typedef
const
Node
*
pointer
;
127
typedef
const
Node
&
reference
;
128
inline
129
static
reference
get
(
const
Node
& node )
130
{
return
node; }
131
};
132
137
struct
VertexAccessor
{
138
typedef
const
Vertex
value
;
139
typedef
const
Vertex
value_type
;
140
typedef
const
Vertex
*
pointer
;
141
typedef
const
Vertex
&
reference
;
142
inline
143
static
reference
get
(
const
Node
& node )
144
{
return
node.first; }
145
};
146
147
template
<
typename
TAccessor>
148
struct
ConstIterator
149
{
150
typedef
ConstIterator<TAccessor>
Self
;
151
typedef
DepthFirstVisitor<TGraph,TMarkSet>
Visitor
;
152
typedef
TAccessor
Accessor
;
153
154
// stl iterator types.
155
typedef
std::input_iterator_tag
iterator_category
;
156
typedef
typename
Accessor::value
value_type
;
157
typedef
std::ptrdiff_t
difference_type
;
158
typedef
typename
Accessor::pointer
pointer
;
159
typedef
typename
Accessor::reference
reference
;
160
162
CountedPtr< Visitor >
myVisitor
;
163
164
inline
165
ConstIterator
()
166
:
myVisitor
( 0 ) {}
167
inline
168
ConstIterator
(
Visitor
* ptrV )
169
:
myVisitor
( ptrV ) {}
170
inline
171
ConstIterator
(
const
Self
& other )
172
:
myVisitor
( other.
myVisitor
) {}
173
174
inline
175
Self
&
operator=
(
const
Self
& other )
176
{
177
if
(
this
!= &other )
178
myVisitor
= other.
myVisitor
;
179
return
*
this
;
180
}
181
182
inline
183
reference
184
operator*
()
const
185
{
186
ASSERT( (
myVisitor
.
get
() != 0 )
187
&&
"DGtal::DepthFirstVisitor<TGraph,TMarkSet>::ConstIterator::operator*(): you cannot dereferenced a null visitor (i.e. end())."
);
188
return
Accessor::get(
myVisitor
->
current
() );
189
}
190
191
inline
192
pointer
193
operator->
()
const
194
{
195
ASSERT( (
myVisitor
.
get
() != 0 )
196
&&
"DGtal::DepthFirstVisitor<TGraph,TMarkSet>::ConstIterator::operator->(): you cannot dereferenced a null visitor (i.e. end())."
);
197
return
& Accessor::get(
operator
*() );
198
}
199
200
inline
201
Self
&
202
operator++
()
203
{
204
myVisitor
->
expand
();
205
return
*
this
;
206
}
207
208
inline
209
Self
210
operator++
(
int
)
211
{
212
Self
__tmp = *
this
;
213
myVisitor
->
expand
();
214
return
__tmp;
215
}
216
217
inline
218
bool
operator==
(
const
Self
& other )
const
219
{
220
if
( (
myVisitor
.
get
() == 0 ) ||
myVisitor
->
finished
() )
221
return
( other.
myVisitor
.
get
() == 0 ) || other.
myVisitor
->
finished
();
222
else
if
( other.
myVisitor
.
get
() == 0 )
223
return
false
;
224
else
225
return
&(
myVisitor
->
current
()) == &(other.
myVisitor
->
current
());
226
}
227
228
inline
229
bool
operator!=
(
const
Self
& other )
const
230
{
231
return
! ( this->
operator==
( other ) );
232
}
233
};
234
237
typedef
ConstIterator<VertexAccessor>
VertexConstIterator
;
240
typedef
ConstIterator<NodeAccessor>
NodeConstIterator
;
241
242
// ----------------------- Standard services ------------------------------
243
public
:
244
248
~DepthFirstVisitor
();
249
256
DepthFirstVisitor
(
const
Graph
&
graph
);
257
265
DepthFirstVisitor
(
const
Graph
&
graph
,
const
Vertex
& p );
266
279
template
<
typename
VertexIterator>
280
DepthFirstVisitor
(
const
Graph
&
graph
,
281
VertexIterator b, VertexIterator e );
282
283
287
const
Graph
&
graph
()
const
;
288
289
// ----------------------- traversal services ------------------------------
290
public
:
291
299
const
Node
&
current
()
const
;
300
308
void
ignore
();
309
315
void
expand
();
316
328
template
<
typename
VertexPredicate>
329
void
expand
(
const
VertexPredicate & authorized_vtx );
330
334
bool
finished
()
const
;
335
343
void
terminate
();
344
350
const
MarkSet
&
markedVertices
()
const
;
351
364
MarkSet
visitedVertices
()
const
;
365
366
367
// ----------------------- Interface --------------------------------------
368
public
:
369
374
void
selfDisplay
( std::ostream & out )
const
;
375
380
bool
isValid
()
const
;
381
382
// ------------------------- Protected Datas ------------------------------
383
private
:
384
// ------------------------- Private Datas --------------------------------
385
private
:
386
390
const
Graph
&
myGraph
;
391
397
MarkSet
myMarkedVertices
;
398
403
NodeQueue
myQueue
;
404
405
// ------------------------- Hidden services ------------------------------
406
protected
:
407
412
DepthFirstVisitor
();
413
414
private
:
415
421
DepthFirstVisitor
(
const
DepthFirstVisitor
& other );
422
429
DepthFirstVisitor
&
operator=
(
const
DepthFirstVisitor
& other );
430
431
// ------------------------- Internals ------------------------------------
432
private
:
433
434
};
// end of class DepthFirstVisitor
435
436
443
template
<
typename
TGraph,
typename
TMarkSet >
444
std::ostream&
445
operator<<
( std::ostream & out,
446
const
DepthFirstVisitor<TGraph, TMarkSet >
&
object
);
447
448
}
// namespace DGtal
449
450
452
// Includes inline functions.
453
#include "DGtal/topology/DepthFirstVisitor.ih"
454
455
// //
457
458
#endif // !defined DepthFirstVisitor_h
459
460
#undef DepthFirstVisitor_RECURSES
461
#endif // else defined(DepthFirstVisitor_RECURSES)
Generated on Wed Dec 19 2012 19:10:21 for DGtal by
1.8.1.1