Far planner 代码系列(14)
MatchContourWithNavGraph(3)
this->EnclosePolygonsCheck(); //可能有些ctnode的is_contour_necessary属性变成了true // 这说明我的contour_graph是一个local层级的 才会从这里面 get new vertices new_convex_vertices.clear(); //! 把contour_graph_里符合要求的 ctnode_ptr push 进 new_convex_vertices for (const auto& ctnode_ptr : ContourGraph::contour_graph_) { // Get new vertices // ctnode不是global_match 且 free_direct 不是UNKNOWN if (!ctnode_ptr->is_global_match && ctnode_ptr->free_direct != NodeFreeDirect::UNKNOW) { if (ctnode_ptr->free_direct != NodeFreeDirect::PILLAR) { // check wall contour // 因为dir里的点对都是归一化过的,所以点积直接就可以得到夹角的cos值 const float dot_value = ctnode_ptr->surf_dirs.first * ctnode_ptr->surf_dirs.second; if (dot_value < ALIGN_ANGLE_COS) continue; // wall detected // ALIGN_ANGLE_COS 这里是178° cos值是-0.9939 比这个还小就说明是180°了 } new_convex_vertices.push_back(ctnode_ptr); } }}
检查完EnclosePolygonsCheck()之后,我们就要来更新new_contour_vertices了
首先把new_convex_vertices清空,因为我们要来装新的nodes了,来看看什么样的nodes才能被放进去:
if (!ctnode_ptr->is_global_match && ctnode_ptr->free_direct != NodeFreeDirect::UNKNOW)
一是 它没有被匹配到 也就是 is_global_match 为 false;
二是 它的类型不为UNKNOW
满足这两个条件后,程序往下运行,又遇到一个if判断:
if (ctnode_ptr->free_direct != NodeFreeDirect::PILLAR)
这个判断主要是过滤掉wall contour 当node类型不为PILLAR的时候,因为如果是PILLAR 那没什么好算的。
if (ctnode_ptr->free_direct != NodeFreeDirect::PILLAR) { // check wall contour // 因为dir里的点对都是归一化过的,所以点积直接就可以得到夹角的cos值 const float dot_value = ctnode_ptr->surf_dirs.first * ctnode_ptr->surf_dirs.second; if (dot_value < ALIGN_ANGLE_COS) continue; // wall detected // ALIGN_ANGLE_COS 这里是178° cos值是-0.9939 比这个还小就说明是180°了 }
这里我们注意到一个参数,ALIGN_ANGLE_COS 在CONTOUR_GRAPH的类里,这个值是-0.9939 也就是178°左右。 dot_value是两个单位向量的点乘,那么模值直接为1 只剩下cos值。如果dot_value<ALIGN_ANGLE_COS 那就说明这个nodes的front方向和back方向形成的角度有180° 表面这个是个墙。
最后把满足要求的ctnode给它push进去。MatchContourWithNavGraph完事了
new_convex_vertices.push_back(ctnode_ptr)