pushing before transfering ownership
added new tests and new helper classes speed improvements minor fixes
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#define GRIDFACTORY_H
|
||||
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "../../floorplan/Floor.h"
|
||||
#include "../../floorplan/Stairs.h"
|
||||
|
||||
@@ -30,9 +32,10 @@ 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));
|
||||
Log::add(name, "adding floor at height " + std::to_string(z_cm), false);
|
||||
Log::tick();
|
||||
|
||||
const float gridSize_cm = grid.getGridSize_cm();
|
||||
const int gridSize_cm = grid.getGridSize_cm();
|
||||
|
||||
// build grid-points
|
||||
for(int x_cm = 0; x_cm < floor.getWidth_cm(); x_cm += gridSize_cm) {
|
||||
@@ -48,6 +51,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
Log::tock();
|
||||
|
||||
connectAdjacent(z_cm);
|
||||
|
||||
}
|
||||
@@ -55,15 +60,16 @@ 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));
|
||||
Log::add(name, "connecting all adjacent nodes at height " + std::to_string(z_cm), false);
|
||||
Log::tick();
|
||||
|
||||
const int gridSize_cm = grid.getGridSize_cm();
|
||||
|
||||
// connect adjacent grid-points
|
||||
for (int idx = 0; idx < grid.getNumNodes(); ++idx) {
|
||||
for (T& n1 : grid) {
|
||||
|
||||
T& n1 = (T&) grid[idx];
|
||||
if (n1.z_cm != z_cm) {continue;} // ugly... different floor -> skip
|
||||
// not the floor we are looking for? -> skip (ugly.. slow(er))
|
||||
if (n1.z_cm != z_cm) {continue;}
|
||||
|
||||
// square around each point
|
||||
for (int x = -gridSize_cm; x <= gridSize_cm; x += gridSize_cm) {
|
||||
@@ -73,14 +79,14 @@ public:
|
||||
if ((x == y) && (x == 0)) {continue;}
|
||||
|
||||
// position of the potential neighbor
|
||||
int ox = n1.x_cm + x;
|
||||
int oy = n1.y_cm + y;
|
||||
GridPoint p(ox, oy, n1.z_cm);
|
||||
const int ox = n1.x_cm + x;
|
||||
const int oy = n1.y_cm + y;
|
||||
const GridPoint p(ox, oy, n1.z_cm);
|
||||
|
||||
// does the grid contain the potential neighbor?
|
||||
if (grid.hasNodeFor(p)) {
|
||||
T& n2 = (T&) grid.getNodeFor(p);
|
||||
grid.connectUniDir(n1, n2);
|
||||
const T* n2 = grid.getNodePtrFor(p);
|
||||
if (n2 != nullptr) {
|
||||
grid.connectUniDir(n1, *n2); // UNI-dir connection as EACH node is processed!
|
||||
}
|
||||
|
||||
}
|
||||
@@ -88,6 +94,8 @@ public:
|
||||
|
||||
}
|
||||
|
||||
Log::tock();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -205,7 +213,7 @@ public:
|
||||
Log::add(name, "searching for isolated nodes");
|
||||
|
||||
// get largest connected region
|
||||
std::set<int> set;
|
||||
std::unordered_set<int> set;
|
||||
do {
|
||||
const int idxStart = rand() % grid.getNumNodes();
|
||||
set.clear();
|
||||
@@ -229,7 +237,7 @@ public:
|
||||
private:
|
||||
|
||||
/** recursively get all connected nodes and add them to the set */
|
||||
void getConnected(const int idx, std::set<int>& set) {
|
||||
void getConnected(const int idx, std::unordered_set<int>& set) {
|
||||
|
||||
// get the node behind idx
|
||||
const T& n1 = (T&) grid[idx];
|
||||
|
||||
Reference in New Issue
Block a user