19 Map::Map(
float cellSize, std::vector<std::vector<int>> &grid, std::vector<std::vector<Point>> &obstacles)
21 this->cellSize = cellSize;
22 this->grid =
new std::vector<std::vector<int>>(grid);
23 this->obstacles =
new std::vector<std::vector<ObstacleSegment>>();
25 height = this->grid->size();
29 width = (*this->grid)[0].size();
34 for(
auto obstacle : obstacles)
36 if(obstacle.size() < 2)
41 bool rCvx =
true, lCvx;
42 std::vector<ObstacleSegment> tmpObstacle;
43 for(
int i = 0; i < obstacle.size(); i++)
45 Vertex left = obstacle[(i == 0 ? obstacle.size() - 1 : i - 1)];
46 Vertex right = obstacle[i];
47 Vertex next = obstacle[(i == obstacle.size() - 1 ? 0 : i + 1)];
50 if (obstacle.size() > 2)
52 rCvx = (left-next).Det(right - left) >= 0.0f;
60 tmpObstacle[0].left.SetConvex(rCvx);
61 this->obstacles->push_back(tmpObstacle);
65 for(
auto &obstacle : (*this->obstacles))
67 for(
int i = 0; i < obstacle.size(); i++)
69 obstacle[i].next = (i == obstacle.size()-1) ? &obstacle.at(0) : &obstacle.at(i+1);
70 obstacle[i].prev = (i == 0) ? &obstacle.at(obstacle.size()-1) : &obstacle.at(i-1);
79 cellSize = obj.cellSize;
80 grid = (obj.grid ==
nullptr) ?
nullptr :
new std::vector<std::vector<int>>(*obj.grid);
81 obstacles = (obj.obstacles ==
nullptr) ?
nullptr :
new std::vector<std::vector<ObstacleSegment>>(*obj.obstacles);
95 if(obstacles !=
nullptr)
117 return (i < height && i >= 0 && j < width && j >= 0);
142 res.
i = height - 1 - (int) (point.
Y() / cellSize);
143 res.
j = (int) (point.
X() / cellSize);
149 if(res.
i > height - 1)
157 if(res.
j > width - 1)
168 return {(node.
j * cellSize + cellSize/2), (height - 1 - node.
i) * cellSize + cellSize/2};
180 cellSize = obj.cellSize;
188 grid = (obj.grid ==
nullptr) ?
nullptr :
new std::vector<std::vector<int>>(*obj.grid);
190 if(obstacles !=
nullptr)
194 obstacles = (obj.obstacles ==
nullptr) ?
nullptr :
new std::vector<std::vector<ObstacleSegment>>(*obj.obstacles);
unsigned int GetWidth() const
Return width of grid.
The Node class defines a cell of grid (see Map class)
void SetConvex(bool cvx)
Sets convexity of vertex.
bool CellIsTraversable(int i, int j) const
Check Cell (i,j) is traversable.
bool CellOnGrid(int i, int j) const
Check Cell (i,j) is inside grid.
float Y() const
Returns Y-coordinate of the point.
The ObstacleSegment class defines an edge of an obstacle polygon.
float GetCellSize() const
Return size of cell side.
The Point class defines a position (or euclidean vector from (0,0)) in 2D space.
const std::vector< std::vector< ObstacleSegment > > & GetObstacles() const
Return obstacles in form of polygons.
Point GetPoint(const Node &node) const
Return center of grid cell in orthogonal coordinates.
bool CellIsObstacle(int i, int j) const
Check Cell (i,j) is obstacle.
#define CN_GC_NOOBS
Not obstacle cell in XML.
Map class describes static environment.
int i
The number of row. Part of (i,j) address of cell on grid.
Map & operator=(const Map &obj)
Assignment operator.
Map()
Map default constructor.
int j
The number of column. Part of (i,j) address of cell on grid.
float X() const
Returns X-coordinate of the point.
The Vertex class defines a vertex of an obstacle polygon.
Node GetClosestNode(const Point &point) const
Return cell to which point in orthogonal coordinates belong.
unsigned int GetHeight() const
Return height of grid.