Extract retaining wall boundaries based on point clouds
Algorithm ideas
- Transfer the point to the polar coordinate system, get the index value in the polar coordinate system, and output the distance information.
double getCellIndexFromPoints(double x, double y, int& chI)
{
// 计算点到原点的欧几里得距离
double distance = sqrt(x * x + y * y);
// 将极坐标中的角度映射为一个标准化的值,确保在 [0, 1) 范围内
double chP = (atan2(y, x) + M_PI) / (2 * M_PI);
// 将标准化的角度值映射为索引值(在 numChannel_ 范围内)
chI = floor(chP * numChannel_);
// 返回点到原点的欧几里得距离
return distance;
}
2. Define a grid Cell, which stores x, y coordinates and distance. Define a map, key is the index, and value is the raster. When the indexes are the same, the distance of the grid is judged, and the small distance is retained.
typedef struct
{
double x,y;
double distance = 9999;
}Cell;
cell_map.clear();
for(auto point : cloud->points){
int chI = -1;
double distance = getCellIndexFromPoints(point.x,point.y,chI);
if (chI >= 0 && chI < numChannel_){
if(cell_map.find(chI)==cell_map.end() || cell_map[chI].distance > distance){
cell_map[chI] = {
point.x,point.y,distance};
}
}
}
- Traverse the map, fill in the x and y in Value into the boundary line, and get the final content
for(auto map_item : cell_map){
PointSany point{
map_item.second.x,map_item.second.y,1.0};
hull->points.push_back(point);
}