#ifndef GRIDFACTORY_H #define GRIDFACTORY_H #include #include "../../floorplan/Floor.h" #include "../../geo/Units.h" #include "../GridNodeBBox.h" #include "../Grid.h" template class GridFactory { private: Grid& grid; public: /** ctor with the grid to fill */ GridFactory(Grid& 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