added new data-structures
added new test-cases added flexible dijkstra calculation added debugging log modified: plotting, grid-generation, grid-importance, refactoring
This commit is contained in:
@@ -9,10 +9,16 @@
|
||||
#include "../GridNodeBBox.h"
|
||||
#include "../Grid.h"
|
||||
|
||||
#include "../../misc/Debug.h"
|
||||
|
||||
template <int gridSize_cm, typename T> class GridFactory {
|
||||
|
||||
/** logging name */
|
||||
static constexpr const char* name = "GridFac";
|
||||
|
||||
private:
|
||||
|
||||
/** the grid to build into */
|
||||
Grid<gridSize_cm, T>& grid;
|
||||
|
||||
|
||||
@@ -24,6 +30,7 @@ public:
|
||||
/** add the given floor at the provided height (in cm) */
|
||||
void addFloor(const Floor& floor, const float z_cm) {
|
||||
|
||||
Log::add(name, "adding floor at height " + std::to_string(z_cm));
|
||||
|
||||
// build grid-points
|
||||
for(int x_cm = 0; x_cm < floor.getWidth_cm(); x_cm += gridSize_cm) {
|
||||
@@ -43,8 +50,11 @@ public:
|
||||
|
||||
}
|
||||
|
||||
/** connect all neighboring nodes located on the given height-plane */
|
||||
void connectAdjacent(const float z_cm) {
|
||||
|
||||
Log::add(name, "connecting all adjacent nodes at height " + std::to_string(z_cm));
|
||||
|
||||
// connect adjacent grid-points
|
||||
for (int idx = 0; idx < grid.getNumNodes(); ++idx) {
|
||||
|
||||
@@ -79,6 +89,8 @@ public:
|
||||
|
||||
void addStairs(const Stairs& stairs, const float z1_cm, const float z2_cm) {
|
||||
|
||||
Log::add(name, "adding stairs between " + std::to_string(z1_cm) + " and " + std::to_string(z2_cm));
|
||||
|
||||
for (const Stair& s : stairs) {
|
||||
|
||||
for (int i = 0; i < grid.getNumNodes(); ++i) {
|
||||
@@ -100,7 +112,7 @@ public:
|
||||
buildStair(n, n2);
|
||||
|
||||
}
|
||||
int i = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,16 +194,21 @@ public:
|
||||
|
||||
void removeIsolated() {
|
||||
|
||||
Log::add(name, "searching for isolated nodes");
|
||||
|
||||
// get largest connected region
|
||||
std::set<int> set;
|
||||
do {
|
||||
const int idxStart = rand() % grid.getNumNodes();
|
||||
set.clear();
|
||||
Log::add(name, "getting connected region starting at " + (std::string) grid[idxStart]);
|
||||
getConnected(idxStart, set);
|
||||
Log::add(name, "region size is " + std::to_string(set.size()) + " nodes");
|
||||
|
||||
} while (set.size() < 0.5 * grid.getNumNodes());
|
||||
|
||||
|
||||
// remove all other
|
||||
Log::add(name, "removing the isolated nodes");
|
||||
for (int i = 0; i < grid.getNumNodes(); ++i) {
|
||||
if (set.find(i) == set.end()) {grid.remove(i);}
|
||||
}
|
||||
@@ -206,10 +223,14 @@ private:
|
||||
/** recursively get all connected nodes and add them to the set */
|
||||
void getConnected(const int idx, std::set<int>& set) {
|
||||
|
||||
T& n1 = (T&) grid[idx];
|
||||
// get the node behind idx
|
||||
const T& n1 = (T&) grid[idx];
|
||||
|
||||
// add him to the current region
|
||||
set.insert(n1.getIdx());
|
||||
|
||||
for (T& n2 : grid.neighbors(n1)) {
|
||||
// get all his (unprocessed) neighbors and add them to the region
|
||||
for (const T& n2 : grid.neighbors(n1)) {
|
||||
if (set.find(n2.getIdx()) == set.end()) {
|
||||
getConnected(n2.getIdx(), set);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user