结合整个函数,逐行加上注释
时间: 2023-06-23 20:00:43 浏览: 91
函数上半:void IntersectionInfoCache::makeIntersectionInfo(bool bIsInlink, const std::vector<LinkSymbol>& nodelinks, std::vector<IntersectionLinkInfo>& intersectionlinks) //制作路口信息,为set服务
{
// 遍历nodelinks中的每个LinkSymbol对象
for(int8 i = 0; i < nodelinks.size(); ++i) {
// 创建一个IntersectionLinkInfo对象
IntersectionLinkInfo intersectionLinkInfo;
// 填充IntersectionLinkInfo对象的各个属性
intersectionLinkInfo.direction = nodelinks[i].direction;
intersectionLinkInfo.index = nodelinks[i].index;
intersectionLinkInfo.bIsInlink = bIsInlink;
// 获取LinkSymbol对象对应的RoadLinkInfo对象
RoadLinkInfo* link = NULL;
RGDataManagerInstance->getRoadInfos(nodelinks[i].index,&link);
// 填充IntersectionLinkInfo对象的各个属性
intersectionLinkInfo.length = link->length;
intersectionLinkInfo.linkId = link->linkId;
intersectionLinkInfo.roadNameIdx = link->roadNameIdx;
intersectionLinkInfo.linkKind = link->linkKind;
// 如果LinkSymbol对象的direction属性为0
if(nodelinks[i].direction == 0) {
// 填充IntersectionLinkInfo对象的各个属性
intersectionLinkInfo.lineCount = (link->lineCount & 0x0F);
// 获取道路形状点的数量
int8 pointcount = link->shapePoints.count > LinkShapePoints_Max_Count ? LinkShapePoints_Max_Count : link->shapePoints.count;
// 分配空间
intersectionLinkInfo.shapePoints.reserve(pointcount);
// 如果是进口道,则从后往前添加道路形状点
if(bIsInlink) {
for(int8 p = pointcount; p > 0; p--) {
intersectionLinkInfo.shapePoints.push_back(link->shapePoints.locations[link->shapePoints.count-p].m_point);
}
// 更新RoadLinkInfo对象的intersection_form_index属性
link->e_inersection_form_index = intersection_form_index;
}
// 如果是出口道,则从前往后添加道路形状点
else {
for(int8 p = 0; p < pointcount; p++) {
intersectionLinkInfo.shapePoints.push_back(link->shapePoints.locations[p].m_point);
}
// 更新RoadLinkInfo对象的intersection_form_index属性
link->s_inersection_form_index = intersection_form_index;
}
}
// 如果LinkSymbol对象的direction属性为1
else if(nodelinks[i].direction == 1) {
// 填充IntersectionLinkInfo对象的各个属性
intersectionLinkInfo.lineCount = ((link->lineCount>>4) & 0x0F);
// 获取道路形状点的数量
int8 pointcount = link->shapePoints.count > LinkShapePoints_Max_Count ? LinkShapePoints_Max_Count : link->shapePoints.count;
// 分配空间
intersectionLinkInfo.shapePoints.reserve(pointcount);
// 如果是进口道,则从前往后添加道路形状点
if(bIsInlink) {
for(int8 p = pointcount-1; p >= 0; p--) {
intersectionLinkInfo.shapePoints.push_back(link->shapePoints.locations[p].m_point);
}
// 更新RoadLinkInfo对象的intersection_form_index属性
link->s_inersection_form_index = intersection_form_index;
}
// 如果是出口道,则从后往前添加道路形状点
else {
for(int8 p = 0; p < pointcount; p++) {
intersectionLinkInfo.shapePoints.push_back(link->shapePoints.locations[link->shapePoints.count-p-1].m_point);
}
// 更新RoadLinkInfo对象的intersection_form_index属性
link->e_inersection_form_index = intersection_form_index;
}
}
// 把IntersectionLinkInfo对象添加到intersectionlinks中
intersectionlinks.push_back(intersectionLinkInfo);
}
}
阅读全文