/** * @brief Dumps contents of the entire client routing table to CSV file. * @sa CL_InitLocal */ void Grid_DumpClientRoutes_f (void) { ipos3_t wpMins, wpMaxs; VecToPos(cl.mapData->mapBox.mins, wpMins); VecToPos(cl.mapData->mapBox.maxs, wpMaxs); RT_WriteCSVFiles(cl.mapData->routing, "ufoaiclient", GridBox(wpMins, wpMaxs)); }
void ac::Grid::createGrid(cv::Mat &frame, int w, int h, int size) { cleanBoxes(); g_w = w; g_h = h; g_s = size; boxes = new GridBox*[g_w]; for(int i = 0; i < g_w; ++i) { boxes[i] = new GridBox[h]; } if(!points.empty()) { points.erase(points.begin(), points.end()); } for(int i = 0; i < g_w; ++i) { for(int z = 0; z < g_h; ++z) { cv::Vec3b pixel = frame.at<cv::Vec3b>(z*size, i*size); Point p(i, z); points.push_back(p); boxes[i][z] = GridBox(pixel); if(g_random) boxes[i][z].on = ((rand()%4) == 0) ? false : true; } } std::shuffle(points.begin(), points.end(), rng); current_offset = 0; }
void ofApp::setupScene(int width, int height) { /* setup camera */ double aspectRatio = static_cast<double>(width) / height; ofVec3f topLeft (-CAMERA_SIZE * aspectRatio, CAMERA_SIZE, 0.0); ofVec3f botLeft (-CAMERA_SIZE * aspectRatio, -CAMERA_SIZE, 0.0); ofVec3f botRight( CAMERA_SIZE * aspectRatio, -CAMERA_SIZE, 0.0); cam = OffAxisCamera(topLeft, botLeft, botRight); cam.setPosition(ofVec3f(0.0, 0.0, 50.0f)); /* calculate grid box dimension */ ofVec3f camWidthVec = botRight - botLeft; double camWidth = camWidthVec.length(); gridBox = GridBox(ofVec3f(-CAMERA_SIZE * aspectRatio, -CAMERA_SIZE, 0.0f), camWidth, camWidth / aspectRatio, 8.0f); }
void ac::Grid::fillGrid(cv::Mat &frame) { if(current_offset < points.size()) return; for(int i = 0; i < g_w; ++i) { for(int z = 0; z < g_h; ++z) { cv::Vec3b pixel = frame.at<cv::Vec3b>(z*g_s, i*g_s); boxes[i][z] = GridBox(pixel); if(g_random) boxes[i][z].on = ((rand()%4) == 0) ? false : true; } } current_offset = 0; std::shuffle(points.begin(), points.end(), rng); }
/** * @brief Calculates the routing of a map * @sa CheckUnit * @sa CheckConnections * @sa ProcessWorldModel */ void DoRouting (void) { int i; byte* data; pos3_t pos; /* Turn on trace debugging if requested. */ if (config.generateDebugTrace) debugTrace = true; /* Record the current mapTiles[0] state so we can remove all CLIPS when done. */ PushInfo(); /* build tracing structure */ EmitBrushes(); EmitPlanes(); /** This is needed for tracing to work!!! */ /** @note LEVEL_TRACING is not an actual level */ MakeTracingNodes(LEVEL_ACTORCLIP + 1); /* Reset the whole block of map data to 0 */ Nmap.init(); /* get world bounds for optimizing */ AABB tileBox; RT_GetMapSize(&mapTiles, tileBox); VecToPos(tileBox.mins, wpMins); VecToPos(tileBox.maxs, wpMaxs); /* wpMaxs is on a 32 boundary. This causes VecToPos to calculate a pos *above* wpMAxs. We have to compensate. */ wpMaxs[0]--; wpMaxs[1]--; wpMaxs[2]--; /* Verify the world extents are not lopsided. */ assert(wpMins[0] <= wpMaxs[0]); assert(wpMins[1] <= wpMaxs[1]); assert(wpMins[2] <= wpMaxs[2]); /* scan area heights */ RunSingleThreadOn(CheckUnitThread, PATHFINDING_WIDTH * PATHFINDING_WIDTH * ACTOR_MAX_SIZE, config.verbosity >= VERB_NORMAL, "UNITCHECK"); /* scan connections */ RunSingleThreadOn(CheckConnectionsThread, PATHFINDING_WIDTH * PATHFINDING_WIDTH * (CORE_DIRECTIONS / (1 + RT_IS_BIDIRECTIONAL)) * (ACTOR_MAX_SIZE), config.verbosity >= VERB_NORMAL, "CONNCHECK"); /* Try to shrink the world bounds along the x and y coordinates */ for (i = 0; i < 2; i++) { /* for x and y, but not z */ int j = i ^ 1; /* if i points to x, j points to y and vice versa */ /* Increase the mins */ while (wpMaxs[j] > wpMins[j]) { VectorSet(pos, wpMins[0], wpMins[1], wpMaxs[2]); for (pos[i] = wpMins[i]; pos[i] <= wpMaxs[i]; pos[i]++) { /* for all cells in an x or y row */ if (Nmap.getFloor(1, pos[0], pos[1], wpMaxs[2]) + wpMaxs[2] * CELL_HEIGHT != -1) /* no floor ? */ break; } if (pos[i] <= wpMaxs[i]) /* found a floor before the end of the row ? */ break; /* break while */ wpMins[j]++; /* if it was an x-row, increase y-value of mins and vice versa */ } /* Decrease the maxs */ while (wpMaxs[j] > wpMins[j]) { VectorCopy(wpMaxs, pos); for (pos[i] = wpMins[i]; pos[i] <= wpMaxs[i]; pos[i]++) { if (Nmap.getFloor(1, pos[0], pos[1], wpMaxs[2]) + wpMaxs[2] * CELL_HEIGHT != -1) break; } if (pos[i] <= wpMaxs[i]) break; wpMaxs[j]--; } } /* Output the floor trace file if set */ if (config.generateTraceFile) { RT_WriteCSVFiles(Nmap, baseFilename, GridBox(wpMins, wpMaxs)); } /* store the data */ data = curTile->routedata; for (i = 0; i < 3; i++) wpMins[i] = LittleLong(wpMins[i]); data = CompressRouting((byte*)wpMins, data, sizeof(wpMins)); for (i = 0; i < 3; i++) wpMaxs[i] = LittleLong(wpMaxs[i]); data = CompressRouting((byte*)wpMaxs, data, sizeof(wpMaxs)); data = CompressRouting((byte*)&Nmap, data, sizeof(Nmap)); curTile->routedatasize = data - curTile->routedata; /* Ensure that we did not exceed our allotment of memory for this data. */ assert(curTile->routedatasize <= MAX_MAP_ROUTING); /* Remove the CLIPS fom the tracing structure by resetting it. */ PopInfo(); }