Go to the documentation of this file.
12 #include <unordered_map>
18 return v1.
x == v2.
x && v1.
y == v2.
y && v1.
z == v2.
z;
23 out <<
"(" << v.
x <<
", " << v.
y <<
", " << v.
z <<
")";
40 FILE *f = fopen(filename,
"r");
43 printf(
"Error opening file\n");
49 printf(
"Error reading dimensions\n");
54 while ((cnt = fscanf(f,
"%d %d %d\n", &a, &b, &c)) == 3)
70 for (
int y = 0; y <
yWidth; y++)
72 for (
int z = 0; z <
zWidth; z++)
74 for (
int x = 0; x <
xWidth; x++)
84 for (
int y = 0; y <
yWidth; y++)
86 for (
int z = 0; z <
zWidth; z++)
88 for (
int x = 0; x <
xWidth; x++)
99 FILE *f = fopen(filename,
"w+");
102 printf(
"Error opening file\n");
106 for (
int x = 0; x <
xWidth; x++)
108 for (
int y = 0; y <
yWidth; y++)
110 for (
int z = 0; z <
zWidth; z++)
113 fprintf(f,
"%d %d %d\n", x, y, z);
129 for (
int x = 0; x <
xWidth; x++)
131 for (
int y = 0; y <
yWidth; y++)
133 for (
int z = 0; z <
zWidth; z++)
148 FILE *f = fopen(filename,
"w+");
151 printf(
"Error opening file\n");
154 fprintf(f,
"voxel %d %d %d\n", xMax-xMin+1, yMax-yMin+1, zMax-zMin+1);
155 for (
int x = 0; x <
xWidth; x++)
157 for (
int y = 0; y <
yWidth; y++)
159 for (
int z = 0; z <
zWidth; z++)
162 fprintf(f,
"%d %d %d\n", x-xMin, y-yMin, z-zMin);
227 std::deque<voxelGridState> q;
250 for (
size_t x = 0; x <
voxels.size(); x++)
281 for (
int x = -1; x <= 1; x++)
283 for (
int y = -1; y <= 1; y++)
285 for (
int z = -1; z <= 1; z++)
291 {
static_cast<uint16_t
>(nodeID.
x+x),
292 static_cast<uint16_t
>(nodeID.
y+y),
293 static_cast<uint16_t
>(nodeID.
z+z)};
295 neighbors.push_back(s);
306 for (
int x = -1; x <= 1; x++)
308 for (
int y = -1; y <= 1; y++)
310 for (
int z = -1; z <= 1; z++)
315 {
static_cast<uint16_t
>(nodeID.
x+x),
316 static_cast<uint16_t
>(nodeID.
y+y),
317 static_cast<uint16_t
>(nodeID.
z+z)};
343 double xd = abs(node1.
x-node2.
x);
344 double yd = abs(node1.
y-node2.
y);
345 double zd = abs(node1.
z-node2.
z);
370 assert(!
"Should not be able to get here.");
378 if (node1.
x != node2.
x)
380 if (node1.
y != node2.
y)
382 if (node1.
z != node2.
z)
390 assert(!
"Action consts not implemented yet");
414 return (uint64_t(
node.x)<<32)|(uint64_t(
node.y)<<16)|uint64_t(
node.z);
420 s.
y = (parent>>16)&0xFFFF;
421 s.
x = (parent>>32)&0xFFFF;
433 p.x = 2.0*v.
x/range-1.0+(-
xWidth+range)/range + 1.0/range;
434 p.y = 2.0*v.
y/range-1.0+(-
yWidth+range)/range + 1.0/range;
435 p.z = 2.0*v.
z/range-1.0+(-
zWidth+range)/range + 1.0/range;
441 p.x = 2.0*v.
x/range-1.0+(-
xWidth+range)/range;
442 p.y = 2.0*v.
y/range-1.0+(-
yWidth+range)/range;
443 p.z = 2.0*v.
z/range-1.0+(-
zWidth+range)/range;
449 printf(
"Building pre-computed draw buffers\n");
452 std::vector<VoxelUtils::triangle> data;
454 std::unordered_map<VoxelUtils::vn, int> index;
456 for (
size_t x = 0; x < data.size(); x++)
458 for (
int y = 0; y < 3; y++)
461 auto i = index.find(v);
462 if (i == index.end())
479 vertices.push_back(1.0-2.0*v.
v[0]/range);
480 vertices.push_back(0.0+2.0*v.
v[1]/range);
485 vertices.push_back(0.0+2.0*v.
v[1]/range);
487 vertices.push_back(1.0-2.0*v.
v[0]/range);
491 vertices.push_back(1.0-2.0*v.
v[0]/range);
492 vertices.push_back(0.0+2.0*v.
v[1]/range);
497 printf(
"%d individual items\n", next);
499 for (
size_t x = 0; x < data.size(); x++)
501 for (
int y = 0; y < 3; y++)
503 indices.push_back(index[data[x].GetVN(y)]);
512 glEnable(GL_LIGHTING);
513 glEnableClientState(GL_VERTEX_ARRAY);
514 glEnableClientState(GL_NORMAL_ARRAY);
515 glEnableClientState(GL_COLOR_ARRAY);
516 glVertexPointer(3, GL_FLOAT, 9 *
sizeof(GLfloat), &
vertices[0]);
517 glNormalPointer(GL_FLOAT, 9 *
sizeof(GLfloat), &
vertices[0] + 3);
518 glColorPointer(3, GL_FLOAT, 9 *
sizeof(GLfloat), &
vertices[0] + 6);
520 glDrawElements(GL_TRIANGLES,
indices.size(), GL_UNSIGNED_INT, &
indices[0]);
522 glDisableClientState(GL_VERTEX_ARRAY);
523 glDisableClientState(GL_COLOR_ARRAY);
524 glDisableClientState(GL_NORMAL_ARRAY);
525 glDisable(GL_LIGHTING);
536 glEnable(GL_LIGHTING);
537 glColor3f(0.0, 1.0, 0.0);
539 for (uint16_t x = 0; x <
xWidth; x++)
541 for (uint16_t y = 0; y <
yWidth; y++)
543 for (uint16_t z = 0; z <
zWidth; z++)
548 rr = 1-(2.0*x/range-1.0+(-
xWidth+range)/range);
549 gg = 1+(2.0*y/range-1.0+(-
yWidth+range)/range);
550 bb = 1-(2.0*z/range-1.0+(-
zWidth+range)/range);
555 glColor3f(gg, rr, bb);
559 DrawBox(p.x, p.y, p.z, 1/range);
564 glDisable(GL_LIGHTING);
594 glVertex3f(p1.x, p1.y, p1.z);
595 glVertex3f(p2.x, p2.y, p2.z);
605 for (uint16_t x = 0; x <
xWidth; x++)
607 for (uint16_t y = 0; y <
yWidth; y++)
609 for (uint16_t z = 0; z <
zWidth; z++)
625 for (uint16_t x = 0; x <
xWidth; x++)
627 for (uint16_t y = 0; y <
yWidth; y++)
629 for (uint16_t z = 0; z <
zWidth; z++)
634 c.
b = 1.0f-(z-minz)/(
float)(maxz-minz);
640 Graphics::rect r(p.x-1.f/range, p.y-1.f/range, p.x+1.f/range, p.y+1.f/range);
656 for (uint16_t x = 0; x <
xWidth; x++)
658 for (uint16_t y = 0; y <
yWidth; y++)
660 for (uint16_t z = 0; z <
zWidth; z++)
676 for (uint16_t x = 0; x <
xWidth; x++)
678 for (uint16_t y = 0; y <
yWidth; y++)
681 for (uint16_t z = 0; z <
zWidth; z++)
686 c.
b = 1.0f-(z-minz)/(
float)(maxz-minz);
rgbColor GetColor(float v, float vmin, float vmax, int type)
Given min/max values, get a color from a color schema.
voxelGridAction MakeAction(int &x, int &y, int &z) const
void GLLabelState(const voxelGridState &, const char *) const
A color; r/g/b are between 0...1.
BitMapPic * GetImage(int face)
void GetActionOffsets(voxelGridAction a, int &x, int &y, int &z) const
void SetBlocked(const voxelGridState &s, bool block)
void Draw(Graphics::Display &display) const
bool operator==(const voxelGridState &v1, const voxelGridState &v2)
double min(double a, double b)
void Fill(voxelGridState)
void GetActions(const voxelGridState &nodeID, std::vector< voxelGridAction > &actions) const
void GetStateFromHash(uint64_t parent, voxelGridState &s)
std::ostream & operator<<(std::ostream &out, const voxelGridState &v)
void GetGLCornerCoordinate(const voxelGridState &, point3d &) const
void GLDrawLine(const voxelGridState &x, const voxelGridState &y) const
bool Legal(const voxelGridState &s) const
void Save(const char *filename)
void ApplyAction(voxelGridState &s, voxelGridAction a) const
bool GoalTest(const voxelGridState &node, const voxelGridState &goal) const
void GetSuccessors(const voxelGridState &nodeID, std::vector< voxelGridState > &neighbors) const
double GCost(const voxelGridState &node1, const voxelGridState &node2) const
static const double ROOT_TWO
bool CanMove(const voxelGridState &s1, const voxelGridState &s2) const
void SetPixel(int x, int y, uint8_t redByte, uint8_t greenByte, uint8_t blueByte, uint8_t alphaByte=0)
void GetGLCoordinate(const voxelGridState &, point3d &) const
void EfficientDraw() const
bool IsBlocked(const voxelGridState &s) const
void DrawBox(GLfloat xx, GLfloat yy, GLfloat zz, GLfloat rad)
uint64_t GetStateHash(const voxelGridState &node) const
uint64_t GetActionHash(voxelGridAction act) const
std::vector< uint32_t > indices
static const double ROOT_THREE
VoxelGrid(int x, int y, int z)
void GetTriangles(VoxelGrid *s, std::vector< triangle > &data)
std::vector< bool > voxels
voxelGridState GetRandomState()
int GetIndex(const voxelGridState &s) const
void FillRect(rect r, rgbColor c)
std::vector< GLfloat > vertices
bool InvertAction(voxelGridAction &a) const
void GetCoordinates(int index, int &x, int &y, int &z) const
void SaveInMinBB(const char *filename)
Nodes to be stored within a Graph.
double HCost(const voxelGridState &node1, const voxelGridState &node2) const
Heuristic value between two arbitrary nodes.