27 if (
points[index]&(((
int)dir)<<8))
29 points[index] |= (((int)dir)<<8);
30 uint32_t val = (((int)dir)<<16);
41 uint32_t val = (((int)dir)<<16);
52 if (
points[index]&(((
int)dir)<<8))
54 points[index] &= ~(((int)dir)<<8);
62 uint16_t val = (((int)dir)<<8);
73 return (
points[offset]>>8)&0xFF;
83 return (
points[offset]>>16)&0xFF;
120 return (
points[offset]>>3)&0x1F;
132 assert(height < 31 && height >= 0);
139 assert(height < 31 && height >= 0);
177 counts.push_back(
BFS(labels, x, nextID));
186 static std::vector<int> q;
190 while (q.size() != 0)
192 int nextLoc = q.back();
194 if (labels[nextLoc] != -1)
196 assert(labels[nextLoc] == label);
200 labels[nextLoc] = label;
210 if ((labels[nextLoc-1] == -1) &&
212 q.push_back(nextLoc-1);
216 if ((labels[nextLoc+1] == -1) &&
218 q.push_back(nextLoc+1);
362 int newx=0, newy=0, cnt=0;
380 for (
unsigned int x = 0; x <
edges.size(); x++)
393 for (
unsigned int x = 0; x <
edges.size(); x++)
398 if (
edges[x].support == 0)
414 for (
unsigned int t = 0; t <
regions.size(); t++)
416 if (
regions[t].CanAddPoint(regionX, regionY, z))
428 return regions.back().AddPoint(regionX, regionY, z);
435 for (
unsigned int t = 0; t <
regions.size(); t++)
437 if (
regions[t].grid.GetHeightOffset(regionX, regionY) +
regions[t].baseHeight == z)
439 regions[t].grid.RemovePoint(regionX, regionY);
474 for (
unsigned int loc = 0;
loc < visited.size();
loc++)
485 std::deque<int> nextx;
486 std::deque<int> nexty;
493 while (nextx.size() > 0)
495 xLoc = nextx.front();
496 yLoc = nexty.front();
510 nextx.push_back(xLoc+1);
511 nexty.push_back(yLoc);
515 nextx.push_back(xLoc-1);
516 nexty.push_back(yLoc);
520 nextx.push_back(xLoc);
521 nexty.push_back(yLoc+1);
525 nextx.push_back(xLoc);
526 nexty.push_back(yLoc-1);
545 for (
int t = 0; t < 8; t++)
599 neighbors.push_back(s);
776 for (
unsigned int x = 0; x < cnt; x++)
795 for (
int x = 0; x < 8; x++)
800 actions.push_back(a);
815 case kWest: x--;
break;
816 case kEast: x++;
break;
851 return (
node == goal);
873 if ((x < 0) || (y < 0))
956 assert(found[4] != -1);
962 AddEdge(neighborhood[4], neighborhood[1]);
967 AddEdge(neighborhood[4], neighborhood[3]);
972 AddEdge(neighborhood[4], neighborhood[5]);
977 AddEdge(neighborhood[4], neighborhood[7]);
981 if ((found[0] != -1) && (found[1] != -1) && (found[3] != -1) &&
982 (abs(found[0]-found[1]) <= 1) && (abs(found[0]-found[3]) <= 1))
984 AddEdge(neighborhood[4], neighborhood[0]);
985 if (abs(found[1]-found[3]) <= 1)
986 AddEdge(neighborhood[1], neighborhood[3]);
989 if ((found[1] != -1) && (found[2] != -1) && (found[5] != -1) &&
990 (abs(found[1]-found[2]) <= 1) && (abs(found[2]-found[5]) <= 1))
992 AddEdge(neighborhood[4], neighborhood[2]);
993 if (abs(found[1]-found[5]) <= 1)
994 AddEdge(neighborhood[1], neighborhood[5]);
997 if ((found[3] != -1) && (found[6] != -1) && (found[7] != -1) &&
998 (abs(found[3]-found[6]) <= 1) && (abs(found[6]-found[7]) <= 1))
1000 AddEdge(neighborhood[4], neighborhood[6]);
1001 if (abs(found[3]-found[7]) <= 1)
1002 AddEdge(neighborhood[3], neighborhood[7]);
1005 if ((found[5] != -1) && (found[8] != -1) && (found[7] != -1) &&
1006 (abs(found[5]-found[8]) <= 1) && (abs(found[8]-found[7]) <= 1))
1008 AddEdge(neighborhood[4], neighborhood[8]);
1009 if (abs(found[5]-found[7]) <= 1)
1010 AddEdge(neighborhood[5], neighborhood[7]);
1019 assert(
sectors.size() > sec1);
1020 assert(
sectors.size() > sec2);
1025 sectors[sec1].regions[reg1].AddEdge(e2);
1026 sectors[sec2].regions[reg2].AddEdge(e1);
1097 if (offsetDiff == 1)
1102 else if (offsetDiff == -1)
1107 else if (offsetDiff ==
mWidth)
1112 else if (offsetDiff == -
mWidth)
1118 else if (offsetDiff ==
mWidth+1)
1123 else if (offsetDiff ==
mWidth-1)
1128 else if (offsetDiff == -
mWidth+1)
1133 else if (offsetDiff == -
mWidth-1)
1144 if (theRegion == -1)
1151 static std::vector<int> labels;
1152 static std::vector<int> counts;
1153 static std::vector<int> heights;
1154 int regions =
sectors[
GetSector(x, y)].regions[theRegion].grid.LabelAreas(labels, counts, heights);
1157 printf(
"%d regions; split needed\n", regions);
1172 for (
int t = 1; t < counts.size(); t++)
1174 if (counts[t] < counts[smallest])
1181 if (labels[t] == smallest)
1188 if (labels[t] == smallest)
1223 RemoveEdge(neighborhood[4], neighborhood[1]);
1225 RemoveEdge(neighborhood[4], neighborhood[3]);
1227 RemoveEdge(neighborhood[4], neighborhood[5]);
1229 RemoveEdge(neighborhood[4], neighborhood[7]);
1232 if ((found[0] != -1) && (found[1] != -1) && (found[3] != -1) &&
1233 (abs(found[0]-found[1]) <= 1) && (abs(found[0]-found[3]) <= 1))
1235 RemoveEdge(neighborhood[4], neighborhood[0]);
1236 if (abs(found[1]-found[3]) <= 1)
1237 RemoveEdge(neighborhood[1], neighborhood[3]);
1240 if ((found[1] != -1) && (found[2] != -1) && (found[5] != -1) &&
1241 (abs(found[1]-found[2]) <= 1) && (abs(found[2]-found[5]) <= 1))
1243 RemoveEdge(neighborhood[4], neighborhood[2]);
1244 if (abs(found[1]-found[5]) <= 1)
1245 RemoveEdge(neighborhood[1], neighborhood[5]);
1248 if ((found[3] != -1) && (found[6] != -1) && (found[7] != -1) &&
1249 (abs(found[3]-found[6]) <= 1) && (abs(found[6]-found[7]) <= 1))
1251 RemoveEdge(neighborhood[4], neighborhood[6]);
1252 if (abs(found[3]-found[7]) <= 1)
1253 RemoveEdge(neighborhood[3], neighborhood[7]);
1256 if ((found[5] != -1) && (found[8] != -1) && (found[7] != -1) &&
1257 (abs(found[5]-found[8]) <= 1) && (abs(found[8]-found[7]) <= 1))
1259 RemoveEdge(neighborhood[4], neighborhood[8]);
1260 if (abs(found[5]-found[7]) <= 1)
1261 RemoveEdge(neighborhood[5], neighborhood[7]);
1275 sectors[sec1].regions[reg1].RemoveEdge(e2);
1276 sectors[sec2].regions[reg2].RemoveEdge(e1);
1337 if (offsetDiff == 1)
1342 else if (offsetDiff == -1)
1347 else if (offsetDiff ==
mWidth)
1352 else if (offsetDiff == -
mWidth)
1358 else if (offsetDiff ==
mWidth+1)
1363 else if (offsetDiff ==
mWidth-1)
1368 else if (offsetDiff == -
mWidth+1)
1373 else if (offsetDiff == -
mWidth-1)
1388 for (
unsigned t = 0; t <
sectors[sect].regions.size(); t++)
1436 px = (
loc.
x-(-1+scale+xOffset*scale))/(2.0*scale);
1437 py = (
loc.
y-(-1+scale+yOffset*scale))/(2.0*scale);
1438 pz = -
loc.z/(scale*0.1);
1444 glColor4f(0.0, 1.0, 0.0, 1.0);
1451 GLdouble x1, y1, z1, rad, h;
1453 GLdouble left, right, top, bottom;
1460 glVertex3f(x1-rad, top, z1);
1461 glVertex3f(x1-rad, bottom, z1);
1464 glVertex3f(x1-rad, top, z1);
1465 glVertex3f(x1-rad, bottom, z1);
1470 glVertex3f(left, y1-rad, z1);
1471 glVertex3f(right, y1-rad, z1);
1474 glVertex3f(left, y1-rad, z1);
1475 glVertex3f(right, y1-rad, z1);
1480 glVertex3f(-1, -1, 0.01);
1481 glVertex3f( 1, -1, 0.01);
1482 glVertex3f( 1, 1, 0.01);
1483 glVertex3f(-1, 1, 0.01);
1486 glEnable(GL_LIGHTING);
1487 for (
unsigned int x = 0; x <
sectors.size(); x++)
1490 for (
unsigned int y = 0; y <
sectors[x].regions.size(); y++)
1494 glTranslatef(0, 0, -5*h);
1495 for (
unsigned int z = 0; z <
sectors[x].regions[y].edges.size(); z++)
1498 s1.
Init(x, y,
sectors[x].regions[y].centerLocation);
1500 sectors[x].regions[y].edges[z].region,
1501 sectors[
sectors[x].regions[y].edges[z].sector].regions[
sectors[x].regions[y].edges[z].region].centerLocation);
1502 glLineWidth(2+
sectors[x].regions[y].edges[z].support/4);
1505 glTranslatef(0, 0, 5*h);
1508 GLdouble r=0, g=0, b=0;
1511 case 0: g=0.25;r=0.5;b=0.15;
break;
1512 case 1: g=0.35;r=0.5;b=0.15;
break;
1513 case 2: g=0.25;r=0.4;b=0.15;
break;
1514 case 3: g=0.25;r=0.5;b=0.25;
break;
1518 int xLoc, yLoc, zLoc;
1519 int xRegLoc, yRegLoc;
1523 if (!
sectors[x].regions[y].grid.IsPointPassable(xRegLoc, yRegLoc))
1526 zLoc =
sectors[x].regions[y].baseHeight +
sectors[x].regions[y].grid.GetHeightOffset(xRegLoc, yRegLoc);
1532 glNormal3f(0, 0, -1);
1533 glVertex3f(x1-rad, y1-rad, z1);
1534 glVertex3f(x1-rad, y1+rad, z1);
1535 glVertex3f(x1+rad, y1+rad, z1);
1536 glVertex3f(x1+rad, y1-rad, z1);
1541 std::vector<state3d> suc;
1545 for (
unsigned int t = 0; t < suc.size(); t++)
1567 GLdouble x1, y1, z1, rad, h;
1568 GLfloat rr, gg, bb, tt;
1569 int xLoc, yLoc, zLoc;
1575 glDisable(GL_LIGHTING);
1577 glColor4f(rr, gg, bb, tt);
1579 glVertex3f(x1, y1, z1-h);
1584 glVertex3f(x1, y1, z1-h);
1586 glEnable(GL_LIGHTING);
1592 GLdouble &x, GLdouble &y, GLdouble &z,
1593 GLdouble &r, GLdouble &h)
const
1599 x = 2.0*xLoc*scale-1+scale+xOffset*scale;
1600 y = 2.0*yLoc*scale-1+scale+yOffset*scale;
1608 std::vector<int> regCnt;
1610 printf(
"%lu sectors\n",
sectors.size());
1611 for (
unsigned int x = 0; x <
sectors.size(); x++)
1613 if (
sectors[x].regions.size() >= regCnt.size())
1614 regCnt.resize(
sectors[x].regions.size()+1);
1615 regCnt[
sectors[x].regions.size()]++;
1616 regions +=
sectors[x].regions.size();
1618 printf(
"%d regions [avg: %1.2f]\n", regions, (
float)regions/
sectors.size());
1619 for (
unsigned int x = 0; x < regCnt.size(); x++)
1621 printf(
"%d : %d\n", x, regCnt[x]);
1629 for (
unsigned int x = 0; x <
sectors.size(); x++)
1631 mem +=
sectors[x].regions.size()*12;
1632 for (
int y = 0; y <
sectors[x].regions.size(); y++)
1633 mem +=
sectors[x].regions[y].edges.size()*4;
1642 for (
unsigned int x = 0; x <
sectors.size(); x++)