GlobeEngine
Graph.h
Go to the documentation of this file.
1 //
2 // VBOVertex.h
3 // GlobeEngine
4 //
5 // Created by Mathias Thöny on 27.12.11.
6 // Copyright (c) 2011 University of Zurich. All rights reserved.
7 //
8 
9 #ifndef GlobeEngine_Graph_h
10 #define GlobeEngine_Graph_h
11 
12 #include "VBOVertex.h"
13 #include "OpenGL_Includes.h"
14 #include <map>
15 #include <iostream>
16 #include "GraphNode.h"
17 
18 namespace geGraph {
19  /*
20  * common graph with edges and nodes
21  */
22  template <class NODETYPE, class EDGETYPE, class U> class Graph
23  {
24  public:
25  Graph(){
27  }
28  ~Graph() {}
29 
30  void clearProperties() {
33  }
34 
35  unsigned int addNode(NODETYPE _node){
36  unsigned int idx = nodes.size();
37  nodes.push_back(GraphNode< U >(idx));
38  std::pair< NODETYPE, U> pairContent(_node, idx);
39  nodeByContent.insert(pairContent);
40  std::pair< U, NODETYPE> pairID( idx, _node);
41  nodeByID.insert(pairID);
42  return idx;
43  }
44 
45  const std::map< U, NODETYPE > getMapToIterate() const {
46  return this->nodeByID;
47  }
48 
49  U getNodeCount() const {
50  return this->nodes.size();
51  }
52 
53  U getNodeIDByContent(const NODETYPE _content) const {
54  typename std::map< NODETYPE, U >::const_iterator nodeByContentItr = nodeByContent.find(_content);
55  if(nodeByContentItr != nodeByContent.end()) {
56  return nodeByContentItr->second;
57  }else{
58  return 0;
59  }
60  }
61 
62  NODETYPE getNodeContentByID(U _id) const {
63  typename std::map< U, NODETYPE >::const_iterator nodeByIDItr = nodeByID.find(_id);
64  if(nodeByIDItr != nodeByID.end()) {
65  return nodeByIDItr->second;
66  }
67 
68  return NODETYPE();
69  }
70 
71  std::vector< GraphNode< U > > getGraphNodes(){
72  return nodes;
73  }
74 
75  std::vector< U > getEndnodeIDs(){
76  std::vector< U > ids;
77  for (int i = 0;i < nodes.size();i++) {
78  if (nodes[i].isEndpoint()) {
79  ids.push_back(nodes[i].getUID());
80  }
81  }
82  return ids;
83  }
84 
85  std::vector< U > getCrossingIDs(){
86  std::vector< U > ids;
87  for (int i = 0;i < nodes.size();i++) {
88  if (nodes[i].isCrossing()) {
89  ids.push_back(nodes[i].getUID());
90  }
91  }
92  return ids;
93  }
94 
96  this->clearProperties();
97  for (int i = 0;i < nodes.size();i++) {
98  if (nodes[i].isEndpoint()) {
99  this->endPoints.push_back(i);
100  }
101  if (nodes[i].isCrossing()) {
102  this->crossings.push_back(i);
103  }
104  if (nodes[i].isConnector()) {
106  }
107  if (!nodes[i].hasNeighbors()) {
109  }
110  }
111  }
112 
113  unsigned int getNumberOfEndpoints() const {
114  return this->endPoints.size();
115  }
116 
117  unsigned int getNumberOfCrossings() const {
118  return this->crossings.size();
119  }
120 
121  U getEndPointID(unsigned int _idx){
122  return this->endPoints[_idx];
123  }
124 
125  U getCrossingID(unsigned int _idx){
126  return this->crossings[_idx];
127  }
128 
130  return this->edges.size();
131  }
132 
133  EDGETYPE* getEdge(unsigned int _idx){
134  return &this->edges[_idx];
135  }
136 
137  GraphNode< U > getNode(unsigned int _idx){
138  return this->nodes[_idx];
139  }
140 
141  protected:
142  std::map< NODETYPE, U > nodeByContent;
143  std::map< U, NODETYPE > nodeByID;
144 
145  std::vector< GraphNode< U > > nodes;
146 
147  std::vector< EDGETYPE > edges;
148  std::map< std::pair < U , U >, U > forwardEdges;
149  std::map< std::pair < U , U >, U > backwardEdges;
150 
151  std::vector< U > endPoints;
152  std::vector< U > crossings;
153 
154  // graph properties
155  unsigned int numberOfConnectors;
157  };
158 
159 }
160 #endif
const std::map< U, NODETYPE > getMapToIterate() const
Definition: Graph.h:45
std::map< NODETYPE, U > nodeByContent
Definition: Graph.h:142
std::vector< U > getEndnodeIDs()
Definition: Graph.h:75
void updateGraphProperties()
Definition: Graph.h:95
U getCrossingID(unsigned int _idx)
Definition: Graph.h:125
Graph()
Definition: Graph.h:25
unsigned int addNode(NODETYPE _node)
Definition: Graph.h:35
std::vector< U > crossings
Definition: Graph.h:152
Definition: Graph.h:22
U getEdgeCount()
Definition: Graph.h:129
std::map< std::pair< U, U >, U > forwardEdges
Definition: Graph.h:148
unsigned int getNumberOfCrossings() const
Definition: Graph.h:117
unsigned int numberOfAbandonedNodes
Definition: Graph.h:156
U getEndPointID(unsigned int _idx)
Definition: Graph.h:121
std::vector< U > getCrossingIDs()
Definition: Graph.h:85
U getNodeIDByContent(const NODETYPE _content) const
Definition: Graph.h:53
~Graph()
Definition: Graph.h:28
Definition: DirectedEdge.h:16
std::vector< GraphNode< U > > getGraphNodes()
Definition: Graph.h:71
std::vector< EDGETYPE > edges
Definition: Graph.h:147
unsigned int numberOfConnectors
Definition: Graph.h:155
std::vector< GraphNode< U > > nodes
Definition: Graph.h:145
std::map< U, NODETYPE > nodeByID
Definition: Graph.h:143
EDGETYPE * getEdge(unsigned int _idx)
Definition: Graph.h:133
std::map< std::pair< U, U >, U > backwardEdges
Definition: Graph.h:149
NODETYPE getNodeContentByID(U _id) const
Definition: Graph.h:62
std::vector< U > endPoints
Definition: Graph.h:151
GraphNode< U > getNode(unsigned int _idx)
Definition: Graph.h:137
unsigned int getNumberOfEndpoints() const
Definition: Graph.h:113
void clearProperties()
Definition: Graph.h:30
U getNodeCount() const
Definition: Graph.h:49
Definition: GraphNode.h:19