HOG2
Voxels.h
Go to the documentation of this file.
1 //
2 // Voxels.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 Voxels_h
10 #define Voxels_h
11 
12 #include "SearchEnvironment.h"
13 #include <vector>
14 #include <cstdint>
15 
16 struct OctreeIndex {
17  int layer : 4;
18  int index : 22;
19  int voxel : 6;
20 };
21 
22 struct voxelState {
24  uint16_t x, y, z;
25 };
26 
27 bool operator==(const voxelState &v1, const voxelState &v2);
28 
29 
58 };
59 
60 class Voxels : public SearchEnvironment<voxelState, voxelAction> {
61 public:
62  Voxels(const char *filename);
63  ~Voxels();
64  void Export(const char *filename);
65  void GetSuccessors(const voxelState &nodeID, std::vector<voxelState> &neighbors) const;
66  void GetActions(const voxelState &nodeID, std::vector<voxelAction> &actions) const;
67  void ApplyAction(voxelState &s, voxelAction a) const;
68  bool InvertAction(voxelAction &a) const;
69 
70 
72  double HCost(const voxelState &node1, const voxelState &node2) const;
73  double GCost(const voxelState &node1, const voxelState &node2) const;
74  double GCost(const voxelState &node, const voxelAction &act) const;
75  bool GoalTest(const voxelState &node, const voxelState &goal) const;
76 
77  uint64_t GetStateHash(const voxelState &node) const;
78  void GetStateFromHash(uint64_t parent, voxelState &s);
79 
80  uint64_t GetActionHash(voxelAction act) const;
81 
82  void OpenGLDraw() const;
83  void OpenGLDraw(const voxelState&) const;
84  void OpenGLDraw(const voxelState&, const voxelState&, float) const;
85  void OpenGLDraw(const voxelState&, const voxelAction&) const;
86  void GLLabelState(const voxelState&, const char *) const;
87  void GLDrawLine(const voxelState &x, const voxelState &y) const;
88 
89  void Draw(Graphics::Display &display) const;
90 
91 private:
92 
93  struct voxelWorld {
94  uint32_t header;
95  float voxelSize;
96  uint64_t numVoxelsGrids;
97  float minbounds[4];
98  float maxbounds[4];
99  uint64_t *morton;
100  uint64_t *grid;
101  };
102 
103  std::vector<uint64_t> mLayer0VoxelGrids;
104 
105  struct OctreeNode {
106  float coordinates[3]; //x,y,z
110  };
111 
112  typedef std::vector<OctreeNode> OctreeLayer;
113  std::vector<OctreeLayer> mOctreeLayers;
114 
115  void AddVoxelCubeToOctree(uint64_t values, point3d p);
116 
118  point3d GetVoxelCoordinate(uint64_t morton, float voxelSize, const float minbounds[4]) const;
119 
120  // "Insert" two 0 bits after each of the 10 low bits of x
121  uint32_t Part1By2(uint32_t x) const;
122  uint32_t EncodeMorton3(uint32_t x, uint32_t y, uint32_t z) const;
123  uint32_t Compact1By2(uint32_t x) const;
124  uint32_t DecodeMorton3X(uint32_t code) const;
125  uint32_t DecodeMorton3Y(uint32_t code) const;
126  uint32_t DecodeMorton3Z(uint32_t code) const;
127  size_t GetIndex(size_t x, size_t y, size_t z) const;
128  void GetCoordsForIndex(size_t i, size_t& x, size_t& y, size_t& z) const;
129 };
130 
131 
132 #endif /* Voxels_h */
kXpYmZm
@ kXpYmZm
Definition: Voxels.h:35
Voxels::HCost
double HCost(const voxelState &node1, const voxelState &node2) const
Heuristic value between two arbitrary nodes.
Definition: Voxels.cpp:192
kXsYmZs
@ kXsYmZs
Definition: Voxels.h:54
Voxels::GetVoxelCoordinate
point3d GetVoxelCoordinate(uint64_t morton, float voxelSize, const float minbounds[4]) const
Definition: Voxels.cpp:232
Voxels::OctreeNode::neighbors
OctreeIndex neighbors[6]
Definition: Voxels.h:109
Voxels::GetActionHash
uint64_t GetActionHash(voxelAction act) const
Definition: Voxels.cpp:226
Voxels::GetCoordsForIndex
void GetCoordsForIndex(size_t i, size_t &x, size_t &y, size_t &z) const
Definition: Voxels.cpp:377
Voxels::DecodeMorton3Y
uint32_t DecodeMorton3Y(uint32_t code) const
Definition: Voxels.cpp:362
Voxels::ApplyAction
void ApplyAction(voxelState &s, voxelAction a) const
Definition: Voxels.cpp:180
Voxels::mLayer0VoxelGrids
std::vector< uint64_t > mLayer0VoxelGrids
Definition: Voxels.h:103
Voxels::OctreeNode
Definition: Voxels.h:105
Voxels::GetSuccessors
void GetSuccessors(const voxelState &nodeID, std::vector< voxelState > &neighbors) const
Definition: Voxels.cpp:170
kXsYpZs
@ kXsYpZs
Definition: Voxels.h:51
voxelState
Definition: Voxels.h:22
kXpYpZp
@ kXpYpZp
Definition: Voxels.h:31
kXmYmZm
@ kXmYmZm
Definition: Voxels.h:44
kXsYsZp
@ kXsYsZp
Definition: Voxels.h:55
Voxels::DecodeMorton3Z
uint32_t DecodeMorton3Z(uint32_t code) const
Definition: Voxels.cpp:367
Voxels::EncodeMorton3
uint32_t EncodeMorton3(uint32_t x, uint32_t y, uint32_t z) const
Definition: Voxels.cpp:341
kXpYpZm
@ kXpYpZm
Definition: Voxels.h:32
voxelAction
voxelAction
Definition: Voxels.h:30
Voxels::Part1By2
uint32_t Part1By2(uint32_t x) const
Definition: Voxels.cpp:331
Voxels::voxelWorld::morton
uint64_t * morton
Definition: Voxels.h:99
Voxels::voxelWorld
Definition: Voxels.h:93
Voxels
Definition: Voxels.h:60
voxelState::x
uint16_t x
Definition: Voxels.h:24
Voxels::GetStateHash
uint64_t GetStateHash(const voxelState &node) const
Definition: Voxels.cpp:213
Voxels::OctreeNode::coordinates
float coordinates[3]
Definition: Voxels.h:106
voxelState::i
OctreeIndex i
Definition: Voxels.h:23
Voxels::w
voxelWorld w
Definition: Voxels.h:117
Voxels::Voxels
Voxels(const char *filename)
Definition: Voxels.cpp:38
kXsYsZm
@ kXsYsZm
Definition: Voxels.h:56
Voxels::voxelWorld::grid
uint64_t * grid
Definition: Voxels.h:100
kXsYmZp
@ kXsYmZp
Definition: Voxels.h:52
OctreeIndex::layer
int layer
Definition: Voxels.h:17
kXpYsZm
@ kXpYsZm
Definition: Voxels.h:38
voxelState::y
uint16_t y
Definition: Voxels.h:24
point3d
#define point3d
Definition: GLUtil.h:123
Graphics::Display
Definition: Graphics.h:146
kXmYmZp
@ kXmYmZp
Definition: Voxels.h:43
Voxels::~Voxels
~Voxels()
Definition: Voxels.cpp:107
kXpYsZs
@ kXpYsZs
Definition: Voxels.h:39
kXmYpZm
@ kXmYpZm
Definition: Voxels.h:41
kXmYmZs
@ kXmYmZs
Definition: Voxels.h:45
kXsYpZm
@ kXsYpZm
Definition: Voxels.h:50
operator==
bool operator==(const voxelState &v1, const voxelState &v2)
Definition: Voxels.cpp:32
OctreeIndex
Definition: Voxels.h:16
kXsYsZs
@ kXsYsZs
Definition: Voxels.h:57
Voxels::voxelWorld::numVoxelsGrids
uint64_t numVoxelsGrids
Definition: Voxels.h:96
OctreeIndex::voxel
int voxel
Definition: Voxels.h:19
Voxels::GetStateFromHash
void GetStateFromHash(uint64_t parent, voxelState &s)
Definition: Voxels.cpp:218
Voxels::GLDrawLine
void GLDrawLine(const voxelState &x, const voxelState &y) const
Definition: Voxels.cpp:319
kXpYpZs
@ kXpYpZs
Definition: Voxels.h:33
kXmYsZm
@ kXmYsZm
Definition: Voxels.h:47
kXpYmZs
@ kXpYmZs
Definition: Voxels.h:36
kXpYsZp
@ kXpYsZp
Definition: Voxels.h:37
voxelState::z
uint16_t z
Definition: Voxels.h:24
Voxels::GCost
double GCost(const voxelState &node1, const voxelState &node2) const
Definition: Voxels.cpp:197
OctreeIndex::index
int index
Definition: Voxels.h:18
Voxels::voxelWorld::voxelSize
float voxelSize
Definition: Voxels.h:95
kXsYmZm
@ kXsYmZm
Definition: Voxels.h:53
Voxels::GetActions
void GetActions(const voxelState &nodeID, std::vector< voxelAction > &actions) const
Definition: Voxels.cpp:175
kXmYpZp
@ kXmYpZp
Definition: Voxels.h:40
kXmYsZs
@ kXmYsZs
Definition: Voxels.h:48
Voxels::GLLabelState
void GLLabelState(const voxelState &, const char *) const
Definition: Voxels.cpp:314
Voxels::InvertAction
bool InvertAction(voxelAction &a) const
Definition: Voxels.cpp:185
Voxels::DecodeMorton3X
uint32_t DecodeMorton3X(uint32_t code) const
Definition: Voxels.cpp:357
Voxels::AddVoxelCubeToOctree
void AddVoxelCubeToOctree(uint64_t values, point3d p)
Definition: Voxels.cpp:245
Voxels::Draw
void Draw(Graphics::Display &display) const
Definition: Voxels.cpp:324
Voxels::voxelWorld::minbounds
float minbounds[4]
Definition: Voxels.h:97
Voxels::OctreeNode::parent
OctreeIndex parent
Definition: Voxels.h:107
Voxels::GetIndex
size_t GetIndex(size_t x, size_t y, size_t z) const
Definition: Voxels.cpp:372
Voxels::voxelWorld::maxbounds
float maxbounds[4]
Definition: Voxels.h:98
Voxels::voxelWorld::header
uint32_t header
Definition: Voxels.h:94
kXpYmZp
@ kXpYmZp
Definition: Voxels.h:34
Voxels::GoalTest
bool GoalTest(const voxelState &node, const voxelState &goal) const
Definition: Voxels.cpp:207
Voxels::OctreeLayer
std::vector< OctreeNode > OctreeLayer
Definition: Voxels.h:112
kXmYpZs
@ kXmYpZs
Definition: Voxels.h:42
kXsYpZp
@ kXsYpZp
Definition: Voxels.h:49
Voxels::Export
void Export(const char *filename)
Definition: Voxels.cpp:112
Voxels::OctreeNode::firstChild
OctreeIndex firstChild
Definition: Voxels.h:108
Voxels::mOctreeLayers
std::vector< OctreeLayer > mOctreeLayers
Definition: Voxels.h:113
SearchEnvironment
Definition: SearchEnvironment.h:30
Voxels::Compact1By2
uint32_t Compact1By2(uint32_t x) const
Definition: Voxels.cpp:347
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
SearchEnvironment.h
kXmYsZp
@ kXmYsZp
Definition: Voxels.h:46
Voxels::OpenGLDraw
void OpenGLDraw() const
Definition: Voxels.cpp:251