本文整理汇总了C++中GridMap::isOccupied方法的典型用法代码示例。如果您正苦于以下问题:C++ GridMap::isOccupied方法的具体用法?C++ GridMap::isOccupied怎么用?C++ GridMap::isOccupied使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GridMap
的用法示例。
在下文中一共展示了GridMap::isOccupied方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/**
* \brief Returns the neighbors of a grid cell that are not occupied and not already expanded.
* \param[in] currentNode The current grid node.
* \param[in] list The list of already expanded nodes in the current tree.
* \param[in] map The grid map.
*/
std::vector<AbstractNode*> RRT::getNeighbors(GridNode * const currentNode, const std::vector<AbstractNode*>& list, const GridMap& map) const {
std::vector<AbstractNode*> neighbors;
/* TODO: Fill the neighbors vector with neighbor cells of currentNode that are
* within the map bounds, not occupied, and not in the list of already expanded nodes.
*/
/* Available methods and fields:
* - node->x: the x index of the cell
* - node->y: the y index of the cell
* - map.width: width of the map in cells
* - map.height: height of the map in cells
* - map.isOccupied(int x, int y): returns true iff the cell is occupied by an obstacle
* - GridNode::get(int x, int y): creates and returns a new node representing a cell.
*/
int x = currentNode->x;
int y = currentNode->y;
GridNode* topRight = NULL;
GridNode* top = NULL;
GridNode* topLeft= NULL;
GridNode* left = NULL;
GridNode* bottomLeft = NULL;
GridNode* bottomRight = NULL;
GridNode* bottom = NULL;
GridNode* right = NULL;
std::vector<GridNode *> tmp_grid_vector;
if(x>0 && y>0)
{
topRight = GridNode::get(x-1,y-1);
}
if(y>0){
top = GridNode::get(x,y-1);
}
if(x<map.width-1 && y>0){
topLeft = GridNode::get(x+1,y-1);
}
if(x<map.width-1){
left = GridNode::get(x+1,y);
}
if(x<map.width-1 && y<map.height-1){
bottomLeft = GridNode::get(x+1,y+1);
}
if(x>0 && y<map.height-1){
bottomRight = GridNode::get(x-1, y+1);
}
if(y<map.height-1){ bottom = GridNode::get(x,y+1);
}
if(x>0){
right = GridNode::get(x-1,y);
}
tmp_grid_vector.push_back(topRight);
tmp_grid_vector.push_back(topLeft);
tmp_grid_vector.push_back(right);
tmp_grid_vector.push_back(bottomRight);
tmp_grid_vector.push_back(bottom);
tmp_grid_vector.push_back(bottomLeft);
tmp_grid_vector.push_back(left);
tmp_grid_vector.push_back(top);
std::vector<GridNode *>::iterator it;
for (it =tmp_grid_vector.begin();it!=tmp_grid_vector.end();it++ )
{
if (*it)
{
GridNode * tGridNode = *it;
if(!map.isOccupied(tGridNode->x,tGridNode->y))
if (std::find(list.begin(), list.end(), tGridNode) == list.end())
neighbors.push_back(*it);
}
}
return neighbors;
}