40 #define max(a, b) (((a)>(b))?(a):(b))
90 assert(numRegions < 256);
99 std::vector<tempEdgeData> edges;
101 assert(edges.size() < 256);
106 printf(
"Total bytes used for abstraction: %d\n", (
int)
memory.size());
108 int nodes = 0, edges = 0;
109 for (
unsigned int x = 0; x <
sectors.size(); x++)
111 nodes +=
sectors[x].numRegions;
114 printf(
"%d regions and %d edges\n", nodes, edges);
133 int xSector,
int ySector,
134 std::vector<tempEdgeData> &edges)
136 bool up =
false, down =
false, left =
false, right =
false;
180 edges.push_back(ted);
196 edges.push_back(ted);
212 edges.push_back(ted);
228 edges.push_back(ted);
259 int startIndex,
int startOffset,
260 std::vector<int> &targetRegion,
261 int targetIndex,
int targetOffset,
262 std::vector<tempEdgeData> &edges,
265 int first = (int)edges.size();
269 if ((startRegion[startIndex] != -1) &&
270 (targetRegion[targetIndex] != -1))
273 (edges[edges.size()-1].from != startRegion[startIndex]) ||
274 (edges[edges.size()-1].to != targetRegion[targetIndex]))
278 ted.
from = startRegion[startIndex];
279 ted.
to = targetRegion[targetIndex];
281 for (
unsigned int y = first; y < edges.size(); y++)
291 edges.push_back(ted);
292 last = (int)edges.size()-1;
296 startIndex += startOffset;
297 targetIndex += targetOffset;
315 std::vector<int> &area,
316 std::vector<tempEdgeData> &edges)
320 for (
unsigned int y = 0; y < counts.size(); y++)
322 for (
unsigned int x = 0; x < edges.size(); x++)
323 if (edges[x].from == (
int)y+1)
329 assert(
memory.size() < (1<<16));
344 for (
unsigned int y = 0; y < counts.size(); y++)
346 for (
unsigned int x = 0; x < edges.size(); x++)
348 if (edges[x].from == (
int)y+1)
402 for (
unsigned int x = 0; x < area.size(); x++)
404 if (area[x] == value)
416 for (
unsigned int x = 0; x < area.size(); x++)
418 if (area[x] == value)
446 static bool draw =
false;
449 GLdouble xx, yy, zz, rr;
450 glColor4f(0.5, 0.0, 0.0, 0.5);
458 glVertex3f(xx-rr, yy-rr+2*y*rr*
sectorSize, zz-1*rr);
463 glVertex3f(xx-rr+2*x*rr*
sectorSize, yy-rr, zz-1*rr);
469 if (draw) printf(
"===BEGIN DRAW\n");
471 for (
unsigned int x = 0; x <
sectors.size(); x++)
473 for (
unsigned int y = 0; y <
sectors[x].numRegions; y++)
475 if (draw) printf(
"===DRAW SECTOR %d region %d\n", x, y);
477 unsigned int loc1, loc2;
478 std::vector<tempEdgeData> neighbors;
484 for (
unsigned int z = 0; z < neighbors.size(); z++)
488 glColor3f(1.0, 0.0, 0.0);
490 glColor4f(0.2, 0.8, 0.2, 1.00);
492 if (draw) printf(
"Got edge from region %d to region %d (going dir %d)\n",
493 neighbors[z].from, neighbors[z].to, neighbors[z].direction);
494 if (draw) printf(
"Drawing from (%d, %d)\n", loc1, loc2);
496 GLdouble xx2, yy2, zz2, rr2;
498 switch (neighbors[z].direction)
501 glVertex3f(xx, yy, zz-5.1*rr);
503 glColor3f(1.0, 0.0, 0.0);
505 glColor4f(0.2, 0.8, 0.2, 1.00);
508 if (draw) printf(
"Drawing to (%d, %d)\n", loc1, loc2);
509 glVertex3f(xx2, yy2, zz2-5.1*rr2);
512 glVertex3f(xx, yy, zz-5.1*rr);
514 glColor3f(1.0, 0.0, 0.0);
516 glColor4f(0.2, 0.8, 0.2, 1.00);
519 if (draw) printf(
"Drawing to (%d, %d)\n", loc1, loc2);
520 glVertex3f(xx2, yy2, zz2-5.1*rr2);
525 glVertex3f(xx, yy, zz-5.1*rr);
527 glColor3f(1.0, 0.0, 0.0);
529 glColor4f(0.2, 0.8, 0.2, 1.00);
532 if (draw) printf(
"Drawing to (%d, %d)\n", loc1, loc2);
533 glVertex3f(xx2, yy2, zz2-5.1*rr2);
536 glVertex3f(xx, yy, zz-5.1*rr);
538 glColor3f(1.0, 0.0, 0.0);
540 glColor4f(0.2, 0.8, 0.2, 1.00);
543 if (draw) printf(
"Drawing to (%d, %d)\n", loc1, loc2);
544 glVertex3f(xx2, yy2, zz2-5.1*rr2);
558 static bool draw =
false;
559 static float lineScale = 0.5f;
561 GLdouble xx, yy, zz, rr;
570 display.
DrawLine({
static_cast<float>(xx-rr),
static_cast<float>(yy-rr+2*y*rr*
sectorSize),
static_cast<float>(zz-1*rr)},
578 display.
DrawLine({
static_cast<float>(xx-rr+2*x*rr*
sectorSize),
static_cast<float>(yy-rr),
static_cast<float>(zz-1*rr)},
591 for (
unsigned int x = 0; x <
sectors.size(); x++)
593 for (
unsigned int y = 0; y <
sectors[x].numRegions; y++)
597 unsigned int loc1, loc2;
598 std::vector<tempEdgeData> neighbors;
604 for (
unsigned int z = 0; z < neighbors.size(); z++)
606 GLdouble xx2, yy2, zz2, rr2;
608 switch (neighbors[z].direction)
615 display.
DrawLine({
static_cast<float>(xx),
static_cast<float>(yy),
static_cast<float>(zz-5.1*rr)},
616 {
static_cast<float>(xx2),
static_cast<float>(yy2),
static_cast<float>(zz2-5.1*rr2)}, lineScale*rr2, abstractionColor);
623 display.
DrawLine({
static_cast<float>(xx),
static_cast<float>(yy),
static_cast<float>(zz-5.1*rr)},
624 {
static_cast<float>(xx2),
static_cast<float>(yy2),
static_cast<float>(zz2-5.1*rr2)}, lineScale*rr2, abstractionColor);
633 display.
DrawLine({
static_cast<float>(xx),
static_cast<float>(yy),
static_cast<float>(zz-5.1*rr)},
634 {
static_cast<float>(xx2),
static_cast<float>(yy2),
static_cast<float>(zz2-5.1*rr2)}, lineScale*rr2, abstractionColor);
641 display.
DrawLine({
static_cast<float>(xx),
static_cast<float>(yy),
static_cast<float>(zz-5.1*rr)},
642 {
static_cast<float>(xx2),
static_cast<float>(yy2),
static_cast<float>(zz2-5.1*rr2)}, lineScale*rr2, abstractionColor);
670 unsigned int &y)
const
693 std::vector<tempEdgeData> &edges)
const
696 int sectorAddress =
sectors[sector].memoryAddress;
697 int numRegions =
sectors[sector].numRegions;
698 int numEdges, edgeStart;
702 numEdges =
memory[sectorAddress+region*2+1];
705 edgeStart =
memory[sectorAddress+(region-1)*2+1];
706 numEdges =
memory[sectorAddress+region*2+1]-edgeStart;
708 for (
int x = edgeStart; x < edgeStart+numEdges; x++)
714 ted.
to =
memory[sectorAddress+2*numRegions+x]&0x1F;
717 ted.
to =
memory[sectorAddress+2*numRegions+x]&0x3F;
719 edges.push_back(ted);
740 case 1:
return sector+1;
742 case 3:
return sector-1;
767 if ((x < 0) || (y < 0))
794 if (
sectors[sector].numRegions == 1)
797 std::vector<int> regions(
sectors[sector].numRegions);
798 for (
unsigned int t = 0; t <
sectors[sector].numRegions; t++)
822 std::vector<int> &parents,
823 int mapXOffset,
int mapYOffset)
825 int current = startLoc;
826 std::vector<int> stack;
829 markers[current] = 1;
833 for (
unsigned int x = 0; x < parents.size(); x++)
834 if (current == parents[x])
849 if ((((current+1)%
sectorSize) != 0) && (markers[current+1] == 0))
853 markers[current+1] = 1;
855 if (((current%
sectorSize) != 0) && (markers[current-1] == 0))
859 markers[current-1] = 1;
864 assert(Q.size() != 0);
868 }
while ((markers[current] != 0) &&
937 int x,
int y,
int label)
1019 memory[
sectors[sector].memoryAddress+2*region] = defaultCenter;
1052 for (
unsigned int x = 0; x <
areas[sector].size(); x++)
1054 if (
areas[sector][x] == region+1)
1060 if (
fless(err, error))
1067 printf(
"For %d:%d, error improved to %f at offset %d\n", sector, region, error, best);
1095 int sx,
int sy,
double limit)
1132 assert(!
"Commented out code here.");
1148 int defaultSectors = 0;
1149 for (
unsigned int x = 0; x <
sectors.size(); x++)
1152 if (
sectors[x].numRegions != 1)
1158 std::vector<tempEdgeData> edges;
1159 std::vector<int> edgedir(8);
1161 for (
unsigned int y = 0; y < edges.size(); y++)
1162 edgedir[edges[y].direction] = 1;
1166 for (
unsigned int y = 0; y < edgedir.size(); y++)
1171 printf(
"%d default sectors would save %d bytes\n", defaultSectors, (8+2)*defaultSectors);