1.建立event类和CellNode类
2.将Wall(obostacle)每个坐标点变成event,加入event_list
3.根据event.x的值 对event施加event_type
4.对event_list中event.x排序
5.新建二维deque slice_list存放x值相同的event
6.根据slice_list中的event_type,执行相应的操作。
event类和CellNode类数据结构如下:
class Event
{
public:
Event(int obstacle_idx, int x_pos, int y_pos, EventType type=UNALLOCATED)
{
obstacle_index = obstacle_idx;
x = x_pos;
y = y_pos;
event_type = type;
original_index_in_slice = INT_MAX;
isUsed = false;
}
int x;
int y;
int original_index_in_slice;
int obstacle_index;
EventType event_type;
bool isUsed;
};
class CellNode
{
public:
CellNode()
{
isVisited = false;
isCleaned = false;
parentIndex = INT_MAX;
cellIndex = INT_MAX;
}
bool isVisited;
bool isCleaned;
Edge ceiling;
Edge floor;
int parentIndex;
std::deque<int> neighbor_indices;
int cellIndex;
};
一个CellNode可以由两个列表表示:一个CELING边缘列表和一个FLOOR边缘列表,因此,一个单元格结构包含两个指向边列表的指针:CELING指针和FLOOR指针。
CellNode结构还包含指向相邻单元的指针的链接列表。单元结构具有两个标志:visited和cleaned,
map_decomposition算法
std::vector<CellNode> ConstructCellGraph(const cv::Mat& original_map, const std::vector<std::vector<cv::Point>>& wall_contours, const std::vector<std::vector<cv::Point>>& obstacle_contours, const Polygon& wall, const PolygonList& obstacles)
{
cv::Mat3b map = cv::Mat3b(original_map.size());
map.setTo(cv::Scalar(0, 0, 0));
cv::fillPoly(map, wall_contours, cv::Scalar(255, 255, 255));
cv::fillPoly(map, obstacle_contours, cv::Scalar(0, 0, 0));
std::vector<Event> wall_event_list = GenerateWallEventList(map, wall);
std::vector<Event> obstacle_event_list = GenerateObstacleEventList(map, obstacles);
std::deque<std::deque<Event>> slice_list = SliceListGenerator(wall_event_list, obstacle_event_list);
std::vector<CellNode> cell_graph;
std::vector<int> cell_index_slice;
std::vector<int> original_cell_index_slice;
ExecuteCellDecomposition(cell_graph, cell_index_slice, original_cell_index_slice, slice_list);
return cell_graph;
}