ifndef MESHGRAPH_HPP define MESHGRAPH_HPP include cassert include util

  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
#ifndef MESHGRAPH_HPP
#define MESHGRAPH_HPP
#include <cassert>
#include <utility>
#include <vector>
#include <boost/graph/graph_traits.hpp>
//Froward declarations begin
template <typename Property>
class MeshGraph;
template <typename Property>
std::pair<
typename boost::graph_traits<MeshGraph<Property> >::adjacency_iterator,
typename boost::graph_traits<MeshGraph<Property> >::adjacency_iterator >
adjacent_vertices(typename boost::graph_traits<MeshGraph<Property> >::vertex_descriptor v,
const MeshGraph<Property>& g);
//Froward declarations end
template <typename Property>
class MeshGraph {
public:
enum PartColor {Black=0, White=1, NullVertex=2};
MeshGraph();
private:
typedef std::vector<size_t> OutEdgeList;
typedef std::vector<OutEdgeList> PartRepresenation;
typedef std::vector<Property> PropertyContainer;
typedef std::pair<size_t, PartColor> vertex_descriptor;
//from black to white
typedef std::pair<size_t, size_t> edge_descriptor;
typedef OutEdgeList::const_iterator adjacency_iterator;
vertex_descriptor
addVertex(PartColor part);
std::pair<edge_descriptor, bool>
addEdge(vertex_descriptor u, vertex_descriptor v);
std::pair<adjacency_iterator,adjacency_iterator>
adjacentVertices(vertex_descriptor v) const;
PartRepresenation rep_[2];
PropertyContainer prop_[2];
friend struct boost::graph_traits<MeshGraph<Property> >;
friend
std::pair<
typename boost::graph_traits<MeshGraph<Property> >::adjacency_iterator,
typename boost::graph_traits<MeshGraph<Property> >::adjacency_iterator >
::adjacent_vertices<> (
typename boost::graph_traits<MeshGraph<Property> >::vertex_descriptor v,
const MeshGraph<Property>& g);
};
template <typename Property>
std::pair<typename MeshGraph<Property>::adjacency_iterator, typename MeshGraph<Property>::adjacency_iterator>
MeshGraph<Property>::adjacentVertices(typename MeshGraph<Property>::vertex_descriptor v) const
{
const OutEdgeList& out = rep_[v.second][v.first];
return std::make_pair(out.cbegin(), out.cend());
}
template <typename Property>
MeshGraph<Property>::MeshGraph()
{
//static assert of PartRepresenation::size_type == size_t);
}
template <typename Property>
typename MeshGraph<Property>::vertex_descriptor
MeshGraph<Property>::addVertex(PartColor part)
{
rep_[part].push_back(OutEdgeList());
return vertex_descriptor(rep_[part].size()-1, part);
}
template <typename Property>
std::pair<typename MeshGraph<Property>::edge_descriptor, bool>
MeshGraph<Property>::addEdge(vertex_descriptor u, vertex_descriptor v)
{
assert(u.second != v.second);
//todo:parallel_check
//todo:ordered push
rep_[u.second][u.first].push_back(v.first);
rep_[v.second][v.first].push_back(u.first);
return std::make_pair(edge_descriptor(u.first,v.first),
true);
}
namespace boost {
template <typename Property>
struct graph_traits<MeshGraph<Property> > {
typedef typename MeshGraph<Property>::vertex_descriptor vertex_descriptor;
typedef typename MeshGraph<Property>::edge_descriptor edge_descriptor;
typedef undirected_tag directed_category;
typedef disallow_parallel_edge_tag edge_parallel_category;
typedef adjacency_graph_tag traversal_category; //todo: add more categories
vertex_descriptor null_vertex() {return std::make_pair(0,MeshGraph<Property>::NullVertex);}
typedef typename MeshGraph<Property>::adjacency_iterator adjacency_iterator;
};
}
template <typename Property>
std::pair<
typename boost::graph_traits<MeshGraph<Property> >::adjacency_iterator,
typename boost::graph_traits<MeshGraph<Property> >::adjacency_iterator >
adjacent_vertices(typename boost::graph_traits<MeshGraph<Property> >::vertex_descriptor v,
const MeshGraph<Property>& g)
{
return g.adjacentVertices(v);
}
#endif // MESHGRAPH_HPP