DGtal 1.4.0
|
Aim: This class is useful to perform an exploration of a graph given a starting point or set (called initial core) and a distance criterion. More...
#include <DGtal/graph/DistanceBreadthFirstVisitor.h>
Data Structures | |
struct | Node |
Public Types | |
typedef DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet > | Self |
typedef TGraph | Graph |
typedef TVertexFunctor | VertexFunctor |
typedef TMarkSet | MarkSet |
typedef Graph::Size | Size |
typedef Graph::Vertex | Vertex |
typedef VertexFunctor::Value | Scalar |
typedef Scalar | Data |
typedef std::priority_queue< Node > | NodeQueue |
Internal data structure for computing the distance ordering expansion. | |
typedef std::vector< Vertex > | VertexList |
Internal data structure for storing vertices. | |
Public Member Functions | |
~DistanceBreadthFirstVisitor () | |
DistanceBreadthFirstVisitor (const DistanceBreadthFirstVisitor &other) | |
DistanceBreadthFirstVisitor (ConstAlias< Graph > graph, const VertexFunctor &distance, const Vertex &p) | |
template<typename VertexIterator > | |
DistanceBreadthFirstVisitor (const Graph &graph, const VertexFunctor &distance, VertexIterator b, VertexIterator e) | |
const Graph & | graph () const |
const Node & | current () const |
template<typename TBackInsertionSequence > | |
void | getCurrentLayer (TBackInsertionSequence &layer) |
void | ignore () |
void | ignoreLayer () |
void | expand () |
void | expandLayer () |
template<typename VertexPredicate > | |
void | expand (const VertexPredicate &authorized_vtx) |
template<typename VertexPredicate > | |
void | expandLayer (const VertexPredicate &authorized_vtx) |
bool | finished () const |
void | terminate () |
const MarkSet & | markedVertices () const |
MarkSet | visitedVertices () const |
void | pushAgain (const Node &node) |
void | swap (DistanceBreadthFirstVisitor &other) |
void | selfDisplay (std::ostream &out) const |
bool | isValid () const |
Protected Member Functions | |
DistanceBreadthFirstVisitor () | |
Private Member Functions | |
DistanceBreadthFirstVisitor & | operator= (const DistanceBreadthFirstVisitor &other) |
Private Attributes | |
const Graph * | myGraph |
VertexFunctor | myDistance |
MarkSet | myMarkedVertices |
NodeQueue | myQueue |
Aim: This class is useful to perform an exploration of a graph given a starting point or set (called initial core) and a distance criterion.
Description of template class 'DistanceBreadthFirstVisitor'
The visitor implements a modified breadth-first algorithm on the graph of adjacencies that is based on a priority queue, the priority of which is given by the distance object (and not by the topological distance as in classical breadth-first traversal). It can be used not only to detect connected component but also to identify the layers of the object located at a given distance of a starting set.
The core of the visitor is by definition at the beginning the set of points at the lowest distances. A layer is a set of vertices at the same distance. The visitor can visit one vertex at a time or one layer at a time. Each layer is at a different distance from the initial core, layers having increasing distances.
The object guarantees that vertices are visited in a non-decreasing ordering with respect to the distance object, as long as the breadth-first traversal order can be consistent with the given distance ordering.
TGraph | the type of the graph, a model of CUndirectedSimpleLocalGraph. It must have an inner type Vertex. |
TVertexFunctor | the type of distance object: any mapping from a Vertex toward a scalar value. Requires an inner type Value which is the returned scalar value and an operator()( Vertex ) returning a Value. The neighboring relations of the graph should be consistent with the distance function, in the sense that the closest points to the current set of already visited vertices should be found in the neighbors. |
TMarkSet | the type that is used to store marked vertices. Should be a set of Vertex, hence a model of CSet. |
You may also visit vertices layer by layer, meaning that you wish to consider all the vertices at the same distance at the same time. You should use then DistanceBreadthFirstVisitor::getCurrentLayer, DistanceBreadthFirstVisitor::expandLayer, and DistanceBreadthFirstVisitor::ignoreLayer.
If the bread-first queueing system is not compatible with the distance function, then it has two consequences:
this affects more the layer-by-layer mechanism, which may miss vertices in the traversal. In order to visit all the vertices layer by layer, you should use the visitor as follows:
Definition at line 205 of file DistanceBreadthFirstVisitor.h.
typedef Scalar DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::Data |
Definition at line 216 of file DistanceBreadthFirstVisitor.h.
typedef TGraph DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::Graph |
Definition at line 210 of file DistanceBreadthFirstVisitor.h.
typedef TMarkSet DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::MarkSet |
Definition at line 212 of file DistanceBreadthFirstVisitor.h.
typedef std::priority_queue< Node > DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::NodeQueue |
Internal data structure for computing the distance ordering expansion.
Definition at line 258 of file DistanceBreadthFirstVisitor.h.
typedef VertexFunctor::Value DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::Scalar |
Definition at line 215 of file DistanceBreadthFirstVisitor.h.
typedef DistanceBreadthFirstVisitor<TGraph,TVertexFunctor,TMarkSet> DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::Self |
Definition at line 209 of file DistanceBreadthFirstVisitor.h.
typedef Graph::Size DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::Size |
Definition at line 213 of file DistanceBreadthFirstVisitor.h.
typedef Graph::Vertex DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::Vertex |
Definition at line 214 of file DistanceBreadthFirstVisitor.h.
typedef TVertexFunctor DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::VertexFunctor |
Definition at line 211 of file DistanceBreadthFirstVisitor.h.
typedef std::vector< Vertex > DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::VertexList |
Internal data structure for storing vertices.
Definition at line 260 of file DistanceBreadthFirstVisitor.h.
DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::~DistanceBreadthFirstVisitor | ( | ) |
Destructor.
DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::DistanceBreadthFirstVisitor | ( | const DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet > & | other | ) |
Copy constructor.
other | the object to clone. |
DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::DistanceBreadthFirstVisitor | ( | ConstAlias< Graph > | graph, |
const VertexFunctor & | distance, | ||
const Vertex & | p ) |
Constructor from a point and a vertex functor object. This point provides the initial core of the visitor.
graph | the graph in which the distance ordering traversal takes place (aliased). |
distance | the distance object, a functor Vertex -> Scalar (cloned). |
p | any vertex of the graph. |
DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::DistanceBreadthFirstVisitor | ( | const Graph & | graph, |
const VertexFunctor & | distance, | ||
VertexIterator | b, | ||
VertexIterator | e ) |
Constructor from a graph, a vertex functor and two iterators specifying a range. All vertices visited between the iterators should be distinct two by two. The so specified set of vertices provides the initial core of the distance ordering traversal.
VertexIterator | any type of single pass iterator on vertices. |
graph | the graph in which the distance ordering traversal takes place (aliased). |
distance | the distance object, a functor Vertex -> Scalar (cloned). |
b | the begin iterator in a container of vertices. |
e | the end iterator in a container of vertices. |
|
protected |
Constructor. Forbidden by default (protected to avoid g++ warnings).
const Node & DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::current | ( | ) | const |
NB: valid only if not 'finished()'.
void DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::expand | ( | ) |
Goes to the next vertex and take into account the current vertex for determining the future vsited vertices. NB: valid only if not 'finished()'.
void DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::expand | ( | const VertexPredicate & | authorized_vtx | ) |
Goes to the next vertex and take into account the current vertex for determining the future visited vertices.
VertexPredicate | a type that satisfies CPredicate on Vertex. |
authorized_vtx | the predicate that should satisfy the visited vertices. |
NB: valid only if not 'finished()'.
void DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::expandLayer | ( | ) |
Goes to the next layer and take into account the current layer for determining the future vsited vertices. NB: valid only if not 'finished()'.
void DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::expandLayer | ( | const VertexPredicate & | authorized_vtx | ) |
Goes to the next layer and take into account the current layer for determining the future vsited vertices.
VertexPredicate | a type that satisfies CPredicate on Vertex. |
authorized_vtx | the predicate that should satisfy the visited vertices. |
NB: valid only if not 'finished()'.
bool DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::finished | ( | ) | const |
void DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::getCurrentLayer | ( | TBackInsertionSequence & | layer | ) |
Returns all nodes at same current distance in the given container layer. The node is a pair <Vertex,Scalar> where the second term is the distance to the initial vertex or set.
TBackInsertionSequence | a container of Node that is any model of boost::BackInsertionSequence. |
[out] | layer | a container object that will contain all the nodes at the same current distance. |
NB: Complexity is in O(k log n ), where k is the size of the layer and n the number of elements currently in the priority queue (some O(k)).
const Graph & DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::graph | ( | ) | const |
void DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::ignore | ( | ) |
Goes to the next vertex but ignores the current vertex for determining the future visited vertices. Otherwise said, no future visited vertex will have this vertex as a father.
NB: valid only if not 'finished()'.
void DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::ignoreLayer | ( | ) |
Goes to the next layer but ignores the current layer for determining the future visited vertices. Otherwise said, no future visited vertex will have any vertex of this layer as a father.
NB: valid only if not 'finished()'.
bool DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::isValid | ( | ) | const |
Checks the validity/consistency of the object.
const MarkSet & DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::markedVertices | ( | ) | const |
|
private |
Assignment.
other | the object to copy. |
void DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::pushAgain | ( | const Node & | node | ) |
Push backs some node in the queue. The node should have been ignored previously at some point. Useful when the distance is not truely a distance function.
node | a pair Vertex, distance. |
void DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::selfDisplay | ( | std::ostream & | out | ) | const |
Writes/Displays the object on an output stream.
out | the output stream where the object is written. |
void DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::swap | ( | DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet > & | other | ) |
Exchange 'this' object with 'other'. O(1) operations since containers are swapped (if the VertexFunctor is assignable in O(1)).
other | the other instance. |
void DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::terminate | ( | ) |
Force termination of the distance ordering traversal. 'finished()' returns 'true' afterwards and 'current()', 'expand()', 'ignore()' have no more meaning. Furthermore, 'markedVertices()' and 'visitedVertices()' both represents the set of visited vertices.
MarkSet DGtal::DistanceBreadthFirstVisitor< TGraph, TVertexFunctor, TMarkSet >::visitedVertices | ( | ) | const |
NB: computational cost is a copy of the set of marked vertices then as many deletion as the number of marked vertices yet to be visited.
|
private |
The distance object, a functor Vertex -> Scalar.
Definition at line 483 of file DistanceBreadthFirstVisitor.h.
|
private |
The graph where the traversal takes place.
Definition at line 478 of file DistanceBreadthFirstVisitor.h.
|
private |
Set representing the marked vertices: the ones that have been visited and the ones that are going to be visited soon (at closest distance).
Definition at line 490 of file DistanceBreadthFirstVisitor.h.
|
private |
Queue storing the vertices that are the next visited ones in the distance ordering traversal of the graph.
Definition at line 496 of file DistanceBreadthFirstVisitor.h.