-
Notifications
You must be signed in to change notification settings - Fork 0
/
AJGraph.h
161 lines (114 loc) · 4.56 KB
/
AJGraph.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#ifndef AJGRAPH_H
#define AJGRAPH_H
#include <itkDataObject.h>
#include <itkMacro.h>
#include <itkObjectFactory.h>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include "FeatureDescriptor.h"
#include <itkArray.h>
template<class TAJVertex,class TAJEdge> class AJGraph : public itk::DataObject {
public:
struct AJVertexPropertyTag {
typedef boost::vertex_property_tag kind;
};
struct AJEdgePropertyTag {
typedef boost::edge_property_tag kind;
};
typedef boost::property<AJVertexPropertyTag, typename TAJVertex::Pointer,
boost::property<boost::vertex_index_t, int> > VertexProperty;
typedef boost::property<AJEdgePropertyTag,typename TAJEdge::Pointer,
boost::property<boost::edge_index_t,int,
boost::property<boost::edge_weight_t,double>
> > EdgeProperty;
public:
typedef boost::adjacency_list<boost::vecS,boost::vecS,boost::undirectedS,VertexProperty,EdgeProperty,boost::no_property> BoostGraphType;
private:
BoostGraphType m_Graph;
public:
typedef AJGraph<TAJVertex,TAJEdge> Self;
typedef itk::DataObject Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef TAJVertex AJVertexType;
typedef TAJEdge AJEdgeType;
typedef typename boost::graph_traits<BoostGraphType>::vertex_descriptor AJVertexHandler;
typedef typename boost::graph_traits<BoostGraphType>::edge_descriptor AJEdgeHandler;
typedef typename boost::graph_traits<BoostGraphType>::vertex_iterator VertexIterator;
typedef typename boost::graph_traits<BoostGraphType>::edge_iterator EdgeIterator;
typedef typename boost::graph_traits<BoostGraphType>::adjacency_iterator AdjacencyIterator;
typedef typename boost::graph_traits<BoostGraphType>::out_edge_iterator OutEdgesIterator;
public:
itkNewMacro(Self)
BoostGraphType & GetBoostGraph(){
return m_Graph;
}
virtual AJVertexHandler GetAJEdgeSource(const AJEdgeHandler & source){
return boost::source(source,m_Graph);
}
virtual AJEdgeHandler GetAJEdgeHandler(const AJVertexHandler & source,const AJVertexHandler & target){
return boost::edge(source,target,m_Graph).first;
}
virtual AJVertexHandler GetAJEdgeTarget(const AJEdgeHandler & target){
return boost::target(target,m_Graph);
}
virtual typename AJVertexType::Pointer GetAJVertex(const AJVertexHandler & vertex){
return boost::get(AJVertexPropertyTag(),m_Graph,vertex);
}
virtual int AJVertexDegree(const AJVertexHandler & vertex){
return boost::degree(vertex,m_Graph);
}
virtual AdjacencyIterator AdjacentAJVerticesBegin(const AJVertexHandler & vertex){
return boost::adjacent_vertices(vertex,m_Graph).first;
}
virtual AdjacencyIterator AdjacentAJVerticesEnd(const AJVertexHandler & vertex){
return boost::adjacent_vertices(vertex,m_Graph).second;
}
virtual AJVertexHandler AddAJVertex(const typename AJVertexType::Pointer & vertex){
AJVertexHandler result=boost::add_vertex(m_Graph);
boost::get(AJVertexPropertyTag(),m_Graph,result)=vertex;
return result;
}
virtual void DeleteAJVertex(const AJVertexHandler & vertex){
boost::clear_vertex(vertex,m_Graph);
boost::remove_vertex(vertex,m_Graph);
}
virtual void DeleteAJEdge(const AJEdgeHandler & edge){
boost::remove_edge(edge,m_Graph);
}
virtual AJEdgeHandler AddAJEdge(const AJVertexHandler & a, const AJVertexHandler & b){
AJEdgeHandler result= boost::add_edge(a,b,m_Graph).first;
boost::get(AJEdgePropertyTag(),m_Graph,result)=AJEdgeType::New();
return result;
}
virtual typename AJEdgeType::Pointer GetAJEdge(const AJEdgeHandler & edge){
return boost::get(AJEdgePropertyTag(),m_Graph,edge);
}
unsigned long GetNumVertices(){
return boost::num_vertices(m_Graph);
}
unsigned long GetNumEdges(){
return boost::num_edges(m_Graph);
}
EdgeIterator EdgesBegin(){
return boost::edges(m_Graph).first;
}
EdgeIterator EdgesEnd(){
return boost::edges(m_Graph).second;
}
VertexIterator VerticesBegin(){
return boost::vertices(m_Graph).first;
}
VertexIterator VerticesEnd(){
return boost::vertices(m_Graph).second;
}
OutEdgesIterator BeginOutEdges( const AJVertexHandler & vertex){
return boost::out_edges(vertex,m_Graph).first;
}
OutEdgesIterator EndOutEdges( const AJVertexHandler & vertex){
return boost::out_edges(vertex,m_Graph).second;
}
protected:
AJGraph(){
}
};
#endif // AJGRAPH_H