HOG2
MapFlatAbstraction.cpp
Go to the documentation of this file.
1 /*
2  * $Id: MapFlatAbstraction.cpp
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 6/10/05.
6  * Modified by Nathan Sturtevant on 02/29/20.
7  *
8  * This file is part of HOG2. See https://github.com/nathansttt/hog2 for licensing information.
9  *
10  */
11 
12 #include "MapFlatAbstraction.h"
13 
15 :MapAbstraction(_m)
16 {
17  abstractions.push_back(GetMapGraph(_m));
18  groupsValid = false;
19 }
20 
22 {
23 }
24 
26 {
27  int nextNum = 0;
28  Graph *g = abstractions[0];
29  groups.resize(g->GetNumNodes());
30  for (unsigned int x = 0; x < groups.size(); x++)
31  groups[x] = -1;
32 
33  node_iterator ni = g->getNodeIter();
34  for (node *iter = g->nodeIterNext(ni); iter; iter = g->nodeIterNext(ni))
35  {
36  std::vector<unsigned int> stack;
37  if (groups[iter->GetNum()] == -1)
38  {
39  stack.push_back(iter->GetNum());
40  while (stack.size() > 0)
41  {
42  unsigned int next = stack.back();
43  stack.pop_back();
44  if (groups[next] == -1)
45  {
46  groups[next] = nextNum;
47  }
49  for (int val = g->GetNode(next)->nodeNeighborNext(n); val != -1; val = g->GetNode(next)->nodeNeighborNext(n))
50  if (groups[val] == -1)
51  stack.push_back(val);
52  }
53  nextNum++;
54  }
55  }
56  groupsValid = true;
57 }
58 
60 {
61  if (!groupsValid)
63 // int x1, x2, y1, y2;
64 // GetTileFromNode(from, x1, y1);
65 // GetTileFromNode(to, x2, y2);
66 // printf("(%d, %d) and (%d, %d) %s connected\n", x1, y1, x2, y2,
67 // ((groups[from->GetNum()] == groups[to->GetNum()])?"are":"are not"));
68  return (groups[from->GetNum()] == groups[to->GetNum()]);
69 }
70 
72 {
73 }
74 
76 {
77  unsigned int oldID;
78  abstractions[0]->RemoveNode(n, oldID);
79 }
80 
81 void MapFlatAbstraction::RemoveEdge(edge *e, unsigned int)
82 {
83  if (e) abstractions[0]->RemoveEdge(e);
84 }
85 
87 {
88 // n->SetLabelL(kAbstractionLevel, 0); // level in abstraction tree
89 // n->SetLabelL(kNumAbstractedNodes, 1); // number of abstracted nodes
90 // n->SetLabelL(kParent, -1); // parent of this node in abstraction hierarchy
91 // n->SetLabelF(kXCoordinate, kUnknownPosition);
92 // n->SetLabelL(kNodeBlocked, 0);
93 // n->SetLabelL(kFirstData, x);
94 // n->SetLabelL(kFirstData+1, y);
95 // n->SetLabelL(kFirstData+2, kNone);
96  abstractions[0]->AddNode(n);
97 }
98 
99 void MapFlatAbstraction::AddEdge(edge *e, unsigned int)
100 {
101  abstractions[0]->AddEdge(e);
102 }
103 
105 {
106  groupsValid = false;
107 }
MapFlatAbstraction::RemoveNode
virtual void RemoveNode(node *n)
remove node from abstraction
Definition: MapFlatAbstraction.cpp:75
neighbor_iterator
unsigned int neighbor_iterator
Definition: Graph.h:34
MapFlatAbstraction::RemoveEdge
virtual void RemoveEdge(edge *e, unsigned int absLevel)
remove edge from abstraction
Definition: MapFlatAbstraction.cpp:81
Graph::nodeIterNext
node * nodeIterNext(node_iterator &) const
Definition: Graph.cpp:303
Graph
A generic Graph class.
Definition: Graph.h:66
Graph::GetNode
node * GetNode(unsigned long num)
Definition: Graph.cpp:152
MapFlatAbstraction::buildConnectivityGroups
void buildConnectivityGroups()
Definition: MapFlatAbstraction.cpp:25
node_iterator
std::vector< node * >::const_iterator node_iterator
Definition: Graph.h:33
MapFlatAbstraction::groups
std::vector< int > groups
Definition: MapFlatAbstraction.h:45
MapFlatAbstraction::groupsValid
bool groupsValid
Definition: MapFlatAbstraction.h:44
GetMapGraph
Graph * GetMapGraph(Map *m)
GetMapGraph(map)
Definition: MapAbstraction.cpp:312
MapFlatAbstraction::VerifyHierarchy
virtual void VerifyHierarchy()
verify that the hierarchy is consistent
Definition: MapFlatAbstraction.cpp:71
MapFlatAbstraction::AddEdge
virtual void AddEdge(edge *e, unsigned int absLevel)
add edge to abstraction
Definition: MapFlatAbstraction.cpp:99
MapFlatAbstraction::RepairAbstraction
virtual void RepairAbstraction()
This must be called after any of the above add/remove operations.
Definition: MapFlatAbstraction.cpp:104
Graph::GetNumNodes
int GetNumNodes()
Definition: Graph.cpp:403
Graph::getNodeIter
node_iterator getNodeIter() const
Definition: Graph.cpp:298
node::nodeNeighborNext
int nodeNeighborNext(neighbor_iterator &) const
Definition: Graph.cpp:807
MapFlatAbstraction::Pathable
virtual bool Pathable(node *from, node *to)
Definition: MapFlatAbstraction.cpp:59
node::GetNum
unsigned int GetNum() const
Definition: Graph.h:176
node::getNeighborIter
neighbor_iterator getNeighborIter() const
Definition: Graph.cpp:802
MapFlatAbstraction::~MapFlatAbstraction
~MapFlatAbstraction()
Definition: MapFlatAbstraction.cpp:21
MapFlatAbstraction.h
MapFlatAbstraction::AddNode
virtual void AddNode(node *n)
add node to abstraction
Definition: MapFlatAbstraction.cpp:86
MapFlatAbstraction::MapFlatAbstraction
MapFlatAbstraction(Map *_m)
Definition: MapFlatAbstraction.cpp:14
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
Map
A tile-based representation of the world.
Definition: Map.h:142
edge
Edge class for connections between node in a Graph.
Definition: Graph.h:129