GlobeEngine
GraphNode.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_GraphNode_h
10 #define GlobeEngine_GraphNode_h
11 #include "VBOVertex.h"
12 #include "OpenGL_Includes.h"
13 #include <iostream>
14 
15 namespace geGraph {
16  /*
17  * Graph node
18  */
19  template <class T> class GraphNode
20  {
21  public:
22  GraphNode() { }
23  GraphNode(T _uid): uid(_uid){
24  this->marked = false;
25  }
26 
27  T getUID() {
28  return this->uid;
29  }
30 
31  void addEdge(T _edge) {
32  neighbors.push_back(_edge);
33  }
34 
35  std::vector< T > getNeighbors() {
36  return neighbors;
37  }
38 
39  unsigned int getNeighborCount() {
40  return this->neighbors.size();
41  }
42 
43  bool isCrossing() {
44  if (neighbors.size() > 2)
45  return true;
46  return false;
47  }
48 
49  bool isConnector() {
50  if (neighbors.size() == 2)
51  return true;
52  return false;
53  }
54 
55  T getOppositeEdge(T _edgeID) {
56  if (this->isConnector()) {
57  if (_edgeID != neighbors[0] && _edgeID != neighbors[1]) {
58  std::cout << "cannot find this edge connected to graph node" << std::endl;
59  }
60  if(_edgeID == neighbors[0]) {
61  return neighbors[1];
62  }else{
63  return neighbors[0];
64  }
65  }else{
66  std::cout << "node is not a connector" << std::endl;
67  }
68  return std::numeric_limits<T>::max();
69  }
70 
71  bool isEndpoint() {
72  if (neighbors.size() == 1)
73  return true;
74  return false;
75  }
76 
77  bool hasNeighbors() {
78  if (neighbors.size() == 0)
79  return false;
80  return true;
81  }
82 
83  bool isIDaNeighborEdge(T _edgeID) {
84  for (int i = 0;i < this->neighbors.size();i++) {
85  if(this->neighbors[i] == _edgeID){
86  return true;
87  }
88  }
89  return false;
90  }
91 
92  void mark(){
93  this->marked = true;
94  }
95 
96  void unmark(){
97  this->marked = false;
98  }
99 
100  bool isMarked(){
101  return this->marked;
102  }
103 
104  friend std::ostream& operator<< (std::ostream &out, const GraphNode< T > &graphNode) {
105  out << "uid " << graphNode.uid << " has " << graphNode.neighbors.size() << " neighbors: ";
106  for (int i = 0;i < graphNode.neighbors.size();i++) {
107  out << graphNode.neighbors[i] << " ";
108  }
109  return out;
110  }
111 
112  private:
113  bool marked;
114  T uid;
115  std::vector< T > neighbors;
116  };
117 
118  //typedef GraphNode<unsigned int> GraphNodeui;
119 }
120 #endif
bool hasNeighbors()
Definition: GraphNode.h:77
GraphNode()
Definition: GraphNode.h:22
bool isCrossing()
Definition: GraphNode.h:43
T getOppositeEdge(T _edgeID)
Definition: GraphNode.h:55
T getUID()
Definition: GraphNode.h:27
Definition: DirectedEdge.h:16
bool isEndpoint()
Definition: GraphNode.h:71
GraphNode(T _uid)
Definition: GraphNode.h:23
void mark()
Definition: GraphNode.h:92
bool isConnector()
Definition: GraphNode.h:49
bool isIDaNeighborEdge(T _edgeID)
Definition: GraphNode.h:83
unsigned int getNeighborCount()
Definition: GraphNode.h:39
bool isMarked()
Definition: GraphNode.h:100
void unmark()
Definition: GraphNode.h:96
void addEdge(T _edge)
Definition: GraphNode.h:31
std::vector< T > getNeighbors()
Definition: GraphNode.h:35
Definition: GraphNode.h:19