initial version
This commit is contained in:
55
grid/factory/GridFactory.h
Executable file
55
grid/factory/GridFactory.h
Executable file
@@ -0,0 +1,55 @@
|
||||
#ifndef GRIDFACTORY_H
|
||||
#define GRIDFACTORY_H
|
||||
|
||||
#include <string>
|
||||
#include "../../floorplan/Floor.h"
|
||||
#include "../../geo/Units.h"
|
||||
#include "../GridNodeBBox.h"
|
||||
#include "../Grid.h"
|
||||
|
||||
template <int gridSize_cm, typename T> class GridFactory {
|
||||
|
||||
private:
|
||||
|
||||
Grid<gridSize_cm, T>& grid;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** ctor with the grid to fill */
|
||||
GridFactory(Grid<gridSize_cm, T>& grid) : grid(grid) {;}
|
||||
|
||||
/** add the given floor at the provided height (in cm) */
|
||||
void addFloor(const Floor& floor, const float z_cm) {
|
||||
|
||||
for(int x_cm = 0; x_cm < floor.getWidth_cm(); x_cm += gridSize_cm) {
|
||||
for (int y_cm = 0; y_cm < floor.getDepth_cm(); y_cm += gridSize_cm) {
|
||||
|
||||
// check intersection with the floorplan
|
||||
GridNodeBBox bbox(GridPoint(x_cm, y_cm, z_cm), gridSize_cm);
|
||||
if (intersects(bbox, floor)) {continue;}
|
||||
|
||||
// add to the grid
|
||||
grid.add(T(x_cm, y_cm, z_cm));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/** does the bbox intersect with any of the floor's walls? */
|
||||
bool intersects(const GridNodeBBox& bbox, const Floor& floor) {
|
||||
for (const Line2D l : floor.getObstacles()) {
|
||||
if (bbox.intersects(l)) {return true;}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // GRIDFACTORY_H
|
||||
Reference in New Issue
Block a user