HOG2
Map2DHeading.h
Go to the documentation of this file.
1 //
2 // Map2DHeading.h
3 // hog2 glut
4 //
5 // Created by Nathan Sturtevant on 11/12/12.
6 // Copyright (c) 2012 University of Denver. All rights reserved.
7 //
8 
9 #ifndef __hog2_glut__Map2DHeading__
10 #define __hog2_glut__Map2DHeading__
11 
12 #include "SearchEnvironment.h"
13 #include "Map.h"
14 
15 #include <cassert>
16 #include <iostream>
17 #include <unordered_map>
18 
19 //#include "BaseMapOccupancyInterface.h"
20 
21 struct xyhLoc {
22 public:
23  xyhLoc() { x = -1; y = -1; h = -1; }
24  xyhLoc(uint16_t _x, uint16_t _y, uint8_t heading) :x(_x), y(_y), h(heading) {}
25  uint16_t x;
26  uint16_t y;
27  uint8_t h;
28 };
29 
30 static std::ostream& operator <<(std::ostream & out, const xyhLoc &loc)
31 {
32  out << "(" << loc.x << ", " << loc.y << ", " << static_cast<int>(loc.h) << ")";
33  return out;
34 }
35 
36 static bool operator==(const xyhLoc &l1, const xyhLoc &l2)
37 {
38  return (l1.x == l2.x) && (l1.y == l2.y) && (l1.h == l2.h);
39 }
40 
41 struct xyhAct {
42  uint8_t oldHeading;
43  uint8_t newHeading;
44 };
45 
46 class Map2DHeading : public SearchEnvironment<xyhLoc, xyhAct>
47 {
48 public:
49  Map2DHeading(Map *m);
50 // Map2DHeading(Map2DHeading *);
51  virtual ~Map2DHeading();
52  virtual void GetSuccessors(const xyhLoc &nodeID, std::vector<xyhLoc> &neighbors) const;
53  void GetActions(const xyhLoc &nodeID, std::vector<xyhAct> &actions) const;
54  xyhAct GetAction(const xyhLoc &s1, const xyhLoc &s2) const;
55  virtual void ApplyAction(xyhLoc &s, xyhAct dir) const;
56 
57  virtual bool InvertAction(xyhAct &a) const;
58 
59  // bool Contractable(const xyhLoc &where);
60 
61  virtual double HCost(const xyhLoc &) const {
62  fprintf(stderr, "ERROR: Single State HCost not implemented\n");
63  exit(1); return -1.0;}
64  virtual double HCost(const xyhLoc &node1, const xyhLoc &node2) const;
65  virtual double GCost(const xyhLoc &node1, const xyhLoc &node2) const;
66  virtual double GCost(const xyhLoc &node1, const xyhAct &act) const;
67  bool GoalTest(const xyhLoc &node, const xyhLoc &goal) const;
68 
69  bool GoalTest(const xyhLoc &) const {
70  fprintf(stderr, "ERROR: Single State Goal Test not implemented \n");
71  exit(1); return false;}
72 
73  uint64_t GetStateHash(const xyhLoc &node) const;
74  void GetStateFromHash(uint64_t hash, xyhLoc &node) const;
75  uint64_t GetActionHash(xyhAct act) const;
76  virtual void OpenGLDraw() const;
77  virtual void OpenGLDraw(const xyhLoc &l) const;
78  virtual void OpenGLDraw(const xyhLoc &l1, const xyhLoc &l2, float v) const;
79  virtual void OpenGLDraw(const xyhLoc &, const xyhAct &) const;
80  virtual void GLLabelState(const xyhLoc &, const char *) const;
81  virtual void GLDrawLine(const xyhLoc &x, const xyhLoc &y) const;
82  //virtual void OpenGLDraw(const xyhLoc &, const xyhAct &, GLfloat r, GLfloat g, GLfloat b) const;
83  //virtual void OpenGLDraw(const xyhLoc &l, GLfloat r, GLfloat g, GLfloat b) const;
84  Map* GetMap() const { return map; }
85 
86  virtual void GetNextState(const xyhLoc &currents, xyhAct dir, xyhLoc &news) const;
87 
88  void StoreGoal(xyhLoc &) {} // stores the locations for the given goal state
89  void ClearGoal() {}
90  bool IsGoalStored() const {return false;}
91  void SetDiagonalCost(double val) { DIAGONAL_COST = val; }
92  double GetDiagonalCost() { return DIAGONAL_COST; }
93  bool FourConnected() { return fourConnected; }
94  bool EightConnected() { return !fourConnected; }
95  void SetFourConnected() { fourConnected = true; }
96  void SetEightConnected() { fourConnected = false; }
97 
98  void SetCost(const xyhLoc &, double seen, double dist);
99  void ClearCost(const xyhLoc &);
100  void ClearAllCosts();
102 protected:
106  std::vector<float> cosTable;
107  std::vector<float> sinTable;
108 
109  // P is visibility setting
110  double GetCost(const xyhLoc &a, const xyhLoc &b, double P, double d) const;
111 
112  struct hdData { double seen; double dist; };
113  typedef std::unordered_map<uint64_t, hdData, Hash64> CostTable;
115  bool LegalState(const xyhLoc &s);
116  void BuildAngleTables();
117  float mySin(int dir) const;
118  float myCos(int dir) const;
119 };
120 
121 #endif /* defined(__hog2_glut__Map2DHeading__) */
Map2DHeading::GetActionHash
uint64_t GetActionHash(xyhAct act) const
Definition: Map2DHeading.cpp:223
Map2DHeading::IsGoalStored
bool IsGoalStored() const
Definition: Map2DHeading.h:90
loc::x
int x
Definition: MapGenerators.cpp:296
Map2DHeading::HCost
virtual double HCost(const xyhLoc &) const
Heuristic value between node and the stored goal.
Definition: Map2DHeading.h:61
Map2DHeading::SetFourConnected
void SetFourConnected()
Definition: Map2DHeading.h:95
xyhLoc::xyhLoc
xyhLoc()
Definition: Map2DHeading.h:23
xyhLoc
Definition: Map2DHeading.h:21
Map2DHeading::GetActions
void GetActions(const xyhLoc &nodeID, std::vector< xyhAct > &actions) const
Definition: Map2DHeading.cpp:44
Map2DHeading::GetStateHash
uint64_t GetStateHash(const xyhLoc &node) const
Definition: Map2DHeading.cpp:205
loc::y
int y
Definition: MapGenerators.cpp:296
Map2DHeading::cosTable
std::vector< float > cosTable
Definition: Map2DHeading.h:106
Map2DHeading::drawWeights
bool drawWeights
Definition: Map2DHeading.h:101
d
mcData d[]
Definition: MotionCaptureMovement.cpp:21
Map2DHeading::SetCost
void SetCost(const xyhLoc &, double seen, double dist)
Definition: Map2DHeading.cpp:386
xyhLoc::y
uint16_t y
Definition: Map2DHeading.h:26
Map2DHeading::GetDiagonalCost
double GetDiagonalCost()
Definition: Map2DHeading.h:92
Map2DHeading::InvertAction
virtual bool InvertAction(xyhAct &a) const
Definition: Map2DHeading.cpp:92
Map2DHeading::OpenGLDraw
virtual void OpenGLDraw() const
Definition: Map2DHeading.cpp:228
Map2DHeading::EightConnected
bool EightConnected()
Definition: Map2DHeading.h:94
Map2DHeading::SetEightConnected
void SetEightConnected()
Definition: Map2DHeading.h:96
Map2DHeading::ApplyAction
virtual void ApplyAction(xyhLoc &s, xyhAct dir) const
Definition: Map2DHeading.cpp:71
Map2DHeading::~Map2DHeading
virtual ~Map2DHeading()
Definition: Map2DHeading.cpp:23
Map2DHeading::map
Map * map
Definition: Map2DHeading.h:103
Map2DHeading::ClearGoal
void ClearGoal()
Clears the goal from memory.
Definition: Map2DHeading.h:89
xyhLoc::xyhLoc
xyhLoc(uint16_t _x, uint16_t _y, uint8_t heading)
Definition: Map2DHeading.h:24
Map2DHeading::DIAGONAL_COST
double DIAGONAL_COST
Definition: Map2DHeading.h:104
Map2DHeading::fourConnected
bool fourConnected
Definition: Map2DHeading.h:105
loc
Definition: MapGenerators.cpp:296
Map2DHeading::costs
CostTable costs
Definition: Map2DHeading.h:114
Map2DHeading::GetMap
Map * GetMap() const
Definition: Map2DHeading.h:84
Map2DHeading::GoalTest
bool GoalTest(const xyhLoc &) const
Goal Test if the goal is stored.
Definition: Map2DHeading.h:69
xyhAct::oldHeading
uint8_t oldHeading
Definition: Map2DHeading.h:42
Map2DHeading::hdData::seen
double seen
Definition: Map2DHeading.h:112
Map2DHeading::GetSuccessors
virtual void GetSuccessors(const xyhLoc &nodeID, std::vector< xyhLoc > &neighbors) const
Definition: Map2DHeading.cpp:28
Map2DHeading::hdData::dist
double dist
Definition: Map2DHeading.h:112
Map2DHeading::hdData
Definition: Map2DHeading.h:112
Map2DHeading::FourConnected
bool FourConnected()
Definition: Map2DHeading.h:93
xyhAct::newHeading
uint8_t newHeading
Definition: Map2DHeading.h:43
xyhLoc::x
uint16_t x
Definition: Map2DHeading.h:25
Map2DHeading::mySin
float mySin(int dir) const
Definition: Map2DHeading.cpp:376
Map2DHeading::LegalState
bool LegalState(const xyhLoc &s)
Definition: Map2DHeading.cpp:193
Map2DHeading::GCost
virtual double GCost(const xyhLoc &node1, const xyhLoc &node2) const
Definition: Map2DHeading.cpp:140
Map2DHeading::ClearAllCosts
void ClearAllCosts()
Definition: Map2DHeading.cpp:397
Map2DHeading::GLLabelState
virtual void GLLabelState(const xyhLoc &, const char *) const
Definition: Map2DHeading.cpp:347
Map2DHeading::Map2DHeading
Map2DHeading(Map *m)
Definition: Map2DHeading.cpp:15
Map2DHeading::SetDiagonalCost
void SetDiagonalCost(double val)
Definition: Map2DHeading.h:91
Map2DHeading::sinTable
std::vector< float > sinTable
Definition: Map2DHeading.h:107
xyhLoc::h
uint8_t h
Definition: Map2DHeading.h:27
Map2DHeading::GetCost
double GetCost(const xyhLoc &a, const xyhLoc &b, double P, double d) const
Definition: Map2DHeading.cpp:109
operator<<
static std::ostream & operator<<(std::ostream &out, const xyhLoc &loc)
Definition: Map2DHeading.h:30
Map2DHeading::GetStateFromHash
void GetStateFromHash(uint64_t hash, xyhLoc &node) const
Definition: Map2DHeading.cpp:214
Map.h
Map2DHeading::BuildAngleTables
void BuildAngleTables()
Definition: Map2DHeading.cpp:364
Map2DHeading::StoreGoal
void StoreGoal(xyhLoc &)
Stores the goal for use by single-state HCost.
Definition: Map2DHeading.h:88
Map2DHeading::GetNextState
virtual void GetNextState(const xyhLoc &currents, xyhAct dir, xyhLoc &news) const
Definition: Map2DHeading.cpp:358
Map2DHeading::ClearCost
void ClearCost(const xyhLoc &)
Definition: Map2DHeading.cpp:392
Map2DHeading::CostTable
std::unordered_map< uint64_t, hdData, Hash64 > CostTable
Definition: Map2DHeading.h:113
xyhAct
Definition: Map2DHeading.h:41
operator==
static bool operator==(const xyhLoc &l1, const xyhLoc &l2)
Definition: Map2DHeading.h:36
Map2DHeading
Definition: Map2DHeading.h:46
Map2DHeading::GLDrawLine
virtual void GLDrawLine(const xyhLoc &x, const xyhLoc &y) const
Definition: Map2DHeading.cpp:352
SearchEnvironment
Definition: SearchEnvironment.h:30
Map2DHeading::myCos
float myCos(int dir) const
Definition: Map2DHeading.cpp:381
Map2DHeading::GoalTest
bool GoalTest(const xyhLoc &node, const xyhLoc &goal) const
Definition: Map2DHeading.cpp:200
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
Map
A tile-based representation of the world.
Definition: Map.h:142
SearchEnvironment.h
Map2DHeading::GetAction
xyhAct GetAction(const xyhLoc &s1, const xyhLoc &s2) const
Definition: Map2DHeading.cpp:63