HOG2
VoxelGrid.h
Go to the documentation of this file.
1 //
2 // VoxelGrid.h
3 // hog2 glut
4 //
5 // Created by Nathan Sturtevant on 3/7/16.
6 // Copyright © 2016 University of Denver. All rights reserved.
7 //
8 
9 #ifndef VoxelGrid_h
10 #define VoxelGrid_h
11 
12 #include "SearchEnvironment.h"
13 #include <vector>
14 #include "BitMap.h"
15 
18  voxelGridState(uint16_t a, uint16_t b, uint16_t c)
19  :x(a), y(b), z(c) {}
20  uint16_t x, y, z;
21 };
22 
23 namespace std {
24  template <>
25  struct hash<voxelGridState>
26  {
27  std::size_t operator()(const voxelGridState& k) const
28  {
29  return ((size_t)k.x<<32)|((size_t)k.y<<16)|k.z;
30  }
31  };
32 
33 }
34 
35 bool operator==(const voxelGridState &v1, const voxelGridState &v2);
36 
37 std::ostream &operator<<(std::ostream &out, const voxelGridState &v);
38 
39 typedef uint8_t voxelGridAction;
40 
41 class VoxelGrid : public SearchEnvironment<voxelGridState, voxelGridAction> {
42 public:
43  VoxelGrid(int x, int y, int z);
44  VoxelGrid(const char *filename);
45  ~VoxelGrid();
46 
47  void And(VoxelGrid *g);
48  void Or(VoxelGrid *g);
49  void Save(const char *filename);
50  void SaveInMinBB(const char *filename);
51  void GetSuccessors(const voxelGridState &nodeID, std::vector<voxelGridState> &neighbors) const;
52  void GetActions(const voxelGridState &nodeID, std::vector<voxelGridAction> &actions) const;
53  void ApplyAction(voxelGridState &s, voxelGridAction a) const;
54  bool InvertAction(voxelGridAction &a) const;
55 
57  double HCost(const voxelGridState &node1, const voxelGridState &node2) const;
58  double GCost(const voxelGridState &node1, const voxelGridState &node2) const;
59  double GCost(const voxelGridState &node, const voxelGridAction &act) const;
60  bool GoalTest(const voxelGridState &node, const voxelGridState &goal) const;
61 
62  uint64_t GetStateHash(const voxelGridState &node) const;
63  void GetStateFromHash(uint64_t parent, voxelGridState &s);
64 
65  uint64_t GetActionHash(voxelGridAction act) const;
66 
67  bool IsBlocked(const voxelGridState &s) const;
68  bool IsBlocked(uint16_t x, uint16_t y, uint16_t z) const
69  { return IsBlocked({x, y, z}); }
70  void SetBlocked(const voxelGridState &s, bool block);
71  void SetBlocked(uint16_t x, uint16_t y, uint16_t z, bool block)
72  { SetBlocked({x, y, z}, block); }
73  void GetLimits(int &x, int &y, int &z) const { x = xWidth; y = yWidth; z = zWidth; }
74  bool Legal(const voxelGridState &s) const;
75  bool CanMove(const voxelGridState &s1, const voxelGridState &s2) const;
77 
78  void OpenGLDraw() const;
79  void OpenGLDraw(const voxelGridState&) const;
80  void OpenGLDraw(const voxelGridState&, const voxelGridState&, float) const;
81  void OpenGLDraw(const voxelGridState&, const voxelGridAction&) const;
82  void GLLabelState(const voxelGridState&, const char *) const;
83  void GLDrawLine(const voxelGridState &x, const voxelGridState &y) const;
84  void Draw(Graphics::Display &display) const;
85 
86  void GetGLCoordinate(const voxelGridState &, point3d &) const;
87  void GetGLCornerCoordinate(const voxelGridState &, point3d &) const;
88  void Fill(voxelGridState);
89  void Invert();
90  BitMapPic *GetImage(int face);
91  void SetUseEfficientDraw(bool e)
92  {
93  efficient = e;
95  }
96 private:
97  bool efficient;
98  void SetUpDrawBuffers();
99  void EfficientDraw() const;
100 
101  void GetActionOffsets(voxelGridAction a, int &x, int &y, int &z) const;
102  voxelGridAction MakeAction(int &x, int &y, int &z) const;
103  int GetIndex(const voxelGridState &s) const;
104  int GetIndex(int x, int y, int z) const;
105  void GetCoordinates(int index, int &x, int &y, int &z) const;
106  void GetCoordinates(int index, voxelGridState &s) const;
107  std::vector<bool> voxels;
109  std::vector<GLfloat> vertices;
110  std::vector<uint32_t> indices;
111 };
112 
113 
114 #endif /* VoxelGrid_h */
voxelGridState::voxelGridState
voxelGridState()
Definition: VoxelGrid.h:17
VoxelGrid::MakeAction
voxelGridAction MakeAction(int &x, int &y, int &z) const
Definition: VoxelGrid.cpp:267
voxelGridState::z
uint16_t z
Definition: VoxelGrid.h:20
BitMapPic
Definition: BitMap.h:46
VoxelGrid::GLLabelState
void GLLabelState(const voxelGridState &, const char *) const
Definition: VoxelGrid.cpp:583
VoxelGrid::GetImage
BitMapPic * GetImage(int face)
Definition: VoxelGrid.cpp:650
VoxelGrid::GetActionOffsets
void GetActionOffsets(voxelGridAction a, int &x, int &y, int &z) const
Definition: VoxelGrid.cpp:257
VoxelGrid::SetBlocked
void SetBlocked(const voxelGridState &s, bool block)
Definition: VoxelGrid.cpp:176
VoxelGrid::Draw
void Draw(Graphics::Display &display) const
Definition: VoxelGrid.cpp:599
VoxelGrid::Fill
void Fill(voxelGridState)
Definition: VoxelGrid.cpp:225
voxelGridAction
uint8_t voxelGridAction
Definition: VoxelGrid.h:39
VoxelGrid::~VoxelGrid
~VoxelGrid()
Definition: VoxelGrid.cpp:63
VoxelGrid::GetActions
void GetActions(const voxelGridState &nodeID, std::vector< voxelGridAction > &actions) const
Definition: VoxelGrid.cpp:301
VoxelGrid::GetStateFromHash
void GetStateFromHash(uint64_t parent, voxelGridState &s)
Definition: VoxelGrid.cpp:417
VoxelGrid::And
void And(VoxelGrid *g)
Definition: VoxelGrid.cpp:68
operator==
bool operator==(const voxelGridState &v1, const voxelGridState &v2)
Definition: VoxelGrid.cpp:16
VoxelGrid::GetGLCornerCoordinate
void GetGLCornerCoordinate(const voxelGridState &, point3d &) const
Definition: VoxelGrid.cpp:438
VoxelGrid::Or
void Or(VoxelGrid *g)
Definition: VoxelGrid.cpp:82
VoxelGrid::SetUpDrawBuffers
void SetUpDrawBuffers()
Definition: VoxelGrid.cpp:447
VoxelGrid::GLDrawLine
void GLDrawLine(const voxelGridState &x, const voxelGridState &y) const
Definition: VoxelGrid.cpp:588
VoxelGrid::Legal
bool Legal(const voxelGridState &s) const
Definition: VoxelGrid.cpp:208
VoxelGrid::Save
void Save(const char *filename)
Definition: VoxelGrid.cpp:97
VoxelGrid
Definition: VoxelGrid.h:41
VoxelGrid::ApplyAction
void ApplyAction(voxelGridState &s, voxelGridAction a) const
Definition: VoxelGrid.cpp:325
voxelGridState::y
uint16_t y
Definition: VoxelGrid.h:20
VoxelGrid::GoalTest
bool GoalTest(const voxelGridState &node, const voxelGridState &goal) const
Definition: VoxelGrid.cpp:394
point3d
#define point3d
Definition: GLUtil.h:123
VoxelGrid::zWidth
int zWidth
Definition: VoxelGrid.h:108
VoxelGrid::GetSuccessors
void GetSuccessors(const voxelGridState &nodeID, std::vector< voxelGridState > &neighbors) const
Definition: VoxelGrid.cpp:277
Graphics::Display
Definition: Graphics.h:146
VoxelGrid::GCost
double GCost(const voxelGridState &node1, const voxelGridState &node2) const
Definition: VoxelGrid.cpp:375
VoxelGrid::CanMove
bool CanMove(const voxelGridState &s1, const voxelGridState &s2) const
Definition: VoxelGrid.cpp:213
BitMap.h
VoxelGrid::GetGLCoordinate
void GetGLCoordinate(const voxelGridState &, point3d &) const
Definition: VoxelGrid.cpp:430
VoxelGrid::EfficientDraw
void EfficientDraw() const
Definition: VoxelGrid.cpp:508
VoxelGrid::GetLimits
void GetLimits(int &x, int &y, int &z) const
Definition: VoxelGrid.h:73
VoxelGrid::IsBlocked
bool IsBlocked(const voxelGridState &s) const
Definition: VoxelGrid.cpp:169
std::hash< voxelGridState >::operator()
std::size_t operator()(const voxelGridState &k) const
Definition: VoxelGrid.h:27
VoxelGrid::OpenGLDraw
void OpenGLDraw() const
Definition: VoxelGrid.cpp:529
std
Definition: CanonicalGraphEnvironment.h:26
VoxelGrid::GetStateHash
uint64_t GetStateHash(const voxelGridState &node) const
Definition: VoxelGrid.cpp:412
VoxelGrid::GetActionHash
uint64_t GetActionHash(voxelGridAction act) const
Definition: VoxelGrid.cpp:425
VoxelGrid::indices
std::vector< uint32_t > indices
Definition: VoxelGrid.h:110
VoxelGrid::efficient
bool efficient
Definition: VoxelGrid.h:97
voxelGridState::x
uint16_t x
Definition: VoxelGrid.h:20
VoxelGrid::SetBlocked
void SetBlocked(uint16_t x, uint16_t y, uint16_t z, bool block)
Definition: VoxelGrid.h:71
VoxelGrid::VoxelGrid
VoxelGrid(int x, int y, int z)
Definition: VoxelGrid.cpp:28
VoxelGrid::voxels
std::vector< bool > voxels
Definition: VoxelGrid.h:107
voxelGridState
Definition: VoxelGrid.h:16
VoxelGrid::GetRandomState
voxelGridState GetRandomState()
Definition: VoxelGrid.cpp:400
VoxelGrid::GetIndex
int GetIndex(const voxelGridState &s) const
Definition: VoxelGrid.cpp:182
operator<<
std::ostream & operator<<(std::ostream &out, const voxelGridState &v)
Definition: VoxelGrid.cpp:21
VoxelGrid::SetUseEfficientDraw
void SetUseEfficientDraw(bool e)
Definition: VoxelGrid.h:91
VoxelGrid::vertices
std::vector< GLfloat > vertices
Definition: VoxelGrid.h:109
VoxelGrid::IsBlocked
bool IsBlocked(uint16_t x, uint16_t y, uint16_t z) const
Definition: VoxelGrid.h:68
VoxelGrid::InvertAction
bool InvertAction(voxelGridAction &a) const
Definition: VoxelGrid.cpp:334
VoxelGrid::GetCoordinates
void GetCoordinates(int index, int &x, int &y, int &z) const
Definition: VoxelGrid.cpp:200
VoxelGrid::yWidth
int yWidth
Definition: VoxelGrid.h:108
VoxelGrid::xWidth
int xWidth
Definition: VoxelGrid.h:108
VoxelGrid::SaveInMinBB
void SaveInMinBB(const char *filename)
Definition: VoxelGrid.cpp:120
SearchEnvironment
Definition: SearchEnvironment.h:30
VoxelGrid::Invert
void Invert()
Definition: VoxelGrid.cpp:248
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
SearchEnvironment.h
voxelGridState::voxelGridState
voxelGridState(uint16_t a, uint16_t b, uint16_t c)
Definition: VoxelGrid.h:18
VoxelGrid::HCost
double HCost(const voxelGridState &node1, const voxelGridState &node2) const
Heuristic value between two arbitrary nodes.
Definition: VoxelGrid.cpp:341